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

Re: [augeas-devel] Augeas config help



[ taking this on-list ]

Hi Adam,

On Tue, 2010-01-05 at 15:35 -0500, Adam Stokes wrote:
> I have a question on how to update a commented config item so that it
> will be uncommented once saved:
> 
> in /etc/sysconfig/nfs you'll see that all config items are commented e.g.
> 
> #MOUNTD_PORT=892
> 
> Manually uncommenting those and altering it with augeas is the simple
> part, however, how do I make it so that it will alter the
> configuration item properly so it reads
> 
> MOUNTD_PORT=892
> 
> I am copying and pasting my augeas lens along with test so far, any
> help would be appreciated

The simplest way to do that would be to add some sort of 'commented'
node underneath whatever you parse, so that lines are turned into trees
as follows:

  "MOUNTD_PORT=892\n" -> { "MOUNTD_PORT" = "892" }

  "# MOUNTD_PORT=892\n" -> { "MOUNTD_PORT" = "892" { "commented" } }

That way, you can add and remove the comment marker at the beginning of
the line by adding/removing the "commented" node underneath the setting.

That also means that you'll have to be careful when searching for active
settings in the tree: instead of doing something like

  augtool> match /etc/sysconfig/nfs/MOUNTD_PORT

you'd have to do this

  augtool> match "/etc/sysconfig/nfs/MOUNTD_PORT[ count(commented) = 0 ]"

Here's a rough sketch of what needs to happen:

> (* /etc/sysconfig/nfs - nfs server settings *)
> 
> module NFSserver =
>     autoload xfm
>    
>     let eol         = del /[ \t]*\n/ "\n"
>     let value_sep   = del /[ \t]*=[ \t]*/  " = "
>     let indent      = del /[ \t]*/ ""
>     let empty       = [ label "#empty" . eol ]
>     let comment     = [ label "#comment" . del /#[ \t]*/ "# " .  store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
> 
>     let int_val               = store /[0-9]+/
>     let int_entry (kw:string) = [ key kw . value_sep . int_val ]

Change int_entry to something like

        let int_entry (kw:string) = 
          let marker = [ del /#[ \t]*/ "# " . label "commented" ] in
          [ marker? . key kw . value_sep . int_val ]

The ickier bit is that you'll also have to modify comment, since
commented-out settings will match both int_entry and comment, which
Augeas does not allow.

You'll therefore need to make sure that comment does not match
commented-out settings by changing it to something (untested) like

        let comment     = 
          let settings = /MOUNTD_PORT|LOCKD_TCPPORT|.../ in
          let line_re = /([^ \t\n][^\n]*)?/ - (settings . /[ \t]*=[ \t]*.*/) in
          [ label "#comment" . del /#[ \t]*/ "# " .  store line_re . del /\n/ "\n" ]

The important bit is the line_re which will match anything on a comment
line except for anything that looks like a setting (well, almost; it
matches a little more since it doesn't restrict the values to numbers,
but that's easily fixed)

If you get this to work, I'd be very interested in merging it into the
Shellvars lens; with that, the comment in/out mechanism would be
available for all the /etc/sysconfig files.

>     let mountd_entry    = int_entry "MOUNTD_PORT"
>     let lockd_entry     = int_entry "LOCKD_TCPPORT"
>                         | int_entry "LOCKD_UDPPORT"
>     let statd_entry     = int_entry "STATD_PORT"
>     let rquotad_entry   = int_entry "RQUOTAD_PORT"
>     
>     let entry = mountd_entry
>                 | lockd_entry
>                 | statd_entry
>                 | rquotad_entry
>     
>     let record = indent . entry . eol
>     
>     let lns = ( record | comment | empty ) *
> 
>     let filter = incl "/etc/sysconfig/nfs"
>                . Util.stdexcl
>               
>     let xfm = transform lns filter
> 
> Test file
> 
> (* nfs server settings test *)
> module Test_nfsserver =
>     let conf ="# Port rpc.mountd should listen on.
> MOUNTD_PORT=892
> "
> 
>     test NFSserver.lns get conf =
>         { "#comment" = "Port rpc.mountd should listen on." }
>         { "MOUNTD_PORT" = "892" }
> 
> 
> Thanks,




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