uninstall.sh 691 B

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