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:
@@ -31,7 +31,7 @@ while true; do
|
|||||||
DoAlpineReleaseUpdate=false
|
DoAlpineReleaseUpdate=false
|
||||||
break;;
|
break;;
|
||||||
[Aa]* )
|
[Aa]* )
|
||||||
DoDebianReleaseUpdate=true
|
DoDebianReleaseUpdate=false
|
||||||
DoAlpineReleaseUpdate=true
|
DoAlpineReleaseUpdate=true
|
||||||
break;;
|
break;;
|
||||||
[Bb]* )
|
[Bb]* )
|
||||||
@@ -76,6 +76,7 @@ fi
|
|||||||
|
|
||||||
#CT updates
|
#CT updates
|
||||||
if $UpdateCT; then
|
if $UpdateCT; then
|
||||||
|
TYPE=CT;
|
||||||
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
|
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
|
||||||
#Skip CT if in ExcludeList
|
#Skip CT if in ExcludeList
|
||||||
if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi
|
if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi
|
||||||
@@ -88,6 +89,7 @@ fi
|
|||||||
|
|
||||||
#VM Updates
|
#VM Updates
|
||||||
if $UpdateVM; then
|
if $UpdateVM; then
|
||||||
|
TYPE=VM;
|
||||||
for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do
|
for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do
|
||||||
#Skip VM if in ExcludeList
|
#Skip VM if in ExcludeList
|
||||||
if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi
|
if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi
|
||||||
|
|||||||
@@ -34,16 +34,17 @@ if ! $IdExists; then echo "This ID does not exist"; exit; fi
|
|||||||
#Check type of ID
|
#Check type of ID
|
||||||
if [[ $VMS =~ $ID ]];then
|
if [[ $VMS =~ $ID ]];then
|
||||||
TYPE=VM;
|
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
|
fi
|
||||||
if [[ $CTS =~ $ID ]]; then
|
if [[ $CTS =~ $ID ]]; then
|
||||||
TYPE=CT
|
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
|
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
|
#Check wich distro the CT/VM is running
|
||||||
if [[ "${DIST}" == *"debian"* ]]; then
|
if [[ "${DIST}" == *"debian"* ]]; then
|
||||||
#Ask the wanted Debian version
|
#Ask the wanted Debian version
|
||||||
|
|||||||
30
functions.sh
30
functions.sh
@@ -53,7 +53,7 @@ UpdatePackages () {
|
|||||||
#Getting distributionname
|
#Getting distributionname
|
||||||
if [[ "${DIST}" == *"ubuntu"* ]] || [[ "${DIST}" == *"debian"* ]]; then
|
if [[ "${DIST}" == *"ubuntu"* ]] || [[ "${DIST}" == *"debian"* ]]; then
|
||||||
$INSTCALL -- apt update
|
$INSTCALL -- apt update
|
||||||
$INSTCALL -- apt upgrade -y
|
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confold"
|
||||||
elif [[ "${DIST}" == *"alpine"* ]]; then
|
elif [[ "${DIST}" == *"alpine"* ]]; then
|
||||||
$INSTCALL -- apk update
|
$INSTCALL -- apk update
|
||||||
$INSTCALL -- apk upgrade
|
$INSTCALL -- apk upgrade
|
||||||
@@ -134,7 +134,7 @@ CT-UpgradeRelease () {
|
|||||||
#Call generic release upgrader
|
#Call generic release upgrader
|
||||||
UpgradeRelease
|
UpgradeRelease
|
||||||
if $DOREBOOT; then
|
if $DOREBOOT; then
|
||||||
qm reboot $VMID
|
pct reboot $CTID
|
||||||
fi
|
fi
|
||||||
unset DIST RELVERSION RELNAME INSTCALL DOREBOOT
|
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"
|
echo "Upgrading release for $VMID, No output is provided until task is completed"
|
||||||
#Getting distribution info
|
#Getting distribution info
|
||||||
local DIST=$(qm guest exec $VMID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
|
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 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"]')
|
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"
|
local INSTCALL="qm guest exec $VMID --timeout 0"
|
||||||
local SNAPSHOTCMD="qm snapshot $VMID BeforeReleaseUpgrade --description"
|
local SNAPSHOTCMD="qm snapshot $VMID BeforeReleaseUpgrade --description"
|
||||||
local DOREBOOT=false
|
local DOREBOOT=false
|
||||||
#Call generic release upgrader
|
#Call generic release upgrader
|
||||||
@@ -162,37 +162,39 @@ VM-UpgradeRelease () {
|
|||||||
#Run release update, called by CT-UpgradeRelease and VM-UpgradeRelease
|
#Run release update, called by CT-UpgradeRelease and VM-UpgradeRelease
|
||||||
UpgradeRelease () {
|
UpgradeRelease () {
|
||||||
#Getting distribution name
|
#Getting distribution name
|
||||||
if [[ "${DIST}" == *"debian"* ]] && $DoDebianReleaseUpdate; then
|
if [[ "${DIST}" == *"debian"* ]] && $DoDebianReleaseUpdate && [[ "${TYPE}" == "CT" ]]; then
|
||||||
if [ $RELNAME != $NewDebianVersion ]; then
|
if [ $RELNAME != $NewDebianVersion ]; then
|
||||||
#Create snapshot before upgrading
|
#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
|
#Fully update current version
|
||||||
$INSTCALL -- apt update
|
$INSTCALL -- apt update
|
||||||
$INSTCALL -- apt upgrade -y
|
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confold"
|
||||||
$INSTCALL -- apt full-upgrade -y
|
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt full-upgrade -y -o Dpkg::Options::="--force-confold"
|
||||||
# Update repo file(s)
|
# 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
|
||||||
$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
|
# Run upgrade to new release
|
||||||
$INSTCALL -- apt clean
|
$INSTCALL -- apt clean
|
||||||
$INSTCALL -- apt update
|
$INSTCALL -- apt update
|
||||||
$INSTCALL -- apt upgrade -y
|
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt upgrade -y -o Dpkg::Options::="--force-confold"
|
||||||
$INSTCALL -- apt full-upgrade -y
|
$INSTCALL -- DEBIAN_FRONTEND=noninteractive apt full-upgrade -y -o Dpkg::Options::="--force-confold"
|
||||||
$INSTCALL -- apt autoremove -y
|
$INSTCALL -- apt autoremove -y
|
||||||
DOREBOOT=true
|
DOREBOOT=true
|
||||||
else
|
else
|
||||||
echo "Notice: Skiped, already up-to-date"
|
echo "Notice: Skiped, already up-to-date"
|
||||||
fi
|
fi
|
||||||
|
elif [[ "${DIST}" == *"debian"* ]] && $DoDebianReleaseUpdate && [[ "${TYPE}" == "VM" ]]; then
|
||||||
|
echo "Notice: Release upgrade for Debian VM's is not supported"
|
||||||
elif [[ "${DIST}" == *"debian"* ]]; then
|
elif [[ "${DIST}" == *"debian"* ]]; then
|
||||||
echo "Notice: Release upgrade disabled for Debian"
|
echo "Notice: Release upgrade disabled for Debian"
|
||||||
elif [[ "${DIST}" == *"alpine"* ]] && $DoAlpineReleaseUpdate ; then
|
elif [[ "${DIST}" == *"alpine"* ]] && $DoAlpineReleaseUpdate ; then
|
||||||
if [ $RELVERSION != $NewAlpineVersion ]; then
|
if [ $RELVERSION != $NewAlpineVersion ]; then
|
||||||
#Create snapshot before upgrading
|
#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
|
#Fully update current version
|
||||||
$INSTCALL -- apk update
|
$INSTCALL -- apk update
|
||||||
$INSTCALL -- apk upgrade
|
$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 update
|
||||||
$INSTCALL -- apk add --upgrade apk-tools
|
$INSTCALL -- apk add --upgrade apk-tools
|
||||||
$INSTCALL -- apk upgrade --available
|
$INSTCALL -- apk upgrade --available
|
||||||
|
|||||||
Reference in New Issue
Block a user