       0     STS invalid      unmasked
      ˆ¾‘äÇò 8àG$¯É FËßÏÃƒh¹ÆÊÉ      disabled
  6   ˆl–äY>”Ên-ji@¿pB¸ÈÅ£�þ]+$YÁ	Çã„óïùÄ„dL…ÏÇËÊ ?÷     #!/usr/bin/perl

# This script is essentially copied from /usr/share/lintian/checks/scripts,
# which is:
#   Copyright (C) 1998 Richard Braakman
#   Copyright (C) 2002 Josip Rodin
# This version is
#   Copyright (C) 2003 Julian Gilbey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

use strict;
use warnings;
use Getopt::Long qw(:config bundling permute no_getopt_compat);
use File::Temp   qw/tempfile/;

sub init_hashes;

(my $progname = $0) =~ s|.*/||;

my $usage = <<"EOF";
Usage: $progname [-n] [-f] [-x] [-e] [-l] script ...
   or: $progname --help
   or: $progname --version
This script performs basic checks for the presence of bashisms
in /bin/sh scripts and the lack of bashisms in /bin/bash ones.
EOF

my $version = <<"EOF";
This is $progname, from the Debian devscripts package, version 2.23.4+deb12u2
This code is copyright 2003 by Julian Gilbey <jdg\@debian.org>,
based on original code which is copyright 1998 by Richard Braakman
and copyright 2002 by Josip Rodin.
This program comes with ABSOLUTELY NO WARRANTY.
You are free to redistribute this code under the terms of the
GNU General Public License, version 2, or (at your option) any later version.
EOF

my ($opt_echo, $opt_force, $opt_extra, $opt_posix, $opt_early_fail, $opt_lint);
my ($opt_help, $opt_version);
my @filenames;

# Detect if STDIN is a pipe
if (scalar(@ARGV) == 0 && (-p STDIN or -f STDIN)) {
    push(@ARGV, '-');
}

##
## handle command-line options
##
$opt_help = 1 if int(@ARGV) == 0;

GetOptions(
    "help|h"       => \$opt_help,
    "version|v"    => \$opt_version,
    "newline|n"    => \$opt_echo,
    "lint|l"       => \$opt_lint,
    "force|f"      => \$opt_force,
    "extra|x"      => \$opt_extra,
    "posix|p"      => \$opt_posix,
    "early-fail|e" => \$opt_early_fail,
  )
  or die
"Usage: $progname [options] filelist\nRun $progname --help for more details\n";

if ($opt_help)    { print $usage;   exit 0; }
if ($opt_version) { print $version; exit 0; }

$opt_echo = 1 if $opt_posix;

my $mode     = 0;
my $issues   = 0;
my $status   = 0;
my $makefile = 0;
my (%bashisms, %string_bashisms, %singlequote_bashisms);

my $LEADIN
  = qr'(?:(?:^|[`&;(|{])\s*|(?:(?:if|elif|while)(?:\s+!)?|then|do|shell)\s+)';
init_hashes;

my @bashisms_keys             = sort keys %bashisms;
my @string_bashisms_keys      = sort keys %string_bashisms;
my @singlequote_bashisms_keys = sort keys %singlequote_bashisms;

foreach my $filename (@ARGV) {
    my $check_lines_count = -1;

    my $display_filename = $filename;

    if ($filename eq '-') {
        my $tmp_fh;
        ($tmp_fh, $filename)
          = tempfile("chkbashisms_tmp.XXXX", TMPDIR => 1, UNLINK => 1);
        while (my $line = <STDIN>) {
            print $tmp_fh $line;
        }
        close($tmp_fh);
        $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 $display_filename does not appear to be a /bin/sh script; skipping\n";
        next;
    }

    if ($check_lines_count != -1) {
        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 $display_fi