| 1 | #!/usr/bin/env bash |
| 2 | # Produce and verify a fresh image before replacing a previously built artifact. |
| 3 | set -euo pipefail |
| 4 | |
| 5 | app="${1:?usage: package-desktop-dmg.sh <app> <output.dmg> <app-name>}" |
| 6 | output="${2:?missing output image}" |
| 7 | appname="${3:?missing app name}" |
| 8 | mkdir -p "$(dirname "$output")" |
| 9 | staging=$(mktemp -d "$(dirname "$output")/.desktop-dmg.XXXXXX") |
| 10 | trap 'rm -rf "$staging"' EXIT |
| 11 | mkdir "$staging/input" |
| 12 | cp -R "$app" "$staging/input/${appname}.app" |
| 13 | image="$staging/candidate.dmg" |
| 14 | |
| 15 | # Some create-dmg versions report Finder customization errors after producing |
| 16 | # a valid image. Verify that newly produced image, never the previous output. |
| 17 | create-dmg \ |
| 18 | --volname "$appname" \ |
| 19 | --window-size 540 380 \ |
| 20 | --icon-size 110 \ |
| 21 | --icon "${appname}.app" 150 190 \ |
| 22 | --app-drop-link 390 190 \ |
| 23 | --no-internet-enable \ |
| 24 | "$image" "$staging/input" || true |
| 25 | [ -s "$image" ] || { echo "create-dmg did not produce a fresh image" >&2; exit 1; } |
| 26 | hdiutil verify "$image" |
| 27 | mv -f "$image" "$output" |
| 28 |