File: dmgpack.sh

package info (click to toggle)
python-bumps 1.0.0b2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,144 kB
  • sloc: python: 23,941; xml: 493; ansic: 373; makefile: 209; sh: 91; javascript: 90
file content (65 lines) | stat: -rwxr-xr-x 2,184 bytes parent folder | download | duplicates (2)
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
#! /bin/bash

# dmgpack volume [file|dir]+
#
#    Copy a group of files/directories to a compressed disk image.
#    The resulting image is stored in volume.dmg.
#
#    Files are copied with 'ditto' to preserve resource forks.  For
#    convenience we also call FixupResourceForks after copying.  This
#    allows you to use /Developer/Tools/SplitFork on your tree and
#    manipulate it with CVS, tar, etc.  Don't forget the -kb option
#    when adding or committing app and ._app files to CVS!
#
#    This command will fail if a volume of the given name is already
#    mounted.  It could also fail if the size of the resource forks
#    is large compared to the size of the data forks. Change the
#    scale factor internally from 11/10 to a more appropriate number
#    if it complains it is running out of space.
#
#    It is possible to add a license agreement to a dmg file.  See
#    the "Software License Agreements for UDIFs" sdk available at
#    http://developer.apple.com/sdk/index.html

test $# -lt 2 && echo "usage: $0 diskname [file|dir]+" && exit 1
#set -x
NAME="${1%.dmg}" ; shift
DISK=/tmp/dmgpack$$.dmg
COMPRESSED="$NAME.dmg"
VOLUME="$NAME"

# compute needed image size; scale it by 10%
SIZE=$(du -ck "$@" | tail -1 | sed -e 's/ *total//')
SIZE=$(echo $SIZE*11/10 | bc)
test $SIZE -lt 4200 && SIZE=4200

# create the disk
rm -f $DISK
hdiutil create -size ${SIZE}k $DISK -layout NONE

# create a file system on the disk; last line of output is
# the device on which the disk was attached.
DEVICE=$(hdiutil attach $DISK -nomount | tail -1)
newfs_hfs -v "$VOLUME" $DEVICE

# mount the file system
mkdir $DISK-mount
mount -t hfs $DEVICE $DISK-mount || (echo "mount $DISK-mount failed" && exit 1)

# copy stuff to the disk and fixup resource forks
for f in "$@"; do
    f=${f%/}		;# strip trailing /
    dest="$DISK-mount/${f##*/}"
    ditto -rsrc "$f" "$dest"
    test -d "$f" && /System/Library/CoreServices/FixupResourceForks "$dest"
done

# eject the disk
umount $DISK-mount
rmdir $DISK-mount
hdiutil eject $DEVICE

# compress the disk and make it read only
rm -f "$COMPRESSED"
hdiutil convert -format UDZO $DISK -imagekey zlib-level=9 -o "$COMPRESSED"
rm -f $DISK