Hello all
Apologies if this has already been asked and I have missed it, but has anyone got away of collecting the applications installed by home brew?
Hello all
Apologies if this has already been asked and I have missed it, but has anyone got away of collecting the applications installed by home brew?
@Craig.Whittaker Does the command brew list
return the info you're looking for? If so, you can write an Extension Attribute to collect that.
@StoneMagnet hey it does, but wanted to set up a smart group to filter on home brew installed machines only having this ran on them :/
@Craig.Whittaker EAs run on all machines, and aren't scoped. You could have the EA check for the existence of the file /usr/local/bin/brew
to determine if brew is installed on the machine, and either return Not Installed or the list of installed brew tools.
thanks @StoneMagnet
don't happen to have an example EA doing even something similar I can pick apart?
@Craig.Whittaker This is untested, but should do what you want:
#!/bin/bash
brewtools="Not Installed"
if [ -e /usr/local/bin/brew ]
then
brewtools=$(/usr/local/bin/brew list)
fi
echo "<result>$brewtools</result>"
exit 0
So i found this while looking for other information, About a year later from original post.. so i am turning this into a zombie post i guess..
jamf runs alot of what it does from an elevated state. Brew errors out if run as root. so the above may not work for people. and since I had to make an EA and there was a post needing an EA. i figured i would share in the serendipitous nature of finding this
This only pulls brew installs for logged in users, which means the scope can change based on inventory checkin, and active user. but if you are primarily on a One to One deployment, that shouldn't be an issue.
If you need to get brew installs for all users you could possibly loop through the results of dscl . list or something. but the output of that will be fun to format in a away that is user readable in jamf..
#!/bin/bash
###########################################
set -euo pipefail
IFS=$'
'
## Variables #################
loggedInUser=$(stat -f %Su /dev/console)
brewArray=()
## Work Area ####################
if [[ -d /Users/"${loggedInUser}"/brew ]]; then
while read -r brewApp; do
name=$(basename "$brewApp")
brewArray+=("${name}")
done < <(ls /Users/"${loggedInUser}"/brew/Cellar/)
echo "<result>$(printf '%s
' "${brewArray[@]}")</result>"
else
echo "<result>brew not installed</result>"
fi
exit 0
Do dis:
in extension attrib:
- string
- extension attrib
- script
file="/Library/Caches/Homebrew"
if [ -d "$file" ]
then
echo "<result>"yes"</result>"
else
echo "<result>"No"</result>"
fi
or better yet:
file="/usr/local/bin/brew"
if [ -f "$file" ]
then
echo "<result>"yes"</result>"
else
echo "<result>"no Present"</result>"
fi
Adding to the zombie....
the if needs to be -x (executable) not -d (directory)
Also for M1/ARM machines: /opt/homebrew and it needs a -d
so to add on to this question what if you wanted to track what brew apps are installed, inside jamf, and possibly usage.
here's my version...
#!/bin/sh
brewDir=$(/usr/bin/find /opt /usr/local -d -maxdepth 1 -iname "homebrew" 2>/dev/null)
if [ "${brewDir}" ]; then
brewBin="${brewDir}/bin/brew"
brewOwner=$(id -nu "$(stat -f %u "${brewBin}")")
brewVers=$(sudo -u "${brewOwner}" "${brewBin}" config | grep HOMEBREW_VERSION | awk '{print $2}')
else
brewVers="Not Installed"
fi
printf %s "<result>${brewVers}</result>"
exit 0
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.