1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
# vim: filetype=sh
# kernel command line customization
# ---------------------------------
# The behavior of the following function is better
# understood with the following example:
#
# $ to_bootarglist quiet rootdelay=3 -quiet rootdelay=2 +break=init
# + quiet
# + rootdelay 3
# - quiet
# + rootdelay 2
# + break init
# $
to_bootarglist()
{
echo $@ | tr ' ' '\n' | tr '=' ' ' | \
sed -e 's/^\([^+-]\)/+\1/g' | sed -e 's/^\(.\)/\1 /g'
}
# The following function allows to generate an appropriate kernel cmdline
# given a set of bootarg definitions.
# For a given bootarg name, last definition provided takes precedence.
# Example:
#
# $ aggregate_kernel_cmdline quiet rootdelay=3 -quiet rootdelay=2 +break=init
# break=init rootdelay=2
# $
aggregate_kernel_cmdline()
{
bootarglist="$(to_bootarglist $@)"
bootargnames="$(echo "$bootarglist" | awk '{print $2}' | sort -u)"
cmdline=""
for bootarg in $bootargnames
do
# last definition of given bootarg takes precedence
set -- $(echo "$bootarglist" | grep -w "$bootarg" | tail -n 1)
if [ "$1" = "+" ] # otherwise ignore this bootarg
then
# ok register this bootarg
if [ -z "$3" ]
then
cmdline="$cmdline $bootarg" # bootarg with no value
else
cmdline="$cmdline $bootarg=$3" # bootarg with value
fi
fi
done
echo $cmdline
}
|