Files
helder/scripts/bundle.sh
T

94 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Usage: scripts/bundle.sh [--install] [--force]
# --install copy "build/Helder.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.helder
VERSION=0.2.0
APP="build/Helder.app"
swift build -c release --product Helder
BIN="$(swift build -c release --show-bin-path)"
rm -rf "$APP"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources" "$APP/Contents/Helpers"
cp "$BIN/Helder" "$APP/Contents/MacOS/Helder"
# SwiftPM resource bundles go in Contents/Resources: the .app root would break
# the code signature. FontRegistry and SwiftTerm both look there.
for bundle in "$BIN"/*.bundle; do
cp -R "$bundle" "$APP/Contents/Resources/"
done
# ripgrep powers search and the file list. ExecutableLocator checks Contents/Helpers first.
RG="${RG_BINARY:-}"
[[ -z "$RG" && -x vendor/ripgrep/rg ]] && RG=vendor/ripgrep/rg
[[ -z "$RG" ]] && RG="$(command -v rg || true)"
if [[ -n "$RG" && -x "$RG" ]]; then
cp "$RG" "$APP/Contents/Helpers/rg"
else
echo "warning: no ripgrep found (set RG_BINARY); search falls back to a slow walk" >&2
fi
ICONSET="$(mktemp -d)/Helder.iconset"
mkdir -p "$ICONSET"
for size in 16 32 128 256 512; do
sips -z $size $size assets/icon.png --out "$ICONSET/icon_${size}x${size}.png" >/dev/null
sips -z $((size * 2)) $((size * 2)) assets/icon.png --out "$ICONSET/icon_${size}x${size}@2x.png" >/dev/null
done
iconutil -c icns "$ICONSET" -o "$APP/Contents/Resources/Helder.icns"
rm -rf "$(dirname "$ICONSET")"
cat > "$APP/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key><string>Helder</string>
<key>CFBundleIdentifier</key><string>$BUNDLE_ID</string>
<key>CFBundleName</key><string>Helder</string>
<key>CFBundleDisplayName</key><string>Helder</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>$VERSION</string>
<key>CFBundleVersion</key><string>$VERSION</string>
<key>CFBundleIconFile</key><string>Helder</string>
<key>CFBundleInfoDictionaryVersion</key><string>6.0</string>
<key>LSMinimumSystemVersion</key><string>14.0</string>
<key>LSApplicationCategoryType</key><string>public.app-category.developer-tools</string>
<key>NSHighResolutionCapable</key><true/>
<key>NSPrincipalClass</key><string>NSApplication</string>
</dict>
</plist>
PLIST
codesign --force --deep -s - "$APP"
codesign --verify --deep --strict "$APP"
echo "built $APP"
if $install; then
target="$HOME/Applications/Helder.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"
echo "installed $target"
fi