-
Notifications
You must be signed in to change notification settings - Fork 1
/
instadmg.bash
executable file
·1372 lines (1101 loc) · 52.8 KB
/
instadmg.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
#
# instadmg - script to automate creating ASR disk images
#
#
# Maintained by the InstaDMG dev team @ http://code.google.com/p/instadmg/
# Latest news, releases, and user forums @ http://www.afp548.com
#
SVN_REVISION=459 # killing svn-based revision expansion as of 17 May 2012. formerly: `/bin/echo '$Revision$' | /usr/bin/awk '{ print $2 }'`
VERSION="1.6rc1 (svn revision: $SVN_REVISION)"
PROGRAM=$( (basename $0) )
#<!------------------- Setup Environment ------------------->
IFS=$'\n'
# remove aliases that might be problematic
unset -f unalias
unalias -a
unset -f command
# prevent uninitialized variables from being used
set -o nounset
# set path to a known path
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
export PATH
# Change the working directory to the one containing the instadmg.bash script
cd "`/usr/bin/dirname "$0"`"
# Environment variables used by the installer command
export COMMAND_LINE_INSTALL=1
export CM_BUILD=CM_BUILD
#<!------------------- Variable Defaults ------------------->
# Set the creation date in a variable so it's consistant during execution.
CREATE_DATE=`/bin/date +%y-%m-%d`
# Default values
DMG_SIZE=300g # Size of the sparse image, this should be large enough
DMG_FS=HFS+J # Sparse filesystem created, which affects recovery partition
ISO_CODE="en" # ISO code that installer will use for the install language
DISABLE_CHROOT=false # Use a chroot jail while installing updates
DISABLE_INSTALLD_CHROOT=false # replace roots installd daemon with a chrooted version
DISABLE_BASE_IMAGE_CACHING=false # setting this to true turns off caching
ENABLE_TESTING_VOLUME=false # setting this and the TESTING_TARGET_VOLUME will erase that volume and write the image onto it
ENABLE_NON_PARANOID_MODE=false # disable checking image checksums
# Default folders
INSTALLER_FOLDERS=(`AddOns/InstaUp2Date/Resources/pathHelpers.py --normalize-path --follow-symlinks --supress-return "./InstallerFiles/BaseOS"`) # Images of install DVDs
UPDATE_FOLDER="./InstallerFiles/BaseUpdates" # Combo update first, followed by additional numbered folders
CUSTOM_FOLDER="./InstallerFiles/CustomPKG" # All other update pkg's
UPDATE_FOLDERS=() # Array of the folders to pull updates from in the order they should be installed
ASR_FOLDER="./OutputFiles" # Destination of the ASR images
BASE_IMAGE_CACHE="./Caches/BaseImageCache" # Cached images named by checksums
LOG_FOLDER="./Logs"
TEMPORARY_FOLDER="/private/tmp" # DMGs will be mounted at a location inside of this folder
TESTING_TARGET_VOLUME='' # setting this and the ENABLE_TESTING_VOLUME will erase that volume and write the image onto it
TESTING_TARGET_VOLUME_DEV='' # the mount point to be used when restoring, should look like /dev/disk0s4
# TODO: make sure that the cached images are not indexed
# Default Names
DMG_BASE_NAME=`/usr/bin/uuidgen` # Name of the intermediary image
MOUNT_FOLDER_TEMPLATE="idmg.XXXX"
MOUNT_POINT_TEMPLATE="idmg_mp.XXXX"
SOURCE_FOLDER_TEMPLATE="idmg_pkg.XXXX"
ASR_OUPUT_FILE_NAME="${CREATE_DATE}.dmg" # Name of the final image file
ASR_FILESYSTEM_NAME="InstaDMG" # Name of the filesystem in the final image
# Names allowed for the primary installer disk
ALLOWED_INSTALLER_DISK_NAMES=("Mac OS X Install Disc 1.dmg" "Mac OS X Install DVD.dmg" "InstallESD.dmg")
# Bundle identifier codes to exclude from the chroot system
CHROOT_EXCLUDED_CODES=("edu.uc.daap.createuser.pkg")
#<!-------------------- Working Variables ------------------>
HOST_MOUNT_FOLDER='' # Enclosing folder for the base image mount point, and others if not using chroot
TARGET_TEMP_FOLDER='' # If using chroot packages will be copied into temp folders in here before install
TARGET_IMAGE_MOUNT='' # Where the target is mounted
TARGET_IMAGE_FILE='' # Location of the base image dmg if using cached images, the whole image dmg otherwise
TARGET_IMAGE_CHECKSUM='' # Checksum reported by diskutil for the OS Install disk image
SHADOW_FILE_LOCATION='' # Location of the shadow file that is grafted onto the TARGET_IMAGE_MOUNT
OS_INSTALL_FILE='' # Location of the primary installer disk
OS_INSTALL_MOUNT='' # Mounted location of the primary installer disk
OS_INSTALL_AUTOMOUNTED=false
OS_INSTALL_CHOICES_FILE='' # Location of installer choices file for the BaseOS
PACKAGE_DMG_MOUNT='' # mount point for dmg packages (only while in use)
PACKAGE_DMG_FILE='' # path to the dmg file of dmg packages (only while in use)
OS_REV_MAJOR=''
OS_REV_MINOR=''
CPU_TYPE=''
TARGET_OS_REV=''
TARGET_OS_REV_MAJOR=''
TARGET_OS_REV_BUILD=''
TARGET_OS_NAME=''
INSTALLER_DISK='' # User-supplied path to a specific installer disk
SUPPORTING_DISKS=() # Array of user-supplied supporting disks to mount
MOUNTED_DMG_MOUNT_POINTS=()
MODIFIED_INSTALLD_PLIST_FOLDER=''
MODIFIED_INSTALLD_PLISTS=()
LATEST_IMAGE_MOUNT='' # back-channel to let the mount_dmg command communicate back auto-mounts
#<!----------------------- Logging ------------------------->
# Logging levels
# Error: always logged to everything
# Section: CONSOLE level 1 and higher, PACKAGE level 1 and higher
# Warning: CONSOLE level 2 and higher, PACKAGE level 1 and higher
# Information: CONSOLE level 2 and higher, PACKAGE level 2 and higher
# Detail: CONSOLE level 3 and higher, PACKAGE level 3 and higher
# Detail 2: CONSOLE level 4 and higher, PACKAGE leval 4 and higher
CONSOLE_LOG_LEVEL=2
PACKAGE_LOG_LEVEL=2
# Log a message - takes up to two arguments
# The first argument is the message to send. If blank log prints the date to the standard places for the selected log level
# The second argument tells the type of message. The default is information. The options are:
# section - header announcing that a new section is being started
# warning - non-fatal warning
# error - non-recoverable error
# information - general information
# detail - verbose detail
# everything will always be logged to the full log
# depending on the second argument and the logging levels for CONSOLE_LOG_LEVEL and PACKAGE_LOG_LEVEL the following will be logged
# Detail 2 is lines that begin with "installer:" that don't match a couple of other criteria
# commands should all have the following appended to them:
# | (while read INPUT; do log "$INPUT " information; done)
ERROR_LOG_FORMAT="ERROR: %s\n"
SECTION_LOG_FORMAT="###### %s ######\n"
WARNING_LOG_FORMAT="WARNING: %s\n"
SUBPACKAGE_LOG_FORMAT=" %s\n"
INFORMATION_LOG_FORMAT=" %s\n"
DETAIL_LOG_FORMAT=" %s\n"
log() {
if [ -z "$1" ] || [ "$1" == "" ] || [ "$1" == "#" ]; then
# there is nothing to log
return
else
MESSAGE=`/bin/echo "$1" | /usr/bin/awk '{gsub("installer(\[[[:digit:]]+\])*\:", ""); print $0}'`
fi
if [ -z "$2" ]; then
LEVEL="information"
else
LEVEL="$2"
fi
if [ "$LEVEL" == "error-nolog" ]; then
/usr/bin/printf "$SECTION_LOG_FORMAT" "$MESSAGE" 1>&2
fi
if [ "$LEVEL" == "error" ]; then
/usr/bin/printf "$SECTION_LOG_FORMAT" "$MESSAGE" | /usr/bin/tee -a "$LOG_FILE" "$PKG_LOG" 1>&2
fi
if [ "$LEVEL" == "section" ]; then
TIMESTAMP=`date "+%H:%M:%S"`
/usr/bin/printf "$TIMESTAMP $SECTION_LOG_FORMAT" "$MESSAGE" >> "$LOG_FILE"
if [ $CONSOLE_LOG_LEVEL -ge 1 ]; then
/usr/bin/printf "$TIMESTAMP $SECTION_LOG_FORMAT" "$MESSAGE"
fi
if [ $PACKAGE_LOG_LEVEL -ge 1 ]; then
/usr/bin/printf "$TIMESTAMP $SECTION_LOG_FORMAT" "$MESSAGE" >> "$PKG_LOG"
fi
fi
if [ "$LEVEL" == "warning" ]; then
/usr/bin/printf "$WARNING_LOG_FORMAT" "$MESSAGE" >> "$LOG_FILE"
if [ $CONSOLE_LOG_LEVEL -ge 2 ]; then
/usr/bin/printf "$WARNING_LOG_FORMAT" "$MESSAGE"
fi
if [ $PACKAGE_LOG_LEVEL -ge 1 ]; then
/usr/bin/printf "$WARNING_LOG_FORMAT" "$MESSAGE" >> "$PKG_LOG"
fi
fi
if [ "$LEVEL" == "information" ]; then
/usr/bin/printf "$INFORMATION_LOG_FORMAT" "$MESSAGE" >> "$LOG_FILE"
if [ $CONSOLE_LOG_LEVEL -ge 2 ]; then
/usr/bin/printf "$INFORMATION_LOG_FORMAT" "$MESSAGE"
fi
if [ $PACKAGE_LOG_LEVEL -ge 2 ]; then
/usr/bin/printf "$INFORMATION_LOG_FORMAT" "$MESSAGE" >> "$PKG_LOG"
fi
fi
if [ "$LEVEL" == "detail" ]; then
/usr/bin/printf "$DETAIL_LOG_FORMAT" "$MESSAGE" >> "$LOG_FILE"
# here we are going to split the "detail" and "detail 2" groups
# the different packages will also cause "informational" messages
if [[ $MESSAGE == *installer:\ Installing* ]]; then
FILTERED_MESSAGE=`/bin/echo "$MESSAGE" | /usr/bin/awk 'sub("installer: ", "")'`
if [[ $MESSAGE == *base\ path* ]]; then
if [ $CONSOLE_LOG_LEVEL -ge 3 ]; then
/usr/bin/printf "$SUBPACKAGE_LOG_FORMAT" "$FILTERED_MESSAGE"
fi
if [ $PACKAGE_LOG_LEVEL -ge 3 ]; then
/usr/bin/printf "$SUBPACKAGE_LOG_FORMAT" "$FILTERED_MESSAGE" >> "$PKG_LOG"
fi
else
if [ $CONSOLE_LOG_LEVEL -ge 2 ]; then
/usr/bin/printf "$SUBPACKAGE_LOG_FORMAT" "$FILTERED_MESSAGE"
fi
if [ $PACKAGE_LOG_LEVEL -ge 2 ]; then
/usr/bin/printf "$SUBPACKAGE_LOG_FORMAT" "$FILTERED_MESSAGE" >> "$PKG_LOG"
fi
fi
elif [[ $MESSAGE == installer:* ]]; then
FILTERED_MESSAGE=`/bin/echo "$MESSAGE" | /usr/bin/awk 'sub("installer: ", "")'`
if [ $CONSOLE_LOG_LEVEL -ge 4 ]; then
/usr/bin/printf "$DETAIL_LOG_FORMAT" "$FILTERED_MESSAGE"
fi
if [ $PACKAGE_LOG_LEVEL -ge 4 ]; then
/usr/bin/printf "$DETAIL_LOG_FORMAT" "$FILTERED_MESSAGE" >> "$PKG_LOG"
fi
else
if [ $CONSOLE_LOG_LEVEL -ge 3 ]; then
/usr/bin/printf "$DETAIL_LOG_FORMAT" "$MESSAGE"
fi
if [ $PACKAGE_LOG_LEVEL -ge 3 ]; then
/usr/bin/printf "$DETAIL_LOG_FORMAT" "$MESSAGE" >> "$PKG_LOG"
fi
fi
fi
}
#<!----------------------- Functions ----------------------->
bail() {
#If we get here theres a problem, print the usage message and then exit with a non-zero status
usage $1
}
version() {
# Show the version number
/bin/echo "$PROGRAM version $VERSION"
exit 0
}
usage() {
# Usage format
cat <<EOF
Usage: $PROGRAM [options]
Note: This program must be run as root (sudo is acceptable)
Options:
-b <folder path> Look for the base image in this folder (${INSTALLER_FOLDERS[@]})
-c <folder path> Look for custom pkgs in this folder ($CUSTOM_FOLDER)
-f Enable non-paranoid mode (skip checking image checksumms)
-h Print the useage information (this) and exit
-i <iso code> Use <iso code> for the installer language ($ISO_CODE)
-l <folder path> Set the folder to use as the log folder ($LOG_FOLDER)
-m <name> The file name to use for the ouput file. '.dmg' will be appended as needed. ($ASR_OUPUT_FILE_NAME)
-n <name> The volume name to use for the output file. ($ASR_FILESYSTEM_NAME)
-o <folder path> Set the folder to use as the output folder ($ASR_FOLDER)
-q Quiet: print only errors to the console
-r Disable using chroot for package installs ($DISABLE_CHROOT)
-s Do not replace the installd daemon with a chrooted version ($DISABLE_INSTALLD_CHROOT)
-t <folder path> Create a scratch space in this folder ($TEMPORARY_FOLDER)
-u <folder path> Use folder as the BaseUpdates folder ($UPDATE_FOLDER)
-v Print the version number and exit
-w <folder path> Disk to erase and restore the new image to for testing
-y Enable erase-and-restore of new image to testing volume
-z Disable caching of the base image ($DISABLE_BASE_IMAGE_CACHING)
-I <dmg path> Use dmg at this path as the installer disk.
-J <dmg path> Mount dmg at this path during installs.
-K <folder path> Use folder as a source for updates, call multiple time in order for multiple folders.
-L <file path> Use file as installerChoices file for base install
EOF
if [ -z $1 ]; then
exit 1;
else
exit $1
fi
}
mount_dmg() {
# input
# $1 - path to file (mandatory)
# $2 - mount point (optional)
# $3 - mount name (optional)
LATEST_IMAGE_MOUNT=''
if [ -z "$1" ]; then
log "Internal error: mount_dmg called without a source file" error
exit 1
fi
if [ ! -f "$1" ]; then
log "Internal error: mount_dmg called with invalid source file: $1" error]
exit 1
fi
if [ -z "$2" ]; then
IMAGE_MOUNT_OUTPUT=`AddOns/InstaUp2Date/Resources/dmgMountHelper.py "$1" --mount-read-only --supress-return --parent-folder "$HOST_MOUNT_FOLDER" 2>&1`
else
IMAGE_MOUNT_OUTPUT=`AddOns/InstaUp2Date/Resources/dmgMountHelper.py "$1" --mount-read-only --supress-return --mount-point "$2" 2>&1`
fi
if [ $? -ne 0 ]; then
log "Unable to mount $2: $IMAGE_MOUNT_OUTPUT" error
exit 1
fi
LATEST_IMAGE_MOUNT="$IMAGE_MOUNT_OUTPUT"
# Log the mount
if [ -z "$3" ]; then
log "Mounted disk image from $1 at $IMAGE_MOUNT_OUTPUT" detail
else
log "Mounted $3 ($1) at $IMAGE_MOUNT_OUTPUT" detail
fi
# Add the disk to the list of mount points
MOUNTED_DMG_MOUNT_POINTS[${#MOUNTED_DMG_MOUNT_POINTS[@]}]="$LATEST_IMAGE_MOUNT"
}
unmount_dmg() {
set +o nounset
if [ -z "$1" ]; then
log "Internal error: tried to eject an image without a path" error
return 1
fi
if [ ! -d "$1" ]; then
log "Internal error: tried to eject an image from $1 but that path is not a directory" error
return 1
fi
# ToDo: check to see that there is an image mounted here
FEEDBACK=`/usr/bin/hdiutil eject "$1" 2>&1`
if [ ${?} -ne 0 ]; then
echo "$FEEDBACK" | (while read INPUT; do log "$INPUT " detail; done)
# for some reason it did not un-mount, so we will try again with more force
log "The image did not eject cleanly, so I will force it" information
FEEDBACK=`/usr/bin/hdiutil eject -force "$1" 2>&1`
if [ ${?} -ne 0 ]; then
echo "$FEEDBACK" | (while read INPUT; do log "$INPUT " detail; done)
log "Failed to unmount the $2 image from $1, unable to continue" error
return 1
else
echo "$FEEDBACK" | (while read INPUT; do log "$INPUT " detail; done)
fi
else
echo "$FEEDBACK" | (while read INPUT; do log "$INPUT " detail; done)
fi
# Remove the disk from MOUNTED_DMG_MOUNT_POINTS
for (( unmountDiskCount = 0 ; unmountDiskCount < ${#MOUNTED_DMG_MOUNT_POINTS[@]} ; unmountDiskCount++ )); do
if [ ! -z "${MOUNTED_DMG_MOUNT_POINTS[$unmountDiskCount]}" ] && [ "${MOUNTED_DMG_MOUNT_POINTS[$unmountDiskCount]}" == "$1" ]; then
unset MOUNTED_DMG_MOUNT_POINTS[$unmountDiskCount]
fi
done
if [ -z "$2" ]; then
log "Unmounted image from $1" detail
else
log "Unmounted the $2 image from $1" detail
fi
set -o nounset
}
jail_installer_daemons() {
# create a modified version of the com.apple.installd.plist and launch it in replacement
log "Encasing installer daemon in a chroot jail" information
# make sure that installd is not running already
if [ ! -z `/bin/ps -axww -c -o "comm" | /usr/bin/awk '/^installd$/'` ]; then
echo "Error: There is already an installer process running!" 1>&2
exit 1
fi
# create a folder to hold the modified launchdaemons
MODIFIED_INSTALLD_PLIST_FOLDER=`/usr/bin/mktemp -d -t "modified.com.apple.installd"` # note: this will be cleaned up by jailbreak_installer_daemons
# all the daemons for 10.5 and 10.6
POSSIBLE_DAEMONS=("com.apple.installd" "com.apple.docsetinstalld" "com.apple.installdb.system")
for THIS_DAEMON in "${POSSIBLE_DAEMONS[@]}"; do
if [ -e "/System/Library/LaunchDaemons/${THIS_DAEMON}.plist" ] && [ "`defaults read /System/Library/LaunchDaemons/${THIS_DAEMON} Disabled 2>/dev/null`" != "1" ]; then
log " Chrooting $THIS_DAEMON daemon" information
# copy the normal launchdaemon
/bin/cp "/System/Library/LaunchDaemons/${THIS_DAEMON}.plist" "${MODIFIED_INSTALLD_PLIST_FOLDER}/modified.${THIS_DAEMON}.plist" | (while read INPUT; do log "$INPUT " detail; done)
# modify the copied file
/usr/bin/defaults write "${MODIFIED_INSTALLD_PLIST_FOLDER}/modified.${THIS_DAEMON}" RootDirectory "$TARGET_IMAGE_MOUNT" | (while read INPUT; do log "$INPUT " detail; done)
/usr/bin/defaults write "${MODIFIED_INSTALLD_PLIST_FOLDER}/modified.${THIS_DAEMON}" Label "modified.${THIS_DAEMON}" | (while read INPUT; do log "$INPUT " detail; done)
# disable the normal service and bring up our modified service
/bin/launchctl unload "/System/Library/LaunchDaemons/${THIS_DAEMON}.plist"
if [ $? -ne 0 ]; then
log "Unable to unload system ${THIS_DAEMON} daemon" error
exit 1
fi
/bin/launchctl load "${MODIFIED_INSTALLD_PLIST_FOLDER}/modified.${THIS_DAEMON}.plist"
if [ $? -ne 0 ]; then
defaults read "${MODIFIED_INSTALLD_PLIST_FOLDER}/modified.${THIS_DAEMON}"
log "Unable to load modified ${THIS_DAEMON} daemon" error
exit 1
fi
MODIFIED_INSTALLD_PLISTS[${#MODIFIED_INSTALLD_PLISTS[@]}]="${THIS_DAEMON}"
fi
done
}
jailbreak_installer_daemons() {
log "Restoring normal installd daemon" information
if [ ! -z "$MODIFIED_INSTALLD_PLIST_FOLDER" ] && [ -d "$MODIFIED_INSTALLD_PLIST_FOLDER" ]; then
for THIS_DAEMON in "${MODIFIED_INSTALLD_PLISTS[@]}"; do
if [ -e "${MODIFIED_INSTALLD_PLIST_FOLDER}/modified.${THIS_DAEMON}.plist" ]; then
log " Restoring $THIS_DAEMON daemon" information
/bin/launchctl unload "${MODIFIED_INSTALLD_PLIST_FOLDER}/modified.${THIS_DAEMON}.plist" | (while read INPUT; do log "$INPUT " detail; done)
/bin/launchctl load "/System/Library/LaunchDaemons/${THIS_DAEMON}.plist" | (while read INPUT; do log "$INPUT " detail; done)
fi
done
fi
/bin/rm -rf "$MODIFIED_INSTALLD_PLIST_FOLDER"
}
#<!------------------------ Phases ------------------------->
check_setup () {
IFS=$'\n'
# Check the language
LANGUAGE_CODE_IS_VALID=false
for LANGUAGE_CODE in $(/usr/sbin/installer -listiso | /usr/bin/tr "\t" "\n"); do
if [ "$ISO_CODE" == "$LANGUAGE_CODE" ]; then
LANGUAGE_CODE_IS_VALID=true
fi
done
if [ $LANGUAGE_CODE_IS_VALID == false ]; then
log "The ISO language code $ISO_CODE is not recognized by the Apple installer" error
exit 1
fi
# If the ASR_OUPUT_FILE_NAME does not end in .dmg, add it
if [ "`/bin/echo $ASR_OUPUT_FILE_NAME | /usr/bin/awk 'tolower() ~ /.*\.dmg$/ { print "true" }'`" != "true" ]; then
ASR_OUPUT_FILE_NAME="$ASR_OUPUT_FILE_NAME.dmg"
fi
# make sure that the CONSOLE_LOG_LEVEL is one of the accepted values
if [ "$CONSOLE_LOG_LEVEL" != "0" ] && [ "$CONSOLE_LOG_LEVEL" != "1" ] && [ "$CONSOLE_LOG_LEVEL" != "2" ] && [ "$CONSOLE_LOG_LEVEL" != "3" ] && [ "$CONSOLE_LOG_LEVEL" != "4" ]; then
log "The console log level must be an integer between 0 and 4" error
fi
}
# check to make sure we are root
rootcheck() {
# Root is required to run instadmg
if [ $EUID != 0 ]; then
log "You must run this utility using sudo or as root!" error-nolog
exit 1
fi
}
startup() {
IFS=' '
FOLDER_LIST="UPDATE_FOLDER CUSTOM_FOLDER ASR_FOLDER BASE_IMAGE_CACHE LOG_FOLDER TEMPORARY_FOLDER"
if [ -z "$INSTALLER_DISK" ]; then
# check the INSTALLER_FOLDERS
for THIS_FOLDER in "${INSTALLER_FOLDERS[@]}"; do
if [ ! -d "$THIS_FOLDER" ]; then
log "An installer folder is missing or was not a folder: $THIS_FOLDER" error
exit 1
fi
done
fi
for FOLDER_ITEM in $FOLDER_LIST; do
# sanitize the folder paths to make sure that they don't end in /
if [ ${!FOLDER_ITEM: -1} == '/' ] && [ "${!FOLDER_ITEM}" != '/' ]; then
THE_STR="${!FOLDER_ITEM}"
eval $FOLDER_ITEM='${THE_STR: 0: $((${#THE_STR} - 1)) }'
fi
# check that all the things that should be folders are folders
if [ ! -d "${!FOLDER_ITEM}" ]; then
log "A required folder is missing or was not a folder: $FOLDER_ITEM: ${!FOLDER_ITEM}" error
exit 1
fi
done
# Create folder to enclose host mount points
HOST_MOUNT_FOLDER=`/usr/bin/mktemp -d "$TEMPORARY_FOLDER/$MOUNT_FOLDER_TEMPLATE"`
/bin/chmod og+x "$HOST_MOUNT_FOLDER" 2>&1 | (while read INPUT; do log "$INPUT " detail; done) # allow the installer user through
log "Host mount folder: $HOST_MOUNT_FOLDER" detail
# Get the MacOS X version information.
OS_REV_MAJOR=`/usr/bin/sw_vers -productVersion | awk -F "." '{ print $2 }'`
OS_REV_MINOR=`/usr/bin/sw_vers -productVersion | awk -F "." '{ print $3 }'`
CPU_TYPE=`/usr/bin/arch`
}
# Look for the baseOS disk and supporting disks (if not provided)
find_base_os() {
log "Finding main MacOS X installer disk" section
if [ -z "$INSTALLER_DISK" ]; then
# use the old folder searching method
if [ ${#SUPPORTING_DISKS[@]} -gt 0 ]; then
log "If the -J flag is used, then the -I flag must also be used" error
exit 1
fi
for THIS_INSTALLERFOLDER in "${INSTALLER_FOLDERS[@]}"; do
FOUND_IMAGE_FILE=false
CANIDATE_IMAGES=()
for THIS_CASE in 'DMG' 'dmg'; do
LOCATED_ITEMS=($THIS_INSTALLERFOLDER/*.$THIS_CASE)
if [ "$LOCATED_ITEMS" != "$THIS_INSTALLERFOLDER/"'*'".$THIS_CASE" ]; then
CANIDATE_IMAGES=("${CANIDATE_IMAGES[@]-}" "${LOCATED_ITEMS[@]}")
fi
done
for IMAGE_FILE in "${CANIDATE_IMAGES[@]-}"; do
for THIS_NAME in "${ALLOWED_INSTALLER_DISK_NAMES[@]}"; do
shopt -s nocasematch # case insensitive matching
if [[ "$IMAGE_FILE" == */$THIS_NAME ]]; then
OS_INSTALL_FILE="$IMAGE_FILE"
log "Found primary OS installer disk: $OS_INSTALL_FILE" information
FOUND_IMAGE_FILE=true
# if we were not supplied with an installerChoices file, look beside this image for one
if [ -z "$OS_INSTALL_CHOICES_FILE" ] && [ $OS_REV_MAJOR -gt 4 ] && [ -f "$THIS_INSTALLERFOLDER/InstallerChoices.xml" ]; then
OS_INSTALL_CHOICES_FILE="$THIS_INSTALLERFOLDER/InstallerChoices.xml"
fi
fi
shopt -u nocasematch
done
if [ $FOUND_IMAGE_FILE == false ] && [ ! -z "$IMAGE_FILE" ]; then
# if it is not a primary disk, it must be a supporting one
SUPPORTING_DISKS[${#SUPPORTING_DISKS[@]}]="$IMAGE_FILE"
fi
done
if [ $FOUND_IMAGE_FILE == true ]; then
break
fi
done
else
# user should have supplied us with everything we need
# Check for the disk at the path supplied
if [ -f "$INSTALLER_DISK" ]; then
OS_INSTALL_FILE="$INSTALLER_DISK"
else
log "Unable to find installer disk at supplied path: $INSTALLER_DISK" error
exit 1
fi
fi
if [ -z "$OS_INSTALL_FILE" ]; then
log "Unable to find primary installer disk" error
exit 1
fi
}
# Look for and mount a cached image
mount_cached_image() {
log "Looking for a Cached Image" section
# figure out the name the filesystem should have
# compatibility for old-style checksums (using colons)
OLD_STYLE_TARGET_IMAGE_CHECKSUM='' # using colons
OS_INSTALL_FILE=`AddOns/InstaUp2Date/Resources/pathHelpers.py --normalize-path --follow-symlinks --supress-return "$OS_INSTALL_FILE" 2>&1`
TARGET_IMAGE_CHECKSUM=`/usr/bin/hdiutil imageinfo "$OS_INSTALL_FILE" | /usr/bin/awk '/^Checksum Value:/ { print $3 }' | /usr/bin/sed 's/\\$//'`
# sanity check
if [ -z "$TARGET_IMAGE_CHECKSUM" ]; then
log "Unable to get checksum for image: $OS_INSTALL_FILE" error
exit 1
fi
# get the checksum on the installer choices file, if there is one
if [ ! -z "$OS_INSTALL_CHOICES_FILE" ]; then
INSTALLER_CHOICES_CHEKSUM=`/usr/bin/openssl dgst -sha1 "$OS_INSTALL_CHOICES_FILE" | awk 'sub(".*= ", "")'`
OLD_STYLE_TARGET_IMAGE_CHECKSUM="${TARGET_IMAGE_CHECKSUM}:${INSTALLER_CHOICES_CHEKSUM}"
TARGET_IMAGE_CHECKSUM="${TARGET_IMAGE_CHECKSUM}_${INSTALLER_CHOICES_CHEKSUM}"
fi
# look for the cached image, new style first
if [ -e "${BASE_IMAGE_CACHE}/${TARGET_IMAGE_CHECKSUM}.dmg" ]; then
TARGET_IMAGE_FILE="${BASE_IMAGE_CACHE}/${TARGET_IMAGE_CHECKSUM}.dmg"
elif [ -e "${BASE_IMAGE_CACHE}/${OLD_STYLE_TARGET_IMAGE_CHECKSUM}.dmg" ]; then
TARGET_IMAGE_FILE="${BASE_IMAGE_CACHE}/${OLD_STYLE_TARGET_IMAGE_CHECKSUM}.dmg"
else
log "No cached image found" information
return
fi
# Create mount point for the (read-only) target
TARGET_IMAGE_MOUNT=`/usr/bin/mktemp -d "$HOST_MOUNT_FOLDER/$MOUNT_POINT_TEMPLATE"`
/bin/chmod og+x "$TARGET_IMAGE_MOUNT" 2>&1 | (while read INPUT; do log "$INPUT " detail; done) # allow the installer user through
log "Current image mount point: $TARGET_IMAGE_MOUNT" detail
# Decide the location for the shadow file to be attached to the target dmg
SHADOW_FILE_LOCATION="$HOST_MOUNT_FOLDER/`/usr/bin/uuidgen`.shadowfile"
log "Shadow file location: $SHADOW_FILE_LOCATION" detail
# Check if the 10.7+ Recovery partition is in the cached image
RECOVERY=`/usr/bin/hdiutil fsid "$TARGET_IMAGE_FILE" 2>/dev/null | /usr/bin/grep -c Recovery`
# Mount the image and the shadow file
log "Mounting the shadow file ($SHADOW_FILE_LOCATION) onto the cached image ($TARGET_IMAGE_FILE)" information
if [ $RECOVERY -eq 0 ]; then
if [ $ENABLE_NON_PARANOID_MODE == true ]; then
/usr/bin/hdiutil attach "$TARGET_IMAGE_FILE" -nobrowse -noautofsck -noverify -owners on -mountpoint "$TARGET_IMAGE_MOUNT" -shadow "$SHADOW_FILE_LOCATION" | (while read INPUT; do log "$INPUT " detail; done)
else
/usr/bin/hdiutil attach "$TARGET_IMAGE_FILE" -nobrowse -owners on -mountpoint "$TARGET_IMAGE_MOUNT" -shadow "$SHADOW_FILE_LOCATION" | (while read INPUT; do log "$INPUT " detail; done)
fi
else
log "Recovery Partition Found" information
/usr/bin/hdiutil attach "$TARGET_IMAGE_FILE" -nobrowse -noautofsck -noverify -owners on -mountroot "$TARGET_IMAGE_MOUNT" -shadow "$SHADOW_FILE_LOCATION" | (while read INPUT; do log "$INPUT " detail; done)
TARGET_IMAGE_MOUNT="$TARGET_IMAGE_MOUNT/Macintosh HD"
fi
# Check that the host OS is the same major version as the target
TARGET_OS_REV=`/usr/bin/defaults read "$TARGET_IMAGE_MOUNT/System/Library/CoreServices/SystemVersion" ProductVersion`
TARGET_OS_REV_MAJOR=`/usr/bin/defaults read "$TARGET_IMAGE_MOUNT/System/Library/CoreServices/SystemVersion" ProductVersion | awk -F "." '{ print $2 }'`
TARGET_OS_REV_BUILD=`/usr/bin/defaults read "$TARGET_IMAGE_MOUNT/System/Library/CoreServices/SystemVersion" ProductBuildVersion`
TARGET_OS_NAME=`/usr/bin/defaults read "$TARGET_IMAGE_MOUNT/System/Library/CoreServices/SystemVersion" ProductName`
if [ $OS_REV_MAJOR -ne $TARGET_OS_REV_MAJOR ]; then
log "$PROGRAM line number $LINENO: Trying to install 10.$TARGET_OS_REV_MAJOR while running on 10.$OS_REV_MAJOR, this is unsupported" error
exit 1
fi
# TODO: check to see if there was a problem
}
# Mount the OS source image and any supporting disks
mount_os_install() {
log "Mounting Mac OS X installer image" section
mount_dmg "$OS_INSTALL_FILE" "" ""
if [ $? -ne 0 ]; then
log "Unable to mount the Install Disc: $OS_INSTALL_FILE" error
exit 1
fi
OS_INSTALL_MOUNT=$LATEST_IMAGE_MOUNT
# check to make sure we are leaving something useful
if [ -z "$OS_INSTALL_MOUNT" ]; then
log "No OS install disk or cached build was found" error
exit 1
fi
# Check that the host OS is the same major version as the target
TARGET_OS_REV=`/usr/bin/defaults read "$OS_INSTALL_MOUNT/System/Library/CoreServices/SystemVersion" ProductVersion`
TARGET_OS_REV_MAJOR=`/usr/bin/defaults read "$OS_INSTALL_MOUNT/System/Library/CoreServices/SystemVersion" ProductVersion | awk -F "." '{ print $2 }'`
TARGET_OS_REV_BUILD=`/usr/bin/defaults read "$TARGET_IMAGE_MOUNT/System/Library/CoreServices/SystemVersion" ProductBuildVersion`
TARGET_OS_NAME=`/usr/bin/defaults read "$TARGET_IMAGE_MOUNT/System/Library/CoreServices/SystemVersion" ProductName`
if [ $OS_REV_MAJOR -ne $TARGET_OS_REV_MAJOR ]; then
log "$PROGRAM line number $LINENO: Trying to install 10.$TARGET_OS_REV_MAJOR while running on 10.$OS_REV_MAJOR, this is unsupported" error
exit 1
fi
log "Mac OS X installer image mounted" information
}
mount_supporting_images() {
if [ ${#SUPPORTING_DISKS[@]} -gt 0 ]; then
log "Mounting supporting disks" section
for (( diskCount = 0 ; diskCount < ${#SUPPORTING_DISKS[@]} ; diskCount++ )); do
mount_dmg "${SUPPORTING_DISKS[$diskCount]}" "" ""
log "Mounted supporting disk ${SUPPORTING_DISKS[$diskCount]} at $LATEST_IMAGE_MOUNT" information
done
fi
}
# setup and create the DMG.
create_and_mount_image() {
log "Creating intermediary disk image" section
if [ "$CPU_TYPE" == "ppc" ]; then
LAYOUT_TYPE="SPUD"
elif [ "$CPU_TYPE" == "i386" ]; then
LAYOUT_TYPE="GPTSPUD"
else
log "Unknown CPU type: $CPU_TYPE. Unable to continue" error
exit 1
fi
# Create mount point for the (read-only) target
TARGET_IMAGE_MOUNT=`/usr/bin/mktemp -d "/tmp/$MOUNT_POINT_TEMPLATE"` # note: we do not use the temp folder, as it blows up
/bin/chmod og+x "$TARGET_IMAGE_MOUNT" 2>&1 | (while read INPUT; do log "$INPUT " detail; done) # allow the installer user through
log "Current image mount point: $TARGET_IMAGE_MOUNT" detail
# Decide the location for the shadow file to be attached to the target dmg
SHADOW_FILE_LOCATION="$HOST_MOUNT_FOLDER/`/usr/bin/uuidgen`"
log "Shadow file location: $SHADOW_FILE_LOCATION.sparseimage" detail
/usr/bin/hdiutil create -size $DMG_SIZE -volname "$ASR_FILESYSTEM_NAME" -layout "$LAYOUT_TYPE" -type SPARSE -fs $DMG_FS "$SHADOW_FILE_LOCATION" | (while read INPUT; do log "$INPUT " detail; done)
if [ $? -ne 0 ]; then
log "Failed to create targetimage: $SHADOW_FILE_LOCATION" error
exit 1
fi
# The create command appends a ".sparseimage" to what we give it
SHADOW_FILE_LOCATION="$SHADOW_FILE_LOCATION.sparseimage"
/usr/bin/hdiutil mount "$SHADOW_FILE_LOCATION" -owners on -readwrite -noverify -nobrowse -mountpoint "$TARGET_IMAGE_MOUNT" | (while read INPUT; do log "$INPUT " detail; done)
if [ $? -ne 0 ]; then
log "Failed to mount target image: $SHADOW_FILE_LOCATION at: $TARGET_IMAGE_MOUNT" error
exit 1
fi
log "Target image: $SHADOW_FILE_LOCATION mounted successfully at: $TARGET_IMAGE_MOUNT" information
}
# Install from installation media to the DMG
install_system() {
log "Beginning Installation from $OS_INSTALL_MOUNT" section
# Fail if there is an installerChoices file and we are running < 10.5
if [ $OS_REV_MAJOR -lt 5 ] && [ ! -z "$OS_INSTALL_CHOICES_FILE" ]; then
log "Running on Pre-10.5. InstallerChoices.xml files do not work" error
exit 1
fi
OS_INSTALLER_PACKAGE=''
if [ -e "$OS_INSTALL_MOUNT/System/Installation/Packages/OSInstall.mpkg" ]; then
OS_INSTALLER_PACKAGE="$OS_INSTALL_MOUNT/System/Installation/Packages/OSInstall.mpkg"
elif [ -e "$OS_INSTALL_MOUNT/Packages/OSInstall.mpkg" ]; then
OS_INSTALLER_PACKAGE="$OS_INSTALL_MOUNT/Packages/OSInstall.mpkg"
else
log "The OS Install File is missing the OS Installer Package!" error
exit 1
fi
# Fix a bug in 'installer' on certain versions of the OS
/bin/mkdir -p "$TARGET_IMAGE_MOUNT/Library/Caches"
if [ -z "$OS_INSTALL_CHOICES_FILE" ]; then
log "Installing system from: $OS_INSTALL_MOUNT onto image at: $TARGET_IMAGE_MOUNT using language code: $ISO_CODE" information
/usr/sbin/installer -verboseR -dumplog -pkg "$OS_INSTALLER_PACKAGE" -target "$TARGET_IMAGE_MOUNT" -lang $ISO_CODE 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
else
log "Installing system from: $OS_INSTALL_MOUNT onto image at: $TARGET_IMAGE_MOUNT using InstallerChoices file: $OS_INSTALL_CHOICES_FILE and language code: $ISO_CODE" information
/usr/sbin/installer -verboseR -dumplog -applyChoiceChangesXML "$OS_INSTALL_CHOICES_FILE" -pkg "$OS_INSTALLER_PACKAGE" -target "$TARGET_IMAGE_MOUNT" -lang "$ISO_CODE" 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
fi
if [ $? -ne 0 ]; then
log "Failed to install the base image" error
exit 1
fi
# Eject the installer disk
if [ $OS_INSTALL_AUTOMOUNTED == true ]; then
unmount_dmg "$OS_INSTALL_MOUNT" "Primary OS install disk"
/bin/rmdir "$OS_INSTALL_MOUNT" 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
fi
OS_INSTALL_MOUNT=''
# TODO: unmount supporting disks
log "Base OS installed" information
}
save_cached_image() {
# if we are at this point we need to close the image, move it to the cached folder
log "Compacting and saving cached image to: $BASE_IMAGE_CACHE/$TARGET_IMAGE_CHECKSUM.dmg" information
# unmount the image
unmount_dmg "$TARGET_IMAGE_MOUNT" "target image" || exit 1
# move the image to the cached folder with the appropriate name
TARGET_IMAGE_FILE="$BASE_IMAGE_CACHE/$TARGET_IMAGE_CHECKSUM.dmg"
/usr/bin/hdiutil convert -format UDZO -imagekey zlib-level=6 -o "$TARGET_IMAGE_FILE" "$SHADOW_FILE_LOCATION" | (while read INPUT; do log "$INPUT " detail; done)
/bin/rm "$SHADOW_FILE_LOCATION"
if [ $? -ne 0 ]; then
log "Unable to move the image to cache folder, unable to continue" error
exit 1
fi
# set the appropriate metadata on the file so that time-machine does not back it up
if [ -x /usr/bin/xattr ]; then
/usr/bin/xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd "$TARGET_IMAGE_FILE"
fi
}
# make any adjustments that need to be made before installing packages
prepare_image() {
if [ $DISABLE_CHROOT == false ]; then
# create a folder inside the chroot with the same path as the mount point pointing at root to fix some installer bugs
/bin/mkdir -p "${TARGET_IMAGE_MOUNT}${TARGET_IMAGE_MOUNT}" 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
/bin/rmdir "${TARGET_IMAGE_MOUNT}${TARGET_IMAGE_MOUNT}" 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
/bin/ln -s / "${TARGET_IMAGE_MOUNT}${TARGET_IMAGE_MOUNT}" 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
# make sure that the temp folder exists inside the image
TARGET_TEMP_FOLDER="${TARGET_IMAGE_MOUNT}/private/tmp"
/bin/mkdir -p "$TARGET_TEMP_FOLDER" 2>&1 | (while read INPUT; do log "$INPUT " detail; done) # this should probably already exist
fi
}
# install packages from a folder of folders (01, 02, 03...etc)
install_packages_from_folder() {
SELECTED_FOLDER="$1"
log "Beginning Update Installs from $SELECTED_FOLDER" section
if [ -z "$SELECTED_FOLDER" ]; then
log "install_packages_from_folder called without folder" error
exit 1;
fi
IFS=$'\n'
for ORDERED_FOLDER in $(/bin/ls -A1 "$SELECTED_FOLDER" | /usr/bin/awk "/^[[:digit:]]+.*$/" | /usr/bin/sort -n); do
TARGET="$SELECTED_FOLDER/$ORDERED_FOLDER"
ORIGINAL_TARGET="$TARGET"
CHROOT_TARGET=''
TARGET_COPIED=false
PACKAGE_DMG_MOUNT=''
PACKAGE_DMG_FILE=''
log "Working on folder $ORDERED_FOLDER (`date '+%H:%M:%S'`)" information
# first resolve any chain of symlinks
TARGET=`AddOns/InstaUp2Date/Resources/pathHelpers.py --normalize-path --follow-symlinks --supress-return "$TARGET" 2>&1`
# check for dmgs
shopt -s nocasematch # case insensitive matching
if [[ "$TARGET" == *.dmg ]]; then
# use hdiutil to get a volume name
DMG_INTERNAL_NAME=`/usr/bin/hdiutil imageinfo "$TARGET" 2>/dev/null | awk '/^\tName:/ && sub("\tName: ", "")'`
if [ -z "$DMG_INTERNAL_NAME" ]; then
# this is an unknown file type, so we need to bail
log "Error: $ORIGINAL_TARGET pointed at $TARGET, which should be a DMG, but hdiutil cannot get a volume name for it" error
exit 1
else
PACKAGE_DMG_FILE="$TARGET"
if [ $DISABLE_CHROOT == true ]; then
# mount in the host mount folder
TARGET=`/usr/bin/mktemp -d "$HOST_MOUNT_FOLDER/$MOUNT_POINT_TEMPLATE"`
else
# mount in /Volumes in the TARGET_IMAGE_MOUNT
TARGET=`/usr/bin/mktemp -d "$TARGET_IMAGE_MOUNT/private/tmp/$MOUNT_POINT_TEMPLATE"`
fi
/bin/chmod og+x "$TARGET" 2>&1 | (while read INPUT; do log "$INPUT " detail; done) # allow the installer user through
PACKAGE_DMG_MOUNT="$TARGET"
log " Mounting the package dmg: $DMG_INTERNAL_NAME ($ORIGINAL_TARGET) at: $TARGET" information
mount_dmg "$PACKAGE_DMG_FILE" "$TARGET" ""
if [ $DISABLE_CHROOT == false ]; then
# get the chroot target string, in case we use it
CHROOT_TARGET=`basename $TARGET`; CHROOT_TARGET="/private/tmp/$CHROOT_TARGET"
fi
# mark this as copied
TARGET_COPIED=true
fi
fi
shopt -u nocasematch
# build a list of items to install
ITEM_LIST=()
shopt -s nocasematch
if [[ "$TARGET" == *.pkg ]] || [[ "$TARGET" == *.mpkg ]] || [[ "$TARGET" == *.app ]]; then
# a naked package or .app
IFS=$'\n'
ITEM_LIST[${#ITEM_LIST[@]}]="$TARGET"
elif [ -d "$TARGET" ]; then
# a folder of things
IFS=$'\n'
for THIS_ITEM in $(ls -A1 "$TARGET"); do
if [[ "$THIS_ITEM" == *.pkg ]] || [[ "$THIS_ITEM" == *.mpkg ]]; then
ITEM_LIST[${#ITEM_LIST[@]}]="$TARGET/$THIS_ITEM"
fi
done
# if we didn't find anything, then we need to look for naked .app's
if [ ${#ITEM_LIST[@]} -eq 0 ]; then
for THIS_ITEM in $(ls -A1 "$TARGET"); do
if [[ "$THIS_ITEM" == *.app ]]; then
ITEM_LIST[${#ITEM_LIST[@]}]="$TARGET/$THIS_ITEM"
fi
done
fi
else
# we have fallen through, and don't know what to do with this item
log "Unable to figure out what to do with: $TARGET" error
exit 1
fi
if [ ${#ITEM_LIST[@]} -eq 0 ]; then
log "There were no items to install in: $TARGET" error
exit 1
fi
# install the items
IFS=$'\n'
for INSTALL_ITEM in $ITEM_LIST; do
# packages
if [[ "$INSTALL_ITEM" == *.pkg ]] || [[ "$INSTALL_ITEM" == *.mpkg ]]; then
# copy things to a temporary folder inside the chroot zone if we need to
if [ $DISABLE_CHROOT == false ] && [ $TARGET_COPIED == false ]; then
CHROOT_TARGET=`/usr/bin/mktemp -d "$TARGET_IMAGE_MOUNT/private/tmp/$SOURCE_FOLDER_TEMPLATE"`
/bin/chmod og+x "$CHROOT_TARGET" # allow the installer user through
if [ -d "$TARGET" ]; then # note: we should never get here for dmg's
# copy all of the contents into the image, just in case something cross-references
log " Copying folder $TARGET into the target at $CHROOT_TARGET" information
/bin/cp -RHL "$TARGET/" "$CHROOT_TARGET/" 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
else
# copy just the item into the folder
log " Copying $TARGET into the target at $CHROOT_TARGET" information
/bin/cp -RHL "$TARGET" "$CHROOT_TARGET/" 2>&1 | (while read INPUT; do log "$INPUT " detail; done)
fi
# reset the chroot target to the correct path
CHROOT_TARGET=`basename "$CHROOT_TARGET"`; CHROOT_TARGET="/private/tmp/$CHROOT_TARGET"
TARGET_COPIED=true
fi
if [ $OS_REV_MAJOR -ge 5 ] && [ -e "`dirname "$INSTALL_ITEM"`/InstallerChoices.xml" ]; then # 10.4 can't use InstallerChoices files
CHOICES_FILE=true
else
CHOICES_FILE=false
fi
if [ $DISABLE_CHROOT == true ]; then
PACKAGE_USE_CHROOT=false
else
PACKAGE_USE_CHROOT=true
# check to see if this is on the list of packages to exclude from the chroot
if [ -d "$INSTALL_ITEM" ]; then
PACKAGE_BUNDLE_ID=`/usr/bin/defaults read "$INSTALL_ITEM/Contents/Info" "CFBundleIdentifier" 2>/dev/null`
PACKAGE_CHROOT_DISABLE=`/usr/bin/defaults read "$INSTALL_ITEM/Contents/Info" "InstaDMG Chroot Disable" 2>/dev/null`
if [ ! -z "$PACKAGE_CHROOT_DISABLE" ]; then
PACKAGE_USE_CHROOT=false
elif [ ! -z "$PACKAGE_BUNDLE_ID" ]; then
BUNDLE_ID_ARRAY_LENGTH=${#CHROOT_EXCLUDED_CODES[@]}