Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2. INPUT="$1"
  3.  
  4. #remove trailing slash...
  5. if [ "`echo ${INPUT} | rev | cut -c1-1`" == "/" ] ; then
  6.         INPUT="`echo ${INPUT} | rev | cut -c2- | rev`"
  7. fi
  8.  
  9. #get the name before the last /
  10. VOLUME="`echo ${INPUT}|rev | cut -f1 -d/ | rev`"
  11. if [ "$VOLUME" == "" ] ; then
  12.         VOLUME="${INPUT}"
  13. fi
  14.  
  15. OUTPUT_DIR="`dirname $INPUT`"
  16. DMG_NAME="${VOLUME}.dmg"
  17.  
  18. echo "INPUT: ${INPUT}"
  19. echo "OUTPUT_DIR: ${OUTPUT_DIR}"
  20. echo "DMG_NAME: ${DMG_NAME}"
  21. echo "VOLUME: ${VOLUME}"
  22. echo "Constructing DMG File..."
  23. hdiutil create -srcfolder "${INPUT}" -volname "${VOLUME}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDBZ "${OUTPUT_DIR}/${DMG_NAME}"
  24. #if you like zlib, replace above line with following line:
  25. #hdiutil create -srcfolder "${INPUT}" -volname "${INPUT}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDZO -imagekey zlib-level=9 "${DMG_NAME}"
  26.  
  27. ERROR="$?"
  28. if [ "$ERROR" -eq 0 ] ; then
  29.         echo "DMG Created Successfully!"
  30. else
  31.         echo "FAILED!"
  32.         exit "$ERROR"
  33. fi