[369ac54] | 1 | #! /bin/bash |
---|
| 2 | |
---|
| 3 | # dmgpack volume [file|dir]+ |
---|
| 4 | # |
---|
| 5 | # Copy a group of files/directories to a compressed disk image. |
---|
| 6 | # The resulting image is stored in volume.dmg. |
---|
| 7 | # |
---|
| 8 | # Files are copied with 'ditto' to preserve resource forks. For |
---|
| 9 | # convenience we also call FixupResourceForks after copying. This |
---|
| 10 | # allows you to use /Developer/Tools/SplitFork on your tree and |
---|
| 11 | # manipulate it with CVS, tar, etc. Don't forget the -kb option |
---|
| 12 | # when adding or committing app and ._app files to CVS! |
---|
| 13 | # |
---|
| 14 | # This command will fail if a volume of the given name is already |
---|
| 15 | # mounted. It could also fail if the size of the resource forks |
---|
| 16 | # is large compared to the size of the data forks. Change the |
---|
| 17 | # scale factor internally from 11/10 to a more appropriate number |
---|
| 18 | # if it complains it is running out of space. |
---|
| 19 | # |
---|
| 20 | # It is possible to add a license agreement to a dmg file. See |
---|
| 21 | # the "Software License Agreements for UDIFs" sdk available at |
---|
| 22 | # http://developer.apple.com/sdk/index.html |
---|
| 23 | |
---|
| 24 | test $# -lt 2 && echo "usage: $0 diskname [file|dir]+" && exit 1 |
---|
| 25 | #set -x |
---|
| 26 | NAME="${1%.dmg}" ; shift |
---|
| 27 | DISK=/tmp/dmgpack$$.dmg |
---|
| 28 | COMPRESSED="$NAME.dmg" |
---|
| 29 | VOLUME="$NAME" |
---|
| 30 | |
---|
| 31 | # compute needed image size; scale it by 10% |
---|
| 32 | SIZE=$(du -ck "$@" | tail -1 | sed -e 's/ *total//') |
---|
| 33 | SIZE=$(echo $SIZE*11/10 | bc) |
---|
| 34 | test $SIZE -lt 4200 && SIZE=4200 |
---|
| 35 | |
---|
| 36 | # create the disk |
---|
| 37 | rm -f $DISK |
---|
| 38 | hdiutil create -size ${SIZE}k $DISK -layout NONE |
---|
| 39 | |
---|
| 40 | # create a file system on the disk; last line of output is |
---|
| 41 | # the device on which the disk was attached. |
---|
| 42 | DEVICE=$(hdiutil attach $DISK -nomount | tail -1) |
---|
| 43 | newfs_hfs -v "$VOLUME" $DEVICE |
---|
| 44 | |
---|
| 45 | # mount the file system |
---|
| 46 | mkdir $DISK-mount |
---|
| 47 | mount -t hfs $DEVICE $DISK-mount || (echo "mount $DISK-mount failed" && exit 1) |
---|
| 48 | |
---|
| 49 | # copy stuff to the disk and fixup resource forks |
---|
| 50 | for f in "$@"; do |
---|
| 51 | f=${f%/} ;# strip trailing / |
---|
| 52 | dest="$DISK-mount/${f##*/}" |
---|
| 53 | ditto -rsrc "$f" "$dest" |
---|
| 54 | test -d "$f" && /System/Library/CoreServices/FixupResourceForks "$dest" |
---|
| 55 | done |
---|
| 56 | |
---|
| 57 | # eject the disk |
---|
| 58 | umount $DISK-mount |
---|
| 59 | rmdir $DISK-mount |
---|
| 60 | hdiutil eject $DEVICE |
---|
| 61 | |
---|
| 62 | # compress the disk and make it read only |
---|
| 63 | rm -f "$COMPRESSED" |
---|
| 64 | hdiutil convert -format UDZO $DISK -imagekey zlib-level=9 -o "$COMPRESSED" |
---|
| 65 | rm -f $DISK |
---|