AnyBot/deploy/mac/bundle.sh

49 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/sh
# Make AnyBot.app from the release build and zip it (run from app/ on a Mac, after
# `cargo build --release`): deploy/mac/bundle.sh 1.2.0 → dist/AnyBot-1.2.0-macos-<arch>.zip
# With KEEP_APP=1 it leaves dist/AnyBot.app instead of zipping it (make install).
# Signed ad hoc (no Apple developer account): the first time, right-click › 打開.
set -e
VERSION=${1:?version}
BIN=${CARGO_TARGET_DIR:-target}/release/anybot
ARCH=$(uname -m)
OUT=dist
APP="$OUT/AnyBot.app"
rm -rf "$APP" && mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
cp "$BIN" "$APP/Contents/MacOS/AnyBot"
# The icon: every size the system asks for.
SET=$(mktemp -d)/AnyBot.iconset
mkdir -p "$SET"
for s in 16 32 128 256 512; do
"$BIN" --write-icon "$SET/icon_${s}x${s}.png" $s
"$BIN" --write-icon "$SET/icon_${s}x${s}@2x.png" $((s * 2))
done
iconutil -c icns "$SET" -o "$APP/Contents/Resources/AnyBot.icns"
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>CFBundleName</key><string>AnyBot</string>
<key>CFBundleDisplayName</key><string>AnyBot</string>
<key>CFBundleIdentifier</key><string>net.30cm.anybot</string>
<key>CFBundleExecutable</key><string>AnyBot</string>
<key>CFBundleIconFile</key><string>AnyBot</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>$VERSION</string>
<key>CFBundleVersion</key><string>$VERSION</string>
<key>LSMinimumSystemVersion</key><string>12.0</string>
<key>NSHighResolutionCapable</key><true/>
<key>NSMicrophoneUsageDescription</key><string>語音聊天時,聽你說話。</string>
<key>NSAppleEventsUsageDescription</key><string>讓 Bot 在你允許時操作其他 App。</string>
</dict></plist>
PLIST
codesign --force --deep -s - "$APP"
if [ "${KEEP_APP:-}" = 1 ]; then
exit 0
fi
ditto -c -k --norsrc --keepParent "$APP" "$OUT/AnyBot-$VERSION-macos-$ARCH.zip"
rm -rf "$APP"
ls -la "$OUT"