Index: /other-projects/nightly-tasks/diffcol/trunk/diffcol/diffcol.pl
===================================================================
--- /other-projects/nightly-tasks/diffcol/trunk/diffcol/diffcol.pl	(revision 28660)
+++ /other-projects/nightly-tasks/diffcol/trunk/diffcol/diffcol.pl	(revision 28661)
@@ -50,6 +50,11 @@
 my ($gv_test_os, $gv_model_os); # still just file globals
 
-$gv_strModelColRoot = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"/model-collect");
-$gv_strTestColRoot = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"/collect");
+if($ENV{'GSDL3SRCHOME'}) {
+    $gv_strModelColRoot = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites","localsite","/model-collect");
+    $gv_strTestColRoot = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'},"web","sites","localsite","/collect");
+} else {
+    $gv_strModelColRoot = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"/model-collect");
+    $gv_strTestColRoot = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'},"/collect");
+}
 
 $gv_blnErrorStop = "false";
Index: /other-projects/nightly-tasks/diffcol/trunk/diffcol/gdbdiff.pm
===================================================================
--- /other-projects/nightly-tasks/diffcol/trunk/diffcol/gdbdiff.pm	(revision 28660)
+++ /other-projects/nightly-tasks/diffcol/trunk/diffcol/gdbdiff.pm	(revision 28661)
@@ -34,10 +34,37 @@
 }
 
+sub read_db 
+{
+    # need to sort text output of both test and model col database files, to normalise them for the comparison
+    # the -sort option to db2txt was added specifically to support diffcol
+    my($db_file) = @_;
+    my $db_cmd = "db2txt -sort $db_file 2>&1";
+    if($db_file =~ m/\.jdb$/) {
+	print STDERR "NOT YET IMPLEMENTED\n";
+	#$db_cmd = "jdb2txt -sort $db_file 2>&1";
+    }
+
+    my $db_text = readin_gdb($db_cmd);
+    return $db_text;
+}
+
+sub text_to_db_to_text
+{
+    my($db_text, $db_filename) = @_;
+
+    # http://stackoverflow.com/questions/1909262/how-can-i-pipe-input-into-a-java-command-from-perl
+    open PIPE, "| txt2db $db_filename";
+    print PIPE "$db_text";
+    close(PIPE);
+    
+    return &read_db("$db_filename");
+}
+
 # for debugging. Prints txt contents of db to file
 sub print_string_to_file 
 {
-	my ($text, $outfile) = @_;
-	
-	open(FOUT, ">$outfile") or die "ERROR failed to write to $outfile: $!\n";
+    my ($text, $outfile) = @_;
+	
+    open(FOUT, ">$outfile") or die "ERROR failed to write to $outfile: $!\n";
     print FOUT $text;
     close(FOUT);
@@ -51,11 +78,6 @@
 	my ($dbname, $dirname, $suffix)= &File::Basename::fileparse($full_testdb, "\\.[^\\.]+\$");
    
-    # need to sort text output of both test and model col database files, to normalise them for the comparison
-    # the -sort option to db2txt was added specifically to support diffcol
-    my $model_cmd = "db2txt -sort $full_modeldb 2>&1";
-    my $test_cmd  = "db2txt -sort $full_testdb 2>&1";
-
-    my $model_text = readin_gdb($model_cmd);
-    my $test_text = readin_gdb($test_cmd);
+    my $model_text = read_db($full_modeldb);
+    my $test_text = read_db($full_testdb);
 
 #	my $savepath = &getcwd."/../"; # TASK_HOME env var does not exist at this stage, but it's one level up from current directory
@@ -244,16 +266,6 @@
 		# so that we get the tmp files in the same order in both model and test collections
 		
-		# http://stackoverflow.com/questions/1909262/how-can-i-pipe-input-into-a-java-command-from-perl
-		open PIPE, "| txt2db model.gdb";
-		print PIPE "$model_text";
-		close(PIPE);
-		open PIPE, "| txt2db test.gdb";
-		print PIPE "$test_text";
-		close(PIPE);
-		
-		$model_cmd = " db2txt -sort model.gdb 2>&1";
-		$test_cmd  = "db2txt -sort test.gdb 2>&1";
-		$model_text = readin_gdb($model_cmd);
-		$test_text = readin_gdb($test_cmd);
+		$model_text = text_to_db_to_text($model_text, "model.gdb");
+		$test_text = text_to_db_to_text($test_text, "test.gdb");
 	}	
 
Index: /other-projects/nightly-tasks/diffcol/trunk/task.pl
===================================================================
--- /other-projects/nightly-tasks/diffcol/trunk/task.pl	(revision 28660)
+++ /other-projects/nightly-tasks/diffcol/trunk/task.pl	(revision 28661)
@@ -47,5 +47,5 @@
 my $pathsep = $isWin ? ";" : ":";
 #my $script_ext = $isWin ? ".bat" : ".bash";
-my $setup_script = "setup"; # needs to become gs3-setup for GS3
+my $setup_script = "setup"; # will become gs3-setup for GS3
 my $use_blat = 0; # if we ever get blat to send mail/attachments on Windows working, set this to 1
 
@@ -126,4 +126,5 @@
     } elsif($ARGV[$i] =~ m/--gs(2|3)/) {
 	$install_version = $1;
+	$setup_script = $install_version eq "3" ? "gs3-setup" : "setup"; # needs to become gs3-setup for GS3
 	splice @ARGV, $i, 1; # remove the element from the argument array
     }
@@ -190,7 +191,6 @@
 }
 
-#print STDERR "Install type $install_type\n";
-#print STDERR "Install version $install_version\n";
-
+print STDERR "Install type $install_type\n";
+print STDERR "Install version $install_version\n";
 
 #check key environment vars are set
@@ -239,13 +239,13 @@
 
 #set the location of the full report                                               
-my $xmlout=filename_concat($ENV{'DATA_DIR'}, "full-report-$dateid.xml");
+my $xmlout=filename_concat($ENV{'DATA_DIR'}, "full-report-$install_version-$dateid.xml");
 ##print STDERR "XML: $xmlout\n";
 
 # the toplevel folder of the greenstone installation being used
-my $greenstone_home="";
+my $greenstone3_home="";
+my $greenstone_home=""; # gs2build for gs3, toplevel install folder for gs2
 # gsdl is the checkout folder and can be greenstone2 or greenstone3
 my $gsdl="greenstone2";
 
-
 # Check if using existing compiled-up greenstone installation
 # and set the greenstone_home location accordingly
@@ -253,7 +253,21 @@
 if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
     print STDERR "Found existing Greenstone home, will use that instead\n";
-    $greenstone_home=$ENV{'GSDLHOME'};
+    $greenstone_home=$ENV{'GSDLHOME'} if defined $ENV{'GSDLHOME'};
+
+    if(defined $ENV{'GSDL3SRCHOME'}) {
+	print STDERR "*** GSDL3SRCHOME set, changing to using installed GS3\n";
+	$gsdl = "greenstone3";
+	$install_version = "3";
+	$greenstone3_home=$ENV{'GSDL3SRCHOME'};
+	$greenstone_home=filename_concat($greenstone3_home, "gs2build") unless defined $ENV{'GSDLHOME'};	
+    }
 } else {
-    $greenstone_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
+    if($install_version eq "3") {
+	$gsdl = "greenstone3";
+	$greenstone3_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
+	$greenstone_home=filename_concat($greenstone3_home, "gs2build");
+    } else {
+	$greenstone_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
+    }
 }
 ##print STDERR "GSHOME: $greenstone_home\n";
@@ -300,4 +314,9 @@
 sub setup_greenstone
 {
+    if($install_version eq "3" && !defined $ENV{'JAVA_HOME'}) {
+	print "*** JAVA_HOME not set. Set it and add its bin folder to the PATH\n";
+	exit 0;
+    }
+
     #clean up from previous tests
     print STDERR "about to clean up any old tests (Ctrl-C to cancel)"; # no newline
@@ -310,8 +329,15 @@
     # http://perldoc.perl.org/File/Path.html
     print STDERR "cleaning up previous tests\n";
-    &File::Path::remove_tree($ENV{'DATA_DIR'});
-
+    #&File::Path::remove_tree($ENV{'DATA_DIR'});
+    if(-d $greenstone_home && $install_version eq "2") {
+	&File::Path::remove_tree($greenstone_home);
+    }
+    if(-d $greenstone3_home && $install_version eq "3") {
+	&File::Path::remove_tree($greenstone3_home);
+    }
+    unlink glob "$ENV{'DATA_DIR'}$sep"."*report-$install_version*";
+    unlink "$ENV{'DATA_DIR'}$sep"."compilation-errors";
     print STDERR "creating the data dir\n";
-    &File::Path::make_path($ENV{'DATA_DIR'}); # works like mkdir -p
+    #&File::Path::make_path($ENV{'DATA_DIR'}); # works like mkdir -p
 
     chdir($ENV{'DATA_DIR'});
@@ -324,8 +350,22 @@
 
     # Else checkout a GS from svn into DATA_DIR
+    if($install_type eq "svn") {
+	&checkout_gs_from_svn();
+	##print STDERR "$ENV{'DATA_DIR'}$sep$gsdl\n";
+
+	if($install_version eq "2") {
+	    &compile_gs2_svn();
+	} else {
+	    &compile_gs3_svn();
+	}
+    }
+
+}
+
+sub checkout_gs_from_svn {
 
     #svn checkout of main gsdl directory                                       
     print STDERR "checkout $gsdl:\n";
-    my $cmd = "svn co ".$ENV{'SVN_OPT_REV'}." http://svn.greenstone.org/main/trunk/greenstone2 $gsdl";
+    my $cmd = "svn co ".$ENV{'SVN_OPT_REV'}." http://svn.greenstone.org/main/trunk/greenstone$install_version $gsdl";
     ##print STDERR "Checkout CMD: $cmd\n";
 
@@ -333,57 +373,46 @@
     # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
     my $status = system "$cmd"; #my $status = `$cmd`;
-	if($status != 0) {
-		print STDERR "@@@ SVN checkout of $gsdl failed\n";
-		exit -1;
-	}	
+    if($status != 0) {
+	print STDERR "@@@ SVN checkout of $gsdl failed\n";
+	exit -1;
+    }	
     print STDERR "done\n";
-
-    ##print STDERR "$ENV{'DATA_DIR'}$sep$gsdl\n";
-
-    chdir("$ENV{'DATA_DIR'}$sep$gsdl");
-
-    ##print STDERR "@@@ OS:  $^O.|".$Config{'archname64'}."|\n";
-	
-    if($isWin) {
-		print STDERR "Compiling $gsdl using makegs2.bat running in auto (silent) mode\n";
-	
-		# we're now in the GS2 folder, call makegs2 with silent param
-		$cmd = "makegs2.bat silent 2>> $ENV{'DATA_DIR'}/compilation-errors"; # STDERR is sent to compilation-errors file
-		$status = system $cmd;
-		if($status != 0) {
-			print STDERR "Greenstone compilation on Windows failed\n";
-			exit -1;
-		}
-		
-	} else { # if we're on linux/darwin, need gnome-lib for the correct architecture. And need imagemagick to build imgs in collections
+}
+
+sub getImageMagickBins {
+    my ($cmd, $status);
+    my $imagickzip = "";
+
+    chdir ("$greenstone_home");
+    if(!$isWin) { # if we're on linux/darwin, need gnome-lib for the correct architecture. And need imagemagick to build imgs in collections
 	   
 	my $bit_arch=`uname -m`;
-
-	# imagmagick binary
+	
+	# imagemagick binary
 	print STDERR "Getting imagemagick binary\n";
-
+	
 	my $os = $isMac ? "darwin" : "linux";
-	my $imagickzip = "imagemagick-$os";
+	$imagickzip = "imagemagick-$os";
 	
 	if($isMac) {
-#		$imagickzip .= "-10.5.tar.gz";
+#	    $imagickzip .= "-10.5.tar.gz";
 	    # at present, only the Imagemagick binaries created by Max for darwin work on the Macs
-	    &File::Path::make_path($ENV{'DATA_DIR'}."$sep$gsdl$sep$os"); # need to ensure gsdl/bin/darwin exists
+#	    &File::Path::make_path("$greenstone_home$sep"."bin"."$sep$os"); # need to ensure gsdl/bin/darwin exists
 	    $cmd = "svn export http://svn.greenstone.org/main/trunk/binaries/mac/intel/imagemagick bin/darwin/imagemagick";
 	    $status = system($cmd);
-		if($status != 0) {
-			print STDERR "@@@ Unable to get imagemagick for darwin\n";
-		}
-
-		# need ghostscript mac binary too for pdf to img conversions on mac
+	    if($status != 0) {
+		print STDERR "@@@ Unable to get imagemagick for darwin\n";
+	    }
+	    
+	    # need ghostscript mac binary too for pdf to img conversions on mac
 	    $cmd = "svn export http://svn.greenstone.org/main/trunk/binaries/mac/intel/ghostscript bin/darwin/ghostscript";
 	    $status = system($cmd);
-		if($status != 0) {
-			print STDERR "@@@ Unable to get ghostscript for darwin\n";
-		}
-
-		# the imagemagick and ghostscript binaries have been set to executable on svn trac now
-#		system("chmod -R u+x $ENV{'DATA_DIR'}/$gsdl/bin/darwin/imagemagick/bin/*");
-#		system("chmod -R u+x $ENV{'DATA_DIR'}/$gsdl/bin/darwin/ghostscript/bin/*");
+	    if($status != 0) {
+		print STDERR "@@@ Unable to get ghostscript for darwin\n";
+	    }
+	    
+	    # the imagemagick and ghostscript binaries have been set to executable on svn trac now
+#	    system("chmod -R u+x $greenstone_home/bin/darwin/imagemagick/bin/*");
+#	    system("chmod -R u+x $greenstone_home/bin/darwin/ghostscript/bin/*");
 	} else { # linux
 	    my $extension64 = ($bit_arch =~ m/64$/) ? "-x64" : "";
@@ -395,4 +424,13 @@
 	    system("cd ext && tar -xvzf $imagickzip");
 	}
+    }
+    return $imagickzip;
+}
+
+sub getGnomeLibExt
+{
+    my ($cmd, $status);
+    my $bit_arch=`uname -m`;
+    my $os = $isMac ? "darwin" : "linux";
 
 	# gnomelib binary
@@ -412,5 +450,5 @@
 
 	#svn checkout gnome-lib for this linux/darwin
-	chdir("$ENV{'DATA_DIR'}$sep$gsdl$sep"."ext"); #cd $DATA_DIR/$gsdl/ext
+	chdir("$greenstone_home$sep"."ext"); #cd $DATA_DIR/$gsdl/ext
 
 	##print STDERR "**** gnomelib: $gnome_lib_file\n";
@@ -423,7 +461,64 @@
 	system ("tar -xvzf gl.tar.gz");
 
-	chdir("gnome-lib-minimal");
 	##print STDERR "*** ARCH: $bit_arch\n";
-
+}
+
+
+
+sub compile_gs3_svn() {
+    my ($cmd, $status);
+    chdir ("$greenstone3_home");
+
+    $cmd = "ant"; # creates the build.properties file from the .in template
+    $status = system $cmd;
+    if($status != 0) {
+	print STDERR "Unable to run the ant command: $status\n";
+	exit -1;
+    }
+    
+    $cmd = "ant -Dproperties.ok=y -Dcheckout.gnomelib.ext=true prepare"; # pass in confirmation to ant prepare step
+    $status = system $cmd;
+    if($status != 0) {
+	print STDERR "Failed to run $cmd command: $status\n";
+	exit -1;
+    }
+
+    my $imagickzip = &getImageMagickBins();
+    chdir ("$greenstone3_home");
+
+    $cmd = "ant -Dcheckout.gnomelib.ext=true install"; # Compile with gnome-lib.
+    $status = system $cmd;
+    if($status != 0) {
+	print STDERR "Failed to run $cmd command: $status\n";
+	exit -1;
+    }
+}
+
+sub compile_gs2_svn() {    
+    my $imagickzip = &getImageMagickBins();
+    &getGnomeLibExt(); 
+
+    my ($cmd, $status);
+    my $os = $isMac ? "darwin" : "linux";
+
+    chdir("$greenstone_home"); #chdir("$ENV{'DATA_DIR'}$sep$gsdl"); # goes into toplevel gs2 or gs3 folder
+
+    ##print STDERR "@@@ OS:  $^O.|".$Config{'archname64'}."|\n";
+	
+    if($isWin) {
+	print STDERR "Compiling $gsdl using makegs2.bat running in auto (silent) mode\n";
+	
+	# we're now in the GS2 folder, call makegs2 with silent param
+	$cmd = "makegs2.bat silent 2>> $ENV{'DATA_DIR'}/compilation-errors"; # STDERR is sent to compilation-errors file
+	$status = system $cmd;
+	if($status != 0) {
+	    print STDERR "Greenstone compilation on Windows failed\n";
+	    exit -1;
+	}
+	
+    } else { # if we're on linux/darwin, need gnome-lib for the correct architecture. And need imagemagick to build imgs in collections
+	
+	chdir("ext$sep"."gnome-lib-minimal");
+	
 	# need to run source devel.bash on gnome-lib followed by configure, make, make install 
 	# in one go, in order to preserve the compile environment set up by sourcing devel.bash
@@ -464,22 +559,21 @@
 
 	if(!$isMac) { # Linux
-	    # Moving imagemagick after instead of before compilation, since bin/darwin gets overwritten during compilation
-	    move("$ENV{'DATA_DIR'}$sep$gsdl$sep"."ext/imagemagick/$os", "$ENV{'DATA_DIR'}$sep$gsdl$sep"."bin/$os/imagemagick"); # http://www.perlmonks.org/?node_id=586537
-	    unlink "$ENV{'DATA_DIR'}/$gsdl"."/ext/$imagickzip" or warn "Could not unlink ext/$imagickzip: $!";
-	    &File::Path::remove_tree("$ENV{'DATA_DIR'}$sep$gsdl$sep"."ext/imagemagick"); # the untarred parent folder
-	}
-
-    }
-	
-	if($status != 0) {
-		print STDERR "@@@ Compilation of Greenstone on Linux/Mac failed\n";
-		exit -1;
-	}
-
-    &getIsisGdl("$ENV{'DATA_DIR'}/$gsdl");
+	    # Moving imagemagick after instead of before compilation, since bin/darwin and bin/linux gets overwritten during compilation
+	    move("$greenstone_home$sep"."ext/imagemagick/$os", "$greenstone_home$sep"."bin/$os/imagemagick"); # http://www.perlmonks.org/?node_id=586537
+	    unlink "$greenstone_home$sep"."ext$sep$imagickzip" or warn "Could not unlink ext/$imagickzip: $!";
+	    &File::Path::remove_tree("$greenstone_home$sep"."ext$sep"."imagemagick"); # the untarred parent folder
+	}
+
+    }
+	
+    if($status != 0) {
+	print STDERR "@@@ Compilation of Greenstone on Linux/Mac failed\n";
+	exit -1;
+    }
+    
+    &getIsisGdl("$greenstone_home"); #&getIsisGdl("$ENV{'DATA_DIR'}/$gsdl");
 	
     # set the path to the greenstone_home variable                             
-    $greenstone_home="$ENV{'DATA_DIR'}$sep$gsdl";
-	
+    #$greenstone_home="$ENV{'DATA_DIR'}$sep$gsdl";	
 }
 
@@ -542,4 +636,5 @@
     
     if(!$isWin) {
+	chdir($greenstone_home);
 	my $bit_arch=`uname -m`;
 	if ($bit_arch =~ m/64$/) {
@@ -560,5 +655,17 @@
 # http://stackoverflow.com/questions/3377879/how-do-i-receive-command-output-immediately
 sub run_test
-{	
+{
+    my $collect_parent = $greenstone_home;
+    my $model_collect = "model-collect";
+    my $build_options = "";
+    if($install_version eq "3") {
+	$collect_parent = &filename_concat($greenstone3_home,"web","sites","localsite");	
+	$model_collect = "gs3-model-collect";
+	$build_options = " -site localsite ";
+	chdir($greenstone3_home);
+    } else {
+	chdir($greenstone_home);
+    }
+
 	my $num_cols = scalar(@collections); # remember the empty case
 	
@@ -594,13 +701,13 @@
 	
 	if(!$use_local_rebuild) {	
-		print $xml_fh "Updating $ENV{'TASK_HOME'}/model-collect:\n";
+		print $xml_fh "Updating $ENV{'TASK_HOME'}/$model_collect:\n";
 		for my $col (@collections) {
-			$cmd = "svn up $ENV{'TASK_HOME'}/model-collect$col"; #chdir("$ENV{'TASK_HOME'}/model-collect");
+			$cmd = "svn up $ENV{'TASK_HOME'}/$model_collect$col"; #chdir("$ENV{'TASK_HOME'}/$model_collect");
 			$status = system "$cmd";
 		}
 	}
 
-    # go to whichever greenstone_home we're using
-    chdir($greenstone_home);
+    # go to whichever collecthome parent we're using
+    chdir($collect_parent);
 
     # get svn info
@@ -619,5 +726,4 @@
 	    #copy the model collections to the collect folder to be rebuilt
 		print STDERR "installing test collections and model collections to new $gsdl installation... ";
-	
 		#clean up
 		if(-d "collect") {
@@ -642,5 +748,5 @@
 				#copy to collect and strip .svn subfolders
 				&File::Path::make_path("collect$col"); # create the folder and copy contents across
-				&copy_recursively(&filename_concat("$ENV{'TASK_HOME'}","model-collect$col"), "collect$col", ".svn");
+				&copy_recursively(&filename_concat("$ENV{'TASK_HOME'}","$model_collect$col"), "collect$col", ".svn");
 				
 				#make the model copy
@@ -659,5 +765,5 @@
 		@collections = (); # get rid of the empty string put in the array to represent "all collections"
 		
-		opendir my($collect_handle), "collect" or die "Could not open dir $greenstone_home/collect: $!";
+		opendir my($collect_handle), "collect" or die "Could not open dir $collect_parent/collect: $!";
 	
 		for my $collection (readdir $collect_handle) {
@@ -687,4 +793,11 @@
 	print STDERR "*** Found collection $collection\n";
 	print $xml_fh "<collection-test name=\"$collection\">\n";
+
+	# run the building scripts from the toplevel of the GS installation
+	if($install_version eq "3") {
+	    chdir($greenstone3_home);
+	} else {
+	    chdir($greenstone_home);
+	}
 
 	if(!$use_local_rebuild) {		
@@ -696,5 +809,5 @@
 		print STDERR "$collection - Importing:\n";
 		print $xml_fh "<import>\n";
-		&run_build_script("import.pl -removeold $collection"); #-OIDtype hash_on_full_filename
+		&run_build_script("import.pl $build_options -removeold $collection"); #-OIDtype hash_on_full_filename
 		print $xml_fh "</import>\n";
 		print STDERR "done\n";	
@@ -703,5 +816,5 @@
 		print STDERR "$collection - Building:\n";
 		print $xml_fh "<build>\n";
-		&run_build_script("buildcol.pl -removeold $collection");
+		&run_build_script("buildcol.pl $build_options -removeold $collection");
 		print $xml_fh "</build>\n";
 		print STDERR "done\n";
@@ -709,6 +822,6 @@
 		#rename the intermediate 'building' directory 'index'
 		print STDERR "$collection - Move \"building\" to \"index\"... ";
-		my $index = &filename_concat("collect", $collection, "index");
-		my $building = &filename_concat("collect", $collection, "building");
+		my $index = &filename_concat($collect_parent, "collect", $collection, "index");
+		my $building = &filename_concat($collect_parent, "collect", $collection, "building");
 		&File::Path::remove_tree($index);
 		# Renaming Directories, http://www.perlmonks.org/?node_id=177421
@@ -720,4 +833,5 @@
 	my $diffcol_dir = &filename_concat($ENV{'TASK_HOME'},"diffcol");
 	
+#	chdir($collect_parent); # this is actually where we are
 	# help diffcol to know on what os the model cols were generated
 	# and what os this test machine is (on which the test cols will be generated)
@@ -725,5 +839,9 @@
 	&run_diff_script($cmd, $xml_fh, $diffcol_dir);
 
-	chdir($greenstone_home); # this is actually where we are
+	if($install_version eq "3") {
+	    chdir($greenstone3_home); # this is actually where we are
+	} else {
+	    chdir($greenstone_home); # this is actually where we are
+	}
 	print STDERR "done\n";
 	print $xml_fh "</collection-test>\n";
@@ -741,10 +859,12 @@
     my ($cmd, $fh, $diffcol_dir) = @_;
 
+    my $linux_ext = ($install_version eq "3") ? "sh" : "bash";
+
     # we're in greenstone_home now
     if(!$isWin) {	
-	$cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && cd $diffcol_dir && ./$cmd\"";
+	$cmd = "bash -c \"export GSDL3SRCHOME=&& export GSDLHOME=&& source $setup_script.$linux_ext && cd $diffcol_dir && ./$cmd\"";
 
     } else { # Need to prefix cmd -c/-k as necessary
-	$cmd = "cmd /c \"set GSDLHOME=&& $setup_script.bat && cd $diffcol_dir && perl -S $cmd\"";
+	$cmd = "cmd /c \"set GSDL3SRCHOME=&& set GSDLHOME=&& $setup_script.bat && cd $diffcol_dir && perl -S $cmd\"";
 ##	print STDERR "@@@@ Going to call command: $cmd\n";	
     }
@@ -756,12 +876,13 @@
 sub run_build_script {    
     my ($cmd, $fh) = @_;
+    my $linux_ext = ($install_version eq "3") ? "sh" : "bash";
 
 #    chdir($greenstone_home);
     # we are in $greenstone_home already, can directly run the build cmd on the collection
     if(!$isWin) {
-	$cmd = "bash -c \"export GSDLHOME=&& source $setup_script.bash && $cmd\"";
+	$cmd = "bash -c \"export GSDL3SRCHOME=&& export GSDLHOME=&& source $setup_script.$linux_ext && $cmd\"";
 
     } else { # Need to prefix cmd -c/-k as necessary
-	$cmd = "cmd /c \"set GSDLHOME=&& $setup_script.bat && perl -S $cmd\"";
+	$cmd = "cmd /c \"set GSDL3SRCHOME=&& set GSDLHOME=&& $setup_script.bat && perl -S $cmd\"";
     }
 ##     print STDERR "@@@@ Going to call command: $cmd\n";
@@ -845,5 +966,5 @@
     # make a summarised Xml report
     print STDERR "Summarizing the xml report... ";
-    my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/xml-report.xsl -OUT $ENV{'DATA_DIR'}/report-$dateid.xml";
+    my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/xml-report.xsl -OUT $ENV{'DATA_DIR'}/report-$install_version-$dateid.xml";
     my $status = system($cmd);
     print STDERR "done\n";
@@ -851,5 +972,5 @@
     # make a summarised HTMl report
     print STDERR "Creating an html summary report... ";
-    $cmd = "java org.apache.xalan.xslt.Process -IN $ENV{'DATA_DIR'}/report-$dateid.xml -XSL $ENV{'TASK_HOME'}/xsl/html-report.xsl -OUT $ENV{'DATA_DIR'}/report-$dateid.html";
+    $cmd = "java org.apache.xalan.xslt.Process -IN $ENV{'DATA_DIR'}/report-$install_version-$dateid.xml -XSL $ENV{'TASK_HOME'}/xsl/html-report.xsl -OUT $ENV{'DATA_DIR'}/report-$install_version-$dateid.html";
     $status = system($cmd);
     print STDERR "done\n";
@@ -880,4 +1001,5 @@
     for my $entry (readdir $dh) {
 	next if ($entry !~ m/(\.xml|\.html?)$/);
+	next if ($entry !~ m/(report-$install_version)/);
 
 	# copy the reports across with different names: with OS prefixed to them. And for the HTML file on Win, rename to HTM
@@ -923,5 +1045,5 @@
 	# if you need to touch the file on windows: http://stackoverflow.com/questions/51435/windows-version-of-the-unix-touch-command
 	
-	# the report we want to upload is actually just os-diffcol-report-$dateid.html
+	# the report we want to upload is actually just os-diffcol-report-$install_version-$dateid.html
 	my $command = "cd \"$ENV{'UPLOAD_DIR'}\" && tar -c *.htm* | "; #&& cat *.html | "; # && tar -c * |
 	$command .= ($^O eq "MSWin32" ? "plink" : "ssh");
@@ -955,5 +1077,5 @@
 	my $msg = "$gsdl regression test for $dateid failed";
 	my $subject = "Regression Test Failed"; #"$gsdl regression test for $dateid failed\n";
-	my $attach_file = &filename_concat($ENV{'DATA_DIR'}, "report-$dateid.html");
+	my $attach_file = &filename_concat($ENV{'DATA_DIR'}, "report-$install_version-$dateid.html");
 
 	if($isWin) {	
