[21709] | 1 | use File::Basename;
|
---|
[21798] | 2 | my $sep = $^O eq "MSWin32" ? "\\" : "/";
|
---|
[21709] | 3 | do "$ENV{'TASK_HOME'}/lib.pl";
|
---|
| 4 |
|
---|
| 5 | die "Could not determine your operating system"
|
---|
| 6 | unless ( $^O =~ "linux|darwin|MSWin32" );
|
---|
| 7 |
|
---|
| 8 | #arguments
|
---|
| 9 | our $action = "";
|
---|
| 10 |
|
---|
| 11 | #intervening variables
|
---|
| 12 | our $prefix = "";
|
---|
| 13 | our $release_dir = "";
|
---|
| 14 | our $rk = "";
|
---|
| 15 | our $snapshot_id = "";
|
---|
| 16 | our $branch_path = "";
|
---|
| 17 | our $major_version = 0;
|
---|
| 18 |
|
---|
| 19 | if ( exists $ARGV[0] ) {
|
---|
| 20 | $action = $ARGV[0];
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | if ( exists $ARGV[1] ) {
|
---|
| 24 | die "too many arguments to snapshot task\n";
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[21723] | 27 | #default data dir
|
---|
| 28 | if ( ! exists $ENV{'DATA_DIR'} ) {
|
---|
[21798] | 29 | $ENV{'DATA_DIR'} = "$ENV{'HOME'}${sep}snapshots";
|
---|
[21723] | 30 | }
|
---|
| 31 |
|
---|
[21774] | 32 | #default identity dir
|
---|
| 33 | if ( ! exists $ENV{'IDENTITY_DIR'} ) {
|
---|
[21798] | 34 | $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh";
|
---|
[21774] | 35 | }
|
---|
| 36 |
|
---|
[21709] | 37 | #choose the parameters of the build based on the task name
|
---|
| 38 | if ( $ENV{'TASK_NAME'} =~ "gs2-(caveat|stable)" ) {
|
---|
| 39 | $major_version = 2;
|
---|
| 40 | $prefix="2s";
|
---|
| 41 | $rk="rk2";
|
---|
| 42 | } elsif ( $ENV{'TASK_NAME'} =~ "gs3-(caveat|stable)" ) {
|
---|
| 43 | $major_version = 3;
|
---|
| 44 | $prefix="3s";
|
---|
| 45 | $rk="rk3";
|
---|
| 46 | } elsif ( $ENV{'TASK_NAME'} =~ "gs2-src-(caveat|stable)" ) {
|
---|
| 47 | $major_version = 2;
|
---|
| 48 | $prefix="2s";
|
---|
| 49 | $rk="sork2";
|
---|
| 50 | } elsif ( $ENV{'TASK_NAME'} =~ "gs3-src-(caveat|stable)" ) {
|
---|
| 51 | $major_version = 3;
|
---|
| 52 | $prefix="3s";
|
---|
| 53 | $rk="sork3";
|
---|
| 54 | } elsif ( $ENV{'TASK_NAME'} =~ "gs2-cd-(caveat|stable)" ) {
|
---|
| 55 | $major_version = 2;
|
---|
| 56 | $prefix="2s";
|
---|
| 57 | $rk="cdrk2";
|
---|
| 58 | } elsif ( $ENV{'TASK_NAME'} =~ "dec-(caveat|stable)" ) {
|
---|
| 59 | $prefix="";
|
---|
| 60 | $rk="derk";
|
---|
| 61 | } else {
|
---|
| 62 | die "unrecognised task name '$ENV{'TASK_NAME'}'\n";
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[21797] | 65 | #keep wget/curl base command in a variable
|
---|
| 66 | my $httpRetrieve = $^O eq "darwin" ? "curl" : "wget -O -";
|
---|
| 67 |
|
---|
[21709] | 68 | #setup based on mode
|
---|
| 69 | if ( $ENV{'TASK_NAME'} =~ "caveat\$" ) {
|
---|
[21774] | 70 | $ENV{'SNAPSHOT_MODE'} = "caveat";
|
---|
[21709] | 71 |
|
---|
[21773] | 72 | if ( $major_version == 2 ) {
|
---|
[21797] | 73 | $ENV{'snapshot_id2'} = `$httpRetrieve http://www.greenstone.org/next-release.txt`;
|
---|
[21773] | 74 | chomp($ENV{'snapshot_id2'});
|
---|
| 75 | } else {
|
---|
[21797] | 76 | $ENV{'snapshot_id3'} = `$httpRetrieve http://www.greenstone.org/next-release-greenstone3.txt`;
|
---|
[21773] | 77 | chomp($ENV{'snapshot_id3'});
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[21709] | 80 | #change the filenames to have the date in them
|
---|
| 81 | $ENV{'munges'} = "s/$ENV{'snapshot_id2'}/$ENV{'snapshot_id2'}-candidate-" . get_date() . "/g ";
|
---|
| 82 | $ENV{'munges'} .= "s/$ENV{'snapshot_id3'}/$ENV{'snapshot_id3'}-candidate-" . get_date() . "/g";
|
---|
| 83 |
|
---|
| 84 | #set the path to server.exe
|
---|
| 85 | $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/caveat-emptor/server-$ENV{'snapshot_id2'}-candidate-" . get_date() . ".exe";
|
---|
| 86 |
|
---|
[21774] | 87 | } elsif ( $ENV{'TASK_NAME'} =~ "stable\$" ) {
|
---|
| 88 | $ENV{'SNAPSHOT_MODE'} = "stable";
|
---|
| 89 | $ENV{'BRANCH_PATH'} = "tags/stable";
|
---|
[21723] | 90 |
|
---|
[21774] | 91 | #dont proceed if main/stable is old
|
---|
| 92 | #get last changed date from svn
|
---|
| 93 | open( INFO, "svn info http://svn.greenstone.org/main/$ENV{'BRANCH_PATH'}|" )
|
---|
| 94 | or die "Cant determine age of stable tag";
|
---|
| 95 | my $changed_date;
|
---|
| 96 | while ( my $line = <INFO>) {
|
---|
| 97 | chomp($line);
|
---|
| 98 | if ( $line =~ /^Last Changed Date:/ ) {
|
---|
| 99 | $changed_date = $line;
|
---|
| 100 | break;
|
---|
[21723] | 101 | }
|
---|
[21709] | 102 | }
|
---|
[21774] | 103 | close(INFO);
|
---|
| 104 | #change the format
|
---|
| 105 | $changed_date =~ s/.*: ([^ ]+) .*/\1/g;
|
---|
| 106 | if ( $changed_date !~ /^20[0-9]{2}-[0-9]{2}-[0-9]{2}$/ ) {
|
---|
| 107 | die "Cant determine age of stable tag";
|
---|
| 108 | }
|
---|
| 109 | $changed_date =~ s/-/./g;
|
---|
| 110 | #check if main/stable is new
|
---|
| 111 | if ( $changed_date ne get_date() ) {
|
---|
| 112 | print "main/stable is old, will not create snapshot\n";
|
---|
| 113 | exit;
|
---|
| 114 | } else {
|
---|
| 115 | print "main/stable is fresh, will create snapshot\n";
|
---|
| 116 | }
|
---|
[21709] | 117 |
|
---|
| 118 | #set the path to server.exe
|
---|
| 119 | $ENV{'SERVER_EXE_LOCATION'} = "http://www.greenstone.org/release-snapshots/server-\$\\\{version\\\}.exe";
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[21774] | 122 | #use the correct key for uploading
|
---|
| 123 | $ENV{'IDENTITY_FILE'} =
|
---|
[21798] | 124 | "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
|
---|
[21774] | 125 |
|
---|
| 126 |
|
---|
[21709] | 127 | #always rename the log not to clash with other files on puka
|
---|
[21797] | 128 | $ENV{'munges'} = $ENV{'munges'} . " s/\.out/-" . get_date() . "-" . $^O . "-log.txt/";
|
---|
[21709] | 129 |
|
---|
| 130 | #choose a snapshot ID
|
---|
| 131 | if ( exists $ENV{'snapshot_id2'} && $major_version == 2 ) {
|
---|
| 132 | $snapshot_id = $ENV{'snapshot_id2'};
|
---|
| 133 | } elsif ( exists $ENV{'snapshot_id3'} && $major_version == 3 ) {
|
---|
| 134 | $snapshot_id = $ENV{'snapshot_id3'};
|
---|
| 135 | } else {
|
---|
| 136 | $snapshot_id = gen_snapshot_id($prefix);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | #set a release directory
|
---|
[21798] | 140 | $release_dir = "$ENV{'DATA_DIR'}${sep}$ENV{'TASK_NAME'}${sep}from-" . get_date();
|
---|
[21709] | 141 |
|
---|
| 142 | print "creating a snapshot release\n";
|
---|
| 143 | print "release id : $snapshot_id\n";
|
---|
| 144 | print "release dir: $release_dir\n";
|
---|
| 145 |
|
---|
| 146 | if ( $action eq "create" ) {
|
---|
| 147 | create();
|
---|
| 148 | } elsif ( $action eq "upload" ) {
|
---|
| 149 | upload();
|
---|
| 150 | } elsif ( $action eq "all" || !$action ) {
|
---|
| 151 | create();
|
---|
| 152 | upload();
|
---|
| 153 | } else {
|
---|
| 154 | die "bad snapshot action\n";
|
---|
| 155 | }
|
---|
| 156 |
|
---|