Skip to content

Instantly share code, notes, and snippets.

@glejeune
Created January 5, 2012 19:12
Show Gist options
  • Save glejeune/1566718 to your computer and use it in GitHub Desktop.
Save glejeune/1566718 to your computer and use it in GitHub Desktop.
Extract DMG on MacOSX
#!/bin/sh
usage() {
echo "$0 /path/to/image.dmg [/output/path]"
exit 0
}
DMG=$1
OUTPUT=$2
[ "x$DMG" != "x" ] || usage
[ "x$OUTPUT" != "x" ] || OUTPUT="."
[ -f $DMG ] || usage
[ -d $OUTPUT ] || OUTPUT="."
echo Extract $DMG to $OUTPUT
MOUNTINFO=$(hdiutil attach $DMG)
MOUNTDISK=$(echo $MOUNTINFO | awk '{print $1}')
MOUNTDISK_ESCAPED=$(echo $MOUNTDISK | sed -e 's/\//\\\//g')
MOUNTPOINT=$(echo $MOUNTINFO | sed -e "s/$MOUNTDISK_ESCAPED//" | sed -e 's/^[^\/]*//')
cp -r $MOUNTPOINT/* $OUTPUT
hdiutil detach $MOUNTDISK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment