From 40dcae90399347d65fef856b61a116a33bf140a1 Mon Sep 17 00:00:00 2001
From: Cristian Weiland <cw14@inf.ufpr.br>
Date: Mon, 20 Mar 2017 10:52:41 -0300
Subject: [PATCH] Issue #25: Script also checks if variables in config file are
 set.

Signed-off-by: Cristian Weiland <cw14@inf.ufpr.br>
---
 scripts/expenses/insert_expenses.sh           | 21 +++++++++++++++++--
 .../insert_travel_allowances.sh               | 21 +++++++++++++++++--
 scripts/workers/insert_register_payment.sh    | 21 +++++++++++++++++--
 3 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/scripts/expenses/insert_expenses.sh b/scripts/expenses/insert_expenses.sh
index 3ec22d5..4d37253 100755
--- a/scripts/expenses/insert_expenses.sh
+++ b/scripts/expenses/insert_expenses.sh
@@ -17,6 +17,25 @@ if [ "$#" -ne 4 ]; then
 	exit
 fi
 
+source ./config.sh
+
+if [ -z ${index+x} ]; then
+    echo "Var 'index' is unset. Set it in file 'scripts/expenses/config.sh'.";
+    exit;
+fi
+if [ -z ${host+x} ]; then
+    echo "Var 'host' is unset. Set it in file 'scripts/expenses/config.sh'.";
+    exit;
+fi
+if [ -z ${filter+x} ]; then
+    echo "Var 'filter' is unset. Set it in file 'scripts/expenses/config.sh'.";
+    exit;
+fi
+if [ -z ${university+x} ]; then
+    echo "Var 'university' is unset. Set it in file 'scripts/expenses/config.sh'.";
+    exit;
+fi
+
 # Getting the Last day of this month (Using date 2016-05-15 as example):
 # First, get next month (201606).
 aux=$(date +%Y%m -d "$(date +${1}${2}15) next month")
@@ -51,8 +70,6 @@ unzip -o $path$ym/${1}${2}_GastosDiretos.zip -d $path$ym/
 # Remove zip file
 rm $path$ym/${1}${2}_GastosDiretos.zip
 
-source ./config.sh
-
 length=${#filter[@]}
 
 for (( i=0; i<${length}; i++ ));
diff --git a/scripts/travel_allowances/insert_travel_allowances.sh b/scripts/travel_allowances/insert_travel_allowances.sh
index fb2b6b3..7687e6b 100755
--- a/scripts/travel_allowances/insert_travel_allowances.sh
+++ b/scripts/travel_allowances/insert_travel_allowances.sh
@@ -17,6 +17,25 @@ if [ "$#" -ne 4 ]; then
 	exit
 fi
 
+source config.sh
+
+if [ -z ${index+x} ]; then
+    echo "Var 'index' is unset. Set it in file 'scripts/travel_allowance/config.sh'.";
+    exit;
+fi
+if [ -z ${host+x} ]; then
+    echo "Var 'host' is unset. Set it in file 'scripts/travel_allowance/config.sh'.";
+    exit;
+fi
+if [ -z ${filter+x} ]; then
+    echo "Var 'filter' is unset. Set it in file 'scripts/travel_allowance/config.sh'.";
+    exit;
+fi
+if [ -z ${university+x} ]; then
+    echo "Var 'university' is unset. Set it in file 'scripts/travel_allowance/config.sh'.";
+    exit;
+fi
+
 # Getting the Last day of this month (Using date 2016-05-15 as example):
 # First, get next month (201606).
 aux=$(date +%Y%m -d "$(date +${1}${2}15) next month")
@@ -30,8 +49,6 @@ dataPath="../../data/"
 path="../../data/travel_allowance/"
 configPath="../../configs/travel_allowance/logstash/"
 
-source config.sh
-
 if [ ! -d "$path/processed" ]; then
 	mkdir -p "$path/processed"
 fi
diff --git a/scripts/workers/insert_register_payment.sh b/scripts/workers/insert_register_payment.sh
index 7e286fd..4cb384a 100755
--- a/scripts/workers/insert_register_payment.sh
+++ b/scripts/workers/insert_register_payment.sh
@@ -22,13 +22,30 @@ if [ "$#" -ne 4 ]; then
 	exit
 fi
 
+source config.sh
+
+if [ -z ${index+x} ]; then
+    echo "Var 'index' is unset. Set it in file 'scripts/workers/config.sh'.";
+    exit;
+fi
+if [ -z ${host+x} ]; then
+    echo "Var 'host' is unset. Set it in file 'scripts/workers/config.sh'.";
+    exit;
+fi
+if [ -z ${filter+x} ]; then
+    echo "Var 'filter' is unset. Set it in file 'scripts/workers/config.sh'.";
+    exit;
+fi
+if [ -z ${university+x} ]; then
+    echo "Var 'university' is unset. Set it in file 'scripts/workers/config.sh'.";
+    exit;
+fi
+
 ym=$1-$2
 dataPath="../../data/"
 path="../../data/workers/"
 configPath="../../configs/workers/"
 
-source config.sh
-
 # Check if Data and Workers directories already exist:
 if [ ! -d "$path" ]; then
 	mkdir -p "$path"
-- 
GitLab