#!/usr/bin/env bash # Usage: scripts/bundle.sh [--install] [--force] # --install copy "build/Plak.app" to ~/Applications # --force let --install replace an app that has a different bundle id set -euo pipefail source "$(dirname "$0")/env.sh" install=false force=false for arg in "$@"; do case "$arg" in --install) install=true ;; --force) force=true ;; *) echo "unknown option: $arg" >&2; exit 2 ;; esac done BUNDLE_ID=nl.blijnder.plak VERSION=0.1.0 APP="build/Plak.app" swift build -c release --product Plak BIN="$(swift build -c release --show-bin-path)" rm -rf "$APP" mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources" cp "$BIN/Plak" "$APP/Contents/MacOS/Plak" # SwiftPM resource bundles go in Contents/Resources: the .app root would break # the code signature. for bundle in "$BIN"/*.bundle; do [[ -e "$bundle" ]] || continue cp -R "$bundle" "$APP/Contents/Resources/" done cat > "$APP/Contents/Info.plist" < CFBundleExecutablePlak CFBundleIdentifier$BUNDLE_ID CFBundleNamePlak CFBundleDisplayNamePlak CFBundlePackageTypeAPPL CFBundleShortVersionString$VERSION CFBundleVersion$VERSION CFBundleInfoDictionaryVersion6.0 LSMinimumSystemVersion14.0 LSApplicationCategoryTypepublic.app-category.productivity LSUIElement NSHighResolutionCapable NSPrincipalClassNSApplication CFBundleURLTypes CFBundleURLName$BUNDLE_ID CFBundleURLSchemesplak PLIST codesign --force --deep -s - "$APP" codesign --verify --deep --strict "$APP" echo "built $APP" if $install; then target="$HOME/Applications/Plak.app" if [[ -d "$target" ]]; then existing="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$target/Contents/Info.plist" 2>/dev/null || true)" if [[ "$existing" != "$BUNDLE_ID" && "$force" != true ]]; then echo "refusing to replace $target (bundle id '$existing'); pass --force to overwrite it" >&2 exit 1 fi rm -rf "$target" fi mkdir -p "$HOME/Applications" cp -R "$APP" "$target" /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "$target" echo "installed $target" fi