Cleaned lipo builder up a bit.
[puredarwin_setup.git] / pd_setup
bloba259a0105e945d1a1359cb6829845b71241099ff
1 #!/usr/bin/env bash
3 # Copyright (c) 2007-2009 The PureDarwin Project.
4 # All rights reserved.
6 # @LICENSE_HEADER_START@
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # @LICENSE_HEADER_END@
33 # Copyright (c) 2005, Apple Computer, Inc. All rights reserved.
35 # @APPLE_BSD_LICENSE_HEADER_START@
37 # Redistribution and use in source and binary forms, with or without
38 # modification, are permitted provided that the following conditions
39 # are met:
40 # 1. Redistributions of source code must retain the above copyright
41 # notice, this list of conditions and the following disclaimer.
42 # 2. Redistributions in binary form must reproduce the above copyright
43 # notice, this list of conditions and the following disclaimer in the
44 # documentation and/or other materials provided with the distribution.
45 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
46 # its contributors may be used to endorse or promote products derived
47 # from this software without specific prior written permission.
49 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
50 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 # ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
53 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
57 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
58 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 # POSSIBILITY OF SUCH DAMAGE.
61 # @APPLE_BSD_LICENSE_HEADER_END@
65 # probono <probono@puredarwin.org>
66 # aladin <aladin@puredarwin.org>
70 # Set up a basic PureDarwin system
72 # WARNING: this will destroy all data on the target!
74 # Based on darwinmaster.sh by
75 # Kevin Van Vechten <kvv@apple.com>
76 # Based on buildcd.sh by
77 # Shantonu Sen <ssen@opendarwin.org>
78 # Felix Kronlage <fkr@opendarwin.org>
79 # Chuck Remes <cremes@opendarwin.org>
83 # Changelog
85 # 20090313 - See hg log (mercurial) and/or svn log from now - aladin
86 # 20090310 - Enabled PureFoundation
87 # pseudo network support - aladin
88 # 20090208 - Enabled xnu-dev (voodoo Release 1.0 Rev A)
89 # Developer choice, minor fixes - aladin
90 # 20081225 - Enabled xnu-dev (voodoo Release 1.0 Rev 1)
91 # Minor fixes about bootloader
92 # Provide startupfiletool, more WMs - aladin
93 # 20081224 - PureDarwin Xmas released!
94 # 20081219 - Added dtrace, keymaps (for X) in pd_roots
95 # Autoload X via launchd, minor fixes - aladin
96 # 20081217 - Assimilated pd_makeiso setup script
97 # Add qemu-img and mkisofs binary tool
98 # Fixed guestOS in .vmx, minor fixes - aladin
99 # 20081212 - Fixed mount manually to $MOUNT - probono
100 # 20081212 - Added zfs to pd_roots - fixed missingstuff - aladin
101 # 20081211 - We can't use missingstuff any more, need solve it
102 # Use entire disk, not just 256 MB - probono
103 # 20081210 - Mount manually to $MOUNT - probono
104 # 20081210 - Fixed experimental packages built with 9F33pd1.plist
105 # "nano" release uses launchd too, cosmetic updates - aladin
106 # 20081209 - License header update, minor updates
107 # Assimilated "nano" setup script
108 # Added autozone to pd_roots - aladin
109 # 20081030 - Add patched CF, IOKitUser, objc4 and launchd
110 # Added pam to pd_roots (for login & co) - aladin
111 # 20081022 - Fixed diskarbitrationd nag popup - probono
112 # 20081002 - Cleaned again - aladin
113 # 20080927 - Added .vmwarevm extension detection and support
114 # Minor fixes - aladin
115 # 20080926 - Many updates, umount fixed, vmware drivers cleaned
116 # Merge of pd_setup and pd_makedmg - aladin
117 # 20080925 - Fixed shell interactive mode in "nano"
118 # Minor updates, saving more spaces - aladin
119 # 20080921 - Added .zshrc, removed single user mode
120 # Added grep in pd_roots - aladin
121 # 20080917 - Minor updates and fixes
122 # Added zsh interactive mode (for "nano"), system_cmds (ps),
123 # file_cmds (ls), diskdev_cmds (devfs), adv_cmds (ps),
124 # libutil (mount), text_cmds (cat), in pd_roots - aladin
125 # 20080831 - Minor updates and fixes
126 # Added BootCache in pd_roots - aladin
127 # 20080827 - Less missingstuf: PCSC.framework (replaced by pcsc-lite)
128 # Added (temporary) VMware-Drivers-OpenSource.zip
129 # Minor updates - aladin
130 # 20080818 - Fixed minor errors
131 # Added vim in pd_roots
132 # Fake VMware guest OS detection
133 # Added pd_injectuser in pd_contrib/
134 # Added multi-user support - aladin
135 # 20080806 - Added timezone support
136 # Fixed errors found with debug activated (/var/log/syslog)
137 # Fixed pd_binaryroots (forgot to add ipsec in the previous commit)
138 # Fixed (almost) hostname - aladin
139 # 20080803 - Updating booter from v5.0.132_dfe_r28 to v5.0.132_dfe_r146
140 # Added IOBDStorageFamily in pd_drivers
141 # Changed missingstuff to override target existence test
142 # Less missingstuff: com.apple.securityd.plist, securityd,
143 # libsecurity, Security.framework (9D34),
144 # libipsec (9E17), libcrypto (openssl), ...
145 # Launchd debug and verbose boot log via syslog
146 # DTrace support
147 # motd and hostname are back! - aladin
148 # 20080527 - Fixed minor bugs - aladin
149 # 20080525 - Fork for "nano" - probono
150 # 20080523 - Using BinaryDrivers from DarwinBuild - probono
151 # 20080522 - Changed missingstuff not to use "L" since that
152 # filled up the disk too quickly and removed
153 # some of the missingstuff that is now available - probono
154 # 20080303 - Minor updates - aladin
155 # 20080108 - Initial version - probono
158 # Don't fall for user defined aliases.
159 unalias -a
161 function die() {
162 echo "ERROR: ${1}"
163 trap_handler
164 exit 1
167 function locateCommand() {
168 local CMD
169 CMD=$(which ${1})
171 ( [[ $? -gt 0 ]] || [[ -z ${CMD} ]] ) && \
172 die "Unable to find command ${CMD}. Please adjust your PATH properly."
174 echo ${CMD}
177 echo
178 echo "Set up a bootable PureDarwin system."
179 echo
181 ################################################################################
182 # USAGE AND PREVENTIVE TESTS
183 ################################################################################
185 # Fail on return error code
186 #set -e
188 # Fail on uninitialised variables
189 #set -u
191 # Ensure root exclusivity
192 if [ "$UID" -ne 0 ]; then
193 echo "You must be root in order to use $(basename $0)"
194 exit 1
196 #PRIV_CMD="su -c"
197 PRIV_CMD=$(locateCommand "sudo")
199 # Usage statement
200 if [ $# -lt 2 ]; then
201 echo "Usage: $(basename $0) available_output VolumeName"
202 echo
203 echo " * Create a physical volume"
204 echo " $(basename $0) /Volumes/PureDarwin PureDarwin"
205 echo " $(basename $0) /dev/diskX PureDarwin"
206 echo
207 echo " * Create an ISO 9660 image (.iso)"
208 echo " $(basename $0) /tmp/puredarwin.iso PureDarwin"
209 echo
210 echo " * Create a ready-to-run VMware virtual machine (.vmwarevm)"
211 echo " $(basename $0) puredarwin.vmwarevm PureDarwin"
212 echo
213 echo " * Create a ready-to-run VMware virtual disk (.vmdk)"
214 echo " $(basename $0) puredarwin.vmdk PureDarwin"
215 echo
216 exit 1
219 # Ensure "" is not used as "target"
220 if [ "$1" = "" ]
221 then
222 echo "$(basename $0): Empty output filename"
223 exit 1
226 # Ensure / is not used as "target"
227 if [ "$1" = "/" ]
228 then
229 echo "Bad volume name: $1"
230 exit 1
233 # Ensure "target" exists (for real hw)
234 #if [ ! -e "$1" ]
235 #then
236 # echo "Unknown volume name: $1"
237 # exit 1
240 ################################################################################
241 # PATHS AND VARIABLES
242 ################################################################################
244 # Find out where this script lives
245 DIRNAME=$(cd $(dirname $0) && pwd)
247 # Reading global variables in pd_config file
248 source "$DIRNAME"/pd_config
250 # Destination output filename (aka "target")
251 TARGET="$1"
253 # FIXME remove redundancies btw TARGET and MOUNT
254 # Temporary pseudo PureDarwin Volume
255 MOUNT="/tmp/$2"
257 # Volume label of the target image (ie: PureDarwin)
258 VOLNAME="$2"
260 # Thinned binary roots and drivers root folder
261 PACKAGES=$DIRNAME/$DESTDIR
263 # Add PureDarwin binaries and scripts to $PATH
264 # Don't add mach-o bins export PATH=$DIRNAME/pd_setup_files/:$PATH
266 # Location for temporary auxiliary ISO
267 ELTORITOISO=/tmp/eltorito.iso
269 # mkisofs binary path (note: it doesn't come from darwin nor macosx)
270 MKISOFS_BIN=$(locateCommand "mkisofs")
272 # qemu-img binary path (note: it doesn't come from darwin nor macosx)
273 QEMUIMG_BIN=$(locateCommand "qemu-img")
275 # parted binary path
276 PARTED_BIN=$(locateCommand "parted")
278 # newfs_hfs binary path (diskdev_cmds linux port)
279 # ftp://ftp.wh2.tu-dresden.de/pub/mirrors/gentoo/distfiles/diskdev_cmds-332.14.tar.gz
280 # ftp://ftp.wh2.tu-dresden.de/pub/mirrors/gentoo/distfiles/diskdev_cmds-332.14_p1.patch.bz2
282 #NEWFSHFS_BIN=$(locateCommand "newfs_hfs")
283 NEWFSHFS_BIN=$(locateCommand "mkfs.hfsplus")
285 # Target detection (real disk or image/vm) via extension
286 EXT=`basename $1 | awk -F "." '{print $2}'`
288 # Needed for Mr proper in trap() function
289 export DEVICE=""
291 ###############################################################################
292 # INFORMATION
293 ###############################################################################
295 echo "Darwin release: $DARWIN_RELEASE"
296 echo "Architecture : $ARCH"
297 echo "Puredarwin : $PUREDARWIN_RELEASE"
298 echo
299 echo "\$1 (target) : $1"
300 echo "\$2 (name) : $2"
301 echo
303 ###############################################################################
304 # WARNINGS
305 ###############################################################################
307 echo "WARNING! this will destroy all data on $1"
308 printf "Continue? y[n] "
309 read CONT
310 if [ ! "$CONT" = "y" ]; then
311 exit 1
314 echo "WARNING! Are you sure?"
315 printf "Continue? y[n] "
316 read CONT
317 if [ ! "$CONT" = "y" ]; then
318 exit 1
321 # Ensure "target" does not exist
322 if [ -e "$1" ]
323 then
324 echo "WARNING! \`$1' is going to be rewritten"
325 printf "Continue? y[n] "
326 read CONT
327 if [ ! "$CONT" = "y" ]; then
328 echo "Aborting! \`$CONT' is not \`y'."
329 exit 1
333 echo
334 echo "OK, You have been warned.."
335 echo
337 ###############################################################################
338 # TRAP FUNCTIONS
339 ###############################################################################
341 function mr_proper {
342 # Clean up temporary files and folders
343 echo "Cleaning up"
345 if [ -e $ELTORITOISO ];then
346 echo "Removing $ELTORITOISO"
347 rm $ELTORITOISO
350 if [ -e /tmp/i386 ];then
351 echo "Removing /tmp/i386"
352 rm -r /tmp/i386
355 CONT=""
356 T_ERROR=""
358 # Unmounting $MOUNT
359 echo "WARNING! \`$MOUNT is going to be unmounted"
360 printf "Continue? [y]n "
361 read CONT
362 if [ ! "$CONT" = "n" ]; then
363 T_ERROR=`umount -f "$MOUNT" 2>&1`
364 losetup -d ${DEVICE}
365 if [ $? -eq 0 ]; then
366 echo "$MOUNT unmounted"
367 else
368 echo "umount failed (error: $T_ERROR)"
372 # Removing $MOUNT
373 echo "WARNING! \`$MOUNT is going to be removed"
374 printf "Continue? [y]n "
375 read CONT
376 if [ ! "$CONT" = "n" ]; then
377 T_ERROR=`rmdir $MOUNT 2>&1`
378 if [ $? -eq 0 ]; then
379 echo "$MOUNT removed"
380 else
381 echo "rmdir failed: (error: $T_ERROR)"
385 # diskarbitrationd is not present nor needed in the "nano" and "bootstrap" releases.
386 #if [ -e "/System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist" ]; then
387 # # Revert diskarbitrationd mode to on
388 # launchctl load /System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist
391 # Remove any previous copies
392 #if [ -e $TARGET ];then
393 # rm -rf "$TARGET"
394 # echo " * $TARGET removed"
398 # ^c (control-c) trapped
399 function trap_handler {
400 echo
401 echo "Trap function."
402 echo
404 # iso, vmwarevm, vmdk, dmg, etc..
405 if [ ! $EXT = "" ]; then
406 mr_proper
409 # Resetting trap
410 trap - INT TERM EXIT
412 exit 0
415 # Trap ^c (control-c)
416 trap trap_handler INT TERM EXIT
418 ###############################################################################
419 # BOOTLOADER PATH
420 ###############################################################################
422 # Default bootloader: DFE bootloader v5.0.132_dfe_r146 based on Apple boot-132
423 BOOTi386=$DIRNAME/pd_setup_files/boot/i386/
425 # Add Chameleon bootloader (default: yes)
426 if [ ! "$ADD_CHAMELEON" = "n" ]; then
427 # The Chameleon bootloader
428 # (Apple Public Source License)
429 # http://chameleon.osx86.hu
430 # Chameleon 2.0-RC1-r431-bin
431 # Chameleon 2.0-RC2-r640-bin
432 # Chameleon 2.0-RC3-r658-bin
433 # Chameleon-2.0-RC4-r684-bin
435 T_CHAMELEON_RELEASE=""
436 if [ "$ADD_CHAMELEON_RC1" = "y" ]; then
437 T_CHAMELEON_RELEASE="Chameleon-2.0-RC1-r431-bin"
440 if [ "$ADD_CHAMELEON_RC2" = "y" ]; then
441 T_CHAMELEON_RELEASE="Chameleon-2.0-RC2-r640-bin"
444 if [ "$ADD_CHAMELEON_RC3" = "y" ]; then
445 T_CHAMELEON_RELEASE="Chameleon-2.0-RC3-r658-bin"
448 if [ "$ADD_CHAMELEON_RC4" = "y" ]; then
449 T_CHAMELEON_RELEASE="Chameleon-2.0-RC4-r684-bin"
451 echo "Extracting Chameleon bootloader ($T_CHAMELEON_RELEASE)"
452 # bsdtar 2.6.2 - libarchive 2.6.2 / Not in darwinbuild but present by default in Mac OS X
453 #bsdtar xjf $PACKAGES/$T_CHAMELEON_RELEASE.root.tar.bz2 -C "$DIRNAME/pd_setup_files/" --include "*/i386"
454 # tar (GNU tar) 1.15.1 / Present in darwinbuild and in Mac OS X
455 tar xjf $PACKAGES/$T_CHAMELEON_RELEASE.root.tar.bz2 -C "$DIRNAME/pd_setup_files/" --wildcards '*/i386*'
457 BOOTi386=$DIRNAME/pd_setup_files/$T_CHAMELEON_RELEASE/i386/
460 BOOT0="boot0" # MBR
461 BOOT1H="boot1h" # Stage 1 bootsector of EFI partition
462 BOOT="boot" # Stage 2 boot2 HFS+ startup file
463 CDBOOT="cdboot" # CD-ROM, etc..
465 ###############################################################################
466 # PARTITIONING THE DISK
467 ###############################################################################
469 # iso, vmwarevm, vmdk, dmg, etc..
470 if [ ! $EXT = "" ]; then
471 export BLOCKSIZE=512
473 cp pd_setup_files/grub/test.iso $ELTORITOISO
476 # Ingredients for iso, dmg, vmwarevm, etc..
478 if [[ -n "false" ]]; then
479 # Copy bootloader cdboot (but not only) for CD-ROMs
480 echo "Populating /tmp/i386 with bootloader files"
481 #echo "Making an ISO containing the boot-132 files and that has cdboot as its El Torito boot image at $ELTORITOISO..."
482 mkdir -p /tmp/i386
483 cp $BOOTi386/* /tmp/i386/
485 cd /tmp/i386
487 if [ ! -e $CDBOOT ]; then
488 # if it's not there, we should exit
489 echo "Aborting! cdboot cannot be found and is mandatory."
490 mr_proper
491 exit 1
494 # mkisofs
496 # -quiet Less verbose
497 # -V Volume ID to be written into the master block
498 # -no-emul-boot The boot image used to create "El Torito" bootable CDs is a 'no emulation' image
499 # -boot-load-size Specifies the number of "virtual" (512-byte) sectors to load in no-emulation mode.
500 # The default is to load the entire boot file (here it is "4").
501 # Some BIOSes may have problems if this is not
502 # -c Path and filename of the boot catalog to be used when making an "El Torito" bootable CD
503 # -b Eltorito_boot path and filename of the boot image to be used when making an "El Torito" bootable CD
504 # -o Target written image file
505 echo "Creating $ELTORITOISO"
506 "$MKISOFS_BIN" -quiet -V "$VOLNAME" -no-emul-boot -boot-load-size 4 -c boot.cat -b $CDBOOT -o "$ELTORITOISO" .
508 cd - > /dev/null
511 # Create a bootable image
515 # Sector count
516 sectors=$(du -B ${BLOCKSIZE} "$ELTORITOISO" | tail -1 | awk '{print $1}')
517 size_mb=$(du -h "$ELTORITOISO" | tail -1 | awk '{print $1}')
519 #echo "$ELTORITOISO has $sectors sectors, contains the boot-132 files and that has cdboot as its El Torito boot image"
520 echo "created: $ELTORITOISO ($size_mb | $sectors sectors)"
522 # Remove any previous copies
523 #if [ -e "$TARGET" ];then
524 #rm -Rf "$TARGET"
525 #echo "removed: $TARGET"
529 # Default size of the bootable image to be created in Megabyte
530 # FIXME check size < thinned binaryroots dir?
531 # FIXME add size in pd_config
532 #SIZE=$(du -h -d 0 "$SOURCE" | cut -f 1 | sed 's/M//'g) # without "M"
533 #SIZE=$(expr $SIZE + $(expr 255 - $SIZE)) # add some MB to be on the safe side
534 SIZE="2000" # full (unthinned)
535 if [ "$ADD_RELEASE_NANO" = "y" ]; then
536 if [ "$PUREDARWIN_RELEASE" = "nano" ]; then
537 #SIZE="150" # nano
538 SIZE="300" # nano
539 else
540 #SIZE="640" # bootstrap
541 SIZE="1300" # bootstrap
545 # Create a bootable image
546 echo "Creating $TARGET (${SIZE}M)"
547 # hdiutil: manipulate disk images (attach, verify, burn, etc)
548 # create new image of the given size
549 # -fs specify the filesystem (HFS+J <- HFS+ journalised)
550 # -o the result written image
551 # -size specify the size of the image
552 # -layout specify the partition layout of the image (which is "NONE" here)
553 # -type UDIF is the default disk image type
554 # -nospotlight (Undocumented arg)
555 # > strings /usr/bin/hdiutil| grep nospotlight
556 # -nospotlight
557 # > strings /usr/share/man/man1/hdiutil.1 | grep nospotlight
559 #hdiutil create -ov -fs HFS+J -o "$TARGET" -size ${SIZE}M -layout NONE -type UDIF -nospotlight
560 #mv $TARGET.dmg $TARGET
562 dd if=/dev/zero of="$TARGET" bs=1024k count=$SIZE
565 # Suppress automatic mounting of any filesystems in the image
566 # This will result in /dev entries being created and (for non-kernel-attached images)
567 # a process in the background, but no volumes will be mounted.
568 # FIXME `hdid' is not buildable nor available in Darwin, consequently the next steps are failing!
569 # FIXME `hdid' fails with unknown extension as .vmwarevm or .foobar
570 export DEVICE=$(losetup -f --show "$TARGET")
572 # Alternative `nbdst' <- not available.
574 # Alternative via `vndevice' works if
575 # fsck -fy has been run against the volume header of the HFS partition
577 echo "Initializing ${DEVICE}"
578 # pdisk -initialise (Undocumented arg)
579 # > strings /usr/sbin/pdisk | grep "\-initia"
580 # -initialize
581 # > strings /usr/share/man/man8/pdisk.8| grep "\-initia"
583 "${PARTED_BIN}" -s ${DEVICE} mktable mac
584 "${PARTED_BIN}" -s ${DEVICE} unit s print
585 losetup -d ${DEVICE}
587 echo "Partitioning $DEVICE"
588 # pdisk -dump (Undocumented arg)
589 # > strings /usr/sbin/pdisk | grep "\-dump"
590 # -initialize
591 # > strings /usr/share/man/man8/pdisk.8| grep "\-dump"
593 export DEVICE=$(losetup -f --show "$TARGET")
594 dsize=$("${PARTED_BIN}" -s ${DEVICE} unit s print | grep "^Disk" | awk '{ print $3 }' | sed -e 's|s||')
595 p1start=$("${PARTED_BIN}" -s ${DEVICE} unit s print | grep "^ 1 " | awk '{ print $2 }' | sed -e 's|s||')
596 p1size=$("${PARTED_BIN}" -s ${DEVICE} unit s print | grep "^ 1 " | awk '{ print $4 }' | sed -e 's|s||')
597 p2start=$(expr ${p1start} + ${p1size})
598 p2end=$(expr ${p2start} + ${sectors} - 64)
599 # create the partition on the image
600 echo "creating partition from ${p2start}s to ${p2end} with length ${sectors}s"
601 "${PARTED_BIN}" -s ${DEVICE} unit s mkpart primary ${p2start}s ${p2end}s
602 "${PARTED_BIN}" -s ${DEVICE} unit s print
603 losetup -d ${DEVICE}
605 export DEVICE=$(losetup -f --show "$TARGET")
606 p2start=$("${PARTED_BIN}" -s ${DEVICE} unit s print | grep "^ 2 " | awk '{ print $2 }' | sed -e 's|s||')
607 p2size=$("${PARTED_BIN}" -s ${DEVICE} unit s print | grep "^ 2 " | awk '{ print $4 }' | sed -e 's|s||')
608 p3start=$(expr ${p2start} + ${p2size})
609 #p3start=$(expr ${p1start} + ${p1size} + ${sectors} - 64 - 8)
610 echo "creating partition from ${p3start}s to -1s with length ${blocks}s"
611 "${PARTED_BIN}" -s -- ${DEVICE} unit s mkpart primary hfs+ ${p3start}s -1s
612 "${PARTED_BIN}" -s ${DEVICE} unit s print
613 # figure out what slice the partition was created on
614 #slice=`pdisk $DEVICE -dump | grep "$VOLNAME" | awk -F: '{print $1}' | awk -F" " '{print $1}'`
615 # FIXME
616 slice=3
617 losetup -d ${DEVICE}
618 echo "Partition created on slice $slice ($blocks blocks)"
622 # this is the tricky part
623 # dd
624 # skip=n Skip n blocks from the beginning of the input before copying.
625 # On input which supports seeks, an lseek(2) operation is used.
626 # Otherwise, input data is read and discarded.
627 # seek=n Seek n blocks from the beginning of the output before copying.
628 # bs=n Set both input and output block size to n bytes, superseding the ibs and obs operands.
630 # Partition map (with 512 byte blocks) on 'VirtualMachines/full.vmwarevm/full.iso'
631 # #: type name length base ( size )
632 # 1: Apple_partition_map Apple 63 @ 1
633 # 2: Apple_Free Extra 2664 @ 64 ( 1.3M) <=== ELTORITOISO is "dd-ed" here!
634 # 3: Apple_HFS full 2524440 @ 2728 ( 1.2G)
635 # 4: Apple_Free Extra 64 @ 2527168
636 # Device block size=512, Number of Blocks=2527232 (1.2G)
637 # DeviceType=0x0, DeviceId=0x0
638 #export DEVICE=$(losetup -f --show "$TARGET" -o $(expr ${sizp1} \* ${BLOCKSIZE}))
639 export DEVICE=$(losetup -f --show "$TARGET")
640 echo "ddying $ELTORITOISO to $DEVICE"
641 #dd if="$ELTORITOISO" of=$DEVICE skip=64 bs=${BLOCKSIZE}
642 dd if="$ELTORITOISO" of=$DEVICE skip=64 seek=64 bs=${BLOCKSIZE}
643 "${PARTED_BIN}" -s ${DEVICE} unit s print
644 echo $(expr ${p3start} \* ${BLOCKSIZE})
645 "${PARTED_BIN}" -s ${DEVICE} unit b print
646 losetup -d ${DEVICE}
648 # journaled HFS+ volume (default: yes)
649 # create the fs. needs sys-fs/diskdev_cmds (see also http://www.gentoo-wiki.info/Hfsplus)
650 export DEVICE=$(losetup -f --show "$TARGET" -o $(expr ${p3start} \* ${BLOCKSIZE}))
651 if [ ! "$ADD_HFS_JOURNAL" = "n" ]; then
652 echo "Initializing ${DEVICE}s${slice} (Journaled HFS+ volume)"
653 ${NEWFSHFS_BIN} -s -J -v "$VOLNAME" ${DEVICE}
654 else
655 echo "Initializing ${DEVICE}s${slice} (HFS+ volume)"
656 ${NEWFSHFS_BIN} -s -v "$VOLNAME" ${DEVICE}
659 echo "Mounting ${DEVICE}s${slice} on $MOUNT"
660 mkdir -p "$MOUNT"
661 #mount -t hfs -o perm ${DEVICE}s${slice} "$MOUNT"
662 mount -t hfsplus -o rw,force ${DEVICE} "$MOUNT"
664 # copying the boot2 HFS+ startup file
665 echo "Installing stage 2 loader (boot) to the partition's root directory"
666 cp $BOOTi386/$BOOT $MOUNT/
667 else
669 die "Handling of physical devices not yet done."
672 # Preparing and partitionning a whole physical disk device
675 # /dev/diskX passed as $1 ($TARGET)
676 if [ "`ls "$TARGET" | cut -b-9`" = "/dev/disk" ]; then
677 # Preventive check for disk device in /dev
678 if [ ! -e "$TARGET" ]; then
679 echo "ERROR: $TARGET does not exist."
680 trap_handler
683 # disk device node in $1 ($TARGET)
684 export DEVICE=`ls "$TARGET" | cut -b-10`
685 export DEVICE=${DEVICE/disk/rdisk}
686 else
687 # Default disk device node linked to an existing volume (e.g. /Volumes/PureDarwin)
688 PARTITION=$(df | grep "$1" | cut -d " " -f 1 ) # e.g.: /dev/disk0s2
689 RPARTITION=${PARTITION/disk/rdisk}
690 export DEVICE=$(echo $PARTITION | grep -o -e /dev/disk\[0-9\]\* )
691 export DEVICE=${DEVICE/disk/rdisk}
694 # diskarbitrationd is not present nor needed in the "nano" and "bootstrap" releases.
695 if [ -e "/System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist" ]; then
696 # Disable automounting in Finder and popping-up dialog boxed
697 launchctl unload /System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist
700 export COMMAND_LINE_INSTALL=1
701 umount -f ${DEVICE}s1
702 #umount -f $PARTITION
704 # FIXME fix needed for time
705 sleep 3
708 # Partitioning and Bootloader
711 # MBR initialisation with a template file (for BIOS)
712 # -i initialise the MBR sector and also erase partition table (exclusiv to u)
713 # -u Update MBR code, preserving existing partition table (exclusiv to i)
714 # -y Do not ask for confirmation before writing
715 # -a Specify an automatic partitioning style (which is "hfs")
716 # -f Specifies an alternate MBR template file (which is $BOOT0)
717 # Erase MBR (default: yes)
718 echo "Installing boot0 to the partition MBR"
719 if [ ! "$ADD_MBR_ERASE" = "n" ]; then
720 fdisk -i -y -a hfs -f $BOOTi386/$BOOT0 $DEVICE
721 else
722 fdisk -u -y -a hfs -f $BOOTi386/$BOOT0 $DEVICE
725 # Create an HFS Plus file system
726 # -s case-sensitive HFS Plus filesystem
727 # -J journaled HFS+ volume (default journal size is 8MB)
728 # -v volume name (which is the following arg)
729 # journaled HFS+ volume (default: yes)
730 # FIXME "...s1" should not be hardcoded
731 if [ ! "$ADD_HFS_JOURNAL" = "n" ]; then
732 /sbin/newfs_hfs -s -J -v "$VOLNAME" ${DEVICE}s1
733 else
734 /sbin/newfs_hfs -s -v "$VOLNAME" ${DEVICE}s1
737 sleep 5 # FIXME fix needed for time / absolutely needed!
739 echo "Installing stage 1 booter (boot1h) to the partition bootsector"
740 dd if=$BOOTi386/$BOOT1H of=${DEVICE}s1
742 sleep 3 # FIXME fix needed for time
744 # Add Chameleon bootloader (default: yes)
745 if [ "$ADD_CHAMELEON" = "n" ]; then
746 # startupfiletool should not be needed with Chameleon
747 $DIRNAME/../scripts/startupfiletool ${DEVICE}s1 $BOOTi386/$BOOT
750 # TODO RAID Install
752 /bin/sync
754 # Force the mount point to be $MOUNT before diskarbitrationd is launched again
755 mkdir -p ${MOUNT}
756 mount -t hfs ${DEVICE}s1 ${MOUNT}
758 # copying the boot2 HFS+ startup file
759 echo "Installing stage 2 loader (boot) to the partition's root directory"
760 cp $BOOTi386/$BOOT $MOUNT/
762 # FIXME?
763 # ./fdisk -e /dev/rdiskX
764 # f 1
768 # diskarbitrationd is not present nor needed in the "nano" and "bootstrap" releases.
769 if [ -e "/System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist" ]; then
770 # Enable "automounting in Finder and popping-up dialog boxed" on Mac OS X host
771 launchctl load /System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist
775 # Disable Spotlight
776 echo "Disabling Spotlight indexation"
777 touch ${MOUNT}/.metadata_never_index
779 # Adopts (activates) on-disk ownership
780 # FIXME deprecated.
781 echo "Adopting (Activating) on-disk ownership"
782 #vsdbutil -a ${MOUNT}
784 # Ensure permissions are on
785 # FIXME seems to always fail and make the set -e strict mode also.
786 #vsdbutil -c ${MOUNT}
788 ###############################################################################
789 # BINARYROOTS DEPLOYMENT
790 ###############################################################################
792 # Moving to the PureDarwin root ("/")
793 cd ${MOUNT}
795 mkdir -p ./private/var/log/
796 echo "Installing packages on '${MOUNT}'..."
798 for PROJECT in `cat $DIRNAME/$BINARYROOTS_LIST_FILE` ; do
799 echo " * $(basename $PROJECT.root.tar.bz2)"
801 # (default: n)
802 if [ "$ADD_RELEASE_NANO" = "y" ]; then
803 tar xjpf $PACKAGES/$PROJECT.root.tar.bz2 \
804 --exclude '*svn*' \
805 --exclude '*/include/*' \
806 --exclude '/Developer' \
807 --exclude '/AppleInternal' \
808 --exclude '/usr/lib/libSystem.B_debug.dylib' \
809 --exclude '/usr/lib/libSystem.B_profile.dylib' \
810 --exclude '*.h' >> ${MOUNT}/private/var/log/pd_setup.log
811 #--exclude '/usr/local/lib/*' \
812 else
813 tar xjpf $PACKAGES/$PROJECT.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
815 done
817 echo
819 ###############################################################################
820 # MISSING STUFF (mainly vital binarydrivers of darwin 10)
821 ###############################################################################
823 # fixme: "until" is commented because missingstuff shouldn't miss stuff.
824 # It happens (stuff is missed) if the target dir or file exists, even partially.
825 # (e.g., CoreFoundation.framework)
826 # note: no missingstuff in "nano" release
828 missingstuff() {
829 echo "Copying OSX-stuff not supported :-)"
830 return
832 until [ -e ${MOUNT}/$1 ]; do
833 echo "WARNING! $1 is missing. Do you want to copy it from your start volume?"
834 echo "You will not be allowed to use the resulting installation anywhere else but on your Apple-labeled computer. Please check with the Mac OS X license first."
835 printf "Copy? y[n] "
836 read CONT
837 if [ "$CONT" = "y" ]; then
838 ditto -v $1 ${MOUNT}/$1 #--rsrc --extattr
840 done
843 # FIXME IOKitUser built in 9J61 lacks of symbol as _kextmanager* needed by kextload..
844 # The one from 9F33pd1/IOKitUser.root.tar.gz is OK!
846 #if [ "$DARWIN_RELEASE" = "10" ]; then
847 # Disabled for obvious reasons.
848 # missingstuff /System/Library/Extensions/AppleACPIPlatform.kext
849 # missingstuff /System/Library/Extensions/IOSCSIArchitectureModelFamily.kext
850 # missingstuff /System/Library/Extensions/AppleRTC.kext
851 # missingstuff /System/Library/Extensions/IOATAFamily.kext
852 # missingstuff /System/Library/Extensions/IOPCIFamily.kext
856 # Add Chameleon themes (default: yes)
857 #if [ ! "$ADD_CHAMELEON_THEMES" = "n" ]; then
858 # FIXME populate Extra folder, and custom plist + adapt graphics resolution
859 # http://forum.voodooprojects.org/index.php/topic,388.0.html
862 # Voodoo kernel (xnu-dev) replacement (default: y)
863 if [ ! "$ADD_VOODOO_XNU" = "n" ]; then
865 # Sources: http://code.google.com/p/xnu-dev/
867 echo " * Voodoo_kernel.root.tar.bz2"
868 tar xjpf $PACKAGES/Voodoo_kernel.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
870 # Keeping the "vanilla" kernel
871 mv $MOUNT/mach_kernel $MOUNT/mach_kernel.origin
873 # mach_kernel.voodoo.9.5 (Voodoo 1.0 Rev A / xnu-dev) (default: y)
874 if [ ! "$ADD_VOODOO_XNU_9_5_0" = "n" ]; then
875 cp $MOUNT/mach_kernel.voodoo.9.5 $MOUNT/mach_kernel
878 # mach_kernel.voodoo.9.7 (Voodoo 2 -- alpha 3 -- (based on XNU 9.7.0, for Intel only) (default: n)
879 if [ "$ADD_VOODOO_XNU_9_7_0" = "y" ]; then
880 cp $MOUNT/mach_kernel.voodoo.9.7 $MOUNT/mach_kernel
884 # Xnu-speedstep support (default: n)
885 if [ "$ADD_VOODOO_XNU_SPEEDSTEP" = "y" ]; then
886 # "A kernel extension for OS X to enable Intel SpeedStep and undervolting on any kernel"
888 # Intel SpeedStep driver which extends the range of CPUs and motherboard support
889 # AppleIntelCPUPowerManagement kext
890 # http://code.google.com/p/xnu-speedstep
891 # v1.4.9
892 echo " * VoodooIntelEnhancedSpeedStep.root.tar.bz2"
893 tar xjpf $PACKAGES/VoodooIntelEnhancedSpeedStep.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
895 chown -R root:wheel ${MOUNT}/System/Library/Extensions/IntelEnhancedSpeedStep.kext
896 chmod -R 755 $MOUNT/System/Library/Extensions/IntelEnhancedSpeedStep.kext
898 # Which frequencies are available: sysctl kern.cputhrottle_freqs
899 # switch frequency : sudo sysctl -w kern.cputhrottle_curfreq=YYYY
902 # VoodooPowerMini Kext (v 1.2.4) support (default: n)
903 if [ "$ADD_VOODOO_POWER_MINI" = "y" ]; then
904 # "OSX Alternative Power Management"
906 # http://code.google.com/p/voodoo-power
907 # http://www.superhai.com/darwin.html
908 echo " * VoodooPowerMini.root.tar.bz2"
909 tar xjpf $PACKAGES/VoodooPowerMini.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
911 # FIXME add choice for:
912 #VoodooBattery.kext - To be used with vanilla ACPI and pm.bundle, 10.5.x
913 #VoodooPower Kext
914 #VoodooPower Command Line Interface Tool
915 #VoodooUSBEHCI for 10.5.x see readme!
919 # VoodooPS2Controller 0.98 support (default: y)
920 if [ ! "$ADD_VOODOO_PS2CONTROLLER" = "n" ]; then
921 # WARNING: conflict with ACPIPS2Nub!
923 # Contains:
924 # - VoodooPS2Controller
925 # - VoodooPS2Keyboard
926 # - VoodooPS2Mouse
927 # - VoodooPS2Trackpad
928 # c.f. Contents/Plugins/VoodooPS2Trackpad.kext/Info.plist
930 # FIXME synapticsconfigload <- needed? functional?
931 # FIXME in vmx? <- keyboard.vusb.enable = "FALSE"
932 echo " * VoodooPS2Controller.root.tar.bz2"
933 tar xjpf $PACKAGES/VoodooPS2Controller.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
936 # David Elliott PS2 support (default: n)
937 if [ "$ADD_DFE_PS2CONTROLLER" = "y" ]; then
938 # ACPIPS2Nub: PS2Controller for mouse matching a PNP device from David Elliott
939 # org.tgwbd.driver.ACPIPS2Nub
940 # version 1.0.0d1
941 echo " * ACPIPS2Nub.root.tar.bz2 (Copyright David Elliott, 2007)"
942 tar xjpf $PACKAGES/ACPIPS2Nub.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
944 echo " * ApplePS2Controller.root.tar.bz2"
945 tar xjpf $PACKAGES/ApplePS2Controller.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
948 # Prompt for VMware support (default: y)
949 if [ ! "$ADD_VMWARE" = "n" ]; then
950 # Fake easily guest OS detection (Mac OS X Server) in Fusion
951 # Template for a PureDarwin binary root:
952 # /System/Library/CoreServices/ServerVersion.plist
953 # /System/Library/CoreServices/SystemVersion.plist
954 # Info: http://code.google.com/p/puredarwin/issues/detail?id=3
956 # FIXME repack or at least move the archive elsewhere than in pd_setup_files
957 # LegacyAppleIntelPIIXATA and NullCPUPowerManagement KEXTs for use with VMware other than Fusion
958 echo " * VMware-Drivers-OpenSource.zip"
959 unzip -q $DIRNAME/pd_setup_files/VMware-Drivers-OpenSource.zip -d ${MOUNT}/System/Library/Extensions
961 # (default: n)
962 if [ "$ADD_X" = "y" ]; then
963 # Graphic drivers required for X display
964 echo " * VMwareIOFramebuffer.kext.zip"
965 unzip -q $DIRNAME/pd_setup_files/VMwareIOFramebuffer.kext.zip -d ${MOUNT}/System/Library/Extensions
969 # PureFoundation enhancements (default: y)
970 if [ ! "$ADD_PUREFOUNDATION" = "n" ]; then
971 #echo "Installing PureFoundation enhancements"
972 #rm -rf $MOUNT/System/Library/Frameworks/CoreFoundation.framework
973 # PureFoundation 0.003.1 (svn rev 30)
974 # SHA1 Checksum: b0bc7432627a060874f28f04297a80c4a5fbd094
975 # CoreFoundation and ddistnoted
976 # PureFoundation-0.003.1.root.zip
977 echo " * PureFoundation.root.tar.bz2 (Foundation, CoreFoundation and ddistnoted)"
978 tar xjpf $PACKAGES/PureFoundation.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
979 # WORKAROUND
980 # FIXME remove workaround
981 # Because otool -L /Volumes/PureDarwin/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
982 # /Volumes/PureDarwin/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation:
983 # /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 476.0.0)
984 # ---> /Users/stuart/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 300.0.0)
985 # /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 36.0.0)
986 mkdir -p "$MOUNT/Users/stuart/Library/Frameworks"
987 #chroot "$MOUNT" ln -fs /System/Library/Frameworks/Foundation.framework /Users/stuart/Library/Frameworks/Foundation.framework
988 ln -fs /System/Library/Frameworks/Foundation.framework "$MOUNT"/Users/stuart/Library/Frameworks/Foundation.framework
990 # ddistnoted content is provided in PureFoundation archive too
991 echo " * ddistnoted.root.tar.bz2"
992 tar xjpf $PACKAGES/ddistnoted.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
994 # Usefull for passwd (and dscl (and sudo?))
995 #rm -R ${MOUNT}/System/Library/PrivateFrameworks/OpenDirectory.framework/Versions/A/Frameworks
996 echo " * CFOpenDirectory.root.tar.bz2"
997 mkdir -p ${MOUNT}/System/Library/PrivateFrameworks/OpenDirectory.framework/Versions/A/Frameworks
998 tar xjpf $PACKAGES/CFOpenDirectory.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1000 # configd stuff for network support
1001 # Source: https://sites.google.com/a/puredarwin.org/puredarwin/developers/network
1002 # on Mar 7, 2009 8:25 PM by stuart@echus.demon.co.uk (version 3 / earlier versions)
1003 echo " * configd.root.tar.bz2"
1004 tar xjpf $PACKAGES/configd.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1006 # Satisfy dependencies for bootp (bootp popuplate /System/Library/SystemConfiguration with IPConf.. & co)
1007 # bootp is now added in pd_roots
1008 echo " * NotApple80211.root.tar.bz2"
1009 tar xjpf $PACKAGES/NotApple80211.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1011 # CFNetwork.framework and CarbonCore.framework (only headers) wrapped inside CoreServices.framework
1012 # Source: https://sites.google.com/a/puredarwin.org/puredarwin/developers/cfnetwork
1013 # on Feb 23, 2009 6:10 PM by stuart@echus.demon.co.uk (version 1)
1014 echo " * CFNetwork.root.tar.bz2 (wrapped in CoreServices.framework)"
1015 tar xjpf $PACKAGES/CFNetwork.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1017 # configd_plugins-91.root (partially built)
1019 # InterfaceNamer.bundle <- ?
1020 # KernelEventMonitor.bundle <- dhcp client (according to qemu user mode network stack
1021 # Kicker.bundle <- ???
1022 #cp -R /Users/aladin/PureDarwin/darwinbuild/9J61/.build/buildroot.nfs/private/var/tmp/configd_plugins/configd_plugins-91.root/System/Library/SystemConfiguration/KernelEventMonitor.bundle $MOUNT/System/Library/SystemConfiguration/
1023 echo " * configd_plugins.root.tar.bz2 (InterfaceNamer.bundle, KernelEventMonitor.bundle and Kicker.bundle)"
1024 tar xjpf $PACKAGES/configd_plugins.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1026 chown -R root:wheel $MOUNT/System/Library/LaunchDaemons/
1028 # FIXME ? + /Library/Preferences/SystemConfiguration/preferences.plist
1031 # User login support (default: y)
1032 if [ ! "$ADD_LOGIN" = "n" ]; then
1033 # multi-user - temporary workaround mode (small PAM module for session)
1035 # Source: https://sites.google.com/a/puredarwin.org/puredarwin/users/users
1036 # https://sites.google.com/a/puredarwin.org/puredarwin/downloads
1038 echo " * pam_sessioncreate.root.tar.bz2"
1039 tar xjpf $PACKAGES/pam_sessioncreate.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1040 # FIXME should it be integrated into "pam_modules" ?
1041 # FIXME + cat >${MOUNT}/etc/pam.d/login<<EOOF
1043 # PC/SC stack
1045 # Contain:
1046 # - System/Library/Frameworks/PCSC.framework
1047 # - usr/sbin/pcscd
1048 echo " * PCSC.root.tar.bz2"
1049 tar xjpf $PACKAGES/PCSC.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1052 # FIXME add MacPorts sources & bin? archive?
1054 # Add MacPorts tcl requirements (default: y)
1055 if [ ! "$ADD_MACPORTS_TCL" = "n" ]; then
1056 # Needed in order to be able to compile MacPorts and probably with it.
1057 echo " * tcl-8.5.6_0+threads.i386.tbz2"
1058 tar xjpf $DIRNAME/$BINARYROOTS_DEFAULT_DIR/mp/tcl-8.5.6_0+threads.i386.tbz2 >> ${MOUNT}/private/var/log/pd_setup.log
1061 # FIXME archive
1062 # Add X and co (default: no)
1063 if [ "$ADD_X" = "y" ]; then
1064 # Installing X binaryroots from macports (windowmaker, fluxbox, wmii, eterm, etc..)
1065 for f in `ls $DIRNAME/$BINARYROOTS_DEFAULT_DIR/X/*.tbz2` ; do
1066 echo " * $(basename $f)"
1067 tar xjpf $f >> ${MOUNT}/private/var/log/pd_setup.log
1068 done
1070 # Removing MacPorts archive "noise" (+COMMENT +CONTENTS +DESC +PORTFILE and +STATE in /)
1071 rm -f "${MOUNT}/+*"
1073 # Prevent error: "Fontconfig error: Cannot load default config file" which "cycles" X
1074 chroot ${MOUNT} /usr/X11R6/bin/fc-cache -v -f /usr/X11R6/lib/X11/fonts/
1077 # DTrace facility (default: n)
1079 # DTrace is not present on http://src.macosforge.org/Roots/
1080 # Notice Foundation.framework and CoreFoundation.framework dependencies
1082 # What about "Symbolication.framework"? (problem with 9J61 (not patched as 9F33pd1))
1084 if [ "$ADD_DTRACE" = "y" ]; then
1086 echo " * dtrace.root.tar.bz2"
1087 tar xjpf $PACKAGES/dtrace.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1089 #missingstuff /usr/sbin/dtrace
1090 #missingstuff /System/Library/PrivateFrameworks/Symbolication.framework
1091 #missingstuff /usr/lib/libdtrace.dylib
1092 #missingstuff /usr/bin/dtruss
1093 #missingstuff /usr/bin/procsystime
1096 # MacFUSE userland filesystem (default: n)
1097 if [ "$ADD_MACFUSE" = "y" ]; then
1099 # MacFUSE 2.0 - Version 2.0.3.2
1100 echo " * MacFUSE.root.tar.bz2"
1101 tar xjpf $PACKAGES/MacFUSE.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1103 chown -R root:wheel ${MOUNT}/Library/Filesystems/fusefs.fs
1104 chmod -R 755 ${MOUNT}/Library/Filesystems/fusefs.fs
1106 # FIXME TODO add binaryroots to uncomment below
1107 # sshfs in MacFUSE (default: n)
1108 # if [ "$ADD_MACFUSE_SSHFS" = "y" ]; then
1109 # echo " * MacFUSE_sshfs.root.tar.bz2"
1110 # curl "http://macfuse.googlecode.com/svn/trunk/filesystems/sshfs/binary/sshfs-static-leopard" > ${MOUNT}/usr/sbin/mount_sshfs
1111 # chmod a+x ${MOUNT}/usr/sbin/mount_sshfs
1112 # fi
1114 # ramdisk in MacFUSE (default: n)
1115 if [ "$ADD_MACFUSE_RAMDISK" = "y" ]; then
1116 echo " * MacFUSE_ramdisk.root.tar.bz2"
1117 tar xjpf $PACKAGES/MacFUSE_ramdisk.root.tar.bz2 >> ${MOUNT}/private/var/log/pd_setup.log
1123 cd - > /dev/null
1125 ###############################################################################
1126 # SELF DEPLOYMENT (bootstrap)
1127 ###############################################################################
1129 # Clone the setup scripts repository to the target? (default: n)
1130 if [ "$ADD_CLONE" = "y" ]; then
1131 echo "Copying setup files..."
1132 mkdir -p ${MOUNT}/usr/local/share/puredarwin/setup/$TEMPDIR
1133 # Warning: read `hg help clone' (e.g. incompatible with mq)
1134 # -l not supported on Darwin and Mac OS X
1135 # -a not supported on Darwin..
1136 #cp -Rfp $DIRNAME/.. ${MOUNT}/usr/local/share/puredarwin
1137 cp -Rfp $DIRNAME/../APPLE_DRIVER_LICENSE.txt ${MOUNT}/usr/local/share/puredarwin/
1138 cp -Rfp $DIRNAME/../APPLE_LICENSE.txt ${MOUNT}/usr/local/share/puredarwin/
1139 cp -Rfp $DIRNAME/../PUREDARWIN_LICENSE.txt ${MOUNT}/usr/local/share/puredarwin/
1140 cp -Rfp $DIRNAME/../WELCOME ${MOUNT}/usr/local/share/puredarwin/
1141 cp -Rfp $DIRNAME/../patches ${MOUNT}/usr/local/share/puredarwin/
1142 cp -Rfp $DIRNAME/../plists ${MOUNT}/usr/local/share/puredarwin/
1143 cp -Rfp $DIRNAME/../projects ${MOUNT}/usr/local/share/puredarwin/
1144 cp -Rfp $DIRNAME/../scripts ${MOUNT}/usr/local/share/puredarwin/
1146 cp -fp $DIRNAME/../setup/* ${MOUNT}/usr/local/share/puredarwin/setup/ 2> /dev/null
1148 # c.f. pd_config: DESTDIR="$TEMPDIR/Packages_D${DARWIN_RELEASE}_${ARCH}"
1149 cp -Rfp $DIRNAME/../setup/pd_setup_files ${MOUNT}/usr/local/share/puredarwin/setup/
1151 # FIXME below should disappear (with deps)
1152 # An arbitrary mountpoint potentially usefull on read-only mode
1153 mkdir -p ${MOUNT}/Volumes/PureDarwin
1154 # Idem
1155 mkdir -p ${MOUNT}/tmp/i386
1159 # Add setup binaryroots to the target? (default: n)
1160 if [ "$ADD_CLONE_PACKAGES" = "y" ]; then
1162 # e.g., DESTDIR="Packages_D9_i386" and TEMPDIR="pd_tmp"
1163 cp -Rfp $DIRNAME/../setup/$DESTDIR ${MOUNT}/usr/local/share/puredarwin/setup/$TEMPDIR/
1165 # Specific for X roots
1166 mkdir -p ${MOUNT}/usr/local/share/puredarwin/setup/$BINARYROOTS_DEFAULT_DIR
1167 cp -Rfp $DIRNAME/../setup/$BINARYROOTS_DEFAULT_DIR/mp ${MOUNT}/usr/local/share/puredarwin/setup/$BINARYROOTS_DEFAULT_DIR/
1168 cp -Rfp $DIRNAME/../setup/$BINARYROOTS_DEFAULT_DIR/X ${MOUNT}/usr/local/share/puredarwin/setup/$BINARYROOTS_DEFAULT_DIR/
1170 cp -Rfp $DIRNAME/../setup/$DESTDIR ${MOUNT}/usr/local/share/puredarwin/setup/$TEMPDIR/
1172 # Alternative if a mercurial binary root is available (including its dependencies..)
1173 #hg clone $DIRNAME/.. ${MOUNT}/usr/local/share/puredarwin
1174 # Can take a lot of disk space
1175 #hg clone $DIRNAME/$TEMPDIR ${MOUNT}/usr/local/share/puredarwin/$TEMPDIR
1178 ###############################################################################
1179 # SETTING FILES DEPLOYMENT
1180 ###############################################################################
1182 echo "Copying settings files..."
1183 # default: y
1184 if [ "$ADD_SETTINGS_FILES" = "n" ]; then
1185 # FIXME not sure we need all of them for nano
1186 mkdir -p ${MOUNT}/Library/Preferences/SystemConfiguration/
1187 cp -fp $DIRNAME/../projects/PureDarwinSettings/Library/Preferences/SystemConfiguration/com.apple.Boot.plist ${MOUNT}/Library/Preferences/SystemConfiguration/com.apple.Boot.plist
1189 mkdir -p ${MOUNT}/System/Library/LaunchDaemons/
1190 cp -fp $DIRNAME/../projects/PureDarwinSettings/System/Library/LaunchDaemons/com.apple.getty.plist ${MOUNT}/System/Library/LaunchDaemons/com.apple.getty.plist
1191 cp -fp $DIRNAME/../projects/PureDarwinSettings/System/Library/LaunchDaemons/org.puredarwin.nanoshell.plist ${MOUNT}/System/Library/LaunchDaemons/org.puredarwin.nanoshell.plist
1192 cp -fp $DIRNAME/../projects/PureDarwinSettings/System/Library/LaunchDaemons/org.puredarwin.installer.plist ${MOUNT}/System/Library/LaunchDaemons/org.puredarwin.installer.plist
1194 mkdir -p ${MOUNT}/etc/
1195 cp -fp $DIRNAME/../projects/PureDarwinSettings/etc/ttys ${MOUNT}/etc/ttys
1196 cp -fp $DIRNAME/../projects/PureDarwinSettings/etc/zshrc ${MOUNT}/etc/zshrc
1197 cp -fp $DIRNAME/../projects/PureDarwinSettings/etc/bashrc ${MOUNT}/etc/bashrc
1199 mkdir -p ${MOUNT}/System/Library/CoreServices/
1200 touch ${MOUNT}/System/Library/CoreServices/ServerVersion.plist
1202 mkdir -p ${MOUNT}/var/db/dslocal/nodes/Default/users
1203 cp -fp $DIRNAME/../projects/PureDarwinSettings/var/db/dslocal/nodes/Default/users/root.plist ${MOUNT}/var/db/dslocal/nodes/Default/users/root.plist
1205 # APPLE_DRIVER_LICENSE.txt, APPLE_LICENSE.txt and PUREDARWIN_LICENSE.txt
1206 # FIXME how to handle that correctly?
1207 cp -fp $DIRNAME/../projects/PureDarwinSettings/*LICENSE.txt ${MOUNT}/
1208 else
1209 # Copying all settings files
1210 cp -fpR $DIRNAME/../projects/PureDarwinSettings/* ${MOUNT}/
1213 ###############################################################################
1214 # EFI BOOTLOADER
1215 ###############################################################################
1217 # Copy bootloader files for bless (usefull for pd_make_dmg)
1218 mkdir -p $MOUNT/usr/standalone/i386/
1219 cp $BOOTi386/* $MOUNT/usr/standalone/i386/
1221 if [ ! -e "$MOUNT/System/Library/CoreServices" ]; then
1222 echo "WARNING! $MOUNT/System/Library/CoreServices is missing, but it is needed for EFI booting."
1223 #exit 1
1226 if [ ! -e "$MOUNT/usr/standalone/i386/cdboot" ]; then
1227 echo "WARNING! $MOUNT/usr/standalone/i386/cdboot is missing, but it is needed for BIOS booting."
1228 #exit 1
1231 #${MOUNT}/usr/sbin/bless -verbose -folder "$MOUNT/System/Library/CoreServices" -bootinfo -bootefi
1232 # --folder Set this directory to be the Mac OS X/Darwin blessed directory, containing a BootX secondary loader for New World machines
1233 # --bootinfo Create a BootX file in the Darwin system folder using file as a source.
1234 # If file is not provided, a default is used (see FILES), using a path relative
1235 # to the mountpoint you are blessing.
1236 # This attempts to ensure that a BootX is used that is compatible with the OS on the target volume.
1237 # --bootefi Create a boot.efi file in the Mac OS X/Darwin system folder using file as a source
1238 # [...]
1239 # FIXME use grub2
1240 echo "Blessing $MOUNT/System/Library/CoreServices"
1241 ${MOUNT}/usr/sbin/bless --folder "$MOUNT/System/Library/CoreServices" --bootinfo --bootefi --verbose
1242 #${MOUNT}/usr/sbin/bless --folder "$MOUNT/System/Library/CoreServices" --bootefi --verbose
1245 # Use a little resolution (default: n)
1246 # TODO alter com.apple.Boot.plist
1247 if [ "$ADD_FB_640x480x32" = "y" ]; then
1248 GRAPHICS_MODE="\"Graphics Mode\"=\"640x480x32\""
1251 # Use a medium resolution (default: y)
1252 # TODO alter com.apple.Boot.plist
1253 if [ ! "$ADD_FB_800x600x32" = "n" ]; then
1254 GRAPHICS_MODE="\"Graphics Mode\"=\"800x600x32\""
1257 # Use a normal resolution (default: n)
1258 # TODO alter com.apple.Boot.plist
1259 if [ "$ADD_FB_1024x768x32" = "y" ]; then
1260 GRAPHICS_MODE="\"Graphics Mode\"=\"1024x768x32\""
1263 ###############################################################################
1264 # TIMEZONE
1265 ###############################################################################
1267 # FIXME which one as default?
1268 # Setting GMT+1 timezone (instead of Pacific)
1269 rm -f ${MOUNT}/private/etc/localtime
1270 #chroot ${MOUNT} ln -s /usr/share/zoneinfo/Europe/Berlin /private/etc/localtime
1271 # [...]
1272 #chroot ${MOUNT} ln -s /usr/share/zoneinfo/Europe/London /private/etc/localtime
1273 # [...]
1274 ln -fs /usr/share/zoneinfo/Europe/Paris "${MOUNT}"/private/etc/localtime
1276 # Preparing /etc/hostconfig (deprecated?)
1277 echo "CRASHREPORTER=-NO-" >> $MOUNT/private/etc/hostconfig
1279 # Encrypting swap by default
1280 # FIXME: it seems dynamic_pager lacks -E even with ENCRYPTSWAP=-YES
1281 echo "ENCRYPTSWAP=-YES-" >> $MOUNT/private/etc/hostconfig
1283 ###############################################################################
1284 # SYSCTL
1285 ###############################################################################
1287 # Setting hostname
1288 echo "kern.hostname=PureDarwin.local" > $MOUNT/private/etc/sysctl.conf
1290 ###############################################################################
1291 # LOGIN PROMPT
1292 ###############################################################################
1294 # Message Of The Day
1295 echo "Welcome to PureDarwin!" > $MOUNT/private/etc/motd
1296 echo '' >> ${MOUNT}/private/etc/motd
1298 ###############################################################################
1299 # SHELLS
1300 ###############################################################################
1302 # dyld errors
1304 # com.apple.dyld[76]: update_dyld_shared_cache[76] for arch=i386 failed: /var/db/dyld/shared_region_roots/ does not exist, errno=2
1305 mkdir -p ${MOUNT}/var/db/dyld/shared_region_roots
1306 # com.apple.dyld[50]: update_dyld_shared_cache: warning, no entries found in shared_region_roots
1307 echo "/bin/sh" > ${MOUNT}/var/db/dyld/shared_region_roots/Applications.paths
1309 # Add the Bash shell as default shell? (default: y)
1310 if [ ! "$ADD_BASH" = "n" ]; then
1311 ln -fs /bin/bash "${MOUNT}"/bin/sh
1312 echo "/bin/bash" >> ${MOUNT}/var/db/dyld/shared_region_roots/Applications.paths
1316 # Populate (or remove) /etc/bashrc (default: y)
1317 if [ "$ADD_BASHRC" = "n" ]; then
1318 rm -f ${MOUNT}/etc/bashrc
1321 # Add the Z shell as default shell? (default: n)
1322 if [ "$ADD_ZSH" = "y" ]; then
1323 ln -fs /bin/zsh "${MOUNT}"/bin/sh
1324 echo "/bin/zsh" >> ${MOUNT}/var/db/dyld/shared_region_roots/Applications.paths
1327 # Populate (or remove) /etc/zshrc (default: y)
1328 if [ "$ADD_ZSHRC" = "n" ]; then
1329 rm -f ${MOUNT}/etc/zshrc
1332 ###############################################################################
1333 # MINOR ERRORS FIXES
1334 ###############################################################################
1336 echo "Fixing minor errors"
1338 # Avoid orphan link of /etc/resolv.conf
1339 touch ${MOUNT}/private/var/run/resolv.conf
1341 # com.apple.dyld[50]: update_dyld_shared_cache: warning, empty cache not generated for arch i386
1342 # -root specifies the root of an OS installation for which dyld's shared cache should be updated
1343 # -arch generates cache files for the specified one (i386)
1344 # -force regenerated the shared cache files even if they appear to be already up-to-date
1346 # FIXME warning, could not bind /Volumes/PD/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation...
1347 # ...because realpath() failed on /Volumes/PD/Users/stuart/Library/Frameworks/Foundation.framework/Versions/C/Foundation
1349 # FIXME ./pd_setup: line 1138: /Volumes/bootstrap: is a directory
1351 #if [ "$DARWIN_RELEASE" = "9" ]; then
1352 #${MOUNT} update_prebinding -root ${MOUNT} -arch i386 -force # Available in Leopard
1353 #${MOUNT} update_prebinding -root ${MOUNT} -arch i386 -force -debug
1354 #else
1355 #${MOUNT} update_dyld_shared_cache -root ${MOUNT} -arch i386 -force # Available in SnowLeopard
1358 # com.apple.launchd[1] (org.ntp.ntpd): Unknown key: SHAuthorizationRight
1360 # A project at Apple is overloading the launchd configuration file
1361 # schema to store non-launchd preferences. We hope to resolve this
1362 # matter in the next major version of Mac OS X.
1364 # Key (temporary) disabled to keep "Pure" log.
1366 # cat >${MOUNT}/System/Library/LaunchDaemons/org.ntp.ntpd.plist<<EOOF
1368 # Problem: _CFGetHostUUIDString: unable to determine UUID for host. Error: 35
1369 # Solution: A MAC address from an attached network interface should do the trick too.
1370 # Pseudo-solution: Adding AppleEFINVRAM (CREDITS: XSource) via:
1371 #missingstuff /System/Library/Extensions/AppleEFIRuntime.kext
1373 ################################################################################
1374 # DEBUG
1375 ################################################################################
1377 # Crank up the debug logging on launchd (default: yes). Credit: kvv for the tips.
1378 if [ ! "$ADD_DEBUG" = "n" ]; then
1379 echo "log level debug" > ${MOUNT}/etc/launchd.conf
1380 echo "*.debug /var/log/syslog" >> ${MOUNT}/etc/syslog.conf
1383 ###############################################################################
1384 # COPYING UTILS, FUTILS AND INUTILS!
1385 ###############################################################################
1387 mkdir -p ${MOUNT}/usr/local/sbin/
1388 mkdir -p ${MOUNT}/usr/local/share/puredarwin/scripts
1389 mkdir -p ${MOUNT}/usr/local/share/puredarwin/setup/pd_setup_files/
1392 # Copy startupfiletool
1393 echo "Copying startupfiletool"
1394 cp $DIRNAME/pd_setup_files/startupfiletool ${MOUNT}/usr/local/share/puredarwin/setup/pd_setup_files/
1396 # Copy PureDarwin scripts
1397 echo "Copying PureDarwin scripts"
1398 cp $DIRNAME/../scripts/pd_* ${MOUNT}/usr/local/share/puredarwin/scripts/
1400 # Moar futils
1401 #cp $DIRNAME/../projects/pd_xkp/pd_xkp ${MOUNT}/usr/local/sbin/
1403 ###############################################################################
1404 # USER MANAGEMENT
1405 ###############################################################################
1407 # multi-user - temporary workaround mode (securityd in single thread mode (it works with some threads))
1409 # Source : https://sites.google.com/a/puredarwin.org/puredarwin/users/users
1411 # + cat >${MOUNT}/System/Library/LaunchDaemons/com.apple.securityd.plist<<EOOF
1413 # Root account (disabled)
1415 # Enabling root is dangerous and not recommended,
1416 # we do not provide root password! `sudo' should be for
1417 # priviledge elevation purpose.
1419 mkdir -p ${MOUNT}/var/db/dslocal/nodes/Default/users
1420 # + cat >${MOUNT}/var/db/dslocal/nodes/Default/users/root.plist<<EOOF
1422 # Creating default user account (default: y)
1423 # username: toor
1424 # password: toor
1426 if [ ! "$ADD_DEFAULT_USER" = "n" ]; then
1427 echo "Creating default user (toor:toor)"
1428 # pd_injectuser (salter SHA-1 digest by default, should work into single user mode)
1429 # FIXME update pd_adduser..
1430 chroot $MOUNT /usr/local/share/puredarwin/scripts/pd_injectuser / toor
1431 # pd_adduser must be run on Darwin/Mac OS X host, or in single user mode from PureDarwin
1432 # Note: `dscl' and `passwd' dependencies must be satistified.
1433 # $DIRNAME/../scripts/pd_adduser
1436 ###############################################################################
1437 # X11
1438 ###############################################################################
1440 # Add X and co (default: no)
1441 if [ "$ADD_X" = "y" ]; then
1442 # Default keymapping
1443 cp $MOUNT/System/Library/Keyboards/USA.keymapping $MOUNT/System/Library/Keyboards/USA.keymapping.orig
1444 rm -f $MOUNT/System/Library/Keyboards/USA.keymapping
1446 # Belge keymapping (default: n)
1447 if [ "$ADD_KEYMAP_BELGE" = "y" ]; then
1448 ln -fs /System/Library/Keyboards/Belge.keymapping "${MOUNT}"/System/Library/Keyboards/USA.keymapping
1450 # Deutsch keymapping (default: n)
1451 if [ "$ADD_KEYMAP_DEUTSCH" = "y" ]; then
1452 ln -fs /System/Library/Keyboards/Deutsch.keymapping "${MOUNT}"/System/Library/Keyboards/USA.keymapping
1454 # Francais keymapping (default: n)
1455 if [ "$ADD_KEYMAP_FRANCAIS" = "y" ]; then
1456 ln -fs /System/Library/Keyboards/Francais.keymapping "${MOUNT}"/System/Library/Keyboards/USA.keymapping
1458 # UK keymapping (default: n)
1459 if [ "$ADD_KEYMAP_UK" = "y" ]; then
1460 ln -fs /System/Library/Keyboards/UK.keymapping "${MOUNT}"/System/Library/Keyboards/USA.keymapping
1462 # USA keymapping (default: y)
1463 if [ ! "$ADD_KEYMAP_USA" = "n" ]; then
1464 mv $MOUNT/System/Library/Keyboards/USA.keymapping.orig $MOUNT/System/Library/Keyboards/USA.keymapping
1468 ###############################################################################
1469 # X11 WMs
1470 ###############################################################################
1472 # WindowMaker (default: n)
1473 if [ "$ADD_WMAKER" = "y" ]; then
1474 chroot ${MOUNT} /opt/local/bin/wmaker.inst
1475 cp $DIRNAME/pd_setup_files/*png $MOUNT/var/root/GNUstep/Library/WindowMaker/Backgrounds
1478 #echo " 0 - WindowMaker 0.92"
1479 #echo " 1 - Fluxbox 1.1.0.1_0"
1480 #echo " 2 - wmii-3.1_0"
1482 ###############################################################################
1483 # NANO LAUNCHD, DAEMONS AND PLISTS
1484 ###############################################################################
1486 # Add launchd (default: yes)
1487 if [ "$ADD_LAUNCHD" = "n" ]; then
1488 # Overwrite /sbin/launchd with a trivial shell script
1489 mkdir -p ${MOUNT}/sbin/
1490 cp $DIRNAME/../scripts/pd_nanoshell ${MOUNT}/sbin/launchd
1491 chown root:wheel ${MOUNT}/sbin/launchd
1492 chmod 755 ${MOUNT}/sbin/launchd
1493 else
1495 # Add default login prompt (default: yes)
1496 if [ "$ADD_LAUNCHD_GETTY" = "n" ]; then
1497 # Disable login prompt
1498 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.getty.plist
1501 # Add mDNSResponder (default: yes)
1502 if [ "$ADD_LAUNCHD_MDNSRESPONDER" = "n" ]; then
1503 # Disable mDNSResponder
1504 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
1505 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.mDNSResponderHelper.plist
1508 # Add portmap (default: yes)
1509 if [ "$ADD_LAUNCHD_PORTMAP" = "n" ]; then
1510 # Disable portmap
1511 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.portmap.plist
1513 # Add statd (default: yes)
1514 if [ "$ADD_LAUNCHD_STATD" = "n" ]; then
1515 # Disable statd
1516 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.statd.notify.plist
1519 # Add a synthetic custom "shell" launched by launchd (default: no)
1520 if [ "$ADD_LAUNCHD_NANOSHELL" = "y" ]; then
1521 # A launchd plist (org.puredarwin.nanoshell.plist) run a synthetic custom "shell" (pd_nanoshell)
1522 chmod 644 ${MOUNT}/System/Library/LaunchDaemons/org.puredarwin.nanoshell.plist
1523 chmod +x ${MOUNT}/usr/local/share/puredarwin/scripts/pd_nanoshell
1524 else
1525 # Disable launchd plist to run a synthetic custom "shell" (pd_nanoshell)
1526 rm -f ${MOUNT}/System/Library/LaunchDaemons/org.puredarwin.nanoshell.plist
1529 # Add a tiny installer script launched by launchd (default: no)
1530 if [ "$ADD_LAUNCHD_INSTALLER" = "y" ]; then
1531 # A launchd plist (org.puredarwin.installer.plist) run a CLI installer (pd_installer)
1532 chmod 644 ${MOUNT}/System/Library/LaunchDaemons/org.puredarwin.installer.plist
1533 chmod +x ${MOUNT}/usr/local/share/puredarwin/scripts/pd_installer
1535 # not needed in this scenario..
1536 rm -f \
1537 ${MOUNT}/System/Library/LaunchDaemons/com.apple.SystemStarter.plist \
1538 ${MOUNT}/System/Library/LaunchDaemons/com.apple.atrun.plist \
1539 ${MOUNT}/System/Library/LaunchDaemons/com.apple.bootlog.plist \
1540 ${MOUNT}/System/Library/LaunchDaemons/com.apple.bsd.dirhelper.plist \
1541 ${MOUNT}/System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist \
1542 ${MOUNT}/System/Library/LaunchDaemons/com.apple.dyld.plist \
1543 ${MOUNT}/System/Library/LaunchDaemons/com.apple.dynamic_pager.plist \
1544 ${MOUNT}/System/Library/LaunchDaemons/com.apple.firmwaresyncd.plist \
1545 ${MOUNT}/System/Library/LaunchDaemons/com.apple.hidd.plist\
1546 ${MOUNT}/System/Library/LaunchDaemons/com.apple.kextd.plist \
1547 ${MOUNT}/System/Library/LaunchDaemons/com.apple.update.plist\
1548 ${MOUNT}/System/Library/LaunchDaemons/finger.plist \
1549 ${MOUNT}/System/Library/LaunchDaemons/org.puredarwin.ddistnoted.plist
1550 else
1551 # Disable launchd plist to run a synthetic custom "shell" (pd_installer)
1552 rm -f ${MOUNT}/System/Library/LaunchDaemons/org.puredarwin.installer.plist
1556 # (default: no)
1557 if [ "$ADD_RELEASE_NANO" = "y" ]; then
1558 #FIXME: below seems needed for network support!
1559 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.DirectoryServices.plist
1560 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.DirectoryServicesLocal.plist
1561 rm -f ${MOUNT}/System/Library/LaunchDaemons/com.apple.DirectoryServicesInstallDaemon.plist
1565 ###############################################################################
1566 # REDUCING TARGET DISK SIZE
1567 ###############################################################################
1570 # Keep developer stuff (default: y)
1571 if [ "$ADD_DEVELOPER" = "n" ]; then
1572 echo "Cleaning up unneeded developer files from ${MOUNT}..."
1573 rm -rf ${MOUNT}/Developer # saves little (fixme, only if "Developer" has not been selected)
1574 rm -rf ${MOUNT}/usr/include/ # saves > 150 MB (fixme, only if "Developer" has not been selected)
1575 # find ${MOUNT}/ -type f | grep "\.h$" | xargs -I {} rm -f {} # more header files (fixme, only if "Developer" has not been selected)
1576 rm -rf ${MOUNT}/AppleInternal/ # (fixme, only if "Developer" has not been selected)
1577 #rm -rf ${MOUNT}/usr/lib/libSystem.B_debug.dylib # saves ~14M
1578 #rm -rf ${MOUNT}/usr/lib/libSystem.B_profile.dylib # saves ~11M
1579 find ${MOUNT} -name '.svn' | xargs rm -R
1580 #else
1582 # Macports sources
1583 # http://guide.macports.org/#installing.macports.subversion
1585 #svn co http://svn.macports.org/repository/macports/trunk/base
1587 # Libdispatch sources
1588 # http://svn.macosforge.org/repository/libdispatch/trunk/INSTALL
1590 #svn checkout http://svn.macosforge.org/repository/libdispatch/trunk
1593 ###############################################################################
1594 # PERMISSIONS
1595 ###############################################################################
1597 echo "Fixing permissions"
1598 chown root:wheel ${MOUNT}/sbin
1599 chown root:wheel ${MOUNT}/mach_kernel
1600 chown -R root:wheel ${MOUNT}/System/Library/Extensions/
1601 chmod -R 0644 $MOUNT/System/Library/Extensions/
1602 chown -R root:wheel $MOUNT/var/empty # for sshd
1604 # ZFS is disabled since MacOSForge also dropped it.
1606 # zfs perms according to http://zfs.macosforge.org/trac/wiki/downloads
1607 #chown -R root:wheel /System/Library/Extensions/zfs.kext
1608 #chown -R root:wheel /System/Library/Filesystems/zfs.fs
1609 #chown -R root:wheel /usr/sbin/zpool
1610 #chown -R root:wheel /usr/sbin/zfs
1611 #chown -R root:wheel /usr/lib/libzfs.dylib
1613 ###############################################################################
1614 # CACHE AND EXTENTIONS.MKEXT
1615 ###############################################################################
1617 echo "Set Extensions.mkext invocation"
1618 touch $MOUNT/System/Library/Extensions
1620 # Add creation of kext cache file (default: y)
1621 if [ ! "$ADD_KEXTCACHE" = "n" ]; then
1622 mkdir -p $MOUNT/System/Library/Caches/com.apple.kernelcaches
1623 kextcache -a $ARCH -s -l -n -c "$MOUNT/System/Library/Caches/com.apple.kernelcaches/kernelcache.DEADBEEF" -k -K "$MOUNT/mach_kernel" -m "$MOUNT/System/Library/Extensions.mkext" "$MOUNT/System/Library/Extensions"
1624 # ...leads to:
1625 # Can't resolve dependencies amongst kexts for prelinked kernel.
1626 # Failed to generate prelinked kernel.
1630 # Force completion of pending disk writes
1631 /bin/sync
1633 ###############################################################################
1634 # ISO / VMWAREVM / VMDK / DMG / etc..
1635 ###############################################################################
1637 # Detect image extension (iso|vmwarevm|vmdk|dmg|*) and act in consequences
1638 if [ ! $EXT = "" ]; then
1640 # Some .vmx variables
1641 if [ "$DARWIN_RELEASE" = "10" ]; then
1642 T_GUESTOS="darwin10"; # Darwin 10
1643 else
1644 T_GUESTOS="darwin" # Darwin 9 and prior
1647 T_TARGET_EXT=$(basename $TARGET | awk -F '.' '{print $NF}')
1648 case $T_TARGET_EXT in
1650 ###############################################################
1651 # ISO 9660 CD-ROM filesystem (.iso)
1652 ###############################################################
1653 iso)
1654 T_TARGET=$(dirname $TARGET)/$(basename $TARGET | awk -F '.' '{print $1".iso"}')
1657 ###############################################################
1658 # VMware virtual disk (.vmdk)
1659 ###############################################################
1660 vmdk)
1661 T_TARGET=$(dirname $TARGET)/$(basename $TARGET | awk -F '.' '{print $1".iso"}')
1662 # Forced converting iso to VMware vmdk
1663 echo "Converting image to VMware VMDK disk image, please wait..."
1664 $QEMUIMG_BIN convert -O vmdk $T_TARGET $(dirname $TARGET)/$(basename $TARGET | awk -F '.' '{print $1".vmdk"}')
1667 ###############################################################
1668 # VMware virtual machine package (.vmwarevm)
1669 ###############################################################
1670 vmwarevm)
1671 T_TARGET="$(basename $TARGET | awk -F '.' '{print $1".iso"}')"
1672 # Moving the .vmwarevm file to .iso
1673 mv "$TARGET" "$T_TARGET"
1674 # Creating the .vmwarevm directory
1675 mkdir -p "$TARGET"
1676 # Moving the .iso file to the .vmwarevm directory
1677 mv "$T_TARGET" "$TARGET/$T_TARGET"
1679 cat > $TARGET/$(basename $TARGET | awk -F '.' '{print $1".vmx"}') <<EOOF
1680 .encoding = "UTF-8"
1681 bios.bootDelay = "5000"
1682 config.version = "8"
1683 displayName = "`/bin/date +"%y%m%d%H%M "`${DARWIN_RELEASE} / ${ARCH} / $PUREDARWIN_RELEASE"
1684 ehci.present = "TRUE"
1685 ethernet0.linkStatePropagation.enable = "FALSE"
1686 ethernet0.present = "TRUE"
1687 ethernet0.virtualDev = "e1000"
1688 ethernet0.wakeOnPcktRcv = "FALSE"
1689 floppy0.present = "FALSE"
1690 ft.secondary0.enabled = "TRUE"
1691 guestOS = "$T_GUESTOS"
1692 ich7m.present = "TRUE"
1693 ide0:0.deviceType = "cdrom-image"
1694 ide0:0.fileName = "`basename $T_TARGET`"
1695 ide0:0.present = "TRUE"
1696 keyboardAndMouseProfile = "macProfile"
1697 memsize = "128"
1698 nvram = "$VOLNAME.nvram"
1699 pciBridge0.present = "TRUE"
1700 pciBridge4.functions = "8"
1701 pciBridge4.present = "TRUE"
1702 pciBridge4.virtualDev = "pcieRootPort"
1703 pciBridge5.functions = "8"
1704 pciBridge5.present = "TRUE"
1705 pciBridge5.virtualDev = "pcieRootPort"
1706 pciBridge6.functions = "8"
1707 pciBridge6.present = "TRUE"
1708 pciBridge6.virtualDev = "pcieRootPort"
1709 pciBridge7.functions = "8"
1710 pciBridge7.present = "TRUE"
1711 pciBridge7.virtualDev = "pcieRootPort"
1712 powerType.powerOff = "soft"
1713 powerType.powerOn = "soft"
1714 powerType.reset = "soft"
1715 powerType.suspend = "soft"
1716 printers.enabled = "FALSE"
1717 roamingVM.exitBehavior = "go"
1718 scsi0.present = "TRUE"
1719 scsi0.virtualDev = "lsilogic"
1720 scsi0:0.fileName = ""
1721 scsi0:0.present = "FALSE"
1722 serial0.fileType = "thinprint"
1723 serial0.present = "FALSE"
1724 smc.present = "TRUE"
1725 tools.syncTime = "TRUE"
1726 tools.upgrade.policy = "upgradeAtPowerCycle"
1727 usb.present = "TRUE"
1728 virtualHW.productCompatibility = "hosted"
1729 virtualHW.version = "7"
1730 vmci0.present = "TRUE"
1731 EOOF
1733 #Convert to VMware VMDK disk image for read-write support? (default: y)
1734 if [ ! "$ADD_VMWARE_VMDK" = "n" ]; then
1735 # Converting iso to VMware vmdk
1736 echo "Converting image to VMware VMDK disk image, please wait..."
1737 $QEMUIMG_BIN convert -O vmdk $TARGET/$T_TARGET $TARGET/$(basename $TARGET | awk -F '.' '{print $1".vmdk"}')
1739 cat > $TARGET/$(basename $TARGET | awk -F '.' '{print $1".vmx"}') <<EOOF
1740 .encoding = "UTF-8"
1741 bios.bootDelay = "5000"
1742 config.version = "8"
1743 displayName = "`/bin/date +"%y%m%d%H%M "`${DARWIN_RELEASE} / ${ARCH} / $PUREDARWIN_RELEASE"
1744 ehci.present = "TRUE"
1745 ethernet0.linkStatePropagation.enable = "FALSE"
1746 ethernet0.present = "TRUE"
1747 ethernet0.virtualDev = "e1000"
1748 ethernet0.wakeOnPcktRcv = "FALSE"
1749 floppy0.present = "FALSE"
1750 ft.secondary0.enabled = "TRUE"
1751 guestOS = "$T_GUESTOS"
1752 ich7m.present = "TRUE"
1753 ide0:0.fileName = "$(basename $T_TARGET | awk -F '.' '{print $1".vmdk"}')"
1754 ide0:0.present = "TRUE"
1755 ide0:0.redo = ""
1756 ide1:0.autodetect = "TRUE"
1757 ide1:0.deviceType = "cdrom-image"
1758 ide1:0.fileName = "`basename $T_TARGET`"
1759 ide1:0.present = "TRUE"
1760 keyboardAndMouseProfile = "macProfile"
1761 memsize = "128"
1762 nvram = "$VOLNAME.nvram"
1763 pciBridge0.present = "TRUE"
1764 pciBridge4.functions = "8"
1765 pciBridge4.present = "TRUE"
1766 pciBridge4.virtualDev = "pcieRootPort"
1767 pciBridge5.functions = "8"
1768 pciBridge5.present = "TRUE"
1769 pciBridge5.virtualDev = "pcieRootPort"
1770 pciBridge6.functions = "8"
1771 pciBridge6.present = "TRUE"
1772 pciBridge6.virtualDev = "pcieRootPort"
1773 pciBridge7.functions = "8"
1774 pciBridge7.present = "TRUE"
1775 pciBridge7.virtualDev = "pcieRootPort"
1776 powerType.powerOff = "soft"
1777 powerType.powerOn = "soft"
1778 powerType.reset = "soft"
1779 powerType.suspend = "soft"
1780 printers.enabled = "FALSE"
1781 roamingVM.exitBehavior = "go"
1782 scsi0.present = "TRUE"
1783 scsi0.virtualDev = "lsilogic"
1784 scsi0:0.fileName = ""
1785 scsi0:0.present = "FALSE"
1786 serial0.fileType = "thinprint"
1787 serial0.present = "FALSE"
1788 smc.present = "TRUE"
1789 tools.syncTime = "TRUE"
1790 tools.upgrade.policy = "upgradeAtPowerCycle"
1791 usb.generic.autoconnect = "FALSE"
1792 usb.present = "TRUE"
1793 virtualHW.productCompatibility = "hosted"
1794 virtualHW.version = "7"
1795 vmci0.present = "TRUE"
1796 EOOF
1801 # Add an (additional) IDE disk device to the .vmwarevm? (default: n)
1802 if [ "$ADD_VMWARE_IDE_DRIVE" = "y" ]; then
1803 # Creating a (second) VMware4 disk image via qemu-img
1804 # SIZE at least equal to "the parent" one (most of the time, the bootstrap one)
1805 # FIXME add check on the size
1806 qemu-img create -f vmdk $TARGET/second.vmdk 2048M
1808 # Reflect the disk image in the .vmx file
1809 cat >> $TARGET/$(basename $TARGET | awk -F '.' '{print $1".vmx"}') <<EOOF
1810 ide0:1.present = "TRUE"
1811 ide0:1.fileName = "second.vmdk"
1812 ide0:1.redo = ""
1813 EOOF
1818 ###############################################################
1819 # VAX COFF executable (.dmg)
1820 ###############################################################
1821 dmg)
1824 ###############################################################
1825 # Default (.*)
1826 ###############################################################
1829 esac
1831 # FIXME too permissive
1832 # Since the installation is done at root over a normal user,
1833 # in finder the image is open in read-only after clickclick.. owner/perms
1834 # need to be changed for rw (or the image needs to be mount as root)
1835 chmod -R 777 $TARGET
1836 chown -R 501:staff $TARGET
1838 echo "Installation on ${TARGET} complete."
1839 else
1840 # Force completion of pending disk writes
1841 /bin/sync
1843 # Umounting the volume
1844 echo "Unmounting..."
1845 umount -f ${MOUNT}
1846 losetup -d ${DEVICE}
1848 echo "Installation on ${TARGET} complete. "