From 1c4715ade0f203a1cea12d38c558055f4c775ce7 Mon Sep 17 00:00:00 2001 From: masq Date: Mon, 4 Nov 2024 11:30:01 +0100 Subject: [PATCH] [arch_post_update_update_boot] use variables present in profile to set boot path --- arch_post_update_update_boot.sh | 60 ++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/arch_post_update_update_boot.sh b/arch_post_update_update_boot.sh index 5924cbb..014a0b0 100755 --- a/arch_post_update_update_boot.sh +++ b/arch_post_update_update_boot.sh @@ -1,30 +1,64 @@ #!/bin/sh -set -xe -AURA_BIN=/usr/bin/aura -CURRENT_VERSION=`${AURA_BIN} -Qi linux | sed -n '/^Version *:/p' | grep -o '[^ ]*$'` -BOOT_BLK=/dev/vg0/boot +# arch_post_update_update_boot.sh +# +# In your /etc/profile, export the following variables +# LVM_VG_BOOT=vg0 +# LVM_LG_BOOT_NAME=boot +# BOOT_DIR_SUFFIX=/archlinux +# +# Optional variables: +# PACMAN_BIN=/usr/bin/pacman # Alternative pacman binary (eg: aura) +# BOOT_SYMLINK=current (in good boot dir) + +set -e + +source /etc/profile + +ask_overwrite() { + echo "Existing destination folder ($ARCH_BOOT_DST_CURRENT_VERSION), do you want to overwrite? (y/n)"; + read OVERWRITE; + test "$OVERWRITE" = "y" && return + echo "Do not overwrite. Exitting gently..." + exit 0; +} + +PACMAN_BIN=${PACMAN_BIN:-/usr/bin/pacman} +BOOT_SYMLINK=${BOOT_SYMLINK:-current} + +CURRENT_VERSION=`${PACMAN_BIN} -Qi linux \ + | sed -n '/^Version *:/p' \ + | grep -o '[^ ]*$'` +BOOT_BLK=/dev/$LVM_VG_BOOT/$LVM_LG_BOOT_NAME BOOT_ORIG=/boot -BOOT_DST=/mnt/boot -ARCH_BOOT_DST=$BOOT_DST/archlinux +TMP_BOOT_DST=`mktemp -d` + +ARCH_BOOT_DST=$TMP_BOOT_DST/$BOOT_DIR_SUFFIX ARCH_BOOT_DST_CURRENT_VERSION=$ARCH_BOOT_DST/$CURRENT_VERSION ARCH_INITRAMFS=initramfs-linux.img ARCH_INITRAMFS_FALLBACK=initramfs-linux-fallback.img ARCH_VMLINUZ=vmlinuz-linux -mount $BOOT_BLK $BOOT_DST; -test -d $ARCH_BOOT_DST_CURRENT_VERSION && echo "Linux version already up to date ($CURRENT_VERSION)" && exit 0; +mount $BOOT_BLK $TMP_BOOT_DST; +test -d $ARCH_BOOT_DST_CURRENT_VERSION \ + && test `realpath $ARCH_BOOT_DST/$BOOT_SYMLINK` = $ARCH_BOOT_DST_CURRENT_VERSION \ + && echo "Linux version already up to date ($CURRENT_VERSION)" && exit 0; -mkdir $ARCH_BOOT_DST_CURRENT_VERSION; +mkdir $ARCH_BOOT_DST_CURRENT_VERSION || ask_overwrite; ( -cd $BOOT_ORIG; -cp -t $ARCH_BOOT_DST_CURRENT_VERSION $ARCH_INITRAMFS $ARCH_INITRAMFS_FALLBACK $ARCH_VMLINUZ; + cd $BOOT_ORIG; + # Copy the new kernel files to the real destination in boot fs + cp -t $ARCH_BOOT_DST_CURRENT_VERSION $ARCH_INITRAMFS $ARCH_INITRAMFS_FALLBACK $ARCH_VMLINUZ; ) ( -cd $ARCH_BOOT_DST; -rm current && ln -s $CURRENT_VERSION current; + cd $ARCH_BOOT_DST; + # Re-link the good version + test -f $BOOT_SYMLINK && rm $BOOT_SYMLINK; + ln -s $CURRENT_VERSION current; ) + echo "Linux version updated to $CURRENT_VERSION" +umount $TMP_BOOT_DST; exit 0;