$darkmode
Elektra 0.11.0
Plugin: blockresolver

The blockresolver can be used to only resolve a tagged block inside a configuration file.

Installation

See installation. The package is called libelektra5-experimental.

Implementation Details

blockresolver extracts the requested block from the configurations file and writes it into a temporary file. Afterwards Elektra will only work on the temporary file until kdbSet is called. On kdbSet the contents of the temporary file will be merged with parts outside of the requested block from the original file.

Usage

`kdb mount -R blockresolver /path/to/my/file /mountpoint -c identifier="identifier-tag"`

where identifier specifies the tag blockresolver will search for in the configuration file.

A block consists of 2 parts:

Limitations

Currently the identifier must be unique.

Example

1 # Backup-and-Restore: system:/tests/blockresolver
2 
3 # create testfile
4 kdb set system:/tests/blockfile $(mktemp)
5 echo 'text' > $(kdb get system:/tests/blockfile)
6 echo 'more text' >> $(kdb get system:/tests/blockfile)
7 echo 'some more text' >> $(kdb get system:/tests/blockfile)
8 echo '>>> block config start' >> $(kdb get system:/tests/blockfile)
9 echo 'key1=val1' >> $(kdb get system:/tests/blockfile)
10 echo '>>> block config stop' >> $(kdb get system:/tests/blockfile)
11 echo 'text again' >> $(kdb get system:/tests/blockfile)
12 echo 'and more text' >> $(kdb get system:/tests/blockfile)
13 echo 'text' >> $(kdb get system:/tests/blockfile)
14 
15 sudo kdb mount -R blockresolver $(kdb get system:/tests/blockfile) system:/tests/blockresolver -c identifier=">>> block config" mini
16 
17 # check testfile
18 cat $(kdb get system:/tests/blockfile)
19 #> text
20 #> more text
21 #> some more text
22 #> >>> block config start
23 #> key1=val1
24 #> >>> block config stop
25 #> text again
26 #> and more text
27 #> text
28 
29 # only the block between the tags is read!
30 kdb export system:/tests/blockresolver mini
31 # STDOUT-REGEX: key1.*=.*val1
32 
33 # add a new key to the resolved block
34 kdb set system:/tests/blockresolver/key12 val12
35 
36 cat $(kdb get system:/tests/blockfile)
37 #> text
38 #> more text
39 #> some more text
40 #> >>> block config start
41 #> key1=val1
42 #> key12=val12
43 #> >>> block config stop
44 #> text again
45 #> and more text
46 #> text
47 
48 # cleanup
49 kdb rm -r system:/tests/blockresolver
50 rm $(kdb get system:/tests/blockfile)
51 kdb rm system:/tests/blockfile
52 sudo kdb umount system:/tests/blockresolver