Added PostUpgrade tasks for Debian 13 and Alpine 3.23, refactored Type Detection of scripts tageting one system

This commit is contained in:
2026-01-11 01:16:33 +01:00
parent fd4bd0081a
commit d51a694daa
7 changed files with 123 additions and 30 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -17,8 +17,8 @@ if [ -z "${1##*[!0-9]*}" ]; then echo "Invalid ID, usage: $0 <CT/VM-ID>"; 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

View File

@@ -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

View File

@@ -17,8 +17,8 @@ if [ -z "${1##*[!0-9]*}" ]; then echo "Invalid ID, usage: $0 <CT/VM-ID>"; 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

View File

@@ -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
}