From: Christian Franke <Christian.Franke@t-online.de>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] update-grub for Cygwin
Date: Sat, 26 Jul 2008 14:53:11 +0200 [thread overview]
Message-ID: <488B1E37.5000101@t-online.de> (raw)
In-Reply-To: <20080725204016.GD18149@thorin>
[-- 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
next prev parent reply other threads:[~2008-07-26 12:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2008-07-27 6:09 ` Pavel Roskin
2008-07-27 12:39 ` Robert Millan
2008-07-29 15:40 ` Christian Franke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=488B1E37.5000101@t-online.de \
--to=christian.franke@t-online.de \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.