The following commit has been merged in the master branch:
commit 734dce3ba926cd39d6df7602a4dd027e77bacf95
Author: James Vega <[email protected]>
Date:   Thu Sep 22 20:57:02 2011 -0400

    Update scripts to use GNU getopt-compatible option parsing.
    
    For Perl scripts, use Getopt::Long's "gnu_compat" and "bundling" modes.  
When
    allowed, also use "permute" for full GNU getopt compatibility.
    
    For shell scripts, use getopt instead of manual option parsing.
    - Update uses of getopt to show usage when getopt fails.
    
    Closes: #641979
    Signed-off-by: James Vega <[email protected]>

diff --git a/debian/changelog b/debian/changelog
index 1b17ec5..e754fad 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -8,6 +8,12 @@ devscripts (2.11.2) UNRELEASED; urgency=low
   * Remove support for PGP-style commands from debsign/debrsign.  (Closes:
     #639204)
     + DEBSIGN_SIGNLIKE config variable removed
+  * Update scripts to use GNU getopt-compatible option parsing. (Closes:
+    #641979)
+    + For Perl scripts, use Getopt::Long's "gnu_compat" and "bundling" modes.
+      When allowed, also use "permute" for full GNU getopt compatibility.
+    + For shell scripts, use getopt instead of manual option parsing.
+      - Update uses of getopt to show usage when getopt fails.
 
  -- Gerfried Fuchs <[email protected]>  Fri, 26 Aug 2011 21:09:51 +0200
 
diff --git a/scripts/bts.pl b/scripts/bts.pl
index 8b8ce2e..9f011d0 100755
--- a/scripts/bts.pl
+++ b/scripts/bts.pl
@@ -561,7 +561,7 @@ my $opt_ccemail = "";
 my $use_default_cc = 1;
 my $ccsecurity="";
 
-Getopt::Long::Configure('require_order');
+Getopt::Long::Configure(qw(gnu_compat bundling require_order));
 GetOptions("help|h" => \$opt_help,
           "version" => \$opt_version,
           "o" => \$offlinemode,
diff --git a/scripts/build-rdeps.pl b/scripts/build-rdeps.pl
index 1a6ea36..c425509 100755
--- a/scripts/build-rdeps.pl
+++ b/scripts/build-rdeps.pl
@@ -92,7 +92,7 @@ use warnings;
 use strict;
 use File::Basename;
 use File::Find;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use Pod::Usage;
 use Data::Dumper;
 my $progname = basename($0);
@@ -270,7 +270,6 @@ sub findreversebuilddeps {
 if ($#ARGV < 0) { usage; exit(0); }
 
 
-Getopt::Long::Configure('bundling');
 GetOptions(
        "u|update" => \$opt_update,
        "s|sudo" => \$opt_sudo,
diff --git a/scripts/chdist.pl b/scripts/chdist.pl
index 223df33..0652edc 100755
--- a/scripts/chdist.pl
+++ b/scripts/chdist.pl
@@ -132,7 +132,7 @@ use feature 'switch';
 use File::Copy qw(cp);
 use File::Path qw(make_path);
 use File::Basename;
-use Getopt::Long qw(:config require_order);
+use Getopt::Long qw(:config gnu_compat bundling require_order);
 use Cwd qw(abs_path cwd);
 use Dpkg::Version;
 use Pod::Usage;
diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index d6a79d7..647a712 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -21,7 +21,7 @@
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Temp qw/tempfile/;
 
 sub init_hashes;
diff --git a/scripts/dcontrol.pl b/scripts/dcontrol.pl
index e18909e..deac5c6 100755
--- a/scripts/dcontrol.pl
+++ b/scripts/dcontrol.pl
@@ -20,7 +20,7 @@
 
 use strict;
 use File::Basename;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 
 BEGIN {
     # Load the URI::Escape and LWP::UserAgent modules safely
@@ -169,7 +169,6 @@ if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
 }
 
 # handle options
-Getopt::Long::Configure('bundling');
 GetOptions(
     "d|debug"      =>  \$opt->{'debug'},
     "s|show-suite" =>  \$opt->{'show-suite'},
diff --git a/scripts/dd-list.pl b/scripts/dd-list.pl
index f91bea8..ed77796 100755
--- a/scripts/dd-list.pl
+++ b/scripts/dd-list.pl
@@ -20,7 +20,7 @@
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 
 my $version='###VERSION###';
 
diff --git a/scripts/debchange.pl b/scripts/debchange.pl
index 306445c..9f68276 100755
--- a/scripts/debchange.pl
+++ b/scripts/debchange.pl
@@ -35,7 +35,7 @@ use open ':utf8';  # changelogs are written with UTF-8 
encoding
 use filetest 'access';  # use access rather than stat for -w
 # for checking whether user names are valid and making format() behave
 use Encode qw/decode_utf8 encode_utf8/;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Copy;
 use File::Basename;
 use Cwd;
diff --git a/scripts/debcheckout.pl b/scripts/debcheckout.pl
index 6429863..6224427 100755
--- a/scripts/debcheckout.pl
+++ b/scripts/debcheckout.pl
@@ -223,7 +223,7 @@ B<debcheckout> and this manpage have been written by 
Stefano Zacchiroli
 use feature 'switch';
 use strict;
 use warnings;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use Pod::Usage;
 use File::Basename;
 use File::Copy qw/copy/;
diff --git a/scripts/debcommit.pl b/scripts/debcommit.pl
index 6bd0b81..815b786 100755
--- a/scripts/debcommit.pl
+++ b/scripts/debcommit.pl
@@ -170,7 +170,7 @@ options to "bzr commit" will be generated to associate the 
revision and the bugs
 
 use warnings;
 use strict;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use Cwd;
 use Dpkg::Changelog;
 use File::Basename;
@@ -307,7 +307,6 @@ for (qw"debian/changelog changelog") {
 
 # Now read the command line arguments
 
-Getopt::Long::Configure("bundling");
 if (! GetOptions(
                 "r|release" => \$release,
                 "m|message=s" => \$message,
diff --git a/scripts/debi.pl b/scripts/debi.pl
index cb1b903..1668eda 100755
--- a/scripts/debi.pl
+++ b/scripts/debi.pl
@@ -25,7 +25,7 @@
 
 use 5.008;
 use strict;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 use filetest 'access';
 use Cwd;
diff --git a/scripts/debsign.sh b/scripts/debsign.sh
index 4ddba0f..3751ca9 100755
--- a/scripts/debsign.sh
+++ b/scripts/debsign.sh
@@ -310,40 +310,38 @@ else
     fi
 fi
 
-while [ $# != 0 ]
+TEMP=$(getopt -n "$PROGNAME" -o 'p:m:e:k:Sa:t:r:h' \
+             -l 'multi,re-sign,no-re-sign,debs-dir:' \
+             -l 'noconf,no-conf,help,version' \
+             -- "$@") || (rc=$?; usage >&2; exit $rc)
+
+eval set -- "$TEMP"
+
+while true
 do
-    value="`echo x\"$1\" | sed -e 's/^x-.//'`"
     case "$1" in
-       -p*)    signcommand="$value" ;;
-       -m*)    maint="$value" ;;
-       -e*)    maint="$value" ;;     # Order matters: -m before -e!
-       -k*)    signkey="$value" ;;
-       -S)     sourceonly="true" ;;
-       -a*)    targetarch="$value" ;;
-       -t*)    targetgnusystem="$value" ;;
+       -p) signcommand="$2"; shift ;;
+       -m) maint="$2"; shift ;;
+       -e) maint="$2"; shift ;;
+       -k) signkey="$2"; shift ;;
+       -S) sourceonly="true" ;;
+       -a) targetarch="$2"; shift ;;
+       -t) targetgnusystem="$2"; shift ;;
        --multi) multiarch="true" ;;
        --re-sign)    opt_re_sign="true" ;;
        --no-re-sign) opt_re_sign="false" ;;
-       -r*)    if [ -n "$value" ]; then remotehost=$value;
-               elif [ $# -lt 1 ]; then
-                   echo "$PROGNAME: -r option missing argument!" >&2
-                   usage >&2; exit 1;
-               else shift; remotehost=$1;
-               fi
+       -r)     remotehost=$2; shift
                # Allow for the [user@]host:filename format
-               hostpart="`echo $remotehost | sed -e 's/:.*//'`"
-               filepart="`echo $remotehost | sed -e 's/[^:]*:\?//'`"
-               if [ -n "$filepart" ]; then
+               hostpart="${remotehost%:*}"
+               filepart="${remotehost#*:}"
+               if [ -n "$filepart" -a "$filepart" != "$remotehost" ]; then
                    remotehost="$hostpart"
                    set -- "$@" "$filepart"
                fi
                ;;
-       --debs-dir=*)
-           opt_debsdir="`echo \"$1\" | sed -e 's/^--debs-dir=//; s%/\+%/%g; 
s%\(.\)/$%\1%;'`"
-           ;;
        --debs-dir)
            shift
-           opt_debsdir="`echo \"$1\" | sed -e 's%/\+%/%g; s%\(.\)/$%\1%;'`"
+           opt_debsdir="$(echo \"${1%/}\" | sed -e 's%/\+%/%g')"
            ;;
        --no-conf|--noconf)
                echo "$PROGNAME: $1 is only acceptable as the first 
command-line option!" >&2
@@ -352,9 +350,7 @@ do
                usage; exit 0 ;;
        --version)
                version; exit 0 ;;
-       -*)     echo "$PROGNAME: Unrecognised option: $1" >&2
-               usage >&2; exit 1 ;;
-       *)      break ;;
+       --)     shift; break ;;
     esac
     shift
 done
diff --git a/scripts/debsnap.pl b/scripts/debsnap.pl
index 7778631..e8065d5 100755
--- a/scripts/debsnap.pl
+++ b/scripts/debsnap.pl
@@ -18,7 +18,7 @@
 use strict;
 use warnings;
 
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 use Cwd qw/cwd abs_path/;
 use File::Path qw/make_path/;
diff --git a/scripts/desktop2menu.pl b/scripts/desktop2menu.pl
index d3b9b51..cb1b644 100755
--- a/scripts/desktop2menu.pl
+++ b/scripts/desktop2menu.pl
@@ -58,7 +58,7 @@ Sune Vuorela <[email protected]> with modifications by Adam 
D. Barratt
 
 use warnings;
 use strict;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 
 my $progname = basename($0);
diff --git a/scripts/dget.pl b/scripts/dget.pl
index 7ecb049..ef2d8de 100755
--- a/scripts/dget.pl
+++ b/scripts/dget.pl
@@ -31,7 +31,7 @@ use Cwd qw(abs_path);
 use IO::Dir;
 use IO::File;
 use Digest::MD5;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 
 # global variables
diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index 4c5a41c..ddbd037 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -125,7 +125,7 @@ Adam D. Barratt <[email protected]>
 
 use strict;
 use warnings;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 
 sub fatal($);
diff --git a/scripts/mass-bug.pl b/scripts/mass-bug.pl
index a3b3f01..bf9d0e6 100755
--- a/scripts/mass-bug.pl
+++ b/scripts/mass-bug.pl
@@ -149,7 +149,7 @@ F</usr/sbin/sendmail>.  Same as the B<--sendmail> command 
line option.
 =cut
 
 use strict;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use Text::Wrap;
 use File::Basename;
 
diff --git a/scripts/mk-build-deps.pl b/scripts/mk-build-deps.pl
index f321e7b..61ebd3e 100755
--- a/scripts/mk-build-deps.pl
+++ b/scripts/mk-build-deps.pl
@@ -104,7 +104,7 @@ General Public License, version 2 or later.
 
 use strict;
 use warnings;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 use Pod::Usage;
 use Dpkg::Control;
diff --git a/scripts/nmudiff.sh b/scripts/nmudiff.sh
index 641a53c..0dd08c9 100755
--- a/scripts/nmudiff.sh
+++ b/scripts/nmudiff.sh
@@ -1,4 +1,4 @@
-#! /bin/bash -e
+#! /bin/bash
 # Copyright 2006 by Steinar H. Gunderson
 #
 # This program is free software; you can redistribute it and/or modify
@@ -12,6 +12,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
+set -e
 
 PROGNAME=`basename $0`
 MODIFIED_CONF_MSG='Default settings modified by devscripts configuration 
files:'
@@ -145,8 +146,7 @@ TEMP=$(getopt -s bash -o "h" \
        --long sendmail:,from:,new,old,mutt,no-mutt,nomutt \
        --long delay:,no-delay,nodelay \
        --long no-conf,noconf \
-       --long help,version -n "$PROGNAME" -- "$@")
-if [ $? != 0 ] ; then exit 1 ; fi
+        --long help,version -n "$PROGNAME" -- "$@") || (usage >&2; exit 1)
 
 eval set -- $TEMP
 
diff --git a/scripts/plotchangelog.pl b/scripts/plotchangelog.pl
index c530027..64c8cfd 100755
--- a/scripts/plotchangelog.pl
+++ b/scripts/plotchangelog.pl
@@ -29,7 +29,7 @@ use FileHandle;
 use File::Basename;
 use File::Temp qw/ tempfile /;
 use Fcntl;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 
 BEGIN {
     eval { require Date::Parse; import Date::Parse (); };
diff --git a/scripts/pts-subscribe.sh b/scripts/pts-subscribe.sh
index 60a80c7..8daf597 100755
--- a/scripts/pts-subscribe.sh
+++ b/scripts/pts-subscribe.sh
@@ -1,4 +1,5 @@
-#! /bin/bash -e
+#! /bin/bash
+set -e
 
 # Subscribe to the PTS for a specified package for a limited length of time
 
@@ -100,7 +101,7 @@ fi
 TEMP=$(getopt -s bash -o "u:" \
        --long until:,forever \
        --long no-conf,noconf \
-       --long help,version -n "$PROGNAME" -- "$@")
+       --long help,version -n "$PROGNAME" -- "$@") || (usage >&2; exit 1)
 
 eval set -- $TEMP
 
diff --git a/scripts/rc-alert.pl b/scripts/rc-alert.pl
index b4003db..610cc65 100755
--- a/scripts/rc-alert.pl
+++ b/scripts/rc-alert.pl
@@ -24,7 +24,7 @@ use warnings;
 use lib '/usr/share/devscripts';
 use Devscripts::Packages;
 use File::Basename;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 
 sub remove_duplicate_values($);
 sub store_if_relevant(%);
diff --git a/scripts/rmadison.pl b/scripts/rmadison.pl
index 4cad888..76a622f 100755
--- a/scripts/rmadison.pl
+++ b/scripts/rmadison.pl
@@ -20,7 +20,7 @@
 
 use strict;
 use File::Basename;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 
 BEGIN {
     # Load the URI::Escape module safely
@@ -118,7 +118,6 @@ if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
     }
 }
 
-Getopt::Long::config('bundling');
 unless (GetOptions(
     '-a=s'                =>  \$params->{'architecture'},
     '--architecture=s'    =>  \$params->{'architecture'},
diff --git a/scripts/tagpending.pl b/scripts/tagpending.pl
index dcf2a9d..602df44 100755
--- a/scripts/tagpending.pl
+++ b/scripts/tagpending.pl
@@ -26,7 +26,7 @@
 
 use strict;
 use warnings;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 use lib '/usr/share/devscripts';
 use Devscripts::Debbugs;
@@ -50,7 +50,6 @@ $opt_to = '';
 $opt_comments = 1;
 $opt_interactive = 0;
 
-Getopt::Long::Configure ("bundling");
 GetOptions("help|h" => \$opt_help,
           "version" => \$opt_version,
           "verbose|v!" => \$opt_verbose,
diff --git a/scripts/transition-check.pl b/scripts/transition-check.pl
index 3554d4f..81a3d28 100755
--- a/scripts/transition-check.pl
+++ b/scripts/transition-check.pl
@@ -86,7 +86,7 @@ Adam D. Barratt <I<[email protected]>>
 
 use warnings;
 use strict;
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 
 my $progname = basename($0);
diff --git a/scripts/uscan.pl b/scripts/uscan.pl
index 289e66c..2962c47 100755
--- a/scripts/uscan.pl
+++ b/scripts/uscan.pl
@@ -29,7 +29,7 @@ use File::Basename;
 use File::Copy;
 use File::Temp qw/tempdir/;
 use filetest 'access';
-use Getopt::Long;
+use Getopt::Long qw(:config gnu_getopt);
 use lib '/usr/share/devscripts';
 use Devscripts::Versort;
 use Text::ParseWords;
diff --git a/scripts/uupdate.sh b/scripts/uupdate.sh
index 4010a32..76be6d9 100755
--- a/scripts/uupdate.sh
+++ b/scripts/uupdate.sh
@@ -173,8 +173,7 @@ TEMP=$(getopt -s bash -o v:p:r:ubs \
        --long pristine,no-pristine,nopristine \
        --long symlink,no-symlink,nosymlink \
        --long no-conf,noconf \
-       --long help,version -n "$PROGNAME" -- "$@")
-if [ $? != 0 ] ; then exit 1 ; fi
+       --long help,version -n "$PROGNAME" -- "$@") || (usage >&2; exit 1)
 
 eval set -- $TEMP
 
diff --git a/scripts/who-uploads.sh b/scripts/who-uploads.sh
index 519ab39..332314b 100755
--- a/scripts/who-uploads.sh
+++ b/scripts/who-uploads.sh
@@ -148,8 +148,7 @@ TEMP=$(getopt -s bash -o 'h' \
        --long date,nodate,no-date \
        --long help,version \
        --options M: \
-       -n "$PROGNAME" -- "$@")
-if [ $? != 0 ] ; then exit 1 ; fi
+       -n "$PROGNAME" -- "$@") || (usage >&2; exit 1)
 
 eval set -- $TEMP
 

-- 
Git repository for devscripts


-- 
To unsubscribe, send mail to [email protected].

Reply via email to