update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try

Signed-off-by: Jeremy Mordkoff <Jeremy.Mordkoff@riftio.com>

Change-Id: Ib11aa03a2eff5a53c808342508a5d7bee7b202b8
diff --git a/skyquake/scripts/build-dev.sh b/skyquake/scripts/build-dev.sh
new file mode 100755
index 0000000..80bf626
--- /dev/null
+++ b/skyquake/scripts/build-dev.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# 
+#   Copyright 2016 RIFT.IO Inc
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+
+
+abort()
+{
+    echo >&2 '
+***************
+*** ABORTED ***
+***************
+'
+    echo "An error occurred. Exiting..." >&2
+    exit 1
+}
+
+trap 'abort' 0
+
+set -e
+
+# Add your script below....
+# If an error occurs, the abort() function will be called.
+#----------------------------------------------------------
+# change to the directory of this script
+THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+cd $THIS_DIR
+cd ..
+
+echo "NPM config"
+npm config ls
+echo "clean node_modules"
+rm -fr node_modules
+echo "Building RW.UI framework"
+npm install
+echo "RW.UI framework build... done"
+
+echo "Building RW.UI plugins"
+cd plugins
+for f in *; do
+    if [[ -d $f ]]; then
+        echo 'Building plugin '$f
+        cd $f
+        rm -fr node_modules
+        npm install
+        ./node_modules/.bin/webpack --progress --config webpack.production.config.js --bail
+        cd ..
+        echo 'Building plugin '$f' ... done'
+    fi
+done
+
+echo "Building RW.UI plugins... done"
+# Done!
+trap : 0
+
+echo >&2 '
+************
+*** DONE *** 
+************
+'
+
+
diff --git a/skyquake/scripts/build-plugin.sh b/skyquake/scripts/build-plugin.sh
new file mode 100644
index 0000000..6c57800
--- /dev/null
+++ b/skyquake/scripts/build-plugin.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# 
+#   Copyright 2017 RIFT.IO Inc
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+abort()
+{
+    echo >&2 '
+***************
+*** ABORTED ***
+***************
+'
+    echo "An error occurred. Exiting..." >&2
+    exit 1
+}
+
+trap 'abort' 0
+
+set -e
+
+# Add your script below....
+# If an error occurs, the abort() function will be called.
+#----------------------------------------------------------
+CMAKE_BUILD=true
+
+# change to the directory of this script
+cd $PLUGIN_DIR
+cd ..
+
+echo 'Building plugin '$PLUGIN_NAME
+echo 'Fetching third-party node_modules for '$PLUGIN_NAME
+npm install
+echo 'Fetching third-party node_modules for '$PLUGIN_NAME'...done'
+echo 'Packaging '$PLUGIN_NAME' using webpack'
+ui_plugin_cmake_build=$CMAKE_BUILD ./node_modules/.bin/webpack --optimize-minimize --progress --config webpack.production.config.js --bail
+echo 'Packaging '$PLUGIN_NAME' using webpack... done'
+echo 'Packaging debug version of '$PLUGIN_NAME' using webpack'
+ui_plugin_cmake_build=$CMAKE_BUILD ./node_modules/.bin/webpack --progress --config webpack.production.config.js --production-debug --bail
+echo 'Packaging '$PLUGIN_NAME' using webpack... done'
+echo 'Building plugin '$PLUGIN_NAME'... done'
+# Done!
+trap : 0
+
+echo >&2 '
+************
+*** DONE *** 
+************
+'
\ No newline at end of file
diff --git a/skyquake/scripts/build.sh b/skyquake/scripts/build.sh
index 9d9d635..aef81d8 100755
--- a/skyquake/scripts/build.sh
+++ b/skyquake/scripts/build.sh
@@ -34,12 +34,8 @@
     if [[ -d $f ]]; then
         echo 'Building plugin '$f
         cd $f
-        echo 'Fetching third-party node_modules for '$f
-        npm install
-        echo 'Fetching third-party node_modules for '$f'...done'
-        echo 'Packaging '$f' using webpack'
-        ./node_modules/.bin/webpack --optimize-minimize --progress --config webpack.production.config.js
-        echo 'Packaging '$f' using webpack... done'
+        echo 'Run build script for '$f
+        ./scripts/build.sh
         cd ..
         echo 'Building plugin '$f'... done'
     fi
diff --git a/skyquake/scripts/handle_plugin_node_modules b/skyquake/scripts/handle_plugin_node_modules
new file mode 100755
index 0000000..75b65c0
--- /dev/null
+++ b/skyquake/scripts/handle_plugin_node_modules
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+# 
+#   Copyright 2016 RIFT.IO Inc
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+# Unpack tar archives for plugins.  Maintain a timestamp.txt file for each, so
+# that tar archives are only unpacked if they have been changed.
+#
+# This script is needed to unpack the files as cpack cannot handle a lot of files.
+
+usage() {
+    echo "usage: $(basename ${BASH_SOURCE[0]})"
+}
+
+function extract_node_modules() {
+    tar xf node_modules.tar
+    touch timestamp.txt
+}
+
+# change to the directory of this script
+THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+
+cd $THIS_DIR
+echo "Handling plugin node modules"
+
+cd ../plugins
+for dir in */; do
+    echo "Checking plugin "${dir}" for newer node_modules"
+    cd ${dir}
+    if [ ! -f timestamp.txt ]; then
+        echo "timestamp file not found ... node_modules need to be expanded and timestamp needs to be touched"
+        extract_node_modules
+    else
+        echo "Checking if node_modules.tar has a newer timestamp than timestamp.txt"
+        if [[ node_modules.tar -nt timestamp.txt ]]; then
+            echo "node_modules.tar is newer than timestamp ... node modules need to be expanded and timestamp needs to be touched"
+            extract_node_modules
+        else
+            echo "node_modules.tar is older than timestamp ... nothing needs to be done"
+        fi
+    fi
+    cd ..
+    echo "Checking plugin "${dir}" for newer node_modules ...done"
+done
+
diff --git a/skyquake/scripts/launch_ui.sh b/skyquake/scripts/launch_ui.sh
index 5a8f175..f26b325 100755
--- a/skyquake/scripts/launch_ui.sh
+++ b/skyquake/scripts/launch_ui.sh
@@ -17,7 +17,7 @@
 #
 
 usage() {
-	echo "usage: launch_ui.sh [--enable-https --keyfile-path=<keyfile_path> --certfile-path=<certfile-path>]"
+	echo "usage: launch_ui.sh --launchpad-address=<ip_or_fqdn> --idp-port-number=<port_number> [--enable-https --keyfile-path=<keyfile_path> --certfile-path=<certfile-path>]"
 }
 
 function handle_received_signal() {
@@ -26,53 +26,34 @@
     exit
 }
 
+# Gets the current hosts ip/fqdn. If the host is resolvable through dns, it
+# returns the fqdn else returns the ip address.
+get_host_address() {
+  if [[ -z $(hostname -d) ]]; then
+    # not resolvable via dns, use resolvable ip address
+    echo $(hostname --ip-address)
+  else
+    # use the fqdn
+    echo $(hostname --fqdn)
+  fi
+}
 
 start_servers() {
 	cd $THIS_DIR
 	echo "Stopping any previous instances of Skyquake and API servers started with forever"
 	forever stopall
 
+  local launchpad_address=$(get_host_address)
 
-	echo "Running Node.js Skyquake server. HTTPS Enabled: ${ENABLE_HTTPS}"
+	echo "Running Node.js Skyquake server. HTTPS Enabled: ${ENABLE_HTTPS}, Launchpad Address: ${launchpad_address}"
 	cd ..
 	if [ ! -z "${ENABLE_HTTPS}" ]; then
-		forever start -a -l forever.log -o out.log -e err.log skyquake.js	--enable-https --keyfile-path="${KEYFILE_PATH}" --certfile-path="${CERTFILE_PATH}"
+		forever start -a -l forever.log -o out.log -e err.log skyquake.js --enable-https --keyfile-path="${KEYFILE_PATH}" --certfile-path="${CERTFILE_PATH}" --launchpad-address="${LAUNCHPAD_ADDRESS}" --idp-port-number="${IDP_PORT_NUMBER}" --callback-address="${CALLBACK_ADDRESS}"
 	else
-		forever start -a -l forever.log -o out.log -e err.log skyquake.js
+		forever start -a -l forever.log -o out.log -e err.log skyquake.js --launchpad-address="${LAUNCHPAD_ADDRESS}"  --idp-port-number="${IDP_PORT_NUMBER}" --callback-address="${CALLBACK_ADDRESS}"
 	fi
 }
 
-function extract_node_modules() {
-    tar xf node_modules.tar
-    touch timestamp.txt
-}
-
-function handle_plugin_node_modules() {
-    cd $THIS_DIR
-    echo "Handling plugin node modules"
-
-    cd ../plugins
-    for dir in */; do
-        echo "Checking plugin "${dir}" for newer node_modules"
-        cd ${dir}
-        if [ ! -f timestamp.txt ]; then
-            echo "timestamp file not found ... node_modules need to be expanded and timestamp needs to be touched"
-            extract_node_modules
-        else
-            echo "Checking if node_modules.tar has a newer timestamp than timestamp.txt"
-            if [[ node_modules.tar -nt timestamp.txt ]]; then
-                echo "node_modules.tar is newer than timestamp ... node modules need to be expanded and timestamp needs to be touched"
-                extract_node_modules
-            else
-                echo "node_modules.tar is older than timestamp ... nothing needs to be done"
-            fi
-        fi
-        cd ..
-        echo "Checking plugin "${dir}" for newer node_modules ...done"
-    done
-}
-
-
 # Begin work
 for i in "$@"
 do
@@ -85,6 +66,18 @@
     CERTFILE_PATH="${i#*=}"
     shift # past argument=value
     ;;
+    -l=*|--launchpad-address=*)
+    LAUNCHPAD_ADDRESS="${i#*=}"
+    shift # past argument=value
+    ;;
+    -p=*|--idp-port-number=*)
+    IDP_PORT_NUMBER="${i#*=}"
+    shift # past argument=value
+    ;;
+    -r=*|--callback-address=*)
+    CALLBACK_ADDRESS="${i#*=}"
+    shift # past argument=value
+    ;;
     -h|--help)
     usage
     exit
@@ -110,8 +103,10 @@
 # change to the directory of this script
 THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
 
-# Call function to handle tarred node_modules as cpack+RPM cannot handle a lot of files
-handle_plugin_node_modules
+cd $THIS_DIR
+
+# Call script to handle tarred node_modules as cpack+RPM cannot handle a lot of files
+$THIS_DIR/handle_plugin_node_modules
 
 # Call function to start web and API servers
 start_servers