6 Commits

Author SHA1 Message Date
Jordan 9c0d9ea980 Update pvekclean.sh 2023-11-12 17:07:25 +01:00
Jordan 386dcbe95a Update pvekclean.sh 2023-11-12 15:34:24 +01:00
Jordan 6513d748f8 Update pvekclean.sh 2023-11-12 15:31:25 +01:00
Jordan 911bb07097 Update version.txt 2023-11-12 14:53:53 +01:00
Jordan ef8dd187dd Update README.md 2023-11-12 14:40:26 +01:00
Jordan a9c74c22f4 Update README.md 2023-11-12 14:38:28 +01:00
2 changed files with 17 additions and 3 deletions
+2 -1
View File
@@ -2,9 +2,10 @@
Easily remove old/unused PVE kernels on your Proxmox VE system Easily remove old/unused PVE kernels on your Proxmox VE system
[![Version](https://img.shields.io/badge/Version-v1.0-brightgreen)](https://github.com/jordanhillis/pvekclean) [![Version](https://img.shields.io/badge/Version-v1.3-brightgreen)](https://github.com/jordanhillis/pvekclean)
[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
![Updated](https://img.shields.io/github/last-commit/jordanhillis/pvekclean) ![Updated](https://img.shields.io/github/last-commit/jordanhillis/pvekclean)
![Proxmox](https://img.shields.io/badge/-Proxmox-orange)
![Debian](https://img.shields.io/badge/-Debian-red) ![Debian](https://img.shields.io/badge/-Debian-red)
### What is PVE Kernel Cleaner? ### What is PVE Kernel Cleaner?
+15 -2
View File
@@ -317,6 +317,7 @@ pve_kernel_clean() {
# Display percentage used and available space left # Display percentage used and available space left
printf "at ${boot_info[4]}%% capacity (${boot_info[3]} free)\n" printf "at ${boot_info[4]}%% capacity (${boot_info[3]} free)\n"
# For each kernel that was found via dpkg # For each kernel that was found via dpkg
current_kernel_passed=false
for kernel in $kernels for kernel in $kernels
do do
# Only if not removing newer kernels and kernel matches the current kernel # Only if not removing newer kernels and kernel matches the current kernel
@@ -324,6 +325,7 @@ pve_kernel_clean() {
if [ "$remove_newer" == "false" ]; then if [ "$remove_newer" == "false" ]; then
break break
else else
current_kernel_passed=true
continue continue
fi fi
# Add kernel to the list of removal since it is old # Add kernel to the list of removal since it is old
@@ -331,6 +333,10 @@ pve_kernel_clean() {
kernels_to_remove+=("$kernel") # Add the kernel to the array kernels_to_remove+=("$kernel") # Add the kernel to the array
fi fi
done done
# If remove_newer is set keep the last kernel installed as its newest
if [ "$remove_newer" == "true" ] && [ "$current_kernel_passed" == "true" ] && [ ${#kernels_to_remove[@]} -gt 0 ]; then
unset kernels_to_remove[-1]
fi
# If keep_kernels is set we remove this number from the array to remove # If keep_kernels is set we remove this number from the array to remove
if [[ -n "$keep_kernels" ]] && [[ "$keep_kernels" =~ ^[0-9]+$ ]]; then if [[ -n "$keep_kernels" ]] && [[ "$keep_kernels" =~ ^[0-9]+$ ]]; then
if [ $keep_kernels -gt 0 ]; then if [ $keep_kernels -gt 0 ]; then
@@ -383,6 +389,8 @@ pve_kernel_clean() {
/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
/usr/bin/apt purge -y proxmox-kernel-${kernel%-pve} > /dev/null 2>&1 /usr/bin/apt purge -y proxmox-kernel-${kernel%-pve} > /dev/null 2>&1
/usr/bin/apt purge -y pve-headers-${kernel%-pve} > /dev/null 2>&1
/usr/bin/apt purge -y proxmox-headers-${kernel%-pve} > /dev/null 2>&1
fi fi
sleep 1 sleep 1
printf "DONE!\n" printf "DONE!\n"
@@ -407,14 +415,19 @@ pve_kernel_clean() {
# Function to check for updates # Function to check for updates
check_for_update() { check_for_update() {
if [ "$check_for_updates" == "true" ] && [ "$force_purge" == "false" ]; then if [ "$check_for_updates" == "true" ] && [ "$force_purge" == "false" ]; then
local remote_version=$(curl -s https://raw.githubusercontent.com/jordanhillis/pvekclean/master/version.txt) local remote_version=$(curl -s -m 10 https://raw.githubusercontent.com/jordanhillis/pvekclean/master/version.txt || echo "")
# Unable to fetch remote version, so just skip the update check
if [ -z "$remote_version" ]; then
printf "${bold}[*]${reset} Failed to check for updates. Skipping update check.\n"
return
fi
if [ "$remote_version" != "$version" ]; then if [ "$remote_version" != "$version" ]; then
printf "*** A new version $remote_version is available! ***\n" printf "*** A new version $remote_version is available! ***\n"
printf "${bold}[*]${reset} Do you want to update? [y/N] " printf "${bold}[*]${reset} Do you want to update? [y/N] "
read -n 1 -r read -n 1 -r
printf "\n" printf "\n"
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
local updated_script=$(curl -s https://raw.githubusercontent.com/jordanhillis/pvekclean/master/pvekclean.sh) local updated_script=$(curl -s -m 10 https://raw.githubusercontent.com/jordanhillis/pvekclean/master/pvekclean.sh)
# Check if the updated script contains the shebang line # Check if the updated script contains the shebang line
if [[ "$updated_script" == "#!/bin/bash"* ]]; then if [[ "$updated_script" == "#!/bin/bash"* ]]; then
echo "$updated_script" > "$0" # Overwrite the current script echo "$updated_script" > "$0" # Overwrite the current script