Home brew install for M1 and Intel

Rarsf
New Contributor

Does anyone have a good way to auto install homebrew for apple silicon and intel?

 

Previously I used this script but it's getting stuck.

 

#!/bin/sh

# Set variables for the logged in user
loggedInUser=$(stat -f "%Su" /dev/console)

#Obtain processor type and add to variable
processor=$(/usr/bin/uname -p)

# Check for Homebrew if it exists then update it otherwise install Homebrew
which -s brew
if [ where brew ]; then
echo "Homebrew is installed ...moving on"
else
echo "Homebrew is not currently installed. Installing..."
/usr/local/bin/jamf policy -event brew
fi

# Create elevated permissions during install
echo "$loggedInUser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/elevated

# Adjust permissions to elevated
chmod 440 /etc/sudoers.d/elevated
chown root:wheel /etc/sudoers.d/elevated

echo "$loggedInUser"

# Check processor architecture type and run command according to processor
if [ "$processor" = "arm" ]; then
echo "Installing brew app for M1"
sudo -u "$loggedInUser" /opt/homebrew/bin/brew reinstall --no-quarantine $4 || sudo -u "$loggedInUser" /opt/homebrew/bin/brew install --no-quarantine $4

elif [ "$processor" = "i386" ]; then
echo "Installing brew app for Intel"
sudo -u "$loggedInUser" /usr/local/bin/brew reinstall --no-quarantine $4 || sudo -u "$loggedInUser" /usr/local/bin/brew install --no-quarantine $4
fi

# Run all the commands from before
rm /etc/sudoers.d/elevated

if [ -f "/etc/sudoers.d/elevated" ]; then
echo "WARNING YOU MUST REMOVE PERMISSIONS AUTOMATION HAS FAILED"
exit 1
else
echo "Permissions have been properly removed"
fi

exit 0

1 REPLY 1

roiegat
Contributor III

Two questions:

1) Where is it getting stuck?

2) How do you have "/usr/local/bin/jamf policy -event brew" set up?