Skip to content

Commit

Permalink
Merge pull request #148 from crowdsecurity/port
Browse files Browse the repository at this point in the history
improve port management as well for rpm
  • Loading branch information
sabban authored Feb 17, 2022
2 parents 4f89309 + 542f52d commit 977f3b6
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions rpm/SPECS/crowdsec-firewall-bouncer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ rm -rf %{buildroot}

systemctl daemon-reload


START=0
CSCLI=/usr/bin/cscli

if [ "$1" == "1" ] ; then
type cscli > /dev/null

Expand All @@ -84,6 +85,13 @@ else
START=1
fi

if command -v "$CSCLI" >/dev/null; then
PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2)
if [ ! -z "$PORT" ]; then
sed -i "s/localhost:8080/localhost:${PORT}/g" /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
fi
fi

if [ ${START} -eq 0 ] ; then
echo "no api key was generated, won't start service"
else
Expand All @@ -95,14 +103,6 @@ fi
* Tue Feb 16 2021 Manuel Sabban <[email protected]>
- First initial packaging

%preun -p /bin/bash

if [ "$1" == "0" ] ; then
systemctl stop crowdsec-firewall-bouncer || echo "cannot stop service"
systemctl disable crowdsec-firewall-bouncer || echo "cannot disable service"
fi




%package -n crowdsec-firewall-bouncer-nftables
Expand All @@ -120,11 +120,10 @@ Requires: nftables,gettext
systemctl daemon-reload

START=0
CSCLI=/usr/bin/cscli

if [ "$1" == "1" ] ; then
type cscli > /dev/null

if [ "$?" -eq "0" ] ; then
if command -v "$CSCLI" >/dev/null; then
START=1
echo "cscli/crowdsec is present, generating API key"
unique=`date +%s`
Expand All @@ -146,12 +145,26 @@ else
START=1
fi

if command -v "$CSCLI" >/dev/null; then
PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2)
if [ ! -z "$PORT" ]; then
sed -i "s/localhost:8080/localhost:${PORT}/g" /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
fi
fi

if [ ${START} -eq 0 ] ; then
echo "no api key was generated, won't start service"
else
systemctl start crowdsec-firewall-bouncer
fi

%preun -p /bin/bash

if [ "$1" == "0" ] ; then
systemctl stop crowdsec-firewall-bouncer || echo "cannot stop service"
systemctl disable crowdsec-firewall-bouncer || echo "cannot disable service"
fi

%preun -p /bin/bash -n crowdsec-firewall-bouncer-nftables

if [ "$1" == "0" ] ; then
Expand All @@ -164,17 +177,11 @@ fi

if [ "$1" == "1" ] ; then
systemctl restart crowdsec-firewall-bouncer || echo "cannot restart service"
elif [ "$1" == "0" ] ; then
systemctl stop crowdsec-firewall-bouncer
systemctl disable crowdsec-firewall-bouncer
fi


%postun -p /bin/bash -n crowdsec-firewall-bouncer-nftables

if [ "$1" == "1" ] ; then
systemctl restart crowdsec-firewall-bouncer || echo "cannot restart service"
elif [ "$1" == "0" ] ; then
systemctl stop crowdsec-firewall-bouncer
systemctl disable crowdsec-firewall-bouncer
fi

0 comments on commit 977f3b6

Please sign in to comment.