From 4972d15ecd21a6f8dfe6f8451d19ac678fa2865b Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Mon, 19 Oct 2020 13:38:11 +0200 Subject: #988 Read json config file in scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements the function source_json_config() that is used to read the new ogserver.json config file in the scripts. This replaces the old 'source .../ogserver.cfg'. Co-authored-by: Javier Sánchez Parra --- server/lib/checkrest | 4 ++-- server/lib/ogfunctions.sh | 12 ++++++++++++ server/lib/supportsave | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) (limited to 'server/lib') diff --git a/server/lib/checkrest b/server/lib/checkrest index 3fcd8bd1..c88ff53d 100755 --- a/server/lib/checkrest +++ b/server/lib/checkrest @@ -12,7 +12,7 @@ PROG=$(basename "$0") OPENGNSYS=/opt/opengnsys -CONFIGFILE=$OPENGNSYS/etc/ogserver.cfg +CONFIGFILE=$OPENGNSYS/etc/ogserver.json RESTURL="https://localhost/opengnsys/rest" source $OPENGNSYS/lib/ogfunctions.sh || exit 1 @@ -128,7 +128,7 @@ function runtests () { # Check dependencies. which jq &>/dev/null || raiseError notfound "Need to install \"jq\"." -source $CONFIGFILE +source_json_config $CONFIGFILE deletedata loaddata runtests diff --git a/server/lib/ogfunctions.sh b/server/lib/ogfunctions.sh index 30da3107..cf701925 100755 --- a/server/lib/ogfunctions.sh +++ b/server/lib/ogfunctions.sh @@ -110,6 +110,18 @@ function jq() { echo "$OUTPUT" } +function source_json_config() { + FILE=$1 + export ServidorAdm=$(jq -r ".rest.ip" $FILE) + export PUERTO=$(jq -r ".rest.port" $FILE) + export APITOKEN=$(jq -r ".rest.api_token" $FILE) + export USUARIO=$(jq -r ".database.user" $FILE) + export PASSWORD=$(jq -r ".database.pass" $FILE) + export datasource=$(jq -r ".database.ip" $FILE) + export CATALOG=$(jq -r ".database.name" $FILE) + export INTERFACE=$(jq -r ".wol.interface" $FILE) +} + # Private function to acts on a service (do not use directly). function _service() { local ACTION="$1" diff --git a/server/lib/supportsave b/server/lib/supportsave index 8d5c2dd9..5a20545d 100755 --- a/server/lib/supportsave +++ b/server/lib/supportsave @@ -180,9 +180,9 @@ fi echo "- Directory list" ls -Ral ${home_dir} >> $backup_dir/opengnsys_files.txt 2>&1 -if [ -r ${home_dir}/etc/ogserver.cfg ]; then +if [ -r ${home_dir}/etc/ogserver.json ]; then echo "- Database schema" - source ${home_dir}/etc/ogserver.cfg + source_json_config ${home_dir}/etc/ogserver.json mysqldump -u "$USUARIO" -p"$PASSWORD" -d "$CATALOG" >> ${backup_dir}/opengnsys_schema.sql 2>&1 else echo "- WARNING: The OpenGnsys database can not be accessed" | tee ${backup_dir}/db_schema.txt -- cgit v1.2.3-18-g5258