Bug 516346 and changes to support spaces in install path
diff --git a/jetty-server/src/main/filtered/bin/dmk.sh b/jetty-server/src/main/filtered/bin/dmk.sh
old mode 100644
new mode 100755
index 3a5a8f4..aae69f2
--- a/jetty-server/src/main/filtered/bin/dmk.sh
+++ b/jetty-server/src/main/filtered/bin/dmk.sh
@@ -20,15 +20,14 @@
 # make KERNEL_HOME absolute
 KERNEL_HOME=`cd "$KERNEL_HOME"; pwd`
 
-# setup classpath and java environment
-. "$KERNEL_HOME/bin/setupClasspath.sh"
-
 # execute user setenv script if needed
 if [ -r "$KERNEL_HOME/bin/setenv.sh" ]
 then
 	. $KERNEL_HOME/bin/setenv.sh
 fi
 
+# setup classpath and java environment
+. "$KERNEL_HOME/bin/setupClasspath.sh"
 
 # Run java version check with the discovered java jvm.
 . "$KERNEL_HOME/bin/checkJava.sh"
@@ -42,8 +41,7 @@
 if [ "$COMMAND" = "start" ]
 then
 	
-	# parse the standard arguments 
-    JETTY_HOME=$KERNEL_HOME/jetty
+	# parse the standard arguments
 	CONFIG_DIR=$KERNEL_HOME/configuration
 	CLEAN_FLAG=
 	NO_START_FLAG=
@@ -133,8 +131,8 @@
 	if [ "$CLEAN_FLAG" ]
 	then
         echo "Cleaning the serviceability and working directories..."
-        rm -rf $KERNEL_HOME/work
-        rm -rf $KERNEL_HOME/serviceability
+        rm -rf "$KERNEL_HOME/work"
+        rm -rf "$KERNEL_HOME/serviceability"
 
         LAUNCH_OPTS="$LAUNCH_OPTS -clean" #equivalent to setting osgi.clean to "true"
 	fi
@@ -164,17 +162,6 @@
 	# Set the required permissions on the JMX configuration files
 	chmod 600 "$ACCESS_PROPERTIES"
 
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-		-Dcom.sun.management.jmxremote.authenticate=true \
-		-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
-		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
-		-Djavax.net.ssl.keyStore=$KEYSTORE_PATH \
-		-Djavax.net.ssl.keyStorePassword=$KEYSTORE_PASSWORD \
-		-Dcom.sun.management.jmxremote.ssl=true \
-		-Dcom.sun.management.jmxremote.ssl.need.client.auth=false"
-
    	if [ -z "$JAVA_HOME" ]
     then
       	JAVA_EXECUTABLE=java
@@ -188,33 +175,40 @@
 	then
 		TMP_DIR=$KERNEL_HOME/work/tmp
 		# Ensure that the tmp directory exists
-		mkdir -p $TMP_DIR
+		mkdir -p "$TMP_DIR"
 
         JAVA_OPTS="-Xmx1024m \
                     -XX:MaxPermSize=512m $JAVA_OPTS"
 
-		cd $KERNEL_HOME; exec $JAVA_EXECUTABLE \
+		cd "$KERNEL_HOME"; exec $JAVA_EXECUTABLE \
 			$JAVA_OPTS \
 			$DEBUG_OPTS \
 			$JMX_OPTS \
 			-XX:+HeapDumpOnOutOfMemoryError \
-			-XX:ErrorFile=$KERNEL_HOME/serviceability/error.log \
-			-XX:HeapDumpPath=$KERNEL_HOME/serviceability/heap_dump.hprof \
-			-Djava.security.auth.login.config=$AUTH_LOGIN \
-			-Dorg.eclipse.virgo.kernel.authentication.file=$AUTH_FILE \
-			-Djetty.home=$JETTY_HOME \
-       -Djava.io.tmpdir=$TMP_DIR \
-			-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-			-Dorg.eclipse.virgo.kernel.config=$CONFIG_DIR \
-			-Dosgi.sharedConfiguration.area=$CONFIG_DIR \
+			-XX:ErrorFile="$KERNEL_HOME/serviceability/error.log" \
+			-XX:HeapDumpPath="$KERNEL_HOME/serviceability/heap_dump.hprof" \
+			-Djava.security.auth.login.config="$AUTH_LOGIN" \
+			-Dorg.eclipse.virgo.kernel.authentication.file="$AUTH_FILE" \
+			-Djava.io.tmpdir="$TMP_DIR" \
+			-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+			-Dorg.eclipse.virgo.kernel.config="$CONFIG_DIR" \
+			-Dosgi.sharedConfiguration.area="$CONFIG_DIR" \
 			-Dosgi.java.profile="file:$JAVA_PROFILE" \
             -Declipse.ignoreApp=true \
-            -Dosgi.install.area=$KERNEL_HOME \
-            -Dosgi.configuration.area=$CONFIG_AREA \
+            -Dosgi.install.area="$KERNEL_HOME" \
+            -Dosgi.configuration.area="$CONFIG_AREA" \
             -Dssh.server.keystore="$CONFIG_DIR/hostkey.ser" \
-            -Dosgi.frameworkClassPath=$FWCLASSPATH \
+            -Dosgi.frameworkClassPath="$FWCLASSPATH" \
             -Djava.endorsed.dirs="$KERNEL_HOME/lib/endorsed" \
-            -classpath $CLASSPATH \
+            -Dcom.sun.management.jmxremote.port=$JMX_PORT \
+		    -Dcom.sun.management.jmxremote.authenticate=true \
+	    	-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
+    		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
+		    -Djavax.net.ssl.keyStore="$KEYSTORE_PATH" \
+		    -Djavax.net.ssl.keyStorePassword="$KEYSTORE_PASSWORD" \
+		    -Dcom.sun.management.jmxremote.ssl=true \
+		    -Dcom.sun.management.jmxremote.ssl.need.client.auth=false \
+            -classpath "$CLASSPATH" \
 			org.eclipse.equinox.launcher.Main \
             -noExit \
 			$LAUNCH_OPTS \
@@ -223,7 +217,7 @@
 elif [ "$COMMAND" = "stop" ]
 then
 
-	CONFIG_DIR=$KERNEL_HOME/configuration
+	CONFIG_DIR="$KERNEL_HOME/configuration"
 
 	#parse args for the script
 	if [ -z "$TRUSTSTORE_PATH" ]
@@ -268,11 +262,6 @@
 		esac
 		shift
 	done
-	
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Djavax.net.ssl.trustStore=${TRUSTSTORE_PATH} \
-		-Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}"
 
 	OTHER_ARGS+=" -jmxport $JMX_PORT"
 
@@ -281,10 +270,14 @@
         CONFIG_DIR=$(cygpath -wp $CONFIG_DIR)
     fi
 
-	exec $JAVA_EXECUTABLE $JAVA_OPTS $JMX_OPTS \
-		-classpath $CLASSPATH \
-		-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-		-Dorg.eclipse.virgo.kernel.authentication.file=$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties \
+	exec $JAVA_EXECUTABLE \
+	     $JAVA_OPTS \
+	     $JMX_OPTS \
+		-classpath "$CLASSPATH" \
+		-Djavax.net.ssl.trustStore="$TRUSTSTORE_PATH" \
+		-Djavax.net.ssl.trustStorePassword="$TRUSTSTORE_PASSWORD" \
+		-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+		-Dorg.eclipse.virgo.kernel.authentication.file="$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties" \
 		org.eclipse.virgo.nano.shutdown.ShutdownClient $OTHER_ARGS
 	
 else
diff --git a/kernel/src/main/filtered/bin/dmk.sh b/kernel/src/main/filtered/bin/dmk.sh
index f1909cf..aae69f2 100755
--- a/kernel/src/main/filtered/bin/dmk.sh
+++ b/kernel/src/main/filtered/bin/dmk.sh
@@ -20,15 +20,14 @@
 # make KERNEL_HOME absolute
 KERNEL_HOME=`cd "$KERNEL_HOME"; pwd`
 
-# setup classpath and java environment
-. "$KERNEL_HOME/bin/setupClasspath.sh"
-
 # execute user setenv script if needed
 if [ -r "$KERNEL_HOME/bin/setenv.sh" ]
 then
 	. $KERNEL_HOME/bin/setenv.sh
 fi
 
+# setup classpath and java environment
+. "$KERNEL_HOME/bin/setupClasspath.sh"
 
 # Run java version check with the discovered java jvm.
 . "$KERNEL_HOME/bin/checkJava.sh"
@@ -132,8 +131,8 @@
 	if [ "$CLEAN_FLAG" ]
 	then
         echo "Cleaning the serviceability and working directories..."
-        rm -rf $KERNEL_HOME/work
-        rm -rf $KERNEL_HOME/serviceability
+        rm -rf "$KERNEL_HOME/work"
+        rm -rf "$KERNEL_HOME/serviceability"
 
         LAUNCH_OPTS="$LAUNCH_OPTS -clean" #equivalent to setting osgi.clean to "true"
 	fi
@@ -163,17 +162,6 @@
 	# Set the required permissions on the JMX configuration files
 	chmod 600 "$ACCESS_PROPERTIES"
 
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-		-Dcom.sun.management.jmxremote.authenticate=true \
-		-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
-		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
-		-Djavax.net.ssl.keyStore=$KEYSTORE_PATH \
-		-Djavax.net.ssl.keyStorePassword=$KEYSTORE_PASSWORD \
-		-Dcom.sun.management.jmxremote.ssl=true \
-		-Dcom.sun.management.jmxremote.ssl.need.client.auth=false"
-
    	if [ -z "$JAVA_HOME" ]
     then
       	JAVA_EXECUTABLE=java
@@ -187,32 +175,40 @@
 	then
 		TMP_DIR=$KERNEL_HOME/work/tmp
 		# Ensure that the tmp directory exists
-		mkdir -p $TMP_DIR
+		mkdir -p "$TMP_DIR"
 
         JAVA_OPTS="-Xmx1024m \
                     -XX:MaxPermSize=512m $JAVA_OPTS"
 
-		cd $KERNEL_HOME; exec $JAVA_EXECUTABLE \
+		cd "$KERNEL_HOME"; exec $JAVA_EXECUTABLE \
 			$JAVA_OPTS \
 			$DEBUG_OPTS \
 			$JMX_OPTS \
 			-XX:+HeapDumpOnOutOfMemoryError \
-			-XX:ErrorFile=$KERNEL_HOME/serviceability/error.log \
-			-XX:HeapDumpPath=$KERNEL_HOME/serviceability/heap_dump.hprof \
-			-Djava.security.auth.login.config=$AUTH_LOGIN \
-			-Dorg.eclipse.virgo.kernel.authentication.file=$AUTH_FILE \
-			-Djava.io.tmpdir=$TMP_DIR \
-			-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-			-Dorg.eclipse.virgo.kernel.config=$CONFIG_DIR \
-			-Dosgi.sharedConfiguration.area=$CONFIG_DIR \
+			-XX:ErrorFile="$KERNEL_HOME/serviceability/error.log" \
+			-XX:HeapDumpPath="$KERNEL_HOME/serviceability/heap_dump.hprof" \
+			-Djava.security.auth.login.config="$AUTH_LOGIN" \
+			-Dorg.eclipse.virgo.kernel.authentication.file="$AUTH_FILE" \
+			-Djava.io.tmpdir="$TMP_DIR" \
+			-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+			-Dorg.eclipse.virgo.kernel.config="$CONFIG_DIR" \
+			-Dosgi.sharedConfiguration.area="$CONFIG_DIR" \
 			-Dosgi.java.profile="file:$JAVA_PROFILE" \
             -Declipse.ignoreApp=true \
-            -Dosgi.install.area=$KERNEL_HOME \
-            -Dosgi.configuration.area=$CONFIG_AREA \
+            -Dosgi.install.area="$KERNEL_HOME" \
+            -Dosgi.configuration.area="$CONFIG_AREA" \
             -Dssh.server.keystore="$CONFIG_DIR/hostkey.ser" \
-            -Dosgi.frameworkClassPath=$FWCLASSPATH \
+            -Dosgi.frameworkClassPath="$FWCLASSPATH" \
             -Djava.endorsed.dirs="$KERNEL_HOME/lib/endorsed" \
-            -classpath $CLASSPATH \
+            -Dcom.sun.management.jmxremote.port=$JMX_PORT \
+		    -Dcom.sun.management.jmxremote.authenticate=true \
+	    	-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
+    		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
+		    -Djavax.net.ssl.keyStore="$KEYSTORE_PATH" \
+		    -Djavax.net.ssl.keyStorePassword="$KEYSTORE_PASSWORD" \
+		    -Dcom.sun.management.jmxremote.ssl=true \
+		    -Dcom.sun.management.jmxremote.ssl.need.client.auth=false \
+            -classpath "$CLASSPATH" \
 			org.eclipse.equinox.launcher.Main \
             -noExit \
 			$LAUNCH_OPTS \
@@ -221,7 +217,7 @@
 elif [ "$COMMAND" = "stop" ]
 then
 
-	CONFIG_DIR=$KERNEL_HOME/configuration
+	CONFIG_DIR="$KERNEL_HOME/configuration"
 
 	#parse args for the script
 	if [ -z "$TRUSTSTORE_PATH" ]
@@ -266,11 +262,6 @@
 		esac
 		shift
 	done
-	
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Djavax.net.ssl.trustStore=${TRUSTSTORE_PATH} \
-		-Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}"
 
 	OTHER_ARGS+=" -jmxport $JMX_PORT"
 
@@ -279,10 +270,14 @@
         CONFIG_DIR=$(cygpath -wp $CONFIG_DIR)
     fi
 
-	exec $JAVA_EXECUTABLE $JAVA_OPTS $JMX_OPTS \
-		-classpath $CLASSPATH \
-		-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-		-Dorg.eclipse.virgo.kernel.authentication.file=$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties \
+	exec $JAVA_EXECUTABLE \
+	     $JAVA_OPTS \
+	     $JMX_OPTS \
+		-classpath "$CLASSPATH" \
+		-Djavax.net.ssl.trustStore="$TRUSTSTORE_PATH" \
+		-Djavax.net.ssl.trustStorePassword="$TRUSTSTORE_PASSWORD" \
+		-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+		-Dorg.eclipse.virgo.kernel.authentication.file="$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties" \
 		org.eclipse.virgo.nano.shutdown.ShutdownClient $OTHER_ARGS
 	
 else
diff --git a/nano/src/main/filtered/bin/dmk.sh b/nano/src/main/filtered/bin/dmk.sh
index f1909cf..aae69f2 100755
--- a/nano/src/main/filtered/bin/dmk.sh
+++ b/nano/src/main/filtered/bin/dmk.sh
@@ -20,15 +20,14 @@
 # make KERNEL_HOME absolute
 KERNEL_HOME=`cd "$KERNEL_HOME"; pwd`
 
-# setup classpath and java environment
-. "$KERNEL_HOME/bin/setupClasspath.sh"
-
 # execute user setenv script if needed
 if [ -r "$KERNEL_HOME/bin/setenv.sh" ]
 then
 	. $KERNEL_HOME/bin/setenv.sh
 fi
 
+# setup classpath and java environment
+. "$KERNEL_HOME/bin/setupClasspath.sh"
 
 # Run java version check with the discovered java jvm.
 . "$KERNEL_HOME/bin/checkJava.sh"
@@ -132,8 +131,8 @@
 	if [ "$CLEAN_FLAG" ]
 	then
         echo "Cleaning the serviceability and working directories..."
-        rm -rf $KERNEL_HOME/work
-        rm -rf $KERNEL_HOME/serviceability
+        rm -rf "$KERNEL_HOME/work"
+        rm -rf "$KERNEL_HOME/serviceability"
 
         LAUNCH_OPTS="$LAUNCH_OPTS -clean" #equivalent to setting osgi.clean to "true"
 	fi
@@ -163,17 +162,6 @@
 	# Set the required permissions on the JMX configuration files
 	chmod 600 "$ACCESS_PROPERTIES"
 
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-		-Dcom.sun.management.jmxremote.authenticate=true \
-		-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
-		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
-		-Djavax.net.ssl.keyStore=$KEYSTORE_PATH \
-		-Djavax.net.ssl.keyStorePassword=$KEYSTORE_PASSWORD \
-		-Dcom.sun.management.jmxremote.ssl=true \
-		-Dcom.sun.management.jmxremote.ssl.need.client.auth=false"
-
    	if [ -z "$JAVA_HOME" ]
     then
       	JAVA_EXECUTABLE=java
@@ -187,32 +175,40 @@
 	then
 		TMP_DIR=$KERNEL_HOME/work/tmp
 		# Ensure that the tmp directory exists
-		mkdir -p $TMP_DIR
+		mkdir -p "$TMP_DIR"
 
         JAVA_OPTS="-Xmx1024m \
                     -XX:MaxPermSize=512m $JAVA_OPTS"
 
-		cd $KERNEL_HOME; exec $JAVA_EXECUTABLE \
+		cd "$KERNEL_HOME"; exec $JAVA_EXECUTABLE \
 			$JAVA_OPTS \
 			$DEBUG_OPTS \
 			$JMX_OPTS \
 			-XX:+HeapDumpOnOutOfMemoryError \
-			-XX:ErrorFile=$KERNEL_HOME/serviceability/error.log \
-			-XX:HeapDumpPath=$KERNEL_HOME/serviceability/heap_dump.hprof \
-			-Djava.security.auth.login.config=$AUTH_LOGIN \
-			-Dorg.eclipse.virgo.kernel.authentication.file=$AUTH_FILE \
-			-Djava.io.tmpdir=$TMP_DIR \
-			-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-			-Dorg.eclipse.virgo.kernel.config=$CONFIG_DIR \
-			-Dosgi.sharedConfiguration.area=$CONFIG_DIR \
+			-XX:ErrorFile="$KERNEL_HOME/serviceability/error.log" \
+			-XX:HeapDumpPath="$KERNEL_HOME/serviceability/heap_dump.hprof" \
+			-Djava.security.auth.login.config="$AUTH_LOGIN" \
+			-Dorg.eclipse.virgo.kernel.authentication.file="$AUTH_FILE" \
+			-Djava.io.tmpdir="$TMP_DIR" \
+			-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+			-Dorg.eclipse.virgo.kernel.config="$CONFIG_DIR" \
+			-Dosgi.sharedConfiguration.area="$CONFIG_DIR" \
 			-Dosgi.java.profile="file:$JAVA_PROFILE" \
             -Declipse.ignoreApp=true \
-            -Dosgi.install.area=$KERNEL_HOME \
-            -Dosgi.configuration.area=$CONFIG_AREA \
+            -Dosgi.install.area="$KERNEL_HOME" \
+            -Dosgi.configuration.area="$CONFIG_AREA" \
             -Dssh.server.keystore="$CONFIG_DIR/hostkey.ser" \
-            -Dosgi.frameworkClassPath=$FWCLASSPATH \
+            -Dosgi.frameworkClassPath="$FWCLASSPATH" \
             -Djava.endorsed.dirs="$KERNEL_HOME/lib/endorsed" \
-            -classpath $CLASSPATH \
+            -Dcom.sun.management.jmxremote.port=$JMX_PORT \
+		    -Dcom.sun.management.jmxremote.authenticate=true \
+	    	-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
+    		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
+		    -Djavax.net.ssl.keyStore="$KEYSTORE_PATH" \
+		    -Djavax.net.ssl.keyStorePassword="$KEYSTORE_PASSWORD" \
+		    -Dcom.sun.management.jmxremote.ssl=true \
+		    -Dcom.sun.management.jmxremote.ssl.need.client.auth=false \
+            -classpath "$CLASSPATH" \
 			org.eclipse.equinox.launcher.Main \
             -noExit \
 			$LAUNCH_OPTS \
@@ -221,7 +217,7 @@
 elif [ "$COMMAND" = "stop" ]
 then
 
-	CONFIG_DIR=$KERNEL_HOME/configuration
+	CONFIG_DIR="$KERNEL_HOME/configuration"
 
 	#parse args for the script
 	if [ -z "$TRUSTSTORE_PATH" ]
@@ -266,11 +262,6 @@
 		esac
 		shift
 	done
-	
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Djavax.net.ssl.trustStore=${TRUSTSTORE_PATH} \
-		-Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}"
 
 	OTHER_ARGS+=" -jmxport $JMX_PORT"
 
@@ -279,10 +270,14 @@
         CONFIG_DIR=$(cygpath -wp $CONFIG_DIR)
     fi
 
-	exec $JAVA_EXECUTABLE $JAVA_OPTS $JMX_OPTS \
-		-classpath $CLASSPATH \
-		-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-		-Dorg.eclipse.virgo.kernel.authentication.file=$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties \
+	exec $JAVA_EXECUTABLE \
+	     $JAVA_OPTS \
+	     $JMX_OPTS \
+		-classpath "$CLASSPATH" \
+		-Djavax.net.ssl.trustStore="$TRUSTSTORE_PATH" \
+		-Djavax.net.ssl.trustStorePassword="$TRUSTSTORE_PASSWORD" \
+		-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+		-Dorg.eclipse.virgo.kernel.authentication.file="$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties" \
 		org.eclipse.virgo.nano.shutdown.ShutdownClient $OTHER_ARGS
 	
 else
diff --git a/tomcat-server/src/main/filtered/bin/dmk.sh b/tomcat-server/src/main/filtered/bin/dmk.sh
index f1909cf..aae69f2 100755
--- a/tomcat-server/src/main/filtered/bin/dmk.sh
+++ b/tomcat-server/src/main/filtered/bin/dmk.sh
@@ -20,15 +20,14 @@
 # make KERNEL_HOME absolute
 KERNEL_HOME=`cd "$KERNEL_HOME"; pwd`
 
-# setup classpath and java environment
-. "$KERNEL_HOME/bin/setupClasspath.sh"
-
 # execute user setenv script if needed
 if [ -r "$KERNEL_HOME/bin/setenv.sh" ]
 then
 	. $KERNEL_HOME/bin/setenv.sh
 fi
 
+# setup classpath and java environment
+. "$KERNEL_HOME/bin/setupClasspath.sh"
 
 # Run java version check with the discovered java jvm.
 . "$KERNEL_HOME/bin/checkJava.sh"
@@ -132,8 +131,8 @@
 	if [ "$CLEAN_FLAG" ]
 	then
         echo "Cleaning the serviceability and working directories..."
-        rm -rf $KERNEL_HOME/work
-        rm -rf $KERNEL_HOME/serviceability
+        rm -rf "$KERNEL_HOME/work"
+        rm -rf "$KERNEL_HOME/serviceability"
 
         LAUNCH_OPTS="$LAUNCH_OPTS -clean" #equivalent to setting osgi.clean to "true"
 	fi
@@ -163,17 +162,6 @@
 	# Set the required permissions on the JMX configuration files
 	chmod 600 "$ACCESS_PROPERTIES"
 
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-		-Dcom.sun.management.jmxremote.authenticate=true \
-		-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
-		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
-		-Djavax.net.ssl.keyStore=$KEYSTORE_PATH \
-		-Djavax.net.ssl.keyStorePassword=$KEYSTORE_PASSWORD \
-		-Dcom.sun.management.jmxremote.ssl=true \
-		-Dcom.sun.management.jmxremote.ssl.need.client.auth=false"
-
    	if [ -z "$JAVA_HOME" ]
     then
       	JAVA_EXECUTABLE=java
@@ -187,32 +175,40 @@
 	then
 		TMP_DIR=$KERNEL_HOME/work/tmp
 		# Ensure that the tmp directory exists
-		mkdir -p $TMP_DIR
+		mkdir -p "$TMP_DIR"
 
         JAVA_OPTS="-Xmx1024m \
                     -XX:MaxPermSize=512m $JAVA_OPTS"
 
-		cd $KERNEL_HOME; exec $JAVA_EXECUTABLE \
+		cd "$KERNEL_HOME"; exec $JAVA_EXECUTABLE \
 			$JAVA_OPTS \
 			$DEBUG_OPTS \
 			$JMX_OPTS \
 			-XX:+HeapDumpOnOutOfMemoryError \
-			-XX:ErrorFile=$KERNEL_HOME/serviceability/error.log \
-			-XX:HeapDumpPath=$KERNEL_HOME/serviceability/heap_dump.hprof \
-			-Djava.security.auth.login.config=$AUTH_LOGIN \
-			-Dorg.eclipse.virgo.kernel.authentication.file=$AUTH_FILE \
-			-Djava.io.tmpdir=$TMP_DIR \
-			-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-			-Dorg.eclipse.virgo.kernel.config=$CONFIG_DIR \
-			-Dosgi.sharedConfiguration.area=$CONFIG_DIR \
+			-XX:ErrorFile="$KERNEL_HOME/serviceability/error.log" \
+			-XX:HeapDumpPath="$KERNEL_HOME/serviceability/heap_dump.hprof" \
+			-Djava.security.auth.login.config="$AUTH_LOGIN" \
+			-Dorg.eclipse.virgo.kernel.authentication.file="$AUTH_FILE" \
+			-Djava.io.tmpdir="$TMP_DIR" \
+			-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+			-Dorg.eclipse.virgo.kernel.config="$CONFIG_DIR" \
+			-Dosgi.sharedConfiguration.area="$CONFIG_DIR" \
 			-Dosgi.java.profile="file:$JAVA_PROFILE" \
             -Declipse.ignoreApp=true \
-            -Dosgi.install.area=$KERNEL_HOME \
-            -Dosgi.configuration.area=$CONFIG_AREA \
+            -Dosgi.install.area="$KERNEL_HOME" \
+            -Dosgi.configuration.area="$CONFIG_AREA" \
             -Dssh.server.keystore="$CONFIG_DIR/hostkey.ser" \
-            -Dosgi.frameworkClassPath=$FWCLASSPATH \
+            -Dosgi.frameworkClassPath="$FWCLASSPATH" \
             -Djava.endorsed.dirs="$KERNEL_HOME/lib/endorsed" \
-            -classpath $CLASSPATH \
+            -Dcom.sun.management.jmxremote.port=$JMX_PORT \
+		    -Dcom.sun.management.jmxremote.authenticate=true \
+	    	-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
+    		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
+		    -Djavax.net.ssl.keyStore="$KEYSTORE_PATH" \
+		    -Djavax.net.ssl.keyStorePassword="$KEYSTORE_PASSWORD" \
+		    -Dcom.sun.management.jmxremote.ssl=true \
+		    -Dcom.sun.management.jmxremote.ssl.need.client.auth=false \
+            -classpath "$CLASSPATH" \
 			org.eclipse.equinox.launcher.Main \
             -noExit \
 			$LAUNCH_OPTS \
@@ -221,7 +217,7 @@
 elif [ "$COMMAND" = "stop" ]
 then
 
-	CONFIG_DIR=$KERNEL_HOME/configuration
+	CONFIG_DIR="$KERNEL_HOME/configuration"
 
 	#parse args for the script
 	if [ -z "$TRUSTSTORE_PATH" ]
@@ -266,11 +262,6 @@
 		esac
 		shift
 	done
-	
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Djavax.net.ssl.trustStore=${TRUSTSTORE_PATH} \
-		-Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}"
 
 	OTHER_ARGS+=" -jmxport $JMX_PORT"
 
@@ -279,10 +270,14 @@
         CONFIG_DIR=$(cygpath -wp $CONFIG_DIR)
     fi
 
-	exec $JAVA_EXECUTABLE $JAVA_OPTS $JMX_OPTS \
-		-classpath $CLASSPATH \
-		-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-		-Dorg.eclipse.virgo.kernel.authentication.file=$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties \
+	exec $JAVA_EXECUTABLE \
+	     $JAVA_OPTS \
+	     $JMX_OPTS \
+		-classpath "$CLASSPATH" \
+		-Djavax.net.ssl.trustStore="$TRUSTSTORE_PATH" \
+		-Djavax.net.ssl.trustStorePassword="$TRUSTSTORE_PASSWORD" \
+		-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+		-Dorg.eclipse.virgo.kernel.authentication.file="$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties" \
 		org.eclipse.virgo.nano.shutdown.ShutdownClient $OTHER_ARGS
 	
 else
diff --git a/virgo/nano/bin/dmk.sh b/virgo/nano/bin/dmk.sh
index f1909cf..aae69f2 100755
--- a/virgo/nano/bin/dmk.sh
+++ b/virgo/nano/bin/dmk.sh
@@ -20,15 +20,14 @@
 # make KERNEL_HOME absolute
 KERNEL_HOME=`cd "$KERNEL_HOME"; pwd`
 
-# setup classpath and java environment
-. "$KERNEL_HOME/bin/setupClasspath.sh"
-
 # execute user setenv script if needed
 if [ -r "$KERNEL_HOME/bin/setenv.sh" ]
 then
 	. $KERNEL_HOME/bin/setenv.sh
 fi
 
+# setup classpath and java environment
+. "$KERNEL_HOME/bin/setupClasspath.sh"
 
 # Run java version check with the discovered java jvm.
 . "$KERNEL_HOME/bin/checkJava.sh"
@@ -132,8 +131,8 @@
 	if [ "$CLEAN_FLAG" ]
 	then
         echo "Cleaning the serviceability and working directories..."
-        rm -rf $KERNEL_HOME/work
-        rm -rf $KERNEL_HOME/serviceability
+        rm -rf "$KERNEL_HOME/work"
+        rm -rf "$KERNEL_HOME/serviceability"
 
         LAUNCH_OPTS="$LAUNCH_OPTS -clean" #equivalent to setting osgi.clean to "true"
 	fi
@@ -163,17 +162,6 @@
 	# Set the required permissions on the JMX configuration files
 	chmod 600 "$ACCESS_PROPERTIES"
 
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Dcom.sun.management.jmxremote.port=$JMX_PORT \
-		-Dcom.sun.management.jmxremote.authenticate=true \
-		-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
-		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
-		-Djavax.net.ssl.keyStore=$KEYSTORE_PATH \
-		-Djavax.net.ssl.keyStorePassword=$KEYSTORE_PASSWORD \
-		-Dcom.sun.management.jmxremote.ssl=true \
-		-Dcom.sun.management.jmxremote.ssl.need.client.auth=false"
-
    	if [ -z "$JAVA_HOME" ]
     then
       	JAVA_EXECUTABLE=java
@@ -187,32 +175,40 @@
 	then
 		TMP_DIR=$KERNEL_HOME/work/tmp
 		# Ensure that the tmp directory exists
-		mkdir -p $TMP_DIR
+		mkdir -p "$TMP_DIR"
 
         JAVA_OPTS="-Xmx1024m \
                     -XX:MaxPermSize=512m $JAVA_OPTS"
 
-		cd $KERNEL_HOME; exec $JAVA_EXECUTABLE \
+		cd "$KERNEL_HOME"; exec $JAVA_EXECUTABLE \
 			$JAVA_OPTS \
 			$DEBUG_OPTS \
 			$JMX_OPTS \
 			-XX:+HeapDumpOnOutOfMemoryError \
-			-XX:ErrorFile=$KERNEL_HOME/serviceability/error.log \
-			-XX:HeapDumpPath=$KERNEL_HOME/serviceability/heap_dump.hprof \
-			-Djava.security.auth.login.config=$AUTH_LOGIN \
-			-Dorg.eclipse.virgo.kernel.authentication.file=$AUTH_FILE \
-			-Djava.io.tmpdir=$TMP_DIR \
-			-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-			-Dorg.eclipse.virgo.kernel.config=$CONFIG_DIR \
-			-Dosgi.sharedConfiguration.area=$CONFIG_DIR \
+			-XX:ErrorFile="$KERNEL_HOME/serviceability/error.log" \
+			-XX:HeapDumpPath="$KERNEL_HOME/serviceability/heap_dump.hprof" \
+			-Djava.security.auth.login.config="$AUTH_LOGIN" \
+			-Dorg.eclipse.virgo.kernel.authentication.file="$AUTH_FILE" \
+			-Djava.io.tmpdir="$TMP_DIR" \
+			-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+			-Dorg.eclipse.virgo.kernel.config="$CONFIG_DIR" \
+			-Dosgi.sharedConfiguration.area="$CONFIG_DIR" \
 			-Dosgi.java.profile="file:$JAVA_PROFILE" \
             -Declipse.ignoreApp=true \
-            -Dosgi.install.area=$KERNEL_HOME \
-            -Dosgi.configuration.area=$CONFIG_AREA \
+            -Dosgi.install.area="$KERNEL_HOME" \
+            -Dosgi.configuration.area="$CONFIG_AREA" \
             -Dssh.server.keystore="$CONFIG_DIR/hostkey.ser" \
-            -Dosgi.frameworkClassPath=$FWCLASSPATH \
+            -Dosgi.frameworkClassPath="$FWCLASSPATH" \
             -Djava.endorsed.dirs="$KERNEL_HOME/lib/endorsed" \
-            -classpath $CLASSPATH \
+            -Dcom.sun.management.jmxremote.port=$JMX_PORT \
+		    -Dcom.sun.management.jmxremote.authenticate=true \
+	    	-Dcom.sun.management.jmxremote.login.config=virgo-kernel \
+    		-Dcom.sun.management.jmxremote.access.file="$ACCESS_PROPERTIES" \
+		    -Djavax.net.ssl.keyStore="$KEYSTORE_PATH" \
+		    -Djavax.net.ssl.keyStorePassword="$KEYSTORE_PASSWORD" \
+		    -Dcom.sun.management.jmxremote.ssl=true \
+		    -Dcom.sun.management.jmxremote.ssl.need.client.auth=false \
+            -classpath "$CLASSPATH" \
 			org.eclipse.equinox.launcher.Main \
             -noExit \
 			$LAUNCH_OPTS \
@@ -221,7 +217,7 @@
 elif [ "$COMMAND" = "stop" ]
 then
 
-	CONFIG_DIR=$KERNEL_HOME/configuration
+	CONFIG_DIR="$KERNEL_HOME/configuration"
 
 	#parse args for the script
 	if [ -z "$TRUSTSTORE_PATH" ]
@@ -266,11 +262,6 @@
 		esac
 		shift
 	done
-	
-	JMX_OPTS=" \
-		$JMX_OPTS \
-		-Djavax.net.ssl.trustStore=${TRUSTSTORE_PATH} \
-		-Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWORD}"
 
 	OTHER_ARGS+=" -jmxport $JMX_PORT"
 
@@ -279,10 +270,14 @@
         CONFIG_DIR=$(cygpath -wp $CONFIG_DIR)
     fi
 
-	exec $JAVA_EXECUTABLE $JAVA_OPTS $JMX_OPTS \
-		-classpath $CLASSPATH \
-		-Dorg.eclipse.virgo.kernel.home=$KERNEL_HOME \
-		-Dorg.eclipse.virgo.kernel.authentication.file=$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties \
+	exec $JAVA_EXECUTABLE \
+	     $JAVA_OPTS \
+	     $JMX_OPTS \
+		-classpath "$CLASSPATH" \
+		-Djavax.net.ssl.trustStore="$TRUSTSTORE_PATH" \
+		-Djavax.net.ssl.trustStorePassword="$TRUSTSTORE_PASSWORD" \
+		-Dorg.eclipse.virgo.kernel.home="$KERNEL_HOME" \
+		-Dorg.eclipse.virgo.kernel.authentication.file="$CONFIG_DIR/org.eclipse.virgo.kernel.users.properties" \
 		org.eclipse.virgo.nano.shutdown.ShutdownClient $OTHER_ARGS
 	
 else