Skip to contentSkip to conversation

Option handling in grub-mkconfig

DISCUSSION Grégoire Sutre 4 participants 7 messages May 21, 2010 – May 24, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

The processing of option `-o' in grub-mkconfig only works when it is the first option. The code is:

# Check the arguments.
for option in "$@"; do
case "$option" in
[...]

    -o)
	shift
	grub_cfg=$1
	;;
    --output=*)
	grub_cfg=`echo "$option" | sed 's/--output=//'`
	;;

For instance:

grub-mkconfig -o /tmp/tata -o /tmp/titi
rm: invalid option -- 'o'
Try `rm --help' for more information.

grub-mkconfig --output=/tmp/tata -o /tmp/titi
rm: invalid option -- 'o'
Try `rm --help' for more information.

AFAICS, other scripts (grub-install, grub-mkrescue) only support the long option (--output=FILE).

The simpler solution would be to get rid of `-o' in grub-mkconfig, but this would break some user/distribution scripts (e.g. Debian's update-grub).

What do you think?

Grégoire

#1 lore raw
Quoted 7 lines · Grégoire Sutre

The processing of option `-o' in grub-mkconfig only works when it is the first option. The code is:

# Check the arguments.
for option in "$@"; do
case "$option" in
[...]

Quoted 7 lines
    -o)
	shift
	grub_cfg=$1
	;;
    --output=*)
	grub_cfg=`echo "$option" | sed 's/--output=//'`
	;;

How about:

=== modified file 'util/grub-mkconfig.in'

grub-mkconfig.in +12 -2
@@ -50,7 +50,13 @@ EOF
 }
 
 # Check the arguments.
+next_grub_cfg=false
 for option in "$@"; do
+    if $next_grub_cfg; then
+	grub_cfg=$option
+	next_grub_cfg=false
+	continue
+    fi
     case "$option" in
     -h | --help)
 	usage
@@ -59,8 +65,7 @@ for option in "$@"; do
 	echo "$0 (GNU GRUB ${package_version})"
 	exit 0 ;;
     -o)
-	shift
-	grub_cfg=$1
+	next_grub_cfg=:
 	;;
     --output=*)
 	grub_cfg=`echo "$option" | sed 's/--output=//'`
@@ -72,6 +77,11 @@ for option in "$@"; do
 	;;
     esac
 done
+if $next_grub_cfg; then
+    echo "Missing argument to \`-o'" 1>&2
+    usage
+    exit 1
+fi
 
 . ${libdir}/grub/grub-mkconfig_lib
 
Signature · 1 line
Colin Watson                                       [[email protected]]
#2 lore raw

On 05/21/2010 12:57 PM, Colin Watson wrote:

Thanks for the patch, it works fine. I'm just wondering: Is keeping `-o' worth the extra complication?

Grégoire

Quoted 42 lines

How about:

=== modified file 'util/grub-mkconfig.in'

grub-mkconfig.in +12 -2
@@ -50,7 +50,13 @@ EOF
  }
 
  # Check the arguments.
+next_grub_cfg=false
  for option in "$@"; do
+    if $next_grub_cfg; then
+	grub_cfg=$option
+	next_grub_cfg=false
+	continue
+    fi
      case "$option" in
      -h | --help)
  	usage
@@ -59,8 +65,7 @@ for option in "$@"; do
  	echo "$0 (GNU GRUB ${package_version})"
  	exit 0 ;;
      -o)
-	shift
-	grub_cfg=$1
+	next_grub_cfg=:
  	;;
      --output=*)
  	grub_cfg=`echo "$option" | sed 's/--output=//'`
@@ -72,6 +77,11 @@ for option in "$@"; do
  	;;
      esac
  done
+if $next_grub_cfg; then
+    echo "Missing argument to \`-o'" 1>&2
+    usage
+    exit 1
+fi
 
  . ${libdir}/grub/grub-mkconfig_lib
 
#3 lore raw
Quoted 2 lines · Grégoire Sutre

Thanks for the patch, it works fine. I'm just wondering: Is keeping `-o' worth the extra complication?

I think so. It's probably stuck in a number of people's heads by now.

If we want to simplify things, we should use something like getopt(1) as I think I proposed a while back, although that's not entirely without its problems. TBH I don't think the complication here is a big deal; it's just one option and it doesn't change often.

Signature · 1 line
Colin Watson                                       [[email protected]]
#4 lore raw
Quoted 11 lines · Colin Watson
Quoted 3 lines · Grégoire Sutre

Thanks for the patch, it works fine. I'm just wondering: Is keeping `-o' worth the extra complication?

I think so. It's probably stuck in a number of people's heads by now.

If we want to simplify things, we should use something like getopt(1) as I think I proposed a while back, although that's not entirely without its problems.

What are the problems with getopt? Cross-vendor compatibility? Can it be alleviated the gnulib way?

Quoted 4 lines

TBH I don't think the complication here is a big deal;
it's just one option and it doesn't change often.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#5 lore raw
In reply to Grégoire Sutre

2010/5/21 Grégoire Sutre <[email protected]>:

Quoted 4 lines

The processing of option `-o' in grub-mkconfig only works when it is the first option.

IMO this issue might have been fixed in experimental branch, by fix-cmdline-parsing (or similar) branch. I am on travel, so I cannot confirm this now :-(

Signature · 1 line
bvk.chaitanya
#6 lore raw
Quoted 9 lines · BVK Chaitanya

2010/5/21 Grégoire Sutre<[email protected]>:

Quoted 4 lines

The processing of option `-o' in grub-mkconfig only works when it is the first option.

IMO this issue might have been fixed in experimental branch, by fix-cmdline-parsing (or similar) branch. I am on travel, so I cannot confirm this now :-(

I confirm that the fix-cmdline-arg-parsing branch does not have this problem.

Grégoire