From f9053fd6bfeb89bee93c7a8616aa332dec5be774 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch>
Date: Tue, 13 Apr 2021 17:56:46 +0200
Subject: [PATCH] 2021-04-13  v1.1  add support for custom config

---
 shellscripts/getfile.sh | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/shellscripts/getfile.sh b/shellscripts/getfile.sh
index 33508ce..65d1bb8 100755
--- a/shellscripts/getfile.sh
+++ b/shellscripts/getfile.sh
@@ -4,7 +4,8 @@
 # API CLIENT :: GET A CI FILE FROM PACKAGE SERVER
 #
 # ----------------------------------------------------------------------
-# 2021-03-31  v0.0  <axel.hahn@iml.unibe.ch>  init
+# 2021-03-31  v1.0  <axel.hahn@iml.unibe.ch>  init
+# 2021-04-13  v1.1  <axel.hahn@iml.unibe.ch>  add support for custom config
 # ======================================================================
 
 # ----------------------------------------------------------------------
@@ -13,6 +14,7 @@
 
 line="----------------------------------------------------------------------"
 bDebug=0
+customconfig=
 
 . $0.cfg
 
@@ -33,6 +35,7 @@ SYNTAX:
 
 OPTIONS:
 
+  -c CFGFILE  load custom config file after defaults in $self.cfg
   -d          enable debug infos
   -e PHASE    phase; overrides env variable IMLCI_PHASE
   -f FILE     filename to get (without path); overrides env variable IMLCI_FILE
@@ -43,7 +46,9 @@ OPTIONS:
   -u URL      URL of iml ci server without trailing /; overrides env variable IMLCI_URL
 
 VALUES:
-  
+
+  CFGFILE     custom config file. It is useful to handle files of different 
+              projects on a server.
   PHASE       is a phase of the ci server; one of preview|stage|live
   FILE        is a filename without path that was created by ci server.
   OUTFILE     Output file. It can countain a path. If none is given the filename
@@ -54,6 +59,7 @@ VALUES:
   ITEM        type what to list; one of phases|projects|files
               To list projects a phase must be set.
               To list files a phase and a project must be set.
+
 DEFAULTS:
 
   You don't need to set all values by command line. Use a config to set defaults
@@ -166,8 +172,9 @@ if  [ $# -lt 1 ]; then
 fi
 
 
-while getopts "de:f:l:o:p:s:u:" option; do 
+while getopts "c:de:f:l:o:p:s:u:" option; do 
     case ${option} in
+      c) customconfig="$OPTARG" ;;
       d) bDebug=1 ;;
       e) export IMLCI_PHASE=$OPTARG ;;
       f) export IMLCI_FILE=$OPTARG ;;
@@ -203,20 +210,35 @@ while getopts "de:f:l:o:p:s:u:" option; do
     esac
 done
 
+if [ ! -z "$customconfig" ]; then
+    if [ -r "$customconfig" ]; then
+        . "$customconfig" || exit 2
+     else
+        echo "ERROR: unable to read custom config [$customconfig]."
+        exit 2
+     fi
+fi
+
 test -z ${IMLCI_OUTFILE} && IMLCI_OUTFILE=$IMLCI_FILE
 
 if [ $bDebug = 1 ]; then
+    pre=">>>>>> "
     echo $line
     echo
     echo DEBUG INFOS
     echo
-    echo ----- defaults in $0.cfg
+    echo "${pre} defaults in $0.cfg"
     cat $0.cfg 2>/dev/null
     echo
-    echo '----- Params (override default values)'
+    if [ ! -z "$customconfig" ]; then 
+        echo "${pre} custom config $customconfig"
+        cat "$customconfig"
+        echo
+    fi
+    echo "${pre} Params (override default values)"
     echo $*
     echo
-    echo ----- effective values
+    echo "${pre} effective values"
     echo "IMLCI_URL = $IMLCI_URL"
     echo "IMLCI_PKG_SECRET = $IMLCI_PKG_SECRET"
     echo "IMLCI_PROJECT = $IMLCI_PROJECT"
-- 
GitLab