grub-set-default.in 2.5 KB

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