Files
Ydisks-Xianyu-Helper/packaging/macos/build-pkg.sh
T
Christ 0bafa50dbf fix: 修复桌面安装包签名与 Windows 服务参数
- 按目录深度签名 macOS Chromium 内嵌 framework、xpc 和应用组件,避免 amd64 构建留下未签名 Mach-O 文件。

- 修正 Inno Setup 中 xianyu-server 和 Playwright runtime 路径的嵌套引号,确保 Windows 安装器可以正常编译并注册服务。
2026-08-12 01:30:41 +08:00

117 lines
4.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
set -eu
VERSION="${1:?version is required}"
DIST_DIR="${2:?dist directory is required}"
ARCH="${3:?architecture is required (arm64 or amd64)}"
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
PROJECT_ROOT="$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)"
BIN_DIR="$DIST_DIR/$ARCH"
ROOT_DIR="$DIST_DIR/pkgroot-$ARCH"
APP_DIR="$ROOT_DIR/Applications/Ydisks闲鱼助手"
APP="$APP_DIR/Ydisks闲鱼助手.app"
PACKAGE_PATH="$DIST_DIR/Ydisks-Xianyu-Helper-$VERSION-$ARCH.pkg"
UNSIGNED_PACKAGE_PATH="$DIST_DIR/.Ydisks-Xianyu-Helper-$VERSION-$ARCH.unsigned.pkg"
case "$ARCH" in
arm64|amd64) ;;
*) echo "不支持的 macOS 架构:$ARCH" >&2; exit 1 ;;
esac
if [ ! -x "$BIN_DIR/xianyu-server" ] || [ ! -x "$BIN_DIR/xianyu-tray" ]; then
echo "缺少 $ARCH 架构的桌面二进制:$BIN_DIR" >&2
exit 1
fi
if [ ! -d "$DIST_DIR/playwright-runtime/$ARCH/playwright-driver" ] || \
[ ! -d "$DIST_DIR/playwright-runtime/$ARCH/playwright-browsers" ]; then
echo "缺少 $ARCH 架构的 Playwright runtime:$DIST_DIR/playwright-runtime/$ARCH" >&2
exit 1
fi
rm -rf "$ROOT_DIR"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Helpers" "$APP/Contents/Resources"
cp "$BIN_DIR/xianyu-server" "$APP/Contents/Helpers/xianyu-server"
cp "$BIN_DIR/xianyu-tray" "$APP/Contents/MacOS/Ydisks闲鱼助手"
cp "$SCRIPT_DIR/uninstall.command" "$APP_DIR/卸载 Ydisks闲鱼助手.command"
cp "$SCRIPT_DIR/com.ydisks.xianyu-helper.server.plist.template" "$APP/Contents/Resources/"
cp "$SCRIPT_DIR/com.ydisks.xianyu-helper.tray.plist.template" "$APP/Contents/Resources/"
mkdir -p "$APP/Contents/Resources/playwright-runtime/$ARCH"
cp -R "$DIST_DIR/playwright-runtime/$ARCH/." "$APP/Contents/Resources/playwright-runtime/$ARCH/"
cp "$PROJECT_ROOT/icon/macos/Assets.car" "$APP/Contents/Resources/Assets.car"
cp "$PROJECT_ROOT/icon/macos/icon.icns" "$APP/Contents/Resources/icon.icns"
sed "s/__VERSION__/$VERSION/g" "$SCRIPT_DIR/Info.plist" > "$APP/Contents/Info.plist"
chmod 0755 "$APP/Contents/MacOS/Ydisks闲鱼助手" "$APP/Contents/Helpers/xianyu-server" "$APP_DIR/卸载 Ydisks闲鱼助手.command"
if [ -n "${MACOS_SIGNING_IDENTITY:-}" ]; then
sign_code() {
target="$1"
if [ -n "${MACOS_SIGNING_KEYCHAIN:-}" ]; then
codesign --force --sign "$MACOS_SIGNING_IDENTITY" \
--keychain "$MACOS_SIGNING_KEYCHAIN" --timestamp=none "$target"
else
codesign --force --sign "$MACOS_SIGNING_IDENTITY" \
--timestamp=none "$target"
fi
}
sign_nested_bundle() {
nested_bundle="$1"
echo "Signing nested bundle: $nested_bundle"
sign_code "$nested_bundle"
}
# Playwright runtime 中包含 Node 和 Chromium.app,必须在 App 签名之前完成签名。
# 先签每个 Mach-O 文件,再按目录深度从内到外签 bundle。Chromium 的
# .app 内还嵌套了 .framework/.xpc 和其他 helper .app;依赖 codesign --deep
# 自动推断顺序会在 amd64 runner 上留下未签名的 framework 主程序。
find "$APP/Contents/Resources/playwright-runtime" -type f -print | while IFS= read -r executable; do
if file "$executable" | grep -q 'Mach-O'; then
sign_code "$executable" || exit 1
fi
# `set -e` is not reliable for a while loop in a pipeline on macOS /bin/sh.
# Exit explicitly so a failed child signature reaches the parent script.
done || exit 1
find "$APP/Contents/Resources/playwright-runtime" -depth -type d \
\( -name '*.framework' -o -name '*.xpc' -o -name '*.app' \) -print |
while IFS= read -r nested_bundle; do
sign_nested_bundle "$nested_bundle" || exit 1
done || exit 1
# macOS 代码签名必须从内部组件开始,最后再签名 App 包本身。
sign_code "$APP/Contents/Helpers/xianyu-server"
sign_code "$APP/Contents/MacOS/Ydisks闲鱼助手"
sign_code "$APP"
codesign --verify --deep --strict --verbose=2 "$APP"
fi
if [ -n "${MACOS_SIGNING_IDENTITY:-}" ] && [ -z "${MACOS_INSTALLER_SIGNING_IDENTITY:-}" ]; then
echo 'MACOS_INSTALLER_SIGNING_IDENTITY 未设置,不能生成已签名 macOS 安装包' >&2
exit 1
fi
rm -f "$PACKAGE_PATH" "$UNSIGNED_PACKAGE_PATH"
pkgbuild \
--root "$ROOT_DIR" \
--component-plist "$SCRIPT_DIR/component.plist" \
--scripts "$SCRIPT_DIR/scripts" \
--identifier com.ydisks.xianyu-helper \
--version "$VERSION" \
--install-location / \
"$UNSIGNED_PACKAGE_PATH"
if [ -n "${MACOS_INSTALLER_SIGNING_IDENTITY:-}" ]; then
if [ -n "${MACOS_SIGNING_KEYCHAIN:-}" ]; then
productsign --sign "$MACOS_INSTALLER_SIGNING_IDENTITY" \
--keychain "$MACOS_SIGNING_KEYCHAIN" \
"$UNSIGNED_PACKAGE_PATH" "$PACKAGE_PATH"
else
productsign --sign "$MACOS_INSTALLER_SIGNING_IDENTITY" \
"$UNSIGNED_PACKAGE_PATH" "$PACKAGE_PATH"
fi
pkgutil --check-signature "$PACKAGE_PATH"
rm -f "$UNSIGNED_PACKAGE_PATH"
else
mv "$UNSIGNED_PACKAGE_PATH" "$PACKAGE_PATH"
fi