---
- name: Package cache updated
  shell: pkg update -f

- name: Dependencies installed
  community.general.pkgng:
    name: git-tiny,py39-afew,py39-alot,openssl,pkgconf,sqlite,autotools,isync
    state: latest

- name: Source folder exists
  file:
    path: /usr/local/src
    mode: 0755
    state: directory

- name: Muchsync release fetched
  get_url:
    url: "http://www.muchsync.org/src/muchsync-6.tar.gz"
    dest: "/usr/local/src/muchsync-6.tar.gz"

- name: Muchsync unpacked
  command: "tar -xzf /usr/local/src/muchsync-6.tar.gz"
  args:
    chdir: "/usr/local/src"
    warn: false

- name: Muchsync built and installed
  shell:
    cmd: ./configure && make && make install
    chdir: /usr/local/src/muchsync-6

- name: afew config folder exists
  file:
    path: /root/.config/afew
    mode: 0755
    state: directory

- name: afew config file installed
  copy:
    src: afew-config
    dest: /root/.config/afew/config
    mode: 0644

- name: archive_filter installed
  copy:
    src: archive_filter.py
    dest: /root/.config/afew/archive_filter.py
    mode: 0644

- name: mbsync config file installed
  template:
    src: mbsyncrc.j2
    dest: /root/.mbsyncrc
    mode: 0644

- name: notmuchconfig file installed
  copy:
    src: notmuch-config
    dest: /root/.notmuch-config
    mode: 0644

- name: Checkmail script installed
  copy:
    src: checkmail
    dest: /usr/local/bin/checkmail
    owner: root
    mode: 0744

- name: Run checkmail once
  shell: checkmail

- name: Checkmail cronjob configured
  cron:
    name: "Check mail"
    minute: "*/10"
    hour: "*"
    day: "*"
    month: "*"
    job: "/usr/local/bin/checkmail"
