Last active
January 22, 2023 10:15
-
-
Save coldfire7/f317c061a3b6a0ffa13b68d536f29d9b to your computer and use it in GitHub Desktop.
PROXMOX Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
YW=`echo "\033[33m"` | |
BL=`echo "\033[36m"` | |
RD=`echo "\033[01;31m"` | |
CM='\xE2\x9C\x94\033' | |
GN=`echo "\033[1;92m"` | |
CL=`echo "\033[m"` | |
while true; do | |
read -p "This will Clean unused Kernel images. Proceed(y/n)?" yn | |
case $yn in | |
[Yy]* ) break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
clear | |
current_kernel=$(uname -r) | |
function check_root { | |
if [[ $EUID -ne 0 ]]; then | |
printf "[!] Error: this script must be ran as the root user.\n" | |
exit 1 | |
fi | |
} | |
function header_info { | |
echo -e "${RD} | |
____ __. .__ _________ .__ | |
| |/ _|___________ ____ ____ | | \_ ___ \| | ____ _____ ____ __ ________ | |
| <_/ __ \_ __ \/ \_/ __ \| | / \ \/| | _/ __ \\__ \ / \| | \____ \ | |
| | \ ___/| | \/ | \ ___/| |__ \ \___| |_\ ___/ / __ \| | \ | / |_> > | |
|____|__ \___ >__| |___| /\___ >____/ \______ /____/\___ >____ /___| /____/| __/ | |
\/ \/ \/ \/ \/ \/ \/ \/ |__| | |
${CL}" | |
} | |
function kernel_info { | |
latest_kernel=$(dpkg --list| grep 'pve-kernel-.*-pve' | awk '{print $2}' | tac | head -n 1) | |
printf "OS: $(cat /etc/os-release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g' | sed 's/["]//g' | awk '{print $0}')\n" | |
printf "Current Kernel: pve-kernel-$current_kernel\n" | |
if [[ "$current_kernel" == *"pve"* ]]; then | |
if [[ "$latest_kernel" != *"$current_kernel"* ]]; then | |
printf "Latest Kernel: $latest_kernel\n" | |
fi | |
else | |
printf "___________________________________________\n\n" | |
printf "[!] Warning, you're not running a PVE Kernel\n" | |
exit 1 | |
fi | |
} | |
function kernel_clean { | |
kernels=$(dpkg --list| grep 'pve-kernel-.*-pve' | awk '{print $2}' | sort -V) | |
kernels_to_remove="" | |
for kernel in $kernels | |
do | |
if [ "$(echo $kernel | grep $current_kernel)" ]; then | |
break | |
else | |
printf "\"$kernel\" has been added to the Kernel remove list\n" | |
kernels_to_remove+=" $kernel" | |
fi | |
done | |
printf "Kernel Search Complete!\n" | |
if [[ "$kernels_to_remove" != *"pve"* ]]; then | |
printf "It appears there are no old Kernels on your system \n" | |
else | |
read -p "[!] Would you like to remove the $(echo $kernels_to_remove | awk '{print NF}') selected Kernels listed above? [y/n]: " -n 1 -r | |
printf "\n" | |
fi | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
printf "Removing $(echo $kernels_to_remove | awk '{print NF}') old Kernels..." | |
/usr/bin/apt purge -y $kernels_to_remove > /dev/null 2>&1 | |
printf "Finished!\n" | |
printf "Updating GRUB... \n" | |
/usr/sbin/update-grub > /dev/null 2>&1 | |
printf "Finished!\n" | |
else | |
printf "\nExiting...\n" | |
fi | |
} | |
function main { | |
check_root | |
header_info | |
kernel_info | |
} | |
while true; do | |
case "$1" in | |
* ) | |
main | |
kernel_clean | |
exit 1 | |
;; | |
esac | |
shift | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
YW=`echo "\033[33m"` | |
BL=`echo "\033[36m"` | |
RD=`echo "\033[01;31m"` | |
CM='\xE2\x9C\x94\033' | |
GN=`echo "\033[1;92m"` | |
CL=`echo "\033[m"` | |
while true; do | |
read -p "This Will Update All LXC Containers. Proceed(y/n)?" yn | |
case $yn in | |
[Yy]* ) break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
clear | |
function header_info { | |
echo -e "${BL} | |
____ ___ .___ __ .____ ____ ____________ | |
| | \______ __| _/____ _/ |_ ____ | | \ \/ /\_ ___ \ | |
| | /\____ \ / __ |\__ \\ __\/ __ \ | | \ / / \ \/ | |
| | / | |_> > /_/ | / __ \| | \ ___/ | |___ / \ \ \____ | |
|______/ | __/\____ |(____ /__| \___ > |_______ \/___/\ \ \______ / | |
|__| \/ \/ \/ \/ \_/ \/ | |
${CL}" | |
} | |
header_info | |
containers=$(pct list | tail -n +2 | cut -f1 -d' ') | |
function update_container() { | |
container=$1 | |
clear | |
header_info | |
echo -e "${BL}[Info]${GN} Updating${BL} $container ${CL} \n" | |
pct exec $container -- bash -c "apt update && apt upgrade -y && apt autopurge -y" | |
} | |
for container in $containers | |
do | |
status=`pct status $container` | |
if [ "$status" == "status: stopped" ]; then | |
echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n" | |
pct start $container | |
echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n" | |
sleep 5 | |
update_container $container | |
echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL} \n" | |
pct shutdown $container & | |
elif [ "$status" == "status: running" ]; then | |
update_container $container | |
fi | |
done; wait | |
echo -e "${GN} Finished, All Containers Updated. ${CL} \n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment