100 lines
2.8 KiB
Bash
Executable File
100 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#########################################
|
|
# ProxMox update tools #
|
|
# Upgrade OS release on all CT`s/VM`s #
|
|
# @author: Bram Prieshof #
|
|
#########################################
|
|
|
|
#Dirs
|
|
WorkDir=$(dirname $0)
|
|
LogDir=$WorkDir/RelUpgradelogs
|
|
#Load functions
|
|
source $WorkDir/functions.sh
|
|
#Create Log folder
|
|
if [ ! -d $LogDir ]; then
|
|
mkdir $LogDir
|
|
fi
|
|
|
|
#ID list of excluded VM/CT's
|
|
ExcludeList=()
|
|
|
|
#Get what sould be updated
|
|
UpdateVM=true
|
|
UpdateCT=true
|
|
|
|
while true; do
|
|
read -p "Wich software should be updated (D)Debian, (A)Alpine or (B)oth? " sofq
|
|
case $sofq in
|
|
[Dd]* )
|
|
DoDebianReleaseUpdate=true
|
|
DoAlpineReleaseUpdate=false
|
|
break;;
|
|
[Aa]* )
|
|
DoDebianReleaseUpdate=true
|
|
DoAlpineReleaseUpdate=true
|
|
break;;
|
|
[Bb]* )
|
|
DoDebianReleaseUpdate=true
|
|
DoAlpineReleaseUpdate=true
|
|
break;;
|
|
* ) echo "Please answer with (D)Debian, (A)Alpine or (B)oth.";;
|
|
esac
|
|
done
|
|
|
|
#Get required versions to upgrade to
|
|
if $DoDebianReleaseUpdate; then
|
|
echo "Enter the Debian version to upgrade to"
|
|
read NewDebianVersion
|
|
while true; do
|
|
read -p "Upgrade to Debian $NewDebianVersion, is this correct? -> yes/no?" yn
|
|
case $yn in
|
|
[Nn]* )
|
|
echo "Enter the Debian version to upgrade to"
|
|
read NewDebianVersion
|
|
;;
|
|
[Yy]* ) break;;
|
|
* ) echo "Choose yes or no.";;
|
|
esac
|
|
done
|
|
fi
|
|
if $DoAlpineReleaseUpdate; then
|
|
echo "Enter the Alpine version to upgrade to"
|
|
read NewAlpineVersion
|
|
while true; do
|
|
read -p "Upgrade to Alpine $NewAlpineVersion, is this correct? -> yes/no?" yn
|
|
case $yn in
|
|
[Nn]* )
|
|
echo "Enter the Alpine version to upgrade to"
|
|
read NewAlpineVersion
|
|
;;
|
|
[Yy]* ) break;;
|
|
* ) echo "Choose yes or no.";;
|
|
esac
|
|
done
|
|
fi
|
|
|
|
#CT updates
|
|
if $UpdateCT; then
|
|
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
|
|
#Skip CT if in ExcludeList
|
|
if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi
|
|
# Skip CT if not running
|
|
if ! $(CT-State $CTID); then echo "Notice: $CTID not running"; continue; fi
|
|
#DEBUG echo "Task for $CTID"
|
|
CT-UpgradeRelease $CTID | tee "$LogDir"/"$CTID"_Release.log
|
|
done
|
|
fi
|
|
|
|
#VM Updates
|
|
if $UpdateVM; then
|
|
for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do
|
|
#Skip VM if in ExcludeList
|
|
if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi
|
|
# Skip VM if not running
|
|
if ! $(VM-State $VMID); then echo "Notice: $VMID not running"; continue; fi
|
|
#DEBUG echo "Task for $VMID"
|
|
VM-UpgradeRelease $VMID | tee "$LogDir"/"$VMID"_Release.log
|
|
done
|
|
fi
|