#!/usr/bin/perl # advxfixconf # Script to fix a module include file # (C) 2001 Jean-Michel Dault <jmdault@mandrakesoft.com> and Mandrakesoft # You can use it under the Apache Licence # The script removes all LoadModule/Addmodule directives from a module # config file (addon-modules/mod_foo.conf) and puts the whole file # between IfDefine's $bakpath="/etc/httpd/conf/bak"; if ((!$ARGV[0]) || (!$ARGV[1]) || (!$ARGV[2]) || (!$ARGV[3])) { print "Usage: $0 <conffile> <mod_filename> <mod_name> \n"; print "<name_module> [OPTIONS]\n"; print "Options:\n"; print " ifmodule will wrap config between <Ifmodule mod_name>\n"; die "\n"; } sub debug{ if ($DEBUG) { foreach (@_) { print $_; } } } $_=$ARGV[1]; s/^.*\///g; s/^mod_//g; s/^lib//g; s/\.so$//g; $modso=$_; $modc=$ARGV[2]; $name_mod=$ARGV[3]; @confparts=split(/\//,$ARGV[0]); if ($#confparts==0) { # debug "confparts=0\n"; $confpath="/etc/httpd/conf"; $conf="$ARGV[0]"; } else { # debug "confparts=$#confparts\n"; $conf="$confparts[$#confparts]"; $confpath=join('/',@confparts[0 .. $#confparts-1]); } system("mkdir -p $bakpath") ==0 or die "Can't create backup directory $bakpath\n"; #debug "Confpath: $confpath\n"; #debug "Conffile: $conf\n"; #debug "Backups: $bakpath\n"; foreach (@ARGV) { if (/ifmodule/i) { $opendef="<IfModule $modc>\n"; $closedef="</IfModule>\n"; debug "##ifmodule $modc##\n"; } } $_=`date +%Y%m%d-%T`;chop;s/:/./g;$dat=$_; $bak="$conf-$dat"; debug "$bak\n"; open(BAK,">$bakpath/$bak") or die "Can't create $bakpath/$bak\n"; open(CONFF,"$confpath/$conf") or die "Can't open $confpath/$conf\n"; while (<CONFF>) { print BAK $_; if (($opendef) && (/^$opendef/i)) { debug "$opendef"; $mysection=1; } if (/^#*LoadModule\s+$name_mod\s+.*$modso/i) { $delline{$.}=1; debug "Deleting Loadmodule at line $.\n"; } if (/^#*AddModule\s+$modc/i) { $delline{$.}=1; debug "Deleting Addmodule at line $.\n"; } } close(CONFF); close(BAK); debug "-----\n"; foreach (sort keys %delline) { debug "Delete line $_="; debug $delline{$_}; debug "\n"; } debug "-----\n"; open(BAK,"$bakpath/$bak") or die "Can't open $bakpath/$bak\n"; open(CONFF,">$confpath/$conf") or die "Can't create $confpath/$conf\n"; if ($mysection!=1) { print CONFF $opendef; } while (<BAK>) { if ($delline{$.}!=1) { print CONFF $_; } } if ($mysection!=1) { print CONFF $closedef; } close(CONFF); close(BAK);