17c478bd9Sstevel@tonic-gate#! /bin/sh
27c478bd9Sstevel@tonic-gate
37c478bd9Sstevel@tonic-gate# Set a default boot entry for GRUB
47c478bd9Sstevel@tonic-gate#   Copyright (C) 2004 Free Software Foundation, Inc.
57c478bd9Sstevel@tonic-gate#
67c478bd9Sstevel@tonic-gate# This file is free software; you can redistribute it and/or modify it
77c478bd9Sstevel@tonic-gate# under the terms of the GNU General Public License as published by
87c478bd9Sstevel@tonic-gate# the Free Software Foundation; either version 2 of the License, or
97c478bd9Sstevel@tonic-gate# (at your option) any later version.
107c478bd9Sstevel@tonic-gate#
117c478bd9Sstevel@tonic-gate# This program is distributed in the hope that it will be useful, but
127c478bd9Sstevel@tonic-gate# WITHOUT ANY WARRANTY; without even the implied warranty of
137c478bd9Sstevel@tonic-gate# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147c478bd9Sstevel@tonic-gate# General Public License for more details.
157c478bd9Sstevel@tonic-gate#
167c478bd9Sstevel@tonic-gate# You should have received a copy of the GNU General Public License
177c478bd9Sstevel@tonic-gate# along with this program; if not, write to the Free Software
187c478bd9Sstevel@tonic-gate# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
197c478bd9Sstevel@tonic-gate
207c478bd9Sstevel@tonic-gate# Initialize some variables.
217c478bd9Sstevel@tonic-gatePACKAGE=@PACKAGE@
227c478bd9Sstevel@tonic-gateVERSION=@VERSION@
237c478bd9Sstevel@tonic-gate
247c478bd9Sstevel@tonic-gaterootdir=
257c478bd9Sstevel@tonic-gateentry=
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate# Usage: usage
287c478bd9Sstevel@tonic-gate# Print the usage.
297c478bd9Sstevel@tonic-gateusage () {
307c478bd9Sstevel@tonic-gate    cat <<EOF
317c478bd9Sstevel@tonic-gateUsage: grub-set-default [OPTION] entry
327c478bd9Sstevel@tonic-gateSet the default boot entry for GRUB.
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate  -h, --help              print this message and exit
357c478bd9Sstevel@tonic-gate  -v, --version           print the version information and exit
367c478bd9Sstevel@tonic-gate  --root-directory=DIR    Use the directory DIR instead of the root directory
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gateENTRY is a number or the special keyword \`default\'.
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gateReport bugs to <bug-grub@gnu.org>.
417c478bd9Sstevel@tonic-gateEOF
427c478bd9Sstevel@tonic-gate}
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate# Check the arguments.
457c478bd9Sstevel@tonic-gatefor option in "$@"; do
467c478bd9Sstevel@tonic-gate    case "$option" in
477c478bd9Sstevel@tonic-gate    -h | --help)
487c478bd9Sstevel@tonic-gate	usage
497c478bd9Sstevel@tonic-gate	exit 0 ;;
507c478bd9Sstevel@tonic-gate    -v | --version)
517c478bd9Sstevel@tonic-gate	echo "grub-set-default (GNU GRUB ${VERSION})"
527c478bd9Sstevel@tonic-gate	exit 0 ;;
537c478bd9Sstevel@tonic-gate    --root-directory=*)
547c478bd9Sstevel@tonic-gate	rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
557c478bd9Sstevel@tonic-gate    -*)
567c478bd9Sstevel@tonic-gate	echo "Unrecognized option \`$option'" 1>&2
577c478bd9Sstevel@tonic-gate	usage
587c478bd9Sstevel@tonic-gate	exit 1
597c478bd9Sstevel@tonic-gate	;;
607c478bd9Sstevel@tonic-gate    *)
617c478bd9Sstevel@tonic-gate	if test "x$entry" != x; then
627c478bd9Sstevel@tonic-gate	    echo "More than one entries?" 1>&2
637c478bd9Sstevel@tonic-gate	    usage
647c478bd9Sstevel@tonic-gate	    exit 1
657c478bd9Sstevel@tonic-gate	fi
667c478bd9Sstevel@tonic-gate	# We don't care about what the user specified actually.
677c478bd9Sstevel@tonic-gate	entry="${option}" ;;
687c478bd9Sstevel@tonic-gate    esac
697c478bd9Sstevel@tonic-gatedone
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gateif test "x$entry" = x; then
727c478bd9Sstevel@tonic-gate    echo "entry not specified." 1>&2
737c478bd9Sstevel@tonic-gate    usage
747c478bd9Sstevel@tonic-gate    exit 1
757c478bd9Sstevel@tonic-gatefi
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate# Determine the GRUB directory. This is different among OSes.
787c478bd9Sstevel@tonic-gategrubdir=${rootdir}/boot/grub
797c478bd9Sstevel@tonic-gateif test -d ${grubdir}; then
807c478bd9Sstevel@tonic-gate    :
817c478bd9Sstevel@tonic-gateelse
827c478bd9Sstevel@tonic-gate    grubdir=${rootdir}/grub
837c478bd9Sstevel@tonic-gate    if test -d ${grubdir}; then
847c478bd9Sstevel@tonic-gate	:
857c478bd9Sstevel@tonic-gate    else
867c478bd9Sstevel@tonic-gate	echo "No GRUB directory found under ${rootdir}/" 1>&2
877c478bd9Sstevel@tonic-gate	exit 1
887c478bd9Sstevel@tonic-gate    fi
897c478bd9Sstevel@tonic-gatefi
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gatefile=${grubdir}/default
927c478bd9Sstevel@tonic-gateif test -f ${file}; then
937c478bd9Sstevel@tonic-gate    chmod 0600 ${file}
947c478bd9Sstevel@tonic-gate    rm -f ${file}
957c478bd9Sstevel@tonic-gatefi
967c478bd9Sstevel@tonic-gatecat <<EOF > $file
977c478bd9Sstevel@tonic-gate$entry
987c478bd9Sstevel@tonic-gate#
997c478bd9Sstevel@tonic-gate#
1007c478bd9Sstevel@tonic-gate#
1017c478bd9Sstevel@tonic-gate#
1027c478bd9Sstevel@tonic-gate#
1037c478bd9Sstevel@tonic-gate#
1047c478bd9Sstevel@tonic-gate#
1057c478bd9Sstevel@tonic-gate#
1067c478bd9Sstevel@tonic-gate#
1077c478bd9Sstevel@tonic-gate#
1087c478bd9Sstevel@tonic-gate# WARNING: If you want to edit this file directly, do not remove any line
1097c478bd9Sstevel@tonic-gate# from this file, including this warning. Using \`grub-set-default\' is
1107c478bd9Sstevel@tonic-gate# strongly recommended.
1117c478bd9Sstevel@tonic-gateEOF
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate# Bye.
1147c478bd9Sstevel@tonic-gateexit 0
115