Files
Ydisks-Xianyu-Helper/packaging/macos/scripts/preinstall
T
Christ 07fea7d1e6 fix: 修复 macOS 旧版本升级安装失败
安装前卸载旧 Bundle ID 对应的应用与 LaunchAgent,避免安装器因组件标识变化保留旧应用,导致 postinstall 找不到新版本资源模板。
2026-08-11 22:51:40 +08:00

36 lines
1.2 KiB
Bash
Executable File

#!/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
APP="/Applications/Ydisks Xianyu Helper.app"
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
if [ -d "$APP" ]; then
existing_bundle_id="$(/usr/bin/plutil -extract CFBundleIdentifier raw -o - \
"$APP/Contents/Info.plist" 2>/dev/null || true)"
if [ "$existing_bundle_id" != "$EXPECTED_BUNDLE_ID" ]; then
echo "清理旧 Bundle ID 的应用:${existing_bundle_id:-未知}"
rm -rf "$APP"
fi
fi