From d51a694daadbaf593771d3f438e42d1a42a7d40c Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Sun, 11 Jan 2026 01:16:33 +0100 Subject: [PATCH] Added PostUpgrade tasks for Debian 13 and Alpine 3.23, refactored Type Detection of scripts tageting one system --- Playground/testDetermineType.sh | 29 ++++++++++++++++----- Playground/testDetermineTypeOld.sh | 10 ++++++++ ReleaseUpgradeALL.sh | 6 +++-- ReleaseUpgradeOne.sh | 37 ++++++++++++++++++--------- UpdateAll.sh | 6 +++-- UpdateOne.sh | 24 +++++++++++++---- functions.sh | 41 ++++++++++++++++++++++++++++-- 7 files changed, 123 insertions(+), 30 deletions(-) create mode 100644 Playground/testDetermineTypeOld.sh diff --git a/Playground/testDetermineType.sh b/Playground/testDetermineType.sh index f70879e..f2e4740 100644 --- a/Playground/testDetermineType.sh +++ b/Playground/testDetermineType.sh @@ -1,9 +1,24 @@ #!/bin/bash -ID=100 -#ID=$1 -VMS=$(qm list | tail -n+2 | awk '{print $1}') -CTS=$(pct list | tail -n+2 | awk '{print $1}') +#ID=100 +ID=$1 +VMS=($(qm list | tail -n+2 | awk '{print $1}')) +CTS=($(pct list | tail -n+2 | awk '{print $1}')) #Determine id type -if [[ $VMS =~ $ID ]]; then TYPE=VM; fi -if [[ $CTS =~ $ID ]]; then TYPE=CT; fi -echo ID is $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 TYPE=Unset; fi + +echo ID: $ID is $TYPE diff --git a/Playground/testDetermineTypeOld.sh b/Playground/testDetermineTypeOld.sh new file mode 100644 index 0000000..ba19e3d --- /dev/null +++ b/Playground/testDetermineTypeOld.sh @@ -0,0 +1,10 @@ +#!/bin/bash +ID=100 +#ID=$1 +VMS=$(qm list | tail -n+2 | awk '{print $1}') +CTS=$(pct list | tail -n+2 | awk '{print $1}') +#Determine id type +if [[ $VMS =~ $ID ]]; then TYPE=VM; fi +if [[ $CTS =~ $ID ]]; then TYPE=CT; fi +if [ -z ${TYPE+x} ]; then TYPE=Unset; fi +echo ID: $ID is $TYPE diff --git a/ReleaseUpgradeALL.sh b/ReleaseUpgradeALL.sh index b637866..8dea5fc 100755 --- a/ReleaseUpgradeALL.sh +++ b/ReleaseUpgradeALL.sh @@ -95,7 +95,8 @@ fi #CT updates if $UpdateCT; then TYPE=CT; - for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do + CTS=($(pct list | tail -n+2 | awk '{print $1}')) + for CTID in "${CTS[@]}"; do #Skip CT if in ExcludeList if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi # Skip CT if not running @@ -108,7 +109,8 @@ fi #VM Updates if $UpdateVM; then TYPE=VM; - for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do + VMS=($(qm list | tail -n+2 | awk '{print $1}')) + for VMID in "${VMS[@]}"; do #Skip VM if in ExcludeList if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi # Skip VM if not running diff --git a/ReleaseUpgradeOne.sh b/ReleaseUpgradeOne.sh index 4a840a1..cdf9310 100644 --- a/ReleaseUpgradeOne.sh +++ b/ReleaseUpgradeOne.sh @@ -17,8 +17,8 @@ if [ -z "${1##*[!0-9]*}" ]; then echo "Invalid ID, usage: $0 "; exit; #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}') +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 @@ -31,17 +31,30 @@ IdExists=false done if ! $IdExists; then echo "This ID does not exist"; exit; fi -#Check type of ID -if [[ $VMS =~ $ID ]];then - TYPE=VM; - if ! $(VM-State $ID); then echo "This ID is not runnig"; 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 + +#Get distro type +if [ "$TYPE" = "VM" ];then DIST=$(qm guest exec $ID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]') -fi -if [[ $CTS =~ $ID ]]; then - TYPE=CT - #Check if CT is running - if ! $(CT-State $ID); then echo "This ID is not runnig"; exit; fi - #Get CT distro +elif [ "$TYPE" = "CT" ]; then DIST=$(pct exec $ID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release) fi diff --git a/UpdateAll.sh b/UpdateAll.sh index 1ad1128..dd85580 100755 --- a/UpdateAll.sh +++ b/UpdateAll.sh @@ -63,7 +63,8 @@ done #CT updates if $UpdateCT; then - for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do + CTS=($(pct list | tail -n+2 | awk '{print $1}')) + for CTID in "${CTS[@]}"; do #Skip CT if in ExcludeList if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi # Skip CT if not running @@ -80,7 +81,8 @@ fi #VM Updates if $UpdateVM; then - for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do + VMS=($(qm list | tail -n+2 | awk '{print $1}')) + for VMID in "${VMS[@]}"; do #Skip VM if in ExcludeList if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi # Skip VM if not running diff --git a/UpdateOne.sh b/UpdateOne.sh index b5e0ba6..23d9e53 100755 --- a/UpdateOne.sh +++ b/UpdateOne.sh @@ -17,8 +17,8 @@ if [ -z "${1##*[!0-9]*}" ]; then echo "Invalid ID, usage: $0 "; exit; #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}') +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 @@ -31,9 +31,23 @@ 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 +#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 diff --git a/functions.sh b/functions.sh index 224cb63..fec285e 100644 --- a/functions.sh +++ b/functions.sh @@ -180,6 +180,8 @@ UpgradeRelease () { $INSTCALL -- sh -c "DEBIAN_FRONTEND=noninteractive apt full-upgrade -y -o Dpkg::Options::="--force-confold"" $INSTCALL -- apt autoremove -y DOREBOOT=true + # Post release cleanup if required + if [ "${NewDebianVersion}" = "trixie" ]; then PostDebianTrixieTasks; fi else echo "Notice: Skiped, already up-to-date" fi @@ -199,6 +201,8 @@ UpgradeRelease () { $INSTCALL -- apk add --upgrade apk-tools $INSTCALL -- apk upgrade --available DOREBOOT=true + # Post release cleanup if required + if [ "${NewAlpineVersion}" = "3.23" ]; then PostAlpine323Tasks; fi else echo "Notice: Skiped, already up-to-date" fi @@ -231,8 +235,7 @@ UpgradeRelease () { fi } -ParseOSRelease() -{ +ParseOSRelease () { if [ ! -z "$OSRELEASE" ]; then DISTRO=$(printf "$OSRELEASE" | awk -F= '$1=="ID" { print $2 ;}' |tr -d '"') VERSION=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_ID" { print $2 ;}' |tr -d '"') @@ -248,4 +251,38 @@ ParseOSRelease() if [ -z ${VERSION+x} ]; then local VERSION=N/A;fi fi echo "$TYPE,$ID,$NAME,$STATUS,$DISTRO,$VERSION" | tee -a $InventoryFile +} + +#Steps required after upgrade for certain distros and releases + +PostDebianTrixieTasks () { + #Modernize apt sources + $INSTCALL -- apt modernize-sources -y + $INSTCALL -- rm -f /etc/apt/sources.list.bak + $INSTCALL -- rm -f /etc/apt/sources.list.d/*.bak + + # Disable unwanted mounts + $INSTCALL -- systemctl mask dev-mqueue.mount + $INSTCALL -- systemctl mask run-lock.mount + $INSTCALL -- systemctl mask sys-kernel-config.mount + $INSTCALL -- systemctl mask sys-kernel-debug.mount + $INSTCALL -- systemctl mask tmp.mount +} + +PostAlpine323Tasks () { + $INSTCALL -- apk add merge-usr + $INSTCALL -- merge-usr --dryrun + while true; do + read -p "Are any errors are printed out? -> yes/no?" yn + case $yn in + [Nn]* ) + $INSTCALL -- merge-usr + $INSTCALL -- apk del merge-usr + ;; + [Yy]* ) + echo "Migrating /bin to /usr/bin skiped due to an error, please investigate and complete manualy" + ;; + * ) echo "Choose yes or no.";; + esac + done } \ No newline at end of file