#!/usr/bin/env bash set -euo pipefail SERVICE_NAME="vmess-domain-rotator" APP_DIR="/opt/vmess-domain-rotator" KEEP_APP_DIR="0" REMOVE_USER="0" RUN_USER="vmessrotator" usage() { cat <<'EOF' Usage: sudo bash scripts/uninstall_debian.sh [options] Options: --app-dir Install directory (default: /opt/vmess-domain-rotator) --service-name Service base name (default: vmess-domain-rotator) --keep-app-dir Keep install directory and files --remove-user Remove this service user after uninstall -h, --help Show help Examples: sudo bash scripts/uninstall_debian.sh sudo bash scripts/uninstall_debian.sh --keep-app-dir sudo bash scripts/uninstall_debian.sh --remove-user vmessrotator EOF } while [[ $# -gt 0 ]]; do case "$1" in --app-dir) APP_DIR="$2" shift 2 ;; --service-name) SERVICE_NAME="$2" shift 2 ;; --keep-app-dir) KEEP_APP_DIR="1" shift ;; --remove-user) REMOVE_USER="1" RUN_USER="$2" shift 2 ;; -h|--help) usage exit 0 ;; *) echo "Unknown option: $1" >&2 usage exit 1 ;; esac done if [[ "$(id -u)" -ne 0 ]]; then echo "Please run as root (use sudo)." >&2 exit 1 fi if systemctl list-unit-files | grep -q "^${SERVICE_NAME}.timer"; then systemctl disable --now "${SERVICE_NAME}.timer" || true fi if systemctl list-unit-files | grep -q "^${SERVICE_NAME}.service"; then systemctl stop "${SERVICE_NAME}.service" || true fi rm -f "/etc/systemd/system/${SERVICE_NAME}.service" rm -f "/etc/systemd/system/${SERVICE_NAME}.timer" systemctl daemon-reload systemctl reset-failed if [[ "$KEEP_APP_DIR" != "1" ]]; then rm -rf "$APP_DIR" fi if [[ "$REMOVE_USER" == "1" ]]; then if id -u "$RUN_USER" >/dev/null 2>&1; then userdel "$RUN_USER" || true fi fi echo "Uninstall completed." if [[ "$KEEP_APP_DIR" == "1" ]]; then echo "Kept app directory: ${APP_DIR}" else echo "Removed app directory: ${APP_DIR}" fi