| 1 | #!/usr/bin/perl |
| 2 | ##--------------------------------------------------------------------------## |
| 3 | ## File: |
| 4 | ## $Id: compress-mboxes,v 1.8 2002/09/15 03:33:08 ehood Exp $ |
| 5 | ## Description: |
| 6 | ## Script to compress older mailbox inorder to save disk space. |
| 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 | |
| 26 | package MHArc::compress_mboxes; |
| 27 | |
| 28 | ##--------------------------------------------------------------------------## |
| 29 | # <x-boot-strap> |
| 30 | BEGIN { die qq/CGI use FORBIDDEN!\n/ if (defined($ENV{'GATEWAY_INTERFACE'})); } |
| 31 | my $Dir; BEGIN { $Dir = `dirname $0`; chomp $Dir; } |
| 32 | use lib "$Dir/../lib"; # Add relative lib to search path |
| 33 | # </x-boot-strap> |
| 34 | ##--------------------------------------------------------------------------## |
| 35 | # <x-config> |
| 36 | use MHArc::Config; |
| 37 | my $config = MHArc::Config->load("$Dir/../lib/config.sh"); |
| 38 | # </x-config> |
| 39 | ##--------------------------------------------------------------------------## |
| 40 | |
| 41 | |
| 42 | use Getopt::Long; |
| 43 | use MHArc::Util qw( exec_prg usage ); |
| 44 | |
| 45 | MAIN: { |
| 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 | $MHArc::Util::ECHO_CMDS = $noact || $debug; |
| 62 | $MHArc::Util::ECHO_ONLY = $noact; |
| 63 | |
| 64 | $ENV{'PATH'} = join(':', join('/', $config->{'SW_ROOT'}, 'bin'), |
| 65 | '/usr/local/bin', |
| 66 | '/bin', |
| 67 | '/usr/bin'); |
| 68 | |
| 69 | # Sanity check on $MBOX_DIR |
| 70 | if (! -d $config->{'MBOX_DIR'}) { |
| 71 | die qq/ERROR: "/, $config->{'MBOX_DIR'}, qq/" is not a directory!/; |
| 72 | } |
| 73 | |
| 74 | # Call compress-files |
| 75 | my @cmd_args = ( |
| 76 | '-mbox-mode', |
| 77 | ); |
| 78 | if ($noact) { |
| 79 | push(@cmd_args, '-n'); |
| 80 | } |
| 81 | if ($debug) { |
| 82 | push(@cmd_args, '-debug'); |
| 83 | } |
| 84 | exec("$Dir/compress-files", @cmd_args, $config->{'MBOX_DIR'}); |
| 85 | die qq/exec @_ failed: $?\n/; |
| 86 | |
| 87 | } # End: MAIN |
| 88 | |
| 89 | ##---------------------------------------------------------------------------## |
| 90 | __END__ |
| 91 | |
| 92 | =head1 NAME |
| 93 | |
| 94 | compress-mboxes - Gzip old raw mailbox files |
| 95 | |
| 96 | =head1 SYNOPSIS |
| 97 | |
| 98 | compress-mboxes |
| 99 | compress-mboxes [options] |
| 100 | |
| 101 | =head1 DESCRIPTION |
| 102 | |
| 103 | This program is part of mharc and has the responsibility of gzipping |
| 104 | mailbox files that have not been modified in over a month to save |
| 105 | disk space. |
| 106 | |
| 107 | Generally, this program will be invoked automatically from C<cron> |
| 108 | on a periodic basis. |
| 109 | |
| 110 | This program will use the C<MBOX_DIR> variable from |
| 111 | C<E<lt>mharc-rootE<gt>/lib/config.sh> as the root directory to search for |
| 112 | mailbox files. Any file matching the following regex, |
| 113 | |
| 114 | ^\d+(?:-\d+)?$ |
| 115 | |
| 116 | is considered to be a mailbox file. |
| 117 | |
| 118 | =head1 OPTIONS |
| 119 | |
| 120 | =over |
| 121 | |
| 122 | =item C<-debug> |
| 123 | |
| 124 | Print out alot of status information. |
| 125 | |
| 126 | =item C<-help> |
| 127 | |
| 128 | Print out usage information. |
| 129 | |
| 130 | =item C<-n> |
| 131 | |
| 132 | Print the commands that would be executed, but do not execute them. |
| 133 | |
| 134 | =item C<-man> |
| 135 | |
| 136 | Print out manpage. |
| 137 | |
| 138 | =back |
| 139 | |
| 140 | =head1 FILES |
| 141 | |
| 142 | =over |
| 143 | |
| 144 | =item C<E<lt>mharc-rootE<gt>/lib/config.sh> |
| 145 | |
| 146 | Main configuration file for mharc. |
| 147 | |
| 148 | =back |
| 149 | |
| 150 | =head1 NOTES |
| 151 | |
| 152 | =over |
| 153 | |
| 154 | =item * |
| 155 | |
| 156 | This program basically invokes L<compress-files|compress-files> with the proper |
| 157 | arguments to do the actual work. |
| 158 | |
| 159 | =back |
| 160 | |
| 161 | =head1 SEE ALSO |
| 162 | |
| 163 | L<compress-files|compress-files> |
| 164 | |
| 165 | =head1 VERSION |
| 166 | |
| 167 | $Id: compress-mboxes,v 1.8 2002/09/15 03:33:08 ehood Exp $ |
| 168 | |
| 169 | =head1 AUTHOR |
| 170 | |
| 171 | Earl Hood, earl@earlhood.com |
| 172 | |
| 173 | This program is part of the mharc archiving system and comes with |
| 174 | ABSOLUTELY NO WARRANTY and may be copied only under the terms of |
| 175 | the GNU General Public License, which may be found in the mharc |
| 176 | distribution. |
| 177 | |
| 178 | =cut |
| 179 | |