document branches better
[mharc.git] / bin / gc-search-indexes
CommitLineData
2ea8f66b
IK
1#!/usr/bin/perl
2##--------------------------------------------------------------------------##
3## File:
4## $Id: gc-search-indexes,v 1.6 2002/09/15 03:33:08 ehood Exp $
5## Description:
6## Script to do garbage collection on Namazu search indexes.
7##--------------------------------------------------------------------------##
8## Copyright (C) 2001-2002 Earl Hood <earl@earlhood.com>
9##
10## This program is free software; you can redistribute it and/or modify
11## it under the terms of the GNU General Public License as published by
12## the Free Software Foundation; either version 2 of the License, or
13## (at your option) any later version.
14##
15## This program is distributed in the hope that it will be useful,
16## but WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18## GNU General Public License for more details.
19##
20## You should have received a copy of the GNU General Public License
21## along with this program; if not, write to the Free Software
22## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23## 02111-1307, USA
24##--------------------------------------------------------------------------##
25
26package MHArc::compress_mboxes;
27
28##--------------------------------------------------------------------------##
29# <x-boot-strap>
30BEGIN { die qq/CGI use FORBIDDEN!\n/ if (defined($ENV{'GATEWAY_INTERFACE'})); }
31my $Dir; BEGIN { $Dir = `dirname $0`; chomp $Dir; }
32use lib "$Dir/../lib"; # Add relative lib to search path
33# </x-boot-strap>
34##--------------------------------------------------------------------------##
35# <x-config>
36use MHArc::Config;
37my $config = MHArc::Config->load("$Dir/../lib/config.sh");
38# </x-config>
39##--------------------------------------------------------------------------##
40
41
42use Getopt::Long;
43use MHArc::Util qw( cmd usage );
44
45MAIN: {
46 my %opt = ( );
47 my $clstatus = GetOptions(\%opt,
48 "debug!",
49 "n!",
50
51 'help',
52 'man'
53 );
54 usage(0) unless $clstatus;
55 usage(1) if $opt{'help'};
56 usage(2) if $opt{'man'};
57
58 my $debug = $opt{'debug'};
59 my $noact = $opt{'n'};
60
61 $ENV{'PATH'} = join(':', join('/', $config->{'SW_ROOT'}, 'bin'),
62 '/usr/local/bin',
63 '/bin',
64 '/usr/bin');
65
66 $MHArc::Util::ECHO_CMDS = $noact || $debug;
67 $MHArc::Util::ECHO_ONLY = $noact;
68
69 print "PATH=$ENV{'PATH'}\n" if $debug;
70
71 # Sanity check on $HTML_DIR
72 my $html_dir = $config->{'HTML_DIR'};
73 if (! -d $html_dir) {
74 die qq/ERROR: "/, $html_dir, qq/" is not a directory!/;
75 }
76 print qq/HTML_DIR=$html_dir\n/ if $debug;
77
78 # Get list of possible directories
79 opendir(HTML_DIR, $html_dir) ||
80 die qq/ERROR: Unable to open "$html_dir" for reading: $!\n/;
81 my @dirs = map { "$html_dir/$_" }
82 grep { ($_ ne '.') &&
83 ($_ ne '..') &&
84 (-d "$html_dir/$_") &&
85 (-e "$html_dir/$_/NMZ.t") } readdir(HTML_DIR);
86
87 # Check that we have something to do
88 if (!scalar(@dirs)) {
89 print "No search indexes found\n" if $debug;
90 exit 0;
91 }
92 print "Searchable directories:\n\t",
93 join("\n\t", @dirs), "\n" if $debug;
94
95 # Run garbage collection
96 my @cmd_args = ( '-b' );
97 if ($debug) {
98 push(@cmd_args, '-v');
99 } else {
100 push(@cmd_args, '-q');
101 }
102 foreach (@dirs) {
103 if (cmd('gcnmz', @cmd_args, $_) != 0) {
104 warn qq/Warning: Command "gcnmz @cmd_args $_" failed: $?\n/;
105 }
106 }
107
108} # End: MAIN
109
110##---------------------------------------------------------------------------##
111__END__
112
113=head1 NAME
114
115gc-search-indexes - Garbage collect archive search indexes.
116
117=head1 SYNOPSIS
118
119 gc-search-indexes
120 gc-search-indexes [options]
121
122=head1 DESCRIPTION
123
124This program is part of mharc, and has the responsibility of performing
125garbage collection on archive search indexes.
126
127Generally, this program will be invoked automatically from C<cron>
128on a periodic basis.
129
130This program will use the C<HTML_DIR> variable from
131C<E<lt>mharc-rootE<gt>/lib/config.sh> as the root directory to search for
132searchable archives.
133
134=head1 OPTIONS
135
136=over
137
138=item C<-debug>
139
140Print out alot of information on what is going on.
141
142=item C<-help>
143
144Print out usage information.
145
146=item C<-n>
147
148Print the commands that would be executed, but do not execute them.
149
150=item C<-man>
151
152Print out manpage.
153
154=back
155
156=head1 FILES
157
158=over
159
160=item C<E<lt>mharc-rootE<gt>/lib/config.sh>
161
162Main configuration file for mharc.
163
164=back
165
166=head1 NOTES
167
168=over
169
170=item *
171
172This program should be invoked occasionally, like once a week. The
173template crontab provided with mharc provides a useful crontab entry
174for invoking this program.
175
176=back
177
178=head1 VERSION
179
180$Id: gc-search-indexes,v 1.6 2002/09/15 03:33:08 ehood Exp $
181
182=head1 AUTHOR
183
184Earl Hood, earl@earlhood.com
185
186This program is part of the mharc archiving system and comes with
187ABSOLUTELY NO WARRANTY and may be copied only under the terms of
188the GNU General Public License, which may be found in the mharc
189distribution.
190
191=cut
192