110 lines
3.2 KiB
Bash
110 lines
3.2 KiB
Bash
#!/bin/bash
|
|
|
|
#####################################
|
|
# ProxMox update tools #
|
|
# Upgrade one CT/VM OS release #
|
|
# @author: Bram Prieshof #
|
|
#####################################
|
|
|
|
#Load functions
|
|
source $(dirname $0)/functions.sh
|
|
|
|
#InputChecks
|
|
## Check if exists
|
|
if [ -z ${1+x} ]; then echo "No input, usage: $0 <CT/VM-ID>"; exit; fi
|
|
## Check if valid (number/integer)
|
|
if [ -z "${1##*[!0-9]*}" ]; then echo "Invalid ID, usage: $0 <CT/VM-ID>"; exit; fi
|
|
|
|
#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}')
|
|
ALLIDS=(${CTS[@]} ${VMS[@]})
|
|
|
|
## Check if ID exists
|
|
for ExistingID in "${ALLIDS[@]}"; do
|
|
if [ $ExistingID -eq $ID ]; then
|
|
IdExists=true
|
|
break
|
|
fi
|
|
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
|
|
TYPE=CT
|
|
#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
|
|
|
|
#Check wich distro the CT/VM is running
|
|
if [[ "${DIST}" == *"debian"* ]]; then
|
|
#Ask the wanted Debian version
|
|
DoDebianReleaseUpdate=true
|
|
DoAlpineReleaseUpdate=false
|
|
|
|
echo "Enter the Debian version to upgrade to"
|
|
read NewDebianVersion
|
|
while true; do
|
|
read -p "Upgrade to Debian $NewDebianVersion, is this correct? -> yes/no?" yn
|
|
case $yn in
|
|
[Nn]* )
|
|
echo "Enter the Debian version to upgrade to"
|
|
read NewDebianVersion
|
|
;;
|
|
[Yy]* ) break;;
|
|
* ) echo "Choose yes or no.";;
|
|
esac
|
|
done
|
|
elif [[ "${DIST}" == *"alpine"* ]]; then
|
|
#Ask the wanted Alpine version
|
|
DoAlpineReleaseUpdate=true
|
|
DoDebianReleaseUpdate=false
|
|
|
|
echo "Enter the Alpine version to upgrade to"
|
|
read NewAlpineVersion
|
|
while true; do
|
|
read -p "Upgrade to Alpine $NewAlpineVersion, is this correct? -> yes/no?" yn
|
|
case $yn in
|
|
[Nn]* )
|
|
echo "Enter the Alpine version to upgrade to"
|
|
read NewAlpineVersion
|
|
;;
|
|
[Yy]* ) break;;
|
|
* ) echo "Choose yes or no.";;
|
|
esac
|
|
done
|
|
elif [[ "${DIST}" == *"fedora"* ]]; then
|
|
#Ask the wanted Fedora version
|
|
DoDebianReleaseUpdate=true
|
|
DoAlpineReleaseUpdate=true
|
|
DoFedoraReleaseUpdate=false
|
|
|
|
echo "Enter the Fedora version to upgrade to"
|
|
read NewFedoraVersionNewFedoraVersion
|
|
while true; do
|
|
read -p "Upgrade to Fedora $NewFedoraVersion, is this correct? -> yes/no?" yn
|
|
case $yn in
|
|
[Nn]* )
|
|
echo "Enter the Fedora version to upgrade to"
|
|
read NewFedoraVersion
|
|
;;
|
|
[Yy]* ) break;;
|
|
* ) echo "Choose yes or no.";;
|
|
esac
|
|
done
|
|
else
|
|
echo "Warning: Release upgrade are supported for this distro"
|
|
exit
|
|
fi
|
|
|
|
|
|
$TYPE-UpgradeRelease $ID |