Adding tool to test release readiness.

Fixing minor issues with onos-upload-docs and envDefaults.

Change-Id: I6bc0ba4cebab625cd371ebbf58f356541e75b859
diff --git a/tools/build/envDefaults b/tools/build/envDefaults
index 2da2843..da7d165 100644
--- a/tools/build/envDefaults
+++ b/tools/build/envDefaults
@@ -11,8 +11,8 @@
 export KARAF_DIST=$(basename $KARAF_ZIP .zip)
 
 # Add ONOS-specific directories to the exectable PATH
-export PATH="$PATH:$ONOS_ROOT/tools/dev/bin:$ONOS_ROOT/tools/test/bin"
-export PATH="$PATH:$ONOS_ROOT/tools/build"
+export PATH="$ONOS_ROOT/tools/dev/bin:$ONOS_ROOT/tools/test/bin:$PATH"
+export PATH="$ONOS_ROOT/tools/build:$PATH"
 
 # Fallback build number us derived from from the user name & time
 export BUILD_NUMBER=${BUILD_NUMBER:-$(id -un)~$(date +'%Y/%m/%d@%H:%M')}
diff --git a/tools/build/onos-release-prerequisites b/tools/build/onos-release-prerequisites
new file mode 100755
index 0000000..90629dd
--- /dev/null
+++ b/tools/build/onos-release-prerequisites
@@ -0,0 +1,61 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Validates that the local environment is ready to commence release process.
+# -----------------------------------------------------------------------------
+
+[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
+
+GERRIT_USER=${GERRIT_USER:-$USER}
+
+set -e
+
+# Test access to Gerrit (Administrator)
+function testGerritAccess {
+    trap "echo 'FAILED'" ERR
+    printf "Checking Gerrit Administrator access... "
+    ssh -p 29418 gerrit.onosproject.org gerrit ls-members Administrators \
+        --recursive | grep -q $GERRIT_USER
+    echo "OK"
+}
+
+# Test access to wiki.onosproject.org
+function testWikiAccess {
+    trap "echo 'FAILED'" ERR
+    printf "Checking Wiki access... "
+    ssh $USER@api.onosproject.org "test -w /var/www/api/index.html"
+    echo "OK"
+}
+
+# Test access to EC2
+function testEC2Access {
+    aux=$(mktemp)
+    trap "cat $aux; rm -f $aux; echo 'FAILED'" ERR
+    printf "Checking EC2 access... "
+    uploadToS3.py -v 1>$aux 2>&1
+    rm -f $aux
+    echo "OK"
+}
+
+# Sonatype account must be created & ~/.m2/settings.xml must be configured
+# Test by "releasing" a fake project setup for that purpose to validate access.
+function testSonatypeAccess {
+    aux=$(mktemp)
+    trap "cat $aux; rm -f $aux; echo 'FAILED'" ERR
+    printf "Checking Sonatype access... "
+    pushd $ONOS_ROOT/tools/build/release-test >/dev/null
+    # TODO: Figure out how to supress the GPG note
+    mvn -Prelease clean deploy org.sonatype.plugins:nexus-staging-maven-plugin:drop \
+        1>$aux 2>&1 </dev/null
+    mvn clean >/dev/null
+    rm -f $aux
+    popd >/dev/null
+    echo "OK"
+}
+
+testGerritAccess
+testWikiAccess
+testEC2Access
+testSonatypeAccess
+
+echo "Ready to commence release process!"
+
diff --git a/tools/build/onos-upload-docs b/tools/build/onos-upload-docs
index b98bf74..18985e8 100755
--- a/tools/build/onos-upload-docs
+++ b/tools/build/onos-upload-docs
@@ -8,7 +8,7 @@
 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1
 . $ONOS_ROOT/tools/build/envDefaults
 
-user=${1:-jenkins}
+user=${1:-$USER}
 remote=$user@wiki.onosproject.org
 
 scp $ONOS_ROOT/docs/target/onos-apidocs-$ONOS_VERSION.tar.gz $remote:/tmp