diff --git a/.gitignore b/.gitignore index 4cf8dd1..d68968a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -logs/* \ No newline at end of file +logs/* +*.csv \ No newline at end of file diff --git a/DistroInventory.sh b/DistroInventory.sh new file mode 100644 index 0000000..cc025e8 --- /dev/null +++ b/DistroInventory.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +########################################## +# ProxMox update tools # +# Get OS release info on all CT`s/VM`s # +# @author: Bram Prieshof # +########################################## + +#Dirs +WorkDir=$(dirname $0) +#InventoryFile +InventoryFile=$WorkDir/GuestInventory.csv +#Load functions +source $WorkDir/functions.sh +#Create Log folder + +#Get what sould be checked +CheckVM=true +CheckCT=true + +echo "Type,ID,Name,Status,Distro,Version" | tee $InventoryFile + +#CT updates +if $CheckVM; then + TYPE=CT; + for ID in $(pct list | tail -n+2 | awk '{print $1}'); do + local STATUS=$(pct status $ID |sed 's/status: //') + local NAME=$(pct config $ID | grep hostname |sed 's/hostname: //') + if [ $STATUS == "running" ]; then local OSRELEASE=$(pct exec $ID -- cat /etc/os-release);fi + ParseOSRelease + unset OSRELEASE TYPE ID NAME STATUS DISTRO VERSION + done +fi + +#VM Updates +if $CheckCT; then + TYPE=VM; + for ID in $(qm list | tail -n+2 | awk '{print $1}'); do + local STATUS=$(qm status $ID |sed 's/status: //') + local NAME=$(qm config $ID | grep name |sed 's/name: //') + if [ $STATUS == "running" ]; then local OSRELEASE=$(qm guest exec 2002 -- cat /etc/os-release |jq -r '.["out-data"]') + ParseOSRelease + unset OSRELEASE TYPE ID NAME STATUS DISTRO VERSION + done +fi diff --git a/functions.sh b/functions.sh index 37f23cd..45386b5 100644 --- a/functions.sh +++ b/functions.sh @@ -208,4 +208,20 @@ UpgradeRelease () { echo "Warning: Release upgrade are supported for this distro" #exit 100 fi +} + +ParseOSRelease() +{ + if [ ! -z "$OSRELEASE" ]; then + DISTRO=$(printf "$OSRELEASE" | awk -F= '$1=="ID" { print $2 ;}' /etc/os-release) + VERSION=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release |tr -d '"' ) + VERSIONNAME=$(printf "$OSRELEASE" | -- awk -F= '$1=="VERSION_CODENAME" { print $2 ;}' /etc/os-release) + if [ ! -z "$VERSIONNAME" ]; then + VERSION="$VERSION ($VERSIONNAME)" + fi + else + DISTRO=N/A + VERSION=N/A + fi + echo "$TYPE,$ID,$NAME,$STATUS,$DISTRO,$VERSION" | tee -a $InventoryFile } \ No newline at end of file