Creating build of a small bundle of remote administrative tools that
can be installed separately from the ONOS source or ONOS runtime.

Change-Id: I0f8a7e2739010f34d913d79ab40390aef3fc07e2
diff --git a/BUCK b/BUCK
index b5c7537..cf58a0e 100644
--- a/BUCK
+++ b/BUCK
@@ -58,6 +58,17 @@
     other_tars = [ '//tools/package:onos-package-runtime' ],
 )
 
+tar_file(
+    name = 'onos-admin',
+    root = 'onos-admin-%s' % ONOS_VERSION,
+    srcs = [
+        'tools/dev/bin/onos-create-app',
+        'tools/test/bin/onos',
+    ],
+    other_tars = [ '//tools/package:onos-package-runtime' ],
+    flat = True,
+)
+
 only_lib_dep_pom(
     name = 'top-level-pom',
     src = 'pom.xml',
diff --git a/bucklets/onos.bucklet b/bucklets/onos.bucklet
index 5bb4036..1a53d10 100644
--- a/bucklets/onos.bucklet
+++ b/bucklets/onos.bucklet
@@ -316,6 +316,7 @@
    name,
    srcs,
    other_tars = [],
+   flat = False,
    root = None,
    out = None,
    visibility = [ 'PUBLIC' ],
@@ -325,6 +326,11 @@
             'cp -R -L $SRCDIR/* $TMP/%(root_dir)s' ]
    for t in other_tars:
        cmds += [ 'tar -zxf $(location %s)' % t + ' -C $TMP/%(root_dir)s' ]
+
+   if flat:
+       cmds += [ 'find $TMP/%(root_dir)s -type f -exec mv {} $TMP/%(root_dir)s \;',
+                 'find $TMP/%(root_dir)s/* -type d -d -exec rmdir {} \;' ]
+
    cmds += [ 'tar -C $TMP -zcf $OUT %(root_dir)s' ]
 
    cmd = ' && '.join(cmds) % {
diff --git a/tools/build/envDefaults b/tools/build/envDefaults
index fb93dfc..73812f9 100644
--- a/tools/build/envDefaults
+++ b/tools/build/envDefaults
@@ -41,12 +41,14 @@
 
 # ONOS test bits (onos-test.tar.gz) staging environment
 export ONOS_TEST_BITS=onos-test-${ONOS_VERSION%~*}
-export ONOS_TEST_STAGE_ROOT=${ONOS_TEST_STAGE_ROOT:-/tmp}
-export ONOS_TEST_STAGE=$ONOS_STAGE_ROOT/$ONOS_TEST_BITS
-export ONOS_TEST_TAR=$ONOS_TEST_STAGE.tar.gz
+export ONOS_TEST_TAR=$ONOS_STAGE_ROOT/$ONOS_TEST_BITS.tar.gz
+
+# ONOS admin bits (onos-admin.tar.gz) staging environment
+export ONOS_ADMIN_BITS=onos-admin-${ONOS_VERSION%~*}
+export ONOS_ADMIN_TAR=$ONOS_STAGE_ROOT/$ONOS_ADMIN_BITS.tar.gz
 
 export ONOS_INSTALL_DIR="/opt/onos"     # Installation directory on remote
-export OCI="${OCI:-192.168.56.101}"     # ONOS Controller Instance
+export OCI="${OCI:-localhost}"          # ONOS Controller Instance
 export ONOS_USER="${ONOS_USER:-sdn}"    # ONOS user on remote system
 export ONOS_GROUP="${ONOS_GROUP:-sdn}"  # ONOS group on remote system
 export ONOS_PWD="rocks"                 # ONOS user password on remote system
diff --git a/tools/build/onos-package b/tools/build/onos-package
index 18619da..67c507b 100755
--- a/tools/build/onos-package
+++ b/tools/build/onos-package
@@ -5,249 +5,3 @@
 
 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
 cd $ONOS_ROOT && onos-buck build onos --show-output && onos-check-bits
-exit $?
-
-#=============================================================================
-
-# FIXME: This needs to be refactored using Buck; for now it is disabled
-# FIXME: .deb, .rpm, .zip need to be re-implemented
-# FIXME: SM-ONOS packaging flavour needs to be re-implemented
-
-set -e
-
-# Build the staging directory used to produce the packages
-function build_stage_dir() {
-    # Make sure we have the original apache karaf bits first
-    [ ! -d $M2_REPO ] && echo "M2 repository $M2_REPO not found" && exit 1
-    [ -d $ONOS_STAGE ] && echo "ONOS stage $ONOS_STAGE already exists" && exit 1
-
-    # Create the stage directory and warp into it
-    mkdir -p $ONOS_STAGE
-    cd $ONOS_STAGE
-
-    # Check if Apache Karaf bits are available and if not, fetch them.
-    if [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ]; then
-        echo "Downloading $KARAF_TAR..."
-        curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR
-    fi
-    [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \
-        echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1
-
-    # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
-    [ -f $KARAF_ZIP ] && unzip -q $KARAF_ZIP && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
-    [ -f $KARAF_TAR ] && tar zxf $KARAF_TAR && rm -rf $ONOS_STAGE/$KARAF_DIST/demos
-    mkdir bin
-
-    # Patch the log-file size in place to increase it to 10 MB
-    perl -pi.old -e "s/maxFileSize=1MB/maxFileSize=10MB/g" \
-        $ONOS_STAGE/$KARAF_DIST/etc/org.ops4j.pax.logging.cfg
-
-    # Stage the ONOS admin scripts and patch in Karaf service wrapper extras
-    cp -r $ONOS_ROOT/tools/package/bin .
-    cp -r $ONOS_ROOT/tools/package/init $ONOS_STAGE/init
-    cp -r $ONOS_ROOT/tools/package/etc/* $ONOS_STAGE/$KARAF_DIST/etc
-
-    # Stage all builtin ONOS apps for factory install
-    onos-stage-apps $ONOS_STAGE/apps $ONOS_STAGE/$KARAF_DIST/system
-
-    # Mark the org.onosproject.drivers app active by default
-    touch $ONOS_STAGE/apps/org.onosproject.drivers/active
-
-    # Patch-in proper Karaf version into the startup script
-    sed "s/\$KARAF_VERSION/$KARAF_VERSION/g" \
-        $ONOS_ROOT/tools/package/bin/onos-service > bin/onos-service
-    chmod a+x bin/onos-service bin/onos
-
-    if [ -d $ONOS_ROOT/tools/package/karaf-assembly/target/repo ]; then
-        cp -r $ONOS_ROOT/tools/package/karaf-assembly/target/repo/* $ONOS_STAGE/$KARAF_DIST/system
-        #FIXME we need to add onos-features manually
-        mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION
-        cp $M2_REPO/org/onosproject/onos-features/$ONOS_POM_VERSION/onos-features* \
-           $ONOS_STAGE/$KARAF_DIST/system/org/onosproject/onos-features/$ONOS_POM_VERSION
-    else
-        # TODO: Deprecated so remove when confident staging works.
-        # Stage the ONOS bundles, but only those that match the version
-        mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/onosproject
-        find $M2_REPO/org/onosproject -type f -path "*/$ONOS_POM_VERSION/*" \
-            \( -name '*.jar' -o -name '*.pom' -o -name '*-features.xml' \) \
-                | grep -v -Ee '-tests.jar|-[0-9]{8}.[0-9]{6}-' \
-                | while read src; do
-            dst=$ONOS_STAGE/$KARAF_DIST/system/${src#$M2_REPO/*}
-            mkdir -p $(dirname $dst)
-            cp $src $dst
-        done
-    fi
-
-    # ONOS Patching ----------------------------------------------------------------
-
-    export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui"
-
-    [ "$ONOS_SECURITY_MODE" = true ] && enable_security_mode
-
-    # Patch the Apache Karaf distribution file to add ONOS features repository
-    perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \
-        $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
-
-    # Patch the Apache Karaf distribution file to load default ONOS boot features
-    perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \
-        $ONOS_STAGE/$KARAF_DIST/etc/org.apache.karaf.features.cfg
-
-    # Patch the Apache Karaf distribution with ONOS branding bundle
-    cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-*.jar \
-        $ONOS_STAGE/$KARAF_DIST/lib
-
-    # Patch in the ONOS version file
-    echo $ONOS_VERSION > $ONOS_STAGE/VERSION
-}
-
-function clean_stage_dir() {
-    [ -d "$ONOS_STAGE" ] && rm -r $ONOS_STAGE || :
-}
-
-function enable_security_mode() {
-    echo "Enabling security mode ONOS..."
-
-    # SM-ONOS step 1: downgrade felix config admin
-    FELIX_CFG_ADMIN=${FELIX_CFG_ADMIN:-~/Downloads/org.apache.felix.configadmin-1.6.0.jar}
-    if [ ! -f $FELIX_CFG_ADMIN ]; then
-        echo "Downloading $FELIX_CFG_ADMIN..."
-        curl -sL http://archive.apache.org/dist/felix/org.apache.felix.configadmin-1.6.0.jar > $FELIX_CFG_ADMIN
-    fi
-    [ ! -f $FELIX_CFG_ADMIN ] && \
-        echo "Felix config admin not found: $FELIX_CFG_ADMIN" && exit 1
-
-    mkdir -p $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
-    cp $FELIX_CFG_ADMIN $ONOS_STAGE/$KARAF_DIST/system/org/apache/felix/org.apache.felix.configadmin/1.6.0
-    perl -pi.old -e "s|^(.*org.apache.felix.configadmin.*)|mvn\\\\:org.apache.felix/org.apache.felix.configadmin/1.6.0 = 10|" \
-        $ONOS_STAGE/$KARAF_DIST/etc/startup.properties
-
-    # SM-ONOS step 2: stage ONOS Felix framework security (this is already done by karaf assembly); end
-
-    # SM-ONOS step 3.1: configure karaf
-    perl -pi.old -e "s|#java.security.policy|java.security.policy|" \
-        $ONOS_STAGE/$KARAF_DIST/etc/system.properties
-    perl -pi.old -e "s|#org.osgi.framework.security|org.osgi.framework.security|" \
-        $ONOS_STAGE/$KARAF_DIST/etc/system.properties
-
-    # SM-ONOS step 3.2: update featuresBoot
-    export BOOT_FEATURES="onos-security,$BOOT_FEATURES"
-}
-
-function build_compressed_zip() {
-    cd $ONOS_STAGE_ROOT
-    rm -f $ONOS_ZIP
-    which zip >/dev/null && zip -rq $ONOS_ZIP $ONOS_BITS && ls -lh $ONOS_ZIP
-}
-
-function build_compressed_tar() {
-    cd $ONOS_STAGE_ROOT
-    rm -f $ONOS_TAR
-    COPYFILE_DISABLE=1 tar zcf $ONOS_TAR $ONOS_BITS && ls -lh $ONOS_TAR
-}
-
-# Build a DEB package
-function build_deb() {
-    echo "This command may ask for your password to run commands as sudo,"
-    echo "  because you need to be root in order to generate a proper DEB package."
-
-    sudo rm -fr $ONOS_DEB_ROOT
-
-    mkdir -p $ONOS_DEB_ROOT/{DEBIAN,opt,etc/init}
-
-    # Copy the debian directory and fill in version
-    cp -r $ONOS_ROOT/tools/package/deb/* $ONOS_DEB_ROOT/DEBIAN/
-    sed -i'' -E "s/@ONOS_POM_VERSION/$ONOS_POM_VERSION/" $ONOS_DEB_ROOT/DEBIAN/control
-
-    cp -r $ONOS_STAGE $ONOS_DEB_ROOT/opt/onos
-    cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_DEB_ROOT/etc/init/
-
-    mkdir -p $ONOS_DEB_ROOT/opt/onos/var/
-
-    sudo chown -R root:root $ONOS_DEB_ROOT
-
-    sudo dpkg-deb --build $ONOS_DEB_ROOT > /dev/null &&
-    sudo mv $ONOS_STAGE_ROOT/deb.deb $ONOS_DEB && ls -l $ONOS_DEB
-
-    #TODO run lintian on .deb
-}
-
-# Build an RPM package
-function build_rpm() {
-    read -r -p "WARN: rpm-build utility and root priviledges are need to build the package. Do you want to continue? [Y/n] " response
-    [[ "$response" =~ ^[Nn] ]] && exit 0
-
-    sudo rm -fr $ONOS_RPM_ROOT
-
-    sudo yum -y install rpm-build
-
-    mkdir -p $ONOS_RPM_ROOT/{BUILD,RPMS,SOURCES/onos-$ONOS_RPM_VERSION/{etc/init,opt},SPECS,SRPMS}
-
-    cp -r $ONOS_STAGE $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/opt/onos
-    cp $ONOS_ROOT/tools/package/init/onos.conf $ONOS_RPM_ROOT/SOURCES/onos-$ONOS_RPM_VERSION/etc/init/
-
-    cd $ONOS_RPM_ROOT/SOURCES
-    COPYFILE_DISABLE=1 tar zcf onos-$ONOS_RPM_VERSION.tar.gz onos-$ONOS_RPM_VERSION
-
-    cp $ONOS_ROOT/tools/package/rpm/onos.spec $ONOS_RPM_ROOT/SPECS/
-    sed -i'' -E "s/@ONOS_RPM_VERSION/$ONOS_RPM_VERSION/g" $ONOS_RPM_ROOT/SPECS/onos.spec
-
-    rpmbuild --define "_topdir $ONOS_RPM_ROOT" -bb $ONOS_RPM_ROOT/SPECS/onos.spec
-
-    cp $ONOS_RPM_ROOT/RPMS/noarch/onos-$ONOS_RPM_VERSION-1.noarch.rpm $ONOS_STAGE_ROOT && ls -l $ONOS_STAGE_ROOT/onos-$ONOS_RPM_VERSION-1.noarch.rpm
-}
-
-# Script entry point
-[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
-. $ONOS_ROOT/tools/build/envDefaults
-
-# Bail on any errors
-set -e
-
-[[ $# == 0 ]] && ONOS_PACKAGE_TAR_arg=true
-while [[ $# -gt 0 ]]; do
-case $1 in
-    -t|--tar)
-        ONOS_PACKAGE_TAR_arg=true
-    ;;
-    -z|--zip)
-        ONOS_PACKAGE_ZIP_arg=true
-    ;;
-    -d|--deb)
-        ONOS_PACKAGE_DEB_arg=true
-    ;;
-    -r|--rpm)
-        ONOS_PACKAGE_RPM_arg=true
-    ;;
-    -s|--secure)
-        ONOS_SECURITY_MODE=true
-    ;;
-    *)
-       # unknown option
-       echo "Unknown options: $1"
-       echo "usage: $(basename $0) [--tar] [--zip] [--deb] [--rpm] [--secure]" >&2 && exit 1
-    ;;
-esac
-shift
-done
-
-#TODO consider moving this block to build_stage_dir
-# Run karaf assembly to collect artifacts for off-line installations.
-aux=/tmp/assembly-$$.log
-trap "rm -f $aux 2>/dev/null" EXIT
-#TODO possibly merge with MAVEN_OPTS, also M2_REPO must be set for the reasons
-[ -n "$M2_REPO" ] && args="-Dmaven.repo.local=$M2_REPO" || args=""
-cd $ONOS_ROOT/tools/package/karaf-assembly &&
-  mvn $args clean install > $aux 2>&1 ||
-  ( cat $aux &&
-    printf "\nFailed to run karaf-assembly, which stages artifacts for offline deployments.\n" &&
-    exit 1 )
-
-# Before starting make sure the environment is clan - delete onos staging folder
-clean_stage_dir
-
-build_stage_dir
-[ "$ONOS_PACKAGE_TAR_arg" = true ] && build_compressed_tar
-[ "$ONOS_PACKAGE_ZIP_arg" = true ] && build_compressed_zip
-[ "$ONOS_PACKAGE_DEB_arg" = true ] && build_deb
-[ "$ONOS_PACKAGE_RPM_arg" = true ] && build_rpm
-clean_stage_dir
diff --git a/tools/build/onos-release b/tools/build/onos-release
index 621d5fe..33576e5 100755
--- a/tools/build/onos-release
+++ b/tools/build/onos-release
@@ -46,6 +46,9 @@
 # Package test tar.gz
 onos-buck build //:onos-test
 
+# Package admin tar.gz
+onos-buck build //:onos-admin
+
 # Build ONOS archetypes & deploy to staging repo using the release profile.
 # Note that release of the staging repository is a separate manual step.
 if [ $dryRun -eq 0 ]; then
diff --git a/tools/build/onos-upload-bits b/tools/build/onos-upload-bits
index d74deb8..98fd23c 100755
--- a/tools/build/onos-upload-bits
+++ b/tools/build/onos-upload-bits
@@ -23,6 +23,11 @@
 rm -f $ONOS_TEST_TAR
 cp $(onos-buck build //:onos-test --show-output | tail -1 | cut -d\  -f2) $ONOS_TEST_TAR
 
+# Stage the admin bits tar in /tmp
+rm -f $ONOS_ADMIN_TAR
+cp $(onos-buck build //:onos-admin --show-output | tail -1 | cut -d\  -f2) $ONOS_ADMIN_TAR
+
+
 # use this to upload to AWS
 # onosUploadBits.py ${ONOS_VERSION%-*}
 
@@ -34,4 +39,5 @@
 UPLOAD_BASE="https://oss.sonatype.org/service/local/staging/deploy/maven2/org/onosproject/onos-releases/$ONOS_VERSION"
 curl -v -u "$SONATYPE_USER:$SONATYPE_PASSWORD" --upload-file $ONOS_TAR $UPLOAD_BASE/onos-$ONOS_VERSION.tar.gz
 curl -v -u "$SONATYPE_USER:$SONATYPE_PASSWORD" --upload-file $ONOS_TEST_TAR $UPLOAD_BASE/onos-test-$ONOS_VERSION.tar.gz
+curl -v -u "$SONATYPE_USER:$SONATYPE_PASSWORD" --upload-file $ONOS_ADMIN_TAR $UPLOAD_BASE/onos-admin-$ONOS_VERSION.tar.gz
 curl -v -u "$SONATYPE_USER:$SONATYPE_PASSWORD" --upload-file $ONOS_ZIP $UPLOAD_BASE/onos-$ONOS_VERSION.zip
\ No newline at end of file
diff --git a/tools/dev/bin/onos-create-app b/tools/dev/bin/onos-create-app
index 0430a58..281b0a1 100755
--- a/tools/dev/bin/onos-create-app
+++ b/tools/dev/bin/onos-create-app
@@ -3,8 +3,10 @@
 # Tool to create an application from scratch using ONOS Maven archetypes.
 # -----------------------------------------------------------------------------
 
-[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
-. $ONOS_ROOT/tools/build/envDefaults
+# If ONOS_HOME is set, respect its value.
+# If ONOS_HOME is not set (e.g. in the init or service environment),
+# set it based on this script's path.
+ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
 
 type=${1:-bundle}
 
diff --git a/tools/package/runtime/bin/_find-node b/tools/package/runtime/bin/_find-node
index 3f65474..744d955 100644
--- a/tools/package/runtime/bin/_find-node
+++ b/tools/package/runtime/bin/_find-node
@@ -24,30 +24,26 @@
 validate_number () {
     local re="^[0-9]+$"
     if [[ ! $1 =~ $re ]] ; then
-    return 1
+        return 1
     fi
-
     return 0
 }
 
 find_node () {
     if validate_number $1 ; then
-    # input is a number, try to find if an OC node is defined
+        # input is a number, try to find if an OC node is defined
+        oc_try="OC$1"
+        node=${!oc_try}
 
-    oc_try="OC$1"
-    node=${!oc_try}
-
-    if [ -n "$node" ]; then
+        if [ -n "$node" ]; then
             # node lookup succeeded, return node
-        echo $node
-    else
+            echo $node
+        else
             # node lookup failed, return original input
+            echo $1
+        fi
+    else
         echo $1
     fi
-
-    else
-    echo $1
-    fi
-
     return 0
 }
diff --git a/tools/package/runtime/bin/onos-app b/tools/package/runtime/bin/onos-app
index 1c30c42..7ea93a7 100755
--- a/tools/package/runtime/bin/onos-app
+++ b/tools/package/runtime/bin/onos-app
@@ -20,14 +20,10 @@
 # Tool to manage ONOS applications using REST API.
 # -----------------------------------------------------------------------------
 
-# If ONOS_HOME is set, respect its value.
-# If ONOS_HOME is not set (e.g. in the init or service environment),
-# set it based on this script's path.
-ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
-ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
+ONOS_WEB_USER=${ONOS_WEB_USER:-onos}  # ONOS WEB User defaults to 'onos'
 ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
 
-. ${ONOS_HOME}/bin/_find-node
+. $(dirname $0)/_find-node
 
 node=$(find_node $1)
 cmd=${2:-list}
diff --git a/tools/package/runtime/bin/onos-cfg b/tools/package/runtime/bin/onos-cfg
index 6b02dfa..6855d03 100755
--- a/tools/package/runtime/bin/onos-cfg
+++ b/tools/package/runtime/bin/onos-cfg
@@ -20,19 +20,15 @@
 # Tool to manage ONOS component configurations using REST API.
 # -----------------------------------------------------------------------------
 
-# If ONOS_HOME is set, respect its value.
-# If ONOS_HOME is not set (e.g. in the init or service environment),
-# set it based on this script's path.
-ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
-ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
+ONOS_WEB_USER=${ONOS_WEB_USER:-onos}  # ONOS WEB User defaults to 'onos'
 ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
 
+. $(dirname $0)/_find-node
+. $(dirname $0)/_check-json
+
 fail="--fail"
 [ "$1" == "-v" ] && shift && fail=""
 
-. ${ONOS_HOME}/bin/_find-node
-. ${ONOS_HOME}/bin/_check-json
-
 node=$(find_node $1)
 cmd=${2:-list}
 component=${3}
diff --git a/tools/package/runtime/bin/onos-compile-yang b/tools/package/runtime/bin/onos-compile-yang
index 855167c..e1bb987 100755
--- a/tools/package/runtime/bin/onos-compile-yang
+++ b/tools/package/runtime/bin/onos-compile-yang
@@ -20,14 +20,10 @@
 # Tool to compile the specified YANG file(s) using the ONOS live compilation.
 # -----------------------------------------------------------------------------
 
-# If ONOS_HOME is set, respect its value.
-# If ONOS_HOME is not set (e.g. in the init or service environment),
-# set it based on this script's path.
-ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
-ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
+ONOS_WEB_USER=${ONOS_WEB_USER:-onos}  # ONOS WEB User defaults to 'onos'
 ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
 
-. ${ONOS_HOME}/bin/_find-node
+. $(dirname $0)/_find-node
 
 node=$(find_node $1)
 yang=$2
diff --git a/tools/package/runtime/bin/onos-diagnostics b/tools/package/runtime/bin/onos-diagnostics
index 442b1fd..4ab9bf5 100755
--- a/tools/package/runtime/bin/onos-diagnostics
+++ b/tools/package/runtime/bin/onos-diagnostics
@@ -19,6 +19,12 @@
 # -----------------------------------------------------------------------------
 # Tool to collect cluster-wide diagnostics into a single tar stream.
 # -----------------------------------------------------------------------------
+
+ONOS_WEB_USER=${ONOS_WEB_USER:-onos}  # ONOS WEB User defaults to 'onos'
+ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
+
+. $(dirname $0)/_find-node
+
 function usage() {
     echo "usage: $(basename $0) [-x] [-n name] [-u user] [-p password] [ip1 ip2...]"
     echo ""
@@ -69,6 +75,9 @@
     "ports -e"
     "portstats -nz"
 
+    "packet-processors"
+    "packet-requests"
+
     "intents"
     "flows -s"
     "groups"
@@ -93,8 +102,7 @@
         *) usage;;
     esac
 done
-ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
-ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
+
 user=${user:-$ONOS_WEB_USER}
 password=${password:-$ONOS_WEB_PASS}
 let OPC=$OPTIND-1
@@ -118,7 +126,7 @@
     printf "logs "
     curl -sS --fail --user $user:$password  \
         http://$node:8181/onos/v1/diagnostics > ../$node.tar.gz
-    tar zxf ../$node.tar.gz
+    tar zxf ../$node.tar.gz && rm ../$node.tar.gz
 
     # Acquire remotely obtained diagnostics via ssh CLI
     for cmd in "${CLI_COMMANDS[@]}"; do
@@ -127,9 +135,7 @@
         onos $node $cmd 2>/dev/null >$cmdLog
     done
 
-    # Tar-up local and remote diagnostics together
     printf " Done.\n"
-    tar zcf ../$node.tar.gz *
 done
 
 # Tar-up diagnostics from all the nodes
diff --git a/tools/package/runtime/bin/onos-netcfg b/tools/package/runtime/bin/onos-netcfg
index 17552ac..5e22836 100755
--- a/tools/package/runtime/bin/onos-netcfg
+++ b/tools/package/runtime/bin/onos-netcfg
@@ -20,15 +20,11 @@
 # ONOS network configuration uploader.
 # -----------------------------------------------------------------------------
 
-# If ONOS_HOME is set, respect its value.
-# If ONOS_HOME is not set (e.g. in the init or service environment),
-# set it based on this script's path.
-ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
-ONOS_WEB_USER=${ONOS_WEB_USER:-onos} # ONOS WEB User defaults to 'onos'
+ONOS_WEB_USER=${ONOS_WEB_USER:-onos}  # ONOS WEB User defaults to 'onos'
 ONOS_WEB_PASS=${ONOS_WEB_PASS:-rocks} # ONOS WEB Password defaults to 'rocks'
 
-. ${ONOS_HOME}/bin/_find-node
-. ${ONOS_HOME}/bin/_check-json
+. $(dirname $0)/_find-node
+. $(dirname $0)/_check-json
 
 fail="--fail"
 [ "$1" == "-v" ] && shift && fail=""
diff --git a/tools/package/runtime/bin/onos-node-diagnostics b/tools/package/runtime/bin/onos-node-diagnostics
index 1cb18b5..f5dd520 100755
--- a/tools/package/runtime/bin/onos-node-diagnostics
+++ b/tools/package/runtime/bin/onos-node-diagnostics
@@ -20,10 +20,7 @@
 # Tool to collect node-specific diagnostics into a single tar stream.
 # -----------------------------------------------------------------------------
 
-# If ONOS_HOME is set, respect its value.
-# If ONOS_HOME is not set (e.g. in the init or service environment),
-# set it based on this script's path.
-ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
+ONOS_HOME=$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)
 
 diag=/tmp/diag$$
 mkdir -p $diag; cd $diag
diff --git a/tools/test/bin/onos b/tools/test/bin/onos
index c74ebc6..8e2f600 100755
--- a/tools/test/bin/onos
+++ b/tools/test/bin/onos
@@ -5,32 +5,24 @@
 
 function _usage () {
 cat << _EOF_
-usage:
- $(basename $0) [-w] [-f] [node]
+usage: $(basename $0) [node [command]]
 
-flags:
-- -w : Waits for ONOS instance to reach run-level 100, i.e. to be fully started.
-- -f : Deprecated - use bash's IFS expansion of positional parameters
+ONOS remote command-line client.
 
-options:
-- [node] : the node to attach to
+Parameters:
+  - node          ip or hostname of cluster node to attach to
+  - command       command to be executed
 
-summary:
- ONOS remote command-line client.
-
- The -w flag depends on 'onos-wait-for-start'. If [node] is unspecified, \$OCI
- is used.
-
+If node is unspecified, the value of \$OCI environment variable is used.
 _EOF_
 }
-[ "$1" = "-h" ] && _usage && exit 0
 
-[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
-. $ONOS_ROOT/tools/build/envDefaults
-. $ONOS_ROOT/tools/test/bin/find-node.sh
+[ "$1" = "-h" -o "$1" = '-?' ] && _usage && exit 0
+[ "$1" = "-w" ] && echo "-w option is deprecated" && shift   # Deprecated
+[ "$1" = "-f" ] && echo "-f option is deprecated" && shift   # Deprecated
 
-[ "$1" = "-w" ] && shift && onos-wait-for-start $1
-[ "$1" = "-f" ] && shift   # Deprecated
+[ -f $(dirname $0)/find-node.sh ] && . $(dirname $0)/find-node.sh
+[ -f $(dirname $0)/_find-node ] && . $(dirname $0)/_find-node
 
 [ -n "$1" ] && OCI=$(find_node $1) && shift
 
diff --git a/tools/test/bin/proxy-stc b/tools/test/bin/proxy-stc
index 63e65cc..3a30be7 100755
--- a/tools/test/bin/proxy-stc
+++ b/tools/test/bin/proxy-stc
@@ -23,7 +23,6 @@
     cd \$(ls -Fd onos-test-*/)
     export ONOS_ROOT=\$PWD
     export ONOS_STAGE_ROOT=/tmp
-    export ONOS_TEST_STAGE_ROOT=/tmp
     source \$ONOS_ROOT/tools/dev/bash_profile
     setPrimaryInstance 1
     onos-verify-cell   # TODO: remove once warden does this for us