Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2. INPUT="${1%%/}" #remove trailing slash
  3.  
  4. VOLUME="${INPUT##*/}" #compute volume name as folder name
  5. OUTPUT_DIR="${INPUT%/*}" #make output dir the same level as the input's parent
  6. DMG_NAME="${VOLUME}.dmg" #dmg name will be volume name +.dmg
  7.  
  8. if [ "${INPUT}" = "${OUTPUT_DIR}" ] ; then
  9.     OUTPUT_DIR="."
  10. fi
  11.  
  12. echo "INPUT: ${INPUT}"
  13. echo "OUTPUT_DIR: ${OUTPUT_DIR}"
  14. echo "DMG_NAME: ${DMG_NAME}"
  15. echo "VOLUME: ${VOLUME}"
  16. echo "Constructing DMG File..."
  17. hdiutil create -srcfolder "${INPUT}" -volname "${VOLUME}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDBZ "${OUTPUT_DIR}/${DMG_NAME}"
  18. #if you like zlib, replace above line with following line:
  19. #hdiutil create -srcfolder "${INPUT}" -volname "${INPUT}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDZO -imagekey zlib-level=9 "${DMG_NAME}"
  20.  
  21. ERROR="$?"
  22. if [ "$ERROR" -eq 0 ] ; then
  23.     echo "DMG Created Successfully!"
  24. else
  25.     echo "FAILED!"
  26.     exit "$ERROR"
  27. fi