-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhomebrew_info.sh
executable file
·50 lines (39 loc) · 1.28 KB
/
homebrew_info.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# Made by tuxudo
# homebrew_info
# Skip manual check
if [ "$1" = 'manualcheck' ]; then
echo 'Manual check: skipping'
exit 0
fi
# Check if homebrew is installed
CURRENTUSER=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')
if [[ $CURRENTUSER != "" ]]; then
brew=$(sudo -i -u $CURRENTUSER command -v brew)
if [[ $? = 1 ]] && [[ -f "/usr/local/bin/brew" ]] ; then
# If Intel Mac
brew="/usr/local/bin/brew"
elif [[ $? = 1 ]] && [[ -f "/opt/homebrew/bin/brew" ]] ; then
# Else if Apple Silicon Mac
brew="/opt/homebrew/bin/brew"
fi
else
if [[ -f "/usr/local/bin/brew" ]] ; then
# If Intel Mac
brew="/usr/local/bin/brew"
elif [[ -f "/opt/homebrew/bin/brew" ]] ; then
# Else if Apple Silicon Mac
brew="/opt/homebrew/bin/brew"
fi
fi
if [[ -f $brew ]]; then
# The sudo is needed to escape brew.sh's UID of 0 check
BREWCONFIG='[{"'
BREWCONFIG="$BREWCONFIG$(cd /; sudo -HE -u nobody $brew config | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/", "/g' -e 's/: /": "/g')"
BREWCONFIG="$BREWCONFIG\"}]"
homebrewfile="$DIR/cache/homebrew_info.json"
echo "${BREWCONFIG}" > "${homebrewfile}"
else
echo "Homebrew is not installed, skipping"
fi
exit 0