Skip to content

Commit

Permalink
deb: fixed bouncer removal when purging package (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Apr 12, 2023
1 parent e2bd175 commit 5f505bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 14 additions & 0 deletions debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

set -eu

BOUNCER="crowdsec-blocklist-mirror"
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/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@ set -eu

BOUNCER="crowdsec-blocklist-mirror"

#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 5f505bd

Please sign in to comment.