Skip to content

Commit

Permalink
Hide template logic
Browse files Browse the repository at this point in the history
Back to tempesta_fw.conf
Delete temp .conf file after start
  • Loading branch information
pale-emperor committed Mar 17, 2022
1 parent 5591660 commit cf0a85d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
File renamed without changes.
30 changes: 19 additions & 11 deletions scripts/tempesta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tfw_path=${TFW_PATH:="$TFW_ROOT/fw"}
tls_path=${TLS_PATH:="$TFW_ROOT/tls"}
lib_path=${LIB_PATH:="$TFW_ROOT/lib"}
tfw_cfg_path=${TFW_CFG_PATH:="$TFW_ROOT/etc/tempesta_fw.conf"}
tfw_cfg_template=${TFW_CFG_TMPL:="$TFW_ROOT/etc/tempesta_tmpl.conf"}
tfw_cfg_temp=${TFW_CFG_TMPL:="$TFW_ROOT/etc/tempesta_tmp.conf"}

lib_mod=tempesta_lib
tls_mod=tempesta_tls
Expand Down Expand Up @@ -72,29 +72,33 @@ usage()
templater()
{
# Replace !include dircetive with file contents
> $tfw_cfg_path
> $tfw_cfg_temp
while IFS= read -r line
do
if [[ $line =~ '!include' ]];
then
if [[ ${line:0:1} = \# ]]; then
:
elif [[ $line =~ '!include' ]]; then
IFS=' '
read -ra path <<< "$line"

files=$(find ${path[1]} -type f -regextype posix-extended -regex '.*')
while IFS= read -r file; do
value=`cat $file`
echo "$value" >> $tfw_cfg_path
echo "$value" >> $tfw_cfg_temp
done <<< "$files"
elif [[ ${line:0:1} = \# ]]; then
:
else
value="$line"
echo "$value" >> $tfw_cfg_path
echo "$value" >> $tfw_cfg_temp
fi
done < "$tfw_cfg_template"
done < "$tfw_cfg_path"
}

templater
remove_tmp_conf()
{
if [ -f $tfw_cfg_temp ]; then
rm $tfw_cfg_temp
fi
}

error()
{
Expand Down Expand Up @@ -139,7 +143,7 @@ load_modules()
load_one_module "$tdb_path/$tdb_mod.ko" ||
error "cannot load tempesta database module"

load_one_module "$tfw_path/$tfw_mod.ko" "tfw_cfg_path=$tfw_cfg_path" ||
load_one_module "$tfw_path/$tfw_mod.ko" "tfw_cfg_path=$tfw_cfg_temp" ||
error "cannot load tempesta module"
}

Expand Down Expand Up @@ -199,6 +203,8 @@ update_single_js_template()
# Let TempestaFW warn user on issues.
update_js_challenge_templates()
{
templater

echo "...compile html templates for JS challenge"
# Just a simple parser: don't care about commented brackets and sections.
# More sophisticated parser should work inside configuration processing.
Expand Down Expand Up @@ -249,6 +255,7 @@ start()
else
echo "done"
fi
remove_tmp_conf
}

stop()
Expand All @@ -274,6 +281,7 @@ reload()
error "cannot reconfigure Tempesta FW"
else
echo "done"
remove_tmp_conf
fi
}

Expand Down

0 comments on commit cf0a85d

Please sign in to comment.