From f1ff8615b62da8ea858b18ce4e4c5ded1147c411 Mon Sep 17 00:00:00 2001 From: Adrian Wannenmacher Date: Fri, 25 Sep 2020 15:22:09 +0200 Subject: [PATCH] Add cleanup and more streamlined hook descriptions --- hooks/01_snap-pac-uki_pre.hook | 2 +- ...c-uki_post.hook => zzy_snap-pac-uki_post.hook} | 2 +- hooks/zzz_snap-pac-uki_cleanup.hook | 11 +++++++++++ scripts/snap-pac-uki_cleanup.fish | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) rename hooks/{zz_snap-pac-uki_post.hook => zzy_snap-pac-uki_post.hook} (74%) create mode 100644 hooks/zzz_snap-pac-uki_cleanup.hook create mode 100755 scripts/snap-pac-uki_cleanup.fish diff --git a/hooks/01_snap-pac-uki_pre.hook b/hooks/01_snap-pac-uki_pre.hook index 852b059..ad022a9 100644 --- a/hooks/01_snap-pac-uki_pre.hook +++ b/hooks/01_snap-pac-uki_pre.hook @@ -6,7 +6,7 @@ Type = Package Target = * [Action] -Description = Performing snapper pre snapshot UKI creation... +Description = Performing pre UKI creation... When = PreTransaction Exec = /usr/share/libalpm/scripts/snap-pac-uki_create.fish AbortOnFail diff --git a/hooks/zz_snap-pac-uki_post.hook b/hooks/zzy_snap-pac-uki_post.hook similarity index 74% rename from hooks/zz_snap-pac-uki_post.hook rename to hooks/zzy_snap-pac-uki_post.hook index c0ca293..8c7711a 100644 --- a/hooks/zz_snap-pac-uki_post.hook +++ b/hooks/zzy_snap-pac-uki_post.hook @@ -6,6 +6,6 @@ Type = Package Target = * [Action] -Description = Performing snapper post snapshot UKI creation... +Description = Performing post UKI creation... When = PostTransaction Exec = /usr/share/libalpm/scripts/snap-pac-uki_create.fish diff --git a/hooks/zzz_snap-pac-uki_cleanup.hook b/hooks/zzz_snap-pac-uki_cleanup.hook new file mode 100644 index 0000000..0f6869d --- /dev/null +++ b/hooks/zzz_snap-pac-uki_cleanup.hook @@ -0,0 +1,11 @@ +[Trigger] +Operation = Upgrade +Operation = Install +Operation = Remove +Type = Package +Target = * + +[Action] +Description = Performing UKI cleanup... +When = PostTransaction +Exec = /usr/share/libalpm/scripts/snap-pac-uki_cleanup.fish diff --git a/scripts/snap-pac-uki_cleanup.fish b/scripts/snap-pac-uki_cleanup.fish new file mode 100755 index 0000000..98b66a0 --- /dev/null +++ b/scripts/snap-pac-uki_cleanup.fish @@ -0,0 +1,15 @@ +#!/bin/fish + +# get snapshots +set -l config "root" +set -l snapshot_ids (snapper -c $config --jsonout ls | jq ".$config | .[] | .number") + + +# get current ukis +set -l ukis (ls /boot/EFI/Linux/ | grep "snap-pac-uki-[1-9][0-9]*\.efi" | grep -o '[1-9][0-9]*') + +for x in $ukis + if not contains $x $snapshot_ids + rm "/boot/EFI/Linux/snap-pac-uki-$x.efi" + end +end