The following commit has been merged in the master branch:
commit 26c61140a5308dba3c9e04411b54dea171d14018
Author: Patrick Schoenfeld <[email protected]>
Date: Thu Apr 21 13:20:49 2011 +0200
checkbashisms: add stdin support
* checkbashisms:
- add code to detect weither STDIN is a pipe and if so, write the lines
passed
via stdin to a tempfile
- add tempfile filename to the list of files to process
- add logic to detect if filename is a tempfile and if so, use the string
"(stdin)" for filename display instead of the real filename.
(Closes: #586500)
diff --git a/debian/changelog b/debian/changelog
index d77bb40..2e7a2d5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -15,7 +15,16 @@ devscripts (2.10.73) UNRELEASED; urgency=low
* debcommit: Support for commiting from debian/ when using bzr. Thanks to
Loïc Minier for the patch. (Closes: #580861)
- -- Benjamin Drung <[email protected]> Wed, 20 Apr 2011 18:52:18 +0200
+ [ Patrick Schoenfeld ]
+ * checkbashisms:
+ - add code to detect weither STDIN is a pipe and if so, write the lines
+ passed via stdin to a tempfile
+ - add tempfile filename to the list of files to process
+ - add logic to detect if filename is a tempfile and if so, use the string
+ "(stdin)" for filename display instead of the real filename.
+ (Closes: #586500)
+
+ -- Patrick Schoenfeld <[email protected]> Thu, 21 Apr 2011 13:13:43 +0200
devscripts (2.10.72) unstable; urgency=low
diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
index 5c3252c..45cfbc9 100755
--- a/scripts/checkbashisms.pl
+++ b/scripts/checkbashisms.pl
@@ -22,6 +22,7 @@
use strict;
use Getopt::Long;
+use File::Temp qw/tempfile/;
sub init_hashes;
@@ -47,6 +48,17 @@ EOF
my ($opt_echo, $opt_force, $opt_extra, $opt_posix);
my ($opt_help, $opt_version);
+my @filenames;
+
+# Detect if STDIN is a pipe
+if (-p STDIN or -f STDIN) {
+ my ($tmp_fh, $tmp_filename) = tempfile("chkbashisms_tmp.XXXX", TMPDIR =>
1, UNLINK => 1);
+ while (my $line = <STDIN>) {
+ print $tmp_fh $line;
+ }
+ close($tmp_fh);
+ push(@ARGV, $tmp_filename);
+}
##
## handle command-line options
@@ -77,22 +89,27 @@ init_hashes;
foreach my $filename (@ARGV) {
my $check_lines_count = -1;
+ my $display_filename = $filename;
+ if ($filename =~ /chkbashisms_tmp\.....$/) {
+ $display_filename = "(stdin)";
+ }
+
if (!$opt_force) {
$check_lines_count = script_is_evil_and_wrong($filename);
}
if ($check_lines_count == 0 or $check_lines_count == 1) {
- warn "script $filename does not appear to be a /bin/sh script;
skipping\n";
+ warn "script $display_filename does not appear to be a /bin/sh script;
skipping\n";
next;
}
if ($check_lines_count != -1) {
- warn "script $filename appears to be a shell wrapper; only checking the
first "
+ warn "script $display_filename appears to be a shell wrapper; only
checking the first "
. "$check_lines_count lines\n";
}
unless (open C, '<', $filename) {
- warn "cannot open script $filename for reading: $!\n";
+ warn "cannot open script $display_filename for reading: $!\n";
$status |= 2;
next;
}
@@ -123,18 +140,18 @@ foreach my $filename (@ARGV) {
next if $opt_force;
if ($interpreter =~ m,/bash$,) {
- warn "script $filename is already a bash script;
skipping\n";
+ warn "script $display_filename is already a bash script;
skipping\n";
$status |= 2;
last; # end this file
}
elsif ($interpreter !~ m,/(sh|posh)$,) {
### ksh/zsh?
- warn "script $filename does not appear to be a /bin/sh
script; skipping\n";
+ warn "script $display_filename does not appear to be a
/bin/sh script; skipping\n";
$status |= 2;
last;
}
} else {
- warn "script $filename does not appear to have a \#!
interpreter line;\nyou may get strange results\n";
+ warn "script $display_filename does not appear to have a \#!
interpreter line;\nyou may get strange results\n";
}
}
@@ -314,7 +331,7 @@ foreach my $filename (@ARGV) {
$found = 1;
$match = $1;
$explanation = "sourced script with arguments";
- output_explanation($filename, $orig_line, $explanation);
+ output_explanation($display_filename, $orig_line,
$explanation);
}
}
@@ -330,7 +347,7 @@ foreach my $filename (@ARGV) {
$found = 1;
$match = $1;
$explanation = $expl;
- output_explanation($filename, $orig_line, $explanation);
+ output_explanation($display_filename, $orig_line,
$explanation);
}
}
@@ -338,7 +355,7 @@ foreach my $filename (@ARGV) {
if ($line =~ m/(.*)($re)/){
my $count = () = $1 =~ /(^|[^\\])\'/g;
if( $count % 2 == 0 ) {
- output_explanation($filename, $orig_line, q<$'...' should
be "$(printf '...')">);
+ output_explanation($display_filename, $orig_line, q<$'...'
should be "$(printf '...')">);
}
}
@@ -364,7 +381,7 @@ foreach my $filename (@ARGV) {
if ($line =~ m/(.*)($re)/){
my $count = () = $1 =~ /(^|[^\\])\"/g;
if( $count % 2 == 0 ) {
- output_explanation($filename, $orig_line, q<$"foo" should
be eval_gettext "foo">);
+ output_explanation($display_filename, $orig_line, q<$"foo"
should be eval_gettext "foo">);
}
}
@@ -373,7 +390,7 @@ foreach my $filename (@ARGV) {
$found = 1;
$match = $1;
$explanation = $expl;
- output_explanation($filename, $orig_line, $explanation);
+ output_explanation($display_filename, $orig_line,
$explanation);
}
}
@@ -386,7 +403,7 @@ foreach my $filename (@ARGV) {
$found = 1;
$match = $1;
$explanation = $expl;
- output_explanation($filename, $orig_line, $explanation);
+ output_explanation($display_filename, $orig_line,
$explanation);
}
}
--
Git repository for devscripts
--
To unsubscribe, send mail to [email protected].