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
#Load functions
source $WorkDir/functions.sh
#Create Log folder
#Get what sould be checked
CheckVM=true
@@ -20,8 +19,8 @@ CheckCT=true
echo "Type,ID,Name,Status,Distro,Version" | tee $InventoryFile
#CT updates
if $CheckVM; then
#CT Inventory
if $CheckCT; then
TYPE=CT;
for ID in $(pct list | tail -n+2 | awk '{print $1}'); do
STATUS=$(pct status $ID |sed 's/status: //')
@@ -33,15 +32,23 @@ if $CheckVM; then
unset TYPE
fi
#VM Updates
if $CheckCT; then
#VM inventory
if $CheckVM; then
TYPE=VM;
for ID in $(qm list | tail -n+2 | awk '{print $1}'); do
STATUS=$(qm status $ID |sed 's/status: //')
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"]')
ParseOSRelease
unset OSRELEASE ID NAME STATUS DISTRO VERSION
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
fi
fi
unset OSRELEASE OSYPE ID NAME STATUS DISTRO VERSION
done
unset TYPE
fi

View File

@@ -213,9 +213,9 @@ UpgradeRelease () {
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)
DISTRO=$(printf "$OSRELEASE" | awk -F= '$1=="ID" { print $2 ;}')
VERSION=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_ID" { print $2 ;}' |tr -d '"')
VERSIONNAME=$(printf "$OSRELEASE" | awk -F= '$1=="VERSION_CODENAME" { print $2 ;}')
if [ ! -z "$VERSIONNAME" ]; then
VERSION="$VERSION ($VERSIONNAME)"
fi