Inital commit

This commit is contained in:
2022-04-15 22:42:28 +02:00
commit f58f6a2953
13 changed files with 348 additions and 0 deletions

9
Playground/testCTfile.sh Normal file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
CTID=100
#CTID=$1
FILE=/opt/test
if pct exec $CTID -- test -f $FILE ; then
echo "File exists in $CTID"
else
echo "File does not exist in $CTID."
fi

4
Playground/testCTloop.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
echo "Task for $CTID"
done

View File

@@ -0,0 +1,8 @@
#!/bin/bash
ExcludeList=(100 900)
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
if [[ "${ExcludeList[*]}" =~ $CTID ]]; then continue; fi
echo "Task for $CTID"
done

15
Playground/testCTpkgm.sh Normal file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
#CTID=$1
CTID=100
DIST=$(pct exec $CTID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
if [[ "${DIST}" == *"ubuntu"* ]] || [[ "${DIST}" == *"debian"* ]]; then
echo "Apt Detected"
elif [[ "${DIST}" == *"alpine"* ]]; then
echo "APK Detected"
#elif [[ "${DIST}" == *"centos"* ]]; then
# echo "DNF Detected"
else
echo "Package manager in not supported"
fi

View File

@@ -0,0 +1,20 @@
#!/bin/bash
ID=100
#ID=$1
VMS=$(qm list | tail -n+2 | awk '{print $1}')
CTS=$(pct list | tail -n+2 | awk '{print $1}')
EXISTINGIDS=(${CTS[@]} ${VMS[@]})
#for ExistingID in $(qm list | tail -n+2 | awk '{print $1}' &&pct list | tail -n+2 | awk '{print $1}'); do
for ExistingID in "${EXISTINGIDS[@]}"; do
echo $ExistingID
if [ $ExistingID -eq $ID ]; then
echo Exists
IdExists=true
break
fi
IdExists=false
done
if ! $IdExists; then echo "This ID does not exist"; exit; fi
echo end

View File

@@ -0,0 +1,9 @@
#!/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
echo ID is $TYPE

9
Playground/testVMfile.sh Normal file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
#VMID=$1
VMID=101
FILE=/opt/test
if [ $(qm guest exec $VMID -- test -f $FILE |jq '.exitcode') == 0 ] ; then
echo "File exists in $VMID"
else
echo "File does not exist in $VMID."
fi

4
Playground/testVMloop.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do
echo "Task for $VMID"
done

14
Playground/testVMpkgm.sh Normal file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
#VMID=$1
VMID=100
DIST=$(qm guest exec $VMID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
if [[ "${DIST}" == *"ubuntu"* ]] || [[ "${DIST}" == *"debian"* ]]; then
echo "Apt Detected"
elif [[ "${DIST}" == *"alpine"* ]]; then
echo "APK Detected"
#elif [[ "${DIST}" == *"centos"* ]]; then
# echo "DNF Detected"
else
echo "Package manager in not supported"
fi

20
ReadMe.md Normal file
View File

@@ -0,0 +1,20 @@
# Proxmox helper scrips
### Scripts and their usage
| Name | Usage |
|:------------:|:-------------------------------------------------:|
| UpdateAll.sh | Update all CT's and VM's |
| UpdateOne.sh | Update one CT or VM by passing its ID as argument |
| functions.sh | Shared functions for both scripts |
### Installation
* Install jq `apt install jq`
* Clone this repo to your Proxmox service
### Features
* Upgrade all CT's/VM's at once
* Exclude list in `UpdateAll.sh`, to skip once you don't want to update
* Updates using package manager
* Application updates by checking for and running /opt/ProxMoxToolKitAppUpdate.sh _!This script runs using the sh shell_

85
UpdateAll.sh Normal file
View File

@@ -0,0 +1,85 @@
#!/bin/bash
##########################
# ProxMox update tools #
# Update all CT`s/VM`s #
# @author: Bram Prieshof #
##########################
#Load functions
source $(dirname $0)/functions.sh
#ID list of excluded VM/CT's
ExcludeList=()
#Get what sould be updated
UpdateVM=true
UpdateCT=true
#while true; do
# read -p "Wich systems should be updated (A)ll, (C)T's only or (V)M's only? " sysq
# case $sysq in
# [Aa]* )
# UpdateVM=true
# UpdateCT=true
# break;;
# [Cc]* )
# UpdateVM=false
# UpdateCT=true
# break;;
# [Vv]* )
# UpdateVM=true
# UpdateCT=false
# break;;
# * ) echo "Please answer with (A)ll, (C)T's or (V)M's.";;
# esac
#done
while true; do
read -p "Wich software should be updated (P)ackages, (A)pplications or (B)oth? " sofq
case $sofq in
[Pp]* )
UpdatePKG=true
UpdateAPP=false
break;;
[Aa]* )
UpdatePKG=false
UpdateAPP=true
break;;
[Bb]* )
UpdatePKG=true
UpdateAPP=true
break;;
* ) echo "Please answer with (A)ll, (C)T`s or (V)M`s.";;
esac
done
#CT updates
if $UpdateCT; then
for CTID in $(pct list | tail -n+2 | awk '{print $1}'); do
#Skip CT if in ExcludeList
if [[ "${ExcludeList[*]}" =~ $CTID ]]; then echo "Notice: $CTID excluded"; continue; fi
#DEBUG echo "Task for $CTID"
if $UpdatePKG; then
CT-UpdatePackages $CTID
fi
if $UpdateAPP; then
CT-UpdateApplicatons $CTID
fi
done
fi
#VM Updates
if $UpdateVM; then
for VMID in $(qm list | tail -n+2 | awk '{print $1}'); do
#Skip CT if in ExcludeList
if [[ "${ExcludeList[*]}" =~ $VMID ]]; then echo "Notice: $VMID excluded"; continue; fi
#DEBUG echo "Task for $VMID"
if $UpdatePKG; then
VM-UpdatePackages $VMID
fi
if $UpdateAPP; then
VM-UpdateApplicatons $VMID
fi
done
fi

57
UpdateOne.sh Normal file
View File

@@ -0,0 +1,57 @@
#!/bin/bash
##########################
# ProxMox update tools #
# Update one CT/VM #
# @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; fi
if [[ $CTS =~ $ID ]]; then TYPE=CT; fi
#Ask what should be updated
while true; do
read -p "Wich software should be updated (P)ackages, (A)pplications or (B)oth? " sofq
case $sofq in
[Pp]* )
#Update system packages
$TYPE-UpdatePackages $ID
break;;
[Aa]* )
#Update applications
$TYPE-UpdateApplicatons $ID
break;;
[Bb]* )
#Update both
$TYPE-UpdatePackages $ID
$TYPE-UpdateApplicatons $ID
break;;
* ) echo "Please answer with (A)ll, (C)T`s or (V)M`s.";;
esac
done

94
functions.sh Normal file
View File

@@ -0,0 +1,94 @@
#!/bin/bash
##########################
# ProxMox update tools #
# FUNCTIONS #
# @author: Bram Prieshof #
##########################
#Update Packages and Applications on CT
#CT-UpdateBoth () {
# local CTID=$1
# echo "Updating Packages and Applications for $CTID"
# CT-UpdatePackages
# CT-UpdateApplicatons
#}
##Update Packages and Applications on VM
#VM-UpdateBoth () {
# local VMID=$1
# echo "Updating Packages and Applications for $VMID"
# VM-UpdatePackages
# VM-UpdateApplicatons
#}
#Updating Packages on CT
CT-UpdatePackages () {
#If not called by UpdateBoth then set $1 as CTID
if [ -z ${CTID+x} ]; then local CTID=$1;fi
echo "Updating Packages for $CTID"
#Getting distributionname
local DIST=$(pct exec $CTID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
local INSTCALL="pct exec $CTID"
#Call generic package updater
UpdatePackages
unset DIST INSTCALL
}
#Updating Packages on VM
VM-UpdatePackages () {
#If not called by UpdateBoth then set $1 as VMID
if [ -z ${VMID+x} ]; then local VMID=$1;fi
echo "Updating Packages for $VMID, No output is provided until task is completed"
#Getting distributionname
local DIST=$(qm guest exec $VMID -- awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | jq '.["out-data"]')
local INSTCALL="qm guest exec $VMID"
#Call generic package updater
UpdatePackages
unset DIST INSTCALL
}
#Starts package manager, called by CT-UpdatePackages and VM-UpdatePackages
UpdatePackages () {
#Getting distributionname
if [[ "${DIST}" == *"ubuntu"* ]] || [[ "${DIST}" == *"debian"* ]]; then
$INSTCALL -- apt update
$INSTCALL -- apt upgrade -y
elif [[ "${DIST}" == *"alpine"* ]]; then
$INSTCALL -- apk update
$INSTCALL -- apk upgrade
elif [[ "${DIST}" == *"centos"* ]]; then
$INSTCALL -- dnf update -y
else
echo "Warning: Package manager in not supported"
#exit 100
fi
}
#Updating CT applications using /opt/ProxMoxToolKitAppUpdate.sh in CT
CT-UpdateApplicatons () {
#If not called by UpdateBoth then set $1 as CTID
if [ -z ${CTID+x} ]; then local CTID=$1;fi
#Test if CT has Applicatons update script
if pct exec $CTID -- test -f /opt/ProxMoxToolKitAppUpdate.sh ; then
echo "Updating Applications for $CTID"
pct exec $CTID -- sh /opt/ProxMoxToolKitAppUpdate.sh
else
echo "Warning: Application updates not enabled in $CTID"
#exit 102
fi
}
#Updating VM applications using /opt/ProxMoxToolKitAppUpdate.sh in VM
VM-UpdateApplicatons () {
#If not called by UpdateBoth then set $1 as VMID
if [ -z ${VMID+x} ]; then local VMID=$1;fi
#Test if VM has Applicatons update script
if [ $(qm guest exec $VMID -- test -f /opt/ProxMoxToolKitAppUpdate.sh |jq '.exitcode') == 0 ] ; then
echo "Updating Applications for $VMID, No output is provided until task is completed"
qm guest exec $VMID -- sh /opt/ProxMoxToolKitAppUpdate.sh
else
echo "Warning: application updates not enabled in $VMID"
#exit 102
fi
}