reimported savedefault by cjwatson and myself

Also-By: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
This commit is contained in:
Colin Watson 2009-11-20 09:41:20 +01:00 committed by Vladimir 'phcoder' Serbinenko
parent cd4f42b0c1
commit 242f0731c7
17 changed files with 315 additions and 2 deletions

View file

@ -39,6 +39,7 @@ else
fi
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@ -250,6 +251,10 @@ fi
# Write device to a variable so we don't have to traverse /dev every time.
grub_device=`$grub_probe --target=device ${grubdir}`
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device ${grub_device}`
if test "x$fs_module" = x -a "x$modules" = x; then

View file

@ -130,6 +130,14 @@ convert_system_path_to_grub_path ()
echo ${drive}${relative_path}
}
save_default_entry ()
{
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then
echo 'saved_entry=${chosen}'
echo 'save_env saved_entry'
fi
}
prepare_grub_to_access_device ()
{
device=$1

104
util/grub-reboot.in Normal file
View file

@ -0,0 +1,104 @@
#! /bin/sh
#
# Set a default boot entry for GRUB, for the next boot only.
# Copyright (C) 2004,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/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] entry
Set the default boot entry for GRUB, for the next boot only.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR expect GRUB images under the directory DIR
instead of the root directory
ENTRY is a number or a menu item title.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$entry" != x; then
echo "More than one entry?" 1>&2
usage
exit 1
fi
entry="${option}" ;;
esac
done
if test "x$entry" = x; then
echo "entry not specified." 1>&2
usage
exit 1
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
grubdir=${bootdir}/`echo grub | sed ${transform}`
prev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
if [ "$prev_saved_entry" ]; then
$grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
else
$grub_editenv ${grubdir}/grubenv unset prev_saved_entry
fi
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
# Bye.
exit 0

99
util/grub-set-default.in Normal file
View file

@ -0,0 +1,99 @@
#! /bin/sh
#
# Set a default boot entry for GRUB.
# Copyright (C) 2004,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/>.
# Initialize some variables.
transform="@program_transform_name@"
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
# Usage: usage
# Print the usage.
usage () {
cat <<EOF
Usage: $0 [OPTION] entry
Set the default boot entry for GRUB.
-h, --help print this message and exit
-v, --version print the version information and exit
--root-directory=DIR expect GRUB images under the directory DIR
instead of the root directory
ENTRY is a number or a menu item title.
Report bugs to <bug-grub@gnu.org>.
EOF
}
# Check the arguments.
for option in "$@"; do
case "$option" in
-h | --help)
usage
exit 0 ;;
-v | --version)
echo "grub-install (GNU GRUB ${PACKAGE_VERSION})"
exit 0 ;;
--root-directory=*)
rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
exit 1
;;
*)
if test "x$entry" != x; then
echo "More than one entry?" 1>&2
usage
exit 1
fi
entry="${option}" ;;
esac
done
if test "x$entry" = x; then
echo "entry not specified." 1>&2
usage
exit 1
fi
# Initialize these directories here, since ROOTDIR was initialized.
case "$host_os" in
netbsd* | openbsd*)
# Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub
# instead of /boot/grub.
grub_prefix=`echo /grub | sed ${transform}`
bootdir=${rootdir}
;;
*)
# Use /boot/grub by default.
bootdir=${rootdir}/boot
;;
esac
grubdir=${bootdir}/`echo grub | sed ${transform}`
$grub_editenv ${grubdir}/grubenv unset prev_saved_entry
$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
# Bye.
exit 0

View file

@ -32,11 +32,19 @@ for i in ${GRUB_PRELOAD_MODULES} ; do
done
if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi
if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi
if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi
if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=640x480 ; fi
cat << EOF
load_env
set default=${GRUB_DEFAULT}
if [ \${prev_saved_entry} ]; then
saved_entry=\${prev_saved_entry}
save_env saved_entry
prev_saved_entry=
save_env prev_saved_entry
fi
EOF
case ${GRUB_TERMINAL_INPUT}:${GRUB_TERMINAL_OUTPUT} in

View file

@ -75,6 +75,7 @@ prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
cat << EOF
multiboot ${kernel} root=device:${GRUB_DEVICE#/dev/}
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
cat << EOF
module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\

View file

@ -39,6 +39,7 @@ kfreebsd_entry ()
args="$4" # not used yet
title="$(gettext "%s, with kFreeBSD %s")"
printf "menuentry \"${title}\" {" ${os} ${version}
save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi

View file

@ -59,6 +59,7 @@ linux_entry ()
title="$(gettext "%s, with Linux %s")"
fi
printf "menuentry \"${title}\" {" ${os} ${version}
save_default_entry | sed -e "s/^/\t/"
if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
fi

View file

@ -73,6 +73,7 @@ for dir in $dirlist ; do
menuentry "$OS" {
EOF
save_default_entry | sed -e 's,^,\t,'
prepare_grub_to_access_device "$dev" | sed 's,^,\t,'
cat << EOF

View file

@ -55,6 +55,7 @@ for OS in ${OSPROBED} ; do
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
EOF
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
case ${LONGNAME} in
@ -113,6 +114,8 @@ EOF
cat << EOF
menuentry "${LONGNAME} (on ${DEVICE})" {
EOF
save_default_entry | sed -e "s/^/\t/"
save_default_entry | sed -e "s/^/\t/"
prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/"
cat << EOF
insmod vbe

View file

@ -34,6 +34,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@ -178,6 +179,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst; do
cp -f $file ${grubdir} || exit 1
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = xfat; then :; else

View file

@ -37,6 +37,7 @@ pkglibdir=${libdir}/`echo ${PACKAGE_TARNAME}/${target_cpu}-${platform} | sed ${t
grub_mkimage=${bindir}/`echo grub-mkelfimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@ -163,6 +164,10 @@ for file in ${pkglibdir}/*.mod ${pkglibdir}/*.lst ; do
cp -f $file ${grubdir} || exit 1
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Create the core image. First, auto-detect the filesystem module.
fs_module=`$grub_probe --target=fs --device-map=${device_map} ${grubdir}`
if test "x$fs_module" = x -a "x$modules" = x; then

View file

@ -38,6 +38,7 @@ grub_setup=${sbindir}/`echo grub-setup | sed ${transform}`
grub_mkimage=${bindir}/`echo grub-mkimage | sed ${transform}`
grub_mkdevicemap=${sbindir}/`echo grub-mkdevicemap | sed ${transform}`
grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
grub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
rootdir=
grub_prefix=`echo /boot/grub | sed ${transform}`
modules=
@ -206,6 +207,10 @@ for file in ${pkglibdir}/*.img; do
cp -f $file ${grubdir} || exit 1
done
if ! test -f ${grubdir}/grubenv; then
$grub_editenv ${grubdir}/grubenv create
fi
# Write device to a variable so we don't have to traverse /dev every time.
grub_device=`$grub_probe --target=device ${grubdir}`