-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathjumpcloud_bootstrap_template.sh
1809 lines (1590 loc) · 85.2 KB
/
jumpcloud_bootstrap_template.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
#*******************************************************************************
#
# Version 3.1.10 | See the CHANGELOG.md for version information
#
# See the ReadMe file for detailed configuration steps.
#
# The "jumpcloud_bootstrap_template.sh" is a template file. Populate the
# variables in this template file with your org specific settings and zero
# touch requirements.
#
# Find a detailed description of each variable within the General Settings.
#
# Questions or feedback on the JumpCloud bootstrap workflow? Please
# contact [email protected]
#
# Authors: Scott Reed | [email protected]
# Joe Workman | [email protected]
#
#*******************************************************************************
################################################################################
# General Settings - INSERT-CONFIGURATION - POPULATE THE BELOW VARIABLES #
################################################################################
### Bind user as admin or standard user ###
# Admin user: admin="true"
# Standard user: admin="false"
admin="false"
### Minimum password length ###
# Align this setting with the length settings configured in your JumpCloud admin console
minlength=8
### JumpCloud Connect Key ###
YOUR_CONNECT_KEY=""
### Encrypted API Key ###
## Use below SCRIPT FUNCTION: EncryptKey to encrypt key
ENCRYPTED_KEY=""
### Username of the JumpCloud user whose UID is used for decryption ###
DECRYPT_USER=""
### JumpCloud System Group ID For DEP Enrollment ###
DEP_ENROLLMENT_GROUP_ID=""
### JumpCloud System Group ID For DEP POST Enrollment ###
DEP_POST_ENROLLMENT_GROUP_ID=""
### DEPNotify Welcome Window Title ###
WELCOME_TITLE=""
### DEPNotify Welcome Window Text use \n for line breaks ###
WELCOME_TEXT=""
### Boolean to delete the enrollment user set through MDM ###
# Set to false to keep the enrollment users profile on the system
# Ex: DELETE_ENROLLMENT_USERS=false
DELETE_ENROLLMENT_USERS=true
### Username of the enrollment user account configured in the MDM.
### This account will be deleted if the above boolean is set to true.
ENROLLMENT_USER=""
### NTP server, set to time.apple.com by default, Ensure time is correct ###
NTP_SERVER="time.apple.com"
### Daemon Variable
DAEMON="com.jumpcloud.prestage.plist"
### User self identification parameter
# Update the SELF_ID variable with one of the below options to change the default option (Company Email)
# Company Email (default): SELF_ID="CE"
# lastname: SELF_ID="LN"
# personal email: SELF_ID="PE"
# NOTE for "personal email" the JumpCloud user field "description" is used
SELF_ID="CE"
### Include secret id (employee ID) ###
# Default setting is false
# Set to true to add "secret word" to user self identification screen
# This is recommended if "active" JumpCloud users will be enrolled
# NOTE for "secret word" the JumpCloud user field "employeeID" is used
# Ex: DELETE_ENROLLMENT_USERS=true
SELF_SECRET=false
### Password Update Settings ###
# This setting defines if active users will be forced to update their passwords
# Pending users will always be required to set a password during enrollment
# Default setting is false
# Update the SELF_ID SELF_PASSWD to modify this setting
# Ex: SELF_PASSWD=true
SELF_PASSWD=false
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END General Settings ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#-------------------------------------------------------------------------------
# Script Functions -
#-------------------------------------------------------------------------------
# Used to create $ENCRYPTED_KEY
# Usage: EncryptKey "API_KEY" "DECRYPT_USER_UID" "ORG_ID"
function EncryptKey() {
local ENCRYPTION_KEY=${2}${3}
local ENCRYPTED_KEY=$(echo "${1}" | /usr/bin/openssl enc -e -base64 -A -aes-128-ctr -md md5 -nopad -nosalt -k ${ENCRYPTION_KEY})
echo "Encrypted key: ${ENCRYPTED_KEY}"
}
# Used to decrypt $ENCRYPTED_KEY
# Usage: DecryptKey "ENCRYPTED_KEY" "DECRYPT_USER_UID" "ORG_ID"
function DecryptKey() {
echo "${1}" | /usr/bin/openssl enc -d -base64 -aes-128-ctr -md md5 -nopad -A -nosalt -k "${2}${3}"
}
# Resets DEPNotify
function DEPNotifyReset() {
ACTIVE_USER=$( ls -l /dev/console | awk '{print $3}' )
rm /var/tmp/depnotify* >/dev/null 2>&1
rm /var/tmp/com.depnotify.* >/dev/null 2>&1
rm /Users/"$ACTIVE_USER"/Library/Preferences/menu.nomad.DEPNotify* >/dev/null 2>&1
killall cfprefsd
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END Script Functions ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#-------------------------------------------------------------------------------
# Script Variables -
#-------------------------------------------------------------------------------
WINDOW_TITLE="Welcome"
DEP_N_DEBUG="/var/tmp/debug_depnotify.log"
DEP_N_APP="/Applications/Utilities/DEPNotify.app"
DEP_N_LOG="/var/tmp/depnotify.log"
DEP_N_REGISTER_DONE="/var/tmp/com.depnotify.registration.done"
DEP_N_DONE="/var/tmp/com.depnotify.provisioning.done"
# Script Receipts Removed at workflow completion
DEP_N_GATE_INSTALLJC="/var/tmp/com.jumpcloud.gate.installjc"
DEP_N_GATE_SYSADD="/var/tmp/com.jumpcloud.gate.sysadd"
DEP_N_GATE_UI="/var/tmp/com.jumpcloud.gate.ui"
DEP_N_GATE_DONE="/var/tmp/com.jumpcloud.gate.done"
DEP_N_COUNTER="/var/tmp/com.jumpcloud.gate.counter.txt"
DEP_N_PERSIST="/var/tmp/com.jumpcloud.persist.txt"
DEP_N_HTTP_RESPONSE="/var/tmp/com.jumpcloud.httpResponse.txt"
# System Versions
MacOSMajorVersion=$(sw_vers -productVersion | cut -d '.' -f 1)
MacOSMinorVersion=$(sw_vers -productVersion | cut -d '.' -f 2)
MacOSPatchVersion=$(sw_vers -productVersion | cut -d '.' -f 3)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END Script Variables ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#*******************************************************************************
# Pre login bootstrap workflow *
#*******************************************************************************
CLIENT="mdm-zero-touch"
VERSION="3.1.10"
USER_AGENT="JumpCloud_${CLIENT}/${VERSION}"
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END Script Variables ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#*******************************************************************************
# Pre login bootstrap workflow *
#*******************************************************************************
# First condition - is JC installed
if [[ ! -f $DEP_N_GATE_INSTALLJC ]]; then
# Caffeinate this script
caffeinate -d -i -m -u &
caffeinatePID=$!
# Install DEPNotify
curl --silent --output /tmp/DEPNotify-1.1.6.pkg "https://files.nomad.menu/DEPNotify.pkg" >/dev/null
installer -pkg /tmp/DEPNotify-1.1.6.pkg -target /
# Create DEPNotify log files
touch "$DEP_N_DEBUG"
touch "$DEP_N_LOG"
# Configure DEPNotify General Settings
# echo "Command: QuitKey: x" >>"$DEP_N_LOG"
echo "Command: WindowTitle: $WINDOW_TITLE" >>"$DEP_N_LOG"
echo "Command: MainTitle: $WELCOME_TITLE" >>"$DEP_N_LOG"
echo "Command: MainText: $WELCOME_TEXT" >>"$DEP_N_LOG"
echo "Status: Installing the JumpCloud agent" >>"$DEP_N_LOG"
# Wait for active user session
FINDER_PROCESS=$(pgrep -l "Finder")
until [ "$FINDER_PROCESS" != "" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Finder process not found. User session not active." >>"$DEP_N_DEBUG"
sleep 1
FINDER_PROCESS=$(pgrep -l "Finder")
done
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END Pre login bootstrap workflow ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#*******************************************************************************
# Post login active session workflow *
#*******************************************************************************
# Capture active user username
ACTIVE_USER=$( ls -l /dev/console | awk '{print $3}' )
# Captures active users UID
uid=$(id -u "$ACTIVE_USER")
DEP_N_USER_INPUT_PLIST="/Users/$ACTIVE_USER/Library/Preferences/menu.nomad.DEPNotifyUserInput.plist"
DEP_N_CONFIG_PLIST="/Users/$ACTIVE_USER/Library/Preferences/menu.nomad.DEPNotify.plist"
defaults write "$DEP_N_CONFIG_PLIST" pathToPlistFile "$DEP_N_USER_INPUT_PLIST"
################################################################################
# DEPNotify PLIST Settings - INSERT-CONFIGURATION #
################################################################################
#<--INSERT-CONFIGURATION for "DEPNotify PLIST Settings" below this line---------
defaults write "$DEP_N_CONFIG_PLIST" registrationMainTitle "Activate Your Account"
defaults write "$DEP_N_CONFIG_PLIST" registrationButtonLabel "Activate Your Account"
if [[ $SELF_ID == "CE" ]]; then
defaults write "$DEP_N_CONFIG_PLIST" textField1Label "Enter Your Company Email Address"
defaults write "$DEP_N_CONFIG_PLIST" textField1Placeholder "enter email in all lowercase characters"
elif [[ $SELF_ID == "PE" ]]; then
defaults write "$DEP_N_CONFIG_PLIST" textField1Label "Enter Your Personal Email Address"
defaults write "$DEP_N_CONFIG_PLIST" textField1Placeholder "enter email in all lowercase characters"
elif [[ $SELF_ID == "LN" ]]; then
defaults write "$DEP_N_CONFIG_PLIST" textField1Label "Enter Your Last Name"
defaults write "$DEP_N_CONFIG_PLIST" textField1Placeholder "enter last name in all lowercase characters"
fi
if [[ $SELF_SECRET == true ]]; then
defaults write "$DEP_N_CONFIG_PLIST" textField2Label "Enter Your Secret Word"
defaults write "$DEP_N_CONFIG_PLIST" textField2Placeholder "enter secret in all lowercase characters"
fi
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END DEPNotify PLIST Settings ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Launch DEPNotify full screen
# Set ownership of the plist file
chown "$ACTIVE_USER":staff "$DEP_N_CONFIG_PLIST"
chmod 600 "$DEP_N_CONFIG_PLIST"
sudo -u "$ACTIVE_USER" open -a "$DEP_N_APP" --args -path "$DEP_N_LOG" -fullScreen
# Download and install the JumpCloud agent
# cat EOF can not be indented
curl --silent --output /tmp/jumpcloud-agent.pkg "https://cdn02.jumpcloud.com/production/jumpcloud-agent.pkg" >/dev/null
mkdir -p /opt/jc
cat <<-EOF >/opt/jc/agentBootstrap.json
{
"publicKickstartUrl": "https://kickstart.jumpcloud.com:443",
"privateKickstartUrl": "https://private-kickstart.jumpcloud.com:443",
"connectKey": "$YOUR_CONNECT_KEY"
}
EOF
# Installs JumpCloud agent
echo "$(date "+%Y-%m-%d %H:%M:%S"): User $ACTIVE_USER is logged in, installing JC" >>"$DEP_N_DEBUG"
installer -pkg /tmp/jumpcloud-agent.pkg -target /
# Validate JumpCloud agent install
JCAgentConfPath='/opt/jc/jcagent.conf'
while [ ! -f "$JCAgentConfPath" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for JC Agent to install" >>"$DEP_N_DEBUG"
sleep 1
done
conf="$(cat /opt/jc/jcagent.conf)"
regex='\"systemKey\":\"[a-zA-Z0-9]{24}\"'
if [[ $conf =~ $regex ]]; then
systemKey="${BASH_REMATCH[@]}"
fi
while [ -z "$systemKey" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for systemKey to register" >>"$DEP_N_DEBUG"
sleep 1
conf="$(cat /opt/jc/jcagent.conf)"
if [[ $conf =~ $regex ]]; then
systemKey="${BASH_REMATCH[@]}"
fi
done
echo "$(date "+%Y-%m-%d %H:%M:%S"): JumpCloud agent installed!"
Sleep 1
echo "Status: JumpCloud agent installed!" >>"$DEP_N_LOG"
# JumpCloud installed - add gate file
kill $caffeinatePID
touch $DEP_N_GATE_INSTALLJC
fi
# Check if the system has yet to be added to JumpCloud
if [[ ! -f $DEP_N_GATE_SYSADD ]]; then
# Caffeinate this script
caffeinate -d -i -m -u &
caffeinatePID=$!
sleep 1
echo "Status: Pulling configuration settings from JumpCloud" >>"$DEP_N_LOG"
# Add system to DEP_ENROLLMENT_GROUP_ID using System Context API Authentication
conf="$(cat /opt/jc/jcagent.conf)"
regex='\"systemKey\":\"[a-zA-Z0-9]{24}\"'
if [[ $conf =~ $regex ]]; then
systemKey="${BASH_REMATCH[@]}"
fi
echo "$(date "+%Y-%m-%d %H:%M:%S"): systemKey = $systemKey " >>"$DEP_N_DEBUG"
regex='[a-zA-Z0-9]{24}'
if [[ $systemKey =~ $regex ]]; then
systemID="${BASH_REMATCH[@]}"
fi
echo "$(date "+%Y-%m-%d %H:%M:%S"): systemID = $systemID " >>"$DEP_N_DEBUG"
now=$(date -u "+%a, %d %h %Y %H:%M:%S GMT")
# create the string to sign from the request-line and the date
signstr="POST /api/v2/systemgroups/${DEP_ENROLLMENT_GROUP_ID}/members HTTP/1.1\ndate: ${now}"
# create the signature
signature=$(printf "$signstr" | openssl dgst -sha256 -sign /opt/jc/client.key | openssl enc -e -a | tr -d '\n')
DEPenrollmentGroupAdd=$(
curl -s \
-X 'POST' \
-A "${USER_AGENT}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Date: ${now}" \
-H "Authorization: Signature keyId=\"system/${systemID}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"${signature}\"" \
-d '{"op": "add","type": "system","id": "'${systemID}'"}' \
"https://console.jumpcloud.com/api/v2/systemgroups/${DEP_ENROLLMENT_GROUP_ID}/members"
)
# create the GET string to sign from the request-list and the date
signstr_check="GET /api/v2/systems/${systemID}/memberof HTTP/1.1\ndate: ${now}"
# create the GET signature
signature_check=$(printf "$signstr_check" | openssl dgst -sha256 -sign /opt/jc/client.key | openssl enc -e -a | tr -d '\n')
DEPenrollmentGroupGet=$(
curl \
-X 'GET' \
-A "${USER_AGENT}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Date: ${now}" \
-H "Authorization: Signature keyId=\"system/${systemID}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"${signature_check}\"" \
--url "https://console.jumpcloud.com/api/v2/systems/${systemID}/memberof"
)
# check if the system was added to the DEP ENROLLMENT GROUP in JumpCloud
groupCheck=$(echo $DEPenrollmentGroupGet | grep $DEP_ENROLLMENT_GROUP_ID)
# given the case that the above POST request fails, system would not be in the enrollment group
# while the groupCheck variable is empty, attempt to add the system to the enrollment group
# then check if the group was added, if the system is in the enrollment group, exit the loop
echo "$(date "+%Y-%m-%d %H:%M:%S"): Expected systemID: ${systemID} to be a member of group: ${DEP_ENROLLMENT_GROUP_ID}" >>"$DEP_N_DEBUG"
while [[ -z $groupCheck ]]; do
# log note
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for system to be added to the DEP ENROLLMENT GROUP" >>"$DEP_N_DEBUG"
echo "Adding System to JumpCloud Enrollment Group" >>"$DEP_N_LOG"
sleep 5
# if system is 10.12 or newer, this command should work to set the system time
if [[ ($MacOSMajorVersion -eq 10 && $MacOSMinorVersion -ge 12) || $MacOSMajorVersion -ge 11 ]]; then
# only run this once - set system time (in testing restored images can be out of sync with a time server)
echo "$(date "+%Y-%m-%d %H:%M:%S"): Setting the correct system time" >>"$DEP_N_DEBUG"
sntp -sS $NTP_SERVER
fi
# attempt to add system to enrollment group
echo "$(date "+%Y-%m-%d %H:%M:%S"): Attempting to add system to enrollment group again" >>"$DEP_N_DEBUG"
now=$(date -u "+%a, %d %h %Y %H:%M:%S GMT")
signstr="POST /api/v2/systemgroups/${DEP_ENROLLMENT_GROUP_ID}/members HTTP/1.1\ndate: ${now}"
# create the signature with updated time and string
signature=$(printf "$signstr" | openssl dgst -sha256 -sign /opt/jc/client.key | openssl enc -e -a | tr -d '\n')
DEPenrollmentGroupAdd=$(
curl -s \
-X 'POST' \
-A "${USER_AGENT}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Date: ${now}" \
-H "Authorization: Signature keyId=\"system/${systemID}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"${signature}\"" \
-d '{"op": "add","type": "system","id": "'${systemID}'"}' \
"https://console.jumpcloud.com/api/v2/systemgroups/${DEP_ENROLLMENT_GROUP_ID}/members"
)
# check if the system is in the enrollment group
echo "$(date "+%Y-%m-%d %H:%M:%S"): Checking Status" >>"$DEP_N_DEBUG"
now=$(date -u "+%a, %d %h %Y %H:%M:%S GMT")
signstr_check="GET /api/v2/systems/${systemID}/memberof HTTP/1.1\ndate: ${now}"
signature_check=$(printf "$signstr_check" | openssl dgst -sha256 -sign /opt/jc/client.key | openssl enc -e -a | tr -d '\n')
DEPenrollmentGroupGet=$(
curl \
-X 'GET' \
-A "${USER_AGENT}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Date: ${now}" \
-H "Authorization: Signature keyId=\"system/${systemID}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"${signature_check}\"" \
--url "https://console.jumpcloud.com/api/v2/systems/${systemID}/memberof"
)
groupCheck=$(echo $DEPenrollmentGroupGet | grep $DEP_ENROLLMENT_GROUP_ID)
done
# Set the receipt for the system add gate. The system was added to JumpCloud at this stage
echo "$(date "+%Y-%m-%d %H:%M:%S"): System added, killing caffeinate process at PID: ${caffeinatePID}" >>"$DEP_N_DEBUG"
kill $caffeinatePID
touch $DEP_N_GATE_SYSADD
echo "System added to JumpCloud Enrollment Group" >>"$DEP_N_LOG"
fi
# User interaction steps - check if user has completed these steps.
if [[ ! -f $DEP_N_GATE_UI ]]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): Begin User Interaction steps" >>"$DEP_N_DEBUG"
# Caffeinate this script
caffeinate -d -i -m -u &
caffeinatePID=$!
echo "$(date "+%Y-%m-%d %H:%M:%S"): User Interaction steps, starting caffeinate process at PID: ${caffeinatePID}" >>"$DEP_N_DEBUG"
# reboot check
FINDER_PROCESS=$(pgrep -l "Finder")
until [ "$FINDER_PROCESS" != "" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Finder process not found. User session not active." >>"$DEP_N_DEBUG"
sleep 1
FINDER_PROCESS=$(pgrep -l "Finder")
done
echo "$(date "+%Y-%m-%d %H:%M:%S"): User session active." >>"$DEP_N_DEBUG"
# check if the DEPNotify process is running
process=$(echo | ps aux | grep "\bDEPNotify\.app")
if [[ -z $process ]]; then
ACTIVE_USER=$( ls -l /dev/console | awk '{print $3}' )
echo "$(date "+%Y-%m-%d %H:%M:%S"): Expected DEPNotify.app to be in process list, process not found. Launching DEPNotify as $ACTIVE_USER" >>"$DEP_N_DEBUG"
sudo -u "$ACTIVE_USER" open -a "$DEP_N_APP" --args -path "$DEP_N_LOG" -fullScreen
process=$(echo | ps aux | grep "\bDEPNotify\.app")
sleep 2
echo "$(date "+%Y-%m-%d %H:%M:%S"): DEPNotify should be running on process: $process" >>"$DEP_N_DEBUG"
fi
# Waiting for DECRYPT_USER_ID to be bound to system
echo "Status: Pulling Security Settings from JumpCloud" >>"$DEP_N_LOG"
DECRYPT_USER_ID=$(dscl . -read /Users/$DECRYPT_USER | grep UniqueID | cut -d " " -f 2)
while [ -z "$DECRYPT_USER_ID" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for DECRYPT_USER_ID for user $DECRYPT_USER" >>"$DEP_N_DEBUG"
sleep 1
DECRYPT_USER_ID=$(dscl . -read /Users/$DECRYPT_USER | grep UniqueID | cut -d " " -f 2)
done
echo "Status: Security Settings Configured" >>"$DEP_N_LOG"
# Gather OrgID
conf="$(cat /opt/jc/jcagent.conf)"
regex='\"ldap_domain\":\"[a-zA-Z0-9]*'
if [[ $conf =~ $regex ]]; then
ORG_ID_RAW="${BASH_REMATCH[@]}"
fi
ORG_ID=$(echo $ORG_ID_RAW | cut -d '"' -f 4)
if [ ${#ORG_ID} -eq 24 ]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): ORG_ID is the correct length" >>"$DEP_N_DEBUG"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): ORG_ID is not the correct length: ${#ORG_ID}" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): Getting System Details with systemContext API" >>"$DEP_N_DEBUG"
# Get the current time.
now=$(date -u "+%a, %d %h %Y %H:%M:%S GMT")
# create the string to sign from the request-line and the date
signstr="GET /api/systems/${systemID} HTTP/1.1\ndate: ${now}"
# create the signature
signature=$(printf "$signstr" | openssl dgst -sha256 -sign /opt/jc/client.key | openssl enc -e -a | tr -d '\n')
# make the api call passing the signature in the authorization header
httpRequest=$(
curl -s -o $DEP_N_HTTP_RESPONSE -w "%{http_code}" \
-H "Accept: application/json" \
-H "Date: ${now}" \
-H "Authorization: Signature keyId=\"system/${systemID}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"${signature}\"" \
--url https://console.jumpcloud.com/api/systems/${systemID}
)
# Check Response
responseContent=$(cat $DEP_N_HTTP_RESPONSE)
if [[ $httpRequest != "200" ]]; then
# handle error
echo "$(date "+%Y-%m-%d %H:%M:%S"): [error] HTTP Response does not indicate success" >>"$DEP_N_DEBUG"
# echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response: $responseContent"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): System details returned successfully" >>"$DEP_N_DEBUG"
# echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response: $responseContent"
# Get ORGID
regexORG='\"organization\":\"([a-zA-Z0-9]{24})\"'
if [[ $responseContent =~ $regexORG ]]; then
ORG_ID="${BASH_REMATCH[1]}"
fi
if [ ${#ORG_ID} -eq 24 ]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): ORG_ID is the correct length" >>"$DEP_N_DEBUG"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): ORG_ID is not the correct length: ${#ORG_ID}" >>"$DEP_N_DEBUG"
fi
fi
fi
APIKEY=$(DecryptKey $ENCRYPTED_KEY $DECRYPT_USER_ID $ORG_ID)
if [ ${#APIKEY} -eq 40 ]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): APIKey is the correct length" >>"$DEP_N_DEBUG"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): APIKey is not the correct length: ${#APIKEY}" >>"$DEP_N_DEBUG"
fi
###
# Recapture these variables - necessary if the system was restarted
DEP_N_USER_INPUT_PLIST="/Users/$ACTIVE_USER/Library/Preferences/menu.nomad.DEPNotifyUserInput.plist"
DEP_N_CONFIG_PLIST="/Users/$ACTIVE_USER/Library/Preferences/menu.nomad.DEPNotify.plist"
ACTIVE_USER=$( ls -l /dev/console | awk '{print $3}' )
uid=$(id -u "$ACTIVE_USER")
###
if [[ -z "${APIKEY}" ]]; then
echo "Command: Notification: Oh no we ran into an error. Tell your Admin that your system could not decrypt the key!" >>"$DEP_N_LOG"
echo "Command: ContinueButtonRegister: EXIT WITH ERROR" >>"$DEP_N_LOG"
exit 1
fi
################################################################################
# User Configuration Settings - INSERT-CONFIGURATION #
################################################################################
#<--INSERT-CONFIGURATION for "User Configuration Settings" below this line-------
### variable assignments for completing the user module
if [[ $SELF_ID == "CE" ]]; then
id_type='"email"'
elif [[ $SELF_ID == "PE" ]]; then
id_type='"description"'
elif [[ $SELF_ID == "LN" ]]; then
id_type='"lastname"'
fi
echo "Command: ContinueButtonRegister: ACTIVATE YOUR ACCOUNT" >>"$DEP_N_LOG"
sleep 1
while [ ! -f "$DEP_N_REGISTER_DONE" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for user to fill in information." >>"$DEP_N_DEBUG"
sleep 1
done
echo "$(date "+%Y-%m-%d %H:%M:%S"): User Selection is: $SELF_ID" >>"$DEP_N_DEBUG"
if [[ $SELF_ID == "CE" ]]; then
CompanyEmail=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Company Email Address")
elif [[ $SELF_ID == "PE" ]]; then
CompanyEmail=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Personal Email Address")
elif [[ $SELF_ID == "LN" ]]; then
CompanyEmail=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Last Name")
fi
if [[ $SELF_SECRET == true ]]; then
Secret=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Secret Word")
fi
## secret sauce
if [[ $SELF_SECRET == true ]]; then
injection='"employeeIdentifier":"'${Secret}'",'
else
injection=""
fi
# pending user search default to false
sec='"activated":false'
search_active=false
search_step=0
# default value for account located
LOCATED_ACCOUNT='False'
while [ "$LOCATED_ACCOUNT" == "False" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): User: $CompanyEmail entered information." >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): Performing Search with the following parameters: " >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): User activation status: $sec" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): Using Secret: $injection" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): ID Type: $id_type" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): ID Value: $CompanyEmail" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
userSearch=$(
curl -s -o $DEP_N_HTTP_RESPONSE -w "%{http_code}" \
-X 'POST' \
-A "${USER_AGENT}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${APIKEY}" \
-d '{"filter":[{'$sec','$injection''${id_type}':"'${CompanyEmail}'"}],"fields":["username"]}' \
"https://console.jumpcloud.com/api/search/systemusers"
)
userSearchResponse=$(cat $DEP_N_HTTP_RESPONSE)
echo "$(date "+%Y-%m-%d %H:%M:%S"): User search returned the following:" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
if [[ $userSearch != "200" ]]; then
# handle error
echo "$(date "+%Y-%m-%d %H:%M:%S"): [error] HTTP Response does not indicate success" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response: $userSearchResponse" >>"$DEP_N_DEBUG"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response Code: $userSearch" >>"$DEP_N_DEBUG"
fi
#debug
echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response: $userSearchResponse" >>"$DEP_N_DEBUG"
regex='totalCount"*.*,"results"'
if [[ $userSearchResponse =~ $regex ]]; then
userSearchRaw="${BASH_REMATCH[@]}"
fi
#debug
totalCount=$(echo $userSearchRaw | cut -d ":" -f2 | cut -d "," -f1)
echo "$(date "+%Y-%m-%d %H:%M:%S"): Total Count: $totalCount" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
sleep 1
# switch to checking active users and increment search step int
echo "$(date "+%Y-%m-%d %H:%M:%S"): active? $search_active, step $search_step, totalCount $totalCount" >>"$DEP_N_DEBUG"
if [[ $search_active == false && $search_step -eq 0 && "$totalCount" != "1" ]]; then
search_step=$((search_step + 1))
echo "$(date "+%Y-%m-%d %H:%M:%S"): no pending users found. Searching for active users. Search step: $search_step" >>"$DEP_N_DEBUG"
sec='"activated":true'
search_active=true
echo "$(date "+%Y-%m-%d %H:%M:%S"): User: $CompanyEmail entered information." >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): Performing Search with the following parameters: " >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): User activation status: $sec" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): Using Secret: $injection" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): ID Type: $id_type" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): ID Value: $CompanyEmail" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
# rerun the search:
userSearch=$(
curl -s -o $DEP_N_HTTP_RESPONSE -w "%{http_code}" \
-X 'POST' \
-A "${USER_AGENT}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${APIKEY}" \
-d '{"filter":[{'$sec','$injection''${id_type}':"'${CompanyEmail}'"}],"fields":["username"]}' \
"https://console.jumpcloud.com/api/search/systemusers"
)
userSearchResponse=$(cat $DEP_N_HTTP_RESPONSE)
echo "$(date "+%Y-%m-%d %H:%M:%S"): User search returned the following:" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
if [[ $userSearch != "200" ]]; then
# handle error
echo "$(date "+%Y-%m-%d %H:%M:%S"): [error] HTTP Response does not indicate success" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response: $responseContent" >>"$DEP_N_DEBUG"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response Code: $userSearch" >>"$DEP_N_DEBUG"
fi
echo "$(date "+%Y-%m-%d %H:%M:%S"): HTTP Response: $userSearchResponse" >>"$DEP_N_DEBUG"
regex='totalCount"*.*,"results"'
if [[ $userSearchResponse =~ $regex ]]; then
userSearchRaw="${BASH_REMATCH[@]}"
fi
#debug
totalCount=$(echo $userSearchRaw | cut -d ":" -f2 | cut -d "," -f1)
echo "$(date "+%Y-%m-%d %H:%M:%S"): Total Count: $totalCount" >>"$DEP_N_DEBUG"
echo "$(date "+%Y-%m-%d %H:%M:%S"): =================================================" >>"$DEP_N_DEBUG"
fi
# success criteria
if [ "$totalCount" == "1" ]; then
search_step=$((search_step + 1))
LOCATED_ACCOUNT='True'
# Get the username from JumpCloud User Search
regex='\"username\":\"([^\"]*)'
if [[ $userSearchResponse =~ $regex ]]; then
usernameMatch="${BASH_REMATCH[1]}"
fi
regex='\"systemUsername\":\"([^\"]*)'
if [[ $userSearchResponse =~ $regex ]]; then
systemUsernameMatch="${BASH_REMATCH[1]}"
fi
# determine the username of the user to be bound
if [[ -z $systemUsernameMatch && -n $usernameMatch ]]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): Found user has username: $usernameMatch" >>"$DEP_N_DEBUG"
echo "$usernameMatch" >>"$DEP_N_PERSIST"
elif
[[ -n $systemUsernameMatch && -n $usernameMatch ]]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): Found user has systemUsername: $systemUsernameMatch" >>"$DEP_N_DEBUG"
echo "$systemUsernameMatch" >>"$DEP_N_PERSIST"
fi
# Set the enrollment user from file
enrollmentUser=$(cat $DEP_N_PERSIST)
if [[ search_step -gt 1 && $search_active == true ]]; then
pass_path=not_required
echo "Status: Click CONTINUE" >>"$DEP_N_LOG"
echo "Command: ContinueButton: CONTINUE" >>"$DEP_N_LOG"
else
pass_path=update_required
echo "Status: Click SET PASSWORD" >>"$DEP_N_LOG"
echo "Command: ContinueButton: SET PASSWORD" >>"$DEP_N_LOG"
fi
fi
if [[ $search_step -ge 1 && "$totalCount" != "1" ]]; then
echo "Status: Account Not Found" >>"$DEP_N_LOG"
# search_step=$((search_step + 1))
rm $DEP_N_REGISTER_DONE >/dev/null 2>&1
echo "$(date "+%Y-%m-%d %H:%M:%S"): Try again search step: $search_step" >>"$DEP_N_DEBUG"
echo "Command: ContinueButtonRegister: Try Again" >>"$DEP_N_LOG"
sleep 1
while [ ! -f "$DEP_N_REGISTER_DONE" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for user to fill in information." >>"$DEP_N_DEBUG"
sleep 1
done
echo "$(date "+%Y-%m-%d %H:%M:%S"): User Selection is: $SELF_ID" >>"$DEP_N_DEBUG"
if [[ $SELF_ID == "CE" ]]; then
CompanyEmail=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Company Email Address")
elif [[ $SELF_ID == "PE" ]]; then
CompanyEmail=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Personal Email Address")
elif [[ $SELF_ID == "LN" ]]; then
CompanyEmail=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Last Name")
fi
if [[ $SELF_SECRET == true ]]; then
Secret=$(defaults read $DEP_N_USER_INPUT_PLIST "Enter Your Secret Word")
# update injection variable
injection='"employeeIdentifier":"'${Secret}'",'
fi
# Reset search variables
search_step=$((0))
search_active=false
sec='"activated":false'
echo "$(date "+%Y-%m-%d %H:%M:%S"): no users found entering loop again search step: $search_step" >>"$DEP_N_DEBUG"
fi
done
# Capture userID
regex='[a-zA-Z0-9]{24}'
if [[ $userSearchResponse =~ $regex ]]; then
# determine cases
if [[ $SELF_PASSWD == true ]]; then
pass_path="update_required"
fi
userID="${BASH_REMATCH[@]}"
echo "$(date "+%Y-%m-%d %H:%M:%S"): JumpCloud userID found userID: "$userID >>"$DEP_N_DEBUG"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): No JumpCloud userID found." >>"$DEP_N_DEBUG"
exit 1
fi
echo "Status: JumpCloud User Account Located" >>"$DEP_N_LOG"
case $pass_path in
update_required)
echo "Status: Click SET PASSWORD" >>"$DEP_N_LOG"
echo "Command: ContinueButton: SET PASSWORD" >>"$DEP_N_LOG"
while [ ! -f "$DEP_N_DONE" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for user to click Set Password." >>"$DEP_N_DEBUG"
sleep 1
done
;;
not_required)
echo "Status: Click CONTINUE" >>"$DEP_N_LOG"
echo "Command: ContinueButton: CONTINUE" >>"$DEP_N_LOG"
while [ ! -f "$DEP_N_DONE" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for user to click Continue." >>"$DEP_N_DEBUG"
sleep 1
done
;;
esac
#### PASSWORD BLOCK ####
case $pass_path in
update_required)
echo "doing password stuff"
# DEPNotify reset
DEPNotifyReset
WINDOW_TITLE='Set a password'
PASSWORD_TITLE="Please set a password"
PASSWORD_TEXT="Your password must be $minlength characters long and contain at least one number, upper case character, lower case character, and special character. \n The longer the better!"
echo "Command: QuitKey: x" >>"$DEP_N_LOG"
echo "Command: WindowTitle: $WINDOW_TITLE" >>"$DEP_N_LOG"
echo "Command: MainTitle: $PASSWORD_TITLE" >>"$DEP_N_LOG"
echo "Command: MainText: $PASSWORD_TEXT" >>"$DEP_N_LOG"
echo "Status: Set a password" >>"$DEP_N_LOG"
sudo -u "$ACTIVE_USER" open -a "$DEP_N_APP" --args -path "$DEP_N_LOG"
Sleep 2
# set the number of password pass checks to zero
passCheck=0
VALID_PASSWORD='False'
while [ "$VALID_PASSWORD" == "False" ]; do
VALID_PASSWORD='True'
password=$(launchctl asuser "$uid" /usr/bin/osascript -e '
Tell application "System Events"
with timeout of 1800 seconds
display dialog "PASSWORD COMPLEXITY REQUIREMENTS:\n--------------------------------------------------------------\n * At least '"$minlength"' characters long \n * Have at least 1 lowercase character \n * Have at least 1 uppercase character \n * Have at least 1 number \n * Have at least 1 special character'"$COMPLEXITY"'" with title "CREATE A SECURE PASSWORD" buttons {"Continue"} default button "Continue" with hidden answer default answer ""' -e 'text returned of result
end timeout
end tell' 2>/dev/null)
# Length check
lengthCheck='.{'$minlength',100}'
if [[ $password =~ $lengthCheck ]]; then
LENGTH=''
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password meets length requirements"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password does not meet length requirements" >>"$DEP_N_DEBUG"
LENGTH='\n* LENGTH'
VALID_PASSWORD='False'
fi
# Upper case check
upperCheck='[[:upper:]]+'
if [[ $password =~ $upperCheck ]]; then
UPPER=''
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password contains a upper case letter"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password does not contain a upper case letter" >>"$DEP_N_DEBUG"
UPPER='\n* UPPER CASE'
VALID_PASSWORD='False'
fi
# Lower chase check
lowerCheck='[[:lower:]]+'
if [[ $password =~ $lowerCheck ]]; then
LOWER=''
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password contains a lower case letter"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password does not contain a lower case letter" >>"$DEP_N_DEBUG"
LOWER='\n* LOWER CASE'
VALID_PASSWORD='False'
fi
# Special character check
specialCharCheck='[!@#$%^&*(),.?":{}|<>]'
if [[ $password =~ $specialCharCheck ]]; then
SPECIAL=''
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password contains a special character"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password does not contains a special character" >>"$DEP_N_DEBUG"
SPECIAL='\n* SPECIAL CHARACTER'
VALID_PASSWORD='False'
fi
# Number check
numberCheck='[0-9]'
if [[ $password =~ $numberCheck ]]; then
NUMBER=''
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password contains a number"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password does not contain a number" >>"$DEP_N_DEBUG"
NUMBER='\n* NUMBER'
VALID_PASSWORD='False'
fi
# only display password match confirmation after all password is valid
if [[ $passCheck == 0 ]]; then
COMPLEXITY='\n\nCOMPLEXITY NOT SATISFIED:\n --------------------------------------------------------------'$LENGTH''$UPPER''$LOWER''$SPECIAL''$NUMBER' \n\n TRY AGAIN'
else
# Dialogue returned with password match status
COMPLEXITY='\n\nCOMPLEXITY NOT SATISFIED:\n --------------------------------------------------------------'$LENGTH''$UPPER''$LOWER''$SPECIAL''$NUMBER''$passMatch' \n\n TRY AGAIN'
fi
if [[ $VALID_PASSWORD == 'True' ]]; then
passCheck=$((passCheck + 1))
passwordMatch=$(launchctl asuser "$uid" /usr/bin/osascript -e '
Tell application "System Events"
with timeout of 1800 seconds
display dialog "CONFIRM PASSWORD:\n--------------------------------------------------------------\n" with title "CONFIRM A SECURE PASSWORD" buttons {"Continue"} default button "Continue" with hidden answer default answer ""' -e 'text returned of result
end timeout
end tell' 2>/dev/null)
# match Check
passMatch="Passwords do not match"
if [[ $password == "$passwordMatch" ]]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): Passwords Match"
passMatch="Passwords match"
else
# Passwords do not match, reset passCheck counter
echo "$(date "+%Y-%m-%d %H:%M:%S"): Password does not contain a match"
passCheck=0
VALID_PASSWORD='False'
fi
COMPLEXITY='\n\nCOMPLEXITY NOT SATISFIED:\n --------------------------------------------------------------'$LENGTH''$UPPER''$LOWER''$SPECIAL''$NUMBER''$passMatch' \n\n TRY AGAIN'
fi
done
echo "Status: Click CONTINUE" >>"$DEP_N_LOG"
echo "Command: ContinueButton: CONTINUE" >>"$DEP_N_LOG"
while [ ! -f "$DEP_N_DONE" ]; do
echo "$(date "+%Y-%m-%d %H:%M:%S"): Waiting for user to click CONTINUE" >>"$DEP_N_DEBUG"
sleep 1
done
;;
not_required)
echo "not required"
;;
esac
#### PASSWORD BLOCK ####
# DEPnotify rest
DEPNotifyReset
touch "$DEP_N_LOG"
WINDOW_TITLE='User Configuration'
FINAL_TITLE="Almost to the finish line!"
FINAL_TEXT='\n \n \n Working on account configuration'
echo "Command: QuitKey: x" >>"$DEP_N_LOG"
echo "Command: WindowTitle: $WINDOW_TITLE" >>"$DEP_N_LOG"
echo "Command: MainTitle: $FINAL_TITLE" >>"$DEP_N_LOG"
echo "Command: MainText: $FINAL_TEXT" >>"$DEP_N_LOG"
echo "Status: Activating Account" >>"$DEP_N_LOG"
sudo -u "$ACTIVE_USER" open -a "$DEP_N_APP" --args -path "$DEP_N_LOG" -fullScreen
## User creation
userUpdate=$(
curl -s \
-X 'PUT' \
-A "${USER_AGENT}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: ${APIKEY}" \
-d '{"password" : "'${password}'"}' \
"https://console.jumpcloud.com/api/systemusers/${userID}"
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END User Configuration Settings ~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# user interaction complete - add gate file
kill $caffeinatePID
touch $DEP_N_GATE_UI
fi
# Final steps to complete the install
if [[ ! -f $DEP_N_GATE_DONE ]]; then
# Caffeinate this script
caffeinate -d -i -m -u &
caffeinatePID=$!
## Get the JumpCloud SystemID
conf="$(cat /opt/jc/jcagent.conf)"
regex='\"systemKey\":\"[a-zA-Z0-9]{24}\"'
if [[ $conf =~ $regex ]]; then
systemKey="${BASH_REMATCH[@]}"
fi
regex='[a-zA-Z0-9]{24}'
if [[ $systemKey =~ $regex ]]; then
systemID="${BASH_REMATCH[@]}"
echo "$(date "+%Y-%m-%d %H:%M:%S"): JumpCloud systemID found: "$systemID >>"$DEP_N_DEBUG"
else
echo "$(date "+%Y-%m-%d %H:%M:%S"): No systemID found" >>"$DEP_N_DEBUG"
exit 1
fi
# we still need to validate the API key variable here. If it's null attempt to get it
if [[ -z $APIKEY ]]; then
echo "$(date "+%Y-%m-%d %H:%M:%S"): Credential set is null, attempting to get API key again..." >>"$DEP_N_DEBUG"
DECRYPT_USER_ID=$(dscl . -read /Users/$DECRYPT_USER | grep UniqueID | cut -d " " -f 2)
# Gather OrgID
conf="$(cat /opt/jc/jcagent.conf)"