#!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later # Copyright (C) 2026 overcatbe # # slynx-clean: what slynx wrote outside its own package, taken away again (after removepkg, or to # go back to another desktop). Not installed; run it from the source or the release tarball. # # sh slynx-clean shows what it would take away, changes nothing # sh slynx-clean --do takes it away # sh slynx-clean --do --own also slynx's own folders (asks first: the slynx keyring is in them) # # As yourself: your home. As root: the system. Run it both ways for everything. # # Home: the slynx block in ~/.config/gtk-3.0/gtk.css and gtk-4.0/gtk.css, fontconfig's # 50-slynx.conf, slynx's colours and fonts in ~/.config/kdeglobals. With --own: ~/.config/slynx, # ~/.cache/slynx, ~/.local/share/slynx (the keyring!), ~/.local/state/slynx. # Never touched: mimeapps.list, gtk-3.0/bookmarks, ~/.config/xkb, user-dirs.dirs and your home # folders (your choices, used by other desktops too). # System: rc.slynx-guard and its blocks in rc.local / rc.local_shutdown, the guard's log, slynx's # rc.firewall (its firewall can't load without slynx), the systemd units, slynx's SSH settings # (sshd_slynx.conf, its Include line, the phone code line in /etc/pam.d/sshd), the keyring's PAM # lines, slynx.json in the browsers' policies. With --own: /etc/slynx (the firewall's rules, the # phone codes) and /etc/slynx-guard (the never list). # Never touched: /etc/wireguard (your tunnels). DO=0 OWN=0 for a in "$@"; do case "$a" in --do) DO=1 ;; --own) OWN=1 ;; -h|--help) sed -n '5,25p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "slynx-clean: unknown: $a (--do, --own, --help)"; exit 2 ;; esac done FOUND=0 say() { FOUND=1; if [ $DO = 1 ]; then echo "removed: $*"; else echo "would remove: $*"; fi; } # a file rewritten through a temporary one beside it (its owner and mode kept) rewrite() { # $1 file, stdin the new text tmp="$1.slynx-clean.$$" cat > "$tmp" || { rm -f "$tmp"; return 1; } chmod --reference="$1" "$tmp" 2>/dev/null chown --reference="$1" "$tmp" 2>/dev/null mv -f "$tmp" "$1" } # a file with only blank lines left: away drop_if_empty() { [ -f "$1" ] && ! grep -q '[^[:space:]]' "$1" && rm -f "$1" } # ---------------------------------------------------------------- home clean_home() { cfg="${XDG_CONFIG_HOME:-$HOME/.config}" for f in "$cfg/gtk-3.0/gtk.css" "$cfg/gtk-4.0/gtk.css"; do if [ -f "$f" ] && grep -q 'slynx theme: start' "$f"; then say "the slynx block in $f" if [ $DO = 1 ]; then awk '/slynx theme: start/ {skip=1} !skip {print} /slynx theme: end/ {skip=0}' "$f" | rewrite "$f" drop_if_empty "$f" fi fi done f="$cfg/fontconfig/conf.d/50-slynx.conf" if [ -f "$f" ]; then say "$f" [ $DO = 1 ] && rm -f "$f" fi f="$cfg/kdeglobals" if [ -f "$f" ] && grep -q '^ColorScheme=slynx' "$f"; then say "slynx's colours and fonts in $f" if [ $DO = 1 ]; then awk ' /^\[/ { g = substr($0, 2, index($0, "]") - 2) own = (g ~ /^Colors:(Window|View|Button|Selection|Tooltip|Header|Complementary)$/ || g == "Icons") if (!own) print; next } own { next } g == "General" && /^(ColorScheme|font|fixed|menuFont|toolBarFont|smallestReadableFont)[=[ ]/ { next } { print }' "$f" | rewrite "$f" drop_if_empty "$f" fi fi if [ $OWN = 1 ]; then own="" for d in "$cfg/slynx" "${XDG_CACHE_HOME:-$HOME/.cache}/slynx" "${XDG_DATA_HOME:-$HOME/.local/share}/slynx" \ "${XDG_STATE_HOME:-$HOME/.local/state}/slynx"; do [ -e "$d" ] && own="$own $d" done if [ -n "$own" ]; then FOUND=1 if [ $DO = 1 ]; then echo "slynx's own folders:$own" echo "The slynx keyring (passwords) is in ${XDG_DATA_HOME:-$HOME/.local/share}/slynx/keyring and goes with them." printf "Remove them all? Type yes: " read answer if [ "$answer" = yes ]; then for d in $own; do rm -rf -- "$d" && echo "removed: $d"; done else echo "kept: slynx's own folders" fi else for d in $own; do say "$d (slynx's own; the keyring with it)"; done fi fi fi } # ---------------------------------------------------------------- system # SLYNX_CLEAN_ROOT=DIR: the system part on a copy under DIR (for trying it out; no services told) R="${SLYNX_CLEAN_ROOT:-}" clean_system() { f=$R/etc/rc.d/rc.slynx-guard if [ -f "$f" ] && [ ! -L "$f" ] && grep -q 'slynx traffic guard' "$f"; then say "$f" [ $DO = 1 ] && rm -f "$f" fi for f in $R/etc/rc.d/rc.local $R/etc/rc.d/rc.local_shutdown; do if [ -f "$f" ] && [ ! -L "$f" ] && grep -q '^# the slynx traffic guard' "$f"; then say "the slynx traffic guard block in $f" if [ $DO = 1 ]; then # the comment, if … fi, and the blank line slynx put before it awk ' !skip && $0 == "" { blank++; next } /^# the slynx traffic guard/ { blank = 0; skip = 1; next } skip { if ($0 == "fi") skip = 0; next } { while (blank > 0) { print ""; blank-- } print } END { while (blank > 0) { print ""; blank-- } }' "$f" | rewrite "$f" fi fi done for f in $R/var/log/slynx-guard.log $R/var/log/slynx-guard.log.old; do if [ -f "$f" ]; then say "$f" [ $DO = 1 ] && rm -f "$f" fi done f=$R/etc/rc.d/rc.firewall if [ -f "$f" ] && [ ! -L "$f" ] && grep -q '^# slynx firewall' "$f"; then say "$f (slynx's; its firewall can't load without slynx)" [ $DO = 1 ] && rm -f "$f" fi for u in slynx-guard.service slynx-firewall.service; do f="$R/etc/systemd/system/$u" if [ -f "$f" ]; then say "$f" if [ $DO = 1 ]; then [ -z "$R" ] && command -v systemctl >/dev/null && systemctl disable --now "$u" >/dev/null 2>&1 rm -f "$f" [ -z "$R" ] && command -v systemctl >/dev/null && systemctl daemon-reload fi fi done # SSH: the Include line (and slynx's two comment lines above it), its file, the phone code line f=$R/etc/ssh/sshd_config if [ -f "$f" ] && grep -q '^Include /etc/ssh/sshd_slynx.conf' "$f"; then say "the slynx Include line in $f, and /etc/ssh/sshd_slynx.conf" if [ $DO = 1 ]; then new="$f.slynx-clean.$$" grep -v -e '^Include /etc/ssh/sshd_slynx.conf' -e '^# slynx: its SSH settings come first' \ -e '^# and sshd is as before\.$' "$f" > "$new" if [ -z "$R" ] && command -v sshd >/dev/null && ! sshd -t -f "$new" 2>/dev/null; then rm -f "$new" echo " sshd doesn't accept $f without slynx's line: left as it was, look at it by hand" else chmod --reference="$f" "$new" 2>/dev/null mv -f "$new" "$f" rm -f $R/etc/ssh/sshd_slynx.conf [ -z "$R" ] && pkill -HUP -x sshd 2>/dev/null # open sessions stay; new ones get sshd's own settings fi fi elif [ -f $R/etc/ssh/sshd_slynx.conf ]; then say "/etc/ssh/sshd_slynx.conf" [ $DO = 1 ] && rm -f $R/etc/ssh/sshd_slynx.conf fi f=$R/etc/pam.d/sshd if [ -f "$f" ] && grep -q 'pam_slynx_totp\.so\|^# slynx: the phone code' "$f"; then say "the phone code lines in $f" [ $DO = 1 ] && grep -v -e 'pam_slynx_totp\.so' -e '^# slynx: the phone code' "$f" | rewrite "$f" fi # the keyring at login: Debian's profile, or the lines in system-auth (all optional ones) if [ -f $R/usr/share/pam-configs/slynx-keyring ] && command -v pam-auth-update >/dev/null; then say "the slynx-keyring PAM profile (pam-auth-update --disable)" [ $DO = 1 ] && [ -z "$R" ] && pam-auth-update --disable slynx-keyring fi f=$R/etc/pam.d/system-auth if [ -f "$f" ] && [ ! -L "$f" ] && grep -q 'pam_slynx_keyring\.so' "$f"; then say "the slynx keyring lines in $f" [ $DO = 1 ] && grep -v 'pam_slynx_keyring\.so' "$f" | rewrite "$f" fi for d in $R/etc/chromium/policies/managed $R/etc/opt/chrome/policies/managed $R/etc/brave/policies/managed; do if [ -f "$d/slynx.json" ]; then say "$d/slynx.json (extensions slynx blocked)" [ $DO = 1 ] && rm -f "$d/slynx.json" fi done if [ $OWN = 1 ]; then for d in $R/etc/slynx $R/etc/slynx-guard; do if [ -e "$d" ]; then say "$d (slynx's own: the firewall's rules and phone codes, the never list)" [ $DO = 1 ] && rm -rf -- "$d" fi done fi } if [ "$(id -u)" = 0 ] || [ -n "$R" ]; then clean_system echo "(the system; your home: run it again as yourself)" else clean_home echo "(your home; the system: run it again as root)" fi [ $FOUND = 0 ] && echo "nothing of slynx's left here" [ $DO = 0 ] && [ $FOUND = 1 ] && echo "nothing changed yet: --do takes it away" exit 0