AnyBot/deploy/mac/bundle.sh

55 lines
2.5 KiB
Bash
Raw Permalink 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 v0.0.1-36bc2be → dist/AnyBot-v0.0.1-36bc2be-macos-<arch>.zip
# With KEEP_APP=1 it leaves dist/AnyBot.app instead of zipping it (make install).
# Signed with this Mac's own fixed key (no Apple developer account): the first time, right-click › 打開.
set -e
VERSION=${1:?version}
# Info.plist wants plain numbers (0.0.1): the commit stays in the file name and in the app itself.
NUMBER=$(printf '%s' "$VERSION" | sed -n 's/^v\{0,1\}\([0-9][0-9.]*\).*/\1/p')
NUMBER=${NUMBER:-0.0.0}
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>$NUMBER</string>
<key>CFBundleVersion</key><string>$NUMBER</string>
<key>LSMinimumSystemVersion</key><string>12.0</string>
<key>NSHighResolutionCapable</key><true/>
<!-- The bots work while the window is covered or minimized: macOS must not put the app to sleep (App Nap) then. -->
<key>NSAppSleepDisabled</key><true/>
<key>NSMicrophoneUsageDescription</key><string>語音聊天時,聽你說話。</string>
<key>NSAppleEventsUsageDescription</key><string>讓 Bot 在你允許時操作其他 App。</string>
</dict></plist>
PLIST
# The same signature every build, so macOS keeps the permissions it gave (see sign.sh).
sh "$(dirname "$0")/sign.sh" "$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"