---

- include_role:
    name: evolix/remount-usr

- name: Scripts dir is present
  file:
    path: "/usr/share/scripts"
    state: directory
    owner: root
    group: root
    mode: "0700"

- name: Copy listupgrade script
  copy:
    src: listupgrade.sh
    dest: "/usr/share/scripts/listupgrade.sh"
    mode: "0700"
    owner: root
    group: root
    force: yes

- name: Create /etc/evolinux
  file:
    path: /etc/evolinux
    state: directory
    owner: root
    group: root
    mode: "0700"

- name: Copy listupgrade config
  template:
    src: listupgrade.cnf.j2
    dest: /etc/evolinux/listupgrade.cnf
    mode: "0600"
    owner: root
    group: root
    force: no

- name: Cron.d is present
  file:
    path: "/etc/cron.d"
    state: directory
    mode: "0755"
    owner: root
    group: root

- name: Enable listupgrade cron
  cron:
    name: "lisupgrade.sh"
    cron_file: "listupgrade"
    user: root
    job: "/usr/share/scripts/listupgrade.sh --cron {{ listupgrade_cron_force | bool | ternary('--force','') }}"
    minute: "{{ listupgrade_cron_minute }}"
    hour: "{{ listupgrade_cron_hour }}"
    weekday: "{{ listupgrade_cron_weekday }}"
    day: "{{ listupgrade_cron_day }}"
    month: "{{ listupgrade_cron_month }}"
    state: "{{ listupgrade_cron_enabled | bool | ternary('present','absent') }}"

- name: old-kernel-autoremoval script is present
  copy:
    src: old-kernel-autoremoval.sh
    dest: /usr/share/scripts/old-kernel-autoremoval.sh
    mode: "0755"
    owner: root
    group: root
