From b02c7c8fb57a92cd04a84d32bb67c6142980f144 Mon Sep 17 00:00:00 2001 From: BVK Chaitanya Date: Mon, 12 Apr 2010 21:33:03 +0530 Subject: [PATCH] added getopt like error for missing option parameters --- util/grub-install.in | 27 ++++++++++++++++++-------- util/grub-mkconfig.in | 19 +++++++++++++++--- util/grub-mkrescue.in | 19 ++++++++++++++---- util/grub-reboot.in | 13 ++++++++++++- util/grub-set-default.in | 13 ++++++++++++- util/i386/efi/grub-install.in | 21 +++++++++++++++----- util/ieee1275/grub-install.in | 21 +++++++++++++++----- util/powerpc/ieee1275/grub-mkrescue.in | 17 +++++++++++++--- 8 files changed, 120 insertions(+), 30 deletions(-) diff --git a/util/grub-install.in b/util/grub-install.in index 7b9c04913..e5ed9dcd5 100644 --- a/util/grub-install.in +++ b/util/grub-install.in @@ -105,6 +105,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + # Check the arguments. while test $# -gt 0 do @@ -120,37 +131,37 @@ do exit 0 ;; --modules) - modules=$1; shift;; + modules=`argument $option "$@"`; shift;; --modules=*) modules=`echo "$option" | sed 's/--modules=//'` ;; --font) - font=$1; shift;; + font=`argument $option "$@"`; shift;; --font=*) font=`echo "$option" | sed 's/--font=//'` ;; --root-directory) - rootdir=$1; shift;; + rootdir=`argument $option "$@"`; shift;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; --grub-setup) - grub_setup=$1; shift;; + grub_setup=`argument $option "$@"`; shift;; --grub-setup=*) grub_setup=`echo "$option" | sed 's/--grub-setup=//'` ;; --grub-mkimage) - grub_mkimage=$1; shift;; + grub_mkimage=`argument $option "$@"`; shift;; --grub-mkimage=*) grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; --grub-mkdevicemap) - grub_mkdevicemap=$1; shift;; + grub_mkdevicemap=`argument $option "$@"`; shift;; --grub-mkdevicemap=*) grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; --grub-probe) - grub_probe=$1; shift;; + grub_probe=`argument $option "$@"`; shift;; --grub-probe=*) grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;; @@ -161,7 +172,7 @@ do --disk-module) if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then - disk_module=$1; shift; + disk_module=`argument $option "$@"`; shift; fi ;; --disk-module=*) if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in index 82964836b..c3aa57723 100644 --- a/util/grub-mkconfig.in +++ b/util/grub-mkconfig.in @@ -49,6 +49,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + # Check the arguments. while test $# -gt 0 do @@ -63,9 +74,7 @@ do echo "$0 (GNU GRUB ${package_version})" exit 0 ;; -o | --output) - grub_cfg=$1 - shift - ;; + grub_cfg=`argument $option "$@"`; shift;; --output=*) grub_cfg=`echo "$option" | sed 's/--output=//'` ;; @@ -74,6 +83,10 @@ do usage exit 1 ;; + *) + echo "Invalid parameter, $option" 1>&2 + exit 1 + ;; esac done diff --git a/util/grub-mkrescue.in b/util/grub-mkrescue.in index 64ccd6ae8..ffb987718 100644 --- a/util/grub-mkrescue.in +++ b/util/grub-mkrescue.in @@ -51,6 +51,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + # Check the arguments. while test $# -gt 0 do @@ -66,18 +77,18 @@ do exit 0 ;; --modules) - modules=$1; shift ;; + modules=`argument $option "$@"`; shift ;; --modules=*) modules=`echo "$option" | sed 's/--modules=//'` ;; -o | --output) - output_image=$1; shift ;; + output_image=`argument $option "$@"`; shift ;; --output=*) output_image=`echo "$option" | sed 's/--output=//'` ;; # Intentionally undocumented --override-directory) - override_dir=$1 + override_dir=`argument $option "$@"` shift PATH=${override_dir}:$PATH export PATH @@ -93,7 +104,7 @@ do exit 1 ;; *) - source="${source} ${option}" ;; + source="${source} ${option} $@"; break ;; esac done diff --git a/util/grub-reboot.in b/util/grub-reboot.in index eb7073e02..48e3ae243 100644 --- a/util/grub-reboot.in +++ b/util/grub-reboot.in @@ -44,6 +44,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + # Check the arguments. while test $# -gt 0 do @@ -59,7 +70,7 @@ do exit 0 ;; --root-directory) - rootdir=$1; shift ;; + rootdir=`argument $option "$@"`; shift ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; diff --git a/util/grub-set-default.in b/util/grub-set-default.in index 2636543c3..a4739f95f 100644 --- a/util/grub-set-default.in +++ b/util/grub-set-default.in @@ -44,6 +44,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + # Check the arguments. while test $# -gt 0 do @@ -59,7 +70,7 @@ do exit 0 ;; --root-directory) - rootdir=$1; shift ;; + rootdir=`argument $option "$@"`; shift ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; diff --git a/util/i386/efi/grub-install.in b/util/i386/efi/grub-install.in index 097519d50..54c190678 100644 --- a/util/i386/efi/grub-install.in +++ b/util/i386/efi/grub-install.in @@ -71,6 +71,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + # Check the arguments. while test $# -gt 0 do @@ -86,27 +97,27 @@ do exit 0 ;; --modules) - modules=$1; shift ;; + modules=`argument $option "$@"`; shift ;; --modules=*) modules=`echo "$option" | sed 's/--modules=//'` ;; --root-directory) - rootdir=$1; shift ;; + rootdir=`argument $option "$@"`; shift ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; --grub-mkimage) - grub_mkimage=$1; shift ;; + grub_mkimage=`argument $option "$@"`; shift ;; --grub-mkimage=*) grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; --grub-mkdevicemap) - grub_mkdevicemap=$1; shift ;; + grub_mkdevicemap=`argument $option "$@"`; shift ;; --grub-mkdevicemap=*) grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; --grub-probe) - grub_probe=$1; shift ;; + grub_probe=`argument $option "$@"`; shift ;; --grub-probe=*) grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;; diff --git a/util/ieee1275/grub-install.in b/util/ieee1275/grub-install.in index 4a5403c18..dde275c2a 100644 --- a/util/ieee1275/grub-install.in +++ b/util/ieee1275/grub-install.in @@ -74,6 +74,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + # Check the arguments. while test $# -gt 0 do @@ -89,27 +100,27 @@ do exit 0 ;; --modules) - modules=$1; shift ;; + modules=`argument $option "$@"`; shift ;; --modules=*) modules=`echo "$option" | sed 's/--modules=//'` ;; --root-directory) - rootdir=$1; shift ;; + rootdir=`argument $option "$@"`; shift ;; --root-directory=*) rootdir=`echo "$option" | sed 's/--root-directory=//'` ;; --grub-mkdevicemap) - grub_mkdevicemap=$1; shift ;; + grub_mkdevicemap=`argument $option "$@"`; shift ;; --grub-mkdevicemap=*) grub_mkdevicemap=`echo "$option" | sed 's/--grub-mkdevicemap=//'` ;; --grub-mkimage) - grub_mkimage=$1; shift ;; + grub_mkimage=`argument $option "$@"`; shift ;; --grub-mkimage=*) grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;; --grub-probe) - grub_probe=$1; shift ;; + grub_probe=`argument $option "$@"`; shift ;; --grub-probe=*) grub_probe=`echo "$option" | sed 's/--grub-probe=//'` ;; diff --git a/util/powerpc/ieee1275/grub-mkrescue.in b/util/powerpc/ieee1275/grub-mkrescue.in index 375adb0cb..1adc149ae 100644 --- a/util/powerpc/ieee1275/grub-mkrescue.in +++ b/util/powerpc/ieee1275/grub-mkrescue.in @@ -52,6 +52,17 @@ Report bugs to . EOF } +argument () { + opt=$1 + shift + + if test $# -eq 0; then + echo "$0: option requires an argument -- '$opt'" 1>&2 + exit 1 + fi + echo $1 +} + input_dir=${pkglibdir} # Check the arguments. @@ -69,17 +80,17 @@ do exit 0 ;; --modules) - modules=$1; shift ;; + modules=`argument $option "$@"`; shift ;; --modules=*) modules=`echo "$option" | sed 's/--modules=//'` ;; --pkglibdir) - input_dir=$1; shift ;; + input_dir=`argument $option "$@"`; shift ;; --pkglibdir=*) input_dir=`echo "$option" | sed 's/--pkglibdir=//'` ;; --grub-mkimage) - grub_mkimage=$1; shift ;; + grub_mkimage=`argument $option "$@"`; shift ;; --grub-mkimage=*) grub_mkimage=`echo "$option" | sed 's/--grub-mkimage=//'` ;;