Last active
February 19, 2022 23:03
-
-
Save maojj/ad98b65b0230d1ea71a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # BuildDmg.sh | |
| # Build OS X .dmg install file | |
| # Author maojiajun | |
| set -eu | |
| ################################################################################### | |
| # config, change for you app. | |
| # dmg title | |
| TITLE="YoudaoNote" | |
| # app path to add | |
| APP_PATH="YoudaoNote.app" | |
| # writable dmg size (k), (my be changed for your app) | |
| size="10000" | |
| # background image name, use your own image | |
| BG_IMAGE="install.png" | |
| # final name | |
| DMG_NAME="YoudaoNote.dmg" | |
| # should not be changed | |
| # temp writable dmg name | |
| TEMP_DMG_NAME="Temp.dmg" | |
| # option | |
| dmg_options="-fs HFS+ -fsargs '-c c=64,a=16,e=16' -format UDRW -size ${size}k" | |
| # temp path | |
| DIR="dmg" | |
| ################################################################################### | |
| #setp 1 : create an writable dmg | |
| echo "Step 1: create writable dmg" | |
| rm -rf "$DIR" | |
| mkdir $DIR | |
| cp -r "$APP_PATH" "$DIR" | |
| chmod -Rf go-w "$DIR" | |
| ln -s /Applications "$DIR/Applications" | |
| rm -f "$TEMP_DMG_NAME" | |
| hdiutil create -srcfolder $DIR -volname $TITLE -fs HFS+ \ | |
| -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${size}k "$TEMP_DMG_NAME" | |
| rm -rf "$DIR" | |
| #setp 2 : mount the dmg and copy the background image to .bacground | |
| echo "steo 2: add bacground image" | |
| device=$(hdiutil attach -readwrite -noverify -noautoopen ${TEMP_DMG_NAME} | \ | |
| egrep '^/dev/' | sed 1q | awk '{print $1}') | |
| mkdir /Volumes/${TITLE}/.background | |
| cp $BG_IMAGE /Volumes/${TITLE}/.background | |
| #step 3: set background image and position | |
| echo "Step 3: Set UI" | |
| echo ' | |
| tell application "Finder" | |
| tell disk "'${TITLE}'" | |
| open | |
| set current view of container window to icon view | |
| set toolbar visible of container window to false | |
| set statusbar visible of container window to false | |
| set the bounds of container window to {400, 100, 978, 482} | |
| set theViewOptions to the icon view options of container window | |
| set arrangement of theViewOptions to not arranged | |
| set icon size of theViewOptions to 72 | |
| set background picture of theViewOptions to file ".background:'${BG_IMAGE}'" | |
| set position of item "'${TITLE}'" of container window to {200, 200} | |
| set position of item "Applications" of container window to {375, 200} | |
| update without registering applications | |
| delay 5 | |
| #eject | |
| end tell | |
| end tell | |
| ' | osascript | |
| #setp 4: create a read-only dmg from the dmg | |
| echo "Step 4: create final read-only dmg" | |
| sudo chmod -Rf go-w /Volumes/"${TITLE}" | |
| sync | |
| sync | |
| hdiutil detach ${device} | |
| hdiutil convert ${TEMP_DMG_NAME} -format UDZO -imagekey zlib-level=9 -o "${DMG_NAME}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment