From 473c2e9a619e5b285a6f3785230eb8df71dc5844 Mon Sep 17 00:00:00 2001 From: Adrian Wannenmacher Date: Fri, 12 Feb 2021 02:05:34 +0100 Subject: [PATCH] feat: :sparkles: add cleaning facilities --- install.fish | 3 +++ src/snap-pac-uki.fish | 13 +++++++++++++ systemd/snap-pac-uki-cleanup.service | 6 ++++++ systemd/snap-pac-uki-cleanup.timer | 9 +++++++++ 4 files changed, 31 insertions(+) create mode 100644 systemd/snap-pac-uki-cleanup.service create mode 100644 systemd/snap-pac-uki-cleanup.timer diff --git a/install.fish b/install.fish index d4b2c1b..e0d4da7 100755 --- a/install.fish +++ b/install.fish @@ -4,3 +4,6 @@ echo "installed creation script." cp ./pacman/* /usr/share/libalpm/hooks/ echo "installed pacman hooks." + +cp ./systemd/* /etc/systemd/system/ +echo "installed systemd unit files" diff --git a/src/snap-pac-uki.fish b/src/snap-pac-uki.fish index 0f19f8c..f919539 100755 --- a/src/snap-pac-uki.fish +++ b/src/snap-pac-uki.fish @@ -151,6 +151,19 @@ function main cp "$CFG_BUILD_DIR/current/arch-linux-fallback.efi" "$CFG_UKI_DIR" echo " -> copied ukis into uki directory" + case "clean" + echo "==> cleaning ukis" + + set ids (snapper -c $CFG_SNAPSHOT_CONFIG --jsonout ls | jq ".$CFG_SNAPSHOT_CONFIG [] | .number") + for uki in (ls "$CFG_UKI_DIR" | rg "[0-9]" | sed "s/arch-linux-\([0-9]*\).efi/\1/") + if not contains "$uki" $ids + echo " -> cleaning uki and boot entry for removed snapshot $uki" + rm "$CFG_UKI_DIR/arch-linux-$uki.efi" + + efibootmgr -q -b (efibootmgr -v | rg "arch-linux-$uki.efi" | sed "s/\*//;s/Boot0*\(.*\) Arch .*/\1/") -B + end + end + case "*" error "unknown command" end diff --git a/systemd/snap-pac-uki-cleanup.service b/systemd/snap-pac-uki-cleanup.service new file mode 100644 index 0000000..69774d2 --- /dev/null +++ b/systemd/snap-pac-uki-cleanup.service @@ -0,0 +1,6 @@ +[Unit] +Description=cleaning up ukis + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/snap-pac-uki clean diff --git a/systemd/snap-pac-uki-cleanup.timer b/systemd/snap-pac-uki-cleanup.timer new file mode 100644 index 0000000..f4de455 --- /dev/null +++ b/systemd/snap-pac-uki-cleanup.timer @@ -0,0 +1,9 @@ +[Unit] +Description="timer for triggering uki cleanup + +[Timer] +OnBootSec=15min +OnUnitActiveSec=1d + +[Install] +WantedBy=timers.target