Index: /gs3-extensions/solr/trunk/src/gs3-setup.bat
===================================================================
--- /gs3-extensions/solr/trunk/src/gs3-setup.bat	(revision 30573)
+++ /gs3-extensions/solr/trunk/src/gs3-setup.bat	(revision 30574)
@@ -14,10 +14,18 @@
 set SOLR_PORT=8983
 set SOLR_HOST=localhost
+
+setlocal enabledelayedexpansion
+set FOUNDPROPS=
 :: Loosely based on 
 :: http://stackoverflow.com/questions/7708681/how-to-read-from-a-properties-file-using-batch-script 
 FOR /F "tokens=1,2 delims==" %%G IN (%GSDL3SRCHOME%\build.properties) DO ( 
-	if "%%G"=="tomcat.server" set SOLR_HOST=%%H
-	if "%%G"=="tomcat.port" set SOLR_PORT=%%H
+	if "%%G"=="tomcat.server" set SOLR_HOST=%%H& set FOUNDPROPS=!FOUNDPROPS!found
+	if "%%G"=="tomcat.port" set SOLR_PORT=%%H& set FOUNDPROPS=!FOUNDPROPS!found
+	:: break out of the loop as soon as both properties are found
+	if "!FOUNDPROPS!" == "foundfound" goto foundall
 )
+endlocal
+
+:foundall
 echo Tomcat host: %SOLR_HOST%
 echo Tomcat port: %SOLR_PORT%
Index: /main/trunk/gli/gli.bat
===================================================================
--- /main/trunk/gli/gli.bat	(revision 30573)
+++ /main/trunk/gli/gli.bat	(revision 30574)
@@ -167,16 +167,17 @@
 
 	rem In a web-dispersed GS3 set up like in the labs, gsdl3home.isreadonly would be true and
-	rem we need to run the web server in read-only mode. This section of code borrowed from gs3-server.bat.
-	set USE_TMPDIR_FOR_TOMCAT=
+	rem we need to run the web server in read-only mode. This section of code borrowed from gs3-server.bat.	
 	for /F "tokens=1,2 delims==" %%G in (%GSDL3SRCHOME%\build.properties) do ( 
-		if "%%G"=="gsdl3home.isreadonly" set USE_TMPDIR_FOR_TOMCAT=%%H
-	)	
-	if "%USE_TMPDIR_FOR_TOMCAT%" == "true" (
-		set gsdl3_writablehome=%TMP%\greenstone\web
-		set opt_properties="-Dgsdl3home.isreadonly=true" -Dgsdl3.writablehome="%gsdl3_writablehome%"
-		echo Setting Greenstone3 web home writable area to be: %gsdl3_writablehome%
-		pushd %GSDL3SRCHOME%
-		cmd /c ant.bat %opt_properties% configure-web
-		popd
+		if "%%G"=="gsdl3home.isreadonly" if "%%H" == "true" (
+			set gsdl3_writablehome=%TMP%\greenstone\web
+			:: not used
+			set opt_properties="-Dgsdl3home.isreadonly=true" -Dgsdl3.writablehome="%gsdl3_writablehome%"
+			echo Setting Greenstone3 web home writable area to be: %gsdl3_writablehome%
+			pushd %GSDL3SRCHOME%
+			:: passing opt_properties is no longer necessary because ant.bat is unmodified (doesn't make use of it) 
+			:: and because build.xml already contains the properties with the correct values
+			cmd /c ant.bat %opt_properties% configure-web
+			popd
+		)
 	)
 	
Index: /main/trunk/greenstone2/perllib/util.pm
===================================================================
--- /main/trunk/greenstone2/perllib/util.pm	(revision 30573)
+++ /main/trunk/greenstone2/perllib/util.pm	(revision 30574)
@@ -234,4 +234,43 @@
 
 
+# works out the temporary directory, including in the case where Greenstone is not writable
+# In that case, gs3-setup.bat would already have set the GS_TMP_OUTPUT_DIR temp variable
+sub determine_tmp_dir
+{
+	my $try_collect_dir = shift(@_) || 0;
+
+	my $tmp_dirname;
+	if(defined $ENV{'GS_TMP_OUTPUT_DIR'}) {
+		$tmp_dirname = $ENV{'GS_TMP_OUTPUT_DIR'};
+	} elsif($try_collect_dir && defined $ENV{'GSDLCOLLECTDIR'}) {
+		$tmp_dirname = $ENV{'GSDLCOLLECTDIR'};
+    } elsif(defined $ENV{'GSDLHOME'}) {
+		$tmp_dirname = $ENV{'GSDLHOME'};
+    } else {
+		return undef;
+    }
+	
+	if(!defined $ENV{'GS_TMP_OUTPUT_DIR'}) {
+		# test the tmp_dirname folder is writable, by trying to write out a file
+		# Unfortunately, cound not get if(-w $dirname) to work on directories on Windows
+			## http://alvinalexander.com/blog/post/perl/perl-file-test-operators-reference-cheat-sheet (test file/dir writable)
+			## http://www.makelinux.net/alp/083 (real and effective user IDs)
+		
+		my $tmp_test_file = &FileUtils::filenameConcatenate($tmp_dirname, "writability_test.tmp");
+		if (open (FOUT, $tmp_test_file)) {
+			close(FOUT);
+			&FileUtils::removeFiles($tmp_test_file);
+	    } else { # location not writable, use TMP location
+			$tmp_dirname = &FileUtils::filenameConcatenate($ENV{'TMP'}, "greenstone");
+			$ENV{'GS_TMP_OUTPUT_DIR'} = $tmp_dirname; # store for next time
+		}
+	}
+	
+	$tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "tmp");
+	&FileUtils::makeAllDirectories ($tmp_dirname) unless -e $tmp_dirname;
+
+	return $tmp_dirname;
+}
+
 sub get_tmp_filename 
 {
@@ -251,6 +290,5 @@
     }
 
-    my $tmpdir = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "tmp");
-    &FileUtils::makeAllDirectories ($tmpdir) unless -e $tmpdir;
+	my $tmpdir = &util::determine_tmp_dir(0);
 
     my $count = 1000;
@@ -274,17 +312,6 @@
 sub get_timestamped_tmp_folder
 {
-	
-    my $tmp_dirname;
-    if(defined $ENV{'GSDLCOLLECTDIR'}) {
-	$tmp_dirname = $ENV{'GSDLCOLLECTDIR'};
-    } elsif(defined $ENV{'GSDLHOME'}) {
-	$tmp_dirname = $ENV{'GSDLHOME'};
-    } else {
-	return undef;
-    }
-
-    $tmp_dirname = &FileUtils::filenameConcatenate($tmp_dirname, "tmp");
-    &FileUtils::makeDirectory($tmp_dirname) if (!-e $tmp_dirname);
-
+	my $tmp_dirname = &util::determine_tmp_dir(1);
+	
     # add the timestamp into the path otherwise we can run into problems 
     # if documents have the same name
Index: /main/trunk/greenstone3/gs3-server.bat
===================================================================
--- /main/trunk/greenstone3/gs3-server.bat	(revision 30573)
+++ /main/trunk/greenstone3/gs3-server.bat	(revision 30574)
@@ -53,4 +53,5 @@
 
 set GSDL3PATH=
+set USE_TMPDIR_FOR_TOMCAT=
 
 "%RUNJAVA%" -cp "%CLASSPATH%" %opt_properties% org.greenstone.server.Server3 "%GSDL3SRCHOME%"
Index: /main/trunk/greenstone3/gs3-setup.bat
===================================================================
--- /main/trunk/greenstone3/gs3-setup.bat	(revision 30573)
+++ /main/trunk/greenstone3/gs3-setup.bat	(revision 30574)
@@ -36,5 +36,5 @@
 :: set GSDL3HOME to the 'web' subdirectory
 set GSDL3HOME=!GSDL3SRCHOME!\web
-set TOMCATWEB=!GSDL3SRCHOME!\web
+set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
 :: set GSDL3HOME to any web.home property provided, and create that folder if it doesn't exist
 :: Replace forward slashes in web.home with back slashes 
@@ -44,13 +44,15 @@
 		set GSDL3HOME=%%H
 		set GSDL3HOME=!GSDL3HOME:/=\!
-		set TOMCATWEB=!GSDL3HOME!
+		set WEB_CONTAINING_CLASSES=!GSDL3HOME!		
 		if not exist "!GSDL3HOME!" cmd /c "!GSDL3SRCHOME!\userweb.cmd"
-	)
-)
-
+		goto foundwebhome
+	)	
+)
+
+:foundwebhome
 :: Whatever the web directory is, it should contain the WEB-INF\classes folder, else go back to using default for this
 :: The WEB-INF\classes folder will be absent in a userweb folder, but will be present if GSDL3HOME=GSDL3SRCHOME\web
 :: or if web.home points to GS3 as a webapp inside tomcat
-if not exist "!GSDL3HOME!\WEB-INF\classes" set TOMCATWEB=!GSDL3SRCHOME!\web
+if not exist "!GSDL3HOME!\WEB-INF\classes" set WEB_CONTAINING_CLASSES=!GSDL3SRCHOME!\web
 
 :: change if using external tomcat or ant
@@ -63,5 +65,5 @@
 :: ---- Set the CLASSPATH and PATH environment variables ----
 if "!GS_CP_SET!" == "yes" goto skipSetCp
-set CLASSPATH=!TOMCATWEB!\WEB-INF\classes;!GSDL3SRCHOME!\resources\java;!GSDL3SRCHOME!\cp.jar;!CLASSPATH!;
+set CLASSPATH=!WEB_CONTAINING_CLASSES!\WEB-INF\classes;!GSDL3SRCHOME!\resources\java;!GSDL3SRCHOME!\cp.jar;!CLASSPATH!;
 set PATH=!GSDL3SRCHOME!\bin;!GSDL3SRCHOME!\bin\script;!GSDL3SRCHOME!\lib\jni;!ANT_HOME!\bin;!PATH!
 
Index: /main/trunk/greenstone3/userweb.cmd
===================================================================
--- /main/trunk/greenstone3/userweb.cmd	(revision 30573)
+++ /main/trunk/greenstone3/userweb.cmd	(revision 30574)
@@ -14,5 +14,4 @@
 set INSTALLDIR=!GSDL3SRCHOME!
 set USERWEB=
-set IS_TMP_TOMCAT=
 
 :: Loosely based on http://stackoverflow.com/questions/7708681/how-to-read-from-a-properties-file-using-batch-script 
@@ -20,9 +19,9 @@
 :: http://scripts.dragon-it.co.uk/scripts.nsf/docs/batch-search-replace-substitute!OpenDocument&ExpandSection=3&BaseTarget=East&AutoFramed
 for /F "tokens=1,2 delims==" %%G in (!GSDL3SRCHOME!\build.properties) do ( 
-	if "%%G"=="web.home" set USERWEB=%%H& set USERWEB=!USERWEB:/=\!
-	if "%%G"=="gsdl3home.isreadonly" set IS_TMP_TOMCAT=%%H
+	if "%%G"=="web.home" set USERWEB=%%H& set USERWEB=!USERWEB:/=\!& goto found	
 )
+
+:found
 echo USERWEB: !USERWEB!
-echo IS_TMP_TOMCAT: !IS_TMP_TOMCAT!
 
 if "!USERWEB!" == "" echo No userweb directory provided & echo. & goto done
