All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] update-grub for Cygwin
@ 2008-07-24 20:19 Christian Franke
  2008-07-24 20:39 ` Christian Franke
  2008-07-25 20:40 ` Robert Millan
  0 siblings, 2 replies; 16+ messages in thread
From: Christian Franke @ 2008-07-24 20:19 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

This patch allows to run update-grub on Cygwin.

Christian

2008-07-24  Christian Franke  <franke@computer.org>

	* util/update-grub.in: Add a check for admin
	group for Cygwin.
	Add `-f' to `rm' and `mv' of grub.cfg to handle
	the different filesystem semantics on Windows.



[-- Attachment #2: grub2-update-Cygwin.patch --]
[-- Type: text/x-diff, Size: 1268 bytes --]

diff --git a/util/update-grub.in b/util/update-grub.in
index c78444e..70607a5 100644
--- a/util/update-grub.in
+++ b/util/update-grub.in
@@ -73,8 +73,20 @@ if [ "x$EUID" = "x" ] ; then
 fi
 
 if [ "$EUID" != 0 ] ; then
-  echo "$0: You must run this as root" >&2
-  exit 1
+  root=f
+  case "`uname 2>/dev/null`" in
+    CYGWIN*)
+      # Cygwin: Assume root if member of admin group
+      for g in `id -G 2>/dev/null` ; do
+	case $g in
+	  0|544) root=t ;;
+	esac
+      done ;;
+  esac
+  if [ $root != t ] ; then
+    echo "$0: You must run this as root" >&2
+    exit 1
+  fi
 fi
 
 set $grub_mkdevicemap dummy
@@ -154,6 +166,7 @@ export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_
 # These are optional, user-defined variables.
 export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID
 
+rm -f ${grub_cfg}.new
 exec > ${grub_cfg}.new
 
 # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
@@ -187,6 +200,6 @@ for i in ${update_grub_dir}/* ; do
 done
 
 # none of the children aborted with error, install the new grub.cfg
-mv ${grub_cfg}.new ${grub_cfg}
+mv -f ${grub_cfg}.new ${grub_cfg}
 
 echo "done" >&2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-24 20:19 [PATCH] update-grub for Cygwin Christian Franke
@ 2008-07-24 20:39 ` Christian Franke
  2008-07-25 20:42   ` Robert Millan
  2008-07-25 20:40 ` Robert Millan
  1 sibling, 1 reply; 16+ messages in thread
From: Christian Franke @ 2008-07-24 20:39 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 174 bytes --]

Christian Franke wrote:
> This patch allows to run update-grub on Cygwin.
>
... and here is a simple example for /etc/grub.d/10_cygwin

Only adds current OS yet.

Christian


[-- Attachment #2: grub2-10_cygwin.patch --]
[-- Type: text/x-diff, Size: 1420 bytes --]

diff --git a/util/grub.d/10_cygwin.in b/util/grub.d/10_cygwin.in
new file mode 100644
index 0000000..1dd1116
--- /dev/null
+++ b/util/grub.d/10_cygwin.in
@@ -0,0 +1,48 @@
+#! /bin/sh -e
+
+# update-grub helper script.
+# Copyright (C) 2008  Free Software Foundation, Inc.
+#
+# 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/>.
+
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+sbindir=@sbindir@
+
+grub_probe=${sbindir}/grub-probe
+
+case "`uname 2>/dev/null`" in
+  CYGWIN_NT-5.0) OS="Windows 2000" ;;
+  CYGWIN_NT-5.1) OS="Windows XP" ;;
+  CYGWIN*) OS="Windows" ;;
+  *) exit 0 ;;
+esac
+
+[ "$SYSTEMDRIVE" != "" ] || exit 0
+
+p="`cygpath -a "$SYSTEMDRIVE"`"
+
+[ -f "$p"/ntldr ] || exit 0
+
+d="`${grub_probe} -t drive "$p" 2>/dev/null`" || exit 0
+
+echo "Found $OS on $d" >&2
+cat << EOF
+menuentry "$OS" {
+	root=$d
+	chainloader +1
+}
+EOF
+

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-24 20:19 [PATCH] update-grub for Cygwin Christian Franke
  2008-07-24 20:39 ` Christian Franke
@ 2008-07-25 20:40 ` Robert Millan
  2008-07-26 12:53   ` Christian Franke
  1 sibling, 1 reply; 16+ messages in thread
From: Robert Millan @ 2008-07-25 20:40 UTC (permalink / raw)
  To: The development of GRUB 2

On Thu, Jul 24, 2008 at 10:19:17PM +0200, Christian Franke wrote:
> +  case "`uname 2>/dev/null`" in
> +    CYGWIN*)

Could this be done at build time instead? (when generating update-grub
from update-grub.in)

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What good is a phone call… if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-24 20:39 ` Christian Franke
@ 2008-07-25 20:42   ` Robert Millan
  2008-07-31 21:32     ` Christian Franke
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Millan @ 2008-07-25 20:42 UTC (permalink / raw)
  To: The development of GRUB 2

On Thu, Jul 24, 2008 at 10:39:04PM +0200, Christian Franke wrote:
> +
> +d="`${grub_probe} -t drive "$p" 2>/dev/null`" || exit 0

Please avoid reliing on '-t drive'.  It's based on device.map which just
contains guesswork.

prepare_grub_to_access_device() is a much better option.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What good is a phone call… if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-25 20:40 ` Robert Millan
@ 2008-07-26 12:53   ` Christian Franke
  2008-07-27  6:09     ` Pavel Roskin
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Franke @ 2008-07-26 12:53 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 1662 bytes --]

Robert Millan wrote:
> On Thu, Jul 24, 2008 at 10:19:17PM +0200, Christian Franke wrote:
>   
>> +  case "`uname 2>/dev/null`" in
>> +    CYGWIN*)
>>     
>
> Could this be done at build time instead? (when generating update-grub
> from update-grub.in)
>
>   

Yes, of course. Some alternatives:

1.)
The method used by AM_CONDITIONAL from GNU automake is simple and works 
with config.status without any extra 'shell preprocessor'.

Looks ugly, but may be OK if there are only few changes. See attached 
patch for a working example.


2.)
Use some shell-preprocessor. A primitive version can be configured by 
above method:

update-grub.in:
@ifdef CYGWIN
...
@else CYGWIN
...
@endif CYGWIN

shellpp.sh.in:
@CYGWIN_TRUE@  sed '/^@if CYGWIN/,/^@else CYGWIN/d;/^@endif CYGWIN/d'
@CYGWIN_FALSE@ sed '/^@if CYGWIN/d;/^@else CYGWIN/,/^@endif CYGWIN/d'



3.)
Move platform specific code to functions in update-grub_lib, e.g. 
'check_user_root()' in this case.

Let 'update-grub_lib' include optional platform specific scripts (e.g. 
'update-grub-_lib-i386-pc-cygwin'). The existence of the script can be 
checked by configure. This script can then replace the default 
implementations if necessary:

Example:

update-grub.in:

check_user_root || exit 1


update-grub-lib.in:

check_user_root()
{
... default implementation, test EUID==0
}

platform_lib=@platform_lib@
test -z "${platform_lib}" || . "${libdir}/${platform_lib}"


update-grub-_lib-i386-pc-cygwin:

check_user_root()
{
... Cygwin specific implementation ...
}


Any method would also help to implement 
'make_system_path_relative_to_its_root()' without the need for 
'grub-probe -t prefix'.

Christian


[-- Attachment #2: grub2-update-Cygwin-2.patch --]
[-- Type: text/x-diff, Size: 2297 bytes --]

diff --git a/aclocal.m4 b/aclocal.m4
index ee6c4db..8c44678 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -414,3 +414,17 @@ else
   AC_MSG_RESULT([no])
 [fi]
 ])
+
+dnl Set conditional for target dependend sections in scripts.
+dnl Similar to AM_CONDITIONAL from GNU automake.
+AC_DEFUN([grub_CONDITIONAL],[
+AC_SUBST([$1_TRUE])
+AC_SUBST([$1_FALSE])
+if $2 ; then
+  $1_TRUE=
+  $1_FALSE="#"
+else
+  $1_TRUE="#"
+  $1_FALSE=
+fi
+])
diff --git a/configure.ac b/configure.ac
index 7a5938a..def656d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -351,6 +351,9 @@ CPPFLAGS="$tmp_CPPFLAGS"
 LDFLAGS="$tmp_LDFLAGS"
 LIBS="$tmp_LIBS"
 
+# Set conditionals for target dependend sections in scripts.
+grub_CONDITIONAL(CYGWIN, [test "$target_os" = cygwin])
+
 #
 # Check for options.
 #
diff --git a/util/update-grub.in b/util/update-grub.in
index c78444e..55aab75 100644
--- a/util/update-grub.in
+++ b/util/update-grub.in
@@ -73,8 +73,21 @@ if [ "x$EUID" = "x" ] ; then
 fi
 
 if [ "$EUID" != 0 ] ; then
-  echo "$0: You must run this as root" >&2
-  exit 1
+@CYGWIN_TRUE@  # Begin Cygwin specific.
+@CYGWIN_TRUE@  # Assume root if member of admin group.
+@CYGWIN_TRUE@  root=f
+@CYGWIN_TRUE@  for g in `id -G 2>/dev/null` ; do
+@CYGWIN_TRUE@    case $g in
+@CYGWIN_TRUE@      0|544) root=t ;;
+@CYGWIN_TRUE@    esac
+@CYGWIN_TRUE@  done
+@CYGWIN_TRUE@  if [ $root != t ] ; then
+@CYGWIN_TRUE@    echo "$0: You must have admin rights to run this" >&2
+@CYGWIN_TRUE@    exit 1
+@CYGWIN_TRUE@  fi
+@CYGWIN_TRUE@  # End Cygwin specific.
+@CYGWIN_FALSE@  echo "$0: You must run this as root" >&2
+@CYGWIN_FALSE@  exit 1
 fi
 
 set $grub_mkdevicemap dummy
@@ -154,6 +167,7 @@ export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_
 # These are optional, user-defined variables.
 export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID
 
+rm -f ${grub_cfg}.new
 exec > ${grub_cfg}.new
 
 # Allow this to fail, since /boot/grub/ might need to be fatfs to support some
@@ -187,6 +201,6 @@ for i in ${update_grub_dir}/* ; do
 done
 
 # none of the children aborted with error, install the new grub.cfg
-mv ${grub_cfg}.new ${grub_cfg}
+mv -f ${grub_cfg}.new ${grub_cfg}
 
 echo "done" >&2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-26 12:53   ` Christian Franke
@ 2008-07-27  6:09     ` Pavel Roskin
  2008-07-27 12:39       ` Robert Millan
  0 siblings, 1 reply; 16+ messages in thread
From: Pavel Roskin @ 2008-07-27  6:09 UTC (permalink / raw)
  To: The development of GRUB 2

On Sat, 2008-07-26 at 14:53 +0200, Christian Franke wrote:
> Robert Millan wrote:
> > On Thu, Jul 24, 2008 at 10:19:17PM +0200, Christian Franke wrote:
> >   
> >> +  case "`uname 2>/dev/null`" in
> >> +    CYGWIN*)
> >>     
> >
> > Could this be done at build time instead? (when generating update-grub
> > from update-grub.in)
> >
> >   
> 
> Yes, of course. Some alternatives:
...

I think it's better to have the check at the run time than any of those
alternatives.  If we have many OS specific checks, then we can think how
to leave the relevant ones.  At this point, it's probably not worth the
trouble.

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-27  6:09     ` Pavel Roskin
@ 2008-07-27 12:39       ` Robert Millan
  2008-07-29 15:40         ` Christian Franke
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Millan @ 2008-07-27 12:39 UTC (permalink / raw)
  To: The development of GRUB 2

On Sun, Jul 27, 2008 at 02:09:02AM -0400, Pavel Roskin wrote:
> On Sat, 2008-07-26 at 14:53 +0200, Christian Franke wrote:
> > Robert Millan wrote:
> > > On Thu, Jul 24, 2008 at 10:19:17PM +0200, Christian Franke wrote:
> > >   
> > >> +  case "`uname 2>/dev/null`" in
> > >> +    CYGWIN*)
> > >>     
> > >
> > > Could this be done at build time instead? (when generating update-grub
> > > from update-grub.in)
> > >
> > >   
> > 
> > Yes, of course. Some alternatives:
> ...
> 
> I think it's better to have the check at the run time than any of those
> alternatives.  If we have many OS specific checks, then we can think how
> to leave the relevant ones.  At this point, it's probably not worth the
> trouble.

Ok I don't mind.  It was just a suggestion.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What good is a phone call… if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-27 12:39       ` Robert Millan
@ 2008-07-29 15:40         ` Christian Franke
  0 siblings, 0 replies; 16+ messages in thread
From: Christian Franke @ 2008-07-29 15:40 UTC (permalink / raw)
  To: The development of GRUB 2

Robert Millan wrote:
> On Sun, Jul 27, 2008 at 02:09:02AM -0400, Pavel Roskin wrote:
>   
>> On Sat, 2008-07-26 at 14:53 +0200, Christian Franke wrote:
>>     
>>> Robert Millan wrote:
>>>       
>>>> On Thu, Jul 24, 2008 at 10:19:17PM +0200, Christian Franke wrote:
>>>>   
>>>>         
>>>>> +  case "`uname 2>/dev/null`" in
>>>>> +    CYGWIN*)
>>>>>     
>>>>>           
>>>> Could this be done at build time instead? (when generating update-grub
>>>> from update-grub.in)
>>>>
>>>>   
>>>>         
>>> Yes, of course. Some alternatives:
>>>       
>> ...
>>
>> I think it's better to have the check at the run time than any of those
>> alternatives.  If we have many OS specific checks, then we can think how
>> to leave the relevant ones.  At this point, it's probably not worth the
>> trouble.
>>     
>
> Ok I don't mind.  It was just a suggestion.
>
>   

For now, I committed the original version with the run time check.

Christian




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-25 20:42   ` Robert Millan
@ 2008-07-31 21:32     ` Christian Franke
  2008-08-04 19:46       ` Christian Franke
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Franke @ 2008-07-31 21:32 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

Robert Millan wrote:
> On Thu, Jul 24, 2008 at 10:39:04PM +0200, Christian Franke wrote:
>   
>> +
>> +d="`${grub_probe} -t drive "$p" 2>/dev/null`" || exit 0
>>     
>
> Please avoid reliing on '-t drive'.  It's based on device.map which just
> contains guesswork.
>
> prepare_grub_to_access_device() is a much better option.
>
>   

Yes. Thanks for the info. New version below.

Christian

2008-07-31  Christian Franke  <franke@computer.org>

    * conf/common.rmk: Add `10_cygwin' to `update-grub_SCRIPTS'.
    * util/grub.d/10_cygwin.in: New file.



[-- Attachment #2: grub2-10_cygwin-2.patch --]
[-- Type: text/x-diff, Size: 2061 bytes --]

diff --git a/conf/common.rmk b/conf/common.rmk
index 7db0b2a..0f74f1a 100644
--- a/conf/common.rmk
+++ b/conf/common.rmk
@@ -120,7 +120,7 @@ CLEANFILES += update-grub_lib
 %: util/grub.d/%.in config.status
 	./config.status --file=$@:$<
 	chmod +x $@
-update-grub_SCRIPTS = 00_header 10_linux 10_hurd 30_os-prober 40_custom
+update-grub_SCRIPTS = 00_header 10_cygwin 10_linux 10_hurd 30_os-prober 40_custom
 CLEANFILES += $(update-grub_SCRIPTS)
 
 update-grub_DATA += util/grub.d/README
diff --git a/util/grub.d/10_cygwin.in b/util/grub.d/10_cygwin.in
new file mode 100644
index 0000000..7dee6c1
--- /dev/null
+++ b/util/grub.d/10_cygwin.in
@@ -0,0 +1,52 @@
+#! /bin/sh -e
+
+# update-grub helper script.
+# Copyright (C) 2008  Free Software Foundation, Inc.
+#
+# 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/>.
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+. ${libdir}/grub/update-grub_lib
+
+case "`uname 2>/dev/null`" in
+  CYGWIN_NT-5.0) OS="Windows 2000" ;;
+  CYGWIN_NT-5.1) OS="Windows XP"   ;;
+  CYGWIN_NT-5.2) OS="Windows 2003" ;;
+  CYGWIN*)       OS="Windows"      ;;
+  *) exit 0 ;;
+esac
+
+case "$SYSTEMDRIVE" in
+  [A-Za-z]:) ;;
+  *) exit 0  ;;
+esac
+
+test -f "$SYSTEMDRIVE"/ntldr || exit 0
+
+sysdev=`${grub_probe} -t device "$SYSTEMDRIVE"/ 2>/dev/null` || exit 0
+
+echo "Found $OS on $SYSTEMDRIVE/ ($sysdev)" >&2
+cat << EOF
+menuentry "$OS" {
+EOF
+
+prepare_grub_to_access_device "$sysdev" | sed 's,^,\t,'
+
+cat << EOF
+	chainloader +1
+}
+EOF
+

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-07-31 21:32     ` Christian Franke
@ 2008-08-04 19:46       ` Christian Franke
  2008-08-04 20:00         ` Robert Millan
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Franke @ 2008-08-04 19:46 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 855 bytes --]

Christian Franke wrote:
> Robert Millan wrote:
>> On Thu, Jul 24, 2008 at 10:39:04PM +0200, Christian Franke wrote:
>>  
>>> +
>>> +d="`${grub_probe} -t drive "$p" 2>/dev/null`" || exit 0
>>>     
>>
>> Please avoid reliing on '-t drive'.  It's based on device.map which just
>> contains guesswork.
>>
>> prepare_grub_to_access_device() is a much better option.
>>
>>   
>
> Yes. Thanks for the info. New version below.
>
> Christian
>
> ...
>

Here a more generic version which allows to specifiy windows system dirs 
by /etc/default/grub:GRUB_WINDOWS_DIRS.

Defaults to current SYSTEMDRIVE on Cygwin, and nothing on other OS.

Christian

2008-08-04  Christian Franke  <franke@computer.org>

	* conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'.
	* util/grub.d/10_windows.in: New file.
	* util/update-grub.in: Add export of GRUB_WINDOWS_DIRS.



[-- Attachment #2: grub2-10_windows.patch --]
[-- Type: text/x-diff, Size: 4202 bytes --]

diff --git a/conf/common.rmk b/conf/common.rmk
index 3d3cd8a..3d674a6 100644
--- a/conf/common.rmk
+++ b/conf/common.rmk
@@ -120,7 +120,7 @@ CLEANFILES += update-grub_lib
 %: util/grub.d/%.in config.status
 	./config.status --file=$@:$<
 	chmod +x $@
-update-grub_SCRIPTS = 00_header 10_linux 10_hurd 30_os-prober 40_custom
+update-grub_SCRIPTS = 00_header 10_linux 10_hurd 10_windows 30_os-prober 40_custom
 CLEANFILES += $(update-grub_SCRIPTS)
 
 update-grub_DATA += util/grub.d/README
diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in
new file mode 100644
index 0000000..0b0bce2
--- /dev/null
+++ b/util/grub.d/10_windows.in
@@ -0,0 +1,104 @@
+#! /bin/sh -e
+
+# update-grub helper script.
+# Copyright (C) 2008  Free Software Foundation, Inc.
+#
+# 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/>.
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+. ${libdir}/grub/update-grub_lib
+
+# List of directories to search for Windows can be specified
+# in @sysconfdir@/default/grub by GRUB_WINDOWS_DIRS, e.g:
+# GRUB_WINDOWS_DIRS="/boot /mnt/win*"
+
+dirlist="$GRUB_WINDOWS_DIRS"
+
+if [ -z "$dirlist" ] ; then
+  case "`uname 2>/dev/null`" in
+    CYGWIN*)
+      # Cygwin: try current system partition.
+      dirlist="$SYSTEMDRIVE" ;;
+    *)
+      # Other: do nothing to avoid collision with os-prober.
+      exit 0 ;;
+  esac
+fi
+
+# Test for a file, case-insensitive.
+test_nocase ()
+{
+  local p=""
+  if [ "$1" = "-p" ] ; then
+    p=t ; shift
+  fi
+  local f=`ls -1 "$1" 2>/dev/null | grep -i '^'"$2"'$' | sed 1q`
+  test -n "$f" || return 1
+  test -z "$p" || echo "$1/$f"
+}
+
+# Get OS name from boot.ini.
+get_os_name_from_boot_ini ()
+{
+  local ini=`test_nocase -p "$1" boot.ini` || return 1
+
+  # Fail if no or more than one partition.
+  test "`sed -n 's,^\(\(multi\|scsi\)[^=]*\)=.*$,\1,p' "$ini" 2>/dev/null | \
+    sort | uniq | wc -l`" = 1 || return 1
+
+  # Search 'default=PARTITION'
+  local part=`sed -n 's,^default=,,p' "$ini" | sed 's,\\\\,/,g;s,[ \t\r]*$,,;1q'`
+  test -n "$part" || return 1
+
+  # Search 'PARTITION="NAME" ...'
+  local name=`sed -n 's,\\\\,/,g;s,^'"$part"'="\([^"]*\)".*$,\1,p' "$ini" | sed 1q`
+  test -n "$name" || return 1
+
+  echo "$name"
+}
+
+
+for dir in $dirlist ; do
+
+  # Check for Vista Bootmgr.
+  if test_nocase "$dir" bootmgr && bootdir=`test_nocase -p "$dir" boot` &&
+     test_nocase "$bootdir" bcd ; then
+    OS="Windows Vista bootmgr"
+
+  # Check for NTLDR.
+  elif test_nocase "$dir" ntldr && test_nocase "$dir" ntdetect.com ; then
+    OS=`get_os_name_from_boot_ini "$dir"` || OS="Windows NT/2000/XP loader"
+
+  else
+    continue
+  fi
+
+  # Get boot /dev/ice.
+  dev=`${grub_probe} -t device "$dir" 2>/dev/null` || continue
+
+  echo "Found $OS on $dir ($dev)" >&2
+  cat << EOF
+menuentry "$OS" {
+EOF
+
+  prepare_grub_to_access_device "$dev" | sed 's,^,\t,'
+
+  cat << EOF
+	chainloader +1
+}
+EOF
+done
+
diff --git a/util/update-grub.in b/util/update-grub.in
index 8c60c41..eafaa91 100644
--- a/util/update-grub.in
+++ b/util/update-grub.in
@@ -163,7 +163,7 @@ esac
 export GRUB_DEVICE GRUB_DEVICE_UUID GRUB_DEVICE_BOOT GRUB_DEVICE_BOOT_UUID GRUB_FS GRUB_FONT_PATH GRUB_PRELOAD_MODULES
 
 # These are optional, user-defined variables.
-export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID
+export GRUB_DEFAULT GRUB_TIMEOUT GRUB_DISTRIBUTOR GRUB_CMDLINE_LINUX GRUB_CMDLINE_LINUX_DEFAULT GRUB_TERMINAL GRUB_SERIAL_COMMAND GRUB_DISABLE_LINUX_UUID GRUB_WINDOWS_DIRS
 
 rm -f ${grub_cfg}.new
 exec > ${grub_cfg}.new

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-08-04 19:46       ` Christian Franke
@ 2008-08-04 20:00         ` Robert Millan
  2008-08-04 20:40           ` Christian Franke
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Millan @ 2008-08-04 20:00 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, Aug 04, 2008 at 09:46:03PM +0200, Christian Franke wrote:
> 
> Here a more generic version which allows to specifiy windows system dirs 
> by /etc/default/grub:GRUB_WINDOWS_DIRS.
> 
> Defaults to current SYSTEMDRIVE on Cygwin, and nothing on other OS.
> 
> Christian
> 
> 2008-08-04  Christian Franke  <franke@computer.org>
> 
> 	* conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'.
> 	* util/grub.d/10_windows.in: New file.
> 	* util/update-grub.in: Add export of GRUB_WINDOWS_DIRS.

Why is this needed?  Can't we do something like 'grub-probe -t device c:/ntldr'
or so?

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-08-04 20:00         ` Robert Millan
@ 2008-08-04 20:40           ` Christian Franke
  2008-08-04 21:41             ` Robert Millan
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Franke @ 2008-08-04 20:40 UTC (permalink / raw)
  To: The development of GRUB 2

Robert Millan wrote:
> On Mon, Aug 04, 2008 at 09:46:03PM +0200, Christian Franke wrote:
>   
>> Here a more generic version which allows to specifiy windows system dirs 
>> by /etc/default/grub:GRUB_WINDOWS_DIRS.
>>
>> Defaults to current SYSTEMDRIVE on Cygwin, and nothing on other OS.
>>
>> Christian
>>
>> 2008-08-04  Christian Franke  <franke@computer.org>
>>
>> 	* conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'.
>> 	* util/grub.d/10_windows.in: New file.
>> 	* util/update-grub.in: Add export of GRUB_WINDOWS_DIRS.
>>     
>
> Why is this needed?  Can't we do something like 'grub-probe -t device c:/ntldr'
> or so?
>
>   

It is not needed for standard installations with ntldr on SYSTEMDRIVE (C:).
The ability to specify GRUB_WINDOWS_DIRS is added to support 
non-standard installations.
It also allows to use 10_windows on other OS if os-prober is not available.

Christian




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-08-04 20:40           ` Christian Franke
@ 2008-08-04 21:41             ` Robert Millan
  2008-08-05 12:13               ` Christian Franke
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Millan @ 2008-08-04 21:41 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, Aug 04, 2008 at 10:40:02PM +0200, Christian Franke wrote:
> Robert Millan wrote:
> >On Mon, Aug 04, 2008 at 09:46:03PM +0200, Christian Franke wrote:
> >  
> >>Here a more generic version which allows to specifiy windows system dirs 
> >>by /etc/default/grub:GRUB_WINDOWS_DIRS.
> >>
> >>Defaults to current SYSTEMDRIVE on Cygwin, and nothing on other OS.
> >>
> >>Christian
> >>
> >>2008-08-04  Christian Franke  <franke@computer.org>
> >>
> >>	* conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'.
> >>	* util/grub.d/10_windows.in: New file.
> >>	* util/update-grub.in: Add export of GRUB_WINDOWS_DIRS.
> >>    
> >
> >Why is this needed?  Can't we do something like 'grub-probe -t device 
> >c:/ntldr'
> >or so?
> >
> >  
> 
> It is not needed for standard installations with ntldr on SYSTEMDRIVE (C:).
> The ability to specify GRUB_WINDOWS_DIRS is added to support 
> non-standard installations.
> It also allows to use 10_windows on other OS if os-prober is not available.

Why not have the user write a custom entry then?  I think it clutters the
user interface to add options for everything.  If a corner case (boot a non
native disk, can't use os-prober) can be supported by creating a new config
file, why not do that?  It was the whole reason for designing update-grub to
be easily extensible.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-08-04 21:41             ` Robert Millan
@ 2008-08-05 12:13               ` Christian Franke
  2008-08-05 20:09                 ` Robert Millan
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Franke @ 2008-08-05 12:13 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 2030 bytes --]

Robert Millan wrote:
> On Mon, Aug 04, 2008 at 10:40:02PM +0200, Christian Franke wrote:
>   
>> Robert Millan wrote:
>>     
>>> On Mon, Aug 04, 2008 at 09:46:03PM +0200, Christian Franke wrote:
>>>  
>>>       
>>>> Here a more generic version which allows to specifiy windows system dirs 
>>>> by /etc/default/grub:GRUB_WINDOWS_DIRS.
>>>>
>>>> Defaults to current SYSTEMDRIVE on Cygwin, and nothing on other OS.
>>>>
>>>> Christian
>>>>
>>>> 2008-08-04  Christian Franke  <franke@computer.org>
>>>>
>>>> 	* conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'.
>>>> 	* util/grub.d/10_windows.in: New file.
>>>> 	* util/update-grub.in: Add export of GRUB_WINDOWS_DIRS.
>>>>    
>>>>         
>>> Why is this needed?  Can't we do something like 'grub-probe -t device 
>>> c:/ntldr'
>>> or so?
>>>
>>>  
>>>       
>> It is not needed for standard installations with ntldr on SYSTEMDRIVE (C:).
>> The ability to specify GRUB_WINDOWS_DIRS is added to support 
>> non-standard installations.
>> It also allows to use 10_windows on other OS if os-prober is not available.
>>     
>
> Why not have the user write a custom entry then?  I think it clutters the
> user interface to add options for everything.  If a corner case (boot a non
> native disk, can't use os-prober) can be supported by creating a new config
> file, why not do that?  It was the whole reason for designing update-grub to
> be easily extensible.
>
>   

Even with the new configuration parameter, user can still decide to 
leave the parameter unset and write a custom entry. Or the user can set 
the parameter and so "opt-in" to let the script do the work (or 
"opt-out" to disable the default work on Cygwin).

But in case the extra 'export' in 'update-grub' is a problem, here a 
simplified version.

Scans C: and SYSTEMDRIVE on Cygwin, does nothing elsewhere. Cannot be 
configured.

Christian

2008-08-05  Christian Franke  <franke@computer.org>

	* conf/common.rmk: Add `10_windows' to `update-grub_SCRIPTS'.
	* util/grub.d/10_windows.in: New file.



[-- Attachment #2: grub2-10_windows-2.patch --]
[-- Type: text/x-diff, Size: 2913 bytes --]

diff --git a/conf/common.rmk b/conf/common.rmk
index 3d3cd8a..3d674a6 100644
--- a/conf/common.rmk
+++ b/conf/common.rmk
@@ -120,7 +120,7 @@ CLEANFILES += update-grub_lib
 %: util/grub.d/%.in config.status
 	./config.status --file=$@:$<
 	chmod +x $@
-update-grub_SCRIPTS = 00_header 10_linux 10_hurd 30_os-prober 40_custom
+update-grub_SCRIPTS = 00_header 10_linux 10_hurd 10_windows 30_os-prober 40_custom
 CLEANFILES += $(update-grub_SCRIPTS)
 
 update-grub_DATA += util/grub.d/README
diff --git a/util/grub.d/10_windows.in b/util/grub.d/10_windows.in
new file mode 100644
index 0000000..e8f3c3e
--- /dev/null
+++ b/util/grub.d/10_windows.in
@@ -0,0 +1,83 @@
+#! /bin/sh -e
+
+# update-grub helper script.
+# Copyright (C) 2008  Free Software Foundation, Inc.
+#
+# 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/>.
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+. ${libdir}/grub/update-grub_lib
+
+case "`uname 2>/dev/null`" in
+  CYGWIN*)  ;;
+  *) exit 0 ;;
+esac
+
+# Try C: even if current system is on other partition.
+case "$SYSTEMDRIVE" in
+  [Cc]:)     dirlist="C:"              ;;
+  [D-Zd-z]:) dirlist="C: $SYSTEMDRIVE" ;;
+  *) 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'
+  local part=`sed -n 's,^default=,,p' "$1" | sed 's,\\\\,/,g;s,[ \t\r]*$,,;1q'`
+  test -n "$part" || return 1
+
+  # Search 'PARTITION="NAME" ...'
+  local name=`sed -n 's,\\\\,/,g;s,^'"$part"'="\([^"]*\)".*$,\1,p' "$1" | sed 1q`
+  test -n "$name" || return 1
+
+  echo "$name"
+}
+
+
+for dir in $dirlist ; do
+
+  # Check for Vista bootmgr.
+  if [ -f "$dir"/bootmgr -a -f "$dir"/boot/bcd ] ; then
+    OS="Windows Vista bootmgr"
+
+  # Check for NTLDR.
+  elif [ -f "$dir"/ntldr -a -f "$dir"/ntdetect.com -a -f "$dir"/boot.ini ] ; then
+    OS=`get_os_name_from_boot_ini "$dir"/boot.ini` || OS="Windows NT/2000/XP loader"
+
+  else
+    continue
+  fi
+
+  # Get boot /dev/ice.
+  dev=`${grub_probe} -t device "$dir" 2>/dev/null` || continue
+
+  echo "Found $OS on $dir ($dev)" >&2
+  cat << EOF
+menuentry "$OS" {
+EOF
+
+  prepare_grub_to_access_device "$dev" | sed 's,^,\t,'
+
+  cat << EOF
+	chainloader +1
+}
+EOF
+done
+

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-08-05 12:13               ` Christian Franke
@ 2008-08-05 20:09                 ` Robert Millan
  2008-08-06 18:48                   ` Christian Franke
  0 siblings, 1 reply; 16+ messages in thread
From: Robert Millan @ 2008-08-05 20:09 UTC (permalink / raw)
  To: The development of GRUB 2

On Tue, Aug 05, 2008 at 02:13:43PM +0200, Christian Franke wrote:
> >
> >Why not have the user write a custom entry then?  I think it clutters the
> >user interface to add options for everything.  If a corner case (boot a non
> >native disk, can't use os-prober) can be supported by creating a new config
> >file, why not do that?  It was the whole reason for designing update-grub 
> >to
> >be easily extensible.
> 
> Even with the new configuration parameter, user can still decide to 
> leave the parameter unset and write a custom entry.

My concern is not with presenting too many options to the user, but with having
to support them.  In general, if a use case can be supported without adding a
new user option, I think it's much better not to add it.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH] update-grub for Cygwin
  2008-08-05 20:09                 ` Robert Millan
@ 2008-08-06 18:48                   ` Christian Franke
  0 siblings, 0 replies; 16+ messages in thread
From: Christian Franke @ 2008-08-06 18:48 UTC (permalink / raw)
  To: The development of GRUB 2

Robert Millan wrote:
> On Tue, Aug 05, 2008 at 02:13:43PM +0200, Christian Franke wrote:
>   
>>> Why not have the user write a custom entry then?  I think it clutters the
>>> user interface to add options for everything.  If a corner case (boot a non
>>> native disk, can't use os-prober) can be supported by creating a new config
>>> file, why not do that?  It was the whole reason for designing update-grub 
>>> to
>>> be easily extensible.
>>>       
>> Even with the new configuration parameter, user can still decide to 
>> leave the parameter unset and write a custom entry.
>>     
>
> My concern is not with presenting too many options to the user, but with having
> to support them.  In general, if a use case can be supported without adding a
> new user option, I think it's much better not to add it.
>
>   

OK. I committed the simplified version (no configuration parameter).

Christian




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-08-06 18:48 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-24 20:19 [PATCH] update-grub for Cygwin Christian Franke
2008-07-24 20:39 ` Christian Franke
2008-07-25 20:42   ` Robert Millan
2008-07-31 21:32     ` Christian Franke
2008-08-04 19:46       ` Christian Franke
2008-08-04 20:00         ` Robert Millan
2008-08-04 20:40           ` Christian Franke
2008-08-04 21:41             ` Robert Millan
2008-08-05 12:13               ` Christian Franke
2008-08-05 20:09                 ` Robert Millan
2008-08-06 18:48                   ` Christian Franke
2008-07-25 20:40 ` Robert Millan
2008-07-26 12:53   ` Christian Franke
2008-07-27  6:09     ` Pavel Roskin
2008-07-27 12:39       ` Robert Millan
2008-07-29 15:40         ` Christian Franke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.