Skip to content

Instantly share code, notes, and snippets.

@tjstyle
Created May 17, 2012 00:41
Show Gist options
  • Save tjstyle/2715225 to your computer and use it in GitHub Desktop.
Save tjstyle/2715225 to your computer and use it in GitHub Desktop.
DMG Creation Script
#!/bin/bash
# DMG Creation Script
# Usage: makedmg <imagename> <imagetitle> <imagesize (MB)> <contentdir>
#
# imagename: The output file name of the image, ie foo.dmg
# imagetitle: The title of the DMG File as displayed in OS X
# imagesize: The size of the DMG you're creating in MB (Blame Linux for the fixed size limitation!!)
# contentdir: The directory containing the content you want the DMG file to contain
#
# Example: makedmg foo.dmg "Script Test" 50 /home/jon/work/scripts/content
#
# Author: Jon Cowie
# Creation Date: 02/04/2008
if [ ! $# == 4 ]; then
echo "Usage: makedmg <imagename> <imagetitle> <imagesize (MB)> <contentdir>"
else
OUTPUT=$1
TITLE=$2
FILESIZE=$3
CONTENTDIR=$4
USER=`whoami`
TMPDIR="/tmp/dmgdir"
if [ ${USER} != "root" ]; then
echo "makedmg must be run as root!"
else
echo "Creating DMG File..."
dd if=/dev/zero of=${OUTPUT} bs=1M count=$FILESIZE
mkfs.hfsplus -v "${TITLE}" ${OUTPUT}
echo "Mounting DMG File..."
mkdir -p ${TMPDIR}
mount -t hfsplus -o loop ${OUTPUT} ${TMPDIR}
echo "Copying content to DMG File..."
cp -R ${CONTENTDIR}/* ${TMPDIR}
echo "Unmounting DMG File..."
umount ${TMPDIR}
rm -rf ${TMPDIR}
echo "All Done!"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment