From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KMjH0-0004fv-Fu for mharc-grub-devel@gnu.org; Sat, 26 Jul 2008 08:53:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KMjGy-0004ek-JH for grub-devel@gnu.org; Sat, 26 Jul 2008 08:53:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KMjGw-0004at-51 for grub-devel@gnu.org; Sat, 26 Jul 2008 08:53:20 -0400 Received: from [199.232.76.173] (port=34877 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KMjGv-0004aj-TG for grub-devel@gnu.org; Sat, 26 Jul 2008 08:53:17 -0400 Received: from mailout11.t-online.de ([194.25.134.85]:56254) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KMjGv-0000AN-9Q for grub-devel@gnu.org; Sat, 26 Jul 2008 08:53:17 -0400 Received: from fwd30.aul.t-online.de by mailout11.sul.t-online.de with smtp id 1KMjGs-0005qO-00; Sat, 26 Jul 2008 14:53:14 +0200 Received: from [10.3.2.2] (V+ROZyZa8hL8qHJJQMb8t5IVkWZC5BaBD7gTiCsmtZZvDOwFCUEPBJCO2jheWBFgej@[217.235.233.234]) by fwd30.aul.t-online.de with esmtp id 1KMjGn-0mxnw80; Sat, 26 Jul 2008 14:53:09 +0200 Message-ID: <488B1E37.5000101@t-online.de> Date: Sat, 26 Jul 2008 14:53:11 +0200 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7 MIME-Version: 1.0 To: The development of GRUB 2 References: <4888E3C5.9090707@t-online.de> <20080725204016.GD18149@thorin> In-Reply-To: <20080725204016.GD18149@thorin> Content-Type: multipart/mixed; boundary="------------030701010309020404080706" X-ID: V+ROZyZa8hL8qHJJQMb8t5IVkWZC5BaBD7gTiCsmtZZvDOwFCUEPBJCO2jheWBFgej X-TOI-MSGID: 5e4c9ceb-348f-44d3-930b-000aff69cce1 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: Re: [PATCH] update-grub for Cygwin X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Jul 2008 12:53:20 -0000 This is a multi-part message in MIME format. --------------030701010309020404080706 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------030701010309020404080706 Content-Type: text/x-diff; name="grub2-update-Cygwin-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-update-Cygwin-2.patch" 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 --------------030701010309020404080706--