Imported Robodoc.
[robodoc.git] / osx / dmg.sh
1 #!/bin/sh
2 # $Id: dmg.sh,v 1.4 2005/08/28 13:08:50 petterik Exp $
3 #****h* jpgind/dmg.sh
4 # NAME
5 #   dmg.sh
6 # SYNOPSIS
7 #   dmg.sh <project_name> <project_version>
8 # PURPOSE
9 #   Shell script for wrapping up mountable Mac OS X disk image 
10 #   containing a native installation package.
11 # SOURCE
12 #
13
14 set -e
15
16 NAM=$1
17 VER=$2
18 REL=$3
19
20 if ([ "$NAM" = "" ] || [ "$VER" = "" ]) ; then 
21     echo "usage: dmg.sh <project name> <project version>" 
22     exit 1
23 fi
24
25 if [ "$REL" = "" ] ; then 
26     REL=1
27 fi
28
29 PRJ=${NAM}-${VER}.pkg
30 TMPIMG=$$-${PRJ}.dmg
31 DSKNAM=${NAM}-${VER}-${REL}
32
33 if [ ! -d $PRJ ] ; then
34     echo " Directory $PRJ does not exist"
35     exit 1
36 fi
37
38 for f in $TMPIMG ${DSKNAM}.dmg ${DSKNAM}.dmg.gz ; do 
39     if [ -f $f ] ; then
40                 rm -f $f
41     fi
42 done
43
44
45 BLKS=`du -s $PRJ | awk '{print $1}'`
46
47 echo " $PRJ blocks $BLKS"
48
49 # man hdutil example adds 100 sectors, min size is 4MB
50 if [ $BLKS -lt 8192 ] ; then 
51     BLKS=8192
52 else
53     BLKS=`expr $BLKS \+ 100`
54 fi
55
56 echo " Using $BLKS sectors for raw image"
57
58 hdiutil create $TMPIMG -sectors $BLKS -layout NONE
59
60 # Create a /dev/disk device from the image
61 drive=`hdid -nomount $TMPIMG | awk '{print $1}'`
62
63 # Create a new filesystem on the disk device
64 newfs_hfs -v "${DSKNAM}" -b 4096 /dev/r${drive:t}
65
66 # Remount the disk
67 echo " Image formatted, ejecting ${drive}..."
68 hdiutil eject ${drive}
69
70 echo " Mounting $TMPIMG ..."
71 drive=`hdid $TMPIMG | awk '{print $1}'`
72
73 echo " Searching for ${drive}..."
74 while [ "$MOUNTPOINT" = "" ] ; do
75     MOUNTPOINT=`df -l | grep $drive | awk '{print $6}'`
76 done
77 echo " Found $drive at $MOUNTPOINT"
78
79 # Unpack the tarball into the mounted filesystem
80 echo " Copying application..."
81
82 tar cf - $PRJ | (cd  $MOUNTPOINT; tar xf -)
83
84 # Eject the disk
85 echo " Ejecting..."
86 hdiutil eject ${drive}
87
88 # Convert the image to a UDIF compressed image 
89 echo " Compressing..."
90 hdiutil convert -format UDCO $TMPIMG -o ${DSKNAM}.dmg
91 gzip ${DSKNAM}.dmg
92
93 # Remove the temporary image
94 echo " Removing scratch image"
95 rm -f $TMPIMG
96
97 ls -l ${DSKNAM}.dmg.gz
98
99 md5 ${DSKNAM}.dmg.gz
100
101 exit 0
102
103 #***** end dmg.sh