mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-09 20:02:20 +08:00
Refs #8515 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
29 lines
1.1 KiB
Bash
Executable File
29 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# Installed as /usr/bin/clash-verge-service-uninstall. During an rpm upgrade the new %post
|
|
# reinstalls an existing Service before the previous package's %preun runs, and released
|
|
# %preun scripts uninstall it unconditionally through this path. Skip only that call: one
|
|
# made by a scriptlet of the transaction that %post recorded.
|
|
RECORD=/run/clash-verge-service-rpm-upgrade
|
|
UNINSTALLER=/usr/lib/clash-verge-rev/clash-verge-service-uninstall
|
|
|
|
# Fields after the parenthesised command name, which may itself contain spaces.
|
|
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
|
|
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."
|
|
exit 0
|
|
fi
|
|
pid="$(stat_field "$pid" 2)"
|
|
depth=$((depth + 1))
|
|
done
|
|
fi
|
|
|
|
exec "$UNINSTALLER" "$@"
|