-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinalise.sh
executable file
·58 lines (44 loc) · 2.5 KB
/
finalise.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
51
52
53
54
55
56
57
58
#!/bin/bash
# Xcode finalisation script
# Lots of code curtesy of the Munki wiki pages: https://github.com/munki/munki/wiki/Xcode
# Set up variables and functions here
consoleuser="$(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");')"
brandid="com.application.id"
tn="/path/to/terminal-notifier.app/Contents/MacOS/terminal-notifier"
# Let's start here by caffinating the mac so it stays awake or bad things happen.
caffeinate -d -i -m -u &
caffeinatepid=$!
# Notify the user that things are happening
su -l "$consoleuser" -c " "'"'$tn'"'" -sender "'"'$brandid'"'" -title "'"Xcode Install"'" -message "'"Starting Xcode finalisation"'" "
sleep 3
# make sure all users on this machine are members of the _developer group
/usr/sbin/dseditgroup -o edit -a everyone -t group _developer
# enable developer mode
/usr/sbin/DevToolsSecurity -enable
# accept Xcode license
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -license accept
# install embedded packages
for PKG in /Applications/Xcode.app/Contents/Resources/Packages/*.pkg
do
name=$( echo $PKG | cut -c53- )
su -l "$consoleuser" -c " "'"'$tn'"'" -sender "'"'$brandid'"'" -title "'"Xcode Install"'" -message "'"Installing '$name'"'" "
/usr/sbin/installer -pkg "$PKG" -target /
done
# disable version check for MobileDeviceDevelopment
/usr/bin/defaults write /Library/Preferences/com.apple.dt.Xcode DVTSkipMobileDeviceFrameworkVersionChecking -bool true
# alter authorisation database to allow installation of apple components without admin rights
security authorizationdb read system.install.apple-software > /tmp/xcode.plist
defaults write /tmp/xcode.plist rule -array authenticate-session-owner-or-admin
security authorizationdb write system.install.apple-software < /tmp/xcode.plist
# Rename Xcode so it has it's version number on the App. Allows us to have multiple xcode versions installed.
version=$( defaults read /Applications/Xcode.app/Contents/Info.plist CFBundleShortVersionString )
if [ ! -d "/Applications/Xcode-$version.app" ];
then
mv "/Applications/Xcode.app/" "/Applications/Xcode-$version.app"
else
rm -rf "/Applications/Xcode.app/"
fi
# Notify user all is done
su -l "$consoleuser" -c " "'"'$tn'"'" -title "'"Xcode Install"'" -message "'"Xcode install completed!"'" "
# No more caffeine please. I've a headache.
kill "$caffeinatepid"