Use functions, add echo statement to start script

Change-Id: Id86f5aa5b12996c272ea51324d327328042a8143
diff --git a/infoCenter/createInfoCenter.sh b/infoCenter/createInfoCenter.sh
old mode 100644
new mode 100755
index d7b15dd..3ad298b
--- a/infoCenter/createInfoCenter.sh
+++ b/infoCenter/createInfoCenter.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # This script requires the following files to be present in the same dir:
 # * get_jars.sh
 # * find_jars.sh
@@ -20,6 +20,7 @@
 DOWNLOADDIR=/home/data/httpd/download.eclipse.org/eclipse/downloads/drops4
 SCRIPT_NAME="$(basename ${0})"
 BANNER_FILE=org.foundation.helpbanner2_2.0.0.jar
+PORT=8086
 
 usage() {
   printf "Usage %s [releaseName] [pathToArchive] [p2RepoDir] [legacyMode]\n" "${SCRIPT_NAME}"
@@ -30,87 +31,102 @@
 }
 
 # Verify inputs
-[[ -z "$RELEASE_NAME" && $# -lt 1 ]] && {
+if [[ -z "$RELEASE_NAME" && $# -lt 1 ]]; then
   printf "ERROR: a release name must be given.\n"
   usage
   exit 1
-}
+fi
 
-[[ -z "$ZIP_PATH" && $# -lt 2 ]] && {
+if [[ -z "$ZIP_PATH" && $# -lt 2 ]]; then
   printf "ERROR: a path to the eclipse-platform archive must be given.\n"
   usage
   exit 1
+fi
+
+prepare() {
+    # Create new sub directory for info center
+    echo "Create sub directory for new info center..."
+    if [ ! -d "$WORKDIR" ]; then
+      mkdir -p $WORKDIR
+    fi
+    # TODO: exit when sub directory already exists?
+    
+    
+    # Copy/download eclipse-platform
+    echo "Downloading eclipse-platform..."
+    if [ ! -f $WORKDIR/eclipse-platform*.tar.gz ]; then
+      cp $DOWNLOADDIR/$ZIP_PATH .
+    fi
+    
+    # Extract eclipse-platform
+    tar xzf eclipse-platform*.tar.gz -C $WORKDIR
+    
+    # Copy eclipse/plugin_customization.ini
+    echo "Copying plugin_customization.ini..."
+    cp plugin_customization.ini $WORKDIR/eclipse/
+    
+    # Create dropins/plugins dir
+    echo "Create dropins/plugins dir..."
+    mkdir -p $WORKDIR/eclipse/dropins/plugins
+    
+    # Add custom banner
+    echo "Add custom banner..."
+    cp $BANNER_FILE $WORKDIR/eclipse/dropins/plugins
 }
 
-# Create new sub directory for info center
-echo "Create sub directory for new info center..."
-if [ ! -d "$WORKDIR" ]; then
-  mkdir -p $WORKDIR
-fi
-# TODO: exit when sub directory already exists?
+find_base() {
+    # Find org.eclipse.help.base
+    echo "Locating org.eclipse.help.base..."
+    HELP_BASE_PATH=`find $WORKDIR -name "org.eclipse.help.base*.jar"`
+    echo "Found $HELP_BASE_PATH."
+    substring_tmp=${HELP_BASE_PATH#.*_}
+    HELP_BASE_VERSION=${substring_tmp%.jar}
+    echo "Found base version $HELP_BASE_VERSION."
+}
 
+find_doc_jars() {
+    # Find doc JARs
+    echo "Find doc JARs..."
+    if [[ $LEGACY_MODE == 'true' ]]; then
+      # Run get_jars.sh (legacy)
+      echo "Executing get_jars.sh (LEGACY MODE)... "
+      ./get_jars.sh $WORKDIR/eclipse/dropins/plugins
+    else
+      echo "Executing find_jars.sh (P2_REPO_DIR: $P2_REPO_DIR)..."
+      filename=doc_plugin_list.txt
+      ./find_jars.sh $P2_REPO_DIR
+      while read line; do
+        cp $line $WORKDIR/eclipse/dropins/plugins
+      done < $filename
+    fi
+}
 
-# Copy/download eclipse-platform
-echo "Downloading eclipse-platform..."
-if [ ! -f $WORKDIR/eclipse-platform*.tar.gz ]; then
-  cp $DOWNLOADDIR/$ZIP_PATH .
-fi
+create_scripts() {
+    # Create start script
+    echo "Create start and stop scripts..."
+    echo "java -Dhelp.lucene.tokenizer=standard -Dorg.eclipse.equinox.http.jetty.context.sessioninactiveinterval=60 -classpath eclipse/plugins/org.eclipse.help.base_$HELP_BASE_VERSION.jar org.eclipse.help.standalone.Infocenter -clean -command start -eclipsehome eclipse -port $PORT -nl en -locales en -plugincustomization eclipse/plugin_customization.ini -vmargs -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError &" > $WORKDIR/startInfoCenter.sh
+	echo "echo \"The Eclipse info center is now started and can be accessed here: http://localhost:$PORT/help/index.jsp\"" >> $WORKDIR/startInfoCenter.sh
 
-# Extract eclipse-platform
-tar xzf eclipse-platform*.tar.gz -C $WORKDIR
+    # Create stop script
+    echo "java -classpath eclipse/plugins/org.eclipse.help.base_$HELP_BASE_VERSION.jar org.eclipse.help.standalone.Infocenter -clean -command shutdown -eclipsehome eclipse -port $PORT 2>&1" > $WORKDIR/stopInfoCenter.sh
+   	echo "echo \"The Eclipse info center is now stopped.\"" >> $WORKDIR/startInfoCenter.sh
 
-# Copy eclipse/plugin_customization.ini
-echo "Copying plugin_customization.ini..."
-cp plugin_customization.ini $WORKDIR/eclipse/
+    chmod +x $WORKDIR/*InfoCenter.sh
+}
 
-# Create dropins/plugins dir
-echo "Create dropins/plugins dir..."
-mkdir -p $WORKDIR/eclipse/dropins/plugins
+create_archive() {
+    # Create tar.gz
+    if [ -f info-center-$RELEASE_NAME.tar.gz ]; then
+      rm info-center-$RELEASE_NAME.tar.gz
+    fi
+    echo "Creating info center archive..."
+    tar czf info-center-$RELEASE_NAME.tar.gz $WORKDIR
+}
 
-# Add custom banner
-echo "Add custom banner..."
-cp $BANNER_FILE $WORKDIR/eclipse/dropins/plugins
-
-# Find org.eclipse.help.base
-echo "Locating org.eclipse.help.base..."
-HELP_BASE_PATH=`find $WORKDIR -name "org.eclipse.help.base*.jar"`
-echo "Found $HELP_BASE_PATH."
-substring_tmp=${HELP_BASE_PATH#.*_}
-HELP_BASE_VERSION=${substring_tmp%.jar}
-echo "Found base version $HELP_BASE_VERSION."
-
-# Find doc JARs
-echo "Find doc JARs..."
-if [[ $LEGACY_MODE == 'true' ]]; then
-  # Run get_jars.sh (legacy)
-  echo "Executing get_jars.sh (LEGACY MODE)... "
-  ./get_jars.sh $WORKDIR/eclipse/dropins/plugins
-else
-  echo "Executing find_jars.sh (P2_REPO_DIR: $P2_REPO_DIR)..."
-  filename=doc_plugin_list.txt
-  ./find_jars.sh $P2_REPO_DIR
-  while read line; do
-    cp $line $WORKDIR/eclipse/dropins/plugins
-  done < $filename
-fi
-
-PORT=8086
-
-# Create start script
-echo "Create start and stop scripts..."
-echo "java -Dhelp.lucene.tokenizer=standard -Dorg.eclipse.equinox.http.jetty.context.sessioninactiveinterval=60 -classpath eclipse/plugins/org.eclipse.help.base_$HELP_BASE_VERSION.jar org.eclipse.help.standalone.Infocenter -clean -command start -eclipsehome eclipse -port $PORT -nl en -locales en -plugincustomization eclipse/plugin_customization.ini -vmargs -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError &" > $WORKDIR/startInfoCenter.sh
-
-# Create stop script
-echo "java -classpath eclipse/plugins/org.eclipse.help.base_$HELP_BASE_VERSION.jar org.eclipse.help.standalone.Infocenter -clean -command shutdown -eclipsehome eclipse -port $PORT 2>&1" > $WORKDIR/stopInfoCenter.sh
-
-chmod +x $WORKDIR/*InfoCenter.sh
-
-# Create tar.gz
-if [ -f info-center-$RELEASE_NAME.tar.gz ]; then
-  rm info-center-$RELEASE_NAME.tar.gz
-fi
-echo "Creating info center archive..."
-tar czf info-center-$RELEASE_NAME.tar.gz $WORKDIR
-
+prepare
+find_base
+find_doc_jars
+create_scripts
+create_archive
 
 printf "Done.\n"
\ No newline at end of file