From b84a214b99e1b6c7585e91fb291f15dfb1cd5da1 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Fri, 23 Nov 2018 01:22:56 +0100 Subject: [PATCH] grubby-bls: expand kernel options if these are environment variables The grub2 bootloader allows the BLS snippets fields to contain environment variables instead of constants. This is useful for example to define the kernel command line parameters only once in the grubenv file and set this variable in the BLS snippets. But this can be confusing for users when the information is printed by the grubby script, so expand the variables if they can be looked up in grubenv. Resolves: rhbz#1649785 Signed-off-by: Javier Martinez Canillas --- grubby-bls | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/grubby-bls b/grubby-bls index c9bf226..1e6a9e5 100755 --- a/grubby-bls +++ b/grubby-bls @@ -216,6 +216,20 @@ get_prefix() { fi } +expand_var() { + local var=$1 + + if [[ $bootloader == "grub2" ]]; then + local value="$(grub2-editenv "${env}" list | grep ${var##$} | sed -e "s/${var##$}=//")" + value="$(echo ${value} | sed -e 's/\//\\\//g')" + if [[ -n $value ]]; then + var="$value" + fi + fi + + echo $var +} + display_info_values() { local indexes=($(param_to_indexes "$1")) local prefix=$(get_prefix) @@ -226,9 +240,19 @@ display_info_values() { for i in ${indexes[*]}; do local root="" + local value="" local args=${bls_options[$i]} local opts=(${args}) + for opt in ${opts[*]}; do + if [[ $opt =~ ^\$ ]]; then + value="$(expand_var $opt)" + args="$(echo ${args} | sed -e "s/${opt}/${value}/")" + fi + done + + local opts=(${args}) + for opt in ${opts[*]}; do if echo $opt | grep -q "^root="; then root="$(echo $opt | sed -e 's/root=//')" @@ -443,7 +467,7 @@ update_args() { get_bls_args() { if [[ $bootloader = "grub2" && "${bls_options[$i]}" = "\$kernelopts" ]]; then - old_args=$(grub2-editenv list | grep kernelopts) + old_args=$(grub2-editenv "${env}" list | grep kernelopts) old_args="${old_args##kernelopts=}" else old_args="${bls_options[$i]}"