Added release-upgrade scripts

This commit is contained in:
2023-11-19 16:57:13 +01:00
parent 040310b33a
commit 2bc12f8ae2
3 changed files with 277 additions and 0 deletions

View File

@@ -117,4 +117,93 @@ VM-State (){
* )
return 2;;
esac
}
#Upgrading Release on CT
CT-UpgradeRelease () {
#If yet set then set CTID as $1
if [ -z ${CTID+x} ]; then local CTID=$1;fi
echo "Upgrading release for $CTID"
#Getting distribution info
local DIST=$(pct exec $CTID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
local RELVERSION=$(pct exec $CTID -- awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release | cut -d"." -f 1,2)
local RELNAME=$(pct exec $CTID -- awk -F= '$1=="VERSION_CODENAME" { print $2 ;}' /etc/os-release)
local INSTCALL="pct exec $CTID"
local SNAPSHOTCMD="pct snapshot $CTID BeforeReleaseUpgrade --description"
local DOREBOOT=false
#Call generic release upgrader
UpgradeRelease
if $DOREBOOT; then
qm reboot $VMID
fi
unset DIST RELVERSION RELNAME INSTCALL DOREBOOT
}
#Upgrading Release on VM
VM-UpgradeRelease () {
#If yet set then set VMID as $1
if [ -z ${VMID+x} ]; then local VMID=$1;fi
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 SNAPSHOTCMD="qm snapshot $VMID BeforeReleaseUpgrade --description"
local DOREBOOT=false
#Call generic release upgrader
UpgradeRelease
if $DOREBOOT; then
qm reboot $VMID
fi
unset DIST RELVERSION RELNAME INSTCALL
}
#Run release update, called by CT-UpgradeRelease and VM-UpgradeRelease
UpgradeRelease () {
#Getting distribution name
if [[ "${DIST}" == *"debian"* ]] && $DoDebianReleaseUpdate; then
if [ $RELNAME != $NewDebianVersion ]; then
#Create snapshot before upgrading
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
# 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/*
# Run upgrade to new release
$INSTCALL -- apt clean
$INSTCALL -- apt update
$INSTCALL -- apt upgrade -y
$INSTCALL -- apt full-upgrade -y
$INSTCALL -- apt autoremove -y
DOREBOOT=true
else
echo "Notice: Skiped, already up-to-date"
fi
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"
#Fully update current version
$INSTCALL -- apk update
$INSTCALL -- apk upgrade
$INSTCALL -- sed "s/$RELVERSION/$NewAlpineVersion/g" /etc/apk/repositories
$INSTCALL -- apk update
$INSTCALL -- apk add --upgrade apk-tools
$INSTCALL -- apk upgrade --available
DOREBOOT=true
else
echo "Notice: Skiped, already up-to-date"
fi
elif [[ "${DIST}" == *"alpine"* ]]; then
echo "Notice: Release upgrade disabled for Alpine"
else
echo "Warning: Release upgrade are supported for this distro"
#exit 100
fi
}