Posted on 06-28-2022 11:52 AM
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
Posted on 07-07-2022 06:56 AM
Two questions:
1) Where is it getting stuck?
2) How do you have "/usr/local/bin/jamf policy -event brew" set up?
Posted on 03-09-2023 12:30 PM
Did you ever figure this out? This is the script I'm currently using and it works great.
#!/bin/bash
# Script to install Homebrew on a Mac.
# Author: richard at richard - purves dot com
# Version: 1.0 - 21st May 2017
# Heavily hacked by Tony Williams (honestpuck@gmail.com)
# Latest version at https://github.com/Honestpuck/homebrew.sh
# v2.0 - 19th Sept 2019
# v2.0.1 Fixed global cache error
# v2.0.2 Fixed brew location error
# v2.0.3 Added more directories to handle
# v3.0 Catalina version 2020-02-17
# v3.1 | 2020-03-24 | Fix permissions for /private/tmp
# v3.2 2020-07-18 Added Caskroom to directories created and added check for binary
# update if it exists then exit
# Set up variables and functions here
consoleuser="$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')"
if [[ -e /usr/local/bin/brew ]]; then
su -l "$consoleuser" -c "/usr/local/bin/brew update"
exit 0
fi
# are we in the right group
check_grp=$(groups ${consoleuser} | grep -c '_developer')
if [[ $check_grp != 1 ]]; then
/usr/sbin/dseditgroup -o edit -a "${consoleuser}" -t user _developer
fi
# Logging stuff starts here
LOGFOLDER="/private/var/log/"
LOG="${LOGFOLDER}Homebrew.log"
if [ ! -d "$LOGFOLDER" ]; then
mkdir $LOGFOLDER
fi
function logme()
{
# Check to see if function has been called correctly
if [ -z "$1" ] ; then
echo "$(date) - logme function call error: no text passed to function! Please recheck code!"
echo "$(date) - logme function call error: no text passed to function! Please recheck code!" >> $LOG
exit 1
fi
# Log the passed details
echo -e "$(date) - $1" >> $LOG
echo -e "$(date) - $1"
}
# Check and start logging
logme "Homebrew Installation"
# Have the xcode command line tools been installed?
logme "Checking for Xcode Command Line Tools installation"
check=$( pkgutil --pkgs | grep -c "CLTools_Executables" )
if [[ "$check" != 1 ]]; then
logme "Installing Xcode Command Tools"
# This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
clt=$(softwareupdate -l | grep -B 1 -E "Command Line (Developer|Tools)" | awk -F"*" '/^ +\*/ {print $2}' | sed 's/^ *//' | tail -n1)
# the above don't work in Catalina so ...
if [[ -z $clt ]]; then
clt=$(softwareupdate -l | grep "Label: Command" | tail -1 | sed 's#* Label: (.*)#1#')
fi
softwareupdate -i "$clt"
rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
/usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
fi
# Is homebrew already installed?
if [[ ! -e /usr/local/bin/brew ]]; then
# Install Homebrew. This doesn't like being run as root so we must do this manually.
logme "Installing Homebrew"
mkdir -p /usr/local/Homebrew
# Curl down the latest tarball and install to /usr/local
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C /usr/local/Homebrew
# Manually make all the appropriate directories and set permissions
mkdir -p /usr/local/Cellar /usr/local/Homebrew mkdir /usr/local/Caskroom /usr/local/Frameworks /usr/local/bin
mkdir -p /usr/local/include /usr/local/lib /usr/local/opt /usr/local/etc /usr/local/sbin
mkdir -p /usr/local/share/zsh/site-functions /usr/local/var
mkdir -p /usr/local/share/doc /usr/local/man/man1 /usr/local/share/man/man1
chown -R "${consoleuser}":_developer /usr/local/*
chmod -R g+rwx /usr/local/*
chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
# Create a system wide cache folder
mkdir -p /Library/Caches/Homebrew
chmod g+rwx /Library/Caches/Homebrew
chown "${consoleuser}:_developer" /Library/Caches/Homebrew
# put brew where we can find it
ln -s /usr/local/Homebrew/bin/brew /usr/local/bin/brew
# Install the MD5 checker or the recipes will fail
su -l "$consoleuser" -c "/usr/local/bin/brew install md5sha1sum"
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' |
tee -a /Users/${consoleuser}/.bash_profile /Users/${consoleuser}/.zshrc
chown ${consoleuser} /Users/${consoleuser}/.bash_profile /Users/${consoleuser}/.zshrc
# clean some directory stuff for Catalina
chown -R root:wheel /private/tmp
chmod 777 /private/tmp
chmod +t /private/tmp
fi
# Make sure everything is up to date
logme "Updating Homebrew"
su -l "$consoleuser" -c "/usr/local/bin/brew update" 2>&1 | tee -a ${LOG}
# logme user that all is completed
logme "Installation complete"
exit 0