-
#!/bin/bash
-
#Config file string replacer
-
#This allows me to automatically generate my apache2 config files
-
TEMPLATE_FILE=template.conf
-
-
VAR_001_SITE_NAME=site001
-
VAR_001_SITE_HOST=www.site001.com
-
VAR_001_SITE_ROOT=/var/www/site001
-
VAR_001_SITE_ROOT_NOSSL=/var/wwwNOSSL/site001
-
-
VAR_002_SITE_NAME=site002
-
VAR_002_SITE_HOST=www.site002.com
-
VAR_002_SITE_ROOT=/var/www/site002
-
VAR_002_SITE_ROOT_NOSSL=/var/wwwNOSSL/gosecure
-
-
VAR_003_SITE_NAME=theONE
-
VAR_003_SITE_HOST=www.site003.com
-
VAR_003_SITE_ROOT=/var/www/site003
-
VAR_003_SITE_ROOT_NOSSL=/var/wwwNOSSL/gosecure
-
-
VAR_NUMS="001 002 003"
-
-
#$1 = number, $2 = name
-
function readVar_fn()
-
{
-
TMP=$(eval echo \${VAR_${1}_${2}})
-
echo ${TMP//\//\\\/}
-
}
-
-
#$1 = filename, $2 = var to replace
-
function replace_fn()
-
{
-
sed "s/{{\$\$${2}\$\$}}/$(eval echo \${${2}})/g" ${1} > ${1}.replace_fn_tmp
-
mv ${1}.replace_fn_tmp ${1}
-
}
-
-
for CUR in ${VAR_NUMS}; do
-
SITE_NAME=$(readVar_fn ${CUR} SITE_NAME)
-
SITE_HOST=$(readVar_fn ${CUR} SITE_HOST)
-
SITE_ROOT=$(readVar_fn ${CUR} SITE_ROOT)
-
SITE_ROOT_NOSSL=$(readVar_fn ${CUR} SITE_ROOT_NOSSL)
-
-
echo "Creating config file for ${SITE_NAME} (${SITE_HOST})"
-
if [ -f ${SITE_NAME}.conf ]; then
-
echo "Removing current config"
-
rm ${SITE_NAME}.conf
-
fi
-
cp template.conf ${SITE_NAME}.conf
-
-
replace_fn ${SITE_NAME}.conf SITE_NAME
-
replace_fn ${SITE_NAME}.conf SITE_HOST
-
replace_fn ${SITE_NAME}.conf SITE_ROOT
-
replace_fn ${SITE_NAME}.conf SITE_ROOT_NOSSL
-
-
echo
-
done
-
-
exit 0
RJM Article Type
Work Notes