[VOL-5031] - Pre-release voltha-onos build

[VOL-5099] - verify_foltha-onos-sanity-test FAIL

app-install.sh
tests/version-check.sh
----------------------
  o shellcheck cleanups
  o Improve error detection and reporting.
  o cd '..' early VS resolving relative paths everywhere.
  o Replace $(basename) with shell string builtins.
  o use local vars to shorten paths and avoid extra string concatenation.
  o Added error detection in "<app name=" gathering, shell commands can
    fail allowing manipulation in APP_INSTALL_ROOT VS A_I_R/$name.

Makefile
makefiles/virtualenv.mk
-----------------------
  o Update requirements.txt read check to not require existence
    of an empty *.txt file on disk.

dependencies.xml
----------------
  o Update component dependencies to match the latest deployed versions.
  o https://wiki.opennetworking.org/display/VOLTHA/v2.12+Deployments
  o Still pending: segmentrouting.version and kafka.

Change-Id: I05d2d71521fa56ea788cc959e1ce88b1d38e1b2b
diff --git a/app-install.sh b/app-install.sh
index b810097..b783565 100755
--- a/app-install.sh
+++ b/app-install.sh
@@ -13,22 +13,66 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-HERE=$(pwd)
-OARS=$(find $DOWNLOAD_ROOT -name "*.oar")
-for oar in $OARS; do
-    cd $HERE
+##-------------------##
+##---]  GLOBALS  [---##
+##-------------------##
+# set -euo pipefail
+umask 022
+declare -g HERE; HERE="$(pwd)"
+
+## -----------------------------------------------------------------------
+## Intent: Display an error mesage then exit with shell exit status
+## -----------------------------------------------------------------------
+function error()
+{
+    echo "${BASH_SOURCE[0]} ERROR: $*"
+    exit 1
+}
+
+## -----------------------------------------------------------------------
+## Intent: Verify required environment variables are set
+## -----------------------------------------------------------------------
+function init()
+{
+    [[ ! -v APP_INSTALL_ROOT ]] && error "Var APP_INSTALL_ROOT= is required"
+    [[ ! -v DOWNLOAD_ROOT ]]    && error "Var DOWNLOAD_ROOT= is required"
+    return
+}
+
+##----------------##
+##---]  MAIN  [---##
+##----------------##
+
+init
+
+readarray -t OARS < <(find "$DOWNLOAD_ROOT" -name '*.oar')
+for oar in "${OARS[@]}"; do
+
+    app_xml="$APP_INSTALL_ROOT/app.xml"
+    oar_basename="${oar##*/}"    # bash builtin
+
+    cd "$HERE" || error "cd $HERE failed"
     echo "Installing application '$oar'"
-    rm -rf $APP_INSTALL_ROOT
-    mkdir -p $APP_INSTALL_ROOT
-    cd $APP_INSTALL_ROOT
-    cp $oar $APP_INSTALL_ROOT
-    unzip -oq -d . $APP_INSTALL_ROOT/$(basename $oar)
-    name=$(grep "name=" $APP_INSTALL_ROOT/app.xml | sed 's/<app name="//g;s/".*//g')
-    mkdir -p $APPS_ROOT/$name
-    cp $APP_INSTALL_ROOT/app.xml $APPS_ROOT/$name/app.xml
-    touch $APPS_ROOT/$name/active
-    [ -f $APP_INSTALL_ROOT/app.png ] && cp $APP_INSTALL_ROOT/app.png $APPS_ROOT/$name/app.png
-    cp $APP_INSTALL_ROOT/$(basename $oar) $APPS_ROOT/$name/$name.oar
-    cp -rf $APP_INSTALL_ROOT/m2/* $KARAF_M2
-    rm -rf $APP_INSTALL_ROOT
+    rm -rf "$APP_INSTALL_ROOT"
+    mkdir -p "$APP_INSTALL_ROOT"
+    cd "$APP_INSTALL_ROOT"  || error "cd $APP_INSTALL_ROOT failed"
+    cp -v "$oar" "$APP_INSTALL_ROOT"
+    unzip -oq -d . "$APP_INSTALL_ROOT/${oar_basename}"
+
+    readarray -t names < <(grep "name=" "$app_xml" \
+			       | sed 's/<app name="//g;s/".*//g')
+    [[ ${#names[@]} -gt 0 ]] || error "Detected invalid name gathering"
+    name="${names[1]}"
+    apps_name="$APPS_ROOT/$name"
+
+    mkdir -p "$apps_name"
+    cp "$app_xml" "${apps_name}/app.xml"
+    touch "${apps_name}/active"
+    [ -f "$APP_INSTALL_ROOT/app.png" ] \
+	&& cp "$APP_INSTALL_ROOT/app.png" "${apps_name}/app.png"
+    cp "${APP_INSTALL_ROOT}/${oar_basename}" "${apps_name}/${name}.oar"
+    cp -rf "$APP_INSTALL_ROOT/m2/"* "$KARAF_M2"
+    rm -rf "$APP_INSTALL_ROOT"
 done
+
+# [EOF]