tv-anarchy/build-install.sh
Natalie 913135ca8c feat(@applications/tv-anarchy): improve macOS install logic
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-06-09 20:50:54 -07:00

68 lines
3.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build TVAnarchy (Release) and install it to the OS-appropriate Applications
# folder (see resolve_dest), so the running app and the built app can't silently
# drift. The one irreducible manual step is quitting + relaunching — you can't
# hot-swap a running native app — and the sidebar build stamp
# (v<ver> · <sha> · <time>) makes a stale copy obvious.
set -euo pipefail
cd "$(dirname "$0")"
# Where TVAnarchy.app installs. Duplicated in tools/update.sh (kept in sync) so
# that script stays curl-able standalone:
# TVANARCHY_DEST env → explicit override, used verbatim
# macOS, /Applications writable → /Applications (the standard location —
# Finder's "Applications", admin group, no sudo)
# macOS, not writable (non-admin)→ ~/Applications (Apple's per-user location)
# anything else → fail loud; the .app bundle is macOS-only
resolve_dest() {
if [ -n "${TVANARCHY_DEST:-}" ]; then printf '%s\n' "$TVANARCHY_DEST"; return; fi
[ "$(uname -s)" = "Darwin" ] || { echo "✗ TVAnarchy.app is macOS-only (this is $(uname -s))." >&2; return 1; }
if [ -w /Applications ]; then
printf '/Applications/TVAnarchy.app\n'
else
printf '%s/Applications/TVAnarchy.app\n' "$HOME"
fi
}
# Default DD lives in the repo (build/dd); tools/release.sh overrides it with an
# ephemeral tmp dir so a release cut never churns the working build cache.
DD="${TVANARCHY_DD:-build/dd}"
APP="$DD/Build/Products/Release/TVAnarchy.app"
DEST="$(resolve_dest)"
echo "→ stamp build identity (git SHA / time → BuildStamp.swift)"
tools/stamp-build.sh
echo "→ xcodegen generate"
xcodegen generate >/dev/null
echo "→ xcodebuild (Release)"
xcodebuild -scheme TVAnarchy -configuration Release -derivedDataPath "$DD" \
build CODE_SIGNING_ALLOWED=NO 2>&1 | grep -E "Stamp version|stamped:|BUILD SUCCEEDED|BUILD FAILED|error:" || true
[ -d "$APP" ] || { echo "✗ build produced no app at $APP" >&2; exit 1; }
mkdir -p "$(dirname "$DEST")"
rm -rf "$DEST"
cp -R "$APP" "$DEST"
# One install location only: drop a stale copy at the other auto candidate so
# the launched app can never silently be an old build. Skipped under an explicit
# TVANARCHY_DEST (e.g. a test install must not touch the real one).
if [ -z "${TVANARCHY_DEST:-}" ]; then
for other in "/Applications/TVAnarchy.app" "$HOME/Applications/TVAnarchy.app"; do
if [ "$other" != "$DEST" ] && [ -d "$other" ]; then
rm -rf "$other" && echo " removed stale copy at $other"
fi
done
fi
# Marketing version is in the plist; SHA / build / time live in the compiled
# BuildStamp constant we just generated (the reliable source — see project.yml).
VER=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$DEST/Contents/Info.plist")
SHA=$(sed -n 's/.*sha = "\(.*\)"/\1/p' Sources/TVAnarchyCore/BuildStamp.swift)
BUILD=$(sed -n 's/.*commitCount = \(.*\)/\1/p' Sources/TVAnarchyCore/BuildStamp.swift)
STAMP=$(sed -n 's/.*buildTime = "\(.*\)"/\1/p' Sources/TVAnarchyCore/BuildStamp.swift)
echo "✓ installed → $DEST"
echo " v$VER (build $BUILD) · $SHA · $STAMP"
echo " quit any running TVAnarchy and relaunch to pick this up."