[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: best way to express an 'editfiles' idiom?

From: Jamie Wilkinson
Subject: Re: best way to express an 'editfiles' idiom?
Date: Mon, 21 Jul 2003 13:33:44 +1000
User-agent: Mutt/1.5.4i

This one time, at band camp, Daniel Pittman wrote:
>When I manage configuration files with cfengine, I frequently find
>myself wanting to express the following action with 'editfiles':
>  Make every line matching "^Value" equal to "Value foo"

What I do is a little more verbose, and behaves a little differently to your

BeginGroupIfNoLineMatching '^Value.*'
  Append 'Value'
ResetSearch 1
LocateLineMatching '^Value.*'
BeginGroupIfNoMatch '^Value foo$'
  ReplaceLineWith 'Value foo'
ResetSearch 1

This copes with values that exist in the config file but are set
incorrectly, and also doesn't try to modify lines that are already correct
(The BeginGroupIfNoMatch is set to the whole line so that ReplaceLineWith
doesn't do any editing unless necessary).

I have some variations on this for particular config files, some that have
similar values and some that have different structures; it's not elegant but
it works.

There are also issues when the config file uses regex special characters, eg
php and perl files containing program configuration (request tracker and the
horde webmail suite), which can be worked around using a bit of hackery.

I tend to set the 'foo' value in a variable in the control section and use
that variable as $(service_value) (where service is ssh, for example, and
value is some config option, for example, as a way to keep the namespace

I'm contemplating developing some M4 macros to do the hard work of keeping
these config file blocks correct and easy to maintain, but haven't gotten
around to anything like that yet.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]