97 lines
2.4 KiB
Bash
Executable File
97 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
##########################
|
|
# ProxMox update tools #
|
|
# Update all CT`s/VM`s #
|
|
# @author: Bram Prieshof #
|
|
##########################
|
|
|
|
#Dirs
|
|
WorkDir=$(dirname $0)
|
|
LogDir=$WorkDir/logs
|
|
#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 systems should be updated (A)ll, (C)T's only or (V)M's only? " sysq
|
|
# case $sysq in
|
|
# [Aa]* )
|
|
# UpdateVM=true
|
|
# UpdateCT=true
|
|
# break;;
|
|
# [Cc]* )
|
|
# UpdateVM=false
|
|
# UpdateCT=true
|
|
# break;;
|
|
# [Vv]* )
|
|
# UpdateVM=true
|
|
# UpdateCT=false
|
|
# break;;
|
|
# * ) echo "Please answer with (A)ll, (C)T's or (V)M's.";;
|
|
# esac
|
|
#done
|
|
|
|
while true; do
|
|
read -p "Wich software should be updated (P)ackages, (A)pplications or (B)oth? " sofq
|
|
case $sofq in
|
|
[Pp]* )
|
|
UpdatePKG=true
|
|
UpdateAPP=false
|
|
break;;
|
|
[Aa]* )
|
|
UpdatePKG=false
|
|
UpdateAPP=true
|
|
break;;
|
|
[Bb]* )
|
|
UpdatePKG=true
|
|
UpdateAPP=true
|
|
break;;
|
|
* ) echo "Please answer with (P)ackages, (A)pplications or (B)oth.";;
|
|
esac
|
|
done
|
|
|
|
#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"
|
|
if $UpdatePKG; then
|
|
CT-UpdatePackages $CTID | tee "$LogDir"/"$CTID"_Pkgs.log
|
|
fi
|
|
if $UpdateAPP; then
|
|
CT-UpdateApplicatons $CTID | tee "$LogDir"/"$CTID"_Apps.log
|
|
fi
|
|
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"
|
|
if $UpdatePKG; then
|
|
VM-UpdatePackages $VMID | tee "$LogDir"/"$VMID"_Pkgs.log
|
|
fi
|
|
if $UpdateAPP; then
|
|
VM-UpdateApplicatons $VMID | tee "$LogDir"/"$VMID"_Apps.log
|
|
fi
|
|
done
|
|
fi
|