-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathinstall-macOSBigSur.sh
396 lines (340 loc) · 19 KB
/
install-macOSBigSur.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#!/bin/bash
# Created by rcoleman
# Main spine of the code taken from here: https://github.com/laurentpertois/BigSur-Compatibility-Checker/blob/master/BigSur-Compatibility-Checker.sh
#*********** GLOBAL VARIABLES ***********
# Log file location
LOGFILE="/Library/Logs/macOSBigSur-upgrade.log"
# Jamf binary location
JAMF_BINARY="/usr/local/jamf/bin/jamf"
# Declare jamf helper location
JAMF_HELPER="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
# BigSur icon
BIGSUR_ICON="/usr/local/jamf/BigSurInstallAssistant.png"
# Jamf helper title
JH_TITLE="macOS Big Sur Upgrade"
# Jamf helper initial description
JH_DESCRIPTION="Checking your device meets the minimum requirements for upgrading to Big Sur..."
# Error icon location
ERROR_ICON="/usr/local/jamf/Error.png"
# Warning icon
WARNING_ICON="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"
# IBM Notifier options - in testing
# Notifier app
#NOTIFIER="/Applications/Utilities/IBM Notifier.app/Contents/MacOS/IBM Notifier"
# Notifier icon
#NOTIFIER_ICON="/Applications/Utilities/IBM Notifier.app/Contents/Resources/AppIcon.icns"
# Call notifier
#"$NOTIFIER" -type popup -bar_title "$JH_TITLE" -title "$JH_DESCRIPTION" -icon_path "$NOTIFIER_ICON" -no_button
# Function for obtaining timestamp
timestamp() {
while read -r line
do
TIMESTAMP=$(date)
echo "[$TIMESTAMP] $line"
done
}
# Function for dealing with jamf helper - no buttons
jamf_helper_no_buttons () {
# Declare variables
local TITLE="$1"
local ICON="$2"
local HEADING="$3"
local DESCRIPTION="$4"
# Display jamf helper window
"$JAMF_HELPER" -windowType utility \
-title "$TITLE" \
-icon "$ICON" \
-heading "$HEADING" \
-description "$DESCRIPTION"
}
# Function for dealing with jamf helper - one button
jamf_helper_one_button () {
# Declare variables
local TITLE="$1"
local ICON="$2"
local HEADING="$3"
local DESCRIPTION="$4"
local BUTTON1="$5"
# Display jamf helper window
local RETURN_VALUE=$("$JAMF_HELPER" -windowType utility \
-title "$TITLE" \
-icon "$ICON" \
-heading "$HEADING" \
-description "$DESCRIPTION" \
-button1 "$BUTTON1")
# Return button value
echo "${RETURN_VALUE}"
}
# Function for dealing with jamf helper - two buttons
jamf_helper_two_buttons () {
# Declare variables
local TITLE="$1"
local ICON="$2"
local HEADING="$3"
local DESCRIPTION="$4"
local BUTTON1="$5"
local BUTTON2="$6"
local DEFAULT_BUTTON="$7"
# Display jamf helper window
local RETURN_VALUE=$("$JAMF_HELPER" -windowType utility \
-title "$TITLE" \
-icon "$ICON" \
-heading "$HEADING" \
-description "$DESCRIPTION" \
-button1 "$BUTTON1" \
-button2 "$BUTTON2" \
-defaultButton "$DEFAULT_BUTTON")
# Return button value
echo "${RETURN_VALUE}"
}
# ************ MAIN **************
echo "Displaying initial jamf helper window." | timestamp 2>&1 | tee -a $LOGFILE
# Display initial jamf helper window
"$JAMF_HELPER" -windowType utility -title "$JH_TITLE" -icon "$BIGSUR_ICON" -heading "$JH_HEADING" -description "$JH_DESCRIPTION" &
# Wait a few seconds
sleep 5s
# Get build version
OS_VERSION_MAJOR=$(sw_vers -buildVersion | cut -c 1-2)
echo "Major build version of OS is $OS_VERSION_MAJOR" | timestamp 2>&1 | tee -a $LOGFILE
# Declare required minimum RAM
REQUIRED_MINIMUM_RAM=4
# Set default COMPATIBILITY to false
COMPATIBILITY="False"
# Global for MINIMUM_MODEL
MINIMUM_MODEL=""
# If we are running High Sierra or higher
if [[ "$OS_VERSION_MAJOR" -ge 16 ]]; then
# For Sierra and higher required space is 12.3GB for the installer and 35.5GB for required disk space for installation which equals to 47.8GB, 50GB is giving a bit of extra free space for safety
echo "Device running macOS 10.13 or higher. Minimum space required is 50GB." | timestamp 2>&1 | tee -a $LOGFILE
REQUIRED_MINIMUM_SPACE=50
# Else we are running 10.12 or below
else
echo "Device running a pre-10.12 macOS. Minimum space required is 60GB." | timestamp 2>&1 | tee -a $LOGFILE
# For pre-Sierra required space is 12.3GB for the installer and 44.5GB for required disk space for installation which equals to 56.8GB, 60GB is giving a bit of extra free space for safety
REQUIRED_MINIMUM_SPACE=60
fi
# Make sure we are not running Monterey or above!
if [[ "$OS_VERSION_MAJOR" -ge 21 ]]; then
echo "Device appears to be running macOS 12 Monterey. Quitting Big Sur install." | timestamp 2>&1 | tee -a $LOGFILE
jamf_helper_one_button "$JH_TITLE" "$ERROR_ICON" "Cannot upgrade!" "You already appear to be running macOS 12 (Monterey) or above. Big Sur is macOS 11 and would be a downgrade." "Cancel"
# Make sure no instances of jamf helper are running
killall jamfHelper 2> /dev/null
exit 0;
fi
# See if we are already running BigSur
if [[ "$OS_VERSION_MAJOR" -eq 20 ]]; then
echo "Device already appears to be running macOS 11 Big Sur." | timestamp 2>&1 | tee -a $LOGFILE
BIGSUR_CONFIRM=$(jamf_helper_two_buttons "$JH_TITLE" "$BIGSUR_ICON" "Detected current Big Sur installation" "You already appear to be running macOS 11 (Big Sur). You can continue with this installation if you wish, however please note that your Operating System will not be upgraded.
Re-installing Big Sur may resolve some stability issues if you are experiencing performance problems.
Do you wish to continue?" "Continue" "Cancel" "2")
# If user has canceled then quit
if [ "$BIGSUR_CONFIRM" = 2 ]; then
echo "User has selected to cancel the process. Qutting..." | timestamp 2>&1 | tee -a $LOGFILE
# Kill current jamf helper window
killall jamfHelper 2> /dev/null
exit 0;
fi
fi
# Make sure we are at least running 10.9 (Mavericks)
if ! [[ "$OS_VERSION_MAJOR" -ge 13 && "$OS_VERSION_MAJOR" -le 20 ]]; then
echo "Device does not appear to be running at least 10.9." | timestamp 2>&1 | tee -a $LOGFILE
OS=$(sw_vers -productVersion)
echo "Appears to be running macOS $OS" | timestamp 2>&1 | tee -a $LOGFILE
# Kill initial jamf helper window
killall jamfHelper 2> /dev/null
echo "Displaying error message and quitting." | timestamp 2>&1 | tee -a $LOGFILE
# Display error message
jamf_helper_one_button "$JH_TITLE" "$ERROR_ICON" "Cannot upgrade!" "This process cannot complete the upgrade.
Cause - Your device must currently be running macOS 10.9 (Mavericks) or later to install this upgrade.
Please upgrade your Operating System to at least 10.9." "Cancel"
# Make sure all instances of jamf helper are closed
killall jamfHelper 2> /dev/null
# exit
exit 0;
fi
# If we've not hit any issues so far then kill all jamfHelper windows
killall jamfHelper 2> /dev/null
# If the OS is between 10.9 and 10.15 inclusive
if [[ "$OS_VERSION_MAJOR" -ge 13 && "$OS_VERSION_MAJOR" -le 20 ]]; then
# Make sure we are plugged in to mains power outlet
AC_POWER=$(pmset -g ps | grep "AC Power")
# If nothing is returned, then we are not on AC
if ! [[ "$AC_POWER" ]]; then
echo "Not plugged in to AC Mains. Displaying notification to user and waiting until AC power is plugged in or cancel is selected..." | timestamp 2>&1 | tee -a $LOGFILE
# Show jamf helper window. Will didplay until either cancel is selected or mains power is plugged in
jamf_helper_one_button "$JH_TITLE" "$WARNING_ICON" "Mains power warning" "The device does not appear to be plugged in to a mains power outlet!
The process will continue as soon as you plug the device into a mains power outlet.
If you wish to cancel the upgrade, please select cancel below." "Cancel" &
# Loop until power is plugged in or cancel is selected
while ! [[ "$AC_POWER" ]]; do
# If user selects to cancel then there will be no jamfHelper process running. Check and see if it's running. If not then quit.
# Get the current jamfHelper process as this will be the window above
# JH_PID=$( ps -A | grep "jamfHelper" | awk '{print $1}')
if ! pgrep -x "jamfHelper" /dev/null; then
echo "User has selected to cancel upgrade. Quitting." | timestamp 2>&1 | tee -a $LOGFILE
# Just make sure all instances of jamfhelper are closed
killall jamfHelper 2> /dev/null
exit 0;
fi
# Obtain AC_POWER value again
AC_POWER=$(pmset -g ps | grep "AC Power")
done
# Kill the jamfHelper window
killall jamfHelper 2> /dev/null
echo "Device now plugged in to AC power." | timestamp 2>&1 | tee -a $LOGFILE
else
echo "Device already plugged in to AC power." | timestamp 2>&1 | tee -a $LOGFILE
fi
echo "We have a compatible OS. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
# Transform GB into Bytes
GB=$((1024 * 1024 * 1024))
MINIMUM_RAM=$(($REQUIRED_MINIMUM_RAM * $GB))
MINIMUM_SPACE=$(($REQUIRED_MINIMUM_SPACE * $GB))
# Gets the Model Identifier, splits name and major version
MODEL_IDENTIFIER=$(/usr/sbin/sysctl -n hw.model)
MODEL_NAME=$(echo "$MODEL_IDENTIFIER" | sed 's/[^a-zA-Z]//g')
MODEL_VERSION=$(echo "$MODEL_IDENTIFIER" | sed -e 's/[^0-9,]//g' -e 's/,//')
# Gets amount of memory installed
MEMORY_INSTALLED=$(/usr/sbin/sysctl -n hw.memsize)
echo "Installed RAM is $MEMORY_INSTALLED." | timestamp 2>&1 | tee -a $LOGFILE
# Gets free space on the boot drive
FREE_SPACE=$(diskutil info / | awk -F '[()]' '/Free Space|Available Space/ {print $2}' | sed -e 's/\ Bytes//')
echo "Free hard drive space is $FREE_SPACE." | timestamp 2>&1 | tee -a $LOGFILE
# Get the model of mac, and set the name of the minimum model required for upgrade
if [[ "$MODEL_NAME" == "iMac" ]]; then
MINIMUM_MODEL="iMac (2014 or later)"
elif [[ "$MODEL_NAME" == "iMacPro" ]]; then
MINIMUM_MODEL="iMac Pro (2017 or later)"
elif [[ "$MODEL_NAME" == "Macmini" ]]; then
MINIMUM_MODEL="Mac mini (2014 or later)"
elif [[ "$MODEL_NAME" == "MacPro" ]]; then
MINIMUM_MODEL="Mac Pro (2013 or later)"
elif [[ "$MODEL_NAME" == "MacBook" ]]; then
MINIMUM_MODEL="MacBook (2015 or later)"
elif [[ "$MODEL_NAME" == "MacBookAir" ]]; then
MINIMUM_MODEL="MacBook Air (2013 or later)"
elif [[ "$MODEL_NAME" == "MacBookPro" ]]; then
MINIMUM_MODEL="MacBook Pro (Late 2013 or later)"
else
# If we can't get a model then quit.
echo "Cannot detect model." | timestamp 2>&1 | tee -a $LOGFILE
jamf_helper_one_button "$JH_TITLE" "$ERROR_ICON" "Cannot upgrade!" "The upgrade has failed due to not being able to detect the model type of your device.
If the installer (Install macOS Big Sur.app) exists in your Applications folder, then you can attempt to run this manually to upgrade.
If this still fails and you are unable to determine why, please contact IS Helpline for assistance:
https://edin.ac/helpline
This installer will now quit." "Quit"
# Making sure all instances of jamf helper are closed
killall jamfHelper 2> /dev/null
# Exit
exit 1;
fi
# Checks if computer meets pre-requisites for Big Sur
if [[ "$MODEL_NAME" == "iMac" && "$MODEL_VERSION" -ge 144 && "$MEMORY_INSTALLED" -ge "$MINIMUM_RAM" && "$FREE_SPACE" -ge "$MINIMUM_SPACE" ]]; then
COMPATIBILITY="True"
echo "Device is an iMac and appears to be compatible. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
elif [[ "$MODEL_NAME" == "iMacPro" && "$MODEL_VERSION" -ge 10 && "$MEMORY_INSTALLED" -ge "$MINIMUM_RAM" && "$FREE_SPACE" -ge "$MINIMUM_SPACE" ]]; then
COMPATIBILITY="True"
echo "Device is an iMacPro and appears to be compatible. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
elif [[ "$MODEL_NAME" == "Macmini" && "$MODEL_VERSION" -ge 70 && "$MEMORY_INSTALLED" -ge "$MINIMUM_RAM" && "$FREE_SPACE" -ge "$MINIMUM_SPACE" ]]; then
COMPATIBILITY="True"
echo "Device is a Macmini and appears to be compatible. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
elif [[ "$MODEL_NAME" == "MacPro" && "$MODEL_VERSION" -ge 60 && "$MEMORY_INSTALLED" -ge "$MINIMUM_RAM" && "$FREE_SPACE" -ge "$MINIMUM_SPACE" ]]; then
COMPATIBILITY="True"
echo "Device is a MacPro and appears to be compatible. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
elif [[ "$MODEL_NAME" == "MacBook" && "$MODEL_VERSION" -ge 80 && "$MEMORY_INSTALLED" -ge "$MINIMUM_RAM" && "$FREE_SPACE" -ge "$MINIMUM_SPACE" ]]; then
COMPATIBILITY="True"
echo "Device is a MacBook and appears to be compatible. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
elif [[ "$MODEL_NAME" == "MacBookAir" && "$MODEL_VERSION" -ge 60 && "$MEMORY_INSTALLED" -ge "$MINIMUM_RAM" && "$FREE_SPACE" -ge "$MINIMUM_SPACE" ]]; then
COMPATIBILITY="True"
echo "Device is a MacBook Air and appears to be compatible. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
elif [[ "$MODEL_NAME" == "MacBookPro" && "$MODEL_VERSION" -ge 110 && "$MEMORY_INSTALLED" -ge "$MINIMUM_RAM" && "$FREE_SPACE" -ge "$MINIMUM_SPACE" ]]; then
COMPATIBILITY="True"
echo "Device is a MacBook Pro and appears to be compatible. Moving on..." | timestamp 2>&1 | tee -a $LOGFILE
else
# Convert bytes back to GB
FREE_SPACE_GB=$(($FREE_SPACE / 1024 / 1024 / 1024))
RAM_GB=$(($MEMORY_INSTALLED / 1024 / 1024 / 1024))
echo "Currently installed OS appears to meet minimum requirements, however the device has failed to meet one of the following requirements:" | timestamp 2>&1 | tee -a $LOGFILE
echo " " | tee -a $LOGFILE
echo " - The model of mac is not compatible with Big Sur. Model required for Big Sur - $MINIMUM_MODEL" | tee -a $LOGFILE
echo " - The device does not have a minimum of 4 GB RAM. Only has $RAM_GB GB." | tee -a $LOGFILE
echo " - The device does not have enough free space on the hard drive. Only has $FREE_SPACE_GB GB." | tee -a $LOGFILE
echo " " | tee -a $LOGFILE
echo "Killing jamf helper window and quitting." | timestamp 2>&1 | tee -a $LOGFILE
# Kill initial jamf helper window
killall jamfHelper 2> /dev/null
# If conditions above have not been met then most likely not compatible. Display error message.
jamf_helper_one_button "$JH_TITLE" "$ERROR_ICON" "Cannot upgrade!" "This process cannot complete the upgrade due to one of the following reasons:
- Your model of Mac does not meet Apple's minimum requirement for installing Big Sur. Minimum model required: $MINIMUM_MODEL
- Your device does not have a minimum of 4 GB RAM. Amount of installed RAM is: $RAM_GB GB
- You do not have enough free space on your hard drive (50GB required). Amount of free space available: $FREE_SPACE_GB GB.." "Quit"
# Making sure all instances of jamf helper are closed
killall jamfHelper 2> /dev/null
# Exit
exit 0;
fi
fi
# If compatibility is true then start downloading the installer
if [[ "$COMPATIBILITY" == "True" ]]; then
echo "Device appears to meet all minimum requirements. Getting confirmnation from user that we should proceed." | timestamp 2>&1 | tee -a $LOGFILE
# Kill initial jamf helper window
killall jamfHelper 2> /dev/null
# Display confirmation jamf helper window
BUTTON_CLICKED=$(jamf_helper_two_buttons "$JH_TITLE" "$BIGSUR_ICON" "Installing Big Sur" "The Big Sur installer will now download to your Applications folder and then the process will begin. Please make sure you have done the following -
1 - Backed up any local data. Although this upgrade should keep all data intact, we would recommend you backup before running this process.
2 - Close all applications.
3 - Make sure the device is plugged into a mains power outlet.
4 - If you use any specialised applications, check the application manufacturer's website to make sure it is compatible with macOS Big Sur.
Please note that this is a large installer (around 12 GB) that may take several hours to download and install depending on your network speed.
After downloading, the installer will begin in the background. The device will be restarted without warning. Please make sure you have saved your data.
After selecting to continue below, the process will begin and you will not be able to cancel.
Do you wish to continue?" "Continue" "Cancel" "2")
# If 2 is returned then user has selected to cancel
if [ "$BUTTON_CLICKED" == 2 ]; then
echo "User has selected to cancel the process. Qutting..." | timestamp 2>&1 | tee -a $LOGFILE
# Kill current jamf helper window
killall jamfHelper 2> /dev/null
exit 0;
else
echo "User has continued with the process. Showing jamf helper download window." | timestamp 2>&1 | tee -a $LOGFILE
# Kill current jamf helper window
killall jamfHelper 2> /dev/null
# Display jamf helper download window
jamf_helper_no_buttons "$JH_TITLE" "$BIGSUR_ICON" "Downloading Big Sur" "Downloading the Big Sur installer.
This window will close when the application starts to install.
Warning: This process will restart the computer without notification. Please save your data NOW.
Also, please make sure that your device is plugged in to a mains power outlet.
This may take a while. Please be patient." &
echo "Running jamf trigger to download Big Sur." | timestamp 2>&1 | tee -a $LOGFILE
"$JAMF_BINARY" policy -event upgrade-to-BigSur
# Get exit status of last command
POLICY_STATUS=$?
echo "Download complete. Preparing Big Sur install..." | timestamp 2>&1 | tee -a $LOGFILE
# Kill current jamf helper window
killall jamfHelper 2> /dev/null
# Display jamf helper download window
jamf_helper_no_buttons "Installing macOS Big Sur" "$BIGSUR_ICON" "Installing macOS Big Sur" "Download is now complete. Preparing Big Sur install...
Warning: This process will restart the computer without notification. Please save your data NOW.
Also, please make sure that your device is plugged in to a mains power outlet.
This may take a while. Please be patient." &
# Check that last command executed successfully. If it's not equal to 0 then we have a problem.
if [ "$POLICY_STATUS" -ne 0 ]; then
echo "Installing from Self service has returned an error. Please check policy log in JSS for further details. " | timestamp 2>&1 | tee -a $LOGFILE
# Quit all instances of jamf helper
killall jamfHelper 2> /dev/null
# Show new error window
jamf_helper_one_button "$JH_TITLE" "$WARNING_ICON" "Possible issue upgrading!" "The upgrade has encountered a possible issue. If the device doesn't restart automatically within the next few minutes to begin the upgrade, you can check to see if the installer (Install macOS Big Sur.app) exists in your Applications folder.
If so, then you can attempt to run this manually to upgrade.
If this still fails and you are unable to determine why, or if the installer does not exist within your Applications folder, please contact IS Helpline for assistance:
https://edin.ac/helpline
" "OK"
# Making sure all instances of jamf helper are closed
killall jamfHelper 2> /dev/null
# Exit
exit 1;
fi
fi
else
echo "Problem downloading installer. Check policy log in JSS for more details. Quitting..." | timestamp 2>&1 | tee -a $LOGFILE
exit 1;
fi