Gentoo Wiki ArchivesGentoo Wiki

TIP_Migrating_Apache2_to_upstream_configuration

Apache2 Series


Main


Modules


Addons & Tunnels


Tips


Configuring


Other

edit

Upgrading

If you have made special changes to a file, you may want to run a diff before overwriting the new file with the old one. If you have not made special changes, it's probably best not to move it.

cd /etc/apache2
mv -i conf/vhosts/* vhosts.d
mv -i conf/modules.d/* modules.d/
cat conf/apache2.conf conf/commonapache2.conf > httpd.old
cp httpd.conf httpd.conf.diffagainst
perl -pi*.backup -e "s/(^|\n)(([^#\n\"']|\".*?\"|'.*?')+){0,1}#.*(\n|$)/if(\$2){\"\$1\$2\n\";\
  }else{"\$1";}/mge" httpd.conf.diffagainst httpd.old
diff httpd.conf.diffagainst httpd.old

The perl command will make in-place-replacements, but make backups to httpd.conf.diffagianst.backup and httpd.old.backup with the contents which were in the files before we tried to get rid of the comments. Just for safety I suggest you copy httpd.conf to httpd.conf.diffagainst before you get rid of the comments in the new file (and thus makes it comparable with the httpd.old with no comments.) The perl command is provided as is, and if you find any error in it, please correct it (documentation below.)


Here I will try to defend the way I've crafted the regular expression. I've split it up with comment lines starting with ##. Note that " and $ is escaped because it is invoked from a shell with "" to allow '. For background information check out man perlre and perhaps http://www.perl.com/doc/FMTEYEWTK/regexps.html.

## Start search/replace regular expression which will replace lines with comments - others not touched
s/
## Match start of string or newline : $1
(^|\n)
## Keep any characters except from #, don't match newline
## anything within  or "" is kept as is (.*? make non-greedy searches) : $2
(([^#\n\"']|\".*?\"|'.*?')+){0,1}
## Match start of comment to newline or end of string (. will not match newline without the s-switch)
#.*(\n|$)
## End search-pattern, start instructions for replacement of matches
/
if(\$2){\"\$1\$2\n\";} else {"\$1";}
## m: multiline, g:run as long as there are more matches and e:evaluate replacement as perl code
/mge


To be deleted in a month or two after official move.

Retrieved from "http://www.gentoo-wiki.info/TIP_Migrating_Apache2_to_upstream_configuration"

Last modified: Thu, 15 Dec 2005 11:03:00 +1100 Hits: 16,308

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.