grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] update-grub for Cygwin


From: Christian Franke
Subject: Re: [PATCH] update-grub for Cygwin
Date: Sat, 26 Jul 2008 14:53:11 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7

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 '/address@hidden CYGWIN/,/address@hidden 
CYGWIN/d;/address@hidden CYGWIN/d'
@CYGWIN_FALSE@ sed '/address@hidden CYGWIN/d;/address@hidden 
CYGWIN/,/address@hidden 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
}

address@hidden@
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

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
address@hidden@  # Begin Cygwin specific.
address@hidden@  # Assume root if member of admin group.
address@hidden@  root=f
address@hidden@  for g in `id -G 2>/dev/null` ; do
address@hidden@    case $g in
address@hidden@      0|544) root=t ;;
address@hidden@    esac
address@hidden@  done
address@hidden@  if [ $root != t ] ; then
address@hidden@    echo "$0: You must have admin rights to run this" >&2
address@hidden@    exit 1
address@hidden@  fi
address@hidden@  # End Cygwin specific.
address@hidden@  echo "$0: You must run this as root" >&2
address@hidden@  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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]