-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTECH-SetupMyMac.sh
1613 lines (1258 loc) · 65.5 KB
/
TECH-SetupMyMac.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#!/bin/zsh
TESTING_MODE="true"
dialogbinary=/usr/local/bin/dialog
dialogcmdfile=/var/tmp/dialog.log
jamfhelper=/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
LocalAdmin="ladmin"
FDE_SETUP_BINARY="/usr/bin/fdesetup"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Script Version and Jamf Pro Script Parameters
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
scriptVersion="1.8.1"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/
scriptLog="${4:-"/var/log/org.simonsfoundation.swiftdialog.log"}" # Parameter 4: Script Log Location [ /var/log/org.churchofjesuschrist.log ] (i.e., Your organization's default location for client-side logs)
welcomeDialog="${6:-"userInput"}" # Parameter 6: Welcome dialog [ userInput (default) | video | false ]
completionActionOption="${7:-"Restart Attended"}" # Parameter 7: Completion Action [ wait | sleep (with seconds) | Shut Down | Shut Down Attended | Shut Down Confirm | Restart | Restart Attended (default) | Restart Confirm | Log Out | Log Out Attended | Log Out Confirm ]
requiredMinimumBuild="${8:-"disabled"}" # Parameter 8: Required Minimum Build [ disabled (default) | 22D ] (i.e., Your organization's required minimum build of macOS to allow users to proceed; use "22D" for macOS 13.2.x)
outdatedOsAction="${9:-"/System/Library/CoreServices/Software Update.app"}" # Parameter 9: Outdated OS Action [ /System/Library/CoreServices/Software Update.app (default) | jamfselfservice://content?entity=policy&id=117&action=view ] (i.e., Jamf Pro Self Service policy ID for operating system ugprades)
####################################################################################################
#
# Pre-flight Checks
#
####################################################################################################
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Client-side Logging
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if [[ ! -f "${scriptLog}" ]]; then
touch "${scriptLog}"
fi
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Client-side Script Logging Function
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function updateScriptLog() {
echo -e "$( date +%Y-%m-%d\ %H:%M:%S ) - ${1}" | tee -a "${scriptLog}"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Current Logged-in User Function
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function currentLoggedInUser() {
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
updateScriptLog "PRE-FLIGHT CHECK: Current Logged-in User: ${loggedInUser}"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Logging Preamble
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
updateScriptLog "PRE-FLIGHT CHECK: Initiating …"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Confirm script is running as root
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#if [[ $(id -u) -ne 0 ]]; then
# updateScriptLog "PRE-FLIGHT CHECK: This script must be run as root; exiting."
# exit 1
#fi
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Validate Setup Assistant has completed
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
while pgrep -q -x "Setup Assistant"; do
updateScriptLog "PRE-FLIGHT CHECK: Setup Assistant is still running; pausing for 2 seconds"
sleep 2
done
updateScriptLog "PRE-FLIGHT CHECK: Setup Assistant is no longer running; proceeding …"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Confirm Dock is running / user is at Desktop
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
until pgrep -q -x "Finder" && pgrep -q -x "Dock"; do
updateScriptLog "PRE-FLIGHT CHECK: Finder & Dock are NOT running; pausing for 1 second"
sleep 1
done
updateScriptLog "PRE-FLIGHT CHECK: Finder & Dock are running; proceeding …"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Validate Operating System Version and Build
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if [[ "${requiredMinimumBuild}" == "disabled" ]]; then
updateScriptLog "PRE-FLIGHT CHECK: 'requiredMinimumBuild' has been set to ${requiredMinimumBuild}; skipping OS validation."
updateScriptLog "PRE-FLIGHT CHECK: macOS ${osVersion} (${osBuild}) installed"
else
# Since swiftDialog requires at least macOS 11 Big Sur, first confirm the major OS version
# shellcheck disable=SC2086 # purposely use single quotes with osascript
if [[ "${osMajorVersion}" -ge 11 ]] ; then
updateScriptLog "PRE-FLIGHT CHECK: macOS ${osMajorVersion} installed; checking build version ..."
# Confirm the Mac is running `requiredMinimumBuild` (or later)
if [[ "${osBuild}" > "${requiredMinimumBuild}" ]]; then
updateScriptLog "PRE-FLIGHT CHECK: macOS ${osVersion} (${osBuild}) installed; proceeding ..."
# When the current `osBuild` is older than `requiredMinimumBuild`; exit with error
else
updateScriptLog "PRE-FLIGHT CHECK: The installed operating system, macOS ${osVersion} (${osBuild}), needs to be updated to Build ${requiredMinimumBuild}; exiting with error."
osascript -e 'display dialog "Please advise your Support Representative of the following error:\r\rExpected macOS Build '${requiredMinimumBuild}' (or newer), but found macOS '${osVersion}' ('${osBuild}').\r\r" with title "Setup Your Mac: Detected Outdated Operating System" buttons {"Open Software Update"} with icon caution'
updateScriptLog "PRE-FLIGHT CHECK: Executing /usr/bin/open '${outdatedOsAction}' …"
su - "${loggedInUser}" -c "/usr/bin/open \"${outdatedOsAction}\""
exit 1
fi
# The Mac is running an operating system older than macOS 11 Big Sur; exit with error
else
updateScriptLog "PRE-FLIGHT CHECK: swiftDialog requires at least macOS 11 Big Sur and this Mac is running ${osVersion} (${osBuild}), exiting with error."
osascript -e 'display dialog "Please advise your Support Representative of the following error:\r\rExpected macOS Build '${requiredMinimumBuild}' (or newer), but found macOS '${osVersion}' ('${osBuild}').\r\r" with title "Setup Your Mac: Detected Outdated Operating System" buttons {"Open Software Update"} with icon caution'
updateScriptLog "PRE-FLIGHT CHECK: Executing /usr/bin/open '${outdatedOsAction}' …"
su - "${loggedInUser}" -c "/usr/bin/open \"${outdatedOsAction}\""
exit 1
fi
fi
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Ensure computer does not go to sleep during SYM (thanks, @grahampugh!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
updateScriptLog "PRE-FLIGHT CHECK: Caffeinating this script (PID: $$)"
caffeinate -dimsu -w $$ &
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Validate Logged-in System Accounts
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
updateScriptLog "PRE-FLIGHT CHECK: Check for Logged-in System Accounts …"
currentLoggedInUser
counter="1"
until { [[ "${loggedInUser}" != "_mbsetupuser" ]] || [[ "${counter}" -gt "180" ]]; } && { [[ "${loggedInUser}" != "loginwindow" ]] || [[ "${counter}" -gt "30" ]]; } ; do
updateScriptLog "PRE-FLIGHT CHECK: Logged-in User Counter: ${counter}"
currentLoggedInUser
sleep 2
((counter++))
done
loggedInUserFullname=$( id -F "${loggedInUser}" )
loggedInUserFirstname=$( echo "$loggedInUserFullname" | cut -d " " -f 1 )
loggedInUserID=$( id -u "${loggedInUser}" )
updateScriptLog "PRE-FLIGHT CHECK: Current Logged-in User First Name: ${loggedInUserFirstname}"
updateScriptLog "PRE-FLIGHT CHECK: Current Logged-in User ID: ${loggedInUserID}"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Temporarily disable `jamf` binary check-in (thanks, @mactroll and @cube!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
if [ "$TESTING_MODE" = true ]; then
echo "This is where Jamf Binary check-in will get disabled."
elif [ "$TESTING_MODE" = false ]; then
JAMF_TASKS=/Library/LaunchDaemons/com.jamfsoftware.task.1.plist
/bin/launchctl bootout system $JAMF_TASKS
fi
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Validate / install swiftDialog (Thanks big bunches, @acodega!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function dialogCheck() {
# Output Line Number in `verbose` Debug Mode
if [[ "${debugMode}" == "verbose" ]]; then updateScriptLog "PRE-FLIGHT CHECK: # # # SETUP YOUR MAC VERBOSE DEBUG MODE: Line No. ${LINENO} # # #" ; fi
# Get the URL of the latest PKG From the Dialog GitHub repo
dialogURL=$(curl --silent --fail "https://api.github.com/repos/bartreardon/swiftDialog/releases/latest" | awk -F '"' "/browser_download_url/ && /pkg\"/ { print \$4; exit }")
# Expected Team ID of the downloaded PKG
expectedDialogTeamID="PWA5E9TQ59"
# Check for Dialog and install if not found
if [ ! -e "/Library/Application Support/Dialog/Dialog.app" ]; then
updateScriptLog "PRE-FLIGHT CHECK: Dialog not found. Installing..."
# Create temporary working directory
workDirectory=$( /usr/bin/basename "$0" )
tempDirectory=$( /usr/bin/mktemp -d "/private/tmp/$workDirectory.XXXXXX" )
# Download the installer package
/usr/bin/curl --location --silent "$dialogURL" -o "$tempDirectory/Dialog.pkg"
# Verify the download
teamID=$(/usr/sbin/spctl -a -vv -t install "$tempDirectory/Dialog.pkg" 2>&1 | awk '/origin=/ {print $NF }' | tr -d '()')
# Install the package if Team ID validates
if [[ "$expectedDialogTeamID" == "$teamID" ]]; then
/usr/sbin/installer -pkg "$tempDirectory/Dialog.pkg" -target /
sleep 2
dialogVersion=$( /usr/local/bin/dialog --version )
updateScriptLog "PRE-FLIGHT CHECK: swiftDialog version ${dialogVersion} installed; proceeding..."
else
# Display a so-called "simple" dialog if Team ID fails to validate
osascript -e 'display dialog "Please advise your Support Representative of the following error:\r\r• Dialog Team ID verification failed\r\r" with title "Setup Your Mac: Error" buttons {"Close"} with icon caution'
completionActionOption="Quit"
exitCode="1"
quitScript
fi
# Remove the temporary working directory when done
/bin/rm -Rf "$tempDirectory"
else
updateScriptLog "PRE-FLIGHT CHECK: swiftDialog version $(dialog --version) found; proceeding..."
fi
}
if [[ ! -e "/Library/Application Support/Dialog/Dialog.app" ]]; then
dialogCheck
fi
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Pre-flight Check: Complete
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
updateScriptLog "PRE-FLIGHT CHECK: Complete"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Identify location of jamf binary.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# If the jamf binary is not found, this check will return a
# null value. This null value is used by the CheckCasper
# function, in the "Checking for the jamf binary" section
# of the function.
JamfBinary=$(/usr/bin/which jamf)
if [[ "$JamfBinary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ ! -e "/usr/local/bin/jamf" ]]; then
JamfBinary="/usr/sbin/jamf"
elif [[ "$JamfBinary" == "" ]] && [[ ! -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
JamfBinary="/usr/local/bin/jamf"
elif [[ "$JamfBinary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
JamfBinary="/usr/local/bin/jamf"
fi
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Operating System, currently logged-in user and default Exit Code
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
osVersion=$( sw_vers -productVersion )
osBuild=$( sw_vers -buildVersion )
osMajorVersion=$( echo "${osVersion}" | awk -F '.' '{print $1}' )
reconOptions=""
exitCode="0"
Model="$(/usr/sbin/system_profiler SPHardwareDataType |/usr/bin/awk -F ': ' '/Model Name/ { print $2 }')" # | sed -e 's/^[[:space:]]*//')"
Serial="$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}')"
hardwareUDID=$(ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}')
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# User Configuration Dialog UI
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
main_message="Over the next 10-20 minutes, we will be installing some additional applications and configuring some settings on your Mac. Feel free to start working while this process completes.Please don’t shut down or restart the Mac while this is in progress.\n \n At the end of this process, you will be asked to logout and log back in."
banner_image_path="/var/tmp/Simons_logo_blue_fullres.png"
#SF_logo="/Users/achokshi/Downloads/Monday-SF-Blue.png"
# Text that will display in the progress bar
INSTALL_COMPLETE_TEXT="Configuration Complete!"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Policy Variable to Modify
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# The policy array must be formatted "Progress Bar text,customTrigger". These will be
# run in order as they appear below.
POLICY_ARRAY=(
"Installing Adobe Reader,install-adobereader"
"Installing Cisco Umbrella,install-umbrella"
"Installing Dropbox,install-dropbox"
"Installing Firefox,install-firefox"
"Installing Google Chrome,install-chrome"
"Installing LastPass,install-lastpass"
"Installing Mendeley,install-mendeley"
"Installing Microsoft Office,install-office"
"Installing Microsoft Office Auto-Update,install-mau"
"Installing Mural,install-mural"
"Installing Nudge,install-nudge"
"Installing Sentinel One,install-s1"
"Installing Slack,install-slack"
"Installing Zoom,install-zoom"
"Installing Backblaze,install-backblaze"
"Installing Print Drivers,installRicohPrintDrivers"
)
# Setting the status bar
# Counter is for making the determinate look nice. Starts at one and adds
# more based on EULA, register, or other options.
ADDITIONAL_OPTIONS_COUNTER=0
if [ "$EULA_ENABLED" = true ]; then ((ADDITIONAL_OPTIONS_COUNTER++)); fi
((ADDITIONAL_OPTIONS_COUNTER++)) #Determinate for rosetta
((ADDITIONAL_OPTIONS_COUNTER++)) #Determinate for installing additional required items.
((ADDITIONAL_OPTIONS_COUNTER++)) #Determinate for software updates.
# Checking policy array and adding the count from the additional options above.
ARRAY_LENGTH="$((${#POLICY_ARRAY[@]}+ADDITIONAL_OPTIONS_COUNTER))"
echo $ARRAY_LENGTH
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Functions for Jamf Pro Tech Credentials
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function JamfProCredsAuth(){
GetJamfProAPIToken() {
# This function uses Basic Authentication to get a new bearer token for API authentication.
# Create base64-encoded credentials from user account's username and password.
encodedCredentials=$(printf "${jamfpro_user}:${jamfpro_password}" | /usr/bin/iconv -t ISO-8859-1 | /usr/bin/base64 -i -)
# Use the encoded credentials with Basic Authorization to request a bearer token
authToken=$(/usr/bin/curl '..%s..' "${jamfpro_url}/api/v1/auth/token" --max-time 2 --retry 0 --connect-timeout 5 --retry-max-time 10 --retry-delay 0 --silent --request POST --header "Authorization: Basic ${encodedCredentials}")
# Parse the returned output for the bearer token and store the bearer token as a variable.
if [[ $(/usr/bin/sw_vers -productVersion | awk -F . '{print $1}') -lt 12 ]]; then
api_token=$(/usr/bin/awk -F \" 'NR==2{print $4}' <<< "$authToken" | /usr/bin/xargs)
else
api_token=$(/usr/bin/plutil -extract token raw -o - - <<< "$authToken")
fi
}
APITokenValidCheck() {
# Verify that API authentication is using a valid token by running an API command
# which displays the authorization details associated with the current API user.
# The API call will only return the HTTP status code.
api_authentication_check=$(/usr/bin/curl --write-out %{http_code} --silent --output /dev/null "${jamfpro_url}/api/v1/auth" --request GET --header "Authorization: Bearer ${api_token}")
}
CheckAndRenewAPIToken() {
# Verify that API authentication is using a valid token by running an API command
# which displays the authorization details associated with the current API user.
# The API call will only return the HTTP status code.
APITokenValidCheck
# If the api_authentication_check has a value of 200, that means that the current
# bearer token is valid and can be used to authenticate an API call.
if [[ ${api_authentication_check} == 200 ]]; then
# If the current bearer token is valid, it is used to connect to the keep-alive endpoint. This will
# trigger the issuing of a new bearer token and the invalidation of the previous one.
#
# The output is parsed for the bearer token and the bearer token is stored as a variable.
authToken=$(/usr/bin/curl "${jamfpro_url}/api/v1/auth/keep-alive" --silent --request POST --header "Authorization: Bearer ${api_token}")
if [[ $(/usr/bin/sw_vers -productVersion | awk -F . '{print $1}') -lt 12 ]]; then
api_token=$(/usr/bin/awk -F \" 'NR==2{print $4}' <<< "$authToken" | /usr/bin/xargs)
else
api_token=$(/usr/bin/plutil -extract token raw -o - - <<< "$authToken")
fi
else
# If the current bearer token is not valid, this will trigger the issuing of a new bearer token
# using Basic Authentication.
GetJamfProAPIToken
fi
}
InvalidateToken() {
# Verify that API authentication is using a valid token by running an API command
# which displays the authorization details associated with the current API user.
# The API call will only return the HTTP status code.
APITokenValidCheck
# If the api_authentication_check has a value of 200, that means that the current
# bearer token is valid and can be used to authenticate an API call.
if [[ ${api_authentication_check} == 200 ]]; then
# If the current bearer token is valid, an API call is sent to invalidate the token.
authToken=$(/usr/bin/curl "${jamfpro_url}/api/v1/auth/invalidate-token" --silent --header "Authorization: Bearer ${api_token}" -X POST)
# Explicitly set value for the api_token variable to null.
api_token=""
fi
}
#function to ask for tech's jamf credentials.
function promptCredentials() {
#echo "$api_authentication_check"
if [[ "$api_authentication_check" -eq 401 ]]; then
credentials=$($dialogpath --title "Jamf Pro Credentials" \
--titlefont "size=20" \
--message "Sign-in failed. Please verify your credentials and try again." \
--messagefont "size=15" \
--textfield "Username",required \
--textfield "Password",secured,required \
--alignment "center" \
--button2text "Cancel" \
--button2action \
--small \
--icon "none" \
--json
)
/bin/echo "$TIMESTAMP Prompted for Jamf credentials."
userdataexitcode=$?
/bin/echo "$TIMESTAMP Jamf Credentials error. Prompted for retry."
#cancel button.
if [ $userdataexitcode == 2 ]; then
/bin/echo "$TIMESTAMP Tech cancelled the jamf retry screen. exiting.."
exit 1
fi
else
credentials=$($dialogpath --title "Jamf Pro Credentials" \
--titlefont "size=20" \
--message "Please sign in using your Jamf credentials." \
--messagefont "size=15" \
--textfield "Username",required \
--textfield "Password",secured,required \
--alignment "center" \
--button2text "Cancel" \
--button2action \
--small \
--icon "none" \
--json
)
credentialsexitcode=$?
/bin/echo "$TIMESTAMP Prompted for Jamf credentials."
#echo $userdataexitcode
#echo "$credentials"
#cancel button.
if [ $credentialsexitcode == 2 ]; then
/bin/echo "$TIMESTAMP Tech pressed cancel button at the Jamf credentials screen. exiting the script with exit code 1. "
exit 1
fi
fi
}
#function to display an error if tech's jamf credentials are wrong.
function promptCredentialsError() {
credentials=$($dialogpath --title "Jamf Pro Credentials" \
--titlefont "size=20" \
--message "Sign-in failed. Please verify your credentials and try again." \
--messagefont "size=15" \
--textfield "Username",required \
--textfield "Password",secured,required \
--alignment "center" \
--button2text "Cancel" \
--button2action \
--small \
--icon "none" \
--json
)
#credentialsexitcode=$?
/bin/echo "$TIMESTAMP Prompted for Jamf credentials."
userdataexitcode=$?
/bin/echo "$TIMESTAMP Jamf Credentials error. Prompted for retry."
#echo $userdataexitcode
#echo "$credentials"
#cancel button.
if [ $userdataexitcode == 2 ]; then
/bin/echo "$TIMESTAMP Tech cancelled the jamf retry screen. exiting.."
exit 1
fi
}
#function to prompt for the tech to enter the username.
function collectusername()
{
askuserName=$($dialogpath --title "User Account Setup" \
--titlefont "size=20" \
--message "Enter the username for the account you'd like to create on this Mac.\n\n _The username is the **first part** of the primary email address (e.g. [email protected] becomes jsmith)_" \
--messagefont "weight=light,size=15" \
--alignment "center" \
--textfield "Username",required \
--button1text "Look up" \
--button2text "Cancel" \
--infobuttontext "Enter Manually" \
--button2action \
--icon "none" \
--small \
--json
)
collectUserNameExitCode=$?
#echo $userdataexitcode
/bin/echo "$TIMESTAMP Prompted to collect username."
#cancel button.
if [ $collectUserNameExitCode == 2 ]; then
/bin/echo "$TIMESTAMP Tech cancelled the collect username screen. exiting.."
exit 1
fi
if [ $collectUserNameExitCode == 3 ]; then
tech_manual
/bin/echo "$TIMESTAMP Enter Manually button pressed. Enabling Manual switch."
break;
fi
}
#Function to get jamf api token based on the tech's jamf credentials.
function getUserInfoAuthenticated {
# Explicitly set initial value for the api_token variable to null:
# Explicitly set initial value for the api_token variable to null:
api_token=""
# Explicitly set initial value for the token_expiration variable to null:
token_expiration=""
promptCredentials
jamfpro_user=$(echo $credentials | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Username'])" )
jamfpro_password=$(echo $credentials | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Password'])" )
# If you choose to hardcode API information into the script, set one or more of the following values:
#
# The username for an account on the Jamf Pro server with sufficient API privileges
# The password for the account
# The Jamf Pro URL
# Set the Jamf Pro URL here if you want it hardcoded.
jamfpro_url="https://jss.simonsfoundation.org:8443"
# Remove the trailing slash from the Jamf Pro URL if needed.
jamfpro_url=${jamfpro_url%%/}
GetJamfProAPIToken
CheckAndRenewAPIToken
sleep 1
if [[ -z "$api_token" ]]; then
echo "$api_Token"
#echo "no api token"
api_authentication_check=400
else
CheckAndRenewAPIToken
echo $api_authentication_check
fi
until [[ "$api_authentication_check" -eq 200 ]];
do
echo $jamfpro_user
credentials=""
echo "$api_authentication_check"
promptCredentialsError
jamfpro_user=$(echo $credentials | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Username'])" )
jamfpro_password=$(echo $credentials | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Password'])" )
GetJamfProAPIToken
CheckAndRenewAPIToken
done
}
getUserInfoAuthenticated
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Configurations options
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function config_options(){
configurationOptions=$($dialogbinary --title "Configuration Options" \
--titlefont "size=20" \
--message "Please select the configuration options below" \
--selecttitle "Options" --selectvalues "Loaner Pool, Shared Device, User Device, Data Restore, Your device" --selectdefault "Loaner Pool" \
--alignment "center" \
--button1action \
--button2text "Cancel" \
--button2action \
--icon "none" \
--json )
config_options_exit_code=$?
while :
do
#ok button action
if [ $config_options_exit_code == 0 ]; then
break;
fi
#cancel button.
if [ $config_options_exit_code == 2 ]; then
updateScriptLog "Configuration Options: Tech pressed cancelled button. Exiting."
exit 1
fi
done
}
####################################################################################################
#
# Enduser Welcome dialog
#
####################################################################################################
function logout_timer(){
$dialogbinary --height 200 --timer 30 \
--title "logging out" \
--message "During the logout process, you will be asked to enter your password to enable FileVault on this mac." \
--messagefont "weight=light,size=15" \
--alignment "center" \
--hideicon
--ontop
launchctl bootout user/"${loggedInUserID}"
}
function enduser_configuration(){
# Configure Swift dialog to display the apps installation progress.
updateScriptLog "Enduser Configuration: Initializing configuration"
$dialogbinary --title "Welcome to Simons Foundation, $loggedInUserFirstname!" \
--bannerimage $banner_image_path \
--titlefont "shadow=false,weight=light,size=30" \
--message "$main_message" \
--messagefont "weight=light,size=15" \
--alignment "center" \
--height "400" \
--button1text "Wait!" \
--button1disabled \
--progress $ARRAY_LENGTH \
--helpmessage "Contact IT \n \n [email protected]" & sleep 0.3
dialog_pid=$!
sleep 5
/bin/echo "progresstext: Getting things ready" >> $dialogcmdfile
/bin/echo "progress: 1" >> $dialogcmdfile
sleep 3
updateScriptLog "Enduser Configuration: Installing Rosetta"
# Install Rosetta on Macs running Apple Silicon
OSMajorVersion="$(/usr/bin/sw_vers -productVersion | /usr/bin/cut -d '.' -f 1)"
if [[ $OSMajorVersion -ge 11 ]] && [[ "$(/usr/bin/arch)" == "arm64" ]]; then
if [ "$TESTING_MODE" = true ]; then
/bin/echo "progresstext: Installing Rosetta" >> $dialogcmdfile
/bin/echo "progress: 1" >> $dialogcmdfile
sleep 3
elif [ "$TESTING_MODE" = false ]; then
#((ADDITIONAL_OPTIONS_COUNTER++))
/bin/echo "progresstext: Installing Rosetta" >> $dialogcmdfile
/bin/echo "progress: 1" >> $dialogcmdfile
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
fi
if [[ $? -ne 0 ]]; then
/bin/echo "Rosetta was not installed successfully."
fi
else /bin/echo "Rosetta not required."
fi
progress_count=1
updateScriptLog "Enduser Configuration: Running Policy loop"
#Loop to run policies
for POLICY in "${POLICY_ARRAY[@]}"; do
echo "progresstext: $(echo "$POLICY" | cut -d ',' -f1)" >> $dialogcmdfile
((progress_count++))
echo $progress_count
echo "progress: $progress_count" >> $dialogcmdfile
if [ "$TESTING_MODE" = true ]; then
sleep 1
elif [ "$TESTING_MODE" = false ]; then
"$JamfBinary" policy -event "$(echo "$POLICY" | cut -d ',' -f2)"
echo "testing"
fi
done
sleep 5
sudo /usr/bin/killall $JamfBinary
sleep 5
#Re-Enable Jamf Recurring check-ins.
sudo /bin/launchctl bootstrap system $JAMF_TASKS
#Now we need to run the following policies outside of the policy array.
#The reason for running these policies outside of array is, in the following logic, we are simply running Jamf Policy.
#Which will pull in all other additional required items such as fonts, application updates, etc.
if [ "$TESTING_MODE" = true ]; then
#((ADDITIONAL_OPTIONS_COUNTER++))
((progress_count++))
echo "progress: $progress_count" >> $dialogcmdfile
echo "progresstext: Installing additional required items" >> $dialogcmdfile
sleep 3
elif [ "$TESTING_MODE" = false ]; then
#((ADDITIONAL_OPTIONS_COUNTER++))
((progress_count++))
echo "progress: $progress_count" >> $dialogcmdfile
echo "progresstext: Installing additional required items" >> $dialogcmdfile
"$JamfBinary" policy
fi
#We need to run the Swiftdialog cleanup script outside of the policy array
#because it will uninstall the DEPNotify app before it can run the rest of the script.
#Running SwiftDialog cleanup script..
if [ "$TESTING_MODE" = true ]; then
#((ADDITIONAL_OPTIONS_COUNTER++))
echo "progresstext: Cleaning up.." >> $dialogcmdfile
((progress_count++))
echo "progress: $progress_count" >> $dialogcmdfile
sleep 3
elif [ "$TESTING_MODE" = false ]; then
#((ADDITIONAL_OPTIONS_COUNTER++))
echo "progresstext: Cleaning up.." >> $dialogcmdfile
((progress_count++))
echo "progress: $progress_count" >> $dialogcmdfile
updateScriptLog "Enduser Configuration: Running cleanup script"
"$JamfBinary" policy -event cleanup-swiftdialog-preinstaller
fi
#Checking for any pending software updates.
echo "progresstext: Checking for and installing any OS updates..." >> $dialogcmdfile
((progress_count++))
echo "progress: $progress_count" >> $dialogcmdfile
/usr/sbin/softwareupdate -ia
sleep 3
updateScriptLog "Enduser Configuration: Completion text"
/bin/echo "progresstext: $INSTALL_COMPLETE_TEXT" >> $dialogcmdfile
echo "progress: 100" >> $dialogcmdfile
sleep 5
/bin/echo "--ontop" >> $dialogcmdfile
/bin/echo "button1text: Logout" >> $dialogcmdfile
/bin/echo "button1: enable" >> $dialogcmdfile
/bin/echo "progresstext: Please click on the logout button to finish the process" >> $dialogcmdfile
$dialogbinary --notification "Configuration Complete!" --message "Your mac is now configured. Please logout to finish setting up your mac."
wait $dialog_pid
logout_timer
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# User Account Creation function begins
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
dialogpath=/usr/local/bin/dialog
dialogcmdfile=/var/tmp/dialog.log
jamfhelper=/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper
EmptyValueMsg="You left the previous dialog empty. Values cannot be blank unless otherwise stated. Please try again."
LocalAdmin="ladmin"
OSMajorVersion="$(/usr/bin/sw_vers -productVersion | /usr/bin/cut -d '.' -f 1)"
Model="$(/usr/sbin/system_profiler SPHardwareDataType |/usr/bin/awk -F ': ' '/Model Name/ { print $2 }')" # | sed -e 's/^[[:space:]]*//')"
Serial="$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}')"
hardwareUDID=$(ioreg -d2 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/{print $(NF-1)}')
TIMESTAMP=`date "+%Y-%m-%d %H:%M:%S"`
# Signal file for restore.
signalFile="/tmp/restorerequired"
loanerSignalFile="/tmp/thisisaloanerpoolmachine"
function create_user_account(){
function userdata()
{
/bin/echo "$TIMESTAMP Manual Switch enabled. Prompted for user data screen."
uservalue=$($dialogpath --title "User Account Setup" \
--titlefont "size=20" \
--message "Please fill out the following information to create a user account." \
----messagefont "weight=light,size=15" \
--textfield "First name",required \
--textfield "Last name",required \
--textfield "Username",required \
--textfield "Password",secured,required \
--textfield "Confirm password",secured,required \
--selecttitle "Computer type" --selectvalues "Temporary-Loaner, Long-term-deployment" --selectdefault "Long-term-deployment" \
--selecttitle "User account type" --selectvalues "Standard, Administrator" --selectdefault "Standard" \
--alignment "center" \
--button1action \
--button2text "Cancel" \
--button2action \
--icon "none" \
--json
)
userdataexitcode=$?
#echo $userdataexitcode
while :
do
FirstName=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['First name'])" )
LastName=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Last name'])" )
UserName=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Username'])" | tr '[:upper:]' '[:lower:]' )
AccountType=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['User account type']['selectedValue'])" )
#ok button action
if [ $userdataexitcode == 0 ]; then
break;
fi
#cancel button.
if [ $userdataexitcode == 2 ]; then
/bin/echo "$TIMESTAMP Tech cancelled manual user data screen. exiting.."
exit 1
fi
done
}
function manualconfirmuservalue()
{
/bin/echo "$TIMESTAMP Prompted the Manual confirm screen. "
while :
do
FirstName=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['First name'])" )
LastName=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Last name'])" )
UserName=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Username'])" | tr '[:upper:]' '[:lower:]' )
AccountType=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['User account type']['selectedValue'])" )
manualconfirmuservaluedialog=$($dialogpath --title "Confirm Details" \
--titlefont "size=20" \
--message "First name: $FirstName \n\n Last name: $LastName \n\n Username: $UserName \n\n Account type: $AccountType" \
--messagefont "weight=light,size=15" \
--alignment "center" \
--icon "none" \
--small \
--button1text "Looks good!" --button1action \
--button2text "Try again" --button2action \
)
manualconfirmuservalueexitcode=$?
if [ $manualconfirmuservalueexitcode == 2 ]; then
/bin/echo "$TIMESTAMP Try again button pressed at the manual confirm screen. Prompting for userdata screen."
tech_manual
fi
if [ $manualconfirmuservalueexitcode == 0 ]; then
/bin/echo "$TIMESTAMP Looks Good button pressed at the manual confirm screen. Continuing.."
break;
fi
done
}
#Function to verify that the both password entered match.
function passwordverification()
{
while :
do
Password1=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Password'])" )
#echo $Password1
Password2=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Confirm password'])" )
#echo $Password2
if [[ $Password1 == $Password2 ]];
then
/bin/echo "$TIMESTAMP Confirmed password matches."
#$dialogpath --title "Success!" --message "Password match!" --alignment "center"
break;
else
$dialogpath --title "Error!" --titlefont "size=20" --message "Password does not match. Please try again!" --messagefont "weight=light,size=15" --alignment "center" --small --icon "none" >&2
/bin/echo "$TIMESTAMP Password doesnt match. Prompting for userdata screen again. Retrying.."
userdata
useraccount_to_verify_manual
userverification
passwordverification
fi
done
}
#function to verify that the username does not exist in the username list, it is not one of the protected users, the user does not already exists in the local directory or the user does not already have a home directory.
function userverification()
{
while :
do
UserName=$(echo $uservalue | /usr/local/bin/managed_python3 -c "import sys, json; print(json.load(sys.stdin)['Username'])" | tr '[:upper:]' '[:lower:]' )
# List of Home Directories
ListOfDirectories="$(/usr/bin/dscl /Local/Default list /Users NFSHomeDirectory | /usr/bin/awk '{print $2}')"
# Check if home directory is already in use
for Directory in $ListOfDirectories; do
if [[ "$Directory" = "/Users/$UserName" ]]; then
$dialogpath --title "Error!" --titlefont "size=20" --message "Username $UserName already exists. Please try again." --messagefont "weight=light,size=15" --alignment "center" --icon "none" --small
/bin/echo "$TIMESTAMP Username $UserName home directory already exists. Prompted for retry."
userdata
useraccount_to_verify_manual
userverification
fi
done
# List of usernames
ListOfUsernames="$(/usr/bin/dscl /Local/Default list /Users RecordName | /usr/bin/awk '{print $1}')"
# Check if user name is already in use
for user in $ListOfUsernames; do
if [[ $user = "$UserName" ]]; then
$dialogpath --title "Error!" --titlefont "size=20" --message "Username $UserName already exists. Please try again." --messagefont "weight=light,size=15" --alignment "center" --icon "none" --small
/bin/echo "$TIMESTAMP Username $UserName already in use. Prompted for retry."
userdata
useraccount_to_verify_manual
userverification
fi
done
# List of usernames that are protected
ListOfProtectedUsernames="guest"
# Check if user name is one of the protected users.
for user in $ListOfProtectedUsernames; do
if [[ $user = "$Username" ]]; then
$dialogpath --title "Error!" --titlefont "size=20" --message "Username $UserName is protected by the OS. Please try again." --messagefont "weight=light,size=15" --alignment "center" --icon "none" --small
/bin/echo "$TIMESTAMP Username $UserName protected account. Prompted for retry."
userdata
useraccount_to_verify_manual
userverification
fi
done