remaster/src/func/config_build

70 lines
1.8 KiB
Bash

#!/bin/bash
#remaster lib
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }
#config_build jobfile configenv
function config_build() {
config_file="$1"
config_env="$2"
echo "### S e t t i n g s ###"
[ -f "$config_file" ] || {
echo "Config: wrong path for jobfile"
exit 3
}
[ -f "$config_env" ] || {
echo "Config: wrong path for config enviroment"
exit 3
}
##load project
export "`cat "$config_file" | grep ^[^#] | grep ^project= | cut -d "#" -f 1 | tr -d '"'`"
#check if project template exist
[ -f "<LIBDIR>/proj/$project" ] || {
echo "No Project \"$project\" is not supported"
return 3
}
# loard project
source "<LIBDIR>/proj/$project"
echo; echo #space
cat "$config_file" | grep ^[^#] | cut -d "#" -f 1 | grep '=' | while read line; do
#read each var line
config_key=`echo $line | cut -d "=" -f 1`
config_value=`echo $line | cut -d "=" -f 2 | tr -d '"'`
config_corect="false"
#check if this is a alowed config key
for i in $config_keys; do
[ "$i" == "$config_key" ] && config_corect="true"
done
if [ "$config_corect" == "true" ]; then
#load config key
#replace value strings
config_value="${config_value/<date>/`date '+%Y-%m-%d'`}"
config_value="${config_value/<time>/`date '+%H:%M:%S'`}"
onfig_value="${config_value/<DATE>/`date '+%Y-%m-%d'`}"
config_value="${config_value/<TIME>/`date '+%H:%M:%S'`}"
#save seting in environment var
echo "$config_key='$config_value'" | tee $config_env
else
echo "WARNUNG: $config_key is an inconrect setting. This will be ignored"
fi
done
}
#this func is standalone executable
[ -n "$1" ] && {
config_build $@
}