source: trunk/gsdl/bin/script/update.pl@ 2785

Last change on this file since 2785 was 2785, checked in by sjboddie, 23 years ago

The build process now creates a summary of how many files were included,
which were rejected, etc. A link to a page containing this summary is
provided from the final page of the collector (once the collection is built
successfully) and from the default "about this collection" text for
collections built by the collector.

Also did a little bit of tidying in a couple of places

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# update.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 updates any collections that are based on mirrors of
31# web sites after a certain interval. It first checks that the
32# collection is a mirrored collection and whether it is time to
33# update the collection. If so, it updates the mirror with
34# mirror.pl; then imports the collection with import.pl; then
35# builds the collection with buildcol.pl; then replaces the
36# existing index directory with the new building directory.
37# The etc/mirror.log file stores the STDOUT output.
38
39
40BEGIN {
41 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
42 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
43 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
44 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
45 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
46}
47
48use arcinfo;
49use colcfg;
50use plugin;
51use docprint;
52use util;
53use parsargv;
54
55sub print_usage {
56 print STDERR "\n";
57 print STDERR "update.pl: Updates a collection if it has been set up to mirror\n";
58 print STDERR " a website. Calls mirror.pl to do the mirroring.\n\n";
59 print STDERR " usage: $0 [options] collection-name\n\n";
60 print STDERR " options:\n";
61 print STDERR " -verbosity number 0=none, 3=lots\n";
62 print STDERR " -importdir directory Where to place the mirrored material\n";
63 print STDERR " -archivedir directory Where the converted material ends up\n";
64}
65
66
67&main ();
68
69sub main {
70 my ($verbosity, $importdir, $archivedir, $builddir, $indexdir, $etcdir,
71 $mirror, $interval, $logfile,
72 $collection, $configfilename, $collectcfg);
73
74 if (!parsargv::parse(\@ARGV,
75 'verbosity/\d+/2', \$verbosity,
76 'importdir/.*/', \$importdir,
77 'archivedir/.*/', \$archivedir )) {
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 # check the configuration file for options
89 $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
90 if (-e $configfilename) {
91 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
92 if (defined $collectcfg->{'importdir'} && $importdir eq "") {
93 $importdir = $collectcfg->{'importdir'};
94 }
95 if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
96 $archivedir = $collectcfg->{'archivedir'};
97 }
98 if (defined $collectcfg->{'mirror'}) {
99 $mirror = $collectcfg->{'mirror'};
100 }
101 } else {
102 die "Couldn't find the configuration file $configfilename\n";
103 }
104
105 # fill in the default import and archives directories if none
106 # were supplied, turn all \ into / and remove trailing /
107 $importdir = "$ENV{'GSDLCOLLECTDIR'}/import" if $importdir eq "";
108 $importdir =~ s/[\\\/]+/\//g;
109 $importdir =~ s/\/$//;
110 $archivedir = "$ENV{'GSDLCOLLECTDIR'}/archives" if $archivedir eq "";
111 $archivedir =~ s/[\\\/]+/\//g;
112 $archivedir =~ s/\/$//;
113
114 $indexdir = "$ENV{'GSDLCOLLECTDIR'}/index";
115 $builddir = "$ENV{'GSDLCOLLECTDIR'}/building";
116 $etcdir = "$ENV{'GSDLCOLLECTDIR'}/etc";
117 $logfile = "$etcdir/mirror.log";
118
119 # if there is no mirror information, we're all done
120 if (!defined($mirror)) {
121 print "No mirror command in $configfilename\n";
122 exit;
123 }
124
125 # read the mirror interval
126 if (($#$mirror == 1) && ($$mirror[0] =~ /interval/)){
127 $interval = $$mirror[1];
128 } else {
129 die "Malformed mirror information: use \"mirror interval N\"\n" .
130 "where N is the number of days between mirrors.\n";
131 }
132
133 # make sure there is an import directory
134 if (! -e "$importdir") {
135 &util::mk_dir($importdir);
136 }
137
138 print "archives directory: $archivedir\n";
139 print " import directory: $importdir\n";
140 print " etc directory: $etcdir\n";
141 print " interval: $interval days\n";
142
143 # how many days is it since the last mirror
144 my $seconds = 0;
145 if (-e "$logfile") {
146 my $now = time;
147 my @stats = stat("$logfile");
148 my $then = $stats[9];
149 # calculate the number of days since the last mirror
150 $seconds = $now - $then;
151 }
152 my $days = (($seconds / 3600) / 24);
153
154 # Is it too soon to start mirroring?
155 if (($seconds > 0) && ($interval > $days)) {
156 printf "Mirror not started: only %.1f days have passed\n", $days;
157 exit;
158 }
159
160 # Mirror the remote site
161 open(WLOG, ">$logfile");
162 print WLOG "Starting mirror at " . time . "\n\n";
163
164 my $command = "mirror.pl $collection";
165 print WLOG "Executing: $command\n";
166 print WLOG `$command`;
167
168 # Import the collection
169 print WLOG "\n\nStarting import at " . time . "\n\n";
170 $command = "import.pl -removeold $collection";
171 print WLOG "Executing: $command\n";
172 print WLOG `$command`;
173
174 # Build the collection
175 print WLOG "\n\nStarting buildcol.pl at " . time . "\n\n";
176 $command = "buildcol.pl $collection";
177 print WLOG "Executing: $command\n";
178 print WLOG `$command`;
179
180 # Renaming the building directory to index
181 print WLOG "\n\nRenaming building directory at " . time . "\n\n";
182 if (-e $indexdir) {
183 &util::mv($indexdir, "$indexdir.old");
184 &util::mv($builddir, $indexdir);
185 &util::rm_r ("$indexdir.old");
186 } else {
187 &util::mv($builddir, $indexdir);
188 }
189
190
191 close WLOG;
192
193}
194
195
196
197
198
Note: See TracBrowser for help on using the repository browser.