120 lines
3.7 KiB
Bash
120 lines
3.7 KiB
Bash
#!/bin/bash
|
|
|
|
##########################
|
|
# ProxMox update tools #
|
|
# FUNCTIONS #
|
|
# @author: Bram Prieshof #
|
|
##########################
|
|
|
|
#Update Packages and Applications on CT
|
|
#CT-UpdateBoth () {
|
|
# local CTID=$1
|
|
# echo "Updating Packages and Applications for $CTID"
|
|
# CT-UpdatePackages
|
|
# CT-UpdateApplicatons
|
|
#}
|
|
|
|
##Update Packages and Applications on VM
|
|
#VM-UpdateBoth () {
|
|
# local VMID=$1
|
|
# echo "Updating Packages and Applications for $VMID"
|
|
# VM-UpdatePackages
|
|
# VM-UpdateApplicatons
|
|
#}
|
|
|
|
#Updating Packages on CT
|
|
CT-UpdatePackages () {
|
|
#If not called by UpdateBoth then set $1 as CTID
|
|
if [ -z ${CTID+x} ]; then local CTID=$1;fi
|
|
echo "Updating Packages for $CTID"
|
|
#Getting distributionname
|
|
local DIST=$(pct exec $CTID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
|
|
local INSTCALL="pct exec $CTID"
|
|
#Call generic package updater
|
|
UpdatePackages
|
|
unset DIST INSTCALL
|
|
}
|
|
|
|
#Updating Packages on VM
|
|
VM-UpdatePackages () {
|
|
#If not called by UpdateBoth then set $1 as VMID
|
|
if [ -z ${VMID+x} ]; then local VMID=$1;fi
|
|
echo "Updating Packages for $VMID, No output is provided until task is completed"
|
|
#Getting distributionname
|
|
local DIST=$(qm guest exec $VMID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
|
|
local INSTCALL="qm guest exec $VMID"
|
|
#Call generic package updater
|
|
UpdatePackages
|
|
unset DIST INSTCALL
|
|
}
|
|
|
|
#Starts package manager, called by CT-UpdatePackages and VM-UpdatePackages
|
|
UpdatePackages () {
|
|
#Getting distributionname
|
|
if [[ "${DIST}" == *"ubuntu"* ]] || [[ "${DIST}" == *"debian"* ]]; then
|
|
$INSTCALL -- apt update
|
|
$INSTCALL -- apt upgrade -y
|
|
elif [[ "${DIST}" == *"alpine"* ]]; then
|
|
$INSTCALL -- apk update
|
|
$INSTCALL -- apk upgrade
|
|
elif [[ "${DIST}" == *"centos"* ]]; then
|
|
$INSTCALL -- dnf update -y
|
|
else
|
|
echo "Warning: Package manager in not supported"
|
|
#exit 100
|
|
fi
|
|
}
|
|
|
|
#Updating CT applications using /opt/ProxMoxToolKitAppUpdate.sh in CT
|
|
CT-UpdateApplicatons () {
|
|
#If not called by UpdateBoth then set $1 as CTID
|
|
if [ -z ${CTID+x} ]; then local CTID=$1;fi
|
|
#Test if CT has Applicatons update script
|
|
if pct exec $CTID -- test -f /opt/ProxMoxToolKitAppUpdate.sh ; then
|
|
echo "Updating Applications for $CTID"
|
|
pct exec $CTID -- sh /opt/ProxMoxToolKitAppUpdate.sh
|
|
else
|
|
echo "Warning: Application updates not enabled in $CTID"
|
|
#exit 102
|
|
fi
|
|
}
|
|
|
|
#Updating VM applications using /opt/ProxMoxToolKitAppUpdate.sh in VM
|
|
VM-UpdateApplicatons () {
|
|
#If not called by UpdateBoth then set $1 as VMID
|
|
if [ -z ${VMID+x} ]; then local VMID=$1;fi
|
|
#Test if VM has Applicatons update script
|
|
if [ $(qm guest exec $VMID -- test -f /opt/ProxMoxToolKitAppUpdate.sh |jq '.exitcode') == 0 ] ; then
|
|
echo "Updating Applications for $VMID, No output is provided until task is completed"
|
|
qm guest exec $VMID -- sh /opt/ProxMoxToolKitAppUpdate.sh
|
|
else
|
|
echo "Warning: application updates not enabled in $VMID"
|
|
#exit 102
|
|
fi
|
|
}
|
|
|
|
#Get state of CT as exitcode (0 when running 1 when stoped and 2 if CT is existend or other error occurs)
|
|
CT-State () {
|
|
if [ -z ${CTID+x} ]; then local CTID=$1;fi
|
|
case "$(pct status $CTID 2>&1)" in
|
|
*running* )
|
|
return 0;;
|
|
*stopped* )
|
|
return 1;;
|
|
* )
|
|
return 2;;
|
|
esac
|
|
}
|
|
|
|
#Get state of VM as exitcode (0 when running 1 when stoped and 2 if VM is existend or other error occurs)
|
|
VM-State (){
|
|
if [ -z ${VMID+x} ]; then local VMID=$1;fi
|
|
case "$(qm status $VMID 2>&1)" in
|
|
*running* )
|
|
return 0;;
|
|
*stopped* )
|
|
return 1;;
|
|
* )
|
|
return 2;;
|
|
esac
|
|
} |