Debian Codegraph @

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