void-minecraft-usb/kernel.d/pre-install/99-void-usb

25 lines
870 B
Bash

#!/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