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

* check if user has registered bouncers
This commit is contained in:
Thibault "bui" Koechlin 2021-01-19 12:31:03 +01:00 committed by GitHub
parent 13172fc490
commit 6724c2aca4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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