feat: tell the efi about snapshot ukis

This commit is contained in:
Adrian Wannenmacher 2021-02-10 22:40:10 +01:00
parent 0bbca8b8ff
commit 53279cb983
Signed by: tfld
GPG Key ID: 19D986ECB1E492D5
1 changed files with 11 additions and 5 deletions

View File

@ -7,7 +7,7 @@ function error -d "prints an error and terminates the program" -a error
end
function checkdeps -d "check for depenencies"
set -l deps "jq" "snapper"
set -l deps "jq" "snapper" "efibootmgr"
for dep in $deps
which $dep >/dev/null 2>/dev/null
@ -21,6 +21,7 @@ function load_config -d "loads the config from a config file" -a cfg
# set default values
set -g BUILD_PATH "/tmp/snap-pac-uki"
set -g EFI_DIR "/efi/EFI/Linux/"
set -g EFI_PATH '\EFI\Linux'
set -g SNAPPER_CONFIG "root"
set -g SNAPSHOT_SUBVOL "@snapshots"
set -g ROOT_SUBVOL "@"
@ -29,7 +30,7 @@ function load_config -d "loads the config from a config file" -a cfg
set -l cfg (jq -c <$cfg)
# parse config
set -l cfgs "build_path" "efi_dir" "kernel_cmd" "fallback_cmd" "snapper_config" "snapshot_subvol" "root_subvol"
set -l cfgs "build_path" "efi_dir" "efi_dev" "efi_part" "efi_path" "kernel_cmd" "fallback_cmd" "snapper_config" "snapshot_subvol" "root_subvol"
for c in $cfgs
echo $cfg | jq -e ".$c" >/dev/null
@ -42,7 +43,7 @@ function load_config -d "loads the config from a config file" -a cfg
end
# check for mandatory options
set -l mandatory_cfgs "kernel_cmd" "fallback_cmd"
set -l mandatory_cfgs "kernel_cmd" "fallback_cmd" "efi_dev" "efi_part"
for mc in $mandatory_cfgs
set -gq (echo $mc | sed "s/./\U&/g")
@ -64,8 +65,8 @@ function create_uki -d "creates a new uki"
# os-release
cp /usr/lib/os-release "$bp/os-release"
sed "s/BUILD_ID=.*/BUILD_ID=fallback/" </usr/lib/os-release >"$bp/os-release-fallback"
sed "s/BUILD_ID=.*/BUILD_ID=\"snapshot $SNAPSHOT_ID\"/" </usr/lib/os-release >"$bp/os-release-snapshot"
sed "s/BUILD_ID=.*/BUILD_ID=fallback/" </usr/lib/os-release | sed "s/PRETTY_NAME=\"\(.*\)\"/PRETTY_NAME=\"\1 (Fallback)\"" >"$bp/os-release-fallback"
sed "s/BUILD_ID=.*/BUILD_ID=\"snapshot $SNAPSHOT_ID\"/" </usr/lib/os-release | sed "s/PRETTY_NAME=\"\(.*\)\"/PRETTY_NAME=\"\1 (Snapshot $SNAPSHOT_ID)\"" >"$bp/os-release-snapshot"
# kernel cmd
echo $KERNEL_CMD | sed "s/SNAPSHOT/$ROOT_SUBVOL/" >"$bp/kernel-cmd"
@ -96,12 +97,17 @@ function create_uki -d "creates a new uki"
"/usr/lib/systemd/boot/efi/linuxx64.efi.stub" "$bp/arch-linux-$SNAPSHOT_ID.efi"
end
function add_efi_entry -d "adds a boot entry to efi"
efibootmgr -C -d $EFI_DEV -p $EFI_PART -l "$EFI_PATH\arch-linux-$SNAPSHOT_ID.efi" -L (rg "PRETTY_NAME" "$BUILD_PATH/$SNAPSHOT_ID/os-release-snapshot" | sed "s/PRETTY_NAME=\"\(.*\)\"/\1/")
end
function main -d "the main function"
checkdeps
load_config "/etc/snap-pac-uki.json"
get_last_snapshot
create_uki
add_efi_entry
cp $BUILD_PATH/$SNAPSHOT_ID/*.efi "$EFI_DIR"