-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbrew-install-cask.sh
36 lines (30 loc) · 1.34 KB
/
brew-install-cask.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
#!/bin/zsh
item="$4"
#######################
# check something set #
if [[ "$item" == "" ]]; then
echo "**** No item set! exiting ****"
exit 1
fi
UNAME_MACHINE="$(uname -m)"
ConsoleUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
# Check if the item is already installed. If not, install it
if [[ "$UNAME_MACHINE" == "arm64" ]]; then
# M1/arm64 machines
cd /tmp/ # This is required to use sudo as another user or you get a getcwd error
if [[ $(sudo -H -iu ${ConsoleUser} /opt/homebrew/bin/brew list --casks | grep -c ${item}) == "1" ]]; then
echo "${item} is installed already. Skipping installation"
else
echo "${item} is either not installed or not available. Attempting installation..."
sudo -H -iu ${ConsoleUser} /opt/homebrew/bin/brew install --cask ${item}
fi
else
# Intel machines
cd /tmp/ # This is required to use sudo as another user or you get a getcwd error
if [[ $(sudo -H -iu ${ConsoleUser} /usr/local/bin/brew list --casks | grep -c ${item}) == "1" ]]; then
echo "${item} is installed already. Skipping installation"
else
echo "${item} is either not installed or not available. Attempting installation..."
sudo -H -iu ${ConsoleUser} /usr/local/bin/brew install --cask ${item}
fi
fi