2N/A#! /bin/sh
2N/A#
2N/A# Set a default boot entry for GRUB, for the next boot only.
2N/A# Copyright (C) 2004,2009 Free Software Foundation, Inc.
2N/A#
2N/A# GRUB is free software: you can redistribute it and/or modify
2N/A# it under the terms of the GNU General Public License as published by
2N/A# the Free Software Foundation, either version 3 of the License, or
2N/A# (at your option) any later version.
2N/A#
2N/A# GRUB is distributed in the hope that it will be useful,
2N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A# GNU General Public License for more details.
2N/A#
2N/A# You should have received a copy of the GNU General Public License
2N/A# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A
2N/A# Initialize some variables.
2N/Atransform="@program_transform_name@"
2N/A
2N/Aprefix=@prefix@
2N/Aexec_prefix=@exec_prefix@
2N/Abindir=@bindir@
2N/APACKAGE_NAME=@PACKAGE_NAME@
2N/APACKAGE_VERSION=@PACKAGE_VERSION@
2N/A
2N/Aself=`basename $0`
2N/A
2N/Agrub_editenv=${bindir}/`echo grub-editenv | sed ${transform}`
2N/Arootdir=
2N/Abootdir=
2N/Agrubdir=`echo "/@bootdirname@/@grubdirname@" | sed 's,//*,/,g'`
2N/A
2N/A# Usage: usage
2N/A# Print the usage.
2N/Ausage () {
2N/A cat <<EOF
2N/AUsage: $self [OPTION] entry
2N/ASet the default boot entry for GRUB, for the next boot only.
2N/A
2N/A -h, --help print this message and exit
2N/A -v, --version print the version information and exit
2N/A --boot-directory=DIR expect GRUB images under the directory DIR/@grubdirname@
2N/A instead of the $grubdir directory
2N/A
2N/AENTRY is a number or a menu item title.
2N/A
2N/AReport bugs to <bug-grub@gnu.org>.
2N/AEOF
2N/A}
2N/A
2N/Aargument () {
2N/A opt=$1
2N/A shift
2N/A
2N/A if test $# -eq 0; then
2N/A echo "$0: option requires an argument -- '$opt'" 1>&2
2N/A exit 1
2N/A fi
2N/A echo $1
2N/A}
2N/A
2N/A# Check the arguments.
2N/Awhile test $# -gt 0
2N/Ado
2N/A option=$1
2N/A shift
2N/A
2N/A case "$option" in
2N/A -h | --help)
2N/A usage
2N/A exit 0 ;;
2N/A -v | --version)
2N/A echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
2N/A exit 0 ;;
2N/A
2N/A# Accept for compatibility
2N/A --root-directory)
2N/A rootdir=`argument $option "$@"`; shift ;;
2N/A --root-directory=*)
2N/A rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
2N/A
2N/A --boot-directory)
2N/A bootdir=`argument $option "$@"`; shift;;
2N/A --boot-directory=*)
2N/A bootdir=`echo "$option" | sed 's/--boot-directory=//'` ;;
2N/A
2N/A -*)
2N/A echo "Unrecognized option \`$option'" 1>&2
2N/A usage
2N/A exit 1
2N/A ;;
2N/A *)
2N/A if test "x$entry" != x; then
2N/A echo "More than one entry?" 1>&2
2N/A usage
2N/A exit 1
2N/A fi
2N/A entry="${option}" ;;
2N/A esac
2N/Adone
2N/A
2N/Aif test "x$entry" = x; then
2N/A echo "entry not specified." 1>&2
2N/A usage
2N/A exit 1
2N/Afi
2N/A
2N/Aif [ -z "$bootdir" ]; then
2N/A # Default bootdir if bootdir not initialized.
2N/A bootdir=/@bootdirname@
2N/A
2N/A if [ -n "$rootdir" ] ; then
2N/A # Initialize bootdir if rootdir was initialized.
2N/A bootdir=${rootdir}/@bootdirname@
2N/A fi
2N/Afi
2N/A
2N/Agrubdir=`echo "${bootdir}/@grubdirname@" | sed 's,//*,/,g'`
2N/A
2N/Aprev_saved_entry=`$grub_editenv ${grubdir}/grubenv list | sed -n 's/^saved_entry=//p'`
2N/Aif [ "$prev_saved_entry" ]; then
2N/A $grub_editenv ${grubdir}/grubenv set prev_saved_entry="$prev_saved_entry"
2N/Aelse
2N/A # We need some non-empty value for prev_saved_entry so that GRUB will
2N/A # recognise that grub-reboot has been used and restore the previous
2N/A # saved entry. "0" is the same as an empty value, i.e. the first menu
2N/A # entry.
2N/A $grub_editenv ${grubdir}/grubenv set prev_saved_entry=0
2N/Afi
2N/A$grub_editenv ${grubdir}/grubenv set saved_entry="$entry"
2N/A
2N/A# Bye.
2N/Aexit 0