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

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

Added more usage information to all perl programs and removed a few
programs that are no longer useful.

  • 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 strict;
49use arcinfo;
50use colcfg;
51use plugin;
52use docprint;
53use util;
54use parsargv;
55
56sub print_usage {
57 print STDERR "\n";
58 print STDERR "update.pl: Updates a collection if it has been set up to mirror\n";
59 print STDERR " a website. Calls mirror.pl to do the mirroring.\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 print STDERR " -archivedir directory Where the converted material ends up\n";
65}
66
67
68&main ();
69
70sub main {
71 my ($verbosity, $importdir, $archivedir, $builddir, $indexdir, $etcdir,
72 $mirror, $interval, $logfile,
73 $collection, $configfilename, $collectcfg);
74
75 if (!parsargv::parse(\@ARGV,
76 'verbosity/\d+/2', \$verbosity,
77 'importdir/.*/', \$importdir,
78 'archivedir/.*/', \$archivedir )) {
79 &print_usage();
80 die "\n";
81 }
82
83 # get and check the collection name
84 if (($collection = &util::use_collection(@ARGV)) eq "") {
85 &print_usage();
86 die "\n";
87 }
88
89 # check the configuration file for options
90 $configfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc/collect.cfg");
91 if (-e $configfilename) {
92 $collectcfg = &colcfg::read_collect_cfg ($configfilename);
93 if (defined $collectcfg->{'importdir'} && $importdir eq "") {
94 $importdir = $collectcfg->{'importdir'};
95 }
96 if (defined $collectcfg->{'archivedir'} && $archivedir eq "") {
97 $archivedir = $collectcfg->{'archivedir'};
98 }
99 if (defined $collectcfg->{'mirror'}) {
100 $mirror = $collectcfg->{'mirror'};
101 }
102 } else {
103 die "Couldn't find the configuration file $configfilename\n";
104 }
105
106 # fill in the default import and archives directories if none
107 # were supplied, turn all \ into / and remove trailing /
108 $importdir = "$ENV{'GSDLCOLLECTDIR'}/import" if $importdir eq "";
109 $importdir =~ s/[\\\/]+/\//g;
110 $importdir =~ s/\/$//;
111 $archivedir = "$ENV{'GSDLCOLLECTDIR'}/archives" if $archivedir eq "";
112 $archivedir =~ s/[\\\/]+/\//g;
113 $archivedir =~ s/\/$//;
114
115 $indexdir = "$ENV{'GSDLCOLLECTDIR'}/index";
116 $builddir = "$ENV{'GSDLCOLLECTDIR'}/building";
117 $etcdir = "$ENV{'GSDLCOLLECTDIR'}/etc";
118 $logfile = "$etcdir/mirror.log";
119
120 # if there is no mirror information, we're all done
121 if (!defined($mirror)) {
122 print "No mirror command in $configfilename\n";
123 exit;
124 }
125
126 # read the mirror interval
127 if (($#$mirror == 1) && ($$mirror[0] =~ /interval/)){
128 $interval = $$mirror[1];
129 } else {
130 die "Malformed mirror information: use \"mirror interval N\"\n" .
131 "where N is the number of days between mirrors.\n";
132 }
133
134 # make sure there is an import directory
135 if (! -e "$importdir") {
136 &util::mk_dir($importdir);
137 }
138
139 print "archives directory: $archivedir\n";
140 print " import directory: $importdir\n";
141 print " etc directory: $etcdir\n";
142 print " interval: $interval days\n";
143
144 # how many days is it since the last mirror
145 my $seconds = 0;
146 if (-e "$logfile") {
147 my $now = time;
148 my @stats = stat("$logfile");
149 my $then = $stats[9];
150 # calculate the number of days since the last mirror
151 $seconds = $now - $then;
152 }
153 my $days = (($seconds / 3600) / 24);
154
155 # Is it too soon to start mirroring?
156 if (($seconds > 0) && ($interval > $days)) {
157 printf "Mirror not started: only %.1f days have passed\n", $days;
158 exit;
159 }
160
161 # Mirror the remote site
162 open(WLOG, ">$logfile");
163 print WLOG "Starting mirror at " . time . "\n\n";
164
165 my $command = "mirror.pl $collection";
166 print WLOG "Executing: $command\n";
167 print WLOG `$command`;
168
169 # Import the collection
170 print WLOG "\n\nStarting import at " . time . "\n\n";
171 $command = "import.pl -removeold $collection";
172 print WLOG "Executing: $command\n";
173 print WLOG `$command`;
174
175 # Build the collection
176 print WLOG "\n\nStarting buildcol.pl at " . time . "\n\n";
177 $command = "buildcol.pl $collection";
178 print WLOG "Executing: $command\n";
179 print WLOG `$command`;
180
181 # Renaming the building directory to index
182 print WLOG "\n\nRenaming building directory at " . time . "\n\n";
183 if (-e $indexdir) {
184 &util::mv($indexdir, "$indexdir.old");
185 &util::mv($builddir, $indexdir);
186 &util::rm_r ("$indexdir.old");
187 } else {
188 &util::mv($builddir, $indexdir);
189 }
190
191
192 close WLOG;
193
194}
195
196
197
198
199
Note: See TracBrowser for help on using the repository browser.