uninstall.sh 724 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. set -e
  3. if [ $UID -ne 0 ]; then
  4. echo "请用root用户运行当前脚本 (su root)" && exit 1
  5. fi
  6. APP_COMPARTMENT="nsq-server"
  7. APP_MODULE="nsq-server"
  8. root_dir=/opt/$APP_COMPARTMENT/$APP_MODULE
  9. if [ ! -d "$root_dir" ]; then
  10. mkdir -p $root_dir
  11. fi
  12. # Don't delete `/`
  13. if [[ $root_dir == "/" ]]; then
  14. echo "root_dir is /, exit"
  15. exit 1
  16. fi
  17. systemctl stop $APP_MODULE
  18. systemctl disable $APP_MODULE
  19. rm -rf $root_dir
  20. rm -f /etc/systemd/system/$APP_MODULE.service
  21. if [ -d "/opt/$APP_COMPARTMENT" ] && [ -z "$(ls -A /opt/$APP_COMPARTMENT)" ]; then
  22. rmdir /opt/$APP_COMPARTMENT
  23. else
  24. echo "目录 /opt/$APP_COMPARTMENT 非空,不删除"
  25. fi
  26. echo "卸载成功!"
  27. systemctl daemon-reload