add kernel hooks

master
BodgeMaster 2023-06-21 07:07:13 +02:00
parent d24327a69e
commit 0d56e70688
4 changed files with 103 additions and 1 deletions

View File

@ -283,7 +283,16 @@ chmod 755 /mnt/target/opt/void-usb
wget --output-document=/mnt/target/opt/void-usb/grub-config https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master/opt/grub-config wget --output-document=/mnt/target/opt/void-usb/grub-config https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master/opt/grub-config
chmod 744 /mnt/target/opt/void-usb/grub-config chmod 744 /mnt/target/opt/void-usb/grub-config
run_in_target /opt/void-usb/grub-config #TODO: ensure that this is being run by xbps-reconfigure -fa, if not add it here
# run_in_target /opt/void-usb/grub-config
wget --output-document=/mnt/target/etc/kernel.d/pre-install/99-void-usb https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master/kernel.d/pre-install/99-void-usb
chmod 744 /mnt/target/kernel.d/pre-install/99-void-usb
wget --output-document=/mnt/target/etc/kernel.d/post-install/99-void-usb https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master/kernel.d/post-install/99-void-usb
chmod 744 /mnt/target/kernel.d/post-install/99-void-usb
wget --output-document=/mnt/target/etc/kernel.d/post-remove/99-void-usb https://lostcave.ddnss.de/git/BodgeMaster/void-minecraft-usb/raw/branch/master/kernel.d/post-remove/99-void-usb
chmod 744 /mnt/target/kernel.d/post-remove/99-void-usb
run_in_target xbps-reconfigure -fa
# #

View File

@ -0,0 +1,59 @@
#!/usr/bin/env bash
#
# Kernel post-install hook for Void-USB
# This script generates the symlinks for default /boot/{vmlinuz,initramfs}.
# It also re-generates the GRUB config.
#
# Arguments: $1 package name, $2 kernel version
PKGNAME="$1"
VERSION="$2"
echo "Updating default kernel and initramfs symlinks..."
#####################
# Delete old symlinks
#####################
OLD_LINUX=/boot/vmlinu?
if [ ! -f "$OLD_LINUX" ]; then
# in cases where its a .gz or .xz or whatever
OLD_LINUX=$(find /boot -type l -name "vmlinu*" 2>/dev/null | sort | head -n1)
fi
[ -f "$OLD_LINUX" ] && rm "$OLD_LINUX"
OLD_INITRAMFS=/boot/initramfs.img
if [ ! -f "$OLD_INITRAMFS" ]; then
# hope to find anything named initramfs or initrd
OLD_INITRAMFS=$(find /boot -type l -name "init*" 2>/dev/null | sort | head -n1)
fi
[ -f "$OLD_INITRAMFS" ] && rm "$OLD_INITRAMFS"
#####################
# Create new symlinks
#####################
NEW_LINUX_FILE="$(find /boot -name "*$VERSION*" 2>/dev/null | sed 's|^/boot/||' | grep -e '^vmlinu' -e '^linux' -e '^linuz' -e '^kernel')"
NEW_LINUX_SYMLINK="vmlinuz"
if grep -e '^vmlinux' -e '^linux' -e '^kernel' >/dev/null 2>&1 <<< "$NEW_LINUX_FILE"; then
NEW_LINUX_SYMLINK="vmlinux"
fi
if grep -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" >/dev/null 2>&1 <<< "$NEW_LINUX_FILE"; then
NEW_LINUX_SYMLINK="$NEW_LINUX_SYMLINK$(grep -o -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" 2>/dev/null <<< "$NEW_LINUX_FILE")"
fi
ln -s "$NEW_LINUX_FILE" "/boot/$NEW_LINUX_SYMLINK"
NEW_INITRAMFS_FILE="$(find /boot -name "init*$VERSION*" 2>/dev/null | sed 's|^/boot/||')"
NEW_INITRAMFS_SYMLINK="initramfs"
if grep '^initrd' >/dev/null 2>&1 <<< "$NEW_INITRAMFS_FILE"; then
NEW_INITRAMFS_SYMLINK="initrd"
fi
if grep -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" >/dev/null 2>&1 <<< "$NEW_INITRAMFS_FILE"; then
NEW_INITRAMFS_SYMLINK="$NEW_INITRAMFS_SYMLINK$(grep -o -e ".gz$" -e ".xz$" -e ".bz$" -e ".bz2$" -e ".lzma$" -e ".lz$" -e ".img$" 2>/dev/null <<< "$NEW_INITRAMFS_FILE")"
fi
ln -s "$NEW_INITRAMFS_FILE" "/boot/$NEW_INITRAMFS_SYMLINK"
echo "Default kernel and initramfs are now: $NEW_LINUX_FILE, $NEW_INITRAMFS_FILE"
####################
# Update GRUB config
####################
/opt/void-usb/grub-config

View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
#
# Kernel post-remove hook for Void-USB
# This script regenerates the GRUB config.
#
# Arguments: $1 package name, $2 kernel version
PKGNAME="$1"
VERSION="$2"
/opt/void-usb/grub-config

View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Kernel pre-install hook for Void-USB
# This script removes old kernels when disk space is low.
#
# Arguments: $1 package name, $2 kernel version
PKGNAME="$1"
VERSION="$2"
MB_LOW=250
MB_FREE="$(df --block-size=1M --output=avail /boot | tail -n1)"
if [ "$MB_FREE" -lt "$MB_LOW" ]; then
echo
OLDEST_KERNEL="$(vkpurge list | sort | head -n1)"
if [ -z "$OLDEST_KERNEL" ]; then
echo -e "\033[31m================================================\n\033[33mWARNING:\033[0m Failed to find an old kernel to remove.\nThe /boot partition is running out of space.\nThis will become an issue if left unaddressed.\n\033[31m================================================\033[0m"
else
echo "Removing old kernel $OLDEST_KERNEL using vkpurge..."
vkpurge rm "$OLDEST_KERNEL"
fi
else
echo "Not doing anything, /boot has plenty of space."
fi