[27621] | 1 | #!/usr/bin/perl -w
|
---|
[27556] | 2 |
|
---|
[27621] | 3 | # This program is meant to run the nightly diffcol
|
---|
| 4 | # It is meant to be an equivalent for the existing task bash script
|
---|
| 5 | # But it is intended to be expanded to work for Windows and GS3
|
---|
| 6 | # For windows, need to REMEMBER to set the correct shebangs at the top
|
---|
[27556] | 7 |
|
---|
[27663] | 8 |
|
---|
| 9 | # TODO:
|
---|
| 10 | # Have a caveat mode and a stable mode (as in snapshot/task.pl)
|
---|
| 11 | #
|
---|
| 12 | #} elsif ( $ENV{'TASK_NAME'} =~ "gs2-diffcol-(caveat|stable)" ) {
|
---|
| 13 | # $major_version = 2;
|
---|
| 14 | # $prefix="2t";
|
---|
| 15 | # $rk="tk2"; # test kit
|
---|
| 16 | #} elsif ( $ENV{'TASK_NAME'} =~ "gs3-diffcol-(caveat|stable)" ) {
|
---|
| 17 | # $major_version = 3;
|
---|
| 18 | # $prefix="3t";
|
---|
| 19 | # $rk="tk3"; # test kit
|
---|
| 20 |
|
---|
[27628] | 21 | package diffcoltask;
|
---|
[27556] | 22 |
|
---|
[27621] | 23 | use Cwd;
|
---|
[29398] | 24 | #use Switch; # for switch(val) { case: ; ...}
|
---|
[27621] | 25 | use File::Path; # for rmdir and mkdir type functions
|
---|
| 26 | use File::Copy; # for recursive copying of folders but skipping .svn
|
---|
| 27 | use File::Basename;
|
---|
| 28 |
|
---|
[27628] | 29 | use strict;
|
---|
| 30 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[27621] | 31 |
|
---|
[27764] | 32 |
|
---|
[27621] | 33 | my $isWin = ($^O =~ m/mswin/i) ? 1 : 0;
|
---|
[27764] | 34 | my $isMac = ($^O =~ m/macos|darwin/i) ? 1 : 0;
|
---|
[28571] | 35 |
|
---|
| 36 | my $osversion="";
|
---|
| 37 | # Need to get the correct gnome-lib-minimal for the OS
|
---|
| 38 | # darwin11* Lion, darwin12* Mountain Lion, darwin9* and darwin10* are Leopard and Snow Leopard
|
---|
| 39 | if ($^O eq "darwin") {
|
---|
| 40 | $osversion=`uname -r`; # e.g. 12.x.x
|
---|
| 41 | #$osversion =~ s@\..*$@@; # e.g.12
|
---|
[28634] | 42 | $osversion = ($osversion =~ m@^1[1-9](\.)?@i) ? "Lion-" : "";
|
---|
[28571] | 43 | }
|
---|
| 44 |
|
---|
[34941] | 45 | # we're using a GS compiled up wget with https support (at release-kits/bin, on PATH)
|
---|
| 46 | # But we may need to use --no-check-certificate for some https urls.
|
---|
| 47 | my $wget = "wget --no-check-certificate";
|
---|
[28571] | 48 |
|
---|
[27621] | 49 | my $sep = $isWin ? "\\" : "/";
|
---|
| 50 | my $pathsep = $isWin ? ";" : ":";
|
---|
| 51 | #my $script_ext = $isWin ? ".bat" : ".bash";
|
---|
[28661] | 52 | my $setup_script = "setup"; # will become gs3-setup for GS3
|
---|
[27687] | 53 | my $use_blat = 0; # if we ever get blat to send mail/attachments on Windows working, set this to 1
|
---|
[27621] | 54 |
|
---|
[28616] | 55 | my $install_type = "svn";
|
---|
| 56 | my $install_version = "2";
|
---|
| 57 |
|
---|
[28106] | 58 | my $use_local_rebuild = 0; # set to 1 (true) if just diffing and so we needn't copy model-collection over to the test collection again nor rebuild it (This is useful when having built the collection locally once before)
|
---|
[28072] | 59 | my $use_static_model = 0; # set to 1 (true) if working with a non-svn model-collection. Defaults to 1 if $use_local_rebuild is turned on
|
---|
[27701] | 60 |
|
---|
[28072] | 61 | # if use_local_rebuild is on, use_static_model should be on
|
---|
| 62 | if ($use_local_rebuild && !$use_static_model) {
|
---|
| 63 | $use_static_model = 1;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[28172] | 66 | my $test_os = $isWin ? "windows" : ($isMac ? "darwin" : "linux");
|
---|
| 67 | my $model_os = "linux"; # default
|
---|
[28072] | 68 |
|
---|
[29494] | 69 | my $debugging = 0;
|
---|
| 70 |
|
---|
[27621] | 71 | # TASK_HOME should be the toplevel diffcol folder
|
---|
| 72 | $ENV{'TASK_HOME'} = getcwd unless defined $ENV{'TASK_HOME'};
|
---|
[27701] | 73 | if($isWin) {
|
---|
| 74 | $ENV{'TASK_HOME'} =~ s@\/@\\@g;
|
---|
| 75 | # need to convert TASK_HOME path name to resolve very subtle bug when running task.pl via
|
---|
| 76 | # run-gs2-diffcol.bat which uses environment.pl's TASK_HOME setting via envi
|
---|
| 77 | # At that point TASK_HOME is already defined but ends up lowercase, so that entries in archiveinf-doc
|
---|
| 78 | # end up sorted differently when db2txt -sort is applied compared to if TASK_HOME had kept its case.
|
---|
| 79 | require Win32; # for working out Windows Long Filenames from Win 8.3 short filenames
|
---|
| 80 | $ENV{'TASK_HOME'} = &Win32::GetLongPathName($ENV{'TASK_HOME'});
|
---|
| 81 | }
|
---|
[27621] | 82 | ## print STDERR "@@@ TASK_HOME: ".$ENV{'TASK_HOME'}."\n";
|
---|
| 83 |
|
---|
| 84 |
|
---|
[27678] | 85 | $ENV{'BIN_DIR'} = &filename_concat($ENV{'TASK_HOME'}, "bin");
|
---|
| 86 |
|
---|
| 87 | # we'll be using BLAT to send mail attachments on Windows
|
---|
[27687] | 88 | my $blat = $use_blat ? &filename_concat($ENV{'BIN_DIR'}, "blat", "full", "blat.exe") : 0;
|
---|
| 89 | if($isWin && $use_blat && ! -e $blat) {
|
---|
| 90 | print STDERR "\n***********************************\n";
|
---|
| 91 | print STDERR "No blat.exe found in $blat.\n";
|
---|
| 92 | print STDERR "Blat needed to send mail with attachments on Windows.\n";
|
---|
| 93 | print STDERR "Extract the blat zip file found in $ENV{'BIN_DIR'}\n";
|
---|
| 94 | print STDERR "for your bit architecture and name the folder 'blat'\n";
|
---|
| 95 | print STDERR "***********************************\n\n";
|
---|
[27678] | 96 | $blat = 0;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 |
|
---|
[27668] | 100 | $ENV{'DATA_DIR'} = &filename_concat($ENV{'TASK_HOME'}, "diffcol-data");
|
---|
| 101 | $ENV{'UPLOAD_DIR'} = &filename_concat($ENV{'TASK_HOME'}, "diffcol-reports");
|
---|
[27621] | 102 | $ENV{'MONITOR_EMAIL'} = "greenstone_team\@cs.waikato.ac.nz"; # need to escape @ sign
|
---|
[27678] | 103 | $ENV{'GSDL_SMTP'} = ""; #"smtp.gmail.com";
|
---|
[27621] | 104 | ##print STDERR "@@@ email: ".$ENV{'MONITOR_EMAIL'}."\n";
|
---|
| 105 |
|
---|
[29448] | 106 | # When installing diffcol the first time, force the user to create the data-dir and upload-dir
|
---|
| 107 | die "\n@@@@ data dir: ".$ENV{'DATA_DIR'}." does not exist\n" unless (-d $ENV{'DATA_DIR'});
|
---|
| 108 | die "\n@@@@ reports/upload dir: ".$ENV{'UPLOAD_DIR'}." does not exist\n" unless (-d $ENV{'UPLOAD_DIR'});
|
---|
| 109 |
|
---|
[27621] | 110 | # control if an existing compiled greenstone is used
|
---|
| 111 | # or, if one should be checked out, which revision to checkout from svn
|
---|
| 112 | $ENV{'SVN_OPT_REV'} = "-r head";
|
---|
[27656] | 113 | #$ENV{'GSDLHOME'}=
|
---|
| 114 | #$ENV{'GSDL3SRCHOME'}=
|
---|
[27621] | 115 |
|
---|
[27628] | 116 |
|
---|
[27677] | 117 | # if the first arg is a digit, it's the new envi verbosity param. Take it off the array
|
---|
| 118 | my $envi_verbose = shift(@ARGV) if(exists $ARGV[0] && $ARGV[0] =~ m/^\d+$/);
|
---|
[27628] | 119 |
|
---|
| 120 | #parse arguments
|
---|
| 121 | my $action = "all";
|
---|
[28114] | 122 | my $subaction = ""; # run_test can take subactions: --just_diff and --no_svn
|
---|
[28620] | 123 | my @collections = (); # list of collections that run_test should process
|
---|
[28114] | 124 |
|
---|
[28620] | 125 | if(scalar(@ARGV) == 0) {
|
---|
| 126 | $action="all";
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | # process any arguments that are --gs2|--gs3 and --bin|--svn, and delete them from the array
|
---|
| 130 | # if none provided, it's gs2 and svn by default.
|
---|
| 131 | for (my $i = $#ARGV; $i >= 0; --$i) {
|
---|
| 132 | if($ARGV[$i] =~ m/--(bin|svn)/) {
|
---|
| 133 | $install_type = $1;
|
---|
| 134 | splice @ARGV, $i, 1; # remove the element from the argument array
|
---|
| 135 | } elsif($ARGV[$i] =~ m/--gs(2|3)/) {
|
---|
| 136 | $install_version = $1;
|
---|
[28661] | 137 | $setup_script = $install_version eq "3" ? "gs3-setup" : "setup"; # needs to become gs3-setup for GS3
|
---|
[28620] | 138 | splice @ARGV, $i, 1; # remove the element from the argument array
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[36655] | 142 | $ENV{'GSVERSION'} = $install_version;
|
---|
[28620] | 143 |
|
---|
[28172] | 144 | # run_test can take any number of args
|
---|
[28620] | 145 | if(scalar(@ARGV) > 1 && $ARGV[0] ne "run_test") {
|
---|
[28172] | 146 | print STDERR "**** Wrong number of arguments\n";
|
---|
[28114] | 147 | &printusage();
|
---|
| 148 | exit -1;
|
---|
[27628] | 149 | }
|
---|
| 150 |
|
---|
[28620] | 151 | if(scalar(@ARGV) > 0) {
|
---|
[29398] | 152 | #switch ($ARGV[0]) {
|
---|
| 153 | #case qr/^(-h|--?help|help)$/i { &printusage; exit 0; }
|
---|
| 154 | #case qr/^(setup_greenstone|run_test|summarise|upload|all)$/ { $action=$ARGV[0]; }
|
---|
| 155 | #else {
|
---|
| 156 | #print STDERR "**** Bad subcommand.\n";
|
---|
| 157 | #&printusage;
|
---|
| 158 | #exit -1;
|
---|
| 159 | #}
|
---|
| 160 | #}
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | my $switch = $ARGV[0];
|
---|
| 164 | if($switch =~ m/^(-h|--?help|help)$/i) {
|
---|
| 165 | &printusage;
|
---|
| 166 | exit 0;
|
---|
| 167 | } elsif ($switch =~ m/^(setup_greenstone|run_test|summarise|upload|all)$/) {
|
---|
| 168 | $action=$ARGV[0];
|
---|
| 169 | } else {
|
---|
| 170 | print STDERR "**** Bad subcommand.\n";
|
---|
| 171 | &printusage;
|
---|
| 172 | exit -1;
|
---|
[27628] | 173 | }
|
---|
[28616] | 174 |
|
---|
[28172] | 175 | # run_test action can take a subaction: nosvn|justdiff. It can also take --modelOS (windows|linux|darwin)
|
---|
[28114] | 176 | # nosvn: uses the model-collect as static and copies it over to collect, rebuilding what's currently in model-collect instead of copying
|
---|
| 177 | # it out from the svn model-collect again.
|
---|
| 178 | # justdiff: same as nosvn, but doesn't copy over model-collection to collect, and doesn't rebuild either of them. Just does the diff part.
|
---|
[28616] | 179 |
|
---|
[28620] | 180 | if($action eq "run_test" && scalar(@ARGV) >= 2) {
|
---|
[28114] | 181 | push(@collections, @ARGV);
|
---|
| 182 | shift @collections; # remove action from array
|
---|
| 183 |
|
---|
[28172] | 184 | for (my $i=0; $i < scalar(@ARGV); $i++) {
|
---|
| 185 | if($ARGV[$i] =~ m@^--@) {
|
---|
| 186 | shift @collections; # remove subaction/flag from array
|
---|
[28114] | 187 |
|
---|
[28172] | 188 | $subaction = $ARGV[$i];
|
---|
[28114] | 189 | if($subaction eq "--justdiff") {
|
---|
[28172] | 190 | $use_local_rebuild = $use_static_model = 1;
|
---|
[28114] | 191 | } elsif ($subaction eq "--nosvn") {
|
---|
[28172] | 192 | $use_static_model = 1;
|
---|
| 193 | #} elsif ($subaction =~ m/\-\-testOS/i && defined $ARGV[$i+1]) {
|
---|
| 194 | # $test_os = $ARGV[$i+1];
|
---|
| 195 | # $i++;
|
---|
| 196 | # shift @collections; # remove test_os value from array
|
---|
| 197 | } elsif ($subaction =~ m/\-\-modelOS/i && defined $ARGV[$i+1] && $ARGV[$i+1] =~ m/windows|linux|darwin/i) {
|
---|
| 198 | $model_os = $ARGV[$i+1];
|
---|
| 199 | $i++;
|
---|
| 200 | shift @collections; # remove model_os value from array
|
---|
| 201 | #print STDERR "Model_os specified: $model_os\n";
|
---|
[29494] | 202 | } elsif ($subaction =~ m/\-\-debug/i) {
|
---|
| 203 | $debugging = 1;
|
---|
[29496] | 204 | print STDERR "*** DEBUG MODE: debug output files will be in toplevel folder\n";
|
---|
[28114] | 205 | } else {
|
---|
[28172] | 206 | print STDERR "**** Bad subaction/value: ".$ARGV[$i]."\n";
|
---|
| 207 | &printusage;
|
---|
| 208 | exit -1;
|
---|
| 209 | }
|
---|
| 210 | }
|
---|
[28114] | 211 | }
|
---|
| 212 |
|
---|
| 213 | # foreach my $col (@collections) {
|
---|
| 214 | # print STDERR "Collection: $col\n";
|
---|
| 215 | # }
|
---|
| 216 | }
|
---|
[27628] | 217 | }
|
---|
| 218 |
|
---|
[28661] | 219 | print STDERR "Install type $install_type\n";
|
---|
| 220 | print STDERR "Install version $install_version\n";
|
---|
[28114] | 221 |
|
---|
[27621] | 222 | #check key environment vars are set
|
---|
| 223 | if(!defined $ENV{'UPLOAD_DIR'}) {
|
---|
[27629] | 224 | print STDERR "Please set a UPLOAD_DIR for the test in an environment.sh file\n";
|
---|
[27621] | 225 | #return 1;
|
---|
| 226 | }
|
---|
| 227 | if(!defined $ENV{'DATA_DIR'}) {
|
---|
[27629] | 228 | print STDERR "Please set a DATA_DIR for the test in an environment.sh file\n";
|
---|
[27621] | 229 | #return 1;
|
---|
| 230 | }
|
---|
| 231 | if(!defined $ENV{'MONITOR_EMAIL'}) {
|
---|
[27629] | 232 | print STDERR "Please set a MONITOR_EMAIL for the test in an environment.sh file\n";
|
---|
[27621] | 233 | #return 1;
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | if($ENV{'DATA_DIR'} eq "/") {
|
---|
[27629] | 237 | print STDERR "DATA_DIR should not be the fs root\n";
|
---|
[27621] | 238 | #return 1;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[27629] | 241 | print STDERR "DATA_DIR: ".$ENV{'DATA_DIR'}."\n";
|
---|
| 242 | print STDERR "UPLOAD_DIR: ".$ENV{'UPLOAD_DIR'}."\n";
|
---|
[27621] | 243 |
|
---|
| 244 | #create an id for this test
|
---|
| 245 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
---|
| 246 | $year += 1900;
|
---|
| 247 | $mon += 1;
|
---|
| 248 | $mon = "0$mon" if ($mon < 10);
|
---|
| 249 | $mday = "0$mday" if ($mday < 10);
|
---|
[27702] | 250 | my $dateid="$year.$mon.$mday"; #my $dateid=($year+1900)."-".($mon+1)."-$mday";
|
---|
[27621] | 251 |
|
---|
[27629] | 252 | print STDERR "Starting test '$dateid'\n";
|
---|
[27621] | 253 |
|
---|
| 254 |
|
---|
| 255 | # http://stackoverflow.com/questions/2149368/how-can-i-loop-through-files-in-a-directory-in-perl
|
---|
| 256 | $ENV{'CLASSPATH'} = "";
|
---|
| 257 | my $jar_lib_path = $ENV{'TASK_HOME'}.$sep."lib";
|
---|
| 258 | my @files = <$jar_lib_path/*.jar>; # /full/path/to/diffcol/lib/*jar
|
---|
[27628] | 259 | foreach my $file (@files) {
|
---|
[27668] | 260 | $file =~ s@\/@\\@g if $isWin;
|
---|
[27621] | 261 | $ENV{'CLASSPATH'}=$file.$pathsep.$ENV{'CLASSPATH'};
|
---|
| 262 | }
|
---|
| 263 | ##print STDERR "**** classpath: ".$ENV{'CLASSPATH'}."\n";
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 | #set the location of the full report
|
---|
[28661] | 267 | my $xmlout=filename_concat($ENV{'DATA_DIR'}, "full-report-$install_version-$dateid.xml");
|
---|
[27621] | 268 | ##print STDERR "XML: $xmlout\n";
|
---|
| 269 |
|
---|
| 270 | # the toplevel folder of the greenstone installation being used
|
---|
[28661] | 271 | my $greenstone3_home="";
|
---|
| 272 | my $greenstone_home=""; # gs2build for gs3, toplevel install folder for gs2
|
---|
[27621] | 273 | # gsdl is the checkout folder and can be greenstone2 or greenstone3
|
---|
| 274 | my $gsdl="greenstone2";
|
---|
| 275 |
|
---|
| 276 | # Check if using existing compiled-up greenstone installation
|
---|
| 277 | # and set the greenstone_home location accordingly
|
---|
| 278 |
|
---|
| 279 | if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
|
---|
[27629] | 280 | print STDERR "Found existing Greenstone home, will use that instead\n";
|
---|
[28661] | 281 | $greenstone_home=$ENV{'GSDLHOME'} if defined $ENV{'GSDLHOME'};
|
---|
| 282 |
|
---|
| 283 | if(defined $ENV{'GSDL3SRCHOME'}) {
|
---|
| 284 | print STDERR "*** GSDL3SRCHOME set, changing to using installed GS3\n";
|
---|
| 285 | $gsdl = "greenstone3";
|
---|
| 286 | $install_version = "3";
|
---|
| 287 | $greenstone3_home=$ENV{'GSDL3SRCHOME'};
|
---|
| 288 | $greenstone_home=filename_concat($greenstone3_home, "gs2build") unless defined $ENV{'GSDLHOME'};
|
---|
| 289 | }
|
---|
[27621] | 290 | } else {
|
---|
[28661] | 291 | if($install_version eq "3") {
|
---|
| 292 | $gsdl = "greenstone3";
|
---|
| 293 | $greenstone3_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
|
---|
| 294 | $greenstone_home=filename_concat($greenstone3_home, "gs2build");
|
---|
| 295 | } else {
|
---|
| 296 | $greenstone_home=filename_concat($ENV{'DATA_DIR'}, $gsdl);
|
---|
| 297 | }
|
---|
[27621] | 298 | }
|
---|
| 299 | ##print STDERR "GSHOME: $greenstone_home\n";
|
---|
| 300 |
|
---|
[27628] | 301 | #do the requested action
|
---|
| 302 | if($action eq "setup_greenstone") {
|
---|
| 303 | &setup_greenstone;
|
---|
| 304 | }
|
---|
| 305 | elsif ($action eq "run_test") {
|
---|
| 306 | &run_test;
|
---|
| 307 | }
|
---|
| 308 | elsif ($action eq "summarise") {
|
---|
| 309 | &summarise;
|
---|
| 310 | }
|
---|
| 311 | elsif ($action eq "upload") {
|
---|
| 312 | &upload;
|
---|
| 313 | &mail_with_report_attached;
|
---|
| 314 | }
|
---|
| 315 | elsif ($action eq "all") {
|
---|
| 316 | &setup_greenstone;
|
---|
| 317 | &run_test;
|
---|
| 318 | &summarise;
|
---|
| 319 | &upload;
|
---|
| 320 | &mail_with_report_attached;
|
---|
| 321 | }
|
---|
[27621] | 322 |
|
---|
| 323 | ##********************************
|
---|
| 324 |
|
---|
[27628] | 325 | sub printusage
|
---|
| 326 | {
|
---|
[28172] | 327 | # print STDERR "Run as: $0 (help|setup_greenstone|run_test <--modelOS windows|darwin|linux> <--justdiff|--nosvn> <col1 col2 ...> |summarise|upload|all)\n";
|
---|
| 328 | print STDERR "Run as: $0 (help|setup_greenstone|run_test|summarise|upload|all)\n";
|
---|
| 329 | print STDERR "where run_test can further take the following optional parameters:\n";
|
---|
| 330 | print STDERR "\t--modelOS (windows|darwin|linux)\n";
|
---|
| 331 | print STDERR "\t--justdiff|--nosvn\n";
|
---|
[29496] | 332 | print STDERR "\t--debug\n";
|
---|
[28172] | 333 | print STDERR "\t<col1 col2 ...>\n";
|
---|
[28616] | 334 | print STDERR "where setup_greenstone can further take the following optional parameters:\n";
|
---|
| 335 | print STDERR "\t--gs2|--gs3\n";
|
---|
| 336 | print STDERR "\t--svn|--bin\n";
|
---|
[27628] | 337 | }
|
---|
[27621] | 338 |
|
---|
| 339 | #http://stackoverflow.com/questions/7427262/read-a-file-and-save-it-in-variable-using-shell-script
|
---|
| 340 |
|
---|
| 341 | sub setup_greenstone
|
---|
| 342 | {
|
---|
[28661] | 343 | if($install_version eq "3" && !defined $ENV{'JAVA_HOME'}) {
|
---|
| 344 | print "*** JAVA_HOME not set. Set it and add its bin folder to the PATH\n";
|
---|
| 345 | exit 0;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
[27621] | 348 | #clean up from previous tests
|
---|
[27628] | 349 | print STDERR "about to clean up any old tests (Ctrl-C to cancel)"; # no newline
|
---|
[27621] | 350 | for my $i ( 1..5 ) {
|
---|
| 351 | sleep 1; # 1 second
|
---|
[27628] | 352 | print STDERR ".";
|
---|
[27621] | 353 | }
|
---|
[27628] | 354 | print STDERR "\n";
|
---|
[27621] | 355 |
|
---|
| 356 | # http://perldoc.perl.org/File/Path.html
|
---|
[27629] | 357 | print STDERR "cleaning up previous tests\n";
|
---|
[28661] | 358 | #&File::Path::remove_tree($ENV{'DATA_DIR'});
|
---|
| 359 | if(-d $greenstone_home && $install_version eq "2") {
|
---|
| 360 | &File::Path::remove_tree($greenstone_home);
|
---|
| 361 | }
|
---|
| 362 | if(-d $greenstone3_home && $install_version eq "3") {
|
---|
| 363 | &File::Path::remove_tree($greenstone3_home);
|
---|
| 364 | }
|
---|
| 365 | unlink glob "$ENV{'DATA_DIR'}$sep"."*report-$install_version*";
|
---|
| 366 | unlink "$ENV{'DATA_DIR'}$sep"."compilation-errors";
|
---|
[27629] | 367 | print STDERR "creating the data dir\n";
|
---|
[28661] | 368 | #&File::Path::make_path($ENV{'DATA_DIR'}); # works like mkdir -p
|
---|
[27621] | 369 |
|
---|
| 370 | chdir($ENV{'DATA_DIR'});
|
---|
[32047] | 371 | #print STDERR "@@@@ current dir: ".`pwd`."\n";
|
---|
| 372 | #print STDERR "@@@@ data dir: ".$ENV{'DATA_DIR'}."\n";
|
---|
[27621] | 373 |
|
---|
| 374 | # use existing compiled-up greenstone installation, if a GSDLHOME set
|
---|
| 375 | if(defined $ENV{'GSDL3SRCHOME'} || defined $ENV{'GSDLHOME'}) {
|
---|
[27710] | 376 | print STDERR "Found existing Greenstone home, will use that instead\n";
|
---|
[27621] | 377 | return;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | # Else checkout a GS from svn into DATA_DIR
|
---|
[28661] | 381 | if($install_type eq "svn") {
|
---|
| 382 | &checkout_gs_from_svn();
|
---|
| 383 | ##print STDERR "$ENV{'DATA_DIR'}$sep$gsdl\n";
|
---|
[27621] | 384 |
|
---|
[28661] | 385 | if($install_version eq "2") {
|
---|
| 386 | &compile_gs2_svn();
|
---|
| 387 | } else {
|
---|
| 388 | &compile_gs3_svn();
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | sub checkout_gs_from_svn {
|
---|
| 395 |
|
---|
[27621] | 396 | #svn checkout of main gsdl directory
|
---|
[27629] | 397 | print STDERR "checkout $gsdl:\n";
|
---|
[28661] | 398 | my $cmd = "svn co ".$ENV{'SVN_OPT_REV'}." http://svn.greenstone.org/main/trunk/greenstone$install_version $gsdl";
|
---|
[27621] | 399 | ##print STDERR "Checkout CMD: $cmd\n";
|
---|
| 400 |
|
---|
| 401 | # # unlike backticks operator, system() will print the output of the command to the screen as it executes
|
---|
| 402 | # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
|
---|
| 403 | my $status = system "$cmd"; #my $status = `$cmd`;
|
---|
[28661] | 404 | if($status != 0) {
|
---|
| 405 | print STDERR "@@@ SVN checkout of $gsdl failed\n";
|
---|
| 406 | exit -1;
|
---|
| 407 | }
|
---|
[27629] | 408 | print STDERR "done\n";
|
---|
[28661] | 409 | }
|
---|
[27621] | 410 |
|
---|
[28661] | 411 | sub getImageMagickBins {
|
---|
| 412 | my ($cmd, $status);
|
---|
| 413 | my $imagickzip = "";
|
---|
[27621] | 414 |
|
---|
[28661] | 415 | chdir ("$greenstone_home");
|
---|
| 416 | if(!$isWin) { # if we're on linux/darwin, need gnome-lib for the correct architecture. And need imagemagick to build imgs in collections
|
---|
[27710] | 417 |
|
---|
| 418 | my $bit_arch=`uname -m`;
|
---|
[28661] | 419 |
|
---|
| 420 | # imagemagick binary
|
---|
[27710] | 421 | print STDERR "Getting imagemagick binary\n";
|
---|
[28661] | 422 |
|
---|
[27724] | 423 | my $os = $isMac ? "darwin" : "linux";
|
---|
[28661] | 424 | $imagickzip = "imagemagick-$os";
|
---|
[27668] | 425 |
|
---|
[27710] | 426 | if($isMac) {
|
---|
[28661] | 427 | # $imagickzip .= "-10.5.tar.gz";
|
---|
[27962] | 428 | # at present, only the Imagemagick binaries created by Max for darwin work on the Macs
|
---|
[28661] | 429 | # &File::Path::make_path("$greenstone_home$sep"."bin"."$sep$os"); # need to ensure gsdl/bin/darwin exists
|
---|
[27962] | 430 | $cmd = "svn export http://svn.greenstone.org/main/trunk/binaries/mac/intel/imagemagick bin/darwin/imagemagick";
|
---|
| 431 | $status = system($cmd);
|
---|
[28661] | 432 | if($status != 0) {
|
---|
| 433 | print STDERR "@@@ Unable to get imagemagick for darwin\n";
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | # need ghostscript mac binary too for pdf to img conversions on mac
|
---|
[27963] | 437 | $cmd = "svn export http://svn.greenstone.org/main/trunk/binaries/mac/intel/ghostscript bin/darwin/ghostscript";
|
---|
| 438 | $status = system($cmd);
|
---|
[28661] | 439 | if($status != 0) {
|
---|
| 440 | print STDERR "@@@ Unable to get ghostscript for darwin\n";
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | # the imagemagick and ghostscript binaries have been set to executable on svn trac now
|
---|
| 444 | # system("chmod -R u+x $greenstone_home/bin/darwin/imagemagick/bin/*");
|
---|
| 445 | # system("chmod -R u+x $greenstone_home/bin/darwin/ghostscript/bin/*");
|
---|
[27710] | 446 | } else { # linux
|
---|
| 447 | my $extension64 = ($bit_arch =~ m/64$/) ? "-x64" : "";
|
---|
[27724] | 448 | $imagickzip .= "$extension64.tar.gz";
|
---|
[27962] | 449 |
|
---|
| 450 | # now these next imagemagick steps (and those near the end of this sub) are just for linux, no longer also for mac
|
---|
| 451 | $cmd = "svn export http://svn.greenstone.org/gs2-extensions/imagemagick/trunk/$imagickzip ext/$imagickzip";
|
---|
| 452 | $status = system ($cmd);
|
---|
| 453 | system("cd ext && tar -xvzf $imagickzip");
|
---|
[27724] | 454 | }
|
---|
[28661] | 455 | }
|
---|
| 456 | return $imagickzip;
|
---|
| 457 | }
|
---|
[27710] | 458 |
|
---|
[28661] | 459 | sub getGnomeLibExt
|
---|
| 460 | {
|
---|
[29455] | 461 | if($isWin) {
|
---|
| 462 | return; # no gnome-lib for windows
|
---|
| 463 | }
|
---|
[28661] | 464 | my ($cmd, $status);
|
---|
| 465 | my $bit_arch=`uname -m`;
|
---|
| 466 | my $os = $isMac ? "darwin" : "linux";
|
---|
| 467 |
|
---|
[27710] | 468 | # gnomelib binary
|
---|
[27629] | 469 | print STDERR "setting up gnome-lib-minimal for compilation\n";
|
---|
[27621] | 470 |
|
---|
| 471 | # To get gnome-lib, need to determine bit architecture of the linux/darwin
|
---|
| 472 | # http://stackoverflow.com/questions/8963400/the-correct-way-to-read-a-data-file-into-an-array
|
---|
| 473 | # $Config{'archname64'} doesn't work on the Ubuntu and the Sys::Info package seems to not be supported
|
---|
| 474 | # well on ActivePerl.
|
---|
[28621] | 475 | # But since we know we're on a Linux/Darwin machine at this point, we can just run `uname -m` and other linux cmds
|
---|
[27621] | 476 |
|
---|
[28571] | 477 | # osversion will be "Lion" or ""
|
---|
| 478 | # and assuming all darwin is intel, not ppc!!
|
---|
[28572] | 479 | my $gnome_lib_file = $isMac ? "darwin-".$osversion."intel" : "linux";
|
---|
[27621] | 480 |
|
---|
[28571] | 481 | $gnome_lib_file .= "-x64" if($bit_arch =~ m/64$/ && !$isMac); # linux only case
|
---|
[27621] | 482 |
|
---|
| 483 | #svn checkout gnome-lib for this linux/darwin
|
---|
[28661] | 484 | chdir("$greenstone_home$sep"."ext"); #cd $DATA_DIR/$gsdl/ext
|
---|
[27621] | 485 |
|
---|
| 486 | ##print STDERR "**** gnomelib: $gnome_lib_file\n";
|
---|
| 487 |
|
---|
| 488 | # checkout and unpack gnome-lib-minimal
|
---|
| 489 |
|
---|
| 490 | #svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-linux-x64.tar.gz gl.tar.gz
|
---|
| 491 | $cmd = "svn export http://svn.greenstone.org/gs2-extensions/gnome-lib/trunk/gnome-lib-minimal-".$gnome_lib_file.".tar.gz gl.tar.gz";
|
---|
| 492 | system $cmd;
|
---|
| 493 | system ("tar -xvzf gl.tar.gz");
|
---|
| 494 |
|
---|
| 495 | ##print STDERR "*** ARCH: $bit_arch\n";
|
---|
[28661] | 496 | }
|
---|
[27621] | 497 |
|
---|
[28661] | 498 |
|
---|
| 499 |
|
---|
| 500 | sub compile_gs3_svn() {
|
---|
| 501 | my ($cmd, $status);
|
---|
| 502 | chdir ("$greenstone3_home");
|
---|
| 503 |
|
---|
| 504 | $cmd = "ant"; # creates the build.properties file from the .in template
|
---|
| 505 | $status = system $cmd;
|
---|
| 506 | if($status != 0) {
|
---|
| 507 | print STDERR "Unable to run the ant command: $status\n";
|
---|
| 508 | exit -1;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | $cmd = "ant -Dproperties.ok=y -Dcheckout.gnomelib.ext=true prepare"; # pass in confirmation to ant prepare step
|
---|
| 512 | $status = system $cmd;
|
---|
| 513 | if($status != 0) {
|
---|
| 514 | print STDERR "Failed to run $cmd command: $status\n";
|
---|
| 515 | exit -1;
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | my $imagickzip = &getImageMagickBins();
|
---|
[36807] | 519 |
|
---|
| 520 | # To successfully compile up GS3 that gets checked out by diffcol (with --gs3 flag),
|
---|
| 521 | # Need at least unzip and wget on path. So adding winbin to path.
|
---|
| 522 | # Better to have dedicated bin folder with necessities for diffcol and add that to PATH?
|
---|
| 523 |
|
---|
| 524 | # if($isWin) { # steps from http://wiki.greenstone.org/doku.php?id=en:developer:windows_source_install
|
---|
| 525 | # my $iconv_dir = filename_concat($greenstone3_home, "gs2build", "common-src", "indexers", "packages", "windows", "iconv");
|
---|
| 526 | # chdir ("$iconv_dir");
|
---|
| 527 | # move("iconv-winVS14-VS2015-plus.zip", "iconv.zip"); #move("iconv.zip", "iconv_preVS14.zip");
|
---|
| 528 | # https://www.oreilly.com/library/view/perl-cookbook/1565922433/ch09s09.html
|
---|
| 529 | # rmtree("iconv");
|
---|
| 530 |
|
---|
| 531 | # need unzip, and maybe more from winbin
|
---|
| 532 | # my $winbin_dir = filename_concat($greenstone3_home, "gs2build", "bin", "windows");
|
---|
| 533 | # $ENV{'PATH'} = $winbin_dir . ";" . $ENV{'PATH'};
|
---|
| 534 | # }
|
---|
[28661] | 535 | chdir ("$greenstone3_home");
|
---|
| 536 |
|
---|
| 537 | $cmd = "ant -Dcheckout.gnomelib.ext=true install"; # Compile with gnome-lib.
|
---|
| 538 | $status = system $cmd;
|
---|
| 539 | if($status != 0) {
|
---|
| 540 | print STDERR "Failed to run $cmd command: $status\n";
|
---|
| 541 | exit -1;
|
---|
| 542 | }
|
---|
| 543 | }
|
---|
| 544 |
|
---|
| 545 | sub compile_gs2_svn() {
|
---|
| 546 | my $imagickzip = &getImageMagickBins();
|
---|
| 547 | &getGnomeLibExt();
|
---|
| 548 |
|
---|
| 549 | my ($cmd, $status);
|
---|
| 550 | my $os = $isMac ? "darwin" : "linux";
|
---|
| 551 |
|
---|
| 552 | chdir("$greenstone_home"); #chdir("$ENV{'DATA_DIR'}$sep$gsdl"); # goes into toplevel gs2 or gs3 folder
|
---|
| 553 |
|
---|
| 554 | ##print STDERR "@@@ OS: $^O.|".$Config{'archname64'}."|\n";
|
---|
| 555 |
|
---|
| 556 | if($isWin) {
|
---|
| 557 | print STDERR "Compiling $gsdl using makegs2.bat running in auto (silent) mode\n";
|
---|
| 558 |
|
---|
| 559 | # we're now in the GS2 folder, call makegs2 with silent param
|
---|
| 560 | $cmd = "makegs2.bat silent 2>> $ENV{'DATA_DIR'}/compilation-errors"; # STDERR is sent to compilation-errors file
|
---|
| 561 | $status = system $cmd;
|
---|
| 562 | if($status != 0) {
|
---|
| 563 | print STDERR "Greenstone compilation on Windows failed\n";
|
---|
| 564 | exit -1;
|
---|
| 565 | }
|
---|
| 566 |
|
---|
| 567 | } else { # if we're on linux/darwin, need gnome-lib for the correct architecture. And need imagemagick to build imgs in collections
|
---|
| 568 |
|
---|
| 569 | chdir("ext$sep"."gnome-lib-minimal");
|
---|
| 570 |
|
---|
[27621] | 571 | # need to run source devel.bash on gnome-lib followed by configure, make, make install
|
---|
| 572 | # in one go, in order to preserve the compile environment set up by sourcing devel.bash
|
---|
| 573 |
|
---|
| 574 | # http://stackoverflow.com/questions/7369145/activating-a-virtualenv-using-a-shell-script-doesnt-seem-to-work
|
---|
| 575 | # http://ubuntuforums.org/showthread.php?t=1932504 linking /bin/sh to bash instead of dash
|
---|
| 576 |
|
---|
| 577 | # $cmd = "bash -c \"source ./devel.bash && cd ../.. && ./configure --enable-apache-httpd && make && make install\"";
|
---|
| 578 | $cmd = "bash -c \"";
|
---|
| 579 |
|
---|
| 580 | $cmd .= "source ./devel.bash";
|
---|
| 581 | $cmd .= " && cd ../..";
|
---|
| 582 |
|
---|
| 583 | #configure
|
---|
| 584 | # $cmd .= " && ./configure";
|
---|
| 585 | $cmd .= " && echo 'configure $gsdl: ' ";
|
---|
| 586 | $cmd .= " && echo '<configure>' >> $xmlout";
|
---|
| 587 | $cmd .= " && ./configure 2>> $ENV{'DATA_DIR'}/compilation-errors"; # configure
|
---|
| 588 | $cmd .= " && echo '</configure>' >> $xmlout";
|
---|
| 589 | $cmd .= " && echo 'done'";
|
---|
| 590 |
|
---|
| 591 | #make
|
---|
| 592 | $cmd .= " && echo 'make $gsdl: '";
|
---|
| 593 | $cmd .= " && echo '<make>' >> $xmlout";
|
---|
| 594 | $cmd .= " && make 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make
|
---|
| 595 | $cmd .= " && echo '</make>' >> $xmlout";
|
---|
| 596 | $cmd .= " && echo 'done'";
|
---|
| 597 |
|
---|
| 598 | #make install
|
---|
| 599 | $cmd .= " && echo 'make install $gsdl: '";
|
---|
| 600 | $cmd .= " && echo '<make-install>' >> $xmlout";
|
---|
| 601 | $cmd .= " && make install 2>> $ENV{'DATA_DIR'}/compilation-errors"; # make install
|
---|
| 602 | $cmd .= " && echo '</make-install>' >> $xmlout";
|
---|
| 603 | $cmd .= " && echo 'done'";
|
---|
| 604 |
|
---|
| 605 | $cmd .= "\""; # close off cmd to bash and run it
|
---|
[27668] | 606 | $status = system $cmd;
|
---|
[27724] | 607 |
|
---|
[27962] | 608 | if(!$isMac) { # Linux
|
---|
[28661] | 609 | # Moving imagemagick after instead of before compilation, since bin/darwin and bin/linux gets overwritten during compilation
|
---|
| 610 | move("$greenstone_home$sep"."ext/imagemagick/$os", "$greenstone_home$sep"."bin/$os/imagemagick"); # http://www.perlmonks.org/?node_id=586537
|
---|
| 611 | unlink "$greenstone_home$sep"."ext$sep$imagickzip" or warn "Could not unlink ext/$imagickzip: $!";
|
---|
| 612 | &File::Path::remove_tree("$greenstone_home$sep"."ext$sep"."imagemagick"); # the untarred parent folder
|
---|
[27962] | 613 | }
|
---|
[27724] | 614 |
|
---|
[27621] | 615 | }
|
---|
[27668] | 616 |
|
---|
[28661] | 617 | if($status != 0) {
|
---|
| 618 | print STDERR "@@@ Compilation of Greenstone on Linux/Mac failed\n";
|
---|
| 619 | exit -1;
|
---|
| 620 | }
|
---|
| 621 |
|
---|
| 622 | &getIsisGdl("$greenstone_home"); #&getIsisGdl("$ENV{'DATA_DIR'}/$gsdl");
|
---|
[27764] | 623 |
|
---|
[27621] | 624 | # set the path to the greenstone_home variable
|
---|
[28661] | 625 | #$greenstone_home="$ENV{'DATA_DIR'}$sep$gsdl";
|
---|
[27764] | 626 | }
|
---|
[27621] | 627 |
|
---|
[27764] | 628 | sub getPDFBox
|
---|
| 629 | {
|
---|
| 630 | # current revision is 27763, but using "head" works
|
---|
[34941] | 631 | my $PDFBOX_TRAC_URL="https://trac.greenstone.org/export/head/gs2-extensions/pdf-box/trunk/pdf-box-java"; # both for .zip and .tar.gz extension
|
---|
[27764] | 632 | #"http://trac.greenstone.org/export/".$ENV{'SVN_OPT_REV'}."/gs2-extensions/pdf-box/trunk/pdf-box-java";
|
---|
| 633 |
|
---|
| 634 | # now get the PDFBox extension for PDFBox tutorial
|
---|
[36643] | 635 | print STDERR "Getting pdfbox from $PDFBOX_TRAC_URL:\n";
|
---|
[27764] | 636 |
|
---|
[36643] | 637 | my $linux_ext = ($install_version eq "3") ? "sh" : "bash";
|
---|
| 638 |
|
---|
[27764] | 639 | chdir($greenstone_home);
|
---|
| 640 | my $cmd = "";
|
---|
| 641 | if ($isWin) {
|
---|
[36643] | 642 | #$cmd = "setup.bat && cd ext && $wget $PDFBOX_TRAC_URL.zip && unzip pdf-box-java.zip";
|
---|
| 643 | $cmd = "set GSDL3SRCHOME=&& set GSDLHOME=&& $setup_script.bat && cd ext && $wget $PDFBOX_TRAC_URL.zip && unzip pdf-box-java.zip";
|
---|
[27764] | 644 | } elsif ($isMac) { # need to use curl not wget
|
---|
| 645 | $cmd = "cd ext && curl $PDFBOX_TRAC_URL.tar.gz > pdf-box-java.tar.gz && tar -xzf pdf-box-java.tar.gz";
|
---|
| 646 | }
|
---|
| 647 | else { # linux
|
---|
[36643] | 648 | $cmd = "bash -c \"export GSDLHOME=&& source $setup_script.$linux_ext && cd ext && $wget $PDFBOX_TRAC_URL.tar.gz && tar -xzf pdf-box-java.tar.gz\"";
|
---|
[27764] | 649 | }
|
---|
| 650 | my $status = system $cmd;
|
---|
| 651 | if($status != 0) {
|
---|
| 652 | print STDERR "@@@ Failed to set up PDFBox\n";
|
---|
[27765] | 653 | exit -1; # or proceed to testing other tutorials?
|
---|
[27764] | 654 | }
|
---|
[27621] | 655 | }
|
---|
| 656 |
|
---|
[28615] | 657 | sub getOpenOfficeExt
|
---|
| 658 | {
|
---|
| 659 | # current revision is 27763, but using "head" works
|
---|
[34941] | 660 | my $OOEXT_TRAC_URL="https://trac.greenstone.org/export/head/gs2-extensions/open-office/trunk/open-office-java"; # both for .zip and .tar.gz extension
|
---|
[28615] | 661 | #"http://trac.greenstone.org/export/".$ENV{'SVN_OPT_REV'}."/gs2-extensions/open-office/trunk/open-office-java";
|
---|
| 662 |
|
---|
| 663 | # now get the OpenOffice extension for the AllDocTypes collection
|
---|
| 664 | print STDERR "Getting open office ext from $OOEXT_TRAC_URL:\n";
|
---|
| 665 |
|
---|
| 666 | chdir($greenstone_home);
|
---|
| 667 | my $cmd = "";
|
---|
| 668 | if ($isWin) {
|
---|
[34941] | 669 | $cmd = "setup.bat && cd ext && $wget $OOEXT_TRAC_URL.zip && unzip open-office-java.zip";
|
---|
[28615] | 670 |
|
---|
| 671 | } elsif ($isMac) { # need to use curl not wget
|
---|
| 672 | $cmd = "cd ext && curl $OOEXT_TRAC_URL.tar.gz > open-office-java.tar.gz && tar -xzf open-office-java.tar.gz";
|
---|
| 673 | }
|
---|
| 674 | else { # linux
|
---|
[34941] | 675 | $cmd = "bash -c \"export GSDLHOME=&& source setup.bash && cd ext && $wget $OOEXT_TRAC_URL.tar.gz && tar -xzf open-office-java.tar.gz\"";
|
---|
[28615] | 676 | }
|
---|
| 677 | my $status = system $cmd;
|
---|
| 678 | if($status != 0) {
|
---|
| 679 | print STDERR "@@@ Failed to set up the Open Office Extension\n";
|
---|
| 680 | exit -1; # or proceed to testing other tutorials?
|
---|
| 681 | }
|
---|
| 682 | }
|
---|
| 683 |
|
---|
[28605] | 684 | sub getIsisGdl {
|
---|
[28606] | 685 | my $gsfolder = shift(@_);
|
---|
[28605] | 686 |
|
---|
[28606] | 687 | if(!$isWin) {
|
---|
[28661] | 688 | chdir($greenstone_home);
|
---|
[28605] | 689 | my $bit_arch=`uname -m`;
|
---|
| 690 | if ($bit_arch =~ m/64$/) {
|
---|
[28606] | 691 | my $cmd = "";
|
---|
| 692 | if($isMac) {
|
---|
[34941] | 693 | $cmd = "cd $gsfolder/bin/darwin && curl https://www.greenstone.org/caveat-emptor/IsisGdl.macleopard > IsisGdl && chmod u+x IsisGdl";
|
---|
[28606] | 694 | } else { # linux
|
---|
[34941] | 695 | $cmd = "cd $gsfolder/bin/linux && $wget https://www.greenstone.org/caveat-emptor/IsisGdl.bin32 && mv IsisGdl.bin32 IsisGdl && chmod u+x IsisGdl";
|
---|
[28606] | 696 | }
|
---|
[28605] | 697 | my $isis_status = system $cmd;
|
---|
| 698 | if($isis_status != 0) {
|
---|
[28606] | 699 | print STDERR "Unable to get IsisGdl from caveat page\n";
|
---|
[28605] | 700 | }
|
---|
| 701 | }
|
---|
| 702 | }
|
---|
| 703 | }
|
---|
| 704 |
|
---|
[27621] | 705 | # http://stackoverflow.com/questions/3377879/how-do-i-receive-command-output-immediately
|
---|
| 706 | sub run_test
|
---|
[28661] | 707 | {
|
---|
| 708 | my $collect_parent = $greenstone_home;
|
---|
| 709 | my $model_collect = "model-collect";
|
---|
| 710 | my $build_options = "";
|
---|
| 711 | if($install_version eq "3") {
|
---|
| 712 | $collect_parent = &filename_concat($greenstone3_home,"web","sites","localsite");
|
---|
| 713 | $model_collect = "gs3-model-collect";
|
---|
| 714 | $build_options = " -site localsite ";
|
---|
| 715 | chdir($greenstone3_home);
|
---|
| 716 | } else {
|
---|
| 717 | chdir($greenstone_home);
|
---|
| 718 | }
|
---|
| 719 |
|
---|
[28114] | 720 | my $num_cols = scalar(@collections); # remember the empty case
|
---|
| 721 |
|
---|
| 722 | if($num_cols == 0) { # deal with all collections
|
---|
| 723 | push (@collections, "");
|
---|
[28615] | 724 | # putting the empty string in the array so that the "all collections" case
|
---|
| 725 | # can be handled similar to how the case of user-specified collections is handled
|
---|
[28114] | 726 |
|
---|
| 727 | } else { # deal with user specified set of collections
|
---|
| 728 | # prefix the directory separator to each collection name
|
---|
| 729 | @collections = map { $sep.$_ } @collections;
|
---|
| 730 | }
|
---|
| 731 |
|
---|
[27764] | 732 | my $pdfbox = &filename_concat($greenstone_home, "ext", "pdf-box");
|
---|
[36655] | 733 | if(!-d $pdfbox) { # && $install_version eq "2"
|
---|
[27764] | 734 | &getPDFBox();
|
---|
| 735 | }
|
---|
| 736 |
|
---|
[28615] | 737 | my $openofficeext = &filename_concat($greenstone_home, "ext", "open-office");
|
---|
[36655] | 738 | if(!-d $openofficeext && $install_version eq "2") { # We don't checkout openoffice with GS3
|
---|
[36807] | 739 | # (and not all Win machines where we may want to run Win diffcol have openoffice installed)
|
---|
[28615] | 740 | &getOpenOfficeExt();
|
---|
| 741 | }
|
---|
| 742 |
|
---|
| 743 | #&getIsisGdl("$greenstone_home");
|
---|
[28605] | 744 |
|
---|
[27668] | 745 | open (my $xml_fh, '>'.$xmlout) || die "Could not open xml file $xmlout for appending: $!\n";
|
---|
[27621] | 746 |
|
---|
| 747 | # perform the requested subcommands, outputting xml information
|
---|
| 748 | print $xml_fh "<test time=\"$dateid\" id=\"$dateid\">\n";
|
---|
[28072] | 749 |
|
---|
[28114] | 750 | my ($cmd, $status);
|
---|
[27724] | 751 | # make sure that diffcol/model-collect is up to date before copying it over to greenstone-home
|
---|
[28072] | 752 |
|
---|
| 753 | if(!$use_local_rebuild) {
|
---|
[28661] | 754 | print $xml_fh "Updating $ENV{'TASK_HOME'}/$model_collect:\n";
|
---|
[28114] | 755 | for my $col (@collections) {
|
---|
[28661] | 756 | $cmd = "svn up $ENV{'TASK_HOME'}/$model_collect$col"; #chdir("$ENV{'TASK_HOME'}/$model_collect");
|
---|
[28114] | 757 | $status = system "$cmd";
|
---|
| 758 | }
|
---|
[28072] | 759 | }
|
---|
[27724] | 760 |
|
---|
[28661] | 761 | # go to whichever collecthome parent we're using
|
---|
| 762 | chdir($collect_parent);
|
---|
[27621] | 763 |
|
---|
| 764 | # get svn info
|
---|
[27629] | 765 | print STDERR "getting svn info: $xmlout\n";
|
---|
[27621] | 766 | print $xml_fh "<svn-info>\n";
|
---|
[27668] | 767 | &run_and_print_cmd("svn info", $xml_fh);
|
---|
[27621] | 768 | print $xml_fh "</svn-info>\n";
|
---|
[27629] | 769 | print STDERR "done\n";
|
---|
[27621] | 770 |
|
---|
[28114] | 771 | if(!$use_local_rebuild) {
|
---|
| 772 |
|
---|
| 773 | #make two copies of the model-collect directory in gsdl
|
---|
| 774 | #one to be rebuilt and one as the basis for comparison
|
---|
| 775 | #strip both of all .svn directories
|
---|
| 776 |
|
---|
| 777 | #copy the model collections to the collect folder to be rebuilt
|
---|
| 778 | print STDERR "installing test collections and model collections to new $gsdl installation... ";
|
---|
[28072] | 779 | #clean up
|
---|
| 780 | if(-d "collect") {
|
---|
[28114] | 781 | for my $col (@collections) {
|
---|
[28172] | 782 | if(-d "collect$col") {
|
---|
| 783 | &File::Path::remove_tree("collect$col") || die "Error could not delete collect: $!";
|
---|
| 784 | }
|
---|
[28114] | 785 | }
|
---|
[28072] | 786 | }
|
---|
[27621] | 787 |
|
---|
[28072] | 788 | if($use_static_model) {
|
---|
[28114] | 789 | for my $col (@collections) {
|
---|
| 790 | #copy to collect and strip .svn subfolders
|
---|
| 791 | &File::Path::make_path("collect$col"); # create the collect folder and copy contents from static model-collection across
|
---|
| 792 | ©_recursively("model-collect$col", "collect$col", ".svn");
|
---|
| 793 | }
|
---|
[27621] | 794 |
|
---|
[28072] | 795 | } else { # the default situation: where we check out the model-collect from svn
|
---|
[28114] | 796 | for my $col (@collections) {
|
---|
| 797 | &File::Path::remove_tree("model-collect$col");
|
---|
| 798 |
|
---|
| 799 | #copy to collect and strip .svn subfolders
|
---|
| 800 | &File::Path::make_path("collect$col"); # create the folder and copy contents across
|
---|
[28661] | 801 | ©_recursively(&filename_concat("$ENV{'TASK_HOME'}","$model_collect$col"), "collect$col", ".svn");
|
---|
[28114] | 802 |
|
---|
| 803 | #make the model copy
|
---|
| 804 | &File::Path::make_path("model-collect$col");
|
---|
| 805 | ©_recursively("collect$col", "model-collect$col"); # copy contents across
|
---|
| 806 | }
|
---|
[28072] | 807 | }
|
---|
| 808 |
|
---|
| 809 | print STDERR "done\n";
|
---|
| 810 | }
|
---|
| 811 |
|
---|
[28114] | 812 | #for each collection, import, build and diff with its model counterpart
|
---|
| 813 |
|
---|
| 814 | # if working with all collections, read the list of collections from the folders in collect
|
---|
| 815 | if($num_cols == 0) {
|
---|
| 816 | @collections = (); # get rid of the empty string put in the array to represent "all collections"
|
---|
| 817 |
|
---|
[28661] | 818 | opendir my($collect_handle), "collect" or die "Could not open dir $collect_parent/collect: $!";
|
---|
[28114] | 819 |
|
---|
| 820 | for my $collection (readdir $collect_handle) {
|
---|
| 821 | next if ($collection eq "." || $collection eq "..");
|
---|
| 822 | next if ($collection eq "modelcol");
|
---|
| 823 | push(@collections, $collection);
|
---|
| 824 | }
|
---|
| 825 | closedir $collect_handle; # close handle to collect dir
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | for my $collection (@collections) {
|
---|
[36850] | 829 |
|
---|
| 830 | my $model_os_for_collection = $model_os;
|
---|
| 831 | if($collection =~ m/Word-PDF-Enhanced/) {
|
---|
| 832 | print STDERR "**** Found windows-scripting collection for Windows only: collection Word-PDF-Enhanced\n";
|
---|
| 833 | if($test_os ne "windows") {
|
---|
| 834 | print STDERR "**** Can't test windows-specific collection on non-windows test OS: $test_os. Skipping this collection.\n";
|
---|
| 835 | next;
|
---|
| 836 | } else {
|
---|
| 837 | $model_os_for_collection = "windows";
|
---|
| 838 | print STDERR "**** This is a windows-specific collection, its model collection should have been built on windows.\n";
|
---|
| 839 | print STDERR "**** Thus switching the OS setting for this model collection to: $model_os_for_collection.\n";
|
---|
| 840 | }
|
---|
| 841 | }
|
---|
| 842 |
|
---|
[36643] | 843 | chdir($collect_parent); # for GS3 too, ensure we're first in the collect folder for each collection
|
---|
[27621] | 844 |
|
---|
[28114] | 845 | # next if ($collection ne "Demo-Lucene"); ## TEMPORARY, FOR TESTING THIS SCRIPT
|
---|
| 846 | # next if ($collection !~ m/OAI|METS|DSpace|MGPP|Lucene/); ## TEMPORARY, FOR TESTING THIS SCRIPT
|
---|
[29449] | 847 | # next if ($collection !~ m/PDFBox/); ## TEMPORARY, FOR TESTING THIS SCRIPT
|
---|
[28114] | 848 |
|
---|
[27621] | 849 | #escape the filename (in case of space)
|
---|
| 850 | $collection =~ s@ @\\ @g;
|
---|
| 851 | #getting just the basename of the collection would have been necessary had we not cd-ed into $gsdl
|
---|
[28114] | 852 |
|
---|
| 853 | $collection =~ s@^[\\/]@@g; # take the dir-sep prefix away again for user-specified collection names
|
---|
| 854 |
|
---|
| 855 | if (! -d "collect$sep$collection") {
|
---|
[36643] | 856 | print STDERR "**** Looked in current dir ".getcwd."\n";
|
---|
[28114] | 857 | print STDERR "Collection $collection does not exist\n";
|
---|
| 858 | next;
|
---|
| 859 | }
|
---|
| 860 |
|
---|
[27621] | 861 | print STDERR "*** Found collection $collection\n";
|
---|
| 862 | print $xml_fh "<collection-test name=\"$collection\">\n";
|
---|
| 863 |
|
---|
[28661] | 864 | # run the building scripts from the toplevel of the GS installation
|
---|
| 865 | if($install_version eq "3") {
|
---|
| 866 | chdir($greenstone3_home);
|
---|
| 867 | } else {
|
---|
| 868 | chdir($greenstone_home);
|
---|
| 869 | }
|
---|
| 870 |
|
---|
[28072] | 871 | if(!$use_local_rebuild) {
|
---|
| 872 | #import
|
---|
| 873 | # Ensure the OIDtype for importing is hash_on_full_filename
|
---|
| 874 | # "to make document identifiers more stable across upgrades of the software,
|
---|
| 875 | # although it means that duplicate documents contained in the collection are
|
---|
| 876 | # no longer detected automatically."
|
---|
| 877 | print STDERR "$collection - Importing:\n";
|
---|
| 878 | print $xml_fh "<import>\n";
|
---|
[28661] | 879 | &run_build_script("import.pl $build_options -removeold $collection"); #-OIDtype hash_on_full_filename
|
---|
[28072] | 880 | print $xml_fh "</import>\n";
|
---|
| 881 | print STDERR "done\n";
|
---|
[27621] | 882 |
|
---|
[28072] | 883 | #build
|
---|
| 884 | print STDERR "$collection - Building:\n";
|
---|
| 885 | print $xml_fh "<build>\n";
|
---|
[28661] | 886 | &run_build_script("buildcol.pl $build_options -removeold $collection");
|
---|
[28072] | 887 | print $xml_fh "</build>\n";
|
---|
| 888 | print STDERR "done\n";
|
---|
| 889 |
|
---|
| 890 | #rename the intermediate 'building' directory 'index'
|
---|
| 891 | print STDERR "$collection - Move \"building\" to \"index\"... ";
|
---|
[28661] | 892 | my $index = &filename_concat($collect_parent, "collect", $collection, "index");
|
---|
| 893 | my $building = &filename_concat($collect_parent, "collect", $collection, "building");
|
---|
[28072] | 894 | &File::Path::remove_tree($index);
|
---|
| 895 | # Renaming Directories, http://www.perlmonks.org/?node_id=177421
|
---|
| 896 | move($building, $index) or die "copy failed: $!"; # File::Copy::move
|
---|
| 897 | print STDERR "done\n";
|
---|
| 898 | }
|
---|
[27621] | 899 | #diffcol
|
---|
[27629] | 900 | print STDERR "$collection - Diffing:\n";
|
---|
[27621] | 901 | my $diffcol_dir = &filename_concat($ENV{'TASK_HOME'},"diffcol");
|
---|
[28172] | 902 |
|
---|
[28661] | 903 | # chdir($collect_parent); # this is actually where we are
|
---|
[28172] | 904 | # help diffcol to know on what os the model cols were generated
|
---|
| 905 | # and what os this test machine is (on which the test cols will be generated)
|
---|
[29494] | 906 | my $debug_state = $debugging ? "-debug" : "";
|
---|
[36850] | 907 | $cmd = "diffcol.pl -testos $test_os -modelos $model_os_for_collection -output xml -verbosity 10 $debug_state $collection"; # need to run with ./diffcol.pl if bash script
|
---|
[29495] | 908 |
|
---|
| 909 | #print STDERR "Running diffcol cmd: $cmd\n";
|
---|
[27621] | 910 | &run_diff_script($cmd, $xml_fh, $diffcol_dir);
|
---|
| 911 |
|
---|
[28661] | 912 | if($install_version eq "3") {
|
---|
| 913 | chdir($greenstone3_home); # this is actually where we are
|
---|
| 914 | } else {
|
---|
| 915 | chdir($greenstone_home); # this is actually where we are
|
---|
| 916 | }
|
---|
[27629] | 917 | print STDERR "done\n";
|
---|
[27621] | 918 | print $xml_fh "</collection-test>\n";
|
---|
| 919 | }
|
---|
| 920 |
|
---|
| 921 | print $xml_fh "</test>\n";
|
---|
| 922 | close($xml_fh);
|
---|
| 923 |
|
---|
[27629] | 924 | print STDERR "done\n";
|
---|
[27621] | 925 | }
|
---|
| 926 |
|
---|
| 927 | ##***************************************************************
|
---|
| 928 | # runs setup in greenstone_home before running the diff command
|
---|
| 929 | sub run_diff_script {
|
---|
| 930 | my ($cmd, $fh, $diffcol_dir) = @_;
|
---|
| 931 |
|
---|
[28661] | 932 | my $linux_ext = ($install_version eq "3") ? "sh" : "bash";
|
---|
| 933 |
|
---|
[27621] | 934 | # we're in greenstone_home now
|
---|
| 935 | if(!$isWin) {
|
---|
[28661] | 936 | $cmd = "bash -c \"export GSDL3SRCHOME=&& export GSDLHOME=&& source $setup_script.$linux_ext && cd $diffcol_dir && ./$cmd\"";
|
---|
[27621] | 937 |
|
---|
| 938 | } else { # Need to prefix cmd -c/-k as necessary
|
---|
[28661] | 939 | $cmd = "cmd /c \"set GSDL3SRCHOME=&& set GSDLHOME=&& $setup_script.bat && cd $diffcol_dir && perl -S $cmd\"";
|
---|
[27668] | 940 | ## print STDERR "@@@@ Going to call command: $cmd\n";
|
---|
[27621] | 941 | }
|
---|
| 942 |
|
---|
| 943 | return &run_and_print_cmd($cmd, $fh);
|
---|
| 944 | }
|
---|
| 945 |
|
---|
| 946 | # runs setup in greenstone_home before running the given build command
|
---|
| 947 | sub run_build_script {
|
---|
| 948 | my ($cmd, $fh) = @_;
|
---|
[28661] | 949 | my $linux_ext = ($install_version eq "3") ? "sh" : "bash";
|
---|
[27621] | 950 |
|
---|
| 951 | # chdir($greenstone_home);
|
---|
[27687] | 952 | # we are in $greenstone_home already, can directly run the build cmd on the collection
|
---|
[27621] | 953 | if(!$isWin) {
|
---|
[28661] | 954 | $cmd = "bash -c \"export GSDL3SRCHOME=&& export GSDLHOME=&& source $setup_script.$linux_ext && $cmd\"";
|
---|
[29493] | 955 | #$cmd = "bash -c \"export GSDL3SRCHOME=&& export GSDLHOME=&& export PERL_HASH_SEED_DEBUG=1&& source $setup_script.$linux_ext && $cmd\"";
|
---|
[27621] | 956 |
|
---|
| 957 | } else { # Need to prefix cmd -c/-k as necessary
|
---|
[28661] | 958 | $cmd = "cmd /c \"set GSDL3SRCHOME=&& set GSDLHOME=&& $setup_script.bat && perl -S $cmd\"";
|
---|
[27621] | 959 | }
|
---|
[27687] | 960 | ## print STDERR "@@@@ Going to call command: $cmd\n";
|
---|
[27621] | 961 |
|
---|
[27668] | 962 | return system($cmd);
|
---|
[27629] | 963 | #return &run_and_print_cmd($cmd, $fh); # doesn't work on cmds chained with bash -c
|
---|
[27621] | 964 | }
|
---|
| 965 |
|
---|
| 966 |
|
---|
| 967 | # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1activeperl%20sys::info
|
---|
| 968 | # http://stackoverflow.com/questions/1477500/how-do-i-get-the-output-of-an-external-command-in-perl
|
---|
| 969 | sub run_and_print_cmd {
|
---|
| 970 | my ($cmd, $fh) = @_;
|
---|
| 971 |
|
---|
| 972 | open my $pin, "$cmd|" or die "unable to run cmd $cmd: $!"; # open(my $fh, '-|', 'powercfg -l') or die $!;
|
---|
| 973 |
|
---|
| 974 | if(defined $fh) { # print cmd output both to the filehandle and to stdout
|
---|
| 975 | while (my $line = <$pin>) {
|
---|
| 976 | print $fh $line;
|
---|
| 977 | # print STDOUT $line; # if also printing cmd output to STDOUT
|
---|
| 978 | }
|
---|
| 979 | }
|
---|
| 980 | else { # no filehandle, so just need to print to stdout
|
---|
| 981 |
|
---|
| 982 | # unlike backticks operator, system() will print the output of the command to the screen as it executes
|
---|
| 983 | # http://stackoverflow.com/questions/758611/how-to-flush-output-in-backticks-in-perl?rq=1
|
---|
| 984 |
|
---|
| 985 | my $status = system $cmd;
|
---|
| 986 | if($status != 0) {
|
---|
| 987 | print STDERR "ERROR ($status) running $cmd: $!\n";
|
---|
| 988 | }
|
---|
| 989 | }
|
---|
| 990 | close($pin);
|
---|
| 991 | }
|
---|
| 992 |
|
---|
| 993 | sub filename_concat {
|
---|
| 994 | my $first_file = shift(@_);
|
---|
| 995 | my (@filenames) = @_;
|
---|
| 996 |
|
---|
| 997 | # If first_file is not null or empty, then add it back into the list
|
---|
| 998 | if (defined $first_file && $first_file =~ /\S/)
|
---|
| 999 | {
|
---|
| 1000 | unshift(@filenames, $first_file);
|
---|
| 1001 | }
|
---|
| 1002 |
|
---|
| 1003 | my $filename = join($sep, @filenames);
|
---|
| 1004 | $filename =~ s/[\\\/]$//; # remove trailing slashes if any
|
---|
| 1005 | return $filename;
|
---|
| 1006 | }
|
---|
| 1007 |
|
---|
| 1008 |
|
---|
| 1009 | # The following code is from
|
---|
| 1010 | # http://stackoverflow.com/questions/227613/how-can-i-copy-a-directory-recursively-and-filter-filenames-in-perl
|
---|
| 1011 | # It also states that "Perl's File::Copy is a bit broken (it doesn't copy permissions on Unix systems, for example)"
|
---|
| 1012 | sub copy_recursively {
|
---|
| 1013 | my ($from_dir, $to_dir, $regex) = @_;
|
---|
| 1014 | opendir my($dh), $from_dir or die "Could not open dir '$from_dir': $!";
|
---|
| 1015 |
|
---|
| 1016 | # if(-d !$to_dir) {
|
---|
| 1017 | # mkdir $to_dir or die "mkdir '$to_dir' failed: $!" if not -e $to_dir;
|
---|
| 1018 | # }
|
---|
| 1019 |
|
---|
| 1020 | for my $entry (readdir $dh) {
|
---|
| 1021 | next if ($entry eq "." || $entry eq "..");
|
---|
| 1022 | next if (defined $regex && $entry =~ /$regex/);
|
---|
| 1023 | my $source = "$from_dir/$entry";
|
---|
| 1024 | my $destination = "$to_dir/$entry";
|
---|
| 1025 | if (-d $source) {
|
---|
| 1026 | mkdir $destination or die "mkdir '$destination' failed: $!" if not -e $destination;
|
---|
| 1027 | copy_recursively($source, $destination, $regex);
|
---|
| 1028 | } else {
|
---|
| 1029 | copy($source, $destination) or die "copy failed: $!";
|
---|
| 1030 | }
|
---|
| 1031 | }
|
---|
| 1032 | closedir $dh;
|
---|
| 1033 | return;
|
---|
| 1034 | }
|
---|
| 1035 |
|
---|
| 1036 | sub summarise {
|
---|
| 1037 |
|
---|
| 1038 | # make a summarised Xml report
|
---|
[27629] | 1039 | print STDERR "Summarizing the xml report... ";
|
---|
[28661] | 1040 | 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";
|
---|
[27621] | 1041 | my $status = system($cmd);
|
---|
[27629] | 1042 | print STDERR "done\n";
|
---|
[27621] | 1043 |
|
---|
| 1044 | # make a summarised HTMl report
|
---|
[27629] | 1045 | print STDERR "Creating an html summary report... ";
|
---|
[28661] | 1046 | $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";
|
---|
[29493] | 1047 |
|
---|
| 1048 | print STDERR "@@@ Running summarise command: $cmd\n\n";
|
---|
[27621] | 1049 | $status = system($cmd);
|
---|
[29493] | 1050 |
|
---|
[27629] | 1051 | print STDERR "done\n";
|
---|
[28005] | 1052 |
|
---|
| 1053 | # Print whether the tests passed or failed
|
---|
| 1054 | print STDERR "*******************************************\n";
|
---|
| 1055 | print STDERR "Checking if successful... \n";
|
---|
| 1056 | $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
|
---|
| 1057 | $status = `$cmd`; #$status = system($cmd);
|
---|
| 1058 | print STDERR "result: $status\n";
|
---|
| 1059 | print STDERR "*******************************************\n";
|
---|
[27621] | 1060 | }
|
---|
| 1061 |
|
---|
| 1062 | sub upload {
|
---|
[27657] | 1063 | # if the upload dir already existed, clear it of contents
|
---|
| 1064 | if (-d $ENV{'UPLOAD_DIR'}) { #else rm $UPLOAD_DIR/*
|
---|
| 1065 | # don't want to keep previous days reports
|
---|
| 1066 | # else we will have to manually clear them at some point
|
---|
| 1067 | # just generate the set of reports for this run of task.pl upload
|
---|
| 1068 | # and
|
---|
| 1069 | &File::Path::remove_tree($ENV{'UPLOAD_DIR'});
|
---|
| 1070 | }
|
---|
| 1071 | # recreate the upload directory
|
---|
| 1072 | &File::Path::make_path($ENV{'UPLOAD_DIR'});
|
---|
[27621] | 1073 |
|
---|
| 1074 | # copy all *.xml and *.html files across to UPLOAD_DIR
|
---|
| 1075 | opendir my($dh), $ENV{'DATA_DIR'} or die "Could not open DATA_DIR: $!";
|
---|
| 1076 | for my $entry (readdir $dh) {
|
---|
[27687] | 1077 | next if ($entry !~ m/(\.xml|\.html?)$/);
|
---|
[28661] | 1078 | next if ($entry !~ m/(report-$install_version)/);
|
---|
[27687] | 1079 |
|
---|
| 1080 | # copy the reports across with different names: with OS prefixed to them. And for the HTML file on Win, rename to HTM
|
---|
| 1081 | # html files uploaded from windows to nzdl are empty for no reason. Uploading as htm seems to work
|
---|
[27694] | 1082 | my $os_entry = $entry;
|
---|
| 1083 | $os_entry =~ s@\[email protected]@ if $isWin;
|
---|
[28571] | 1084 | if($isMac) {
|
---|
[28634] | 1085 | $osversion = "Leopard-" if ($osversion eq "");
|
---|
[28572] | 1086 | $os_entry = "diffcol-".$^O."-".$osversion."$os_entry"; # darwin-Lion for Lion/Mountain Lion
|
---|
[28571] | 1087 | } else {
|
---|
| 1088 | $os_entry = "diffcol-".$^O."-$os_entry";
|
---|
| 1089 | }
|
---|
[27687] | 1090 |
|
---|
[28621] | 1091 | # if the test failed, prefix "failed" to the report so that it shows up with an error icon on the caveat page
|
---|
| 1092 | my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
|
---|
| 1093 | my $result = `$cmd`;
|
---|
| 1094 | if($result ne "yes") {
|
---|
| 1095 | $os_entry =~ s/diffcol-/diffcol-FAIL-/;
|
---|
| 1096 | }
|
---|
| 1097 |
|
---|
[27687] | 1098 | # get the absolute path to the original files before copying them over
|
---|
| 1099 | $entry = &filename_concat($ENV{'DATA_DIR'}, $entry);
|
---|
| 1100 |
|
---|
| 1101 | # copy them over with their new names
|
---|
| 1102 | ## print STDERR "@@@@ copying across $entry to $ENV{'UPLOAD_DIR'} as $os_entry\n";
|
---|
| 1103 | copy($entry, "$ENV{'UPLOAD_DIR'}$sep$os_entry"); #copy($entry, "$ENV{'UPLOAD_DIR'}");
|
---|
[27621] | 1104 | }
|
---|
| 1105 | closedir $dh;
|
---|
| 1106 |
|
---|
[27637] | 1107 |
|
---|
| 1108 | # Upload the html file to puka
|
---|
| 1109 | #default identity dir
|
---|
| 1110 | if ( ! exists $ENV{'IDENTITY_DIR'} ) {
|
---|
[27725] | 1111 | $ENV{'IDENTITY_DIR'} = "$ENV{'HOME'}${sep}.ssh"; # "C:\\Research\\Nightly\\tools\\keys" on windows, see environment.pl
|
---|
[27637] | 1112 | }
|
---|
| 1113 | if (! exists $ENV{'SNAPSHOT_MODE'} ) {
|
---|
| 1114 | $ENV{'SNAPSHOT_MODE'} = "caveat";
|
---|
| 1115 | }
|
---|
| 1116 |
|
---|
[27678] | 1117 | #use the correct key for uploading
|
---|
[27637] | 1118 | $ENV{'IDENTITY_FILE'} = "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} . ($^O eq "MSWin32" ? ".ppk" : "");
|
---|
[34520] | 1119 |
|
---|
[27637] | 1120 | if(-f $ENV{'IDENTITY_FILE'}) {
|
---|
[27678] | 1121 | # if you need to touch the file on windows: http://stackoverflow.com/questions/51435/windows-version-of-the-unix-touch-command
|
---|
| 1122 |
|
---|
[28661] | 1123 | # the report we want to upload is actually just os-diffcol-report-$install_version-$dateid.html
|
---|
[27687] | 1124 | my $command = "cd \"$ENV{'UPLOAD_DIR'}\" && tar -c *.htm* | "; #&& cat *.html | "; # && tar -c * |
|
---|
[27637] | 1125 | $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
|
---|
| 1126 | $command .= " -T -i \"$ENV{'IDENTITY_FILE'}\" nzdl\@puka.cs.waikato.ac.nz";
|
---|
| 1127 | #print "$command\n";
|
---|
| 1128 | my $status = system("$command");
|
---|
| 1129 | if($status != 0) {
|
---|
[32047] | 1130 | print STDERR "*** Failed to upload test report to nzdl $status\n";
|
---|
[27637] | 1131 | }
|
---|
[32047] | 1132 |
|
---|
[34520] | 1133 |
|
---|
| 1134 | } else {
|
---|
| 1135 | print STDERR "*** Cannot upload the test report to nzdl from this machine - no identity file $ENV{'IDENTITY_FILE'}\n";
|
---|
| 1136 | }
|
---|
| 1137 |
|
---|
| 1138 | #use the correct key for uploading - ed25519 for www-internal
|
---|
| 1139 | $ENV{'IDENTITY_FILE_ED25519'} = "$ENV{'IDENTITY_DIR'}${sep}upload-" . $ENV{'SNAPSHOT_MODE'} ."-ed25519". ($^O eq "MSWin32" ? ".ppk" : "");
|
---|
| 1140 |
|
---|
[34941] | 1141 | if (-f $ENV{'IDENTITY_FILE_ED25519'}) {
|
---|
[34520] | 1142 | # for now, upload a copy to the new new machine, later to replace puka
|
---|
[34941] | 1143 | my $command = "cd \"$ENV{'UPLOAD_DIR'}\" && tar -c *.htm* | "; #&& cat *.html | "; # && tar -c * |
|
---|
[32047] | 1144 | $command .= ($^O eq "MSWin32" ? "plink" : "ssh");
|
---|
[34520] | 1145 | $command .= " -T -i \"$ENV{'IDENTITY_FILE_ED25519'}\" nzdl-gsorg\@www-internal.greenstone.org";
|
---|
[32047] | 1146 | #print "$command\n";
|
---|
[34941] | 1147 | my $status = system("$command");
|
---|
[32047] | 1148 | if($status != 0) {
|
---|
[34418] | 1149 | print STDERR "*** Failed to upload test report to www-internal $status\n";
|
---|
[32047] | 1150 | }
|
---|
| 1151 |
|
---|
[34520] | 1152 | } else {
|
---|
| 1153 | print STDERR "**** Cannot upload the test report to www-internal from this machine - you need to generate the ed215519 identity file $ENV{'IDENTITY_FILE_ED25519'}\n";
|
---|
| 1154 | }
|
---|
[27629] | 1155 | print STDERR "Finished uploading\n";
|
---|
[27621] | 1156 | }
|
---|
| 1157 |
|
---|
| 1158 | # Sending emails with perl: http://learn.perl.org/examples/email.html
|
---|
| 1159 | # Sending email attachments with perl: http://www.perlmonks.org/?node_id=19430
|
---|
[27628] | 1160 | # Sadly none of the packages are installed by default and use of MIME::Lite is discouraged
|
---|
| 1161 | sub mail_with_report_attached
|
---|
| 1162 | {
|
---|
[34520] | 1163 | # email out with report attached, if the tests failed wwwdev
|
---|
[27629] | 1164 | print STDERR "Checking if successful... \n";
|
---|
[27628] | 1165 | my $cmd = "java org.apache.xalan.xslt.Process -IN $xmlout -XSL $ENV{'TASK_HOME'}/xsl/passed-or-not.xsl";
|
---|
| 1166 | #my $result = system($cmd);
|
---|
| 1167 | my $result = `$cmd`;
|
---|
[27621] | 1168 |
|
---|
[27629] | 1169 | print STDERR "result: $result\n";
|
---|
[27621] | 1170 |
|
---|
[27628] | 1171 | if($result ne "yes") {
|
---|
| 1172 | my $msg = "$gsdl regression test for $dateid failed";
|
---|
| 1173 | my $subject = "Regression Test Failed"; #"$gsdl regression test for $dateid failed\n";
|
---|
[28661] | 1174 | my $attach_file = &filename_concat($ENV{'DATA_DIR'}, "report-$install_version-$dateid.html");
|
---|
[27628] | 1175 |
|
---|
[27687] | 1176 | if($isWin) {
|
---|
| 1177 | if($use_blat && $blat && $ENV{'GSDL_SMTP'}) {
|
---|
[27678] | 1178 | # http://stackoverflow.com/questions/709635/sending-mail-from-batch-file
|
---|
| 1179 | #blat -to [email protected] -server smtp.example.com -f [email protected] -subject "subject" -body "body"
|
---|
[27628] | 1180 |
|
---|
[27678] | 1181 | # need to install blat on windows
|
---|
| 1182 | $cmd = "$blat -to $ENV{'MONITOR_EMAIL'} -server $ENV{'GSDL_SMTP'} -f $ENV{'MONITOR_EMAIL'} -attach $attach_file -subject \"$subject\" -body \"$msg\"";
|
---|
| 1183 | $result = system($cmd);
|
---|
| 1184 | }
|
---|
| 1185 | else {
|
---|
[27687] | 1186 | $result = 1; # status from running mail command is 0 if success, 1 if fail
|
---|
[27678] | 1187 | print STDERR "********************************************\n";
|
---|
[27687] | 1188 | if ($use_blat) {
|
---|
| 1189 | print STDERR "Need blat and SMTP set to send mail attachment\n" ;
|
---|
| 1190 | } else {
|
---|
| 1191 | print STDERR "Not set up to send mail on Windows\n";
|
---|
| 1192 | }
|
---|
[27678] | 1193 | print STDERR "Inspect report at: $attach_file\n";
|
---|
| 1194 | print STDERR "********************************************\n";
|
---|
| 1195 | }
|
---|
| 1196 | } else { # linux
|
---|
[27628] | 1197 | my $status = system("command -v mutt > /dev/null 2>&1;"); #better way of doing "which mutt"
|
---|
| 1198 |
|
---|
| 1199 | if($status != 0) { # mutt doesn't exist, can't send attachments, so send simple email
|
---|
| 1200 | $cmd="echo '$gsdl regression test for $dateid failed.' | mail -s 'Regression Test Failed' $ENV{'MONITOR_EMAIL'}";
|
---|
| 1201 |
|
---|
| 1202 | print STDERR "********************************************\n";
|
---|
| 1203 | print STDERR "No mutt installed, unable to mail attachment\n";
|
---|
| 1204 | print STDERR "Inspect report at: $attach_file\n";
|
---|
| 1205 | print STDERR "********************************************\n";
|
---|
| 1206 | } else {
|
---|
| 1207 | #$cmd = "bash -c \"echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}\"";
|
---|
| 1208 | $cmd = "echo '$gsdl regression test for $dateid failed' | mutt -a $attach_file -s 'Regression Test Failed' -- $ENV{'MONITOR_EMAIL'}";
|
---|
| 1209 | }
|
---|
[27678] | 1210 |
|
---|
| 1211 | # run the mail command
|
---|
| 1212 | $result = system($cmd); #&run_and_print_cmd($cmd);
|
---|
[27628] | 1213 | }
|
---|
| 1214 |
|
---|
[27678] | 1215 |
|
---|
[27637] | 1216 | if($result != 0) {
|
---|
| 1217 | print STDERR "*** Unable to send email: $?\n";
|
---|
| 1218 | }
|
---|
| 1219 | else {
|
---|
| 1220 | print STDERR "Sent mail with report attached.\n";
|
---|
| 1221 | }
|
---|
[27628] | 1222 | } else {
|
---|
| 1223 | print STDERR "********************************************\n";
|
---|
[27629] | 1224 | print STDERR "Tests were successful. Not sending mail.\n";
|
---|
[27628] | 1225 | print STDERR "********************************************\n";
|
---|
| 1226 | }
|
---|
| 1227 | }
|
---|
| 1228 |
|
---|
[27621] | 1229 | # The old version of this program contained the following, consisting of 1 line of active code:
|
---|
| 1230 |
|
---|
| 1231 | # Invoke as: sjmc@br:/research/sjm84/envi/bin$ ./envi diffcol summarise
|
---|
| 1232 | # Doing so will call this pl file and pass in "summarise" in ARGV
|
---|
| 1233 | # This pl file will in turn call the task executable in this folder
|
---|
| 1234 | # passing in "summarise" as a parameter.
|
---|
| 1235 | #system("/bin/bash -c \"../etc/tasks/diffcol/task @ARGV\"");
|
---|
| 1236 |
|
---|
| 1237 | ##system("/bin/bash -c \"./task @ARGV\"");
|
---|
| 1238 | ##print STDERR "/bin/bash -c ../etc/tasks/diffcol/task @ARGV"
|
---|
[27694] | 1239 |
|
---|