61 lines
1.6 KiB
Bash
Executable File
61 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
##########################
|
|
# ProxMox update tools #
|
|
# Update one CT/VM #
|
|
# @author: Bram Prieshof #
|
|
##########################
|
|
|
|
#Load functions
|
|
source $(dirname $0)/functions.sh
|
|
|
|
#InputChecks
|
|
## Check if exists
|
|
if [ -z ${1+x} ]; then echo "No input, usage: $0 <CT/VM-ID>"; exit; fi
|
|
## Check if valid (number/integer)
|
|
if [ -z "${1##*[!0-9]*}" ]; then echo "Invalid ID, usage: $0 <CT/VM-ID>"; exit; fi
|
|
|
|
#Setup Vars, since a seemingly valid id is given
|
|
ID=$1
|
|
VMS=$(qm list | tail -n+2 | awk '{print $1}')
|
|
CTS=$(pct list | tail -n+2 | awk '{print $1}')
|
|
ALLIDS=(${CTS[@]} ${VMS[@]})
|
|
|
|
## Check if ID exists
|
|
for ExistingID in "${ALLIDS[@]}"; do
|
|
if [ $ExistingID -eq $ID ]; then
|
|
IdExists=true
|
|
break
|
|
fi
|
|
IdExists=false
|
|
done
|
|
if ! $IdExists; then echo "This ID does not exist"; exit; fi
|
|
|
|
#Check type of ID
|
|
if [[ $VMS =~ $ID ]]; then TYPE=VM; fi
|
|
if [[ $CTS =~ $ID ]]; then TYPE=CT; fi
|
|
|
|
check#Check if VM/CT is running
|
|
if ! $($TYPE-State $ID); then echo "This ID is not runnig"; exit; fi
|
|
|
|
#Ask what should be updated
|
|
while true; do
|
|
read -p "Wich software should be updated (P)ackages, (A)pplications or (B)oth? " sofq
|
|
case $sofq in
|
|
[Pp]* )
|
|
#Update system packages
|
|
$TYPE-UpdatePackages $ID
|
|
break;;
|
|
[Aa]* )
|
|
#Update applications
|
|
$TYPE-UpdateApplicatons $ID
|
|
break;;
|
|
[Bb]* )
|
|
#Update both
|
|
$TYPE-UpdatePackages $ID
|
|
$TYPE-UpdateApplicatons $ID
|
|
break;;
|
|
* ) echo "Please answer with (P)ackages, (A)pplications or (B)oth.";;
|
|
esac
|
|
done
|