I am working on an extension attribute to check if Aternity is installed, running, and its version. I have to write it this way to take into account the two possible install paths for the agent while we roll out the newer version. I keep running into an error "CFBundleShortVersionString", Does Not Exist". This is being generated from the version check in my script. I have visually confirmed that "CFBundleShortVersionString" DOES EXIST!!! I can run the command in Terminal:
version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Applications/AternityAgent.app/Contents/Info.plist)
When I type echo $version, I get the correct result.
Only when I run the whole script in either Terminal or CodeRunner does it give me that error. Here's my EA. What am I doing wrong?
#!/bin/zsh
# Is Aternity installed? Is it the older version or the newer version?
agentOld=(/Library/Aternity/Agent)
agentNew=(/Applications/AternityAgent.app)
if [[ -d $agentOld ]] || [[ -d $agentNew ]]; then
Installed="Installed: Yes"
if [[ $agentOld ]]; then
version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Library/Aternity/Agent/Contents/Info.plist)
proc=$(ps axc | /usr/bin/grep -ci "AternityAgent" 2>/dev/null)
if [ -z "$proc" ];then
procRunning="Process Running: No"
else
procRunning="Process Running: Yes"
fi
elif [[ -d $agentNew ]]; then
version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Applications/AternityAgent.app/Contents/Info.plist)
proc=$(ps aux | grep "AternityEUE" | /usr/bin/awk '{print $2}')
if [ -z "$proc" ];then
procRunning="Process Running: No"
else
procRunning="Process Running: Yes"
fi
else
Installed="Installed: No"
fi
fi
# Results
echo "<result>$(printf '%s\\n' "$Installed" "$procRunning" "Version: $Version")</result>"