Index: /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/aliases.txt
===================================================================
--- /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/aliases.txt	(revision 36214)
+++ /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/aliases.txt	(revision 36214)
@@ -0,0 +1,17 @@
+release
+gs2-caveat
+gs2-caveat-x64
+gs2-stable
+gs2-stable-x64
+gs3-caveat
+gs3-caveat-x64
+gs3-stable
+gs3-stable-x64
+gs2-src-caveat
+gs2-src-stable
+gs3-src-caveat
+gs3-src-stable
+gs2-cd-caveat
+gs2-cd-stable
+dec-caveat
+dec-stable
Index: /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/environment.pl
===================================================================
--- /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/environment.pl	(revision 36214)
+++ /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/environment.pl	(revision 36214)
@@ -0,0 +1,21 @@
+#Where to keep snapshots
+$ENV{'DATA_DIR'} = "/gs-release-builder/snapshots";
+
+#Where to find release kits and ant
+$ENV{'PATH'} = "/gs-release-builder/release-kits/bin:$ENV{'PATH'}";
+
+#Setting JAVA_HOME
+$ENV{'JAVA_HOME'} = "/gs-release-builder/packages/jdk1.8.0_301";
+
+# setting javacflags - needed for release kit to target java classes
+$ENV{'JAVACFLAGS'} = "-source 1.8 -target 1.8";
+    
+#Adding JAVA_HOME to PATH
+$ENV{'PATH'} = "$ENV{'JAVA_HOME'}/bin:$ENV{'PATH'}";
+#$ENV{'LD_LIBRARY_PATH'} = "$ENV{'JAVA_HOME'}/jre/lib/amd64/jli:/home/sjm84/subversion/src/linux/lib:$ENV{'LD_LIBRARY_PATH'}";
+$ENV{'LD_LIBRARY_PATH'} = "$ENV{'JAVA_HOME'}/jre/lib/amd64/jli:/greenstone/packages/subversion/linux/lib:$ENV{'LD_LIBRARY_PATH'}";
+
+# Need to set -fPIC (for generating position independent code) among the CFLAGS
+# in order to get Expat to compile up on bedrock
+#$ENV{'CFLAGS'}="-fPIC $ENV{'CFLAGS'}";
+### do we need this??
Index: /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/lib.pl
===================================================================
--- /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/lib.pl	(revision 36214)
+++ /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/lib.pl	(revision 36214)
@@ -0,0 +1,399 @@
+my $sep = $^O eq "MSWin32" ? "\\" : "/";
+
+sub get_date {
+	local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+	local $day = $mday;
+	local $month = $mon+1;
+	local $year = $year+1900;
+	if ( length $month == 1 ) {
+		$month = join( "", "0", $month);
+	}
+	if ( length $day== 1 ) {
+		$day = join( "", "0", $day );
+	}
+	local $date = join( ".", $year,$month,$day );
+	return $date;
+}
+
+sub gen_snapshot_id {
+	if ( exists $_[0] && exists $_[1] ) {
+		return $_[0] . get_date() . $_[1];
+	}
+
+	if ( exists $_[0] ) {
+		return $_[0] . get_date();
+	}
+	return get_date();
+}
+
+sub create_release {
+
+	die "Must provide parameter to create_release\n" unless (exists $_[0]);
+	
+	my $release_folder_name = $_[0];
+	
+	my $release_version = $release_folder_name;
+	$release_version =~ s/^gs-?//;
+	$release_version =~ s/rc\d$//;
+	my $major_version = $release_version;
+	$major_version =~ s/^(3|2).*/$1/;	
+	$release_version =~ s/^($major_version)\.?(\d*).*/$1.$2/;
+	my $rk = "rk".$major_version;
+	
+	my $release_version_extra;
+	if ($release_folder_name =~ m/(rc\d)$/) {
+		$release_version_extra = $1;
+	}
+	if ($release_folder_name !~ m/^gs/) { # prefix gs
+		$release_folder_name = "gs".$release_folder_name;
+	}
+	my $release_dir = "$ENV{'DATA_DIR'}${sep}$release_folder_name";
+	
+	print "major_version: $major_version\n";
+	print "version: $release_version\n";
+	print "versionextra: $release_version_extra\n";
+	print "release_folder_name: $release_folder_name\n";
+	print "release_dir: $release_dir\n";
+	
+	print "about to clean up old snapshots (Ctrl-C to cancel)";
+	local $| = 1;
+	for ( my $i=0; $i<5; $i++ ) {
+		print ".";
+		sleep 1;
+	}
+	$| = 0;
+
+	print "cleaning up previous release snapshot $release_dir\n";
+	
+	if(-d $release_dir) {
+		if ( $^O eq "MSWin32" ) {
+			system("rd /q /s \"$release_dir\"");
+		} else {
+			system("rm -rf \"$release_dir\"");
+		}
+	}
+		
+	print "creating the release dir\n";	
+	mkdir $release_dir or die "couldn't create release directory\n";
+
+	print "changing to the release dir\n";
+	chdir $release_dir;
+
+	#version property
+ 	print "setting up todays properties\n";
+	`echo version:$release_version> $rk-build.properties`;
+
+	if($release_version_extra) {
+		`echo version-extra:$release_version_extra>> $rk-build.properties`;
+	}	
+	
+	#processor propertylocal $| = 1;
+	if ( $^O eq "darwin" ) {
+		print "setting processor\n";
+		if ( `uname -p` eq "i386" ) {
+			`echo processor:intel>> $rk-build.properties`;
+		} elsif ( `uname -p` eq "powerpc" ) {
+			`echo processor:ppc>> $rk-build.properties`;
+		} else {
+			print "unable to determine processor type, using intel\n";
+			`echo processor:intel>> $rk-build.properties`;
+		}
+	} elsif ( $^O eq "linux" ) {
+		if(`uname -m` =~ m/64$/) {
+			print "Setting linux architecture to 64 bit";
+			`echo x64:true>> $rk-build.properties`;
+		}		
+	}
+
+	#branch path property
+	if ( $ENV{'branch_path'} ) {
+		`echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
+	}
+
+	#server.exe.location
+	if ( $major_version eq "2" && exists $ENV{'SERVER_EXE_LOCATION'} ) {
+		`echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
+	}
+
+	print "creating the snapshot using $rk\n";
+	system( $rk );
+}
+
+sub create {
+	
+	die "release_dir not set, cant create\n" unless $release_dir;
+
+	print "about to clean up old snapshots (Ctrl-C to cancel)";
+	local $| = 1;
+	for ( my $i=0; $i<5; $i++ ) {
+		print ".";
+		sleep 1;
+	}
+	$| = 0;
+
+	print "cleaning up previous snapshot\n";
+	local $release_parent = dirname($release_dir);
+	if ( $^O eq "MSWin32" ) {
+		system("rd /q /s \"$release_parent\"");
+	} else {
+		system("rm -rf \"$release_parent\"");
+	}
+
+	print "creating the release dir\n";
+	mkdir $release_parent or die "couldn't create release parent directory\n";
+	mkdir $release_dir or die "couldn't create release directory\n";
+
+	print "changing to the release dir\n";
+	chdir $release_dir;
+
+	#version property
+ 	print "setting up todays properties\n";
+	`echo version:$snapshot_id> $rk-build.properties`;
+
+	#processor propertylocal $| = 1;
+	if ( $^O eq "darwin" ) {
+		print "setting processor\n";
+		if ( `uname -p` eq "i386" ) {
+			`echo processor:intel>> $rk-build.properties`;
+		} elsif ( `uname -p` eq "powerpc" ) {
+			`echo processor:ppc>> $rk-build.properties`;
+		} else {
+			print "unable to determine processor type, using intel\n";
+			`echo processor:intel>> $rk-build.properties`;
+		}
+	}
+
+	#branch path property
+	if ( $ENV{'branch_path'} ) {
+		`echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
+	}
+
+	#x64 bit property
+	if ( $ENV{'x64'} ) {
+	        `echo x64:true>> $rk-build.properties`;
+	}
+
+	#server.exe.location
+	if ( exists $ENV{'SERVER_EXE_LOCATION'} ) {
+		`echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
+	}
+
+	print "creating the snapshot using $rk\n";
+	system( $rk );
+
+}
+
+sub upload {
+	print "preparing files for uploading\n";
+
+	my @munges = ();
+	if ( exists $ENV{'munges'} ) {
+		@munges = split(' ', $ENV{'munges'});
+	}
+
+	#copy products to a temporary folder, giving them their new names
+	if ( -d "$release_dir${sep}uploads" ) {
+		system( "rm -rf '$release_dir${sep}uploads'" );
+	}
+	mkdir "$release_dir${sep}uploads";
+
+	my @files;
+	if ( -d "$release_dir${sep}products" ) {
+		@files = <$release_dir${sep}products${sep}*>;
+	}
+	push( @files, "$release_dir${sep}$rk.out" );
+
+	for my $file ( @files ) {
+		if ( -e $file ) {
+			my $filename = basename($file);
+			#munge
+			for my $m ( @munges ) {
+				$doit="\$filename =~ $m"; eval "$doit";
+			}
+			#upload
+			print "Will upload '" . basename($file) . "' to '$filename'\n";
+			if( $^O =~ "linux|darwin" ) {
+				system("cp \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
+			}
+			else {
+				system("copy \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
+			}
+		}
+
+	}
+
+# puka is no longer
+#	my $command = "cd \"${release_dir}${sep}uploads\" && tar -c * | ";
+#	$command .= ($^O eq "MSWin32" ? "plink" : "ssh");
+#	$command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
+	#print "$command\n";
+#	system("$command");
+	
+	# ssh too old inside lsb to upload to www-internal, so we do that in a separate step later
+#	$command = "cd \"${release_dir}${sep}uploads\" && tar -c * | ";
+#	$command .= ($^O eq "MSWin32" ? "plink" : "ssh");
+#	$command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl-gsorg\@www-internal.greenstone.org";
+
+	#print "$command\n";
+#	system("$command");
+}
+
+# EMAILING DOESN'T WORK, as SMTP not setup on release-kit LSB machines
+
+#sub xsend_mail_on_releasekit_fail {
+
+    # first, create your message
+    # use Email::MIME;
+#     my $message = Email::MIME->create(
+# 	header_str => [
+# 	    From    => $ENV{'MONITOR_EMAIL'},
+# 	    To      => $ENV{'MONITOR_EMAIL'},
+# 	    Subject => 'Trial message',
+# 	],
+# 	attributes => {
+# 	    encoding => 'quoted-printable',
+# 	    charset  => 'ISO-8859-1',
+# 	},
+# 	body_str => "Email test!\n",
+# 	);
+    
+#     # send the message
+#     use Email::Sender::Simple qw(sendmail);
+#     sendmail($message);
+
+    # %mail = ( To      => $ENV{'MONITOR_EMAIL'},
+# 	      From    => $ENV{'MONITOR_EMAIL'},
+# 	      Message => "This is a test message"
+# 	);
+    
+#     sendmail(%mail) or die $Mail::Sendmail::error;
+    
+#     print "OK. Log says:\n", $Mail::Sendmail::log;
+#}
+
+# EMAILING DOESN'T WORK, as SMTP not setup on release-kit LSB machines
+
+# Copied from diffcol's task.pl into here
+# Sending emails with perl: http://learn.perl.org/examples/email.html
+# Sending email attachments with perl: http://www.perlmonks.org/?node_id=19430
+# Sadly none of the packages are installed by default and use of MIME::Lite is discouraged
+sub send_mail_on_releasekit_fail
+{
+    # email greenstone_team if build failed
+
+    my $logfile="$release_dir${sep}$rk.out";
+    my $finalLinesLogOutput=`tail -n 50 $logfile`;
+
+    print STDERR "Checking if successful... \n";
+    # using reverse index to search from bottom of tail output
+    my $had_error = 0;
+
+    if (rindex($finalLinesLogOutput, "BUILD FAILED") != -1) {
+	# release-kit failed to build binary
+	$had_error = 1;
+    }
+    elsif (rindex($finalLinesLogOutput, "BUILD SUCCESSFUL") != -1) {
+	# SUCCESS!
+	$had_error = 0; 
+    }
+    else {
+	# saw neither BUILD FAILED nor BUILD SUCCESSFUL in tail of log output
+	# Could be that building never completed, still want to be notified
+	$had_error = 2;
+    }
+
+
+    if(!$had_error) {
+	# everything fine, no need to email
+	return;
+    }
+
+
+    print STDERR "Build had error code: $had_error\n";
+    # let's send the last 200 lines of the log file to the user as email
+    # 
+    $finalLinesLogOutput=`tail -n 200 $logfile`;
+
+    my $msg = "Last 200 lines in the log:\n$finalLinesLogOutput";
+    my $subject = "Release-kit $release_dir failed"; # mentions OS, bitness, date
+    
+    # let's attach logfile besides	
+    
+    if($isWin) {	
+	if($use_blat && $blat && $ENV{'GSDL_SMTP'}) {
+	    # http://stackoverflow.com/questions/709635/sending-mail-from-batch-file
+	    #blat -to user@example.com -server smtp.example.com -f batch_script@example.com -subject "subject" -body "body"
+	    
+	    # need to install blat on windows
+	    $cmd = "$blat -to $ENV{'MONITOR_EMAIL'} -server $ENV{'GSDL_SMTP'} -f $ENV{'MONITOR_EMAIL'} -attach $logfile -subject \"$subject\" -body \"$msg\"";			
+	    $result = system($cmd);	
+	}
+	else {
+	    $result = 1; # status from running mail command is 0 if success, 1 if fail
+	    print STDERR "********************************************\n";
+	    if ($use_blat) {
+		print STDERR "Need blat and SMTP set to send mail attachment\n" ;
+	    } else {	
+		print STDERR "Not set up to send mail on Windows\n";
+	    }
+	    print STDERR "Inspect release-kit build log at: $log_file\n";
+	    print STDERR "********************************************\n";
+	}
+    } else { # linux
+
+	# try using sendmail, since mutt is not installed on lsb
+	# https://vitux.com/three-ways-to-send-email-from-ubuntu-command-line/
+	# Sending attachment with sendmail is too involved, see
+	#   https://unix.stackexchange.com/questions/223636/sendmail-attachment/223650
+	#   https://askubuntu.com/questions/355823/sending-file-using-sendmail
+	# Will just put the contents of the rk log file in the body.
+
+	# read in all of logfile
+	# https://stackoverflow.com/questions/206661/what-is-the-best-way-to-slurp-a-file-into-a-string-in-perl
+	my $contents = do {local (@ARGV,$/) = $logfile; <>};
+	my $email_path = "$release_dir${sep}email.txt";
+	if (open(FOUT, '>:utf8', $email_path))
+	{
+	    print FOUT "Subject: $subject";
+	    if($contents) {
+		print FOUT $contents;
+	    } else {
+		print FOUT "Empty release kit building log: $logfile\n";
+	    }
+	    close(FOUT);
+	    $cmd = "sendmail $ENV{'MONITOR_EMAIL'} < $email_path";
+	    $result = system($cmd);
+	}
+	else
+	{
+	    print STDERR "WARNING: sendmail email attempt failed. Failed to open file for writing email msg:\n\t$email_path\n";	
+
+	    # try using mutt to send email
+	    my $status = system("command -v mutt > /dev/null 2>&1;"); #better way of doing "which mutt"
+	    
+	    if($status != 0) { # mutt doesn't exist, can't send attachments, so send simple email
+		$cmd="echo '$message' | mail -s '$subject' $ENV{'MONITOR_EMAIL'}";
+		
+		print STDERR "********************************************\n";
+		print STDERR "No mutt installed, unable to mail attachment\n";
+		print STDERR "Inspect release-kit build log at: $logfile\n";
+		print STDERR "********************************************\n";
+	    } else {
+		#$cmd = "bash -c \"echo '$message' | mutt -a $logfile -s 'subject' -- $ENV{'MONITOR_EMAIL'}\"";
+		$cmd = "echo '$message' | mutt -a $logfile -s '$subject' -- $ENV{'MONITOR_EMAIL'}";
+	    }	
+	
+	    # run the mail command
+	    $result = system($cmd); #&run_and_print_cmd($cmd);
+	}
+    }
+    
+    
+    if($result != 0) {
+	print STDERR "*** Unable to send email: $?\n";
+    }
+    else {
+	print STDERR "Sent mail with $logfile attached.\n";
+    }
+
+}
Index: /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/task.pl
===================================================================
--- /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/task.pl	(revision 36214)
+++ /main/trunk/gs-release-builder/envi/etc/tasks/snapshot/task.pl	(revision 36214)
@@ -0,0 +1,220 @@
+use File::Basename;
+#use Mail::Sendmail;
+    
+
+my $sep = $^O eq "MSWin32" ? "\\" : "/";
+do "$ENV{'TASK_HOME'}/lib.pl";
+
+die "Could not determine your operating system"
+	unless ( $^O =~ "linux|darwin|MSWin32" );
+
+#arguments
+our $action = "";
+
+#intervening variables
+our $prefix = "";
+our $release_dir = "";
+our $rk = "";
+our $snapshot_id = "";
+our $branch_path = "";
+our $major_version = 0;
+
+
+# SET THIS EMAIL SO THAT WE MAY BE INFORMED WHEN A BUILD FAILS
+$ENV{'MONITOR_EMAIL'} = "greenstone_team\@cs.waikato.ac.nz"; # need to escape @ sign
+if(!defined $ENV{'MONITOR_EMAIL'}) {
+    die "Please set a MONITOR_EMAIL for the test in an environment.sh file\n";
+}
+
+
+# for Darwin, specify if this binary is for (Mountain)Lions in the filename, otherwise it's for Leopards
+# http://en.wikipedia.org/wiki/Darwin_(operating_system)
+# darwin11* Lion, darwin12* Mountain Lion, darwin9* and darwin10* are Leopard and Snow Leopard
+my $osversion = "";
+if($^O eq "darwin") {
+	#$osversion=`uname -r | sed 's/\..*$//'`;
+	$osversion=`uname -r`; #$osversion =~ s@\..*$@@; 
+	$osversion = ($osversion =~ m@^1[1-9]@i) ? "-Lion" : "";
+}
+
+# if the first arg is a digit, it's the new envi verbosity param. Take it off the array
+my $envi_verbose = shift(@ARGV) if(exists $ARGV[0] && $ARGV[0] =~ m/^\d+$/);
+
+if ( exists $ARGV[0] ) {
+	$action = $ARGV[0];
+}
+
+if ( exists $ARGV[1] ) {
+	die "too many arguments to snapshot task\n";
+}
+
+#default data dir
+if ( ! exists $ENV{'DATA_DIR'} ) {
+	$ENV{'DATA_DIR'} = "$ENV{'HOME'}${sep}snapshots";
+}
+
+#default identity dir
+if ( ! exists $ENV{'IDENTITY_DIR'} ) {
+	$ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
+}
+
+#choose the parameters of the build based on the task name
+if ( $ENV{'TASK_NAME'} =~ "release" ) { # run as release 306rc1 (or as different as gs-3.06-rc1)
+	if(exists $ARGV[0] && $ARGV[0] =~ m/^(gs-?)?(3|2)\.?\d\d+(-?rc\d)?$/) {		
+		create_release($ARGV[0]);
+		exit;
+	} else {
+		die "Run snapshot task with gs<full-version>[rc#]\n";
+	}	
+} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)/i ) {
+    if ( $ENV{'TASK_NAME'} =~ m/^gs2-(caveat|stable)-x64$/i ) {
+	#        $ENV{'branch_path'} = "branches/64_bit_Greenstone";
+	$ENV{'x64'} = "true";
+    }
+	$major_version = 2;
+	$prefix="2s";
+	$rk="rk2";
+} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)/i ) {
+    if ( $ENV{'TASK_NAME'} =~ m/^gs3-(caveat|stable)-x64$/i ) {
+	#        $ENV{'branch_path'} = "branches/64_bit_Greenstone";
+	$ENV{'x64'} = "true";
+    }
+	$major_version = 3;
+	$prefix="3s";
+	$rk="rk3";
+} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-src-(caveat|stable)$/i ) {
+	$major_version = 2;
+	$prefix="2s";
+	$rk="sork2";
+} elsif ( $ENV{'TASK_NAME'} =~ m/^gs3-src-(caveat|stable)$/i ) {
+	$major_version = 3;
+	$prefix="3s";
+	$rk="sork3";
+} elsif ( $ENV{'TASK_NAME'} =~ m/^gs2-cd-(caveat|stable)$/i ) {
+	$major_version = 2;
+	$prefix="2s";
+	$rk="cdrk2";
+} elsif ( $ENV{'TASK_NAME'} =~ m/^dec-(caveat|stable)$/i ) {
+	$prefix="";
+	$rk="derk";
+} else {
+	die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
+}
+
+#keep wget/curl base command in a variable
+my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget --no-check-certificate -O -";
+
+#print STDERR "@@@@@@@@@@ PATH: ".$ENV{'PATH'}."\n";
+# http://stackoverflow.com/questions/3854651/how-can-i-store-the-result-of-a-system-command-in-a-perl-variable
+
+#setup based on mode
+if ( $ENV{'TASK_NAME'} =~ m/caveat/ ) {
+	$ENV{'SNAPSHOT_MODE'} = "caveat";
+
+	if ( $major_version == 2 ) {
+	        $ENV{'snapshot_id2'} = `$httpRetrieve https://www.greenstone.org/next-release.txt`;
+		chomp($ENV{'snapshot_id2'});
+	} else {
+		$ENV{'snapshot_id3'} = `$httpRetrieve https://www.greenstone.org/next-release-greenstone3.txt`;
+		chomp($ENV{'snapshot_id3'});
+	}
+	
+	#change the filenames to have the date in them
+	my $id2 = $ENV{'snapshot_id2'};
+	(my $id2re = $id2) =~ s@\.@\\.@g; #copy id2 and then change id2re, see http://www.perlmonks.org/?node_id=366431
+
+	my $id3 = $ENV{'snapshot_id3'};
+	(my $id3re = $id3) =~ s@\.@\\.@g;
+
+	$ENV{'munges'} = "s/-$id2re/-$id2-candidate-" . get_date() . "$osversion" . "/g " if ($id2 =~ m/\S/);
+	$ENV{'munges'} .= "s/-$id3re/-$id3-candidate-" . get_date() . "$osversion". "/g" if ($id3 =~ m/\S/);
+	#$ENV{'munges'} = $ENV{'munges'} . " s/\\.dmg\$/$osversion.dmg/";	
+
+	# the above generates a list of regex. Have a \D (non-digit) prefixed to the value to be substituted, else
+	# Greenstone-documented-examples-2013.06.18.tar.gz gets changed to Greenstone-documented-examples-2013.06-candidate-<daterepeat of 2013.06.18>.18.tar.gz
+
+	#set the path to server.exe
+	$ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/caveat-emptor/latest-server.exe";
+
+} elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
+	$ENV{'SNAPSHOT_MODE'} = "stable";
+	$ENV{'BRANCH_PATH'} = "tags/stable";
+
+	#dont proceed if main/stable is old
+	#get last changed date from svn
+	open( INFO, "svn info http://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
+		or die "Cant determine age of stable tag";
+	my $changed_date;
+	while ( my $line = <INFO>) {
+		chomp($line);
+		if ( $line =~ /^Last Changed Date:/ ) {
+			$changed_date = $line;
+			break;
+		}
+	}
+	close(INFO);
+	#change the format
+	$changed_date =~ s/.*: ([^ ]+) .*/\1/g;
+	if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
+		die "Cant determine age of stable tag";
+	}
+	$changed_date =~ s/-/./g;
+	#check if main/stable is new
+	if ( $changed_date ne get_date() ) {
+		print "main/stable is old, will not create snapshot\n";
+		exit;
+	} else {
+		print "main/stable is fresh, will create snapshot\n";
+	}
+
+	#set the path to server.exe
+	$ENV{'SERVER_EXE_LOCATION'} = "https://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
+	#$ENV{'SERVER_EXE_LOCATION'} = "http://community.nzdl.org/gs3files/latest-server.exe";
+}
+
+#use the  correct key for uploading
+$ENV{'IDENTITY_FILE'} =
+	"$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
+
+
+#always rename the log not to clash with other files on puka
+if ( $ENV{'x64'} ) {
+    $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-x64-log.txt/";
+#     $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-x64-log.txt/";
+}
+else {
+    $ENV{'munges'} = $ENV{'munges'} . " s/\\.out\$/-" . get_date() . "-" . $^O . $osversion . "-log.txt/";
+#    $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-log.txt/";
+}
+
+#choose a snapshot ID
+if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
+	$snapshot_id = $ENV{'snapshot_id2'};
+} elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
+	$snapshot_id = $ENV{'snapshot_id3'};
+} else {
+	$snapshot_id = gen_snapshot_id($prefix);
+}
+
+#set a release directory
+$release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
+
+print "creating a snapshot release\n";
+print "release id : $snapshot_id\n";
+print "release dir: $release_dir\n";
+
+if ( $action eq "create" ) {
+	create();
+} elsif ( $action eq "upload" ) {
+# emailing doesn't work as no SMTP setup on release-kit LSB machines
+#    	send_mail_on_releasekit_fail();
+	upload();	
+} elsif ( $action eq "all" || !$action ) {
+	create();
+# emailing doesn't work as no SMTP setup on release-kit LSB machines
+#	send_mail_on_releasekit_fail();
+	upload();
+} else {
+	die "bad snapshot action\n";
+}
+
