summarylogtreecommitdiffstats
path: root/cs-cloudflare-bouncer.install
blob: d176b30bd93007d60e36e96533cda7e27adf0d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
post_install() {
  # Substitute vars in configuration
  API_KEY=`cscli bouncers add crowdsec-cloudflare-bouncer -o raw`
  export API_KEY
  IFS=: read HOST PORT <<< `sudo cscli config show --key "Config.API.Server.ListenURI"`
  echo "Bouncer registered to the CrowdSec Local API."

  CROWDSEC_LAPI_URL="http://${HOST:-'127.0.0.1'}:${PORT:-'8080'}"
  export CROWDSEC_LAPI_URL

  TMP=$(mktemp -p /tmp/)
  install -m600 /etc/crowdsec/bouncers/crowdsec-cloudflare-bouncer.yaml "$TMP"
  envsubst < "$TMP" | tee /etc/crowdsec/bouncers/crowdsec-cloudflare-bouncer.yaml >/dev/null

  # Substitute vars in systemd service
  CFG=/etc/crowdsec/bouncers
  export CFG
  BIN=/usr/bin/crowdsec-cloudflare-bouncer
  export BIN

  TMP=$(mktemp -p /tmp/)
  install -m600 /usr/lib/systemd/system/crowdsec-cloudflare-bouncer.service "$TMP"
  envsubst < "$TMP" | tee /usr/lib/systemd/system/crowdsec-cloudflare-bouncer.service >/dev/null

  # Advice
  echo -e "Make sure to set your Cloudflare credentials in /etc/crowdsec/bouncers/crowdsec-cloudflare-bouncer.yaml,\n then start/enable the service crowdsec-cloudflare-bouncer.service"
}

post_upgrade() {
  # Substitute vars in systemd service
  CFG=/etc/crowdsec/bouncers
  export CFG
  BIN=/usr/bin/crowdsec-cloudflare-bouncer
  export BIN

  TMP=$(mktemp -p /tmp/)
  install -m600 /usr/lib/systemd/system/crowdsec-cloudflare-bouncer.service "$TMP"
  envsubst < "$TMP" | tee /usr/lib/systemd/system/crowdsec-cloudflare-bouncer.service >/dev/null
}

post_remove() {
  if ! cscli bouncers remove crowdsec-cloudflare-bouncer --error; then
    echo -e "\nDon't forget to uninstall the plugin!"
    cscli bouncers list
  else
    echo -e "\nSuccessfully unregistered the plugin"
  fi
}