#!/bin/bash
####
# build-patch - patch the newly built distro
####
#set -x

CONFIG_INSTALL_DIR=web/profiles/custom/wildfire_profiles/wildfire/config/install

####  source in secrets from build server
source ../../wildfire/secrets

#### Change & to \& so the sed command below will work correctly
IPS_API_KEY_ESCAPED=$(echo $IPS_API_KEY | sed -e 's/&/\\&/g')

####  patch secrets into some config files
echo 'build-patch: Patching files'
sed -i "s#^\(.*wildfire_dbp_key: \).*#\1'${WILDFIRE_DBP_KEY}'#"                $CONFIG_INSTALL_DIR/wildfire_dbp.settings.yml
sed -i "s#^\(.*arclight_apikey: \).*#\1'${ARCLIGHT_APIKEY}'#"                  $CONFIG_INSTALL_DIR/arclight.settings.yml
sed -i "s#^\(.*api_key: \).*#\1'${IPS_API_KEY_ESCAPED}'#"                      $CONFIG_INSTALL_DIR/wildfire_ipsdb.settings.yml
sed -i "s#^\(.*username: \).*#\1'${IPS_USERNAME}'#"                            $CONFIG_INSTALL_DIR/wildfire_ipsdb.settings.yml
sed -i "s#^\(.*password: \).*#\1'${IPS_PASSWORD}'#"                            $CONFIG_INSTALL_DIR/wildfire_ipsdb.settings.yml
sed -i "s#^\(.*scripture_earth_api_key: \).*#\1'${SCRIPTURE_EARTH_API_KEY}'#"  $CONFIG_INSTALL_DIR/wildfire_fresh_start.settings.yml

