Skip to content

Commit

Permalink
Uninstall or install unused kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
framps committed May 25, 2024
1 parent 110f69f commit 1d7145f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions raspi-config
Original file line number Diff line number Diff line change
Expand Up @@ -3244,6 +3244,50 @@ do_usb_current() {
}


do_kernels() {

DEFAULT=--defaultno

KERNELS_UNUSED_FILE="/boot/unusedKernels"
KERNELS_INITRD_GREP_REGEX="^initrd\.img.+-rpi+"
KERNELS_INITRD_DELETE_SED="s/^initrd\.img/linux-image/"

KERNELS_UNUSED="$(ls -1 /boot | grep -v "$(uname -r)" | grep -E "$KERNELS_INITRD_GREP_REGEX" | sed "$KERNELS_INITRD_DELETE_SED")"

if [ "$INTERACTIVE" = True ]; then

if [ -z "$KERNELS_UNUSED" ] && [ -e "$KERNELS_UNUSED_FILE" ]; then
whiptail --yesno \
"Would you like unused kernels to be reinstalled?" $DEFAULT 20 60 2
RET=$?
if [ $RET -eq 0 ]; then
apt -y install $(cat $KERNELS_UNUSED_FILE)
if [ $? -eq 0 ]; then
rm "$KERNELS_UNUSED_FILE"
else
whiptail --msgbox "Kernel reinstallation failed." 20 60 1
fi
fi
elif [ -n "$KERNELS_UNUSED" ]; then
whiptail --yesno \
"Would you like unused kernels to be uninstalled?" $DEFAULT 20 60 2
RET=$?
if [ $RET -eq 0 ]; then
echo "$KERNELS_UNUSED" > "$KERNELS_UNUSED_FILE"
apt -y remove $KERNELS_UNUSED
if [ $? -ne 0 ]; then
whiptail --msgbox "Kernel uninstallation failed." 20 60 1
fi
fi
else
whiptail --msgbox "No unused kernels found." 20 60 1
RET=1
fi
else
RET=$1
fi
}

nonint() {
"$@"
}
Expand Down Expand Up @@ -3456,14 +3500,17 @@ do_performance_menu() {
case "$(get_pi_type)" in
[03]) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"P2 Overlay File System" "Enable/disable read-only file system" \
"P5 Kernels" "Uninstall/install unused kernels" \
3>&1 1>&2 2>&3) ;;
[12]) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"P1 Overclock" "Configure CPU overclocking" \
"P2 Overlay File System" "Enable/disable read-only file system" \
"P5 Kernels" "Uninstall/install unused kernels" \
3>&1 1>&2 2>&3) ;;
4) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"P2 Overlay File System" "Enable/disable read-only file system" \
"P3 Fan" "Set behaviour of GPIO case fan" \
"P5 Kernels" "Uninstall/install unused kernels" \
3>&1 1>&2 2>&3) ;;
*) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \
"P2 Overlay File System" "Enable/disable read-only file system" \
Expand All @@ -3479,6 +3526,7 @@ do_performance_menu() {
P2\ *) do_overlayfs ;;
P3\ *) do_fan ;;
P4\ *) do_usb_current ;;
P5\ *) do_kernels ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
Expand Down

0 comments on commit 1d7145f

Please sign in to comment.