From 6ae9ea0c94c6178ed5617ed30abd7999ed2b4655 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Wed, 12 Apr 2023 16:08:30 +0200 Subject: [PATCH] deb: fixed bouncer removal when purging package (#60) --- debian/postrm | 14 ++++++++++++++ debian/prerm | 11 ++--------- scripts/_bouncer.sh | 6 +++--- 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 debian/postrm diff --git a/debian/postrm b/debian/postrm new file mode 100644 index 0000000..f45c61b --- /dev/null +++ b/debian/postrm @@ -0,0 +1,14 @@ +#!/bin/sh + +set -eu + +BOUNCER="crowdsec-custom-bouncer" +CONFIG="/etc/crowdsec/bouncers/$BOUNCER.yaml" + +if [ "$1" = "purge" ]; then + if [ -f "$CONFIG.id" ]; then + bouncer_id=$(cat "$CONFIG.id") + cscli -oraw bouncers delete "$bouncer_id" 2>/dev/null || true + rm -f "$CONFIG.id" + fi +fi diff --git a/debian/prerm b/debian/prerm index ac88779..c0998e4 100644 --- a/debian/prerm +++ b/debian/prerm @@ -4,12 +4,5 @@ set -eu BOUNCER="crowdsec-custom-bouncer" -#shellcheck source=./scripts/_bouncer.sh -. "/usr/lib/$DPKG_MAINTSCRIPT_PACKAGE/_bouncer.sh" - -systemctl stop "$SERVICE" || echo "cannot stop service" -systemctl disable "$SERVICE" || echo "cannot disable service" - -if [ "$1" = "purge" ]; then - delete_bouncer -fi +systemctl stop "$BOUNCER" || echo "cannot stop service" +systemctl disable "$BOUNCER" || echo "cannot disable service" diff --git a/scripts/_bouncer.sh b/scripts/_bouncer.sh index 04b1baa..5a75421 100644 --- a/scripts/_bouncer.sh +++ b/scripts/_bouncer.sh @@ -89,7 +89,7 @@ config_not_set() { before=$(cat "$CONFIG") # shellcheck disable=SC2016 - after=$(envsubst '\$$varname' < "$CONFIG") + after=$(envsubst "\$$varname" < "$CONFIG") if [ "$before" = "$after" ]; then return 1 @@ -99,9 +99,9 @@ config_not_set() { need_api_key() { if config_not_set 'API_KEY'; then - return 1 + return 0 fi - return 0 + return 1 } # Interpolate a variable in the config file with a value.