Home | History | Annotate | Download | only in util
      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.
     21 PACKAGE=@PACKAGE@
     22 VERSION=@VERSION@
     23 
     24 rootdir=
     25 entry=
     26 
     27 # Usage: usage
     28 # Print the usage.
     29 usage () {
     30     cat <<EOF
     31 Usage: grub-set-default [OPTION] entry
     32 Set 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 
     38 ENTRY is a number or the special keyword \`default\'.
     39 
     40 Report bugs to <bug-grub (at] gnu.org>.
     41 EOF
     42 }
     43 
     44 # Check the arguments.
     45 for 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
     69 done
     70 
     71 if test "x$entry" = x; then
     72     echo "entry not specified." 1>&2
     73     usage
     74     exit 1
     75 fi
     76 
     77 # Determine the GRUB directory. This is different among OSes.
     78 grubdir=${rootdir}/boot/grub
     79 if test -d ${grubdir}; then
     80     :
     81 else
     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
     89 fi
     90 
     91 file=${grubdir}/default
     92 if test -f ${file}; then
     93     chmod 0600 ${file}
     94     rm -f ${file}
     95 fi
     96 cat <<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.
    111 EOF
    112 
    113 # Bye.
    114 exit 0
    115