-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Setup-Your-Mac-via-Dialog.bash
executable file
·3545 lines (2773 loc) · 155 KB
/
Setup-Your-Mac-via-Dialog.bash
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
# shellcheck disable=SC2001,SC1111,SC1112,SC2143,SC2145,SC2086,SC2089,SC2090,SC2269
####################################################################################################
#
# Setup Your Mac via swiftDialog
# https://snelson.us/sym
#
####################################################################################################
#
# HISTORY
#
# Version 1.15.0, 11-Jun-2024
# - Added logging functions
# - Modified Microsoft Teams Message `activitySubtitle`
# - Activated main "Setup Your Mac" dialog with each `listitem`
# - Added swiftDialog `2.5.0`'s `--verbose`, `--debug` and `--resizable` flags to debugModes
# - Failure Message: Increased `sleep` value from `0.3` to `0.7` (thanks, for the report, @arnoldtaw; thanks for the code suggestion, @jcmbowman)
# - Miscellaneous formatting and clean-up
# - Added Support Team fields (thanks, @HowardGMac!)
# - Set `swiftDialogMinimumRequiredVersion` to `2.5.0.4768`
# - Improved exit code processing for 'Welcome' dialog
# - Added pre-flight check for AC power (thanks for the suggestion, @arnoldtaw; thanks for the code, Obi-Josh!)
# - Added Variables for Prefill Email and Computer Name (thanks, @AndrewMBarnett!)
# - Improved Remote Validation error-checking
# - Updated Dynamic Download Estimates for macOS 15 Sequoia
#
####################################################################################################
####################################################################################################
#
# Global Variables
#
####################################################################################################
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Script Version and Jamf Pro Script Parameters
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
scriptVersion="1.15.0"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
scriptLog="${4:-"/var/log/org.churchofjesuschrist.log"}" # Parameter 4: Script Log Location [ /var/log/org.churchofjesuschrist.log ] (i.e., Your organization's default location for client-side logs)
debugMode="${5:-"verbose"}" # Parameter 5: Debug Mode [ verbose (default) | true | false ]
welcomeDialog="${6:-"userInput"}" # Parameter 6: Welcome dialog [ userInput (default) | video | messageOnly | 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) | 23F ] (i.e., Your organization's required minimum build of macOS to allow users to proceed; use "23F" for macOS 14.5)
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)
webhookURL="${10:-""}" # Parameter 10: Microsoft Teams or Slack Webhook URL [ Leave blank to disable (default) | https://microsoftTeams.webhook.com/URL | https://hooks.slack.com/services/URL ] Can be used to send a success or failure message to Microsoft Teams or Slack via Webhook. (Function will automatically detect if Webhook URL is for Slack or Teams; can be modified to include other communication tools that support functionality.)
presetConfiguration="${11:-""}" # Parameter 11: Specify a Configuration (i.e., `policyJSON`; NOTE: If set, `promptForConfiguration` will be automatically suppressed and the preselected configuration will be used instead)
swiftDialogMinimumRequiredVersion="2.5.0.4768" # This will be set and updated as dependancies on newer features change.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Various Feature Variables
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
humanReadableScriptName="Setup Your Mac" # Script Human-readable Name
organizationScriptName="sym" # Organization's Script Name
debugModeSleepAmount="3" # Delay for various actions when running in Debug Mode
failureDialog="true" # Display the so-called "Failure" dialog (after the main SYM dialog) [ true | false ]
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Welcome Message User Input Customization Choices (thanks, @rougegoat!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# [SYM-Helper] These control which user input boxes are added to the first page of Setup Your Mac. If you do not want to ask about a value, set it to any other value
promptForUsername="true"
prefillUsername="true" # prefills the currently logged in user's username
promptForRealName="true"
prefillRealname="true" # prefills the currently logged in user's fullname
promptForEmail="true"
prefillEmail="true" # prefills the currently logged in user's email. You need to add to email ending variable
promptForComputerName="true"
prefillComputerName="true" # prefills the currently logged in user's current computer name
promptForAssetTag="true"
promptForRoom="true"
promptForBuilding="true"
promptForDepartment="true"
promptForPosition="true" # When set to true dynamically prompts the user to select from a list of positions or manually enter one at the welcomeDialog, see "positionListRaw" to define the selection / entry type
promptForConfiguration="true" # Removes the Configuration dropdown entirely and uses the "Catch-all (i.e., used when `welcomeDialog` is set to `video` or `false`)" or presetConfiguration policyJSON
# Set to "true" to suppress the Update Inventory option on policies that are called
suppressReconOnPolicy="false"
# [SYM-Helper] Disables the Blurscreen enabled by default in Production
moveableInProduction="false"
# [SYM-Helper] An unsorted, comma-separated list of buildings (with possible duplication). If empty, this will be hidden from the user info prompt
buildingsListRaw="Benson (Ezra Taft) Building,Brimhall (George H.) Building,BYU Conference Center,Centennial Carillon Tower,Chemicals Management Building,Clark (Herald R.) Building,Clark (J. Reuben) Building,Clyde (W.W.) Engineering Building,Crabtree (Roland A.) Technology Building,Ellsworth (Leo B.) Building,Engineering Building,Eyring (Carl F.) Science Center,Grant (Heber J.) Building,Harman (Caroline Hemenway) Building,Harris (Franklin S.) Fine Arts Center,Johnson (Doran) House East,Kimball (Spencer W.) Tower,Knight (Jesse) Building,Lee (Harold B.) Library,Life Sciences Building,Life Sciences Greenhouses,Maeser (Karl G.) Building,Martin (Thomas L.) Building,McKay (David O.) Building,Nicholes (Joseph K.) Building,Smith (Joseph F.) Building,Smith (Joseph) Building,Snell (William H.) Building,Talmage (James E.) Math Sciences/Computer Building,Tanner (N. Eldon) Building,Taylor (John) Building,Wells (Daniel H.) Building"
# A sorted, unique, JSON-compatible list of buildings
buildingsList=$( echo "${buildingsListRaw}" | tr ',' '\n' | sort -f | uniq | sed -e 's/^/\"/' -e 's/$/\",/' -e '$ s/.$//' )
# [SYM-Helper] An unsorted, comma-separated list of departments (with possible duplication). If empty, this will be hidden from the user info prompt
departmentListRaw="Asset Management,Sales,Australia Area Office,Purchasing / Sourcing,Board of Directors,Strategic Initiatives & Programs,Operations,Business Development,Marketing,Creative Services,Customer Service / Customer Experience,Risk Management,Engineering,Finance / Accounting,Sales,General Management,Human Resources,Marketing,Investor Relations,Legal,Marketing,Sales,Product Management,Production,Corporate Communications,Information Technology / Technology,Quality Assurance,Project Management Office,Sales,Technology"
# A sorted, unique, JSON-compatible list of departments
departmentList=$( echo "${departmentListRaw}" | tr ',' '\n' | sort -f | uniq | sed -e 's/^/\"/' -e 's/$/\",/' -e '$ s/.$//' )
# An unsorted, comma-separated list of departments (with possible duplication). If empty and promptForPosition is "true" a user-input box will be shown instead of a dropdown
positionListRaw="Developer,Management,Sales,Marketing"
# Email ending variable
emailEnding="@company.com"
# A sorted, unique, JSON-compatible list of positions
positionList=$( echo "${positionListRaw}" | tr ',' '\n' | sort -f | uniq | sed -e 's/^/\"/' -e 's/$/\",/' -e '$ s/.$//' )
# [SYM-Helper] Branding overrides
brandingBanner="https://img.freepik.com/free-photo/liquid-marbling-paint-texture-background-fluid-painting-abstract-texture-intensive-color-mix-wallpaper_1258-101465.jpg" # [Image by benzoix on Freepik](https://www.freepik.com/author/benzoix)
brandingBannerDisplayText="true"
brandingIconLight="https://cdn-icons-png.flaticon.com/512/979/979585.png"
brandingIconDark="https://cdn-icons-png.flaticon.com/512/740/740878.png"
# [SYM-Helper] IT Support Variables - Use these if the default text is fine but you want your org's info inserted instead
supportTeamName="Support Team Name"
supportTeamPhone="+1 (801) 555-1212"
supportTeamEmail="support@domain.com"
supportTeamChat="chat.support.domain.com"
supportTeamChatHyperlink="[${supportTeamChat}](https://${supportTeamChat})"
supportTeamWebsite="support.domain.com"
supportTeamHyperlink="[${supportTeamWebsite}](https://${supportTeamWebsite})"
supportKB="KB8675309"
supportTeamErrorKB="[${supportKB}](https://servicenow.company.com/support?id=kb_article_view&sysparm_article=${supportKB}#Failures)"
supportTeamHours="Monday through Friday, 8 a.m. to 5 p.m."
# Disable the "Continue" button in the User Input "Welcome" dialog until Dynamic Download Estimates have complete [ true | false ] (thanks, @Eltord!)
lockContinueBeforeEstimations="false"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Operating System, Computer Model Name, etc.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
osVersion=$( sw_vers -productVersion )
osVersionExtra=$( sw_vers -productVersionExtra )
osBuild=$( sw_vers -buildVersion )
osMajorVersion=$( echo "${osVersion}" | awk -F '.' '{print $1}' )
if [[ -n $osVersionExtra ]] && [[ "${osMajorVersion}" -ge 13 ]]; then osVersion="${osVersion} ${osVersionExtra}"; fi # Report RSR sub version if applicable
modelName=$( /usr/libexec/PlistBuddy -c 'Print :0:_items:0:machine_name' /dev/stdin <<< "$(system_profiler -xml SPHardwareDataType)" )
reconOptions=""
exitCode="0"
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Configuration Variables
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
configurationDownloadEstimation="true" # [ true (default) | false ]
correctionCoefficient="1.01" # "Fudge factor" (to help estimate match reality)
configurationCatchAllSize="34" # Catch-all Configuration in Gibibits (i.e., Total File Size in Gigabytes * 7.451)
configurationCatchAllInstallBuffer="0" # Buffer time added to estimates to include installation time of packages, in seconds. Set to 0 to disable.
configurationOneName="Required"
configurationOneDescription="Minimum organization apps"
configurationOneSize="34" # Configuration One in Gibibits (i.e., Total File Size in Gigabytes * 7.451)
configurationOneInstallBuffer="0" # Buffer time added to estimates to include installation time of packages, in seconds. Set to 0 to disable.
configurationTwoName="Recommended"
configurationTwoDescription="Required apps and Microsoft 365"
configurationTwoSize="62" # Configuration Two in Gibibits (i.e., Total File Size in Gigabytes * 7.451)
configurationTwoInstallBuffer="0" # Buffer time added to estimates to include installation time of packages, in seconds. Set to 0 to disable.
configurationThreeName="Complete"
configurationThreeDescription="Recommended apps, Adobe Acrobat Reader and Google Chrome"
configurationThreeSize="106" # Configuration Three in Gibibits (i.e., Total File Size in Gigabytes * 7.451)
configurationThreeInstallBuffer="0" # Buffer time added to estimates to include installation time of packages, in seconds. Set to 0 to disable.
####################################################################################################
#
# Functions
#
####################################################################################################
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Client-side Logging
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function updateScriptLog() {
echo -e "${organizationScriptName} ($scriptVersion): $( date +%Y-%m-%d\ %H:%M:%S ) - ${1}" | tee -a "${scriptLog}"
}
function preFlight() {
updateScriptLog "[PRE-FLIGHT] ${1}"
}
function logComment() {
updateScriptLog " ${1}"
}
function welcomeDialog() {
updateScriptLog "[WELCOME DIALOG] ${1}"
}
function error() {
updateScriptLog "[ERROR] ${1}"
}
function fatal() {
updateScriptLog "[FATAL ERROR] ${1}"
exit 1
}
function info() {
updateScriptLog "[INFO] ${1}"
}
function updateSetupYourMacDialog() {
updateScriptLog "[SETUP YOUR MAC DIALOG] ${1}"
}
function updateFailureDialog() {
updateScriptLog "[FAILURE DIALOG] ${1}"
}
function updateSuccessDialog() {
updateScriptLog "[SUCCESS] ${1}"
}
function finaliseUserExperience() {
updateScriptLog "[FINALISE USER EXPERIENCE] ${1}"
}
function completionActionOut() {
updateScriptLog "[COMPLETION ACTION] ${1}"
}
function quitOut() {
updateScriptLog "[QUIT SCRIPT] ${1}"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Output Line Number in `verbose` Debug Mode (thanks, @bartreardon!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function outputLineNumberInVerboseDebugMode() {
if [[ "${debugMode}" == "verbose" ]]; then updateScriptLog "# # # SETUP YOUR MAC VERBOSE DEBUG MODE: Line No. ${BASH_LINENO[0]} # # #" ; fi
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Run command as logged-in user (thanks, @scriptingosx!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function runAsUser() {
info "Run \"$@\" as \"$loggedInUserID\" … "
launchctl asuser "$loggedInUserID" sudo -u "$loggedInUser" "$@"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Calculate Free Disk Space
# Disk Usage with swiftDialog (https://snelson.us/2022/11/disk-usage-with-swiftdialog-0-0-2/)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function calculateFreeDiskSpace() {
freeSpace=$( diskutil info / | grep -E 'Free Space|Available Space|Container Free Space' | awk -F ":\s*" '{ print $2 }' | awk -F "(" '{ print $1 }' | xargs )
freeBytes=$( diskutil info / | grep -E 'Free Space|Available Space|Container Free Space' | awk -F "(\\\(| Bytes\\\))" '{ print $2 }' )
diskBytes=$( diskutil info / | grep -E 'Total Space' | awk -F "(\\\(| Bytes\\\))" '{ print $2 }' )
freePercentage=$( echo "scale=2; ( $freeBytes * 100 ) / $diskBytes" | bc )
diskSpace="$freeSpace free (${freePercentage}% available)"
diskMessage=$("Disk Space: ${diskSpace}")
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Update the "Welcome" dialog
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function dialogUpdateWelcome(){
echo "$1" >> "$welcomeCommandFile"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Update the "Setup Your Mac" dialog
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function dialogUpdateSetupYourMac() {
updateSetupYourMacDialog "$1"
echo "$1" >> "$setupYourMacCommandFile"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Update the "Failure" dialog
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function dialogUpdateFailure(){
updateFailureDialog "$1"
echo "$1" >> "$failureCommandFile"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Finalise User Experience
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function finalise(){
outputLineNumberInVerboseDebugMode
if [[ "${configurationDownloadEstimation}" == "true" ]]; then
outputLineNumberInVerboseDebugMode
calculateFreeDiskSpace
finaliseUserExperience "${diskMessage}"
fi
if [[ "${jamfProPolicyTriggerFailure}" == "failed" ]]; then
outputLineNumberInVerboseDebugMode
updateFailureDialog "Failed policies detected …"
if [[ -n "${webhookURL}" ]]; then
updateFailureDialog "Display Failure dialog: Sending webhook message"
webhookStatus="Failures detected"
webHookMessage
fi
if [[ "${failureDialog}" == "true" ]]; then
outputLineNumberInVerboseDebugMode
updateFailureDialog "Display Failure dialog: ${failureDialog}"
killProcess "caffeinate"
if [[ "${brandingBannerDisplayText}" == "true" ]] ; then dialogUpdateSetupYourMac "title: Sorry ${loggedInUserFirstname}, something went sideways"; fi
dialogUpdateSetupYourMac "icon: SF=xmark.circle.fill,weight=bold,colour1=#BB1717,colour2=#F31F1F"
dialogUpdateSetupYourMac "progresstext: Failures detected. Please click Continue for troubleshooting information."
dialogUpdateSetupYourMac "button1text: Continue …"
dialogUpdateSetupYourMac "button1: enable"
dialogUpdateSetupYourMac "progress: reset"
# Wait for user-acknowledgment due to detected failure
wait
dialogUpdateSetupYourMac "quit:"
eval "${dialogFailureCMD}" & sleep 0.7
updateFailureDialog "\n\n# # #\n# FAILURE DIALOG\n# # #\n"
updateFailureDialog "Jamf Pro Policy Name Failures:"
updateFailureDialog "${jamfProPolicyNameFailures}"
failureMessage="A failure has been detected, ${loggedInUserFirstname}. \n\nPlease complete the following steps:\n1. Reboot and login to your ${modelName} \n2. Login to Self Service \n3. Re-run any failed policy listed below \n\nThe following failed: \n${jamfProPolicyNameFailures}"
if [[ -n "${supportTeamName}" ]]; then
supportContactMessage+="If you need assistance, please contact the **${supportTeamName}**: \n"
if [[ -n "${supportTeamPhone}" ]]; then
supportContactMessage+="- **Telephone:** ${supportTeamPhone}\n"
fi
if [[ -n "${supportTeamEmail}" ]]; then
supportContactMessage+="- **Email:** ${supportTeamEmail}\n"
fi
if [[ -n "${supportTeamChat}" ]]; then
supportContactMessage+="- **Online Chat:** ${supportTeamChatHyperlink}\n"
fi
if [[ -n "${supportTeamWebsite}" ]]; then
supportContactMessage+="- **Web**: ${supportTeamHyperlink}\n"
fi
if [[ -n "${supportKB}" ]]; then
supportContactMessage+="- **Knowledge Base Article:** ${supportTeamErrorKB}\n"
fi
if [[ -n "${supportTeamHours}" ]]; then
supportContactMessage+="- **Support Hours:** ${supportTeamHours}\n"
fi
fi
failureMessage+="\n\n${supportContactMessage}"
dialogUpdateFailure "message: ${failureMessage}"
dialogUpdateFailure "icon: SF=xmark.circle.fill,weight=bold,colour1=#BB1717,colour2=#F31F1F"
dialogUpdateFailure "button1text: ${button1textCompletionActionOption}"
# Wait for user-acknowledgment due to detected failure
wait
dialogUpdateFailure "quit:"
quitScript "1"
else
outputLineNumberInVerboseDebugMode
dialogUpdateFailure "Display Failure dialog: ${failureDialog}"
killProcess "caffeinate"
if [[ "${brandingBannerDisplayText}" == "true" ]] ; then dialogUpdateSetupYourMac "title: Sorry ${loggedInUserFirstname}, something went sideways"; fi
dialogUpdateSetupYourMac "icon: SF=xmark.circle.fill,weight=bold,colour1=#BB1717,colour2=#F31F1F"
dialogUpdateSetupYourMac "progresstext: Failures detected."
dialogUpdateSetupYourMac "button1text: ${button1textCompletionActionOption}"
dialogUpdateSetupYourMac "button1: enable"
dialogUpdateSetupYourMac "progress: reset"
dialogUpdateSetupYourMac "progresstext: Errors detected; please ${progressTextCompletionAction// and } your ${modelName}, ${loggedInUserFirstname}."
quitScript "1"
fi
else
outputLineNumberInVerboseDebugMode
updateSuccessDialog "All policies executed successfully"
if [[ -n "${webhookURL}" ]]; then
webhookStatus="Successful"
updateSuccessDialog "Sending success webhook message"
webHookMessage
fi
if [[ "${brandingBannerDisplayText}" == "true" ]] ; then dialogUpdateSetupYourMac "title: ${loggedInUserFirstname}‘s ${modelName} is ready!"; fi
dialogUpdateSetupYourMac "icon: SF=checkmark.circle.fill,weight=bold,colour1=#00ff44,colour2=#075c1e"
dialogUpdateSetupYourMac "progresstext: Complete! Please ${progressTextCompletionAction}enjoy your new ${modelName}, ${loggedInUserFirstname}!"
dialogUpdateSetupYourMac "progress: complete"
dialogUpdateSetupYourMac "button1text: ${button1textCompletionActionOption}"
dialogUpdateSetupYourMac "button1: enable"
quitScript "0"
fi
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Parse JSON via osascript and JavaScript
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function get_json_value() {
JSON="$1" osascript -l 'JavaScript' \
-e 'const env = $.NSProcessInfo.processInfo.environment.objectForKey("JSON").js' \
-e "JSON.parse(env).$2"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Parse JSON via osascript and JavaScript for the Welcome dialog (thanks, @bartreardon!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function get_json_value_welcomeDialog() {
for var in "${@:2}"; do jsonkey="${jsonkey}['${var}']"; done
JSON="$1" osascript -l 'JavaScript' \
-e 'const env = $.NSProcessInfo.processInfo.environment.objectForKey("JSON").js' \
-e "JSON.parse(env)$jsonkey"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Execute Jamf Pro Policy Custom Events (thanks, @smithjw)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function run_jamf_trigger() {
outputLineNumberInVerboseDebugMode
trigger="$1"
if [[ "${debugMode}" == "true" ]] || [[ "${debugMode}" == "verbose" ]] ; then
updateSetupYourMacDialog "DEBUG MODE: TRIGGER: $jamfBinary policy -event $trigger ${suppressRecon}"
sleep "${debugModeSleepAmount}"
else
updateSetupYourMacDialog "RUNNING: $jamfBinary policy -event $trigger"
eval "${jamfBinary} policy -event ${trigger} ${suppressRecon}" # Add comment for policy testing
# eval "${jamfBinary} policy -event ${trigger} ${suppressRecon} -verbose | tee -a ${scriptLog}" # Remove comment for policy testing
fi
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Confirm Policy Execution
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function confirmPolicyExecution() {
outputLineNumberInVerboseDebugMode
trigger="${1}"
validation="${2}"
updateSetupYourMacDialog "Confirm Policy Execution: '${trigger}' '${validation}'"
if [ "${suppressReconOnPolicy}" == "true" ]; then suppressRecon="-forceNoRecon"; fi
case ${validation} in
*/* ) # If the validation variable contains a forward slash (i.e., "/"), presume it's a path and check if that path exists on disk
outputLineNumberInVerboseDebugMode
if [[ "${debugMode}" == "true" ]] || [[ "${debugMode}" == "verbose" ]] ; then
updateSetupYourMacDialog "Confirm Policy Execution: DEBUG MODE: Skipping 'run_jamf_trigger ${trigger}'"
sleep "${debugModeSleepAmount}"
elif [[ -e "${validation}" ]]; then
updateSetupYourMacDialog "Confirm Policy Execution: ${validation} exists; skipping 'run_jamf_trigger ${trigger}'"
previouslyInstalled="true"
else
updateSetupYourMacDialog "Confirm Policy Execution: ${validation} does NOT exist; executing 'run_jamf_trigger ${trigger}'"
previouslyInstalled="false"
run_jamf_trigger "${trigger}"
fi
;;
"None" | "none" )
outputLineNumberInVerboseDebugMode
updateSetupYourMacDialog "Confirm Policy Execution: ${validation}"
if [[ "${debugMode}" == "true" ]] || [[ "${debugMode}" == "verbose" ]] ; then
sleep "${debugModeSleepAmount}"
else
run_jamf_trigger "${trigger}"
fi
;;
"Recon" | "recon" )
outputLineNumberInVerboseDebugMode
updateSetupYourMacDialog "Confirm Policy Execution: ${validation}"
if [[ "${debugMode}" == "true" ]] || [[ "${debugMode}" == "verbose" ]] ; then
updateSetupYourMacDialog "DEBUG MODE: Set 'debugMode' to false to update computer inventory with the following 'reconOptions': \"${reconOptions}\" …"
sleep "${debugModeSleepAmount}"
else
updateSetupYourMacDialog "Updating computer inventory with the following 'reconOptions': \"${reconOptions}\" …"
dialogUpdateSetupYourMac "listitem: index: $i, status: wait, statustext: Updating …, "
reconRaw=$( eval "${jamfBinary} recon ${reconOptions} -verbose | tee -a ${scriptLog}" )
computerID=$( echo "${reconRaw}" | grep '<computer_id>' | xmllint --xpath xmllint --xpath '/computer_id/text()' - )
fi
;;
* )
outputLineNumberInVerboseDebugMode
updateSetupYourMacDialog "Confirm Policy Execution Catch-all: ${validation}"
if [[ "${debugMode}" == "true" ]] || [[ "${debugMode}" == "verbose" ]] ; then
sleep "${debugModeSleepAmount}"
else
run_jamf_trigger "${trigger}"
fi
;;
esac
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Validate Policy Result
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function validatePolicyResult() {
outputLineNumberInVerboseDebugMode
trigger="${1}"
validation="${2}"
updateSetupYourMacDialog "Validate Policy Result: '${trigger}' '${validation}'"
case ${validation} in
###
# Absolute Path
# Simulates pre-v1.6.0 behavior, for example: "/Applications/Microsoft Teams classic.app/Contents/Info.plist"
###
*/* )
updateSetupYourMacDialog "Validate Policy Result: Testing for \"$validation\" …"
if [[ "${previouslyInstalled}" == "true" ]]; then
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Previously Installed"
elif [[ -e "${validation}" ]]; then
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Installed"
else
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
;;
###
# Local
# Validation within this script, for example: "rosetta" or "filevault"
###
"Local" )
case ${trigger} in
rosetta )
updateSetupYourMacDialog "Locally Validate Policy Result: Rosetta 2 … " # Thanks, @smithjw!
dialogUpdateSetupYourMac "listitem: index: $i, status: wait, statustext: Checking …"
arch=$( /usr/bin/arch )
if [[ "${arch}" == "arm64" ]]; then
# Mac with Apple silicon; check for Rosetta
rosettaTest=$( arch -x86_64 /usr/bin/true 2> /dev/null ; echo $? )
if [[ "${rosettaTest}" -eq 0 ]]; then
# Installed
updateSetupYourMacDialog "Locally Validate Policy Result: Rosetta 2 is installed"
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Running"
else
# Not Installed
updateSetupYourMacDialog "Locally Validate Policy Result: Rosetta 2 is NOT installed"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
else
# Ineligible
updateSetupYourMacDialog "Locally Validate Policy Result: Rosetta 2 is not applicable"
dialogUpdateSetupYourMac "listitem: index: $i, status: error, statustext: Ineligible"
fi
;;
filevault )
updateSetupYourMacDialog "Locally Validate Policy Result: Validate FileVault … "
dialogUpdateSetupYourMac "listitem: index: $i, status: wait, statustext: Checking …"
updateSetupYourMacDialog "Validate Policy Result: Pausing for 5 seconds for FileVault … "
sleep 5 # Arbitrary value; tuning needed
fileVaultCheck=$( fdesetup isactive )
if [[ -f /Library/Preferences/com.apple.fdesetup.plist ]] || [[ "$fileVaultCheck" == "true" ]]; then
fileVaultStatus=$( fdesetup status -extended -verbose 2>&1 )
case ${fileVaultStatus} in
*"FileVault is On."* )
updateSetupYourMacDialog "Locally Validate Policy Result: FileVault: FileVault is On."
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Enabled"
;;
*"Deferred enablement appears to be active for user"* )
updateSetupYourMacDialog "Locally Validate Policy Result: FileVault: Enabled"
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Enabled (next login)"
;;
* )
dialogUpdateSetupYourMac "listitem: index: $i, status: error, statustext: Unknown"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
;;
esac
else
updateSetupYourMacDialog "Locally Validate Policy Result: '/Library/Preferences/com.apple.fdesetup.plist' NOT Found"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
;;
sophosEndpointServices )
updateSetupYourMacDialog "Locally Validate Policy Result: Sophos Endpoint RTS Status … "
dialogUpdateSetupYourMac "listitem: index: $i, status: wait, statustext: Checking …"
if [[ -d /Applications/Sophos/Sophos\ Endpoint.app ]]; then
if [[ -f /Library/Preferences/com.sophos.sav.plist ]]; then
sophosOnAccessRunning=$( /usr/bin/defaults read /Library/Preferences/com.sophos.sav.plist OnAccessRunning )
case ${sophosOnAccessRunning} in
"0" )
updateSetupYourMacDialog "Locally Validate Policy Result: Sophos Endpoint RTS Status: Disabled"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
;;
"1" )
updateSetupYourMacDialog "Locally Validate Policy Result: Sophos Endpoint RTS Status: Enabled"
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Running"
;;
* )
updateSetupYourMacDialog "Locally Validate Policy Result: Sophos Endpoint RTS Status: Unknown"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Unknown"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
;;
esac
else
updateSetupYourMacDialog "Locally Validate Policy Result: Sophos Endpoint Not Found"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
else
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
;;
globalProtect )
updateSetupYourMacDialog "Locally Validate Policy Result: Palo Alto Networks GlobalProtect Status … "
dialogUpdateSetupYourMac "listitem: index: $i, status: wait, statustext: Checking …"
if [[ -d /Applications/GlobalProtect.app ]]; then
updateSetupYourMacDialog "Locally Validate Policy Result: Pausing for 10 seconds to allow Palo Alto Networks GlobalProtect Services … "
sleep 10 # Arbitrary value; tuning needed
if [[ -f /Library/Preferences/com.paloaltonetworks.GlobalProtect.settings.plist ]]; then
globalProtectStatus=$( /usr/libexec/PlistBuddy -c "print :Palo\ Alto\ Networks:GlobalProtect:PanGPS:disable-globalprotect" /Library/Preferences/com.paloaltonetworks.GlobalProtect.settings.plist )
case "${globalProtectStatus}" in
"0" )
updateSetupYourMacDialog "Locally Validate Policy Result: Palo Alto Networks GlobalProtect Status: Enabled"
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Running"
;;
"1" )
updateSetupYourMacDialog "Locally Validate Policy Result: Palo Alto Networks GlobalProtect Status: Disabled"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
;;
* )
updateSetupYourMacDialog "Locally Validate Policy Result: Palo Alto Networks GlobalProtect Status: Unknown"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Unknown"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
;;
esac
else
updateSetupYourMacDialog "Locally Validate Policy Result: Palo Alto Networks GlobalProtect Not Found"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
else
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
;;
* )
updateSetupYourMacDialog "Locally Validate Policy Result: Local Validation “${validation}” Missing"
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Missing Local “${validation}” Validation"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
;;
esac
;;
###
# Remote
# Validation via a Jamf Pro policy which has a single-script payload, for example: "symvGlobalProtect"
# See: https://vimeo.com/782561166
###
"Remote" )
if [[ "${debugMode}" == "true" ]] || [[ "${debugMode}" == "verbose" ]] ; then
updateSetupYourMacDialog "DEBUG MODE: Remotely Confirm Policy Execution: Skipping 'run_jamf_trigger ${trigger}'"
dialogUpdateSetupYourMac "listitem: index: $i, status: error, statustext: Debug Mode Enabled"
sleep 0.5
else
updateSetupYourMacDialog "Remotely Validate '${trigger}' '${validation}'"
dialogUpdateSetupYourMac "listitem: index: $i, status: wait, statustext: Checking …"
result=$( "${jamfBinary}" policy -event "${trigger}" | grep "Script result:" )
if [[ "${result}" == *"Failed"* ]]; then
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Failed"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
elif [[ "${result}" == *"Running"* ]]; then
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Running"
elif [[ "${result}" == *"Installed"* || "${result}" == *"Success"* ]]; then
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Installed"
else
dialogUpdateSetupYourMac "listitem: index: $i, status: fail, statustext: Unknown"
jamfProPolicyTriggerFailure="failed"
exitCode="1"
jamfProPolicyNameFailures+="• $listitem \n"
fi
fi
;;
###
# None: For triggers which don't require validation
# (Always evaluates as: 'success' and 'Installed')
###
"None" | "none")
outputLineNumberInVerboseDebugMode
updateSetupYourMacDialog "Confirm Policy Execution: ${validation}"
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Installed"
;;
###
# Recon: For reporting computer inventory update
# (Always evaluates as: 'success' and 'Updated')
###
"Recon" | "recon" )
outputLineNumberInVerboseDebugMode
updateSetupYourMacDialog "Confirm Policy Execution: ${validation}"
dialogUpdateSetupYourMac "listitem: index: $i, status: success, statustext: Updated"
;;
###
# Catch-all
###
* )
outputLineNumberInVerboseDebugMode
updateSetupYourMacDialog "Validate Policy Results Catch-all: ${validation}"
dialogUpdateSetupYourMac "listitem: index: $i, status: error, statustext: Error"
;;
esac
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Kill a specified process (thanks, @grahampugh!)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function killProcess() {
process="$1"
if process_pid=$( pgrep -a "${process}" 2>/dev/null ) ; then
info "Attempting to terminate the '$process' process …"
info "(Termination message indicates success.)"
kill "$process_pid" 2> /dev/null
if pgrep -a "$process" >/dev/null ; then
error "'$process' could not be terminated."
fi
else
info "The '$process' process isn't running."
fi
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Completion Action (i.e., Wait, Sleep, Logout, Restart or Shutdown)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
function completionAction() {
outputLineNumberInVerboseDebugMode
if [[ "${debugMode}" == "true" ]] || [[ "${debugMode}" == "verbose" ]] ; then
# If Debug Mode is enabled, ignore specified `completionActionOption`, display simple dialog box and exit
runAsUser osascript -e 'display dialog "Setup Your Mac is operating in Debug Mode.\r\r• completionActionOption == '"'${completionActionOption}'"'\r\r" with title "Setup Your Mac: Debug Mode" buttons {"Close"} with icon note'
exitCode="0"
else
shopt -s nocasematch
case ${completionActionOption} in
"Shut Down" )
completionActionOut "Shut Down sans user interaction"
killProcess "Self Service"
# runAsUser osascript -e 'tell app "System Events" to shut down'
# sleep 5 && runAsUser osascript -e 'tell app "System Events" to shut down' &
sleep 5 && shutdown -h now &
;;
"Shut Down Attended" )
completionActionOut "Shut Down, requiring user-interaction"
killProcess "Self Service"
wait
# runAsUser osascript -e 'tell app "System Events" to shut down'
# sleep 5 && runAsUser osascript -e 'tell app "System Events" to shut down' &
sleep 5 && shutdown -h now &
;;
"Shut Down Confirm" )
completionActionOut "Shut down, only after macOS time-out or user confirmation"
runAsUser osascript -e 'tell app "loginwindow" to «event aevtrsdn»'
;;
"Restart" )
completionActionOut "Restart sans user interaction"
killProcess "Self Service"
# runAsUser osascript -e 'tell app "System Events" to restart'
# sleep 5 && runAsUser osascript -e 'tell app "System Events" to restart' &
sleep 5 && shutdown -r now &
;;
"Restart Attended" )
completionActionOut "Restart, requiring user-interaction"
killProcess "Self Service"
wait
# runAsUser osascript -e 'tell app "System Events" to restart'
# sleep 5 && runAsUser osascript -e 'tell app "System Events" to restart' &
sleep 5 && shutdown -r now &
;;
"Restart Confirm" )
completionActionOut "Restart, only after macOS time-out or user confirmation"
runAsUser osascript -e 'tell app "loginwindow" to «event aevtrrst»'
;;
"Log Out" )
completionActionOut "Log out sans user interaction"
killProcess "Self Service"
# sleep 5 && runAsUser osascript -e 'tell app "loginwindow" to «event aevtrlgo»'
# sleep 5 && runAsUser osascript -e 'tell app "loginwindow" to «event aevtrlgo»' &
sleep 5 && launchctl bootout user/"${loggedInUserID}"
;;
"Log Out Attended" )
completionActionOut "Log out, requiring user-interaction"
killProcess "Self Service"
wait
# sleep 5 && runAsUser osascript -e 'tell app "loginwindow" to «event aevtrlgo»'
# sleep 5 && runAsUser osascript -e 'tell app "loginwindow" to «event aevtrlgo»' &
sleep 5 && launchctl bootout user/"${loggedInUserID}"
;;
"Log Out Confirm" )
completionActionOut "Log out, only after macOS time-out or user confirmation"
sleep 5 && runAsUser osascript -e 'tell app "System Events" to log out'
;;
"Sleep"* )
sleepDuration=$( awk '{print $NF}' <<< "${1}" )
completionActionOut "Sleeping for ${sleepDuration} seconds …"
sleep "${sleepDuration}"
killProcess "Dialog"
info "Goodnight!"
;;
"Wait" )
completionActionOut "Waiting for user interaction …"
wait
;;
"Quit" )
completionActionOut "Quitting script"
exitCode="0"
;;
* )
completionActionOut "Using the default of 'wait'"
wait
;;
esac
shopt -u nocasematch
fi
# Remove custom welcomeBannerImageFileName
if [[ -e "/var/tmp/${welcomeBannerImageFileName}" ]]; then
completionActionOut "Removing /var/tmp/${welcomeBannerImageFileName} …"
rm "/var/tmp/${welcomeBannerImageFileName}"
fi
# Remove overlayicon
if [[ -e ${overlayicon} ]]; then
completionActionOut "Removing ${overlayicon} …"
rm "${overlayicon}"
fi
exit "${exitCode}"