added support to use environment variables instead of set file in data drive.

This commit is contained in:
LePresidente 2024-02-29 18:10:02 +02:00
parent 58ae5a1559
commit c56e64bce2

View File

@ -2,8 +2,24 @@
set -e # Exit immediately if a command exits with a non-zero status.
mkdir -p /data/crowdsec/templates
function set_properties() {
sed -i "s/^$1=.*/$1=$2/" "${3}"
}
echo "Deploy Crowdsec Openresty Bouncer.."
if [ -n "${CROWDSEC_OPENRESTY_BOUNCER}" ]; then
while IFS= read -r line
do
if ! [[ "$line" != "^#" ]] || [[ "$line" != "^\n" ]]; then
name=$(echo "$line" | cut -d "=" -f1)
value=$(echo "$line" | cut -d "=" -f2)
if grep -q "${name}" /defaults/crowdsec/crowdsec-openresty-bouncer.conf ; then
set_properties "${name}" "${value}" "/defaults/crowdsec/crowdsec-openresty-bouncer.conf"
fi
fi
done <<< "${CROWDSEC_OPENRESTY_BOUNCER}"
else
mkdir -p /data/crowdsec/templates
sed -i 's|/defaults/crowdsec|/data/crowdsec|' /etc/nginx/conf.d/crowdsec_openresty.conf
if [ -f /data/crowdsec/crowdsec-openresty-bouncer.conf ]; then
@ -21,6 +37,8 @@ else
fi
#Make sure the config location is where we get the config from instead of /default/
sed -i 's|/defaults/crowdsec|/data/crowdsec|' /data/crowdsec/crowdsec-openresty-bouncer.conf
fi
echo "Deploy Crowdsec Templates .."
#Make sure we only copy files that don't exist in /data/crowdsec.
cd /defaults/crowdsec/templates/