[21798] | 1 | my $sep = $^O eq "MSWin32" ? "\\" : "/";
|
---|
| 2 |
|
---|
[21709] | 3 | sub get_date {
|
---|
| 4 | local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
---|
| 5 | local $day = $mday;
|
---|
| 6 | local $month = $mon+1;
|
---|
| 7 | local $year = $year+1900;
|
---|
| 8 | if ( length $month == 1 ) {
|
---|
| 9 | $month = join( "", "0", $month);
|
---|
| 10 | }
|
---|
| 11 | if ( length $day== 1 ) {
|
---|
| 12 | $day = join( "", "0", $day );
|
---|
| 13 | }
|
---|
| 14 | local $date = join( ".", $year,$month,$day );
|
---|
| 15 | return $date;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | sub gen_snapshot_id {
|
---|
| 19 | if ( exists $_[0] && exists $_[1] ) {
|
---|
| 20 | return $_[0] . get_date() . $_[1];
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | if ( exists $_[0] ) {
|
---|
| 24 | return $_[0] . get_date();
|
---|
| 25 | }
|
---|
| 26 | return get_date();
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[29346] | 29 | sub create_release {
|
---|
| 30 |
|
---|
| 31 | die "Must provide parameter to create_release\n" unless (exists $_[0]);
|
---|
| 32 |
|
---|
| 33 | my $release_folder_name = $_[0];
|
---|
| 34 |
|
---|
| 35 | my $release_version = $release_folder_name;
|
---|
| 36 | $release_version =~ s/^gs-?//;
|
---|
| 37 | $release_version =~ s/rc\d$//;
|
---|
| 38 | my $major_version = $release_version;
|
---|
| 39 | $major_version =~ s/^(3|2).*/$1/;
|
---|
| 40 | $release_version =~ s/^($major_version)\.?(\d*).*/$1.$2/;
|
---|
| 41 | my $rk = "rk".$major_version;
|
---|
| 42 |
|
---|
| 43 | my $release_version_extra;
|
---|
| 44 | if ($release_folder_name =~ m/(rc\d)$/) {
|
---|
| 45 | $release_version_extra = $1;
|
---|
| 46 | }
|
---|
| 47 | if ($release_folder_name !~ m/^gs/) { # prefix gs
|
---|
| 48 | $release_folder_name = "gs".$release_folder_name;
|
---|
| 49 | }
|
---|
[29360] | 50 | my $release_dir = "$ENV{'DATA_DIR'}${sep}$release_folder_name";
|
---|
[29346] | 51 |
|
---|
| 52 | print "major_version: $major_version\n";
|
---|
| 53 | print "version: $release_version\n";
|
---|
| 54 | print "versionextra: $release_version_extra\n";
|
---|
[29360] | 55 | print "release_folder_name: $release_folder_name\n";
|
---|
| 56 | print "release_dir: $release_dir\n";
|
---|
[29346] | 57 |
|
---|
| 58 | print "about to clean up old snapshots (Ctrl-C to cancel)";
|
---|
| 59 | local $| = 1;
|
---|
| 60 | for ( my $i=0; $i<5; $i++ ) {
|
---|
| 61 | print ".";
|
---|
| 62 | sleep 1;
|
---|
| 63 | }
|
---|
| 64 | $| = 0;
|
---|
| 65 |
|
---|
| 66 | print "cleaning up previous release snapshot $release_dir\n";
|
---|
| 67 |
|
---|
| 68 | if(-d $release_dir) {
|
---|
| 69 | if ( $^O eq "MSWin32" ) {
|
---|
| 70 | system("rd /q /s \"$release_dir\"");
|
---|
| 71 | } else {
|
---|
| 72 | system("rm -rf \"$release_dir\"");
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | print "creating the release dir\n";
|
---|
| 77 | mkdir $release_dir or die "couldn't create release directory\n";
|
---|
| 78 |
|
---|
| 79 | print "changing to the release dir\n";
|
---|
| 80 | chdir $release_dir;
|
---|
| 81 |
|
---|
| 82 | #version property
|
---|
| 83 | print "setting up todays properties\n";
|
---|
| 84 | `echo version:$release_version> $rk-build.properties`;
|
---|
| 85 |
|
---|
| 86 | if($release_version_extra) {
|
---|
| 87 | `echo version-extra:$release_version_extra>> $rk-build.properties`;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | #processor propertylocal $| = 1;
|
---|
| 91 | if ( $^O eq "darwin" ) {
|
---|
| 92 | print "setting processor\n";
|
---|
| 93 | if ( `uname -p` eq "i386" ) {
|
---|
| 94 | `echo processor:intel>> $rk-build.properties`;
|
---|
| 95 | } elsif ( `uname -p` eq "powerpc" ) {
|
---|
| 96 | `echo processor:ppc>> $rk-build.properties`;
|
---|
| 97 | } else {
|
---|
| 98 | print "unable to determine processor type, using intel\n";
|
---|
| 99 | `echo processor:intel>> $rk-build.properties`;
|
---|
| 100 | }
|
---|
| 101 | } elsif ( $^O eq "linux" ) {
|
---|
[37800] | 102 | # Running "uname -m" on new 32 bit VM returns "i86_64" too
|
---|
| 103 | # So to properly test for 32 bit, ensure that environment.pl
|
---|
| 104 | # didn't set $ENV{'GS_OPENSSL_HOST'} to "linux-generic32"
|
---|
| 105 | if(`uname -m` =~ m/64$/) {
|
---|
| 106 | if(! exists $ENV{'GS_OPENSSL_HOST'} || $ENV{'GS_OPENSSL_HOST'} ne "linux-generic32") {
|
---|
| 107 | print "Setting linux architecture to 64 bit";
|
---|
| 108 | `echo x64:true>> $rk-build.properties`;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
[29346] | 111 | }
|
---|
| 112 |
|
---|
| 113 | #branch path property
|
---|
| 114 | if ( $ENV{'branch_path'} ) {
|
---|
| 115 | `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | #server.exe.location
|
---|
| 119 | if ( $major_version eq "2" && exists $ENV{'SERVER_EXE_LOCATION'} ) {
|
---|
| 120 | `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | print "creating the snapshot using $rk\n";
|
---|
| 124 | system( $rk );
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[21709] | 127 | sub create {
|
---|
| 128 |
|
---|
| 129 | die "release_dir not set, cant create\n" unless $release_dir;
|
---|
| 130 |
|
---|
| 131 | print "about to clean up old snapshots (Ctrl-C to cancel)";
|
---|
| 132 | local $| = 1;
|
---|
| 133 | for ( my $i=0; $i<5; $i++ ) {
|
---|
| 134 | print ".";
|
---|
| 135 | sleep 1;
|
---|
| 136 | }
|
---|
| 137 | $| = 0;
|
---|
| 138 |
|
---|
| 139 | print "cleaning up previous snapshot\n";
|
---|
[21798] | 140 | local $release_parent = dirname($release_dir);
|
---|
[21709] | 141 | if ( $^O eq "MSWin32" ) {
|
---|
| 142 | system("rd /q /s \"$release_parent\"");
|
---|
| 143 | } else {
|
---|
| 144 | system("rm -rf \"$release_parent\"");
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | print "creating the release dir\n";
|
---|
[21798] | 148 | mkdir $release_parent or die "couldn't create release parent directory\n";
|
---|
[21709] | 149 | mkdir $release_dir or die "couldn't create release directory\n";
|
---|
| 150 |
|
---|
| 151 | print "changing to the release dir\n";
|
---|
| 152 | chdir $release_dir;
|
---|
| 153 |
|
---|
| 154 | #version property
|
---|
| 155 | print "setting up todays properties\n";
|
---|
| 156 | `echo version:$snapshot_id> $rk-build.properties`;
|
---|
| 157 |
|
---|
| 158 | #processor propertylocal $| = 1;
|
---|
| 159 | if ( $^O eq "darwin" ) {
|
---|
| 160 | print "setting processor\n";
|
---|
| 161 | if ( `uname -p` eq "i386" ) {
|
---|
| 162 | `echo processor:intel>> $rk-build.properties`;
|
---|
| 163 | } elsif ( `uname -p` eq "powerpc" ) {
|
---|
| 164 | `echo processor:ppc>> $rk-build.properties`;
|
---|
| 165 | } else {
|
---|
| 166 | print "unable to determine processor type, using intel\n";
|
---|
| 167 | `echo processor:intel>> $rk-build.properties`;
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | #branch path property
|
---|
| 172 | if ( $ENV{'branch_path'} ) {
|
---|
| 173 | `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | #server.exe.location
|
---|
| 177 | if ( exists $ENV{'SERVER_EXE_LOCATION'} ) {
|
---|
| 178 | `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | print "creating the snapshot using $rk\n";
|
---|
| 182 | system( $rk );
|
---|
| 183 |
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | sub upload {
|
---|
| 187 | print "uploading files\n";
|
---|
| 188 |
|
---|
| 189 | my @munges = ();
|
---|
| 190 | if ( exists $ENV{'munges'} ) {
|
---|
| 191 | @munges = split(' ', $ENV{'munges'});
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[21774] | 194 | #copy products to a temporary folder, giving them their new names
|
---|
[27661] | 195 | if ( -d "$release_dir${sep}uploads" ) {
|
---|
[21798] | 196 | system( "rm -rf '$release_dir${sep}uploads'" );
|
---|
[21774] | 197 | }
|
---|
[21798] | 198 | mkdir "$release_dir${sep}uploads";
|
---|
[21774] | 199 |
|
---|
[21797] | 200 | my @files;
|
---|
[21798] | 201 | if ( -d "$release_dir${sep}products" ) {
|
---|
[21886] | 202 | @files = <$release_dir${sep}products${sep}*>;
|
---|
[21797] | 203 | }
|
---|
[21798] | 204 | push( @files, "$release_dir${sep}$rk.out" );
|
---|
[21797] | 205 |
|
---|
[21709] | 206 | for my $file ( @files ) {
|
---|
[21798] | 207 | if ( -e $file ) {
|
---|
| 208 | my $filename = basename($file);
|
---|
| 209 | #munge
|
---|
| 210 | for my $m ( @munges ) {
|
---|
| 211 | $doit="\$filename =~ $m"; eval "$doit";
|
---|
| 212 | }
|
---|
| 213 | #upload
|
---|
| 214 | print "Will upload '" . basename($file) . "' to '$filename'\n";
|
---|
[28299] | 215 | if( $^O =~ "linux|darwin" ) {
|
---|
| 216 | system("cp \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
|
---|
| 217 | }
|
---|
| 218 | else {
|
---|
| 219 | system("copy \"$file\" \"${release_dir}${sep}uploads${sep}$filename\"");
|
---|
| 220 | }
|
---|
[21774] | 221 | }
|
---|
[21709] | 222 |
|
---|
| 223 | }
|
---|
[21798] | 224 |
|
---|
[37770] | 225 | # We use the upload-files-to-www-internal.sh script on linux systems now
|
---|
| 226 | # The following is still left in as it appears to work for the mac
|
---|
| 227 |
|
---|
[34519] | 228 | #my $out = `set`;
|
---|
| 229 | #print "out = $out\n";
|
---|
[21798] | 230 | my $command = "cd \"${release_dir}${sep}uploads\" && tar -c * | ";
|
---|
| 231 | $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
|
---|
| 232 | $command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
|
---|
[34519] | 233 | print "$command\n";
|
---|
[21797] | 234 | system("$command");
|
---|
[32048] | 235 |
|
---|
[34519] | 236 | ## for now, upload a copy to the new machine, later to replace puka
|
---|
| 237 | #$command = "cd \"${release_dir}${sep}uploads\" && tar -c * | ";
|
---|
| 238 | #$command .= ($^O eq "MSWin32" ? "plink" : "ssh");
|
---|
| 239 | #$command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl-gsorg\@wwwdev.greenstone.org";
|
---|
| 240 | ##print "$command\n";
|
---|
| 241 | #system("$command");
|
---|
| 242 |
|
---|
| 243 | # also upload a copy to www-internal, which is the new wwwdev, and will replace puka.
|
---|
[32048] | 244 | $command = "cd \"${release_dir}${sep}uploads\" && tar -c * | ";
|
---|
| 245 | $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
|
---|
[34519] | 246 | $command .= " -T -i \"$ENV{'IDENTITY_FILE_ED25519'}\" nzdl-gsorg\@www-internal.greenstone.org";
|
---|
| 247 | print "$command\n";
|
---|
[32048] | 248 | system("$command");
|
---|
[34519] | 249 |
|
---|
[21709] | 250 | }
|
---|