Debian Codegraph @

debian/upstream_debian/crowdsec-firewall-bouncer-nftables.postinst

raw
1
2 systemctl daemon-reload
3
4
5 START=0
6 CSCLI=/usr/bin/cscli
7
8 if [ "$1" = "configure" ]; then
9
10 if command -v "$CSCLI" >/dev/null ; then
11 START=1
12 echo "cscli/crowdsec is present, generating API key"
13 unique=`date +%s`
14 API_KEY=`cscli -oraw bouncers add FirewallBouncer-${unique}`
15 if [ $? -eq 1 ] ; then
16 echo "failed to create API token, service won't be started."
17 START=0
18 API_KEY="<API_KEY>"
19 else
20 echo "API Key : ${API_KEY}"
21 fi
22 fi
23
24 TMP=`mktemp -p /tmp/`
25 install -m 0600 /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml ${TMP}
26 BACKEND=nftables API_KEY=${API_KEY} envsubst < ${TMP} | install -m 0600 /dev/stdin /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
27 rm ${TMP}
28
29 else
30
31 START=1
32 fi
33
34
35 if command -v "$CSCLI" >/dev/null; then
36 PORT=$(cscli config show --key "Config.API.Server.ListenURI"|cut -d ":" -f2)
37 if [ ! -z "$PORT" ]; then
38 sed -i "s/localhost:8080/127.0.0.1:${PORT}/g" /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
39 sed -i "s/127.0.0.1:8080/127.0.0.1:${PORT}/g" /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
40 fi
41 fi
42
43 systemctl --quiet is-enabled crowdsec-firewall-bouncer || systemctl unmask crowdsec-firewall-bouncer && systemctl enable crowdsec-firewall-bouncer
44
45 if [ ${START} -eq 0 ] ; then
46 echo "no api key was generated, won't start service"
47 else
48 systemctl start crowdsec-firewall-bouncer
49 fi