Added PostUpgrade tasks for Debian 13 and Alpine 3.23, refactored Type Detection of scripts tageting one system
This commit is contained in:
@@ -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
|
||||
|
||||
10
Playground/testDetermineTypeOld.sh
Normal file
10
Playground/testDetermineTypeOld.sh
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
DIST=$(qm guest exec $ID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
|
||||
fi
|
||||
if [[ $CTS =~ $ID ]]; then
|
||||
#Determine id type
|
||||
for ArrayID in "${CTS[@]}"; do
|
||||
if [ $ArrayID -eq $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
|
||||
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"]')
|
||||
elif [ "$TYPE" = "CT" ]; then
|
||||
DIST=$(pct exec $ID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
|
||||
fi
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
24
UpdateOne.sh
24
UpdateOne.sh
@@ -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
|
||||
|
||||
41
functions.sh
41
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 '"')
|
||||
@@ -249,3 +252,37 @@ ParseOSRelease()
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user