uninstall_debian.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SERVICE_NAME="vmess-domain-rotator"
  4. usage() {
  5. cat <<'EOF'
  6. Usage: sudo bash scripts/uninstall_debian.sh
  7. This script will:
  8. - Stop and disable the systemd timer and service
  9. - Remove systemd unit files
  10. - Keep your git repository and all files intact
  11. Options:
  12. --service-name <name> Service base name (default: vmess-domain-rotator)
  13. -h, --help Show help
  14. Examples:
  15. sudo bash scripts/uninstall_debian.sh
  16. EOF
  17. }
  18. while [[ $# -gt 0 ]]; do
  19. case "$1" in
  20. --service-name)
  21. SERVICE_NAME="$2"
  22. shift 2
  23. ;;
  24. -h|--help)
  25. usage
  26. exit 0
  27. ;;
  28. *)
  29. echo "Unknown option: $1" >&2
  30. usage
  31. exit 1
  32. ;;
  33. esac
  34. done
  35. if [[ "$(id -u)" -ne 0 ]]; then
  36. echo "Please run as root (use sudo)." >&2
  37. exit 1
  38. fi
  39. # Stop and disable timer
  40. if systemctl list-unit-files | grep -q "^${SERVICE_NAME}.timer"; then
  41. echo "Stopping and disabling ${SERVICE_NAME}.timer..."
  42. systemctl disable --now "${SERVICE_NAME}.timer" || true
  43. fi
  44. # Stop service if running
  45. if systemctl list-unit-files | grep -q "^${SERVICE_NAME}.service"; then
  46. echo "Stopping ${SERVICE_NAME}.service..."
  47. systemctl stop "${SERVICE_NAME}.service" || true
  48. fi
  49. # Remove systemd unit files
  50. echo "Removing systemd unit files..."
  51. rm -f "/etc/systemd/system/${SERVICE_NAME}.service"
  52. rm -f "/etc/systemd/system/${SERVICE_NAME}.timer"
  53. systemctl daemon-reload
  54. systemctl reset-failed
  55. echo ""
  56. echo "✓ Uninstall complete!"
  57. echo ""
  58. echo "Note: Your git repository and all files have been preserved."
  59. echo " To completely remove, manually delete the repository directory if needed."
  60. echo ""