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

Moved install helper to a library, shorter code #256

Merged
merged 7 commits into from
Apr 11, 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
88 changes: 0 additions & 88 deletions config/helper.sh

This file was deleted.

4 changes: 4 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ Description: Firewall bouncer for Crowdsec (iptables+ipset)
Depends: iptables, ipset, gettext-base
Replaces: crowdsec-firewall-bouncer
Conflicts: crowdsec-firewall-bouncer-nftables
Section: admin
Priority: optional

Package: crowdsec-firewall-bouncer-nftables
Architecture: any
Description: Firewall bouncer for Crowdsec (nftables)
Depends: nftables, gettext-base
Replaces: crowdsec-firewall-bouncer
Conflicts: crowdsec-firewall-bouncer-iptables
Section: admin
Priority: optional
12 changes: 6 additions & 6 deletions debian/crowdsec-firewall-bouncer-iptables.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
systemctl daemon-reload

BOUNCER="crowdsec-firewall-bouncer"
CONFIG="/etc/crowdsec/bouncers/$BOUNCER.yaml"
SERVICE="$BOUNCER.service"
BOUNCER_PREFIX="FirewallBouncer"

helper="/usr/lib/$DPKG_MAINTSCRIPT_PACKAGE/helper.sh"
#shellcheck source=./scripts/_bouncer.sh
. "/usr/lib/$DPKG_MAINTSCRIPT_PACKAGE/_bouncer.sh"
START=1

if [ "$1" = "configure" ]; then
if $helper need-api-key "$CONFIG"; then
if ! $helper set-api-key "$CONFIG" "FirewallBouncer"; then
if need_api_key; then
if ! set_api_key; then
START=0
fi
fi
fi

systemctl --quiet is-enabled "$SERVICE" || systemctl unmask "$SERVICE" && systemctl enable "$SERVICE"

$helper set-local-port "$CONFIG"
set_local_port

if [ "$START" -eq 0 ]; then
echo "no api key was generated, you can generate one on your LAPI server by running 'cscli bouncers add <bouncer_name>' and add it to '$CONFIG'" >&2
Expand Down
14 changes: 0 additions & 14 deletions debian/crowdsec-firewall-bouncer-iptables.postrm

This file was deleted.

15 changes: 13 additions & 2 deletions debian/crowdsec-firewall-bouncer-iptables.prerm
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#!/bin/sh

systemctl stop crowdsec-firewall-bouncer || echo "cannot stop service"
systemctl disable crowdsec-firewall-bouncer || echo "cannot disable service"
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
12 changes: 6 additions & 6 deletions debian/crowdsec-firewall-bouncer-nftables.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
systemctl daemon-reload

BOUNCER="crowdsec-firewall-bouncer"
CONFIG="/etc/crowdsec/bouncers/$BOUNCER.yaml"
SERVICE="$BOUNCER.service"
BOUNCER_PREFIX="FirewallBouncer"

helper="/usr/lib/$DPKG_MAINTSCRIPT_PACKAGE/helper.sh"
#shellcheck source=./scripts/_bouncer.sh
. "/usr/lib/$DPKG_MAINTSCRIPT_PACKAGE/_bouncer.sh"
START=1

if [ "$1" = "configure" ]; then
if $helper need-api-key "$CONFIG"; then
if ! $helper set-api-key "$CONFIG" "FirewallBouncer"; then
if need_api_key; then
if ! set_api_key; then
START=0
fi
fi
fi

systemctl --quiet is-enabled "$SERVICE" || systemctl unmask "$SERVICE" && systemctl enable "$SERVICE"

$helper set-local-port "$CONFIG"
set_local_port

if [ "$START" -eq 0 ]; then
echo "no api key was generated, you can generate one on your LAPI server by running 'cscli bouncers add <bouncer_name>' and add it to '$CONFIG'" >&2
Expand Down
14 changes: 0 additions & 14 deletions debian/crowdsec-firewall-bouncer-nftables.postrm

This file was deleted.

15 changes: 13 additions & 2 deletions debian/crowdsec-firewall-bouncer-nftables.prerm
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#!/bin/sh

systemctl stop crowdsec-firewall-bouncer || echo "cannot stop service"
systemctl disable crowdsec-firewall-bouncer || echo "cannot disable service"
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
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ override_dh_auto_install:
for BACKEND in iptables nftables; do \
PKG="$$BOUNCER-$$BACKEND"; \
install -D -m 0755 $$BOUNCER -t "debian/$$PKG/usr/bin/"; \
install -D -m 0700 config/helper.sh -t "debian/$$PKG/usr/lib/$$PKG/"; \
install -D -m 0600 scripts/_bouncer.sh -t "debian/$$PKG/usr/lib/$$PKG/"; \
BACKEND=$$BACKEND envsubst '$$BACKEND' < config/$$BOUNCER.yaml | install -D -m 0600 /dev/stdin "debian/$$PKG/etc/crowdsec/bouncers/$$BOUNCER.yaml"; \
BIN="/usr/bin/$$BOUNCER" CFG="/etc/crowdsec/bouncers" envsubst '$$BIN $$CFG' < "config/$$BOUNCER.service" | install -D -m 0644 /dev/stdin "debian/$$PKG/etc/systemd/system/$$BOUNCER.service"; \
done
Loading