A lente de estoque Shellvars_list
chega perto de fornecer o que eu precisava.
Dado um arquivo como
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"
Eu quero acrescentar valores arbitrários de maneira idempotente a GRUB_CMDLINE_LINUX
. Esta lente analisa este arquivo da seguinte forma:
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"
Faremos um defvar
no augtool para que $v
represente nosso prefixo.
Adicione um novo valor a este CMDLINE
paramater:
set $v/GRUB_CMDLINE_LINUX/value[last()+1] test=142
Remova os existentes:
rm $v/GRUB_CMDLINE_LINUX/value[. =~ regexp("^test=.*")]
Substitua o par de chaves cuja chave é test=
:
set $v/GRUB_CMDLINE_LINUX/value[. =~ regexp("^test=.*")] test=1234