mirror of
https://github.com/jordanhillis/pvekclean.git
synced 2026-06-20 02:15:35 +02:00
Update pvekclean.sh
This commit is contained in:
+38
-30
@@ -36,8 +36,8 @@ boot_critical_percent="80"
|
|||||||
# To check for updates or not
|
# To check for updates or not
|
||||||
check_for_updates=true
|
check_for_updates=true
|
||||||
|
|
||||||
# Debug mode is for testing without actually removing anything
|
# Dry run mode is for testing without actually removing anything
|
||||||
debug=false
|
dry_run=false
|
||||||
|
|
||||||
# Current kernel
|
# Current kernel
|
||||||
current_kernel=$(uname -r)
|
current_kernel=$(uname -r)
|
||||||
@@ -110,8 +110,8 @@ echo -e " ${bg_black}${orange} ${re
|
|||||||
${bg_orange}${black} ${bold}By Jordan Hillis [jordan@hillis.email] ${reset}
|
${bg_orange}${black} ${bold}By Jordan Hillis [jordan@hillis.email] ${reset}
|
||||||
___________________________________________
|
___________________________________________
|
||||||
"
|
"
|
||||||
if [ "$debug" == "true" ]; then
|
if [ "$dry_run" == "true" ]; then
|
||||||
printf " ${bg_black}${orange}${bold} DEBUG MODE IS ${green}ON ${reset}\n\n"
|
printf " ${bg_black}${orange}${bold} DRY RUN MODE IS ${green}ON ${reset}\n\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ show_usage() {
|
|||||||
printf " -s, --scheduler Have old PVE kernels removed on a scheduled basis\n"
|
printf " -s, --scheduler Have old PVE kernels removed on a scheduled basis\n"
|
||||||
printf " -v, --version Shows current version of $program_name\n"
|
printf " -v, --version Shows current version of $program_name\n"
|
||||||
printf " -r, --remove Uninstall $program_name from the system\n"
|
printf " -r, --remove Uninstall $program_name from the system\n"
|
||||||
printf " -d, --debug Run the program in debug mode for testing without making system changes\n"
|
printf " -d, --dry-run Run the program in dry run mode for testing without making system changes\n"
|
||||||
printf "___________________________________________\n\n"
|
printf "___________________________________________\n\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -239,6 +239,9 @@ scheduler() {
|
|||||||
# Installs PVE Kernel Cleaner for easier access
|
# Installs PVE Kernel Cleaner for easier access
|
||||||
install_program() {
|
install_program() {
|
||||||
force_pvekclean_update=false
|
force_pvekclean_update=false
|
||||||
|
local tmp_file="/tmp/.pvekclean_install_lock"
|
||||||
|
local install=false
|
||||||
|
local ask_interval=3600 # 1 hour in seconds
|
||||||
# If pvekclean exists on the system
|
# If pvekclean exists on the system
|
||||||
if [ -e /usr/local/sbin/$program_name ]; then
|
if [ -e /usr/local/sbin/$program_name ]; then
|
||||||
# Get current version of pvekclean
|
# Get current version of pvekclean
|
||||||
@@ -250,27 +253,32 @@ install_program() {
|
|||||||
force_pvekclean_update=true
|
force_pvekclean_update=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# If pvekclean does not exist on the system or force_purge is enabled
|
# Check if the file doesn't exist or it's been over an hour since the last ask
|
||||||
if [ ! -f /usr/local/sbin/$program_name ] || [ $force_pvekclean_update == true ]; then
|
if [ ! -e "$tmp_file" ] || [ ! -f "$tmp_file" ] || [ $(( $(date +%s) - $(cat "$tmp_file") )) -gt $ask_interval ] || [ $force_pvekclean_update == true ]; then
|
||||||
# Ask user if we can install it to their system
|
# If pvekclean does not exist on the system or force_purge is enabled
|
||||||
if [ $force_purge == true ]; then
|
if [ ! -f /usr/local/sbin/$program_name ] || [ $force_pvekclean_update == true ]; then
|
||||||
REPLY="n"
|
# Ask user if we can install it to their system
|
||||||
else
|
if [ $force_purge == true ]; then
|
||||||
# Ask if we can install it
|
REPLY="n"
|
||||||
printf "${bold}[-]${reset} Can we install PVE Kernel Cleaner to your /usr/local/sbin for easier access [y/N] "
|
else
|
||||||
read -n 1 -r
|
# Update the timestamp in the file to record the time of the last ask
|
||||||
printf "\n"
|
echo $(date +%s) > "$tmp_file"
|
||||||
fi
|
# Ask if we can install it
|
||||||
# User agrees to have it installed
|
printf "${bold}[-]${reset} Can we install PVE Kernel Cleaner to your /usr/local/sbin for easier access [y/N] "
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
read -n 1 -r
|
||||||
# Copy the script to /usr/local/sbin and set execution permissions
|
printf "\n"
|
||||||
cp $0 /usr/local/sbin/$program_name
|
fi
|
||||||
chmod +x /usr/local/sbin/$program_name
|
# User agrees to have it installed
|
||||||
# Tell user how to use it
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
printf "${bold}[*]${reset} Installed PVE Kernel Cleaner to /usr/local/sbin/$program_name\n"
|
# Copy the script to /usr/local/sbin and set execution permissions
|
||||||
printf "${bold}[*]${reset} Run the command \"$program_name\" to begin using this program.\n"
|
cp $0 /usr/local/sbin/$program_name
|
||||||
printf "${bold}[-]${reset} Run the command \"$program_name -r\" to remove this program at any time.\n"
|
chmod +x /usr/local/sbin/$program_name
|
||||||
exit 0
|
# Tell user how to use it
|
||||||
|
printf "${bold}[*]${reset} Installed PVE Kernel Cleaner to /usr/local/sbin/$program_name\n"
|
||||||
|
printf "${bold}[*]${reset} Run the command \"$program_name\" to begin using this program.\n"
|
||||||
|
printf "${bold}[-]${reset} Run the command \"$program_name -r\" to remove this program at any time.\n"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -384,7 +392,7 @@ pve_kernel_clean() {
|
|||||||
do
|
do
|
||||||
printf "${bold}[-]${reset} Removing kernel: $kernel..."
|
printf "${bold}[-]${reset} Removing kernel: $kernel..."
|
||||||
# Purge the old kernels via apt and suppress output
|
# Purge the old kernels via apt and suppress output
|
||||||
if [ "$debug" != "true" ]; then
|
if [ "$dry_run" != "true" ]; then
|
||||||
/usr/bin/apt purge -y pve-kernel-$kernel > /dev/null 2>&1
|
/usr/bin/apt purge -y pve-kernel-$kernel > /dev/null 2>&1
|
||||||
/usr/bin/apt purge -y proxmox-kernel-$kernel > /dev/null 2>&1
|
/usr/bin/apt purge -y proxmox-kernel-$kernel > /dev/null 2>&1
|
||||||
/usr/bin/apt purge -y pve-kernel-${kernel%-pve} > /dev/null 2>&1
|
/usr/bin/apt purge -y pve-kernel-${kernel%-pve} > /dev/null 2>&1
|
||||||
@@ -397,7 +405,7 @@ pve_kernel_clean() {
|
|||||||
done
|
done
|
||||||
printf "${bold}[*]${reset} Updating GRUB..."
|
printf "${bold}[*]${reset} Updating GRUB..."
|
||||||
# Update grub after kernels are removed, suppress output
|
# Update grub after kernels are removed, suppress output
|
||||||
if [ "$debug" != "true" ]; then
|
if [ "$dry_run" != "true" ]; then
|
||||||
/usr/sbin/update-grub > /dev/null 2>&1
|
/usr/sbin/update-grub > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
printf "DONE!\n"
|
printf "DONE!\n"
|
||||||
@@ -502,8 +510,8 @@ while [[ $# -gt 0 ]]; do
|
|||||||
shift
|
shift
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
-d|--debug)
|
-d|--dry-run)
|
||||||
debug=true
|
dry_run=true
|
||||||
shift
|
shift
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user