Files
wehub-resource-sync 3e779be6f3
CI / test (3.14, ubuntu-24.04-arm) (push) Waiting to run
CI / lint (push) Failing after 13m4s
CI / test (3.11, ubuntu-latest) (push) Failing after 2m4s
CI / test (3.13, ubuntu-latest) (push) Successful in 13m30s
CI / test (3.14, ubuntu-latest) (push) Successful in 17m21s
CI / test (3.12, ubuntu-latest) (push) Successful in 17m55s
CI / discover-apps-ps (push) Successful in 1m56s
CI / test (3.9, ubuntu-latest) (push) Successful in 13m17s
CI / test (3.10, ubuntu-latest) (push) Successful in 26m21s
CI / audit (push) Successful in 13m38s
Deploy site / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:32:37 +08:00

87 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
# SPDX-License-Identifier: MIT
#
# Common post-remove hook for winpodx packaging (#255).
#
# Invoked by:
# debian/postrm ($1 = remove|purge|upgrade|...)
# rpm %postun ($1 = number, 0 = removed, >=1 = upgrade)
# aur winpodx.install (post_remove function passes "remove")
#
# Behaviour mirrors apt remove vs apt purge:
#
# * "upgrade" (rpm passes >= 1) -> exit 0; the package isn't going away.
# * "remove" -> run uninstall.sh --from-postrm --yes for every user
# with a winpodx config dir. Container, podman volume,
# config, and storage stay intact.
# * "purge" -> add --purge to the above. Container, volume, config,
# and storage all wiped.
#
# All cleanup is delegated to /usr/share/winpodx/uninstall.sh -- one
# canonical implementation shared with the curl install, pip install,
# and `winpodx uninstall` paths. See issue #255 for the consolidation
# rationale.
#
# --from-postrm tells uninstall.sh to skip the install-source detect
# step (we ARE the package manager removal -- detecting and re-exec'ing
# would loop) and the host-open stop-listener calls (the binary may
# already be gone).
set -e
MODE="${1:-remove}"
UNINSTALL_SH="/usr/share/winpodx/uninstall.sh"
# Normalise rpm / debian / aur mode arg.
case "$MODE" in
upgrade|1|2|3|4|5|6|7|8|9)
exit 0
;;
purge)
PURGE_FLAG="--purge"
;;
*)
PURGE_FLAG=""
;;
esac
# If for some reason the canonical script is missing (corrupted
# install, manual file removal), fall back to a minimal pkill so we
# don't leave processes pointing at a now-deleted binary.
if [ ! -x "$UNINSTALL_SH" ]; then
for home in /home/*; do
[ -d "$home" ] || continue
user=$(basename "$home")
[ -d "$home/.config/winpodx" ] || continue
runuser -u "$user" -- pkill -f 'python.*winpodx' >/dev/null 2>&1 || true
runuser -u "$user" -- pkill -f 'winpodx-app' >/dev/null 2>&1 || true
done
exit 0
fi
# Iterate every user (including root, in case of system-wide install).
# Each user gets their own uninstall.sh invocation so user-state under
# $HOME is cleaned up regardless of who installed the package.
cleanup_for_user() {
user="$1"
home="$2"
[ -d "$home/.config/winpodx" ] || return 0
# shellcheck disable=SC2086
runuser -u "$user" -- "$UNINSTALL_SH" --from-postrm --yes $PURGE_FLAG \
>/dev/null 2>&1 || true
}
for home in /home/*; do
[ -d "$home" ] || continue
user=$(basename "$home")
cleanup_for_user "$user" "$home"
done
# Also handle root, in case the install was system-wide root state.
if [ -d /root/.config/winpodx ]; then
# shellcheck disable=SC2086
"$UNINSTALL_SH" --from-postrm --yes $PURGE_FLAG >/dev/null 2>&1 || true
fi
exit 0