#!/bin/bash
INPUT="$1"
#remove trailing slash...
if [ "`echo ${INPUT} | rev | cut -c1-1`" == "/" ] ; then
INPUT="`echo ${INPUT} | rev | cut -c2- | rev`"
fi
#get the name before the last /
VOLUME="`echo ${INPUT}|rev | cut -f1 -d/ | rev`"
if [ "$VOLUME" == "" ] ; then
VOLUME="${INPUT}"
fi
OUTPUT_DIR="`dirname $INPUT`"
DMG_NAME="${VOLUME}.dmg"
echo "INPUT: ${INPUT}"
echo "OUTPUT_DIR: ${OUTPUT_DIR}"
echo "DMG_NAME: ${DMG_NAME}"
echo "VOLUME: ${VOLUME}"
echo "Constructing DMG File..."
hdiutil create -srcfolder "${INPUT}" -volname "${VOLUME}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDBZ "${OUTPUT_DIR}/${DMG_NAME}"
#if you like zlib, replace above line with following line:
#hdiutil create -srcfolder "${INPUT}" -volname "${INPUT}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDZO -imagekey zlib-level=9 "${DMG_NAME}"
ERROR="$?"
if [ "$ERROR" -eq 0 ] ; then
echo "DMG Created Successfully!"
else
echo "FAILED!"
exit "$ERROR"
fi