2

My first Augeas script looks something like:

set /augeas/load/Properties/lens Properties.lns
set /augeas/load/Properties/incl /firstapp/WEB-INF/classes/some.properties
load
set /files/firstapp/WEB-INF/classes/some.properties/PROPERTY_1 "VALUE A"
set /files/firstapp/WEB-INF/classes/some.properties/PROPERTY_2 "VALUE B"
set /files/firstapp/WEB-INF/classes/some.properties/PROPERTY_3 "VALUE C"
save
set /augeas/load/Properties/lens Properties.lns
set /augeas/load/Properties/incl /secondapp/WEB-INF/classes/more.properties
load
set /files/secondapp/WEB-INF/classes/more.properties/PROPERTY_4 "VALUE D"
set /files/secondapp/WEB-INF/classes/more.properties/PROPERTY_5 "VALUE E"
set /files/secondapp/WEB-INF/classes/more.properties/PROPERTY_6 "VALUE F"
save

and I run it with e.g.:

augtool -LeAf adjust-properties.aug -r $WEB_SERVER_ROOT/

Now I wonder whether one could shorten the script by not repeating reoccuring path elements all the time.


Solution

According to this answer I can update my script to e.g.:

transform Properties.lns incl /firstapp/WEB-INF/classes/some.properties
transform Properties.lns incl /secondapp/WEB-INF/classes/more.properties
load
set /augeas/context /files/firstapp/WEB-INF/classes/some.properties
set PROPERTY_1 "VALUE A"
set PROPERTY_2 "VALUE B"
set PROPERTY_3 "VALUE C"
set /augeas/context /files/secondapp/WEB-INF/classes/more.properties
set PROPERTY_4 "VALUE D"
set PROPERTY_5 "VALUE E"
set PROPERTY_6 "VALUE F"
save
Community
  • 1
  • 1
Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106

1 Answers1

2

There's several things you can do.

First, on recent augeas versions, you can use transform instead of the load commands.

Then, you could set /augeas/context to use shorter, relative paths.

Finally, you could declare variables using defvar and reuse them in your path expressions.

raphink
  • 3,625
  • 1
  • 28
  • 39
  • Thanks for these useful hints. I added the updated example script to my question. Variables defined via `defvar` somehow cannot be used as third parameter of `transform`.. – Jens Piegsa Aug 14 '15 at 08:37