10_windows.in 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #! /bin/sh
  2. set -e
  3. # grub-mkconfig helper script.
  4. # Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
  5. #
  6. # GRUB is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # GRUB is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. prefix="@prefix@"
  19. exec_prefix="@exec_prefix@"
  20. datarootdir="@datarootdir@"
  21. export TEXTDOMAIN=@PACKAGE@
  22. export TEXTDOMAINDIR="@localedir@"
  23. . "$pkgdatadir/grub-mkconfig_lib"
  24. case "`uname 2>/dev/null`" in
  25. CYGWIN*) ;;
  26. *) exit 0 ;;
  27. esac
  28. # Try C: even if current system is on other partition.
  29. case "$SYSTEMDRIVE" in
  30. [Cc]:) drives="C:" ;;
  31. [D-Zd-z]:) drives="C: $SYSTEMDRIVE" ;;
  32. *) exit 0 ;;
  33. esac
  34. get_os_name_from_boot_ini ()
  35. {
  36. # Fail if no or more than one partition.
  37. test "`sed -n 's,^\(\(multi\|scsi\)[^=]*\)=.*$,\1,p' "$1" 2>/dev/null | \
  38. sort | uniq | wc -l`" = 1 || return 1
  39. # Search 'default=PARTITION'
  40. get_os_name_from_boot_ini_part=`sed -n 's,^default=,,p' "$1" | sed 's,\\\\,/,g;s,[ $grub_tab\r]*$,,;1q'`
  41. test -n "$get_os_name_from_boot_ini_part" || return 1
  42. # Search 'PARTITION="NAME" ...'
  43. get_os_name_from_boot_ini_name=`sed -n 's,\\\\,/,g;s,^'"$get_os_name_from_boot_ini_part"'="\([^"]*\)".*$,\1,p' "$1" | sed 1q`
  44. test -n "$get_os_name_from_boot_ini_name" || return 1
  45. echo "$get_os_name_from_boot_ini_name"
  46. }
  47. for drv in $drives ; do
  48. # Convert to Cygwin path.
  49. dir=`cygpath "$drv"`
  50. test -n "$dir" || continue
  51. needmap=
  52. osid=
  53. # Check for Vista bootmgr.
  54. if [ -f "$dir"/bootmgr ] && [ -f "$dir"/boot/bcd ] ; then
  55. OS="$(gettext "Windows Vista/7 (loader)")"
  56. osid=bootmgr
  57. # Check for NTLDR.
  58. elif [ -f "$dir"/ntldr ] && [ -f "$dir"/ntdetect.com ] && [ -f "$dir"/boot.ini ] ; then
  59. OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || OS="$(gettext "Windows NT/2000/XP (loader)")"
  60. osid=ntldr
  61. needmap=t
  62. else
  63. continue
  64. fi
  65. # Get boot device.
  66. dev=`${grub_probe} -t device "$dir" 2>/dev/null` || continue
  67. gettext_printf "Found %s on %s (%s)\n" "$OS" "$drv" "$dev" >&2
  68. cat << EOF
  69. menuentry '$(echo "$OS" | grub_quote)' \$menuentry_id_option '$osid-$(grub_get_device_id "${dev}")' {
  70. EOF
  71. save_default_entry | sed -e 's,^,$grub_tab,'
  72. prepare_grub_to_access_device "$dev" | sed 's,^,$grub_tab,'
  73. test -z "$needmap" || cat <<EOF
  74. drivemap -s (hd0) \$root
  75. EOF
  76. cat << EOF
  77. chainloader +1
  78. }
  79. EOF
  80. done