fix: 修复 macOS 旧版本升级安装失败
安装前卸载旧 Bundle ID 对应的应用与 LaunchAgent,避免安装器因组件标识变化保留旧应用,导致 postinstall 找不到新版本资源模板。
This commit is contained in:
1 parent
761d57f9bf
commit
07fea7d1e6
1 file changed
+35
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/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
|
||||
Reference in new issue
Block a user