Created
August 22, 2013 18:19
-
-
Save DomiR/6310873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh## Creates a disk image (dmg) on Mac OS X from the command line.# usage:# mkdmg <volname> <vers> <srcdir>## Where <volname> is the name to use for the mounted image, <vers> is the version# number of the volume and <srcdir> is where the contents to put on the dmg are.## The result will be a file called <volname>-<vers>.dmgif [ $# != 3 ]; then echo "usage: mkdmg.sh volname vers srcdir" exit 0fiVOL="$1"VER="$2"FILES="$3"DMG="tmp-$VOL.dmg"# create temporary disk image and format, ejecting when doneSIZE=`du -sk ${FILES} | sed -n '/^[0-9]*/s/([0-9]*).*/1/p'`SIZE=$((${SIZE}/1000+1))hdiutil create "$DMG" -megabytes ${SIZE} -ov -type UDIFDISK=`hdid "$DMG" | sed -ne ' /Apple_partition_scheme/ s|^/dev/([^ ]*).*$|1|p'`newfs_hfs -v "$VOL" /dev/r${DISK}s2hdiutil eject $DISK# mount and copy files onto volumehdid "$DMG"cp -R "${FILES}"/* "/Volumes/$VOL"hdiutil eject $DISK#osascript -e "tell application "Finder" to eject disk "$VOL"" && # convert to compressed image, delete temp imagerm -f "${VOL}-${VER}.dmg"hdiutil convert "$DMG" -format UDZO -o "${VOL}-${VER}.dmg"rm -f "$DMG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment