浏览代码

winzard uninstall : check if user has registered bouncers (#579)

* check if user has registered bouncers
Thibault "bui" Koechlin 4 年之前
父节点
当前提交
6724c2aca4
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      wizard.sh

+ 16 - 0
wizard.sh

@@ -440,8 +440,23 @@ delete_bins() {
     rm -f ${CSCLI_BIN_INSTALLED}   
     rm -f ${CSCLI_BIN_INSTALLED}   
 }
 }
 
 
+check_running_bouncers() {
+    #when uninstalling, check if user still has bouncers
+    BOUNCERS_COUNT=$(${CSCLI_BIN} bouncers list -o=json | jq '. | length')
+    if [[ ${BOUNCERS_COUNT} -gt 0 ]] ; then
+        if [[ ${FORCE_MODE} == "false" ]]; then
+            echo "WARNING : You have at least one bouncer registered (cscli bouncers list)."
+            echo "WARNING : Uninstalling crowdsec with a running bouncer will let it in an unpredictable state."
+            echo "WARNING : If you want to uninstall crowdsec, you should first uninstall the bouncers."
+            echo "Specify --force to bypass this restriction."
+            exit 1
+        fi;
+    fi
+}
+
 # uninstall crowdsec and cscli
 # uninstall crowdsec and cscli
 uninstall_crowdsec() {
 uninstall_crowdsec() {
+
     systemctl stop crowdsec.service
     systemctl stop crowdsec.service
     systemctl disable crowdsec.service
     systemctl disable crowdsec.service
     ${CSCLI_BIN} dashboard remove -f -y
     ${CSCLI_BIN} dashboard remove -f -y
@@ -516,6 +531,7 @@ main() {
             log_err "Please run the wizard as root or with sudo"
             log_err "Please run the wizard as root or with sudo"
             exit 1
             exit 1
         fi
         fi
+        check_running_bouncers
         uninstall_crowdsec
         uninstall_crowdsec
         return
         return
     fi
     fi