From 89a494f581239e95578cf30aac9fd1d340bdedff Mon Sep 17 00:00:00 2001 From: Jim Campbell Date: Sat, 27 Jan 2024 23:09:18 -0600 Subject: [PATCH] flatpaks: Include update timer & clean up Ansible Update flatpaks at 4:00am or 2min after boot Combine multiple 'copy' steps into one step --- .../flatpaks/files/flatpak-update.service | 10 ++++++ .../roles/flatpaks/files/flatpak-update.timer | 12 +++++++ .../roles/flatpaks/tasks/main.yml | 33 ++++++++++--------- 3 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 ansible-silverblue/roles/flatpaks/files/flatpak-update.service create mode 100644 ansible-silverblue/roles/flatpaks/files/flatpak-update.timer diff --git a/ansible-silverblue/roles/flatpaks/files/flatpak-update.service b/ansible-silverblue/roles/flatpaks/files/flatpak-update.service new file mode 100644 index 0000000..6e2940e --- /dev/null +++ b/ansible-silverblue/roles/flatpaks/files/flatpak-update.service @@ -0,0 +1,10 @@ +[Unit] +Description=Flatpak Automatic Update +Documentation=man:flatpak(1) +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +ExecCondition=/bin/bash -c '[[ "$(busctl get-property org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager Metered | cut -c 3-)" == @(2|4) ]]' +ExecStart=/usr/bin/flatpak --system uninstall --unused -y --noninteractive ; /usr/bin/flatpak --system update -y --noninteractive ; /usr/bin/flatpak --system repair diff --git a/ansible-silverblue/roles/flatpaks/files/flatpak-update.timer b/ansible-silverblue/roles/flatpaks/files/flatpak-update.timer new file mode 100644 index 0000000..0f9e8aa --- /dev/null +++ b/ansible-silverblue/roles/flatpaks/files/flatpak-update.timer @@ -0,0 +1,12 @@ +[Unit] +Description=Flatpak Automatic Update Trigger +Documentation=man:flatpak(1) + +[Timer] +RandomizedDelaySec=10m +OnBootSec=2m +OnCalendar=*-*-* 4:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/ansible-silverblue/roles/flatpaks/tasks/main.yml b/ansible-silverblue/roles/flatpaks/tasks/main.yml index 5530ede..d9a6896 100644 --- a/ansible-silverblue/roles/flatpaks/tasks/main.yml +++ b/ansible-silverblue/roles/flatpaks/tasks/main.yml @@ -9,26 +9,29 @@ group: root mode: 0755 -- name: Copy 'flatpak-setup.desktop' into the /etc/skel.d/.config/autostart directory - ansible.builtin.copy: - src: files/ansible-silverblue-oci-firstboot.sh - dest: /etc/profile.d/ansible-silverblue-oci-firstboot.sh +- name: Create flatpak installation script at /usr/bin/ansible-silverblue-flatpak + ansible.builtin.template: + src: templates/ansible-silverblue-flatpaks.jinja2 + dest: /usr/bin/ansible-silverblue-flatpak owner: root group: root mode: 0755 -- name: Copy 'flatpak-setup.desktop' into the /etc/skel.d/.config/autostart directory +- name: Copy flatpak script and update service+timer files onto the host ansible.builtin.copy: - src: files/flatpak-setup.desktop - dest: /etc/skel.d/.config/autostart/flatpak-setup.desktop + src: files/{{ item.name }} + dest: {{ item.path }} owner: root group: root - mode: 0755 + mode: {{ item.mode }} + loop: + - {name: 'ansible-silverblue-oci-firstboot.sh', path '/etc/profile.d/ansible-silverblue-oci-firstboot.sh', mode: '0755'} + - [name: 'flatpak-setup.desktop', path: '/etc/skel.d/.config/autostart/flatpak-setup.desktop', mode: '0755 '] + - [name: 'flatpak-update.service', path: '/etc/systemd/system/flatpak-update.service', mode: '0644 '] + - [name: 'flatpak-update.timer', path: '/etc/systemd/system/flatpak-update.timer', mode: '0644 '] -- name: Create flatpak installation script at /usr/bin/ansible-silverblue-flatpak - ansible.builtin.template: - src: templates/ansible-silverblue-flatpaks.jinja2 - dest: /usr/bin/ansible-silverblue-flatpak - owner: root - group: root - mode: 0755 +- name: Enable the flatpak-update service + ansible.builtin.systemd_service: + name: flatpak-update.timer + enabled: true + daemon_reload: true