/
10.12_first_boot.sh
201 lines (166 loc) · 7.64 KB
/
10.12_first_boot.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/sh
# Created by Amsys
#
# Use at your own risk. Amsys will accept
# no responsibility for loss or damage
# caused by this script.
#
# Requires 10.10 or higher.
###############
## variables ##
###############
# Make sure to change these variables
LOCAL_ADMIN_FULLNAME="Local Administrator" # The local admin user's full name
LOCAL_ADMIN_SHORTNAME="ladmin" # The local admin user's shortname
LOCAL_ADMIN_PASSWORD="password" # The local admin user's password
KEYBOARDNAME="British" # Keyboard name
KEYBOARDCODE="2" # Keyboard layout code (currently set to British)
LANG="en" # macOS language
REGION="en_GB" # macOS region
SUBMIT_TO_APPLE=NO # Choose whether to submit diagnostic information to Apple
SUBMIT_TO_APP_DEVELOPERS=NO # Choose whether to submit diagnostic information to 3rd party developers
#### These variables can be left alone
PLBUDDY=/usr/libexec/PlistBuddy
SW_VERS=$(sw_vers -productVersion)
BUILD_VERS=$(sw_vers -buildVersion)
ARD="/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart"
CRASHREPORTER_SUPPORT="/Library/Application Support/CrashReporter"
CRASHREPORTER_DIAG_PLIST="${CRASHREPORTER_SUPPORT}/DiagnosticMessagesHistory.plist"
#############################################
######## Do not edit below this line ########
#############################################
###############
## functions ##
###############
update_kdb_layout() {
${PLBUDDY} -c "Delete :AppleCurrentKeyboardLayoutInputSourceID" "${1}" &>/dev/null
if [ ${?} -eq 0 ]
then
${PLBUDDY} -c "Add :AppleCurrentKeyboardLayoutInputSourceID string com.apple.keylayout.${KEYBOARDNAME}" "${1}"
fi
for SOURCE in AppleDefaultAsciiInputSource AppleCurrentAsciiInputSource AppleCurrentInputSource AppleEnabledInputSources AppleSelectedInputSources
do
${PLBUDDY} -c "Delete :${SOURCE}" "${1}" &>/dev/null
if [ ${?} -eq 0 ]
then
${PLBUDDY} -c "Add :${SOURCE} array" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0 dict" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0:InputSourceKind string 'Keyboard Layout'" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0:KeyboardLayout\ ID integer ${KEYBOARDCODE}" "${1}"
${PLBUDDY} -c "Add :${SOURCE}:0:KeyboardLayout\ Name string '${KEYBOARDNAME}'" "${1}"
fi
done
}
update_language() {
${PLBUDDY} -c "Delete :AppleLanguages" "${1}" &>/dev/null
if [ ${?} -eq 0 ]
then
${PLBUDDY} -c "Add :AppleLanguages array" "${1}"
${PLBUDDY} -c "Add :AppleLanguages:0 string '${LANG}'" "${1}"
fi
}
update_region() {
${PLBUDDY} -c "Delete :AppleLocale" "${1}" &>/dev/null
${PLBUDDY} -c "Add :AppleLocale string ${REGION}" "${1}" &>/dev/null
${PLBUDDY} -c "Delete :Country" "${1}" &>/dev/null
${PLBUDDY} -c "Add :Country string ${REGION:3:2}" "${1}" &>/dev/null
}
################
#### Script ####
################
# Change Keyboard Layout
update_kdb_layout "/Library/Preferences/com.apple.HIToolbox.plist" "${KEYBOARDNAME}" "${KEYBOARDCODE}"
for HOME in /Users/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
HITOOLBOX_FILES=`find . -name "com.apple.HIToolbox.*plist"`
for HITOOLBOX_FILE in ${HITOOLBOX_FILES}
do
update_kdb_layout "${HITOOLBOX_FILE}" "${KEYBOARDNAME}" "${KEYBOARDCODE}"
done
fi
done
# Set the computer language
update_language "/Library/Preferences/.GlobalPreferences.plist" "${LANG}"
for HOME in /Users/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
GLOBALPREFERENCES_FILES=`find . -name "\.GlobalPreferences.*plist"`
for GLOBALPREFERENCES_FILE in ${GLOBALPREFERENCES_FILES}
do
update_language "${GLOBALPREFERENCES_FILE}" "${LANG}"
done
fi
done
# Set the region
update_region "/Library/Preferences/.GlobalPreferences.plist" "${REGION}"
for HOME in /Users/*
do
if [ -d "${HOME}"/Library/Preferences ]
then
cd "${HOME}"/Library/Preferences
GLOBALPREFERENCES_FILES=`find . -name "\.GlobalPreferences.*plist"`
for GLOBALPREFERENCES_FILE in ${GLOBALPREFERENCES_FILES}
do
update_region "${GLOBALPREFERENCES_FILE}" "${REGION}"
done
fi
done
# Create a local admin user account
sysadminctl -addUser $LOCAL_ADMIN_SHORTNAME -fullName "$LOCAL_ADMIN_FULLNAME" -password "$LOCAL_ADMIN_PASSWORD" -admin
dscl . create /Users/$LOCAL_ADMIN_SHORTNAME IsHidden 1 # Hides the account (10.10 and above)
mv /Users/$LOCAL_ADMIN_SHORTNAME /var/$LOCAL_ADMIN_SHORTNAME # Moves the admin home folder to /var
dscl . -create /Users/$LOCAL_ADMIN_SHORTNAME NFSHomeDirectory /var/$LOCAL_ADMIN_SHORTNAME # Create new home dir attribute
dscl . -delete "/SharePoints/$LOCAL_ADMIN_FULLNAME's Public Folder" # Removes the public folder sharepoint for the local admin
# Supress first run screens at login (iCloud, Siri & Diagnostics)
for USER_TEMPLATE in "/System/Library/User Template"/*
do
/usr/bin/defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant DidSeeCloudSetup -bool TRUE
/usr/bin/defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant GestureMovieSeen none
/usr/bin/defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant DidSeeSiriSetup -bool TRUE
/usr/bin/defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant LastSeenCloudProductVersion "${SW_VERS}"
/usr/bin/defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant LastSeenCloudProductVersion "${SW_VERS}"
/usr/bin/defaults write "${USER_TEMPLATE}"/Library/Preferences/com.apple.SetupAssistant LastSeenBuddyBuildVersion "${BUILD_VERS}"
done
# Disable diagnostics pop-up on 10.10 and above
if [ ! -d "${CRASHREPORTER_SUPPORT}" ]; then
mkdir "${CRASHREPORTER_SUPPORT}"
chmod 775 "${CRASHREPORTER_SUPPORT}"
chown root:admin "${CRASHREPORTER_SUPPORT}"
fi
for key in AutoSubmit AutoSubmitVersion ThirdPartyDataSubmit ThirdPartyDataSubmitVersion; do
$PLBUDDY -c "Delete :$key" "${CRASHREPORTER_DIAG_PLIST}" 2> /dev/null
done
$PLBUDDY -c "Add :AutoSubmit bool ${SUBMIT_TO_APPLE}" "${CRASHREPORTER_DIAG_PLIST}"
$PLBUDDY -c "Add :AutoSubmitVersion integer 4" "${CRASHREPORTER_DIAG_PLIST}"
$PLBUDDY -c "Add :ThirdPartyDataSubmit bool ${SUBMIT_TO_APP_DEVELOPERS}" "${CRASHREPORTER_DIAG_PLIST}"
$PLBUDDY -c "Add :ThirdPartyDataSubmitVersion integer 4" "${CRASHREPORTER_DIAG_PLIST}"
# Set the time zone to London
/usr/sbin/systemsetup -settimezone "Europe/London"
# Enable network time servers
/usr/sbin/systemsetup -setusingnetworktime on
# Configure a specific NTP server
/usr/sbin/systemsetup -setnetworktimeserver "time.euro.apple.com"
# Switch on Apple Remote Desktop
$ARD -configure -activate
# Configure ARD access for the local admin user
$ARD -configure -access -on
$ARD -configure -allowAccessFor -specifiedUsers
$ARD -configure -access -on -users $LOCAL_ADMIN_SHORTNAME -privs -all
# Enable SSH
systemsetup -setremotelogin on
# Configure Login Window to username and password text fields
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow SHOWFULLNAME -bool true
# Enable admin info at the Login Window
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow AdminHostInfo HostName
# Show input menu in Login Window
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow showInputMenu 1
# Disable External Accounts at the Login Window
/usr/bin/defaults write /Library/Preferences/com.apple.loginwindow EnableExternalAccounts -bool false
# Flush the JAMF policy history for this computer
jamf flushPolicyHistory
exit 0