Files
Ydisks-Xianyu-Helper/packaging/macos/scripts/preinstall
T
Christ 9cb50a229c fix: 兼容 macOS localized 应用安装路径
macOS 安装器可能将应用放入 Ydisks Xianyu Helper.localized 目录,安装脚本改为自动发现普通路径和 localized 路径,避免 postinstall 找不到模板文件。
2026-08-11 23:27:33 +08:00

42 lines
1.3 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
INSTALL_LOG="/var/log/ydisks-xianyu-helper-install.log"
exec >>"$INSTALL_LOG" 2>&1
trap 'exit_code=$?; printf "[%s] preinstall exit code: %s\\n" "$(date -u "+%Y-%m-%dT%H:%M:%SZ")" "$exit_code"' EXIT
printf '\n[%s] preinstall start; uid=%s; user=%s; args=%s\n' \
"$(date -u '+%Y-%m-%dT%H:%M:%SZ')" "$(id -u)" "$(id -un)" "$*"
set -x
EXPECTED_BUNDLE_ID="com.ydisks.xianyu-helper"
CONSOLE_USER="$(stat -f '%Su' /dev/console)"
if [ "$CONSOLE_USER" != "root" ] && [ -n "$CONSOLE_USER" ]; then
UID_VALUE="$(id -u "$CONSOLE_USER")"
for label in \
"com.ydisks.xianyu-helper.server" \
"com.ydisks.xianyu-helper.tray" \
"com.christ.ydisks-xianyu-helper.server" \
"com.christ.ydisks-xianyu-helper.tray"
do
launchctl bootout "gui/$UID_VALUE/$label" >/dev/null 2>&1 || true
done
fi
for app_path in \
"/Applications/Ydisks Xianyu Helper.app" \
"/Applications/Ydisks Xianyu Helper.localized/Ydisks Xianyu Helper.app"
do
if [ ! -d "$app_path" ]; then
continue
fi
existing_bundle_id="$(/usr/bin/plutil -extract CFBundleIdentifier raw -o - \
"$app_path/Contents/Info.plist" 2>/dev/null || true)"
if [ "$existing_bundle_id" != "$EXPECTED_BUNDLE_ID" ]; then
echo "清理旧 Bundle ID 的应用:${existing_bundle_id:-未知}($app_path)"
rm -rf "$app_path"
fi
done