This repository has been archived by the owner on Nov 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AutoImagrNBIAppDelegate.applescript
executable file
·5274 lines (5125 loc) · 267 KB
/
AutoImagrNBIAppDelegate.applescript
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
--
-- AppDelegate.applescript
-- AutoImagrNBI
--
-- Created by Ben Toms on 04/06/2014.
-- Copyright (c) 2014 macmule. All rights reserved.
--
script AutoImagrNBIAppDelegate
--- PROPERTIES ---
--- Classes
property parent : class "NSObject"
property NSApp : current application's class "NSApp"
--- Objects
property defaults : ""
property hostMacOSVersion : ""
property hostMacOSBuildVersion : ""
property mainWindow : ""
property optionsWindow : ""
property showBuildProcessWindow : ""
property selectedOSdmgPath : ""
property selectedOSdmgMountPath : ""
property selectedOSdmgKind : ""
property selectedOSdmgVersion : ""
property selectedOSBuilddmgVersion : ""
property selectedAppPath : ""
property selectedAppTextField : ""
property selectedAppBundleName : ""
property selectedImagrAppVersion : ""
property imagrConfigURL : ""
property selectOSDMG : ""
property selectedOSDMGTextField : ""
property netBootNameTextField : ""
property netBootImageIndexTextField : ""
property netBootImageIndexLabel : ""
property netBootDescription : ""
property applescriptsDelims : ""
property wordCount : ""
property startTag : ""
property endTag : ""
property hostMacOSVersionToDelim : ""
property hostMacOSVersionMajor : ""
property selectedOSdmgVersionToDelim : ""
property selectedOSdmgVersionMajor : ""
property netBootImageIndexMinValue : ""
property netBootImageIndexMaxValue : ""
property netBootImageIndex : ""
property ardUsername : ""
property ardPassword : ""
property vncPassword : ""
property userName : ""
property longUserName : ""
property netBootServeOptionSelected : ""
property netBootServeOver : ""
property customDesktopImagePath : ""
property customDesktopImageLabel : ""
property pathToResources : ""
property buildProcessTextField : ""
property tempUUID : ""
property netBootDmgMountPath : ""
property selectedAppPathToCopy : ""
property downloadedImagrCACert : ""
property variableVariable : ""
property buildDate : ""
property ardPasswordEncoded : ""
property ardUsernameEncoded : ""
property netBootCreatedPath : ""
property desktopImageExists : ""
property myLogFile : ""
property timeStamp : ""
property logMe : ""
property netBootSelectedLocation : ""
property logDate : ""
property buildProcessLogTextField : ""
property versionOfAutoImagrNBI : ""
property netBootDirectory : ""
property rootDirectory : ""
property adminUserName : ""
property adminUsersPassword : ""
property adminUserWindow : ""
property netBootDmgTotalSize : ""
property netBootDmgFreeSpace : ""
property netBootDmgUsedSpace : ""
property netBootReducedDmgMountPath : ""
property userNotifyWindow : ""
property userNotifyError : ""
property userNotifySuccess : ""
property inputLayoutID : ""
property languageCode : ""
property additionalPKGsArray : ""
property selectedPKGsPath : ""
property selectedObjects : ""
property selectedPKGsColour : ""
property additionalCertsArray : ""
property selectedCertsPath : ""
property selectedCertsColour : ""
property keyboardLayoutInputSourceID : ""
property letters : ""
property freeSpaceOnVolume : ""
property fullPath : ""
property volname : ""
property freeSpaceOnVolumeUnit : ""
property selectedVolume : ""
property copiedAppPath : ""
property selectedOSdmgFreeSpaceOnVolumeUnit : ""
property mountPlist : ""
property selectedOSdmgBytesTotal : ""
property latestNBImageInfo : ""
property latestImagrVersion : ""
property imagrBrowserDownloadURL : ""
property imagrTempDir : ""
property imagrMount : ""
property imagrMountPoint : ""
property validateplistMsg : ""
property httpReportingURL : ""
property syslogReportingURL : ""
--- Booleans
property selectedOSDMGTextFieldEnabled : false
property selectedOSDMGCheckPass : false
property exclamationRedOSDMG : false
property cogOSDMG : false
property cogOSDMGAnimate : true
property selectedAppCheckPass : false
property exclamationRedSelectedApp : false
property warningSelectedApp : false
property cogSelectedApp : false
property cogSelectedAppAnimate : true
property buildButtonDisabled : true
property optionsButtonDisabled : true
property disableOptionsAndBuild : true
property netBootImageIndexLoadBalanced : false
property optionWindowEnabled : true
property netBootImageReduceEnabled : false
property ardEnabled : false
property vncEnabled : false
property ardDetailsCheck : true
property vncPassCheck : true
property closeOptionsWindowButton : true
property netBootDescriptionEnabled : false
property mainWindowCog : false
property mainWindowCogAnimate : true
property buildProcessProgressBarIndeterminate : false
property buildProcessProgressBarAniminate : false
property netBootCreationSuccessful : false
property netBootServeOverNFS : false
property customDesktopImageEnabled : false
property installRCNetBootSelected : true
property timeServerOptionsEnabled : false
property createReadOnlyDMG : false
property userNotifyErrorHidden : true
property userNotifySuccessHidden : true
property optionsWindowPreCheckPassed : true
property buildButtonPreCheckPassed : true
property closeButtonPreCheckPassed : true
property simpleFinderEnabled : false
property servedFromNetSUS : true
property logNewLine : true
property isAdminUser : false
property pkgsMissing : false
property certsMissing : false
property buildPreCheckPassed : false
property adminUserWindowCog : false
property adminUserWindowCogAnimate : false
property disableAdminUserCheck : false
property firstLaunch : true
property netBootDescriptionSet : false
property imagrConfigURLCheckPass : false
property elCapNBImageInfoPlistExists : false
property useLatestNBImageInfo : false
property validateplistCog : false
property validateplistCogAnimate : true
property httpReportingEnabled : false
property syslogReportingEnabled : false
-- Others
property buildProcessProgressBarMax : 0
property buildProcessProgressBar : 0
property selectedOSdmgTotalSize : 0
property selectedOSdmgFreeSpace : 0
property selectedOSdmgUsedSpace : 0
property netBootDmgRequiredSize : 0
property netBootDmgResize : 0
property timeServerSelected : "time.apple.com"
property timeZoneSelected : "Americas/Los_Angeles"
property languageSelected : "English : en"
property inputLanguageSelected : "U.S."
property NSColor : class "NSColor" of current application
property pkgList : {}
property thePKGs : {}
property certList : {}
property theCerts : {}
property additionalCerts : {}
property additionalPKGs : {}
property NSData: current application's class "NSData"
property NSString: current application's class "NSString"
property NSMutableDictionary: current application's class "NSMutableDictionary"
property NSPropertyListSerialization: current application's class "NSPropertyListSerialization"
property NSUTF8StringEncoding: current application's NSUTF8StringEncoding
property NSPropertyListImmutable: current application's NSPropertyListImmutable
property None : missing value
property languagePopup : missing value
--- HANDLERS ---
-- To be run at launch
on startYourEngines_(sender)
-- Get AutoImagrNBI version
set versionOfAutoImagrNBI to get version of application "AutoImagrNBI"
-- Log AutoImagrNBI version
set logMe to "AutoImagrNBI " & versionOfAutoImagrNBI
logToFile_(me)
-- Get OS of host mac to verify that we can create an .nbi from supplied OS.dmg
set my hostMacOSVersion to (do shell script "/usr/bin/sw_vers -productVersion")
-- Variables to mess with, keeping the orignal with their decimals
set my hostMacOSVersionToDelim to hostMacOSVersion
-- Store delimiters for resetting later
set applescriptsDelims to AppleScript's text item delimiters
-- Set delimiters to decimal
set AppleScript's text item delimiters to "."
-- Set variables to the split versions
set hostMacOSVersionToDelim to hostMacOSVersionToDelim's text items
-- Set to major version of OS
set hostMacOSVersionMajor to text item 2 of hostMacOSVersionToDelim as integer
-- Reset delimiters
set AppleScript's text item delimiters to applescriptsDelims
-- Get host macs Build version for logging/debugging
set my hostMacOSBuildVersion to (do shell script "/usr/bin/sw_vers -buildVersion")
-- Log OS version & build of host mac
set logMe to "Running on OS " & hostMacOSVersion & " (" & hostMacOSBuildVersion & ")"
logToFile_(me)
-- Get username of user running AutoImagrNBI
set userName to short user name of (system info)
set logMe to "Launched by " & userName
logToFile_(me)
-- Get a UUID for folder path
set tempUUID to do shell script "/usr/bin/uuidgen"
set logMe to "UUID " & tempUUID
logToFile_(me)
-- Get path to resources folder
set pathToResources to (current application's class "NSBundle"'s mainBundle()'s resourcePath()) as string
end startYourEngines_
-- Register plist default settings
on regDefaults_(sender)
tell current application's NSUserDefaults to set defaults to standardUserDefaults()
tell defaults to registerDefaults_({ardEnabled:ardEnabled, ¬
ardUsername:ardUsername, ¬
ardPassword:ardPassword, ¬
customDesktopImageEnabled:customDesktopImageEnabled, ¬
customDesktopImagePath:customDesktopImagePath, ¬
imagrConfigURL:imagrConfigURL, ¬
netBootDescriptionEnabled:netBootDescriptionEnabled, ¬
servedFromNetSUS:servedFromNetSUS, ¬
netBootImageIndexLoadBalanced:netBootImageIndexLoadBalanced, ¬
netBootImageReduceEnabled:netBootImageReduceEnabled, ¬
netBootServeOverNFS:netBootServeOverNFS, ¬
vncEnabled:vncEnabled, ¬
vncPassword:vncPassword, ¬
timeServerSelected:timeServerSelected, ¬
timeZoneSelected:timeZoneSelected, ¬
languageSelected:languageSelected, ¬
inputLanguageSelected:inputLanguageSelected, ¬
installRCNetBootSelected:installRCNetBootSelected, ¬
createReadOnlyDMG:createReadOnlyDMG, ¬
simpleFinderEnabled:simpleFinderEnabled, ¬
additionalCerts:additionalCerts, ¬
additionalPKGs:additionalPKGs, ¬
httpReportingEnabled:httpReportingEnabled, ¬
httpReportingURL:httpReportingURL, ¬
syslogReportingEnabled:syslogReportingEnabled, ¬
syslogReportingURL:syslogReportingURL})
end regDefaults_
-- Get values from plist
on retrieveDefaults_(sender)
tell defaults to set my ardEnabled to objectForKey_("ardEnabled") as boolean
tell defaults to set my ardUsername to objectForKey_("ardUsername") as string
tell defaults to set my ardPassword to objectForKey_("ardPassword") as string
tell defaults to set my customDesktopImageEnabled to objectForKey_("customDesktopImageEnabled") as boolean
tell defaults to set my customDesktopImagePath to objectForKey_("customDesktopImagePath") as string
tell defaults to set my imagrConfigURL to objectForKey_("imagrConfigURL") as string
tell defaults to set my netBootDescriptionEnabled to objectForKey_("netBootDescriptionEnabled") as boolean
tell defaults to set my servedFromNetSUS to objectForKey_("servedFromNetSUS") as boolean
tell defaults to set my netBootImageIndexLoadBalanced to objectForKey_("netBootImageIndexLoadBalanced") as boolean
tell defaults to set my netBootImageReduceEnabled to objectForKey_("netBootImageReduceEnabled") as boolean
tell defaults to set my netBootServeOverNFS to objectForKey_("netBootServeOverNFS") as boolean
tell defaults to set my vncEnabled to objectForKey_("vncEnabled") as boolean
tell defaults to set my vncPassword to objectForKey_("vncPassword") as string
tell defaults to set my timeServerSelected to objectForKey_("timeServerSelected") as string
tell defaults to set my timeZoneSelected to objectForKey_("timeZoneSelected") as string
tell defaults to set my languageSelected to objectForKey_("languageSelected") as string
tell defaults to set my inputLanguageSelected to objectForKey_("inputLanguageSelected") as string
tell defaults to set my installRCNetBootSelected to objectForKey_("installRCNetBootSelected") as boolean
tell defaults to set my createReadOnlyDMG to objectForKey_("createReadOnlyDMG") as boolean
tell defaults to set my simpleFinderEnabled to objectForKey_("simpleFinderEnabled") as boolean
tell defaults to set my additionalCerts to objectForKey_("additionalCerts") as list
tell defaults to set my additionalPKGs to objectForKey_("additionalPKGs") as list
tell defaults to set my httpReportingEnabled to objectForKey_("httpReportingEnabled") as boolean
tell defaults to set my httpReportingURL to objectForKey_("httpReportingURL") as string
tell defaults to set my syslogReportingEnabled to objectForKey_("syslogReportingEnabled") as boolean
tell defaults to set my syslogReportingURL to objectForKey_("syslogReportingURL") as string
end retrieveDefaults_
----- BUTTON HANDLERS ----
-- Open Options window
on showOptionsWindow_(sender)
-- check the Imagr URL
checkimagrURL_(me)
-- reset value
set optionsWindowPreCheckPassed to true
-- Make sure a name is specified for the NetBoot Image, error if not.
netBootName_(me)
-- Error if incorrect value specified
netBootImageIndexCheck_(me)
-- Set to boolean
set optionsWindowPreCheckPassed to optionsWindowPreCheckPassed as boolean
-- If we ok to proceed
if optionsWindowPreCheckPassed is true and imagrConfigURLCheckPass is true then
-- Disable main windows buttons
set my optionWindowEnabled to false
-- reload options from plist
retrieveDefaults_(me)
-- Set NetBoot Description
enablenetBootDescription_(me)
-- Verify that the description field has a value & reset & prompt if not
netBootDescriptionCheck_(me)
-- Check that image selected for desktop exists
checkDesktopImage_(me)
-- Check additional pkgs array, & amend accordingly
checkAdditionalPKGs_(me)
-- Check additional Certs array, & amend accordingly
checkAdditionalCerts_(me)
-- activate options window
activate
optionsWindow's makeKeyAndOrderFront_(null)
end if
end showOptionsWindow_
-- Cancel & tidy up
on cancelBuildProcess_(sender)
--Log Action
set logMe to "Cancelling..."
logToFile_(me)
-- Enable main windows buttons
set my optionWindowEnabled to true
-- Detach mounted volumes
tidyUpTimeKids_(me)
end cancelBuildProcess_
----- TIDY ICONS ----
-- Reset OSDMG Icons, cog & further options
on doResetOSDMGIcons_(sender)
set my selectedOSDMGCheckPass to false
set my cogOSDMG to false
set my disableOptionsAndBuild to true
end doResetOSDMGIcons_
-- Reset SelectedApp Icons, cog & further options
on doResetSelectedAppIcons_(sender)
set my selectedAppCheckPass to false
set my cogSelectedApp to false
end doResetSelectedAppIcons_
-- Reset Main Window Text Field & Cog
on resetMainWindowLabel_(sender)
set my buildProcessTextField to missing value
set my mainWindowCog to false
end resetMainWindowLabel_
---- ADMIN CHECK PANEL ---
-- Check Administrative credentials
on adminCredentialPrompt_(sender)
-- check the Imagr URL
checkimagrURL_(me)
if imagrConfigURLCheckPass is true then
-- Main Window
set my disableOptionsAndBuild to true
-- activate main window
activate
adminUserWindow's makeKeyAndOrderFront_(null)
end if
end adminCredentialPrompt
-- Prompt for Administrative credentials
on dismissAdminCredentialPrompt_(sender)
-- reset Main Window's buttons
set my disableOptionsAndBuild to false
-- close build process window
adminUserWindow's orderOut_(null)
end dismissAdminCredentialPrompt
---- HELP MENU ----
-- Open the User Guide
on openUserGuide_(sender)
open location "https://macmule.com/projects/AutoImagrNBI"
end openUserGuide_
-- Open default browser to the below
on logAnIssue_(sender)
open location "https://github.com/macmule/AutoImagrNBI/issues"
end logAnIssue_
----- LAUNCHING -----
-- Insert code here to initialize your application before any files are opened
on applicationWillFinishLaunching_(aNotification)
-- Date for log file
set logDate to do shell script "/bin/date +%F"
-- Get OS of host mac & user running the app
startYourEngines_(me)
-- populate plist file with defaults (will not overwrite non-default settings))
regDefaults_(me)
-- retrieve plist values
retrieveDefaults_(me)
-- check for passwords, enable check boxes if found in plist
checkPasswords_(me)
-- Open the Main Window
openMainWindow_(me)
-- Set Image Index
netBootImageIndex_(me)
end applicationWillFinishLaunching_
-- Open the Main Window
on openMainWindow_(sender)
activate
mainWindow's makeKeyAndOrderFront_(null)
end openMainWindow_
----- LOGGING -----
-- Log to file
on logToFile_(sender)
-- Comment out before release.. this will send log messages to Xcode's log
--log logMe
-- Get time & date of command execution for log file
set timeStamp to do shell script "/bin/date"
-- Set to boolean of value
set logNewLine to logNewLine as boolean
-- If we're to create a newline ion the log
if logNewLine is true then
try
-- Create an empty new line for log if exists
do shell script "/bin/echo \"\" >> ~/Library/Logs/AutoImagrNBI/AutoImagrNBI-" & logDate & ".log"
end try
end if
-- Write message to log file
try
do shell script "/bin/echo " & timeStamp & space & quoted form of logMe & ">> ~/Library/Logs/AutoImagrNBI/AutoImagrNBI-" & logDate & ".log"
on error
-- Create directory if doesn't exist
do shell script "/bin/mkdir ~/Library/Logs/AutoImagrNBI/"
-- Write message to log file
do shell script "/bin/echo " & timeStamp & space & quoted form of logMe & ">> ~/Library/Logs/AutoImagrNBI/AutoImagrNBI-" & logDate & ".log"
end try
-- Set to false so we don't create a newline until next time the app is run
set logNewLine to false
end logToFile_
----- MAIN WINDOW----
-- Display a window for the user to select an DMG.
on selectedOSDMG_(sender)
try
-- Prompt user to chose OS.dmg
choose file of type {"public.disk-image"} with prompt "Select an OS.dmg:" default location (path to desktop folder)
-- Set selectedOSdmgPath to path of OS.dmg given
set selectedOSdmgPath to POSIX path of result
-- Log path of selected DMG
set logMe to "Path: " & selectedOSdmgPath
logToFile_(me)
-- Reset OSDMG Icons & hide cog
doResetOSDMGIcons_(me)
-- Do handler:
doOSDMG_(me)
end try
end selectedOSDMG_
-- Try & get OS version from dropped dmg, error if something is not quite right
on doOSDMG_(sender)
-- Log that we're tryin to mount selected DMG
set logMe to "Trying to mount: " & selectedOSdmgPath
logToFile_(me)
-- Update label to show we're doing stuff
set my selectedOSDMGTextField to "Examining..."
-- Display the cog to reinforce we're busy
set my cogOSDMG to true
-- Delay needed to update label
delay 0.1
-- Try & mount OS.dmg
-- Stolen from frogor on IRC with permission :)
-- Mount OS.dmh & get mount point
set mountOutputPlist to do shell script "/usr/bin/hdiutil attach " & quoted form of selectedOSdmgPath & " -nobrowse -owners on -plist"
-- convert the string into a NSString
set theString to NSString's stringWithString_(mountOutputPlist)
-- convert the NSString into NSData
set theData to theString's dataUsingEncoding_(NSUTF8StringEncoding)
-- Parse the NSData as a plist
set thePlist to NSPropertyListSerialization's propertyListFromData_mutabilityOption_format_errorDescription_(theData, NSPropertyListImmutable, None, None)
-- The returned plist is actually either a NSDictionary or NSArray, depending on the plist root object
-- In this case, the output of hdiutil is a dict with a single key we care about (which contains an array)
set theEntities to thePlist's objectForKey_("system-entities")
--log theEntities
-- There can be (and usually are) multiple entities. We're looking for the one that contains a "mount-point" key
-- Start with a default value of None
set selectedOSdmgMountPath to None
set selectedOSdmgKind to None
-- Loop through each entry, looking for the key's value
repeat with anItem in theEntities
set selectedOSdmgMountPath to anItem's objectForKey_("mount-point")
set selectedOSdmgKind to (anItem's objectForKey:"volume-kind")
-- If we have a value, then check.. if APFS a few new mount-points appear that we need to discard
if (selectedOSdmgMountPath is not equal to missing value) then
set selectedOSdmgMountPath to (NSString's stringWithString:selectedOSdmgMountPath) as string
if (selectedOSdmgMountPath as string does not start with "/Volumes/Preboot") and (selectedOSdmgMountPath as string is not equal to "/Volumes/Recovery") then
set selectedOSdmgMountPath to selectedOSdmgMountPath as text
exit repeat
end if
end if
-- Guess we didn't find one, let's check the next ...
end repeat
-- Set to text of variable
set selectedOSdmgMountPath to selectedOSdmgMountPath as text
-- If APFS source but not 10.13
if (hostMacOSVersionMajor is less than 13) and ((NSString's stringWithString:selectedOSdmgKind) as string) is equal to "apfs" then
--Log Action
set logMe to "APFS source, not a 10.13 host"
logToFile_(me)
-- Error advising we cannot mount the DMG
set my selectedOSDMGTextField to "Cannot Mount DMG"
display dialog selectedOSdmgPath & " is an APFS Volume, & therefore needs 10.13 to create an NBI from." with icon 0 buttons {"OK"}
-- Reset OSDMG Icons & hide cog
doResetOSDMGIcons_(me)
-- If we have an value for the OS DMG's mount-point, try & get OS version
else if selectedOSdmgMountPath is not equal to None then
set logMe to "Mounted to: " & selectedOSdmgMountPath
logToFile_(me)
-- Try & read /System/Library/CoreServices/SystemVersion.plist
try
-- Try & get OS version
set selectedOSdmgVersion to do shell script "/usr/bin/defaults read " & quoted form of selectedOSdmgMountPath & "/System/Library/CoreServices/SystemVersion.plist ProductVersion"
-- Try & get build version
set my selectedOSBuilddmgVersion to do shell script "/usr/bin/defaults read " & quoted form of selectedOSdmgMountPath & "/System/Library/CoreServices/SystemVersion.plist ProductBuildVersion"
-- Variables to mess with, keeping the orignal with their decimals
set my selectedOSdmgVersionToDelim to selectedOSdmgVersion
-- Store delimiters for resetting later
set applescriptsDelims to AppleScript's text item delimiters
-- Set delimiters to decimal
set AppleScript's text item delimiters to "."
-- Set variables to the split versions of Imagr & Imagr versions
set selectedOSdmgVersionToDelim to selectedOSdmgVersionToDelim's text items
-- Set to major version of Imagr
set selectedOSdmgVersionMajor to text item 2 of selectedOSdmgVersionToDelim as integer
-- Reset delimiters
set AppleScript's text item delimiters to applescriptsDelims
-- Reset OSDMG Icons
doResetOSDMGIcons_(me)
-- Make sure we're building a 10.10+ NBI
if selectedOSdmgVersionMajor is not greater than 10 then
--Log Action
set logMe to "Error: Select a 10.10+ DMG"
logToFile_(me)
-- Update label to show we're doing stuff
set my selectedOSDMGTextField to "Select a 10.10+ DMG"
-- Hide the cog
set my cogOSDMG to false
-- Delay needed to update label
delay 0.1
-- Set build Process ProgressBar to indeterminate & animated
set my buildProcessProgressBarIndeterminate to true
set my buildProcessProgressBarAniminate to true
delay 0.1
-- activate build process window
activate
showBuildProcessWindow's makeKeyAndOrderFront_(null)
-- Update Build Process Window's Text Field
set my buildProcessTextField to "Error: Select a 10.10+ DMG, detaching mounted volume"
delay 0.1
--Log Action
set logMe to "Error: Select a 10.10+ DMG, detaching mounted volume"
logToFile_(me)
-- Detach Volume
do shell script "/usr/bin/hdiutil detach " & quoted form of selectedOSdmgMountPath & " -force"
--Log Action
set logMe to "Unmounted " & quoted form of selectedOSdmgMountPath
logToFile_(me)
-- Close Build Process Window
showBuildProcessWindow's orderOut_(null)
else
-- If we have both OS & build versions, display them
set my selectedOSDMGTextField to "Mac OS " & selectedOSdmgVersion & " (" & selectedOSBuilddmgVersion & ")"
-- Display green check icon
set my selectedOSDMGCheckPass to true
-- Set netBoot Name
set my netBootNameTextField to selectedOSdmgVersion & " AutoImagrNBI"
-- See if pre-reqs have been met
checkIfReadyToProceed_(me)
end if
on error
--Log Action
set logMe to "Cannot read OS Version"
logToFile_(me)
-- Error advising we cannot get the OS version from dmg
set my selectedOSDMGTextField to "Cannot read OS Version"
end try
else
--Log Action
set logMe to "Cannot Mount DMG"
logToFile_(me)
-- Error advising we cannot mount the DMG
set my selectedOSDMGTextField to "Cannot Mount DMG"
end if
end doOSDMG_
-- Display a window for the user to Select Imagr.app.
on selectedApp_(sender)
-- Create a window prompting user to select an app
try
choose file of type {"com.apple.application-bundle"} with prompt "Select Imagr.app:" default location (path to applications folder)
-- Get path of the selected app.
set my selectedAppPath to POSIX path of result
-- Log path of the selected app
set logMe to "Selected App Path: " & selectedAppPath
logToFile_(me)
-- Reset Selected App Icons & cog
doResetSelectedAppIcons_(me)
-- Run handler
selectedAppCheck_(me)
end try
end selectedApp_
-- Check selected app is Imagr & return version
on selectedAppCheck_(sender)
-- Set label to Imagr version
set my selectedAppTextField to "Examining..."
-- Display the cog to reinforce we're busy
set my cogSelectedApp to true
-- Delay needed to update label
delay 0.1
-- Get Bundle Name of selected app
set selectedAppBundleName to do shell script "/usr/bin/defaults read " & quoted form of selectedAppPath & "/Contents/Info.plist CFBundleName"
--Log Action
set logMe to "Bundle Name: " & selectedAppBundleName
logToFile_(me)
-- If Bundle Name is Imagr, proceed to get version
if selectedAppBundleName is equal to "Imagr" then
try
-- If Imagr, return version
set selectedImagrAppVersion to do shell script "/usr/bin/defaults read " & quoted form of selectedAppPath & "/Contents/Info.plist CFBundleShortVersionString"
--Log Action
set logMe to "Imagr Version: " & selectedImagrAppVersion
logToFile_(me)
-- Set label to Imagr version
set my selectedAppTextField to "Imagr " & selectedImagrAppVersion
delay 0.1
-- Reset Selected App Icons
doResetSelectedAppIcons_(me)
-- Display green tick
set my selectedAppCheckPass to true
-- Check latest Imagr version against selected app
checkImagrVersion_(me)
-- Error if cannot get the version number
on error
-- Reset Selected App Icons
doResetSelectedAppIcons_(me)
-- Display Error if cannot get version number
set my selectedAppTextField to "Cannot Get Version"
-- Disable options and build
set my disableOptionsAndBuild to true
end try
-- If selected app is not Imagr.
else
--Log Action
set logMe to "Select Imagr.app"
logToFile_(me)
-- Reset Selected App Icons
doResetSelectedAppIcons_(me)
-- Display message that we have selected Imagr
set my selectedAppTextField to "Select Imagr.app"
-- Disable options and build
set my disableOptionsAndBuild to true
end if
-- See if pre-reqs have been met
checkIfReadyToProceed_(me)
end selectedAppCheck_
-- Check latest Imagr version against selected app
on checkImagrVersion_(sender)
try
-- Get the latest version number of Imagr
set latestImagrVersion to do shell script "/usr/bin/curl -s https://api.github.com/repos/grahamgilbert/imagr/releases | awk '/tag_name/{ gsub(\"\\\"\",\"\"); gsub(\",\",\"\"); print $2; exit }'"
--Log Action
set logMe to "Latest Imagr version: " & latestImagrVersion
logToFile_(me)
-- Check versions
if selectedImagrAppVersion is less than latestImagrVersion then
-- Prompt user
display dialog "Selected version of Imagr (" & selectedImagrAppVersion & ") is older than the latest release of Imagr (" & latestImagrVersion & ")." & return & return & "Would you like to download the newest version & add to this NBI?" with icon caution buttons {"Release Info","No", "Yes"} default button "Yes"
-- If user selected yes
if button returned of the result is "Yes" then
-- Download the latest version of Imagr
downloadLatestImagr_(me)
else if button returned of the result is "Release Info" then
-- Open a web browser to the latest releases page
open location "https://github.com/grahamgilbert/imagr/releases/latest"
end if
else
-- See if pre-reqs have been met
checkIfReadyToProceed_(me)
end if
on error
-- See if pre-reqs have been met
checkIfReadyToProceed_(me)
end try
end checkImagrVersion_
-- Download the latest version of Imagr
on downloadLatestImagr_(sender)
try
-- Update buildProcessLogTextField to show path to todays log
set my buildProcessLogTextField to "Today's Log: ~/Library/Logs/AutoImagrNBI/AutoImagrNBI-" & logDate & ".log"
-- Set build Process ProgressBar to indeterminate & animated to false
set my buildProcessProgressBarIndeterminate to true
set my buildProcessProgressBarAniminate to true
-- close admin check window
adminUserWindow's orderOut_(null)
-- activate build process window
activate
showBuildProcessWindow's makeKeyAndOrderFront_(null)
-- Update Build Process Window's Text Field
set my buildProcessTextField to "Getting latest version number of Imagr"
delay 0.1
-- Get the latest version number of Imagr
set latestImagrVersion to do shell script "/usr/bin/curl -s https://api.github.com/repos/grahamgilbert/imagr/releases | awk '/tag_name/{ gsub(\"\\\"\",\"\"); gsub(\",\",\"\"); print $2; exit }'"
--Log Action
set logMe to "Latest Imagr version: " & latestImagrVersion
logToFile_(me)
-- Update Build Process Window's Text Field
set my buildProcessTextField to "Getting the download URL for latest Imagr"
delay 0.1
-- Get the download URL for the latest version of Imagr
set imagrBrowserDownloadURL to do shell script "/usr/bin/curl -s https://api.github.com/repos/grahamgilbert/imagr/releases | awk '/browser_download_url/{ gsub(\"\\\"\",\"\"); print $2; exit }'"
--Log Action
set logMe to "Imagr download URL is: " & imagrBrowserDownloadURL
logToFile_(me)
-- Update Build Process Window's Text Field
set my buildProcessTextField to "Creating a temp directory"
delay 0.1
-- Create a temp directory
set imagrTempDir to do shell script "/usr/bin/mktemp -dt \"$0\""
--Log Action
set logMe to "Temp directory created at: " & imagrTempDir
logToFile_(me)
--Log Action
set logMe to "Downloading Imagr.dmg to " & imagrTempDir
logToFile_(me)
-- Update Build Process Window's Text Field
set my buildProcessTextField to "Downloading latest Imagr.dmg"
delay 0.1
-- Download latest version of Imagr
do shell script "/usr/bin/curl -sL -o " & imagrTempDir & "/Imagr.dmg --connect-timeout 30 -f " & imagrBrowserDownloadURL
-- Update Build Process Window's Text Field
set my buildProcessTextField to "Mounting Imagr.dmg"
delay 0.1
-- Mount the Imagr.dmg
set imagrMount to do shell script "/usr/bin/hdiutil attach " & imagrTempDir & "/Imagr.dmg -nobrowse -owners on -plist | awk -F: '/mount-point/ && $0 != \"\" { getline; print $0; exit}'"
-- Get the Imagr.dmg's mountpoint, stipping out the <string> </string>
set AppleScript's text item delimiters to "<string>"
set imagrMountPoint to imagrMount's second text item
set AppleScript's text item delimiters to "</string>"
set imagrMountPoint to imagrMountPoint's first text item
-- Reset Delimters
set AppleScript's text item delimiters to {""}
--Log Action
set logMe to "Imagr.dmg mounted to: " & imagrMountPoint
logToFile_(me)
-- Get path of the downloaded.
set my selectedAppPath to POSIX path of imagrMountPoint & "/Imagr.app/"
-- Update Build Process Window's Text Field
set my buildProcessTextField to "Imagr.dmg mounted"
delay 0.1
-- Close build window
showBuildProcessWindow's orderOut:(null)
-- Run handler
selectedAppCheck_(me)
on error
--Log Action
set logMe to "Error: Downloading latest version of Imagr"
logToFile_(me)
-- Set to false to display
set my userNotifyErrorHidden to false
-- Set Error message
set my userNotifyError to "Error: Downloading latest version of Imagr"
-- stop cog
set my adminUserWindowCog to false
set my adminUserWindowCogAnimate to false
-- Notify of errors or success
userNotify_(me)
end try
end downloadLatestImagr_
-- Check the Imagr URL details
on checkImagrURL_(sender)
-- Error if a local url is passed
if (my imagrConfigURL as string starts with "/") or (my imagrConfigURL as string starts with "file:")
-- Set to false
set imagrConfigURLCheckPass to false
-- Empty variable
set imagrConfigURL to "" as string
-- display message to the user
display dialog "Local plists need to be validated outside of AutoImagrNBI & added to the NBI as a pkg" with icon 0 buttons {"OK"}
-- If imagrConfigURL has a value
else if (my imagrConfigURL as string is not equal to "") and (my imagrConfigURL as string is not equal to missing value) then
-- Update plist
tell defaults to setObject_forKey_(imagrConfigURL, "imagrConfigURL")
-- Set to true so we can continue
set imagrConfigURLCheckPass to true
-- Check config plist
checkConfigPlist_(me)
else
-- Set to true so we can continue
set imagrConfigURLCheckPass to true
-- See if pre-reqs have been met
checkIfReadyToProceed_(me)
end if
end checkImagrURL_
-- Check config plist
on checkConfigPlist_(sender)
try
-- Set label to Imagr version
set my validateplistMsg to "Validating plist..."
-- Display the cog to reinforce we're busy
set my validateplistCog to true
-- Delay needed to update label
delay 0.1
-- Run validateplist again imagrConfigURL
set validateplistOutput to do shell script "python " & quoted form of pathToResources & "/validateplist " & imagrConfigURL
-- Get words from output
set wordCount to (count words of validateplistOutput)
-- Store delimiters for resetting later
set applescriptsDelims to AppleScript's text item delimiters
-- Set delimiters to forwardslash
set AppleScript's text item delimiters to "WARNING"
-- Count any warnings we get
set warningCount to (count text items of validateplistOutput) - 1
-- Reset delimiters
set AppleScript's text item delimiters to applescriptsDelims
-- If we have any warnings
if warningCount is greater than 0 then
-- Show how many warnings
set my validateplistMsg to "WARNING: plist validated with " & warningCount & " warnings."
--Log Action
set logMe to validateplistMsg
logToFile_(me)
-- Hide the cog
set my validateplistCog to false
-- Display alert
display alert "Validateplist Output" message "config plist validated with " & warningCount & " warnings." as warning
else
-- if we suceeded
set my validateplistMsg to last paragraph of validateplistOutput
--Log Action
set logMe to validateplistMsg
logToFile_(me)
-- Hide the cog
set my validateplistCog to false
end if
-- See if pre-reqs have been met
checkIfReadyToProceed_(me)
on error errStr
-- If we got an error
set my validateplistMsg to errStr
--Log Action
set logMe to validateplistMsg
logToFile_(me)
-- Hide the cog
set my validateplistCog to false
-- Display alert
display alert "Validateplist Output" message "config plist validation errored with:\n" & errStr as critical
end try
end checkConfigPlist_
-- Make sure OS & Imaging.app is specified before proceeding, once checked enable Imagr options, as well as Build & Option buttons
on checkIfReadyToProceed_(sender)
-- Check to see if we have ticks or minor warning before we proceed
if selectedAppCheckPass and selectedOSDMGCheckPass is equal to true then
-- Enable Options & Build
set my disableOptionsAndBuild to false
--Log Action
set logMe to "Pre-Reqs met, Options & Build enabled."
logToFile_(me)
-- Get the NetBoot Serve option
netBootServeOption_(me)
-- Correct NetBoot Name, removing spaces if to be hosted on a NetSUS
servedFromNetSUS_(me)
-- Set Image Index
netBootImageIndex_(me)
end if
end checkIfReadyToProceed_
-- Make sure a name is specified for the NetBoot Image, error if not.
on netBootName_(sender)
-- If textfield is empty
if netBootNameTextField is missing value then
-- Set netBoot Name
set my netBootNameTextField to selectedOSdmgVersion & " AutoImagrNBI"
-- Correct NetBoot Name, removing spaces if to be hosted on a NetSUS
servedFromNetSUS_(me)
-- Display error to user
display dialog "Please select a Name for the NetBoot Image" with icon 0 buttons {"OK"}
--Log Action
set logMe to "Error: Name required for NetBoot Image"
logToFile_(me)
-- Set to false so we don't proceed showing options window
set optionsWindowPreCheckPassed to false
-- Set to false so we don't proceed with build
set buildButtonPreCheckPassed to false
else
-- Correct NetBoot Name, removing spaces if to be hosted on a NetSUS
servedFromNetSUS_(me)
end if
end netBootName_
-- Correct NetBoot Name, removing spaces if to be hosted on a NetSUS
on servedFromNetSUS_(sender)
-- Set servedFromNetSUS to boolean of value
set servedFromNetSUS to servedFromNetSUS as boolean
-- If true, remove spaces from NetBoot Name
if servedFromNetSUS is true then
-- Set netBootNameTextField to text of value
set my netBootNameTextField to netBootNameTextField as text
-- Remove spaces from NetBoot Name
set my netBootNameTextField to words of netBootNameTextField as string
--Log Action
set logMe to "NetBoot Name: " & netBootNameTextField
logToFile_(me)
else
--Log Action
set logMe to "NetBoot Name: " & netBootNameTextField
logToFile_(me)
end if
-- Update plist with selection
tell defaults to setObject_forKey_(servedFromNetSUS, "servedFromNetSUS")
end servedFromNetSUS
-- Bound to "Will be served from more than one server"
on netBootImageIndex_(sender)
-- Set netBootImageIndexLoadBalanced to boolean of value
set netBootImageIndexLoadBalanced to netBootImageIndexLoadBalanced as boolean
-- Set options depending on checkbox
if netBootImageIndexLoadBalanced is true then
--Log Action
set logMe to "NetBoot is to be hosted on multiple servers."
logToFile_(me)
-- Set min & max values for Index
set my netBootImageIndexMinValue to 4096 as integer
set my netBootImageIndexMaxValue to 65535 as integer
else
--Log Action
set logMe to "NetBoot is to be hosted on a single server."
logToFile_(me)
-- Set min & max values for Index
set my netBootImageIndexMinValue to 1 as integer
set my netBootImageIndexMaxValue to 4095 as integer
end if
-- Update plist with selection
tell defaults to setObject_forKey_(netBootImageIndexLoadBalanced, "netBootImageIndexLoadBalanced")
-- Update lable to show index value based on hosting option
set my netBootImageIndexLabel to "(" & netBootImageIndexMinValue & " - " & netBootImageIndexMaxValue & ")"
-- Update text field to show the random number
set my netBootImageIndexTextField to current application's (random number from (netBootImageIndexMinValue) to (netBootImageIndexMaxValue))
end netBootImageIndex_
-- Error if incorrect value specified
on netBootImageIndexCheck_(sender)
-- If we have a value
if netBootImageIndexTextField is not equal to missing value
-- Set to integer of value
set netBootImageIndexTextField to netBootImageIndexTextField as integer
end if
-- If integer value is outside of allowed range
if (netBootImageIndexTextField less than netBootImageIndexMinValue) or (netBootImageIndexTextField greater than netBootImageIndexMaxValue) or (netBootImageIndexTextField is equal to missing value) then
-- Display error to user
display dialog "Please select an Index between " & netBootImageIndexMinValue & " & " & netBootImageIndexMaxValue with icon 0 buttons {"OK"}
-- Reset using below function.
netBootImageIndex_(me)
-- Set to false so we proceed showing options window
set optionsWindowPreCheckPassed to false
-- Set to false so we don't proceed with build
set buildButtonPreCheckPassed to false
end if
end netBootImageIndexCheck_
-- Bound to NetBoot Serve over HTTP radio button
on netbootServeOverHTTPSelected_(sender)
-- Set NetBoot Serve Over NFS to false