#!/bin/sh
set -e

CAPI=/etc/crowdsec/online_api_credentials.yaml
LAPI=/etc/crowdsec/local_api_credentials.yaml

if [ "$1" = purge ]; then
  # Might have been created by the postinst during CAPI registration,
  # or created by the admin to prevent CAPI registration. Keep only
  # this file if it doesn't seem to have been generated by the CAPI
  # registration. The rest of /etc/crowdsec goes away in all cases:
  if [ -f "$CAPI" ] && ! grep -qs '^url: https://api.crowdsec.net/$' "$CAPI"; then
    mv "$CAPI" /var/lib/crowdsec/online_api_credentials.yaml
    rm -rf /etc/crowdsec
    mkdir -p /etc/crowdsec
    mv /var/lib/crowdsec/online_api_credentials.yaml "$CAPI"
  else
    rm -rf /etc/crowdsec
  fi

  # Local config and hub:
  rm -rf /var/lib/crowdsec/data
  rm -rf /var/lib/crowdsec/hub

  # Logs:
  rm -f /var/log/crowdsec.log
  rm -f /var/log/crowdsec_api.log
fi

#DEBHELPER#
