zapretgui/packaging/linux/uninstall.sh
loop-uh 9edcd342a1
All checks were successful
Zapret source guards / validate (push) Successful in 9s
Windows-сборка / Dev Dev 21.1.7.304 опубликован
Linux: the helper service works under systemd, OpenRC and sysvinit (Devuan), chosen by the machine itself
initsys.sh finds the init system (running systemd, then OpenRC, then sysvinit, else none) and installs/starts/stops/removes the service
for it: the unit, an openrc-run script or an LSB script. install.sh, uninstall.sh and the .deb scripts use it; the .deb no longer
depends on systemd; the AppImage asks for the helper's socket instead of systemctl; hints in the program name the command of the
init system found. The OpenRC and the sysv scripts were run for real (Debian 13 chroot with OpenRC, start-stop-daemon).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 09:04:01 -05:00

40 lines
1.9 KiB
Shell
Executable file

#!/bin/bash
# Removes what install.sh put on the system, the firewall table included. The people's own data
# (~/.config/zapretgui, ~/.local/share/zapretgui, ...) stays unless --purge-user-data NAME is given.
set -euo pipefail
[ "$(id -u)" = 0 ] || { echo "run it with sudo" >&2; exit 1; }
# the init-system code comes with the program (install.sh puts it next to this script)
HERE="$(cd "$(dirname "$0")" && pwd)"
if [ -r "$HERE/initsys.sh" ]; then
# shellcheck disable=SC1091
. "$HERE/initsys.sh"
zg_service_remove
else
systemctl disable --now zapretgui-helper.service 2>/dev/null || true
fi
# the helper removes its table when it stops; this is the second net
nft delete table inet zapretgui 2>/dev/null || true
pkill -x nfqws2 2>/dev/null || true
rm -f /usr/lib/systemd/system/zapretgui-helper.service /usr/share/polkit-1/rules.d/50-zapretgui.rules \
/usr/share/applications/zapretgui.desktop
find /usr/share/icons/hicolor -name 'zapretgui.*' -delete 2>/dev/null || true
rm -rf /opt/zapretgui /run/zapretgui
command -v systemctl >/dev/null && systemctl daemon-reload 2>/dev/null || true
command -v update-desktop-database >/dev/null && update-desktop-database -q /usr/share/applications || true
getent group zapretgui >/dev/null && groupdel zapretgui 2>/dev/null || true
# the copy of /etc/hosts from before the first change made by the program: removed with the program, unless /etc/hosts
# still differs from it (then it is the only way back, and it stays)
if [ -f /var/lib/zapretgui/hosts.original ] && cmp -s /var/lib/zapretgui/hosts.original /etc/hosts; then
rm -rf /var/lib/zapretgui
fi
if [ "${1:-}" = "--purge-user-data" ]; then
home="$(getent passwd "${2:?user name}" | cut -d: -f6)"
rm -rf "$home/.config/zapretgui" "$home/.local/share/zapretgui" "$home/.local/state/zapretgui" "$home/.cache/zapretgui" \
"$home/.config/autostart/zapretgui.desktop"
echo "the data of ${2} was removed"
fi
echo "Zapret is removed."