-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply_config.sh
executable file
·75 lines (66 loc) · 1.98 KB
/
apply_config.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
##########################################################################################
# Apply config vars to *.source files
#
# USAGE:
# $ script/apply_config [file1] [file2] [...]
#
# EXAMPLE:
# $ script/apply_config dev joe
# applies config/base, config/dev, and config/joe to vars found in *.source files
#
# config/base is always sourced first followed by any files passed in on the command line
#
##########################################################################################
cd -- "${0%/*}"
# set -x
set -e
args=`echo $@`
arr=( "base" ${args} )
cd ..
# Use existing config if no params were passed in
if [ -z "${args}" ] && [ -e "config/applied_config" ]; then
arr=( $(cat config/applied_config) )
else
rm -f config/applied_config
for i in ${arr[@]}; do
echo ${i} >> config/applied_config
done
fi
echo "========================================="
echo "Applying config/"
for file in ${arr[@]}; do
echo " ${file}"
source ./config/${file}
done
echo ''
apply_config_to=( cloudstore/db cloudstore/rel/files cloudstore/test router/rel/files apps/auth )
for d in ${apply_config_to[@]}; do
if [ -d ${d} ]; then
# sf -> source file
for sf in `find ./${d} -name *.source`; do
tf=${sf%.*} # target file
echo ${tf}
cp ${sf} ${tf}
> ${tf}
IFS="
"
for line in $(< ${sf}); do
z=`echo ${line} | sed 's_\"_\\\"_g'`
z=`echo ${z} | sed 's_\\\$_CF-CONFIG-DOLLAR_g'`
x=`echo ${z} | sed -n "s_@@\([^@]*\)@@_$\{\1\}_g p"`
if [ -n "${x}" ]; then
y=`eval echo \"${x}\"`
y=`echo ${y} | sed 's_CF-CONFIG-DOLLAR_\\\$_g'`
echo ${y} >> ${tf}
else
echo ${line} >> ${tf}
fi
done # < ${sf}
done
fi
done
echo ""
echo "DONE applying config"
echo "========================================="
echo ""