aboutsummaryrefslogtreecommitdiff
path: root/packages/darwin_pkg/mkdmg
blob: c11d198703d6e72f3f906a98007720acbaf18deb (plain)
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
#!/bin/sh
#
# from: http://www.macosxhints.com/article.php?story=20020311215452999
# 
# 
# Creates a disk image (dmg) on Mac OS X from the command line
# from a folder.

FOLDER="$1"
if [ -z "$FOLDER" ]; then
echo
echo "usage: $0 <folder>"
echo
exit 1
fi

if [ ! -d "$FOLDER" ]; then
echo $FOLDER does not exist
exit 2
fi

SIZE=`/usr/bin/du -s "$FOLDER" | awk '{ print $1 }'`
# allow space for partition map and directory structure
SIZE=`echo 1024 + $SIZE \* 1.1 / 1 | bc`
NAME=`basename "$FOLDER"`
FILE=$NAME.dmg
TMP=${TMP:-/tmp}

if [ $SIZE -lt 9216 ]; then
SIZE=9216
fi

if [ -e "$FILE" ] ; then
echo $FILE already exists!
exit 3
fi

TMPFILE=$TMP/$$.dmg

echo Creating $TMPFILE from $FOLDER, $SIZE sectors...
hdiutil create $TMPFILE -sectors $SIZE -ov
if [ $? -ne 0 ] ; then
rm -f $TMPFILE
exit 4
fi
echo

DEVICES=`hdid -nomount $TMPFILE`
DEVMASTER=`echo $DEVICES| awk '{ print $1 }'`
DEVHFS=`echo $DEVICES| awk '{ print $5 }'`
echo Creating HFS partition $NAME on $TMPFILE at $DEVHFS
newfs_hfs -v "$NAME" $DEVHFS
if [ $? -ne 0 ] ; then
rm -f $TMPFILE
exit 5
fi
hdiutil eject $DEVMASTER
if [ $? -ne 0 ] ; then
rm -f $TMPFILE
exit 6
fi
DEVICES=`hdid $TMPFILE`
if [ $? -ne 0 ] ; then
rm -f $TMPFILE
exit 7
fi

DEVMASTER=`echo $DEVICES| awk '{ print $1 }'`
DEVHFS=`echo $DEVICES| awk '{ print $5 }'`
echo Copying $FOLDER to /Volumes/$NAME on $DEVMASTER
sudo ditto -rsrcFork "$FOLDER" "/Volumes/$NAME"
if [ $? -ne 0 ]; then
hdiutil eject $DEVMASTER
rm -f $TMPFILE
exit 8
fi

hdiutil eject $DEVMASTER
if [ $? -ne 0 ]; then
#rm -f $TMPFILE
exit 9
fi

echo "Compressing $NAME to $FILE"
#hdiutil convert $TMPFILE -format UDZO -o "$FILE"
hdiutil convert $TMPFILE -format UDZO -imagekey zlib-level=9 -o "$FILE"
if [ $? -ne 0 ]; then
rm -f "$FILE" $TMPFILE
exit 10
fi

rm -f $TMPFILE

# end