67 lines
2.4 KiB
Bash
Executable File
67 lines
2.4 KiB
Bash
Executable File
#!/bin/zsh
|
|
set -euo pipefail
|
|
|
|
PROJECT_DIR="${0:A:h:h}"
|
|
APP_DIR="$PROJECT_DIR/dist/Puter.app"
|
|
ICON_SOURCE="${PUTER_ICON_SOURCE:-$PROJECT_DIR/Puter.icon}"
|
|
STAGING_ROOT="$(mktemp -d /tmp/puter-build.XXXXXX)"
|
|
STAGED_APP="$STAGING_ROOT/Puter.app"
|
|
CONTENTS_DIR="$STAGED_APP/Contents"
|
|
|
|
trap '/bin/rm -rf -- "$STAGING_ROOT"' EXIT
|
|
|
|
cd "$PROJECT_DIR"
|
|
swift build -c release
|
|
|
|
mkdir -p "$CONTENTS_DIR/MacOS" "$CONTENTS_DIR/Resources"
|
|
cp "$PROJECT_DIR/.build/release/Puter" "$CONTENTS_DIR/MacOS/Puter"
|
|
cp "$PROJECT_DIR/Resources/Info.plist" "$CONTENTS_DIR/Info.plist"
|
|
chmod +x "$CONTENTS_DIR/MacOS/Puter"
|
|
|
|
SMC_SOURCE="/Applications/Stats.app/Contents/Resources/smc"
|
|
if [[ -x "$SMC_SOURCE" ]]; then
|
|
ditto --norsrc "$SMC_SOURCE" "$CONTENTS_DIR/Resources/smc"
|
|
chmod +x "$CONTENTS_DIR/Resources/smc"
|
|
cp "$PROJECT_DIR/Resources/Stats-SMC-LICENSE.txt" "$CONTENTS_DIR/Resources/Stats-SMC-LICENSE.txt"
|
|
fi
|
|
|
|
if [[ -d "$ICON_SOURCE" ]]; then
|
|
print "Using Icon Composer source: $ICON_SOURCE"
|
|
xcrun actool "$ICON_SOURCE" \
|
|
--compile "$CONTENTS_DIR/Resources" \
|
|
--platform macosx \
|
|
--minimum-deployment-target 14.0 \
|
|
--app-icon Puter \
|
|
--output-partial-info-plist "$CONTENTS_DIR/Resources/IconInfo.plist" >/dev/null
|
|
|
|
[[ -s "$CONTENTS_DIR/Resources/Assets.car" ]] || {
|
|
print -u2 "Icon Composer did not produce an Assets.car file"
|
|
exit 1
|
|
}
|
|
[[ "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIconName' "$CONTENTS_DIR/Info.plist")" == "Puter" ]] || {
|
|
print -u2 "CFBundleIconName must reference the Icon Composer asset"
|
|
exit 1
|
|
}
|
|
if /usr/libexec/PlistBuddy -c 'Print :CFBundleIconFile' "$CONTENTS_DIR/Info.plist" >/dev/null 2>&1; then
|
|
print -u2 "CFBundleIconFile would override the live Icon Composer asset"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Finder and cloud-sync metadata can make an otherwise valid app bundle
|
|
# unsignable when rebuilding in place.
|
|
xattr -cr "$STAGED_APP"
|
|
codesign --force --deep --sign - "$STAGED_APP" >/dev/null
|
|
codesign --verify --deep --strict "$STAGED_APP"
|
|
|
|
mkdir -p "$PROJECT_DIR/dist"
|
|
/bin/rm -rf -- "$APP_DIR"
|
|
ditto --norsrc "$STAGED_APP" "$APP_DIR"
|
|
# File-provider workspaces can attach Finder/provenance metadata during the
|
|
# final copy. Clean and sign at the delivery path so verification reflects
|
|
# the bundle users actually launch.
|
|
xattr -cr "$APP_DIR"
|
|
codesign --force --deep --sign - "$APP_DIR" >/dev/null
|
|
codesign --verify --deep --strict "$APP_DIR"
|
|
print "Built $APP_DIR"
|