#!/bin/zsh
#===============================================================================
#
# FILE: mkdmg.sh
#
# USAGE: ./mkdmg.sh
#
# DESCRIPTION: Script to take a Mac app and turn it in to a DMG package
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: John Ryland (jryland@xiaofrog.com)
# COMPANY: InvertedLogic
# VERSION: 1.0
# CREATED: 12/26/07 16:54:36 CST
# REVISION: ---
#===============================================================================
#
# Original script of this useful tool from here:
# http://www.kernelthread.com/mac/apme/archive/
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin
SCRATCH=./.mkdmg.$$$$
error()
{
echo "Error"
rm -rf $
exit 1
}
[ $ -ne 1 ] && echo "usage: mkdmg <directory>" && exit 1
[ ! -e $ ] && echo "*** $ does not exist." && exit 1
NAME=`basename $`
NAME="$"
ARCH="$ Archive"
IMAGE=$/$.dmg
OUTPUT="./$.dmg"
mkdir $
echo "Creating disk image $..."
SIZE=`du -s -k $ | awk '{print $}'` || error
hdiutil create "$" -volname "$" -megabytes `expr 5 + $ / 1000` -type SPARSE -fs HFS+ > /dev/null 2>&1 || error
hdid $.sparseimage > /dev/null 2>&1 || error
ditto -rsrcFork $ "/Volumes/$/$" > /dev/null 2>&1 || error
hdiutil detach `mount | grep "Volumes/$" | awk '{print $}'` > /dev/null 2>&1 || error
hdiutil convert "$.sparseimage" -format UDZO -o $ -imagekey zlib-devel=9 > /dev/null 2>&1 || error
echo "Disk image $ ready"
rm -rf $