---

- name: install archivetools package
  pacman: name=archivetools state=present

- name: make archive dir
  file:
    path: "{{ archive_dir }}"
    state: directory
    owner: archive
    group: archive
    mode: 0755

- name: setup archive configuration
  template:
    src: archive.conf.j2
    dest: /etc/archive.conf
    owner: root
    group: root
    mode: 0644

- name: setup archive timer
  systemd: name=archive.timer enabled=yes state=started

- name: setup archive-hardlink timer
  systemd: name=archive-hardlink.timer enabled=yes state=started
- name: install internet archive packages
  pacman: name=python-internetarchive,python-xtarfile state=present

- name: create archive user
  user: name={{ archive_user_name }} shell=/bin/false home="{{ archive_user_home }}" createhome=yes

- name: configure archive.org client
  command: ia configure --username={{ vault_archive_username }} --password={{ vault_archive_password }} creates={{ archive_user_home }}/.config/ia.ini
  become: true
  become_user: "{{ archive_user_name }}"

- name: clone archive uploader code
  git: repo=https://github.com/archlinux/arch-historical-archive.git dest="{{ archive_repo }}" version="{{ archive_uploader_version }}"
  become: true
  become_user: "{{ archive_user_name }}"

- name: install system service
  template: src={{ item }} dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
  loop:
    - archive-uploader.service
    - archive-uploader.timer

- name: start uploader timer
  systemd:
    name: archive-uploader.timer
    enabled: true
    state: started
    daemon_reload: true
