Skip to content

Commit

Permalink
deb: fixed bouncer removal when purging package (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Apr 12, 2023
1 parent 3861061 commit 7f6ba97
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
14 changes: 14 additions & 0 deletions debian/crowdsec-firewall-bouncer-iptables.postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -eu

BOUNCER="crowdsec-firewall-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
11 changes: 2 additions & 9 deletions debian/crowdsec-firewall-bouncer-iptables.prerm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@ set -eu

BOUNCER="crowdsec-firewall-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"
14 changes: 14 additions & 0 deletions debian/crowdsec-firewall-bouncer-nftables.postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -eu

BOUNCER="crowdsec-firewall-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
11 changes: 2 additions & 9 deletions debian/crowdsec-firewall-bouncer-nftables.prerm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@ set -eu

BOUNCER="crowdsec-firewall-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"
6 changes: 3 additions & 3 deletions scripts/_bouncer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 7f6ba97

Please sign in to comment.