xref: /titanic_50/usr/src/grub/grub-0.97/util/grub-set-default.in (revision 495db6fbcd9e8ab893e91f6f5627df6e0cec63cf)
1#! /bin/sh
2
3# Set a default boot entry for GRUB
4#   Copyright (C) 2004 Free Software Foundation, Inc.
5#
6# This file is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20# Initialize some variables.
21PACKAGE=@PACKAGE@
22VERSION=@VERSION@
23
24rootdir=
25entry=
26
27# Usage: usage
28# Print the usage.
29usage () {
30    cat <<EOF
31Usage: grub-set-default [OPTION] entry
32Set the default boot entry for GRUB.
33
34  -h, --help              print this message and exit
35  -v, --version           print the version information and exit
36  --root-directory=DIR    Use the directory DIR instead of the root directory
37
38ENTRY is a number or the special keyword \`default\'.
39
40Report bugs to <bug-grub@gnu.org>.
41EOF
42}
43
44# Check the arguments.
45for option in "$@"; do
46    case "$option" in
47    -h | --help)
48	usage
49	exit 0 ;;
50    -v | --version)
51	echo "grub-set-default (GNU GRUB ${VERSION})"
52	exit 0 ;;
53    --root-directory=*)
54	rootdir=`echo "$option" | sed 's/--root-directory=//'` ;;
55    -*)
56	echo "Unrecognized option \`$option'" 1>&2
57	usage
58	exit 1
59	;;
60    *)
61	if test "x$entry" != x; then
62	    echo "More than one entries?" 1>&2
63	    usage
64	    exit 1
65	fi
66	# We don't care about what the user specified actually.
67	entry="${option}" ;;
68    esac
69done
70
71if test "x$entry" = x; then
72    echo "entry not specified." 1>&2
73    usage
74    exit 1
75fi
76
77# Determine the GRUB directory. This is different among OSes.
78grubdir=${rootdir}/boot/grub
79if test -d ${grubdir}; then
80    :
81else
82    grubdir=${rootdir}/grub
83    if test -d ${grubdir}; then
84	:
85    else
86	echo "No GRUB directory found under ${rootdir}/" 1>&2
87	exit 1
88    fi
89fi
90
91file=${grubdir}/default
92if test -f ${file}; then
93    chmod 0600 ${file}
94    rm -f ${file}
95fi
96cat <<EOF > $file
97$entry
98#
99#
100#
101#
102#
103#
104#
105#
106#
107#
108# WARNING: If you want to edit this file directly, do not remove any line
109# from this file, including this warning. Using \`grub-set-default\' is
110# strongly recommended.
111EOF
112
113# Bye.
114exit 0
115