[14959] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | BEGIN
|
---|
| 4 | {
|
---|
| 5 | if (!defined $ENV{'GSDLHOME'}) {
|
---|
| 6 | print STDERR "Environment variable GSDLHOME not set.\n";
|
---|
| 7 | print STDERR " Have you sourced Greenstone's 'setup.bash' file?\n";
|
---|
| 8 | exit 1;
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | if (!defined $ENV{'JAVA_HOME'}) {
|
---|
| 12 | print STDERR "Environment variable JAVA_HOME not set.\n";
|
---|
| 13 | print STDERR "Needed by Fedora command line scripts.\n";
|
---|
| 14 | exit 1;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | $ENV{'FEDORA_HOSTNAME'} = "localhost" if (!defined $ENV{'FEDORA_HOSTNAME'});
|
---|
| 18 | $ENV{'FEDORA_SERVER_PORT'} = "8080" if (!defined $ENV{'FEDORA_SERVER_PORT'});
|
---|
| 19 | $ENV{'FEDORA_USER'} = "fedoraAdmin" if (!defined $ENV{'FEDORA_USER'});
|
---|
| 20 | $ENV{'FEDORA_PASS'} = "fedoraAdmin" if (!defined $ENV{'FEDORA_PASS'});
|
---|
| 21 | $ENV{'FEDORA_PROTOCOL'} = "http" if (!defined $ENV{'FEDORA_PROTOCOL'});
|
---|
| 22 | $ENV{'FEDORA_PID_NAMESPACE'} = "greenstone" if (!defined $ENV{'FEDORA_PID_NAMESPACE'});
|
---|
| 23 |
|
---|
| 24 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/");
|
---|
| 25 |
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | use strict;
|
---|
| 30 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 31 | no strict 'subs'; # allow barewords (e.g. STDERR) as function arguments
|
---|
| 32 |
|
---|
| 33 | use util;
|
---|
| 34 | use gsprintf 'gsprintf';
|
---|
| 35 | use printusage;
|
---|
| 36 | use parse2;
|
---|
| 37 |
|
---|
| 38 | use g2futil;
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | my $arguments =
|
---|
| 42 | [
|
---|
| 43 | { 'name' => "verbosity",
|
---|
| 44 | 'desc' => "Level of verbosity generated",
|
---|
| 45 | 'type' => "string",
|
---|
| 46 | 'deft' => '1',
|
---|
| 47 | 'reqd' => "no",
|
---|
| 48 | 'hiddengli' => "no" },
|
---|
| 49 | { 'name' => "hostname",
|
---|
| 50 | 'desc' => "Domain hostname of Fedora server",
|
---|
| 51 | 'type' => "string",
|
---|
| 52 | 'deft' => $ENV{'FEDORA_HOSTNAME'},
|
---|
| 53 | 'reqd' => "no",
|
---|
| 54 | 'hiddengli' => "no" },
|
---|
| 55 | { 'name' => "port",
|
---|
| 56 | 'desc' => "Port that the Fedora server is running on.",
|
---|
| 57 | 'type' => "string",
|
---|
| 58 | 'deft' => $ENV{'FEDORA_SERVER_PORT'},
|
---|
| 59 | 'reqd' => "no",
|
---|
| 60 | 'hiddengli' => "no" },
|
---|
| 61 | { 'name' => "username",
|
---|
| 62 | 'desc' => "Fedora admin username",
|
---|
| 63 | 'type' => "string",
|
---|
| 64 | 'deft' => $ENV{'FEDORA_USER'},
|
---|
| 65 | 'reqd' => "no",
|
---|
| 66 | 'hiddengli' => "no" },
|
---|
| 67 | { 'name' => "password",
|
---|
| 68 | 'desc' => "Fedora admin password",
|
---|
| 69 | 'type' => "string",
|
---|
| 70 | 'deft' => $ENV{'FEDORA_PASS'},
|
---|
| 71 | 'reqd' => "no",
|
---|
| 72 | 'hiddengli' => "no" },
|
---|
| 73 | { 'name' => "protocol",
|
---|
| 74 | 'desc' => "Fedora protocol, e.g. 'http' or 'https'",
|
---|
| 75 | 'type' => "string",
|
---|
| 76 | 'deft' => $ENV{'FEDORA_PROTOCOL'},
|
---|
| 77 | 'reqd' => "no",
|
---|
| 78 | 'hiddengli' => "no" },
|
---|
| 79 | { 'name' => "pidnamespace",
|
---|
| 80 | 'desc' => "Fedora prefix for PIDs",
|
---|
| 81 | 'type' => "string",
|
---|
| 82 | 'deft' => $ENV{'FEDORA_PID_NAMESPACE'},
|
---|
| 83 | 'reqd' => "no",
|
---|
| 84 | 'hiddengli' => "no" },
|
---|
| 85 | { 'name' => "gli",
|
---|
| 86 | 'desc' => "",
|
---|
| 87 | 'type' => "flag",
|
---|
| 88 | 'reqd' => "no",
|
---|
| 89 | 'hiddengli' => "yes" },
|
---|
| 90 | { 'name' => "xml",
|
---|
| 91 | 'desc' => "{scripts.xml}",
|
---|
| 92 | 'type' => "flag",
|
---|
| 93 | 'reqd' => "no",
|
---|
| 94 | 'hiddengli' => "yes" },
|
---|
| 95 | { 'name' => "removeold",
|
---|
| 96 | 'desc' => "{import.removeold}",
|
---|
| 97 | 'type' => "flag",
|
---|
| 98 | 'reqd' => "no",
|
---|
| 99 | 'modegli' => "3" },
|
---|
| 100 | { 'name' => "language",
|
---|
| 101 | 'desc' => "{scripts.language}",
|
---|
| 102 | 'type' => "string",
|
---|
| 103 | 'reqd' => "no",
|
---|
[18590] | 104 | 'modegli' => "3" },
|
---|
[14959] | 105 | { 'name' => "collectdir",
|
---|
| 106 | 'desc' => "{import.collectdir}",
|
---|
| 107 | 'type' => "string",
|
---|
| 108 | 'deft' => "",
|
---|
| 109 | 'reqd' => "no",
|
---|
| 110 | 'hiddengli' => "yes" }
|
---|
| 111 | ];
|
---|
| 112 |
|
---|
| 113 | my $prog_options
|
---|
| 114 | = { 'name' => "g2fbuildcol.pl",
|
---|
| 115 | 'desc' => "Ingest Greenstone directory of FedoraMETS documents into Fedora",
|
---|
| 116 | 'args' => $arguments };
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 | sub main
|
---|
| 120 | {
|
---|
| 121 | my (@ARGV) = @_;
|
---|
| 122 |
|
---|
| 123 | my $GSDLHOME = $ENV{'GSDLHOME'};
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | my $options = {};
|
---|
| 127 | # general options available to all plugins
|
---|
| 128 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$options,"allow_extra_options");
|
---|
| 129 |
|
---|
| 130 | # Something went wrong with parsing
|
---|
| 131 | if ($intArgLeftinAfterParsing ==-1)
|
---|
| 132 | {
|
---|
| 133 | &PrintUsage::print_txt_usage($prog_options, "[options] greenstone-col");
|
---|
| 134 | die "\n";
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | my $xml = $options->{'xml'};
|
---|
| 138 | my $gli = $options->{'gli'};
|
---|
| 139 |
|
---|
| 140 | if ($intArgLeftinAfterParsing != 1)
|
---|
| 141 | {
|
---|
| 142 | if ($xml) {
|
---|
| 143 | &PrintUsage::print_xml_usage($prog_options);
|
---|
| 144 | print "\n";
|
---|
| 145 | return;
|
---|
| 146 | }
|
---|
| 147 | else {
|
---|
| 148 | &PrintUsage::print_txt_usage($prog_options, "[options] greenstone-col");
|
---|
| 149 | print "\n";
|
---|
| 150 | return;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | my $gs_col = $ARGV[0];
|
---|
| 156 |
|
---|
| 157 | my $verbosity = $options->{'verbosity'};
|
---|
| 158 | my $hostname = $options->{'hostname'};
|
---|
| 159 | my $port = $options->{'port'};
|
---|
| 160 | my $username = $options->{'username'};
|
---|
| 161 | my $password = $options->{'password'};
|
---|
| 162 | my $protocol = $options->{'protocol'};
|
---|
| 163 | my $pid_namespace = $options->{'pidnamespace'};
|
---|
| 164 |
|
---|
| 165 | # The following are needed in the FedoraMETS plugout
|
---|
| 166 | $ENV{'FEDORA_HOSTNAME'} = $hostname;
|
---|
| 167 | $ENV{'FEDORA_SERVER_PORT'} = $port;
|
---|
| 168 |
|
---|
| 169 | my $collectdir = $options->{'collectdir'};
|
---|
| 170 |
|
---|
| 171 | if (!$collectdir) {
|
---|
[21687] | 172 | if($ENV{'GSDL3HOME'}) {
|
---|
| 173 | $collectdir = &util::filename_cat($ENV{'GSDL3HOME'},"sites","localsite","collect");
|
---|
| 174 | } else {
|
---|
| 175 | $collectdir = util::filename_cat($ENV{'GSDLHOME'},"collect");
|
---|
| 176 | }
|
---|
[14959] | 177 | }
|
---|
| 178 |
|
---|
| 179 | my $full_gs_col = util::filename_cat($collectdir,$gs_col);
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | if (!-e $full_gs_col ) {
|
---|
| 183 | print STDERR "Unable to find Greenstone collection $full_gs_col\n";
|
---|
| 184 | exit 1;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | ## my $archives_dir = &util::filename_cat($full_gs_col,"archives");
|
---|
| 188 | my $export_dir = &util::filename_cat($full_gs_col,"export");
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | print "***\n";
|
---|
| 192 | print "* Ingesting Greenstone processed files into Fedora $pid_namespace\n";
|
---|
| 193 | print "***\n";
|
---|
| 194 |
|
---|
| 195 | # Following falls foul of Schematron rule checking
|
---|
| 196 | my $fd_add_prog = "fedora-ingest";
|
---|
| 197 | # my $fd_add_cmd;
|
---|
| 198 | # $fd_add_args = "dir $export_dir O metslikefedora1 $hostname:$port $username $password \\\n";
|
---|
| 199 | # $fd_add_args .= " \"Automated_ingest_by_gs2fed.pl\"";
|
---|
| 200 |
|
---|
| 201 | # &g2futil::run_cmd($fd_add_prog,$fd_add_args,$options);
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | # => Ingest individually!
|
---|
| 205 |
|
---|
| 206 | if (opendir(DIR, $export_dir)) {
|
---|
| 207 | closedir DIR;
|
---|
[16102] | 208 | ## my @hash_dirs = grep { /\.dir$/ } readdir(DIR);
|
---|
| 209 | my @hash_dirs = &g2futil::get_all_hash_dirs($export_dir);
|
---|
[14959] | 210 |
|
---|
| 211 |
|
---|
| 212 | # for each hash dir, purge its respective PID
|
---|
| 213 | foreach my $hd (@hash_dirs) {
|
---|
| 214 |
|
---|
| 215 | my $docmets_filename
|
---|
[16102] | 216 | = &util::filename_cat($hd,"docmets.xml");
|
---|
[14959] | 217 |
|
---|
| 218 | print STDERR "<Build>\n" if $gli;
|
---|
| 219 |
|
---|
| 220 | print "Ingesting $docmets_filename\n";
|
---|
| 221 |
|
---|
| 222 | &g2futil::run_ingest($docmets_filename,$options);
|
---|
| 223 | print STDERR "</Build>\n" if $gli;
|
---|
| 224 |
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | else {
|
---|
| 228 | print STDERR "Error: Unable to open directory $export_dir: $!\n";
|
---|
| 229 | exit;
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | &main(@ARGV);
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 |
|
---|