#!/usr/bin/env bash set -euo pipefail SERVICE_NAME="vmess-domain-rotator" usage() { cat <<'EOF' Usage: sudo bash scripts/uninstall_debian.sh This script will: - Stop and disable the systemd timer and service - Remove systemd unit files - Keep your git repository and all files intact Options: --service-name Service base name (default: vmess-domain-rotator) -h, --help Show help Examples: sudo bash scripts/uninstall_debian.sh EOF } while [[ $# -gt 0 ]]; do case "$1" in --service-name) SERVICE_NAME="$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 # Stop and disable timer if systemctl list-unit-files | grep -q "^${SERVICE_NAME}.timer"; then echo "Stopping and disabling ${SERVICE_NAME}.timer..." systemctl disable --now "${SERVICE_NAME}.timer" || true fi # Stop service if running if systemctl list-unit-files | grep -q "^${SERVICE_NAME}.service"; then echo "Stopping ${SERVICE_NAME}.service..." systemctl stop "${SERVICE_NAME}.service" || true fi # Remove systemd unit files echo "Removing systemd unit files..." rm -f "/etc/systemd/system/${SERVICE_NAME}.service" rm -f "/etc/systemd/system/${SERVICE_NAME}.timer" systemctl daemon-reload systemctl reset-failed echo "" echo "✓ Uninstall complete!" echo "" echo "Note: Your git repository and all files have been preserved." echo " To completely remove, manually delete the repository directory if needed." echo ""