public
Description: A Mac OS X photo uploader program for my photo album.
Homepage: http://bleu.west.spy.net/~dustin/projects/photoupload/
Clone URL: git://github.com/dustin/photoupload.git
photoupload / createDiskImage
100644 52 lines (38 sloc) 1.297 kb
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
#! /bin/sh
#
# createDiskImage
 
# Requires three or more args
if [ $# -lt 3 ] ; then
echo "usage: $0 <ImageSizeInMegabytes> <NameOfImageWithNoExtension> <FolderToCopyToImage> ..."
    exit 1
fi
 
# Grab the size and image name arguments. Leave the rest of them in $*
imageSize=$1
shift
imageName=$1
shift
 
# Create the image and format it
echo
echo "Creating ${imageSize} MB disk image named ${imageName}..."
 
rm -f ${imageName}.dmg
hdiutil create ${imageName}.dmg -megabytes ${imageSize} -layout NONE
 
hdidOutput=`hdid -nomount ${imageName}.dmg | grep '/dev/disk[0-9]*'`
 
sudo /sbin/newfs_hfs -w -v ${imageName} -b 4096 ${hdidOutput}
 
hdiutil eject ${hdidOutput}
 
# Mount the image and copy stuff
hdidOutput=`hdid ${imageName}.dmg | grep '/dev/disk[0-9]*' | awk '{print $1}'`
sleep 4 # This sleep is needed and there seems to be no way to know when the image is mounted...
 
echo "Copying contents to ${imageName}..."
while [ $# -gt 0 ] ; do
echo "...copying ${1}"
    /Developer/Tools/CpMac -r ${1} /Volumes/${imageName}
    shift
done
 
hdiutil eject ${hdidOutput}
 
# Compress the image
echo "Compressing ${imageName} disk image..."
 
mv ${imageName}.dmg ${imageName}.orig.dmg
hdiutil convert ${imageName}.orig.dmg -format UDCO -o ${imageName}
rm ${imageName}.orig.dmg
 
echo "Done."
echo