10_windows.in 2.76 KB
Newer Older
1 2
#! /bin/sh
set -e
3

4
# grub-mkconfig helper script.
5
# Copyright (C) 2008,2009,2010  Free Software Foundation, Inc.
6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.

20 21 22 23
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"

24 25 26
export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR="@localedir@"

27
. "$pkgdatadir/grub-mkconfig_lib"
28 29 30 31 32 33 34 35

case "`uname 2>/dev/null`" in
  CYGWIN*)  ;;
  *) exit 0 ;;
esac

# Try C: even if current system is on other partition.
case "$SYSTEMDRIVE" in
36 37
  [Cc]:)     drives="C:"              ;;
  [D-Zd-z]:) drives="C: $SYSTEMDRIVE" ;;
38 39 40 41 42 43 44 45 46 47
  *) exit 0 ;;
esac

get_os_name_from_boot_ini ()
{
  # Fail if no or more than one partition.
  test "`sed -n 's,^\(\(multi\|scsi\)[^=]*\)=.*$,\1,p' "$1" 2>/dev/null | \
    sort | uniq | wc -l`" = 1 || return 1

  # Search 'default=PARTITION'
48
  get_os_name_from_boot_ini_part=`sed -n 's,^default=,,p' "$1" | sed 's,\\\\,/,g;s,[ $grub_tab\r]*$,,;1q'`
49
  test -n "$get_os_name_from_boot_ini_part" || return 1
50 51

  # Search 'PARTITION="NAME" ...'
52 53
  get_os_name_from_boot_ini_name=`sed -n 's,\\\\,/,g;s,^'"$get_os_name_from_boot_ini_part"'="\([^"]*\)".*$,\1,p' "$1" | sed 1q`
  test -n "$get_os_name_from_boot_ini_name" || return 1
54

55
  echo "$get_os_name_from_boot_ini_name"
56 57 58
}


59 60 61 62 63 64 65
for drv in $drives ; do

  # Convert to Cygwin path.
  dir=`cygpath "$drv"`
  test -n "$dir" || continue

  needmap=
66
  osid=
67 68

  # Check for Vista bootmgr.
69
  if [ -f "$dir"/bootmgr ] && [ -f "$dir"/boot/bcd ] ; then
70
    OS="$(gettext "Windows Vista/7 (loader)")"
71
    osid=bootmgr
72
  # Check for NTLDR.
73
  elif [ -f "$dir"/ntldr ] && [ -f "$dir"/ntdetect.com ] && [ -f "$dir"/boot.ini ] ; then
74
    OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || OS="$(gettext "Windows NT/2000/XP (loader)")"
75
    osid=ntldr
76
    needmap=t
77 78 79 80 81

  else
    continue
  fi

82
  # Get boot device.
83 84
  dev=`${grub_probe} -t device "$dir" 2>/dev/null` || continue

85
  gettext_printf "Found %s on %s (%s)\n" "$OS" "$drv" "$dev" >&2
86
  cat << EOF
87
menuentry '$(echo "$OS" | grub_quote)' \$menuentry_id_option '$osid-$(grub_get_device_id "${dev}")' {
88 89
EOF

90 91
  save_default_entry | sed -e 's,^,$grub_tab,'
  prepare_grub_to_access_device "$dev" | sed 's,^,$grub_tab,'
92 93 94
  test -z "$needmap" || cat <<EOF
	drivemap -s (hd0) \$root
EOF
95 96 97 98 99 100
  cat << EOF
	chainloader +1
}
EOF
done