diff --git a/src-tauri/packages/linux/post-install-rpm.sh b/src-tauri/packages/linux/post-install-rpm.sh index 0513f1ece..a1f6218d3 100644 --- a/src-tauri/packages/linux/post-install-rpm.sh +++ b/src-tauri/packages/linux/post-install-rpm.sh @@ -22,6 +22,7 @@ write_upgrade_marker() { record_transaction() { local start start="$(sed 's/.*) //' "/proc/$PPID/stat" | cut -d' ' -f20)" + [ -n "$start" ] || return 1 (umask 022 && printf '%s %s\n' "$PPID" "$start" >"$TRANSACTION_RECORD") } @@ -64,15 +65,18 @@ reinstall_existing_service() { # Upgrades keep an existing Service current; first installs and explicit removals never add one. # A symlinked unit is masked or managed by the administrator and is left alone. # The previous %preun runs after this script; the record keeps it from removing the Service. -# The marker stays as a fallback should it still be removed; the app only acts on it if the Service is not ready. +# Without a record that %preun removes the Service, so the marker makes the app offer a reinstall. if [ "$1" -ge 2 ] && [ -d /run/systemd/system ] && [ -f "$SERVICE_UNIT_FILE" ] && [ ! -L "$SERVICE_UNIT_FILE" ]; then - record_transaction || true + recorded=yes + record_transaction || recorded=no gid="$(existing_service_gid)" - write_upgrade_marker "$gid" if [ -z "$gid" ]; then echo "Warning: the Clash Verge Service group could not be resolved; Clash Verge will offer to reinstall the Service." >&2 + write_upgrade_marker "" + elif reinstall_existing_service "$gid" && [ "$recorded" = yes ]; then + rm -f "$UPGRADE_MARKER" else - reinstall_existing_service "$gid" || true + write_upgrade_marker "$gid" fi fi diff --git a/src-tauri/packages/linux/service-uninstall.sh b/src-tauri/packages/linux/service-uninstall.sh index 5e14543fb..417a1e422 100755 --- a/src-tauri/packages/linux/service-uninstall.sh +++ b/src-tauri/packages/linux/service-uninstall.sh @@ -11,13 +11,13 @@ stat_field() { sed 's/.*) //' "/proc/$1/stat" 2>/dev/null | cut -d' ' -f"$2" } -if [ -f "$RECORD" ] && [ ! -L "$RECORD" ] && read -r txn_pid txn_start <"$RECORD"; then +if [ -f "$RECORD" ] && [ ! -L "$RECORD" ] && read -r txn_pid txn_start <"$RECORD" && [ -n "$txn_start" ]; then pid=$PPID depth=0 while [ "$depth" -lt 4 ] && [ -n "$pid" ] && [ "$pid" -gt 1 ]; do if [ "$pid" = "$txn_pid" ] && [ "$(stat_field "$pid" 20)" = "$txn_start" ]; then rm -f "$RECORD" - echo "Keeping the Clash Verge Service reinstalled by this upgrade." + echo "Keeping the Clash Verge Service through this upgrade." exit 0 fi pid="$(stat_field "$pid" 2)"