| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #!/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 <path> Install directory (default: /opt/vmess-domain-rotator)
- --service-name <name> Service base name (default: vmess-domain-rotator)
- --keep-app-dir Keep install directory and files
- --remove-user <name> 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
|