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 <javierm@redhat.com>
This commit is contained in:
Javier Martinez Canillas 2018-11-23 01:22:56 +01:00
parent 4b1d63cacd
commit b84a214b99
No known key found for this signature in database
GPG Key ID: C751E590D63F3D69

View File

@ -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]}"