Index: other-projects/nightly-tasks/snapshot/trunk/aliases.txt
===================================================================
--- other-projects/nightly-tasks/snapshot/trunk/aliases.txt	(revision 21709)
+++ other-projects/nightly-tasks/snapshot/trunk/aliases.txt	(revision 21709)
@@ -0,0 +1,12 @@
+gs2-caveat
+gs2-stable
+gs3-caveat
+gs3-stable
+gs2-src-caveat
+gs2-src-stable
+gs3-src-caveat
+gs3-src-stable
+gs2-cd-caveat
+gs2-cd-stable
+dec-caveat
+dec-stable
Index: other-projects/nightly-tasks/snapshot/trunk/environment.pl.example
===================================================================
--- other-projects/nightly-tasks/snapshot/trunk/environment.pl.example	(revision 21709)
+++ other-projects/nightly-tasks/snapshot/trunk/environment.pl.example	(revision 21709)
@@ -0,0 +1,10 @@
+#where to keep snapshots
+$ENV{'DATA_DIR'}="/data/snapshots";
+
+#where to find release kits and ant
+$ENV{'PATH'} = "$ENV{'PATH'}:/programs/release-kits/bin";
+
+#java
+$ENV{'JAVA_HOME'} = "/usr/lib/jvm/java-1.5.0";
+$ENV{'PATH'} = "$ENV{'JAVA_HOME'}/bin:$ENV{'PATH'}";
+
Index: other-projects/nightly-tasks/snapshot/trunk/lib.pl
===================================================================
--- other-projects/nightly-tasks/snapshot/trunk/lib.pl	(revision 21709)
+++ other-projects/nightly-tasks/snapshot/trunk/lib.pl	(revision 21709)
@@ -0,0 +1,125 @@
+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 {
+	
+	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`;
+	}
+
+	#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 "uploading files\n";
+
+	my @munges = ();
+	if ( exists $ENV{'munges'} ) {
+		@munges = split(' ', $ENV{'munges'});
+	}
+
+	if ( ! -d "$release_dir/products" ) {
+		die "error: products directory doesn't exist, exiting\n";
+	}
+
+	@files = <$release_dir/products/*>;
+	push( @files, "$release_dir/$rk.out" );
+	for my $file ( @files ) {
+		my $filename = basename($file);
+		if ( !$only_upload || $filename =~ $only_upload ) {
+
+			#munge
+			for my $m ( @munges ) {
+				$doit="\$filename =~ $m"; eval "$doit";
+			}
+
+			#upload
+			print "Uploading '" . basename($file) . "' to '$filename'\n";
+			my $command = "scp";
+			if ( $^O eq "MSWin32" ) {
+				$command = "pscp";
+			}
+			if ( exists $ENV{'UPLOAD_IDENTITY_FILE'} ) {
+				$command .= " -i \"$ENV{'UPLOAD_IDENTITY_FILE'}\"";
+			}
+			$command .= " \"$file\" \"$ENV{'UPLOAD_DIR'}/$filename\"";
+			system($command);
+
+		} else {
+			print "Skipping upload of '$filename'\n";
+		}
+	}
+}
Index: other-projects/nightly-tasks/snapshot/trunk/task.pl
===================================================================
--- other-projects/nightly-tasks/snapshot/trunk/task.pl	(revision 21709)
+++ other-projects/nightly-tasks/snapshot/trunk/task.pl	(revision 21709)
@@ -0,0 +1,115 @@
+use File::Basename;
+do "$ENV{'TASK_HOME'}/lib.pl";
+
+#check key environment vars are set
+die "Please set a DATA_DIR in the nightly snapshot environment\n"
+	if ! exists $ENV{'DATA_DIR'};
+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;
+
+if ( exists $ARGV[0] ) {
+	$action = $ARGV[0];
+}
+
+if ( exists $ARGV[1] ) {
+	die "too many arguments to snapshot task\n";
+}
+
+#choose the parameters of the build based on the task name
+if ( $ENV{'TASK_NAME'} =~ "gs2-(caveat|stable)" ) {
+	$major_version = 2;
+	$prefix="2s";
+	$rk="rk2";
+} elsif ( $ENV{'TASK_NAME'} =~ "gs3-(caveat|stable)" ) {
+	$major_version = 3;
+	$prefix="3s";
+	$rk="rk3";
+} elsif ( $ENV{'TASK_NAME'} =~ "gs2-src-(caveat|stable)" ) {
+	$major_version = 2;
+	$prefix="2s";
+	$rk="sork2";
+} elsif ( $ENV{'TASK_NAME'} =~ "gs3-src-(caveat|stable)" ) {
+	$major_version = 3;
+	$prefix="3s";
+	$rk="sork3";
+} elsif ( $ENV{'TASK_NAME'} =~ "gs2-cd-(caveat|stable)" ) {
+	$major_version = 2;
+	$prefix="2s";
+	$rk="cdrk2";
+} elsif ( $ENV{'TASK_NAME'} =~ "dec-(caveat|stable)" ) {
+	$prefix="";
+	$rk="derk";
+} else {
+	die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
+}
+
+#setup based on mode
+if ( $ENV{'TASK_NAME'} =~ "caveat\$" ) {
+	$ENV{'UPLOAD_DIR'}="nzdl\@puka.cs.waikato.ac.nz:/greenstone/greenstone.org/base/caveat-emptor";
+	
+	if ( $major_version == 2 ) {
+		$ENV{'snapshot_id2'} = `wget -O - http://www.greenstone.org/next-release.txt 2>nul`;
+		chomp($ENV{'snapshot_id2'});
+	} else {
+		$ENV{'snapshot_id3'} = `wget -O - http://www.greenstone.org/next-release-greenstone3.txt 2>nul`;
+		chomp($ENV{'snapshot_id3'});
+	}
+
+	#change the filenames to have the date in them
+	$ENV{'munges'} = "s/$ENV{'snapshot_id2'}/$ENV{'snapshot_id2'}-candidate-" . get_date() . "/g ";
+	$ENV{'munges'} .= "s/$ENV{'snapshot_id3'}/$ENV{'snapshot_id3'}-candidate-" . get_date() . "/g";
+
+	#set the path to server.exe
+	$ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/caveat-emptor/server-$ENV{'snapshot_id2'}-candidate-" . get_date() . ".exe";
+
+} else {
+	if ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
+		$ENV{'BRANCH_PATH'}="stable";
+	}
+	$ENV{'UPLOAD_DIR'}="nzdl\@puka.cs.waikato.ac.nz:/greenstone/greenstone.org/base/release-snapshots";
+
+	#set the path to server.exe
+	$ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
+}
+
+#always rename the log not to clash with other files on puka
+$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'}/$ENV{'TASK_NAME'}/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" ) {
+	upload();
+} elsif ( $action eq "all" || !$action ) {
+	create();
+	upload();
+} else {
+	die "bad snapshot action\n";
+}
+
