source: trunk/gsdl/bin/script/mirror.pl@ 2472

Last change on this file since 2472 was 2472, checked in by paynter, 23 years ago

execute perl scripts with perl -S.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
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 strict;
51use arcinfo;
52use colcfg;
53use plugin;
54use docprint;
55use util;
56use parsargv;
57
58sub print_usage {
59 print STDERR "\n";
60 print STDERR "mirror.pl: Uses w3mir or wget to sync a collections import data\n";
61 print STDERR " with a website.\n\n";
62 print STDERR " usage: $0 [options] collection-name\n\n";
63 print STDERR " options:\n";
64 print STDERR " -verbosity number 0=none, 3=lots\n";
65 print STDERR " -importdir directory Where to place the mirrored material\n";
66}
67
68
69&main ();
70
71sub main {
72 my ($verbosity, $importdir, $etcdir,
73 $collection, $configfilename, $collectcfg);
74
75 if (!parsargv::parse(\@ARGV,
76 'verbosity/\d+/2', \$verbosity,
77 'importdir/.*/', \$importdir )) {
78 &print_usage();
79 die "\n";
80 }
81
82 # get and check the collection name
83 if (($collection = &util::use_collection(@ARGV)) eq "") {
84 &print_usage();
85 die "\n";
86 }
87
88 # get the etc directory
89 $etcdir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc");
90
91 # check the collection configuration file for options
92 my $interval = 0;
93 $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'},
94 "etc", "collect.cfg");
95 if (-e $configfilename) {
96 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
97 if (defined $collectcfg->{'importdir'} && $importdir eq "") {
98 $importdir = $collectcfg->{'importdir'};
99 }
100 } else {
101 die "Couldn't find the configuration file $configfilename\n";
102 }
103
104 # fill in the default import directories if none
105 # were supplied, turn all \ into / and remove trailing /
106 $importdir = "$ENV{'GSDLCOLLECTDIR'}/import" if $importdir eq "";
107 $importdir =~ s/[\\\/]+/\//g;
108 $importdir =~ s/\/$//;
109
110 # make sure there is an import directory
111 if (! -e "$importdir") {
112 &util::mk_dir($importdir);
113 }
114
115 # if w3mir.cfg exists,
116 # then we are using w3mirror to mirror the remote site
117 if (-e "$etcdir/w3mir.cfg") {
118
119 # run the mirror program from the import directory
120 my $cmd = "cd $importdir; ";
121 $cmd .= "perl -S gsw3mir.pl -cfgfile $etcdir/w3mir.cfg";
122 # print "\n$cmd\n";
123 `$cmd`;
124
125 }
126
127 # if wget.cfg and wget.url both exist,
128 # then we are using GNU wget to mirror the remote site
129 elsif ((-e "$etcdir/wget.cfg") && (-e "$etcdir/wget.url")) {
130 $ENV{WGETRC} = "$etcdir/wget.cfg";
131 my $cmd = "perl -S gsWget.pl --input-file=$etcdir/wget.url --directory-prefix=$importdir";
132 system($cmd);
133 }
134
135 # otherwise, there are no mirror copnfiguration files
136 else {
137 die "Couldn't find the mirror configuration files in $etcdir\n";
138 }
139
140
141}
142
143
144
145
146
147
Note: See TracBrowser for help on using the repository browser.