aboutsummaryrefslogtreecommitdiff
path: root/net/crowdsec-firewall-bouncer/files/crowdsec-firewall-bouncer.defaults
blob: 64d69a2f116bb0e96dabde20e9d2e1181e9bcb3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh

CONFIG=/etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
## Gen&ConfigApiKey
if grep -q "{API_KEY}" "$CONFIG"; then
	SUFFIX=`tr -dc A-Za-z0-9 </dev/urandom | head -c 8`
	API_KEY=`/usr/bin/cscli bouncers add crowdsec-firewall-bouncer-${SUFFIX} -o raw`
	sed -i "s,^\(\s*api_key\s*:\s*\).*\$,\1$API_KEY," $CONFIG
else
	echo API key already registered...
fi

# unfortunately, UCI doesn't provide a nice way to add an anonymous section only if it doesn't already exist
if ! uci show firewall | grep -q firewall.cs; then
  name="$(uci add firewall include)"
  uci set "firewall.${name}.path=/etc/firewall.cs"
  uci set "firewall.${name}.enabled=1"
  uci set "firewall.${name}.reload=1"
  echo -e "Adding the following UCI config:\n $(uci changes)"
  uci commit
fi

exit 0