Annotation of imach/distributions/osx/create-dmg, revision 1.1

1.1     ! brouard     1: #! /bin/bash
        !             2: 
        !             3: # Create a read-only disk image of the contents of a folder
        !             4: #
        !             5: # Usage: make-diskimage <image_file>
        !             6: #                       <src_folder>
        !             7: #                       <volume_name>
        !             8: #                       <applescript>
        !             9: #                       <artpath>
        !            10: #                       <eula_resource_file>
        !            11: set -x
        !            12: set -e;
        !            13: 
        !            14: function pure_version() {
        !            15:   echo '1.0.0.2'
        !            16: }
        !            17: 
        !            18: function version() {
        !            19:   echo "create-dmg $(pure_version)"
        !            20: }
        !            21: 
        !            22: function usage() {
        !            23:   version
        !            24:   echo "Creates a fancy DMG file."
        !            25:   echo "Usage:  $(basename $0) options... image.dmg source_folder"
        !            26:   echo "All contents of source_folder will be copied into the disk image."
        !            27:   echo "Options:"
        !            28:   echo "  --volname name"
        !            29:   echo "      set volume name (displayed in the Finder sidebar and window title)"
        !            30:   echo "  --background pic.png"
        !            31:   echo "      set folder background image (provide png, gif, jpg)"
        !            32:   echo "  --window-pos x y"
        !            33:   echo "      set position the folder window"
        !            34:   echo "  --window-size width height"
        !            35:   echo "      set size of the folder window"
        !            36:   echo "  --icon-size icon_size"
        !            37:   echo "      set window icons size (up to 128)"
        !            38:   echo "  --icon file_name x y"
        !            39:   echo "      set position of the file's icon"
        !            40:   echo "  --custom-icon file_name custom_icon_or_sample_file x y"
        !            41:   echo "      set position and custom icon"
        !            42:   echo "  --version         show tool version number"
        !            43:   echo "  -h, --help        display this help"
        !            44:   exit 0
        !            45: }
        !            46: 
        !            47: WINX=10
        !            48: WINY=60
        !            49: WINW=600
        !            50: WINH=400
        !            51: ICON_SIZE=128
        !            52: 
        !            53: while test "${1:0:1}" = "-"; do
        !            54:   case $1 in
        !            55:     --volname)
        !            56:       VOLUME_NAME="$2"
        !            57:       shift; shift;;
        !            58:     --background)
        !            59:       BACKGROUND_FILE="$2"
        !            60:       BACKGROUND_FILE_NAME="$(basename $BACKGROUND_FILE)"
        !            61:       BACKGROUND_CLAUSE="set background picture of opts to file \".background:$BACKGROUND_FILE_NAME\""
        !            62:       shift; shift;;
        !            63:     --icon-size)
        !            64:       ICON_SIZE="$2"
        !            65:       shift; shift;;
        !            66:     --window-pos)
        !            67:       WINX=$2; WINY=$3
        !            68:       shift; shift; shift;;
        !            69:     --window-size)
        !            70:       WINW=$2; WINH=$3
        !            71:       shift; shift; shift;;
        !            72:     --icon)
        !            73:       POSITION_CLAUSE="${POSITION_CLAUSE}set position of item \"$2\" to {$3, $4}
        !            74: "
        !            75:       shift; shift; shift; shift;;
        !            76:     --custom-icon)
        !            77:       shift; shift; shift; shift; shift;;
        !            78:     -h | --help)
        !            79:       usage;;
        !            80:     --version)
        !            81:       version; exit 0;;
        !            82:     --pure-version)
        !            83:       pure_version; exit 0;;
        !            84:     -*)
        !            85:       echo "Unknown option $1. Run with --help for help."
        !            86:       exit 1;;
        !            87:   esac
        !            88: done
        !            89: 
        !            90: test -z "$2" && {
        !            91:   echo "Not enough arguments. Invoke with --help for help."
        !            92:   exit 1
        !            93: }
        !            94: 
        !            95: DMG_PATH="$1"
        !            96: DMG_DIRNAME="$(dirname "$DMG_PATH")"
        !            97: DMG_DIR="$(cd $DMG_DIRNAME > /dev/null; pwd)"
        !            98: DMG_NAME="$(basename "$DMG_PATH")"
        !            99: DMG_TEMP_NAME="$DMG_DIR/rw.${DMG_NAME}"
        !           100: SRC_FOLDER="$(cd "$2" > /dev/null; pwd)"
        !           101: test -z "$VOLUME_NAME" && VOLUME_NAME="$(basename "$DMG_PATH" .dmg)"
        !           102: 
        !           103: AUX_PATH="$(cd "$(dirname $0)"; pwd)/support"
        !           104: 
        !           105: test -d "$AUX_PATH" || {
        !           106:   echo "Cannot find support directory: $AUX_PATH"
        !           107:   exit 1
        !           108: }
        !           109: 
        !           110: # Create the image
        !           111: echo "Creating disk image..."
        !           112: test -f "${DMG_TEMP_NAME}" && rm -f "${DMG_TEMP_NAME}"
        !           113: hdiutil create -srcfolder "$SRC_FOLDER" -volname "${VOLUME_NAME}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size 300m "${DMG_TEMP_NAME}"
        !           114: 
        !           115: # mount it
        !           116: echo "Mounting disk image..."
        !           117: MOUNT_DIR="/Volumes/${VOLUME_NAME}"
        !           118: echo "Mount directory: $MOUNT_DIR"
        !           119: DEV_NAME=$(hdiutil attach -readwrite -noverify -noautoopen "${DMG_TEMP_NAME}" | egrep '^/dev/' | sed 1q | awk '{print $1}')
        !           120: echo "Device name:     $DEV_NAME"
        !           121: 
        !           122: #cp RightDS_Store "/Volumes/${VOLUME_NAME}/.DS_Store"
        !           123: 
        !           124: if ! test -z "$BACKGROUND_FILE"; then
        !           125:   echo "Copying background file..."
        !           126:   test -d "$MOUNT_DIR/.background" || mkdir "$MOUNT_DIR/.background"
        !           127:   cp "$BACKGROUND_FILE" "$MOUNT_DIR/.background/$BACKGROUND_FILE_NAME"
        !           128: fi
        !           129: 
        !           130: # run applescript
        !           131: APPLESCRIPT=$(mktemp -t createdmg.XXXXXXX)
        !           132: echo APPLESCRIPT1=$APPLESCRIPT
        !           133: cat "$AUX_PATH/template.applescript" | sed -e "s/WINX/$WINX/g" -e "s/WINY/$WINY/g" -e "s/WINW/$WINW/g" -e "s/WINH/$WINH/g" -e "s/BACKGROUND_CLAUSE/$BACKGROUND_CLAUSE/g" -e "s/ICON_SIZE/$ICON_SIZE/g" | perl -pe  "s/POSITION_CLAUSE/$POSITION_CLAUSE/g" >"$APPLESCRIPT"
        !           134: echo APPLESCRIPT=$APPLESCRIPT
        !           135: 
        !           136: # echo "Running Applescript: ./AdiumApplescriptRunner \"${APPLESCRIPT}\" process_disk_image \"${VOLUME_NAME}\""
        !           137: # "$AUX_PATH/AdiumApplescriptRunner" "${APPLESCRIPT}" process_disk_image "${VOLUME_NAME}" || true
        !           138: #echo "Done running the applescript..."
        !           139: #sleep 4
        !           140: 
        !           141: # make sure it's not world writeable
        !           142: echo "Fixing permissions..."
        !           143: chmod -Rf go-w "${MOUNT_DIR}" || true
        !           144: echo "Done fixing permissions."
        !           145: 
        !           146: # make the top window open itself on mount:
        !           147: if [ -x /usr/local/bin/openUp ]; then
        !           148:     echo "Applying openUp..."
        !           149:     /usr/local/bin/openUp "${MOUNT_DIR}"
        !           150: fi
        !           151: 
        !           152: # unmount
        !           153: echo "Unmounting disk image..."
        !           154: hdiutil detach "${DEV_NAME}"
        !           155: 
        !           156: # compress image
        !           157: echo "Compressing disk image..."
        !           158: hdiutil convert "${DMG_TEMP_NAME}" -format UDZO -imagekey zlib-level=9 -o "${DMG_DIR}/${DMG_NAME}"
        !           159: rm -f "${DMG_TEMP_NAME}"
        !           160: 
        !           161: # adding EULA resources
        !           162: if [ ! -z "${EULA_RSRC}" -a "${EULA_RSRC}" != "-null-" ]; then
        !           163:         echo "adding EULA resources"
        !           164:         hdiutil unflatten "${DMG_DIR}/${DMG_NAME}"
        !           165:         /Developer/Tools/ResMerger -a "${EULA_RSRC}" -o "${DMG_DIR}/${DMG_NAME}"
        !           166:         hdiutil flatten "${DMG_DIR}/${DMG_NAME}"
        !           167: fi
        !           168: 
        !           169: echo "Disk image done"
        !           170: exit 0

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>