2 ##--------------------------------------------------------------------------##
4 ## $Id: apply-config,v 1.15 2002/10/17 03:14:31 ehood Exp $
6 ## Processes all '.in' template files.
7 ##--------------------------------------------------------------------------##
8 ## Copyright (C) 2002 Earl Hood <earl@earlhood.com>
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.
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.
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
24 ##--------------------------------------------------------------------------##
26 package MHArc
::apply_config
;
28 ##--------------------------------------------------------------------------##
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
34 ##--------------------------------------------------------------------------##
37 my $config = MHArc
::Config
->load("$Dir/../lib/config.sh");
39 ##--------------------------------------------------------------------------##
43 use MHArc
::Util
qw(run_prg usage);
51 my $clstatus = GetOptions
(
53 "distclean!" => \
$distclean,
56 "verbose!" => \
$verbose,
61 usage
(0) unless $clstatus;
65 $verbose = 1 if $debug || $noact;
66 $clean = 1 if $distclean;
67 $MHArc::Util
::ECHO_CMDS
= 1 if ($verbose);
68 $MHArc::Util
::ECHO_ONLY
= 1 if ($noact);
73 $config->dump_config(\
*STDERR
);
77 if ($_ =~ /config\.sh$/ ||
78 $_ =~ /config\.sh\.in$/ ||
79 $_ =~ /config\.sh\.dist$/ ||
80 $_ =~ /config\.sh\.in\.dist$/) {
81 print qq/Skipping config file "$File::Find::name"\n/ if $debug;
84 if (-d
$_ && ($_ =~ /RCS$/ || $_ =~ /CVS$/ || $_ =~ /SCCS$/)) {
85 print qq/Pruning "$File::Find::name"\n/ if $debug;
86 $File::Find
::prune
= 1;
89 if (-d
$_ || !/\.in(?:\.dist)?$/o) {
90 print qq/Ignoring "$File::Find::name"\n/ if $debug;
93 if ($done{$File::Find
::name
}) {
94 print qq/Skipping "$File::Find::name", already processed.\n/
100 print qq/Checking "$File::Find::name"...\n/ if $debug;
101 if ($file =~ s/\.dist$//) {
104 run_prg
('/bin/cp', $_, $file);
105 run_prg
('/bin/chmod', 'u+w', $file);
108 $done{$File::Find
::name
} = 1;
109 $done{"$File::Find::dir/$file"} = 1;
112 my $file_out = $file;
113 $file_out =~ s/\.in$//;
116 run_prg
('/bin/rm', $file_out) if (-e
$file_out);
117 run_prg
('/bin/rm', $file) if ($distclean && (-e
$file) &&
122 print qq|Processing
"$File::Find::dir/$file"\n| if $verbose;
126 die qq|ERROR
: Unable to
open "$File::Find::dir/$file": $!\n|;
127 open(OUT
, ">$file_out") ||
128 die qq|ERROR
: Unable to create
"$File::Find::dir/$file_out": $!\n|;
131 while (defined($line = <IN
>)) {
132 $line =~ s/\@\@([^@]*)\@\@/$config->{$1}/g;
138 run_prg
('/bin/chmod', 'a+x,go-w', $file_out);
144 my $home = $config->{'SW_ROOT'};
145 $home = "$Dir/.." unless $home;
149 foreach $dir ($config->{'HTML_DIR'},
150 $config->{'CGI_DIR'},
151 $config->{'MBOX_DIR'},
152 $config->{'INFO_DIR'},
153 $config->{'MKNMZ_TMPL_DIR'}) {
155 next unless $dir =~ /\S/;
157 warn qq/Warning: "$dir" does not exist\n/;
161 if ($dir !~ /^\Q$home\E\//o
) {
167 find
(\
&wanted
, @ARGV);
169 ##--------------------------------------------------------------------------##
174 apply-config - Process input template files based upon configuration settings.
178 apply-config [options] [dir ...]
182 This program processes input template files and expands variables
183 referenced to values specified in C<E<lt>mharc-rootE<gt>/lib/config.sh>.
185 Template files are designated by the C<.in> filename extentions. For a
186 given file, if C<I<file>.in.dist> exists and C<I<file>.in> does not,
187 C<I<file>.in.dist> will be copied to C<I<file>.in> before processing.
189 Variable references in template files are denoted as follows:
193 If the specified variable name is defined, the reference will be
194 replaced with the empty string.
198 Any non-option arguments are treated as directories to recursively
199 scan for template files. If no directories are specified, then
200 C<$SW_ROOT> is used as defined in C<E<lt>mharc-rootE<gt>/lib/config.sh>.
206 Remove all files that have a C<.in> version. This option is useful
207 to clean up all files generated from templates.
211 Remove all files that have a C<.in> version and remove all C<.in>
212 files that have a C<.in.dist> version. This option is useful to
213 clean up all files for generating a distribution bundle.
215 B<WARNING:> Use this option with care since it will delete all
216 customized versions of C<.in> templates. This option is mainly
217 for use by mharc developers.
221 Print out alot of information on what is going on. This options
222 prints out more information than C<-verbose>.
226 Just echo what would be done, but do not do it.
230 Echo out status on any operation that modifies files.
238 =item C<E<lt>mharc-rootE<gt>/lib/config.sh>
240 Configuration file defining variables values.
246 C<$Id: apply-config,v 1.15 2002/10/17 03:14:31 ehood Exp $>
250 Earl Hood, earl@earlhood.com
252 This program is part of the mharc archiving system and comes with
253 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
254 the GNU General Public License, which may be found in the mhArc