diff --git a/lib/include/tw_config.sh b/lib/include/tw_config.sh index b0d08f3..463505e 100644 --- a/lib/include/tw_config.sh +++ b/lib/include/tw_config.sh @@ -283,6 +283,10 @@ function get_tw_config_value() { printf '%s' "$value" | sed -e 's/[[:space:]]*$//' } +function compile_tw_config() { + twcfg.include_exec "autoexec.cfg" > lib/tmp/compiled.cfg +} + function get_tw_config() { if [ "$#" != "2" ] then @@ -304,7 +308,7 @@ function get_tw_config() { fi mkdir -p lib/tmp twcfg_line=0 - twcfg.include_exec "autoexec.cfg" > lib/tmp/compiled.cfg + compile_tw_config found_key="$(grep "^$config_key " lib/tmp/compiled.cfg | tail -n1 | cut -d' ' -f2- | xargs)" if [ "$found_key" == "" ] then diff --git a/lib/lib.sh b/lib/lib.sh index e3ec93a..664bd21 100644 --- a/lib/lib.sh +++ b/lib/lib.sh @@ -277,7 +277,16 @@ function check_warnings() { wrn "" fi fi - port="$(wc -l < <(grep '^sv_port ' lib/tmp/compiled.cfg))" + # make sure the grep does not fail to open the non existent file + if [ ! -f lib/tmp/compiled.cfg ] + then + compile_tw_config + fi + if ! port="$(wc -l < <(grep '^sv_port ' lib/tmp/compiled.cfg))" + then + wrn "WARNING: failed to count ports in compiled.cfg" + wrn " file should be at $PWD/lib/tmp/compiled.cfg" + fi if [ "$port" != "" ] && [ "$port" -gt "1" ] then wrn "WARNING: found sv_port $port times in your config"