Check if running as root

- Added a check to see if the script is running as root to some of the scripts.
  User will be prompted to confirm if they want to continue running as root.

Change-Id: If535945002f0e2fb58417388036373c0d5f69dfd
diff --git a/build-ramcloud-java-bindings.sh b/build-ramcloud-java-bindings.sh
index 3d7cc8e..2ba8713 100755
--- a/build-ramcloud-java-bindings.sh
+++ b/build-ramcloud-java-bindings.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # run this script, when RAMCloud java binding is updated
 
@@ -7,4 +7,8 @@
 export ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)}
 export RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
 
+source ${ONOS_HOME}/scripts/common/utils.sh
+
+confirm-if-root
+
 ${ONOS_HOME}/ramcloud-build-scripts/build_jni_so.sh
diff --git a/onos.sh b/onos.sh
index 810b5e9..c3a26ee 100755
--- a/onos.sh
+++ b/onos.sh
@@ -25,6 +25,8 @@
 
 source ${ONOS_HOME}/scripts/common/utils.sh
 
+confirm-if-root
+
 if [ ! -f ${ONOS_CONF} ]; then
   # falling back to default config file
   ONOS_CONF=${ONOS_CONF_DIR}/onos_node.conf
@@ -34,7 +36,6 @@
   fi
 fi
 
-
 ### Variables read from ONOS config file ###
 ONOS_HOST_NAME=$(read-conf ${ONOS_CONF}     host.name                     `hostname`)
 ONOS_HOST_IP=$(read-conf ${ONOS_CONF}       host.ip)
diff --git a/scripts/common/utils.sh b/scripts/common/utils.sh
index 0eaf0f8..7034685 100644
--- a/scripts/common/utils.sh
+++ b/scripts/common/utils.sh
@@ -77,3 +77,18 @@
   
   mv ${temp} ${conf}
 }
+
+# Confirm user whether to continue if running as root.
+function confirm-if-root {
+  if [ "`whoami`" == "root" ]; then
+    echo "This script should not be run as root. Are you sure you want to continue?[y/N]"
+    local key
+    read key
+    if [ "${key}" == "Y" -o "${key}" == "y" ]; then
+      echo "Continue running as root."
+    else
+      echo "Exiting script"
+      exit 1
+    fi
+  fi
+}
diff --git a/setup-ramcloud.sh b/setup-ramcloud.sh
index bc35e16..08e91d2 100755
--- a/setup-ramcloud.sh
+++ b/setup-ramcloud.sh
@@ -8,6 +8,10 @@
 export ONOS_HOME=${ONOS_HOME:-$(cd `dirname $0`; pwd)}
 export RAMCLOUD_HOME=${RAMCLOUD_HOME:-~/ramcloud}
 
+source ${ONOS_HOME}/scripts/common/utils.sh
+
+confirm-if-root
+
 if [ -d ${RAMCLOUD_HOME} ]; then
   echo "${RAMCLOUD_HOME} already exist, please rename or remove them."
   exit 1