The Shellvars_list stock lens comes close to providing what I needed.
Given a file such as
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=vgroot/lvswap rd.lvm.lv=vgroot/lvroot"
GRUB_DISABLE_RECOVERY="true"
I want to append arbitrary values in an idempotent way to GRUB_CMDLINE_LINUX. This lens parses this file as follows:
augtool> print $v
/files/home/c14027/default-grub-sample
/files/home/c14027/default-grub-sample/GRUB_TIMEOUT
/files/home/c14027/default-grub-sample/GRUB_TIMEOUT/quote = ""
/files/home/c14027/default-grub-sample/GRUB_TIMEOUT/value = "5"
/files/home/c14027/default-grub-sample/GRUB_DEFAULT
/files/home/c14027/default-grub-sample/GRUB_DEFAULT/quote = ""
/files/home/c14027/default-grub-sample/GRUB_DEFAULT/value = "saved"
/files/home/c14027/default-grub-sample/GRUB_DISABLE_SUBMENU
/files/home/c14027/default-grub-sample/GRUB_DISABLE_SUBMENU/quote = ""
/files/home/c14027/default-grub-sample/GRUB_DISABLE_SUBMENU/value = "true"
/files/home/c14027/default-grub-sample/GRUB_TERMINAL_OUTPUT
/files/home/c14027/default-grub-sample/GRUB_TERMINAL_OUTPUT/quote = "\""
/files/home/c14027/default-grub-sample/GRUB_TERMINAL_OUTPUT/value = "console"
/files/home/c14027/default-grub-sample/GRUB_CMDLINE_LINUX
/files/home/c14027/default-grub-sample/GRUB_CMDLINE_LINUX/quote = "\""
/files/home/c14027/default-grub-sample/GRUB_CMDLINE_LINUX/value[1] = "crashkernel=auto"
/files/home/c14027/default-grub-sample/GRUB_CMDLINE_LINUX/value[2] = "rd.lvm.lv=vgroot/lvsap"
/files/home/c14027/default-grub-sample/GRUB_CMDLINE_LINUX/value[3] = "rd.lvm.lv=vgroot/lvroot"
/files/home/c14027/default-grub-sample/GRUB_DISABLE_RECOVERY
/files/home/c14027/default-grub-sample/GRUB_DISABLE_RECOVERY/quote = "\""
/files/home/c14027/default-grub-sample/GRUB_DISABLE_RECOVERY/value = "true"
We'll do a defvar in augtool so that $v represents our prefix.
Add a new value to this CMDLINE paramater:
set $v/GRUB_CMDLINE_LINUX/value[last()+1] test=142
Remove existing ones:
rm $v/GRUB_CMDLINE_LINUX/value[. =~ regexp("^test=.*")]
Replace the key-pair whose key is test=:
set $v/GRUB_CMDLINE_LINUX/value[. =~ regexp("^test=.*")] test=1234