Adding ability to run ONOS locally via 'buck run onos'

Runs ONOS as a server and requires client connections with ONOS_USE_SSH unset.

Change-Id: Id0aedccbfddfb8f3f17b2ef7f73e805066976315
diff --git a/tools/package/BUCK b/tools/package/BUCK
index a3f132f..31896f3 100644
--- a/tools/package/BUCK
+++ b/tools/package/BUCK
@@ -106,3 +106,12 @@
   bash = '$(exe //buck-tools:onos-stage) $OUT $(location :onos-karaf) ' + ' '.join(sources),
   visibility = [ 'PUBLIC' ],
 )
+
+genrule(
+  name = 'onos-run',
+  out = 'onos-run',
+  srcs = [ 'onos-run-karaf' ],
+  bash = 'sed "s#ONOS_TAR=#ONOS_TAR=$(location :onos-package)#" $SRCS > $OUT; chmod +x $OUT',
+  executable = True,
+  visibility = [ 'PUBLIC' ],
+)
\ No newline at end of file
diff --git a/tools/package/onos-prep-karaf b/tools/package/onos-prep-karaf
index d1f561c..337b4b2 100755
--- a/tools/package/onos-prep-karaf
+++ b/tools/package/onos-prep-karaf
@@ -54,7 +54,7 @@
 # Stage the ONOS admin scripts and patch in Karaf service wrapper extras
 cp -r bin $PREFIX
 cp -r init $PREFIX
-cp -r etc $PREFIX/$KARAF_DIR/etc/
+cp -r etc/* $PREFIX/$KARAF_DIR/etc/
 
 zip -q -0 -r $OUT $PREFIX
 
diff --git a/tools/package/onos-run-karaf b/tools/package/onos-run-karaf
new file mode 100755
index 0000000..7c9643f
--- /dev/null
+++ b/tools/package/onos-run-karaf
@@ -0,0 +1,34 @@
+#!/bin/bash
+# -----------------------------------------------------------------------------
+# Runs ONOS from distributable onos.tar.gz
+# -----------------------------------------------------------------------------
+
+ONOS_TAR=
+
+cd /tmp
+
+# Kill any running instances
+[ -f /tmp/onos.pid ] && kill -9 $(cat /tmp/onos.pid) &>/dev/null
+
+set -e
+
+# Blitz previously unrolled onos- directory
+rm -fr onos-*
+
+# Unroll new image from the specified tar file
+[ -f $ONOS_TAR ] && tar zxf $ONOS_TAR
+
+# Change into the ONOS home directory
+cd onos-*
+export ONOS_HOME=$PWD
+
+# FIXME: for now we're running using the karaf client; later use raw SSH
+unset ONOS_USE_SSH
+
+# Start ONOS as a server, but include any specified options
+./bin/onos-service server "$@" &>onos.log &
+echo "$!" > /tmp/onos.pid
+
+# Hang-on a bit and then start tailing the ONOS log output
+sleep 1
+tail -f ./apache*/data/log/karaf.log