uninstall.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
  3. if [ "$UID" -ne 0 ]; then
  4. echo "Must be run as root; try: sudo $0"
  5. exit 1
  6. fi
  7. # Detect systemd vs. regular init
  8. SYSTEMDUNITDIR=
  9. if [ -e /bin/systemctl -o -e /usr/bin/systemctl -o -e /usr/local/bin/systemctl -o -e /sbin/systemctl -o -e /usr/sbin/systemctl ]; then
  10. if [ -e /usr/bin/pkg-config ]; then
  11. SYSTEMDUNITDIR=`/usr/bin/pkg-config systemd --variable=systemdsystemunitdir`
  12. fi
  13. if [ -z "$SYSTEMDUNITDIR" -o ! -d "$SYSTEMDUNITDIR" ]; then
  14. if [ -d /usr/lib/systemd/system ]; then
  15. SYSTEMDUNITDIR=/usr/lib/systemd/system
  16. fi
  17. if [ -d /etc/systemd/system ]; then
  18. SYSTEMDUNITDIR=/etc/systemd/system
  19. fi
  20. fi
  21. fi
  22. echo "Killing any running zerotier-one service..."
  23. if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then
  24. systemctl stop zerotier-one.service
  25. systemctl disable zerotier-one.service
  26. else
  27. if [ -f /sbin/service -o -f /usr/sbin/service -o -f /bin/service -o -f /usr/bin/service ]; then
  28. service zerotier-one stop
  29. fi
  30. fi
  31. sleep 1
  32. if [ -f /var/lib/zerotier-one/zerotier-one.pid ]; then
  33. kill -TERM `cat /var/lib/zerotier-one/zerotier-one.pid`
  34. sleep 1
  35. fi
  36. if [ -f /var/lib/zerotier-one/zerotier-one.pid ]; then
  37. kill -KILL `cat /var/lib/zerotier-one/zerotier-one.pid`
  38. fi
  39. if [ -f /etc/init.d/zerotier-one ]; then
  40. echo "Removing SysV init items..."
  41. if [ -f /sbin/chkconfig -o -f /usr/sbin/chkconfig -o -f /bin/chkconfig -o -f /usr/bin/chkconfig ]; then
  42. chkconfig zerotier-one off
  43. fi
  44. rm -f /etc/init.d/zerotier-one
  45. find /etc/rc*.d -type f -name '???zerotier-one' -print0 | xargs -0 rm -f
  46. fi
  47. if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" -a -f "$SYSTEMDUNITDIR/zerotier-one.service" ]; then
  48. echo "Removing systemd service..."
  49. rm -f "$SYSTEMDUNITDIR/zerotier-one.service"
  50. fi
  51. echo "Erasing binary and support files..."
  52. if [ -d /var/lib/zerotier-one ]; then
  53. cd /var/lib/zerotier-one
  54. rm -rf zerotier-one *.persist identity.public *.log *.pid *.sh updates.d networks.d iddb.d root-topology ui
  55. fi
  56. echo "Erasing anything installed into system bin directories..."
  57. rm -f /usr/local/bin/zerotier-cli /usr/bin/zerotier-cli /usr/local/bin/zerotier-idtool /usr/bin/zerotier-idtool
  58. echo "Done."
  59. echo
  60. echo "Your ZeroTier One identity is still preserved in /var/lib/zerotier-one"
  61. echo "as identity.secret and can be manually deleted if you wish. Save it if"
  62. echo "you wish to re-use the address of this node, as it cannot be regenerated."
  63. echo
  64. exit 0