DistroInventory added windows support

Fixed bugs in os-Release file parsing
This commit is contained in:
2023-11-19 23:44:45 +01:00
parent 1ad843d62a
commit dfe29be6cb
2 changed files with 18 additions and 11 deletions

View File

@@ -12,7 +12,6 @@ WorkDir=$(dirname $0)
InventoryFile=$WorkDir/GuestInventory.csv InventoryFile=$WorkDir/GuestInventory.csv
#Load functions #Load functions
source $WorkDir/functions.sh source $WorkDir/functions.sh
#Create Log folder
#Get what sould be checked #Get what sould be checked
CheckVM=true CheckVM=true
@@ -20,8 +19,8 @@ CheckCT=true
echo "Type,ID,Name,Status,Distro,Version" | tee $InventoryFile echo "Type,ID,Name,Status,Distro,Version" | tee $InventoryFile
#CT updates #CT Inventory
if $CheckVM; then if $CheckCT; then
TYPE=CT; TYPE=CT;
for ID in $(pct list | tail -n+2 | awk '{print $1}'); do for ID in $(pct list | tail -n+2 | awk '{print $1}'); do
STATUS=$(pct status $ID |sed 's/status: //') STATUS=$(pct status $ID |sed 's/status: //')
@@ -33,15 +32,23 @@ if $CheckVM; then
unset TYPE unset TYPE
fi fi
#VM Updates #VM inventory
if $CheckCT; then if $CheckVM; then
TYPE=VM; TYPE=VM;
for ID in $(qm list | tail -n+2 | awk '{print $1}'); do for ID in $(qm list | tail -n+2 | awk '{print $1}'); do
STATUS=$(qm status $ID |sed 's/status: //') STATUS=$(qm status $ID |sed 's/status: //')
NAME=$(qm config $ID | grep name |sed 's/name: //') NAME=$(qm config $ID | grep name |sed 's/name: //')
if [ $STATUS == "running" ]; then OSRELEASE=$(qm guest exec 2002 -- cat /etc/os-release |jq -r '.["out-data"]') OSYPE=$(qm config $ID | grep ostype |sed 's/ostype: //')
if [ $STATUS == "running" ]; then
if [ [$OSYPE == *"win"* ]]; then
DISTRO=Windows
VERSION=$(qm guest exec $ID "systeminfo" |jq -r '.["out-data"]'| grep "OS Name" |sed -e 's/OS Name://' -e 's/^[ \t]*//' -e 's/Microsoft Windows//' -e 's/^[ \t]*//')
else
OSRELEASE=$(qm guest exec $ID -- cat /etc/os-release |jq -r '.["out-data"]')
ParseOSRelease ParseOSRelease
unset OSRELEASE ID NAME STATUS DISTRO VERSION fi
fi
unset OSRELEASE OSYPE ID NAME STATUS DISTRO VERSION
done done
unset TYPE unset TYPE
fi fi

View File

@@ -213,9 +213,9 @@ UpgradeRelease () {
ParseOSRelease() ParseOSRelease()
{ {
if [ ! -z "$OSRELEASE" ]; then if [ ! -z "$OSRELEASE" ]; then
DISTRO=$(printf "$OSRELEASE" | awk -F= '$1=="ID" { print $2 ;}' /etc/os-release) DISTRO=$(printf "$OSRELEASE" | awk -F= '$1=="ID" { print $2 ;}')
VERSION=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release |tr -d '"' ) VERSION=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_ID" { print $2 ;}' |tr -d '"')
VERSIONNAME=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_CODENAME" { print $2 ;}' /etc/os-release) VERSIONNAME=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_CODENAME" { print $2 ;}')
if [ ! -z "$VERSIONNAME" ]; then if [ ! -z "$VERSIONNAME" ]; then
VERSION="$VERSION ($VERSIONNAME)" VERSION="$VERSION ($VERSIONNAME)"
fi fi