simplify program

main
Adrian Wannenmacher 2 months ago
parent 38745b9d44
commit 4d4c2c7920
Signed by: tfld
GPG Key ID: 19D986ECB1E492D5
  1. 17
      src/config.fish
  2. 46
      src/snap-pac-uki.fish

@ -2,7 +2,7 @@ function config -d "sets some configuration variables"
# If this is not set to "yes", snap-pac-uki will not do anything when
# executed.
#
# This is to make sure that this program can be installed with pacman. If
# this wasn't done, pacman would install this program with an default
# config, which most likely wouldn't work correctly. Therefore this needs
@ -21,21 +21,6 @@ function config -d "sets some configuration variables"
# images.
set -g CFG_DEFAULT_SUBVOL "@"
# Wheter to add a new EFI entry for a new snapshot uki
set -g CFG_EFI "yes"
# The device the EFI partition resides on
set -g CFG_EFI_DEV "/dev/nvme0n1"
# The "efi directory" that will contain the ukis
set -g CFG_EFI_PATH "\EFI\Linux"
# The efi partitions number on the device
set -g CFG_EFI_PART "1"
# The snapper config name
set -g CFG_SNAPSHOT_CONFIG "root"
# The linux fs path containing all snapshot data
set -g CFG_SNAPSHOT_PATH "/.snapshots"

@ -7,10 +7,8 @@ end
function check_deps -d "checks if all dependencies are available"
set -l dependencies \
"jq" \
"rg" \
"sed" \
"snapper" \
for dep in $dependencies
which $dep >/dev/null 2>/dev/null
@ -20,12 +18,6 @@ function check_deps -d "checks if all dependencies are available"
end
end
which "efibootmgr" >/dev/null 2>/dev/null
if test $status != "0" -a $CFG_EFI = "yes"
set -g CFG_EFI "no"
echo "CFG_EFI overwriten to \"no\": 'efibootmgr' not available"
end
which "sbsign" >/dev/null 2>/dev/null
if test $status != "0" -a $CFG_SECUREBOOT = "yes"
set -g CFG_SECUREBOOT "no"
@ -33,11 +25,11 @@ function check_deps -d "checks if all dependencies are available"
end
end
function find_tasks -d "finds out what the program needs to do"
function find_ukiless_snapshots -d "find"
set -ge TASK_UKI
for id in (snapper -c $CFG_SNAPSHOT_CONFIG --jsonout ls | jq ".$CFG_SNAPSHOT_CONFIG [] | .number")
if test "$id" = "0"
for id in (ls $CFG_SNAPSHOT_PATH)
if test $id = "0"
continue
end
@ -66,16 +58,7 @@ function create_uki -d "creates a new uki" -a variant id
end
# create initrd
set amd "$prefix/boot/amd-ucode.img"
set intel "$prefix/boot/intel-ucode.img"
set initrd "$bd/initramfs-linux$fallback.img"
if test -f $amd
cat $amd >> $initrd
end
if test -f $intel
cat $intel >> $initrd
end
cat "$prefix/boot/initramfs-linux$fallback.img" >> $initrd
# create uki
@ -139,27 +122,21 @@ function create_current_uki -d "creates an uki for the current system"
create_uki fallback
end
function add_efi_entry -d "adds an efi boot entry for a snapshot uki" -a id
efibootmgr -q -C -d $CFG_EFI_DEV -p $CFG_EFI_PART \
-l "$CFG_EFI_PATH\arch-linux-$id.efi" \
-L "Arch Linux (Snapshot $id)"
end
function main
# prepare for execution
source "/etc/snap-pac-uki/config.fish"
config
if test "$CFG_ENABLED" != "yes"
echo "not enabled in config file" 1>&2
echo "==> snap-pac-uki not enabled in config file" 1>&2
exit 0
end
check_deps
switch $argv[1]
case "snapshots"
find_tasks
find_ukiless_snapshots
for id in $TASK_UKI
echo "==> found snapshot without uki: $id"
@ -168,11 +145,6 @@ function main
cp "$CFG_BUILD_DIR/$id/arch-linux-$id.efi" "$CFG_UKI_DIR"
echo " -> copied uki for snapshot $id into uki directory"
if test "$CFG_EFI" = "yes"
add_efi_entry $id
echo " -> created efi boot entry for uki of snapshot $id"
end
end
case "current"
@ -188,15 +160,11 @@ function main
case "clean"
echo "==> cleaning ukis"
set ids (snapper -c $CFG_SNAPSHOT_CONFIG --jsonout ls | jq ".$CFG_SNAPSHOT_CONFIG [] | .number")
set ids (ls $CFG_SNAPSHOT_PATH)
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"
if test "$CFG_EFI" = "yes"
efibootmgr -q -b (efibootmgr -v | rg "arch-linux-$uki.efi" | sed "s/\*//;s/Boot0*\(.*\) Arch .*/\1/") -B
end
end
end

Loading…
Cancel
Save