Files
Alte_Skripte/VW Skripte/Scripte/500_Brew_Base_MUI_After-1.0.sh
2026-02-16 15:05:15 +01:00

106 lines
5.7 KiB
Bash

#!/bin/sh
set -x
#
# Script Name: installHomebrew.sh
# Function: Deploy Homebrew (brew.sh) to the first user added to a new Mac during the post-DEP enrollment SplashBuddy run
# Requirements: DEP, SplashBuddy
#
# Copyright 2018, Route 1337, LLC, All Rights Reserved.
#
# Maintainers:
# - Matthew Ahrenstein: matthew@route1337.com
#
# Contributors:
# - "Dakr-xv": https://github.com/Dakr-xv
#
# See LICENSE
#
# Apple approved way to get the currently logged in user (Thanks to Froger from macadmins.org and https://developer.apple.com/library/content/qa/qa1133/_index.html)
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 + "\n");')"
# Check to see if we have XCode already
checkForXcode=$( pkgutil --pkgs | grep com.apple.pkg.CLTools_Executables | wc -l | awk '{ print $1 }' )
JH="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
# If XCode is missing we will install the Command Line tools only as that's all Homebrew needs
if [[ "$checkForXcode" != 1 ]];
then
#osx_vers=$(sw_vers -productVersion | awk -F "." '{print $2}')
## This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
#touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
## Verify softwareupdate installs only the latest XCode (Original code from https://github.com/rtrouton/rtrouton_scripts)
#cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | grep "$osx_vers" | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-)
#if (( $(grep -c . <<<"$cmd_line_tools") > 1 )); then
# cmd_line_tools_output="$cmd_line_tools"
# cmd_line_tools=$(printf "$cmd_line_tools_output" | tail -1)
#fi
#softwareupdate -i "$cmd_line_tools"
#rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
#/usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
"$JH" -startlaunchd -windowType utility -description "Bitte erst die Xcode Commandline Tools installieren." -button1 "OK" -defaultButton 1 -lockHUD
exit 1
fi
CHECK=$(/usr/sbin/dseditgroup -o checkmember -m $ConsoleUser admin &> /dev/null ; echo $?)
echo "ERGEBINIS " $CHECK
if [[ $CHECK -gt 0 ]]
then
"$JH" -startlaunchd -windowType utility -description "Sie benötigen Admin-Rechte, damit die Installation fortgesetzt werden kann." -button1 "OK" -defaultButton 1 -lockHUD
exit 1
fi
# Test if Homebrew is installed and install it if it is not
if test ! "$(sudo -u $ConsoleUser which brew)"; then
# Jamf will have to execute all of the directory creation functions Homebrew normally does so we can bypass the need for sudo
/bin/chmod u+rwx /usr/local/bin
/bin/chmod g+rwx /usr/local/bin
/bin/mkdir -p /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
/bin/chmod g+rwx /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
/usr/sbin/chown $ConsoleUser /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/usr/bin/chgrp admin /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
/bin/mkdir -p /Users/$ConsoleUser/Library/Caches/Homebrew
/bin/chmod g+rwx /Users/$ConsoleUser/Library/Caches/Homebrew
/usr/sbin/chown $ConsoleUser /Users/$ConsoleUser/Library/Caches/Homebrew
/bin/mkdir -p /Library/Caches/Homebrew
/bin/chmod g+rwx /Library/Caches/Homebrew
/usr/sbin/chown $ConsoleUser /Library/Caches/Homebrew
# Install Homebrew as the currently logged in user
#/usr/bin/sudo -H -u $ConsoleUser /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" </dev/null
echo "#!/bin/sh" > /tmp/homebrewinstall
echo '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" </dev/null' >> /tmp/homebrewinstall
chmod +x /tmp/homebrewinstall
/usr/bin/sudo -u $ConsoleUser /bin/sh /tmp/homebrewinstall
# If Homebrew is already installed then just echo that it is already installed
else
echo "Homebrew is already installed"
"$JH" -startlaunchd -windowType utility -description "Homebrew ist bereits installiert." -button1 "OK" -defaultButton 1 -lockHUD
exit 0
fi
app="/usr/local/vwg/flag/Homebrew_Base_MUI.app"
rm -rf "${app}"
zipfile="/tmp/Homebrew_Base_MUI.app.zip"
rm -rf "${zipfile}"
sudo uudecode -o "${zipfile}" << 'EOD'
begin-base64 700 Homebrew_Base_MUI.app.zip
====
EOD
unzip "$zipfile" -d "/usr/local/vwg/flag"
rm -rf "${zipfile}"
sudo chmod -r 755 "${app}"
sudo chown root:wheel "${app}"