From 6724c2aca4037ee4279931e510622cd0aee12dfc Mon Sep 17 00:00:00 2001 From: "Thibault \"bui\" Koechlin" Date: Tue, 19 Jan 2021 12:31:03 +0100 Subject: [PATCH] winzard uninstall : check if user has registered bouncers (#579) * check if user has registered bouncers --- wizard.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wizard.sh b/wizard.sh index 9e5952cf1..556e91504 100755 --- a/wizard.sh +++ b/wizard.sh @@ -440,8 +440,23 @@ delete_bins() { 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() { + systemctl stop crowdsec.service systemctl disable crowdsec.service ${CSCLI_BIN} dashboard remove -f -y @@ -516,6 +531,7 @@ main() { log_err "Please run the wizard as root or with sudo" exit 1 fi + check_running_bouncers uninstall_crowdsec return fi