Skip to content

Instantly share code, notes, and snippets.

@aisrael
Created April 4, 2013 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save aisrael/5308455 to your computer and use it in GitHub Desktop.
Save aisrael/5308455 to your computer and use it in GitHub Desktop.
dir2dmg.sh—a bash script to create OS X .DMG images from the given folder or folders (supports wildcards).
#!/bin/bash
if [ "$#" -eq 0 ]; then
echo "Usage:"
echo " dir2dmg <path/to/directory>"
exit 1
fi
PWD=`pwd`
function dmg() {
dir="$1"
if [ ! -d "$dir" ]; then
echo "$dir is not a directory!"
exit 1
fi
if [ ! -r "$dir" ]; then
echo "$dir is not readable!"
exit 1
fi
vol=$( basename "$dir" )
echo "hdiutil create -volname \"$vol\" -srcfolder \"$dir\" -format UDZO \"$PWD/$vol\""
hdiutil create -volname "$vol" -srcfolder "$dir" -format UDZO "$PWD/$vol"
}
while [[ $# > 0 ]]; do
dmg "$1"
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment