- tags: packages
  apt:
    name:
      - borgbackup
    install_recommends: no

- name: "mkdir /etc/tergum"
  file:
    path: "/etc/tergum"
    state: directory
    mode: u=rwx,go=
    owner: root
    group: root

- copy:
    dest: /etc/tergum/ssh-key
    src: "{{ borg_client__ssh_key }}"
    mode: u=rwx,go=
    owner: root
    group: root

- name: "/etc/systemd/system/tergum@.service"
  copy:
    dest: "/etc/systemd/system/tergum@.service"
    content: |
      [Unit]
      Description=Borg backup

      [Service]
      Type=oneshot
      WorkingDirectory=/
      ExecStart=-/usr/bin/tergum %i
      #ExecStartPost=-/usr/bin/tergum-post foo@example.org
      SuccessExitStatus=0 1
      EnvironmentFile=/etc/tergum/jobs/%i/env
  notify:
    - systemctl daemon-reload

- name: "/etc/systemd/system/tergum@.timer"
  copy:
    dest: "/etc/systemd/system/tergum@.timer"
    content: |
      [Unit]
      Description=Borg

      [Install]
      WantedBy=timers.target
  notify:
    - systemctl daemon-reload

- template:
    dest: "/usr/bin/{{ item }}"
    src: "bin/{{ item }}"
    mode: u=rwx,go=rx
    owner: root
    group: root
  with_items:
    - tergum
    - tergum-post