This commit is contained in:
2025-11-07 09:47:03 +01:00
parent 646e574059
commit 55620c52d4
22 changed files with 1835 additions and 2 deletions

115
uninstall.sh Normal file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/env bash
set -euo pipefail
C_RESET="\033[0m"; C_DIM="\033[2m"; C_BOLD="\033[1m"
C_RED="\033[31m"; C_GRN="\033[32m"; C_BLU="\033[34m"; C_YEL="\033[33m"
info(){ echo -e "${C_BLU}${C_RESET} $*"; }
ok(){ echo -e "${C_GRN}${C_RESET} $*"; }
warn(){ echo -e "${C_YEL}!${C_RESET} $*"; }
fail(){ echo -e "${C_RED}${C_RESET} $*"; }
trap 'fail "An unexpected error occurred. Exiting."' ERR
PANEL_ROOT="/var/www/torpanel"
PANEL_PUBLIC="$PANEL_ROOT/public"
STATE_DIR="/var/lib/torpanel"
LOG_DIR="/var/log/torpanel"
ETC_APP="/etc/torpanel"
NGX_SITE_AVAIL="/etc/nginx/sites-available/torpanel"
NGX_SITE_ENABL="/etc/nginx/sites-enabled/torpanel"
SUDOERS_FILE="/etc/sudoers.d/torpanel"
TOR_TORRC_D="/etc/tor/torrc.d"
TOR_PANEL_CONF="$TOR_TORRC_D/99-torpanel.conf"
COLLECTOR_BIN="/usr/local/bin/torpanel-collect.py"
SVC="/etc/systemd/system/torpanel-collector.service"
TIMER="/etc/systemd/system/torpanel-collector.timer"
PKGS=("tor" "tor-geoipdb" "nginx" "php-fpm" "php-cli" "php-json" "php-curl" "php-zip" "php-common" "php-opcache")
YES=0
PURGE=0
for arg in "${@:-}"; do
case "$arg" in
-y|--yes) YES=1 ;;
-h|--help)
echo "Usage: sudo bash uninstall.sh [--yes]"
echo " --yes : don't ask for confirmation (defaults to no package purge)"
exit 0
;;
*) ;;
esac
done
if [[ $EUID -ne 0 ]]; then fail "Run as root (sudo)."; exit 1; fi
echo -e "${C_BOLD}Uninstalling TorPanel...${C_RESET}"
# Step 1: confirm uninstall
if [[ $YES -ne 1 ]]; then
read -r -p "This will remove TorPanel files/configs. Continue? [y/N] " ans
case "${ans,,}" in y|yes) ;; *) warn "Aborted by user."; exit 0 ;; esac
fi
# Step 2: ask if we should purge packages (only when not --yes)
if [[ $YES -ne 1 ]]; then
echo
echo -e "${C_DIM}Optional:${C_RESET} You can also ${C_BOLD}purge Tor/Nginx/PHP packages${C_RESET} installed by the panel."
read -r -p "Also purge Tor/Nginx/PHP packages and autoremove? [y/N] " pans
case "${pans,,}" in y|yes) PURGE=1 ;; *) PURGE=0 ;; esac
else
PURGE=0
fi
info "Stopping services/timers if present"
systemctl disable --now torpanel-collector.timer 2>/dev/null || true
systemctl disable --now torpanel-collector.service 2>/dev/null || true
ok "Services/timers handled"
info "Removing systemd units"
rm -f "$SVC" "$TIMER"
systemctl daemon-reload
ok "Systemd units removed"
info "Removing collector binary"
rm -f "$COLLECTOR_BIN"
ok "Collector removed"
info "Removing Nginx site"
rm -f "$NGX_SITE_ENABL" "$NGX_SITE_AVAIL"
if nginx -t >/dev/null 2>&1; then
systemctl reload nginx || true
else
warn "Nginx config test failed (maybe not installed); skipping reload"
fi
ok "Nginx site removed"
info "Removing TorPanel app/config/state"
rm -rf "$PANEL_ROOT" "$STATE_DIR" "$LOG_DIR" "$ETC_APP"
ok "Files removed"
info "Removing torrc override and reloading Tor"
rm -f "$TOR_PANEL_CONF"
systemctl reload tor 2>/dev/null || true
ok "Tor reloaded"
info "Removing sudoers entry"
rm -f "$SUDOERS_FILE"
ok "Sudoers cleaned"
if [[ $PURGE -eq 1 ]]; then
info "Purging Tor/Nginx/PHP packages"
apt-get purge -y "${PKGS[@]}" || true
apt-get autoremove -y || true
ok "Packages purged"
fi
echo
echo -e "${C_BOLD}All clean!${C_RESET}"
if [[ $PURGE -eq 1 ]]; then
echo -e " TorPanel removed and packages were purged."
else
echo -e " TorPanel files and overrides have been removed (packages remain)."
fi
echo -e " Reinstall anytime with: ${C_GRN}sudo bash install.sh${C_RESET}"