[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Need for the same set of commands for Insert as well as Append
From: |
Marco van Beek |
Subject: |
Need for the same set of commands for Insert as well as Append |
Date: |
Sun, 30 Oct 2005 20:19:12 +0000 |
User-agent: |
Mozilla Thunderbird 1.0.7 (Windows/20050923) |
Hi All,
I think there is a need for the same sort of flexibility that the
AppendIf... commands within editfiles gives us, but as an insert, so
that they can be specified in an exact place.
I am modifying shorewall config files which require a final line that
says "THIS IS THE LAST LINE". I need to place all my edits above this
line, and ideally what I would do is to use InsertFromFileIfNoSuchLines,
or an InsertIfNoSuchLine "ThisLine" in a ForEachLineIn loop.
I could use the standard append commands, and then locate the "last"
line, delete and then append it, but that isn't exactly tidy or
necessarily reliable, as I would have to run it in a separate loop under
a separate class defined by first loop.
The only other way I can think of doing it is to nest a group and a group:
{
/file-to-be-edited
ForEachLineIn "data-file"
BeginGroupIfNoSuchLine "ThisLine"
EmptyEntireFilePlease
Append "# File Header & Comments"
InsertFile "datafile"
Append "# THIS IS THE LAST LINE"
EndGroup
EndLoop
DefineClasses "restart_shorewall"
}
Since the first none match would cause the whole file to be re-written,
subsequent lines would always find a match, but I would guess there are
two problems with this:
1) ThisLine might not be a valid variable for BeginGroupIfNoSuchLine
2) ForEachLineIn doesn't allow nested loops, so does it allow a nested
group?
If the above code works (by the way does ThisLine need " or '' or ``?
The manual is a little unclear), then all well and good, but if not, I
am going to have to work out another way of doing it. There is an
INCLUDE option within shorewall that may allow me to have a much simpler
file to edit, but having an InsertIf.. set of commands may be a worthy
addition to CFEngine. Just don't ask me to write it, I wouldn't know
where to start. ;)
Regards,
Marco van Beek
- Need for the same set of commands for Insert as well as Append,
Marco van Beek <=