#!/bin/sh

if [ $# -ne 4 ]; then
  echo "Usage: $0 size name appbundle.app dmgname.dmg"
  exit 1
fi

SIZE=$1
NAME=$2
APPBUNDLE=$3
DMG=$4

RAW_DMG=raw-${DMG}

rm ${RAW_DMG} ${DMG}

hdiutil create -size ${SIZE} -fs HFS+ -volname "${NAME}" ${RAW_DMG}
DEV=$(hdiutil attach ${RAW_DMG} | cut -f 1 | tail -n 1 )
cp -R ${APPBUNDLE} "/Volumes/${NAME}"
hdiutil detach $DEV
hdiutil convert ${RAW_DMG} -format UDZO -o ${DMG}
