1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | ###########################################################################
|
---|
4 | #
|
---|
5 | # mirror.pl
|
---|
6 | #
|
---|
7 | # A component of the Greenstone digital library software
|
---|
8 | # from the New Zealand Digital Library Project at the
|
---|
9 | # University of Waikato, New Zealand.
|
---|
10 | #
|
---|
11 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or modify
|
---|
14 | # it under the terms of the GNU General Public License as published by
|
---|
15 | # the Free Software Foundation; either version 2 of the License, or
|
---|
16 | # (at your option) any later version.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful,
|
---|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
21 | # GNU General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, write to the Free Software
|
---|
25 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
26 | #
|
---|
27 | ###########################################################################
|
---|
28 |
|
---|
29 |
|
---|
30 | # This program uses w3mirror to mirror a web site. It looks for a
|
---|
31 | # w3mirror configuration file in etc/w3mir.cfg, and if it finds one then
|
---|
32 | # it runs w3mirror (using this configuration file) in the import
|
---|
33 | # directory. Afterwards, a mirror of the web site (as dictated by the
|
---|
34 | # configuration file) will be in the import directory.
|
---|
35 |
|
---|
36 | BEGIN {
|
---|
37 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
38 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
39 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
40 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
|
---|
41 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
|
---|
42 | }
|
---|
43 |
|
---|
44 | use strict;
|
---|
45 | use arcinfo;
|
---|
46 | use colcfg;
|
---|
47 | use plugin;
|
---|
48 | use docprint;
|
---|
49 | use util;
|
---|
50 | use parsargv;
|
---|
51 |
|
---|
52 | sub print_usage {
|
---|
53 | print STDERR "\n usage: $0 [options] collection-name\n\n";
|
---|
54 | print STDERR " options:\n";
|
---|
55 | print STDERR " -verbosity number 0=none, 3=lots\n";
|
---|
56 | print STDERR " -importdir directory Where to place the mirrored material\n";
|
---|
57 | }
|
---|
58 |
|
---|
59 |
|
---|
60 | &main ();
|
---|
61 |
|
---|
62 | sub main {
|
---|
63 | my ($verbosity, $importdir, $etcdir,
|
---|
64 | $collection, $configfilename, $collectcfg);
|
---|
65 |
|
---|
66 | if (!parsargv::parse(\@ARGV,
|
---|
67 | 'verbosity/\d+/2', \$verbosity,
|
---|
68 | 'importdir/.*/', \$importdir )) {
|
---|
69 | &print_usage();
|
---|
70 | die "\n";
|
---|
71 | }
|
---|
72 |
|
---|
73 | # get and check the collection name
|
---|
74 | if (($collection = &util::use_collection(@ARGV)) eq "") {
|
---|
75 | &print_usage();
|
---|
76 | die "\n";
|
---|
77 | }
|
---|
78 |
|
---|
79 | # check the configuration file for options
|
---|
80 | my $interval = 0;
|
---|
81 | $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
|
---|
82 | if (-e $configfilename) {
|
---|
83 | $collectcfg = &colcfg::read_collect_cfg ($configfilename);
|
---|
84 | if (defined $collectcfg->{'importdir'} && $importdir eq "") {
|
---|
85 | $importdir = $collectcfg->{'importdir'};
|
---|
86 | }
|
---|
87 | } else {
|
---|
88 | die "Couldn't find the configuration file $configfilename\n";
|
---|
89 | }
|
---|
90 |
|
---|
91 | # fill in the default import directories if none
|
---|
92 | # were supplied, turn all \ into / and remove trailing /
|
---|
93 | $importdir = "$ENV{'GSDLCOLLECTDIR'}/import" if $importdir eq "";
|
---|
94 | $importdir =~ s/[\\\/]+/\//g;
|
---|
95 | $importdir =~ s/\/$//;
|
---|
96 |
|
---|
97 | $etcdir = "$ENV{'GSDLCOLLECTDIR'}/etc";
|
---|
98 |
|
---|
99 | print "import directory: $importdir\n";
|
---|
100 | print " w3config file: $etcdir/w3mir.cfg\n\n";
|
---|
101 |
|
---|
102 | # make sure there is an import directory
|
---|
103 | if (! -e "$importdir") {
|
---|
104 | &util::mk_dir($importdir);
|
---|
105 | }
|
---|
106 |
|
---|
107 | # make sure there is a w3mir file
|
---|
108 | if (! -e "$etcdir/w3mir.cfg") {
|
---|
109 | die "Couldn't find the w3mir configuration file $etcdir/w3mir.cfg\n";
|
---|
110 | }
|
---|
111 |
|
---|
112 | # run the mirror program from the import directory
|
---|
113 | my $command = "cd $importdir; gsw3mir.pl -cfgfile $etcdir/w3mir.cfg\n";
|
---|
114 | # print "\n$command\n";
|
---|
115 | `$command`;
|
---|
116 |
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|