Voxley / app · voxley.si / Scripts / build-app.sh
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | root="$(cd "$(dirname "$0")/.." && pwd)" |
| 5 | output="${1:-/Volumes/Expand/Projects/Voxley/app-work}" |
| 6 | [[ -d /Volumes/Expand ]] || { echo 'Mount Expand before building Voxley.' >&2; exit 1; } |
| 7 | [[ "$output" == /Volumes/Expand/* ]] || { echo 'Choose an output directory on Expand.' >&2; exit 1; } |
| 8 | mkdir -p "$output/Build/tmp" "$output/Build/modules" "$output/Build/cache" |
| 9 | export TMPDIR="$output/Build/tmp/" |
| 10 | export CLANG_MODULE_CACHE_PATH="$output/Build/modules" |
| 11 | export SWIFTPM_MODULECACHE_OVERRIDE="$output/Build/modules" |
| 12 | args=(--package-path "$root" --scratch-path "$output/Build/swiftpm" --cache-path "$output/Build/cache") |
| 13 | app="$output/Voxley.app" |
| 14 | identity="${VOXLEY_SIGNING_IDENTITY:-}" |
| 15 | if [[ -z "$identity" && -d "$app" ]]; then |
| 16 | signing_info="$(/usr/bin/codesign -d --verbose=2 "$app" 2>&1)" |
| 17 | identity="$(sed -n 's/^Authority=\(Developer ID Application: .*\)$/\1/p' <<< "$signing_info")" |
| 18 | if [[ -z "$identity" && "$signing_info" != *"Signature=adhoc"* ]]; then |
| 19 | echo "Couldn’t read Voxley’s existing signing identity. Set VOXLEY_SIGNING_IDENTITY and try again." >&2 |
| 20 | exit 1 |
| 21 | fi |
| 22 | fi |
| 23 | if [[ -n "$identity" && "$identity" != "-" ]] && |
| 24 | ! /usr/bin/security find-identity -v -p codesigning "$HOME/Library/Keychains/login.keychain-db" | /usr/bin/grep -Fq "\"$identity\""; then |
| 25 | echo "Voxley’s signing identity is not available in the login keychain. The installed app was left intact." >&2 |
| 26 | exit 1 |
| 27 | fi |
| 28 | signing_flags=(--timestamp=none) |
| 29 | sparkle='' |
| 30 | if [[ "${VOXLEY_RELEASE:-0}" == 1 ]]; then |
| 31 | [[ "$identity" == "Developer ID Application: "* ]] || { echo 'A Developer ID Application identity is required for distribution.' >&2; exit 1; } |
| 32 | signing_flags=(--timestamp --options runtime) |
| 33 | sparkle="$(bash "$root/Scripts/prepare-sparkle.sh" '/Volumes/Expand/Projects/Voxley/app-work/Build')" |
| 34 | args+=(-Xswiftc -DVOXLEY_SPARKLE -Xswiftc -F -Xswiftc "$sparkle" |
| 35 | -Xlinker -F -Xlinker "$sparkle" -Xlinker -rpath -Xlinker @executable_path/../Frameworks) |
| 36 | fi |
| 37 | xcrun swift build "${args[@]}" -c release |
| 38 | bin="$(xcrun swift build "${args[@]}" -c release --show-bin-path)" |
| 39 | mkdir -p "$app/Contents/MacOS" |
| 40 | install -m 755 "$bin/Voxley" "$app/Contents/MacOS/Voxley" |
| 41 | install -m 644 "$root/Scripts/Info.plist" "$app/Contents/Info.plist" |
| 42 | iconset="$output/Build/tmp/AppIcon.iconset" |
| 43 | mkdir -p "$iconset" "$app/Contents/Resources" |
| 44 | xcrun actool --compile "$app/Contents/Resources" --platform macosx \ |
| 45 | --minimum-deployment-target 26.0 "$root/Resources/Assets.xcassets" |
| 46 | for size in 16 32 128 256 512; do |
| 47 | /usr/bin/sips -z "$size" "$size" "$root/Resources/AppIcon.png" --out "$iconset/icon_${size}x${size}.png" >/dev/null |
| 48 | twice=$((size * 2)) |
| 49 | /usr/bin/sips -z "$twice" "$twice" "$root/Resources/AppIcon.png" --out "$iconset/icon_${size}x${size}@2x.png" >/dev/null |
| 50 | done |
| 51 | /usr/bin/iconutil -c icns "$iconset" -o "$app/Contents/Resources/AppIcon.icns" |
| 52 | if [[ -n "$sparkle" ]]; then |
| 53 | /usr/libexec/PlistBuddy -c "Merge '$root/Scripts/Sparkle.plist'" "$app/Contents/Info.plist" |
| 54 | install -m 644 "$sparkle/LICENSE" "$app/Contents/Resources/Sparkle-LICENSE.txt" |
| 55 | install -m 644 "$root/Packaging/macOS/background.tiff" "$app/Contents/Resources/VoxleyInstallerBackground.tiff" |
| 56 | framework="$app/Contents/Frameworks/Sparkle.framework" |
| 57 | ditto "$sparkle/Sparkle.framework" "$framework" |
| 58 | for component in "$framework/Versions/Current/XPCServices/"*.xpc \ |
| 59 | "$framework/Versions/Current/Autoupdate" "$framework/Versions/Current/Updater.app" "$framework"; do |
| 60 | /usr/bin/codesign --force --sign "$identity" --keychain "$HOME/Library/Keychains/login.keychain-db" "${signing_flags[@]}" "$component" |
| 61 | done |
| 62 | signing_flags+=(--entitlements "$root/Scripts/VoxleyRelease.entitlements") |
| 63 | fi |
| 64 | if [[ -n "$identity" && "$identity" != "-" ]]; then |
| 65 | /usr/bin/codesign --force --sign "$identity" --keychain "$HOME/Library/Keychains/login.keychain-db" "${signing_flags[@]}" "$app" |
| 66 | else |
| 67 | /usr/bin/codesign --force --sign - "$app" |
| 68 | fi |
| 69 | /usr/bin/codesign --verify --deep --strict "$app" |
| 70 | echo "$app" |