Fixed releaseUpgrade scripts

Updated Debian upgrade commands to be beter suited for scirpts

Set command timeout to 0 for VM's

Fixed container reboots

Disabled Debian VM's upgrades - qemu-guest-agent quit while upgrading

Checking if ID is alive before asking its distro
This commit is contained in:
2023-11-19 20:10:04 +01:00
parent 2bc12f8ae2
commit 170757a749
3 changed files with 25 additions and 20 deletions

View File

@@ -31,7 +31,7 @@ while true; do
DoAlpineReleaseUpdate=false
break;;
[Aa]* )
DoDebianReleaseUpdate=true
DoDebianReleaseUpdate=false
DoAlpineReleaseUpdate=true
break;;
[Bb]* )
@@ -76,6 +76,7 @@ fi
#CT updates
if $UpdateCT; then
TYPE=CT;
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
@@ -88,6 +89,7 @@ fi
#VM Updates
if $UpdateVM; then
TYPE=VM;
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

View File

@@ -34,16 +34,17 @@ if ! $IdExists; then echo "This ID does not exist"; exit; fi
#Check type of ID
if [[ $VMS =~ $ID ]];then
TYPE=VM;
DIST=$(qm guest exec $VMID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
if ! $(VM-State $ID); then echo "This ID is not runnig"; exit; fi
DIST=$(qm guest exec $ID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
fi
if [[ $CTS =~ $ID ]]; then
TYPE=CT
DIST=$(pct exec $CTID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
#Check if CT is running
if ! $(CT-State $ID); then echo "This ID is not runnig"; exit; fi
#Get CT distro
DIST=$(pct exec $ID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
fi
#Check if VM/CT is running
if ! $($TYPE-State $ID); then echo "This ID is not runnig"; exit; fi
#Check wich distro the CT/VM is running
if [[ "${DIST}" == *"debian"* ]]; then
#Ask the wanted Debian version

View File

@@ -53,7 +53,7 @@ UpdatePackages () {
#Getting distributionname
if [[ "${DIST}" == *"ubuntu"* ]] || [[ "${DIST}" == *"debian"* ]]; then
$INSTCALL -- apt update
$INSTCALL -- apt upgrade -y
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confold"
elif [[ "${DIST}" == *"alpine"* ]]; then
$INSTCALL -- apk update
$INSTCALL -- apk upgrade
@@ -134,7 +134,7 @@ CT-UpgradeRelease () {
#Call generic release upgrader
UpgradeRelease
if $DOREBOOT; then
qm reboot $VMID
pct reboot $CTID
fi
unset DIST RELVERSION RELNAME INSTCALL DOREBOOT
}
@@ -146,9 +146,9 @@ VM-UpgradeRelease () {
echo "Upgrading release for $VMID, No output is provided until task is completed"
#Getting distribution info
local DIST=$(qm guest exec $VMID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
local RELVERSION=$(qm guest exec $VMID -- awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]' | cut -d"." -f 1,2 )
local RELNAME=$(qm guest exec $VMID -- awk -F= '$1=="VERSION_CODENAME" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
local INSTCALL="qm guest exec $VMID"
local RELVERSION=$(qm guest exec $VMID -- awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]' | sed 's#\\n##g' | tr -d '"' | cut -d"." -f 1,2 )
local RELNAME=$(qm guest exec $VMID -- awk -F= '$1=="VERSION_CODENAME" { print $2 ;}' /etc/os-release | jq '.["out-data"]' | sed 's#\\n##g' | tr -d '"')
local INSTCALL="qm guest exec $VMID --timeout 0"
local SNAPSHOTCMD="qm snapshot $VMID BeforeReleaseUpgrade --description"
local DOREBOOT=false
#Call generic release upgrader
@@ -162,37 +162,39 @@ VM-UpgradeRelease () {
#Run release update, called by CT-UpgradeRelease and VM-UpgradeRelease
UpgradeRelease () {
#Getting distribution name
if [[ "${DIST}" == *"debian"* ]] && $DoDebianReleaseUpdate; then
if [[ "${DIST}" == *"debian"* ]] && $DoDebianReleaseUpdate && [[ "${TYPE}" == "CT" ]]; then
if [ $RELNAME != $NewDebianVersion ]; then
#Create snapshot before upgrading
SNAPSHOTCMD "Before upgrade form Debian $RELNAME to Debian $NewDebianVersion"
$SNAPSHOTCMD "Before upgrade form Debian $RELNAME to Debian $NewDebianVersion"
#Fully update current version
$INSTCALL -- apt update
$INSTCALL -- apt upgrade -y
$INSTCALL -- apt full-upgrade -y
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confold"
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt full-upgrade -y -o Dpkg::Options::="--force-confold"
# Update repo file(s)
$INSTCALL -- sed -i "s/$RELNAME/$NewDebianVersion/g" /etc/apt/sources.list
$INSTCALL -- sed -i "s/$RELNAME/$NewDebianVersion/g" /etc/apt/sources.list.d/*
$INSTCALL -- sh -c "sed -i "s/$RELNAME/$NewDebianVersion/g" /etc/apt/sources.list.d/\*"
# Run upgrade to new release
$INSTCALL -- apt clean
$INSTCALL -- apt update
$INSTCALL -- apt upgrade -y
$INSTCALL -- apt full-upgrade -y
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confold"
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt full-upgrade -y -o Dpkg::Options::="--force-confold"
$INSTCALL -- apt autoremove -y
DOREBOOT=true
else
echo "Notice: Skiped, already up-to-date"
fi
elif [[ "${DIST}" == *"debian"* ]] && $DoDebianReleaseUpdate && [[ "${TYPE}" == "VM" ]]; then
echo "Notice: Release upgrade for Debian VM's is not supported"
elif [[ "${DIST}" == *"debian"* ]]; then
echo "Notice: Release upgrade disabled for Debian"
elif [[ "${DIST}" == *"alpine"* ]] && $DoAlpineReleaseUpdate ; then
if [ $RELVERSION != $NewAlpineVersion ]; then
#Create snapshot before upgrading
SNAPSHOTCMD "Before upgrade form Alpine $RELVERSION to Alpine $NewAlpineVersion"
$SNAPSHOTCMD "Before upgrade form Alpine $RELVERSION to Alpine $NewAlpineVersion"
#Fully update current version
$INSTCALL -- apk update
$INSTCALL -- apk upgrade
$INSTCALL -- sed "s/$RELVERSION/$NewAlpineVersion/g" /etc/apk/repositories
$INSTCALL -- sed -i "s/$RELVERSION/$NewAlpineVersion/g" /etc/apk/repositories
$INSTCALL -- apk update
$INSTCALL -- apk add --upgrade apk-tools
$INSTCALL -- apk upgrade --available