root/main/trunk/greenstone2/bin/script/mirror.pl @ 24192

Revision 24192, 4.6 KB (checked in by ak19, 8 years ago)

Sam discovered that using dollar-Config{perlpath} in place of dollar-hat-X is the better way to obtain the path to the perl that is being used. We hope this will not be a relative path on the Mac as dollar-hat-x was on Professor Witten's Mac when we tried it there today.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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# mirror program configuration files in etc, and if it finds them then
32# it runs the mirroring software using this configuration file, and placing
33# the mirror in the import directory.
34#
35# mirror.pl can use the w3mirror program or the wget program if they are
36# installed.
37#
38# To use w3mirror, the configuration file must be in etc/w3mir.cfg.
39# To use GNU wget, the configuration file (i.e. a wgetrc file) must
40# be in etc/wget.cfg and a file of the URLs to read in etc/wget.url
41
42BEGIN {
43    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
44    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
45    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
46    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
47    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
48}
49
50use Config; # for getting the perlpath in the recommended way
51use arcinfo;
52use colcfg;
53use util;
54use parsargv;
55
56sub print_usage {
57    print STDERR "\n";
58    print STDERR "mirror.pl: Uses w3mir or wget to sync a collections import data\n";
59    print STDERR "           with a website.\n\n";
60    print STDERR "  usage: $0 [options] collection-name\n\n";
61    print STDERR "  options:\n";
62    print STDERR "   -verbosity number      0=none, 3=lots\n";
63    print STDERR "   -importdir directory   Where to place the mirrored material\n";
64}
65
66
67&main ();
68
69sub main {
70    my ($verbosity, $importdir, $etcdir,
71        $collection, $configfilename, $collectcfg);
72
73    if (!parsargv::parse(\@ARGV,
74             'verbosity/\d+/2', \$verbosity,
75             'importdir/.*/', \$importdir )) {
76    &print_usage();
77    die "\n";
78    }
79
80    # get and check the collection name
81    if (($collection = &util::use_collection(@ARGV)) eq "") {
82    &print_usage();
83    die "\n";
84    }
85
86    # get the etc directory
87    $etcdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc");
88   
89    # check the collection configuration file for options
90    my $interval = 0;
91    $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'},
92                       "etc", "collect.cfg");
93    if (-e $configfilename) {
94    $collectcfg = &colcfg::read_collect_cfg ($configfilename);
95    if (defined $collectcfg->{'importdir'} && $importdir eq "") {
96        $importdir = $collectcfg->{'importdir'};
97    }
98    } else {
99    die "Couldn't find the configuration file $configfilename\n";
100    }
101   
102    # fill in the default import directories if none
103    # were supplied, turn all \ into / and remove trailing /
104    $importdir = "$ENV{'GSDLCOLLECTDIR'}/import" if $importdir eq "";
105    $importdir =~ s/[\\\/]+/\//g;
106    $importdir =~ s/\/$//;
107
108    # make sure there is an import directory
109    if (! -e "$importdir") {
110    &util::mk_dir($importdir);
111    }
112
113    # if w3mir.cfg exists,
114    # then we are using w3mirror to mirror the remote site
115    if (-e "$etcdir/w3mir.cfg") {
116
117    # run the mirror program from the import directory
118    my  $cmd = "cd $importdir; ";
119    #Config{perlpath}, like $^X, is a special variable containing the full path to the current perl executable we are in
120    $cmd .= "\"$Config{perlpath}\" -S gsw3mir.pl -cfgfile $etcdir/w3mir.cfg";
121    # print "\n$cmd\n";
122    `$cmd`;
123
124    }
125
126    # if wget.cfg and wget.url both exist,
127    # then we are using GNU wget to mirror the remote site
128    elsif ((-e "$etcdir/wget.cfg") && (-e "$etcdir/wget.url")) {
129    $ENV{WGETRC} = "$etcdir/wget.cfg";
130    my $cmd = "\"$Config{perlpath}\" -S gsWget.pl --input-file=$etcdir/wget.url --directory-prefix=$importdir";
131    system($cmd);
132    }
133
134    # otherwise, there are no mirror copnfiguration files
135    else {
136    die "Couldn't find the mirror configuration files in $etcdir\n";
137    }
138
139
140}
141
142
143
144
145
146
Note: See TracBrowser for help on using the browser.