Code: Select all
#! /bin/sh -e
# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
# Parse the grub config for linux kernels
# and choose preferred kernel by name as default.
# Caution! If there is no version string in the name available,
# you have to add a space, e.g. like this "vmlinuz ".
# Example: GRUB_PREFERRED_KERNEL="vmlinuz-huge-smp-testing-2.6.31.5-smp"
. /etc/default/grub
cfg="/boot/grub/grub.cfg"
declare -i preferred=`grep "linux" $cfg | grep -m1 -n "$GRUB_PREFERRED_KERNEL" | awk 'BEGIN {FS = ":"} {print $1}'`
if [ $preferred > 1 ] ; then
declare -i preferred_default=$preferred-2
echo "Changing default to preferred '$GRUB_PREFERRED_KERNEL' = $preferred_default" >&2
sed -e "s/^set default=[0-9]*$/set default=$preferred_default/" $cfg > $cfg.new ;
mv $cfg.new $cfg
fi