Files
ProxmoxHelper/UpdateOne.sh

75 lines
1.8 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
#Determine id type
for ArrayID in "${CTS[@]}"; do
if [ $ArrayID -eq $ID ]; then
TYPE=CT
break
fi
done
for ArrayID in "${VMS[@]}"; do
if [ ! -z ${TYPE+x} ]; then break; fi
if [ $ArrayID -eq $ID ]; then
TYPE=VM
break
fi
done
if [ -z ${TYPE+x} ]; then echo "The ID Type chould not be determind"; exit; fi
#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