Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deb: fixed bouncer removal when purging package #48

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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