2023-02-07 17:15:22 +00:00
#!/usr/bin/env bash
# Copyright (c) 2021-2023 tteck
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
2023-01-10 16:08:36 +00:00
function header_info {
2023-09-13 12:50:10 +00:00
clear
cat <<"EOF"
__ __ __ ________
2023-05-16 07:10:49 +00:00
/ //_/__ _________ ___ / / / ____/ /__ ____ _____
2023-01-10 16:08:36 +00:00
/ ,< / _ \/ ___/ __ \/ _ \/ / / / / / _ \/ __ ` / __ \
/ /| / __/ / / / / / __/ / / /___/ / __/ /_/ / / / /
2023-05-16 07:10:49 +00:00
/_/ | _\_ __/_/ /_/ /_/\_ __/_/ \_ ___/_/\_ __/\_ _,_/_/ /_/
2023-01-10 16:08:36 +00:00
EOF
}
2022-10-30 01:04:45 +00:00
YW = $( echo "\033[33m" )
RD = $( echo "\033[01;31m" )
GN = $( echo "\033[1;92m" )
CL = $( echo "\033[m" )
2022-04-23 15:17:44 +00:00
BFR = "\\r\\033[K"
HOLD = "-"
CM = " ${ GN } ✓ ${ CL } "
current_kernel = $( uname -r)
2023-09-13 12:50:10 +00:00
available_kernels = $( dpkg --list | grep 'kernel-.*-pve' | awk '{print $2}' | grep -v " $current_kernel " | sort -V)
2023-01-10 16:08:36 +00:00
header_info
2023-09-13 12:50:10 +00:00
2022-04-23 15:17:44 +00:00
function msg_info( ) {
2023-09-13 12:50:10 +00:00
local msg = " $1 "
echo -ne " ${ HOLD } ${ YW } ${ msg } ... "
2022-04-23 15:17:44 +00:00
}
function msg_ok( ) {
2023-09-13 12:50:10 +00:00
local msg = " $1 "
echo -e " ${ BFR } ${ CM } ${ GN } ${ msg } ${ CL } "
2022-04-23 15:17:44 +00:00
}
2023-09-13 12:50:10 +00:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Proxmox VE Kernel Clean" --yesno "This will Clean Unused Kernel Images, USE AT YOUR OWN RISK. Proceed?" 10 68 || exit
if [ -z " $available_kernels " ] ; then
2023-09-13 13:38:12 +00:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Old Kernels" --msgbox " It appears there are no old Kernels on your system. \nCurrent kernel ( $current_kernel ). " 10 68
2023-10-08 19:08:30 +00:00
echo "Exiting..."
2023-09-13 12:50:10 +00:00
sleep 2
2023-10-08 19:08:30 +00:00
clear
2023-09-13 12:50:10 +00:00
exit
fi
2023-10-08 19:08:30 +00:00
KERNEL_MENU = ( )
MSG_MAX_LENGTH = 0
2023-09-13 12:50:10 +00:00
while read -r TAG ITEM; do
OFFSET = 2
( ( ${# ITEM } + OFFSET > MSG_MAX_LENGTH) ) && MSG_MAX_LENGTH = ${# ITEM } +OFFSET
2023-10-08 19:08:30 +00:00
KERNEL_MENU += ( " $TAG " " $ITEM " "OFF" )
2023-09-13 12:50:10 +00:00
done < <( echo " $available_kernels " )
2022-04-23 15:17:44 +00:00
2023-10-08 19:08:30 +00:00
remove_kernels = $( whiptail --backtitle "Proxmox VE Helper Scripts" --title " Current Kernel $current_kernel " --checklist "\nSelect Kernels to remove:\n" 16 $(( MSG_MAX_LENGTH + 58 )) 6 " ${ KERNEL_MENU [@] } " 3>& 1 1>& 2 2>& 3 | tr -d '"' ) || exit
[ -z " $remove_kernels " ] && {
whiptail --backtitle "Proxmox VE Helper Scripts" --title "No Kernel Selected" --msgbox "It appears that no Kernel was selected" 10 68
echo "Exiting..."
sleep 2
clear
exit
}
2023-09-20 09:27:06 +00:00
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Remove Kernels" --yesno " Would you like to remove the $( echo $remove_kernels | awk '{print NF}' ) previously selected Kernels? " 10 68 || exit
2023-09-13 12:50:10 +00:00
msg_info " Removing ${ CL } ${ RD } $( echo $remove_kernels | awk '{print NF}' ) ${ CL } ${ YW } old Kernels ${ CL } "
/usr/bin/apt purge -y $remove_kernels >/dev/null 2>& 1
msg_ok "Successfully Removed Kernels"
2022-09-10 01:03:20 +00:00
2023-09-13 12:50:10 +00:00
msg_info "Updating GRUB"
/usr/sbin/update-grub >/dev/null 2>& 1
msg_ok "Successfully Updated GRUB"
msg_info "Exiting"
sleep 2
2023-10-08 19:08:30 +00:00
msg_ok "Finished"