mirror of
https://github.com/jordanhillis/pvekclean.git
synced 2026-06-20 18:29:22 +02:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c0d9ea980 | |||
| 386dcbe95a | |||
| 6513d748f8 | |||
| 911bb07097 | |||
| ef8dd187dd | |||
| a9c74c22f4 |
@@ -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
|
||||||
|
|
||||||
[](https://github.com/jordanhillis/pvekclean)
|
[](https://github.com/jordanhillis/pvekclean)
|
||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||

|

|
||||||
|

|
||||||

|

|
||||||
|
|
||||||
### What is PVE Kernel Cleaner?
|
### What is PVE Kernel Cleaner?
|
||||||
|
|||||||
+15
-2
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user