#!/bin/sh # 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 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 $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 || ask_overwrite; ( 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; # 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;