Configuration file option for packaging 81/77781/3
authorSamuli Silvius <s.silvius@partner.samsung.com>
Mon, 4 Feb 2019 12:26:27 +0000 (14:26 +0200)
committerSamuli Silvius <s.silvius@partner.samsung.com>
Fri, 8 Feb 2019 12:43:53 +0000 (14:43 +0200)
At the moment configuration file for the package.sh script is fixed
by name and location package.conf in the same dir as the script.

Allow user to give configuration file as parameter for the script.

Issue-ID: OOM-1627

Change-Id: I8b728996ead73a48b88bbbf364ec913217cbd8d6
Signed-off-by: Samuli Silvius <s.silvius@partner.samsung.com>
build/package.sh

index ee98533..0e4f121 100755 (executable)
@@ -32,8 +32,8 @@ crash () {
 
 usage () {
     echo "Usage:"
-    echo "   ./$(basename $0) <project_name> <version>  <packaging_target_dir>"
-    echo "Example: ./$(basename $0) onap 1.0.1  /tmp/package_onap_1.0.0"
+    echo "   ./$(basename $0) <project_name> <version>  <packaging_target_dir> [--conf <file>]"
+    echo "Example: ./$(basename $0) myproject 1.0.1 /tmp/package --conf ~/myproject.conf"
     echo "packaging_target_dir will be created if does not exist. All tars will be produced into it."
 }
 
@@ -89,7 +89,7 @@ function build_sw_artifacts {
 }
 
 function create_sw_package {
-    local pkg_root="${PACKAGING_TARGET_DIR}/onap"
+    local pkg_root="${PACKAGING_TARGET_DIR}/sw"
 
     # Create tar package
     echo "[Creating software package]"
@@ -186,26 +186,37 @@ PROJECT_VERSION="$2"
 PACKAGING_TARGET_DIR="$3"
 
 TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
-
-# ensure that package.conf is sourced even when package.sh executed from another place
 SCRIPT_DIR=$(dirname "${0}")
 LOCAL_PATH=$(readlink -f "$SCRIPT_DIR")
 
-# lets start from script directory as some path in script are relative
-pushd "${LOCAL_PATH}"
-source ./package.conf
-
-
 if [ "$#" -lt 3 ]; then
     echo "Missing some mandatory parameter!"
     usage
     exit 1
 fi
 
-if [ ! -f "./package.conf" ]; then
-    crash 2 "Mandatory config file ./package.conf missing!"
+CONF_FILE=""
+for arg in "$@"; do
+  shift
+  case "$arg" in
+    -c|--conf)
+        CONF_FILE="$1" ;;
+    *)
+        set -- "$@" "$arg"
+  esac
+done
+
+if [ -z ${CONF_FILE} ]; then
+    CONF_FILE=${LOCAL_PATH}/package.conf # Fall to default conf file
 fi
 
+if [ ! -f ${CONF_FILE} ]; then
+    crash 2 "Mandatory config file missing! Provide it with --conf option or ${LOCAL_PATH}/package.conf"
+fi
+
+source ${CONF_FILE}
+pushd ${LOCAL_PATH}
+
 # checking bash capability of parsing arrays
 whotest[0]='test' || (crash 3 "Arrays not supported in this version of bash.")