2009-08-08 Felix Zielcke <fzielcke@z-51.de>
[grub2/phcoder/solaris.git] / util / grub.d / 10_windows.in
blob055258e292187aaed1afda4139743cdfd62d4ccf
1 #! /bin/sh -e
3 # grub-mkconfig helper script.
4 # Copyright (C) 2008 Free Software Foundation, Inc.
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.
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.
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/>.
19 prefix=@prefix@
20 exec_prefix=@exec_prefix@
21 libdir=@libdir@
22 . ${libdir}/grub/grub-mkconfig_lib
24 case "`uname 2>/dev/null`" in
25 CYGWIN*) ;;
26 *) exit 0 ;;
27 esac
29 # Try C: even if current system is on other partition.
30 case "$SYSTEMDRIVE" in
31 [Cc]:) dirlist="C:" ;;
32 [D-Zd-z]:) dirlist="C: $SYSTEMDRIVE" ;;
33 *) exit 0 ;;
34 esac
36 get_os_name_from_boot_ini ()
38 # Fail if no or more than one partition.
39 test "`sed -n 's,^\(\(multi\|scsi\)[^=]*\)=.*$,\1,p' "$1" 2>/dev/null | \
40 sort | uniq | wc -l`" = 1 || return 1
42 # Search 'default=PARTITION'
43 local part=`sed -n 's,^default=,,p' "$1" | sed 's,\\\\,/,g;s,[ \t\r]*$,,;1q'`
44 test -n "$part" || return 1
46 # Search 'PARTITION="NAME" ...'
47 local name=`sed -n 's,\\\\,/,g;s,^'"$part"'="\([^"]*\)".*$,\1,p' "$1" | sed 1q`
48 test -n "$name" || return 1
50 echo "$name"
54 for dir in $dirlist ; do
56 # Check for Vista bootmgr.
57 if [ -f "$dir"/bootmgr -a -f "$dir"/boot/bcd ] ; then
58 OS="Windows Vista bootmgr"
60 # Check for NTLDR.
61 elif [ -f "$dir"/ntldr -a -f "$dir"/ntdetect.com -a -f "$dir"/boot.ini ] ; then
62 OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || OS="Windows NT/2000/XP loader"
64 else
65 continue
68 # Get boot /dev/ice.
69 dev=`${grub_probe} -t device "$dir" 2>/dev/null` || continue
71 echo "Found $OS on $dir ($dev)" >&2
72 cat << EOF
73 menuentry "$OS" {
74 EOF
76 prepare_grub_to_access_device "$dev" | sed 's,^,\t,'
78 cat << EOF
79 chainloader +1
81 EOF
82 done