diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-11-30 08:32:00 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-11-30 08:32:00 -0500 |
| commit | ea08c505099c6a230d89b570a397aee3529824ce (patch) | |
| tree | 05096fa9b1c97f5835f6730f56d68d3c15a23c2a /sbolint | |
| parent | 93b0c54145b52a510906d8787bb176902fe1e81a (diff) | |
| download | sbo-maintainer-tools-ea08c505099c6a230d89b570a397aee3529824ce.tar.gz | |
sbolint: replace tab indents with 2 spaces each.
Diffstat (limited to 'sbolint')
| -rwxr-xr-x | sbolint | 3190 |
1 files changed, 1595 insertions, 1595 deletions
@@ -398,23 +398,23 @@ use Getopt::Long qw/:config gnu_getopt no_require_order/; use Cwd qw/abs_path getcwd/; @boilerplate = ( - qr/#\s*REMOVE THIS ENTIRE BLOCK OF TEXT/, - qr/#\s*replace with (?:version:name) of program/, - qr/#\s*the "_SBo" is required/, - qr/#\s*Automatically determine the architecture we're building on/, - qr/#\s*Unless \$ARCH is already set,/, - qr/#\s*For consistency's sake, use this/, - qr/#\s*Drop the package in \/tmp/, - qr/#\s*Exit on most errors/, - qr/#\s*If you prefer to do selective error checking with/, - qr/#\s*Your application will probably need/, - qr/#\s*Compile the application and install it into the/, - qr/#\s*Strip binaries and libraries - this can be done with/, - qr/#\s*Compress man pages$/, - qr/#\s*Compress info pages and remove the/, - qr/#\s*Copy program documentation into the package/, - qr/#\s*Copy the slack-desc \(and a custom doinst\.sh if necessary\)/, - qr/#\s*Make the package; be sure to leave it in/, + qr/#\s*REMOVE THIS ENTIRE BLOCK OF TEXT/, + qr/#\s*replace with (?:version:name) of program/, + qr/#\s*the "_SBo" is required/, + qr/#\s*Automatically determine the architecture we're building on/, + qr/#\s*Unless \$ARCH is already set,/, + qr/#\s*For consistency's sake, use this/, + qr/#\s*Drop the package in \/tmp/, + qr/#\s*Exit on most errors/, + qr/#\s*If you prefer to do selective error checking with/, + qr/#\s*Your application will probably need/, + qr/#\s*Compile the application and install it into the/, + qr/#\s*Strip binaries and libraries - this can be done with/, + qr/#\s*Compress man pages$/, + qr/#\s*Compress info pages and remove the/, + qr/#\s*Copy program documentation into the package/, + qr/#\s*Copy the slack-desc \(and a custom doinst\.sh if necessary\)/, + qr/#\s*Make the package; be sure to leave it in/, ); # this was scraped from the HTML source for the upload form: @@ -440,85 +440,85 @@ $color_output = undef; # main() { GetOptions( - "all|a" => sub { $recursive_git = 1; $color_output = 0 unless defined $color_output; }, - "url-head|u" => \$url_head, - "download|d" => \$url_download, - "quiet|q" => \$quiet, - "version|v" => sub { print "$VERSION\n"; exit 0; }, - "no-warnings|e" => sub { $nowarn = 1; $nonote = 1;}, - "no-notes|n" => \$nonote, - "notes-as-warnings|N" => \$notes_as_warnings, - "no-readme|r" => \$suppress_readme_len, - "doc|help|h" => sub { exec("perldoc $0"); }, - "man" => sub { exec("pod2man --stderr -s1 -csbo-maintainer-tools -r$VERSION $0"); }, - "color|colour|c" => sub { $color_output = 1; }, - "mono|no-color|no-colour|m" => sub { $color_output = 0; }, - "U|update-package-list" => sub { exit &update_package_list; }, + "all|a" => sub { $recursive_git = 1; $color_output = 0 unless defined $color_output; }, + "url-head|u" => \$url_head, + "download|d" => \$url_download, + "quiet|q" => \$quiet, + "version|v" => sub { print "$VERSION\n"; exit 0; }, + "no-warnings|e" => sub { $nowarn = 1; $nonote = 1;}, + "no-notes|n" => \$nonote, + "notes-as-warnings|N" => \$notes_as_warnings, + "no-readme|r" => \$suppress_readme_len, + "doc|help|h" => sub { exec("perldoc $0"); }, + "man" => sub { exec("pod2man --stderr -s1 -csbo-maintainer-tools -r$VERSION $0"); }, + "color|colour|c" => sub { $color_output = 1; }, + "mono|no-color|no-colour|m" => sub { $color_output = 0; }, + "U|update-package-list" => sub { exit &update_package_list; }, ) or die_usage("Error in command line options"); $color_output = -t STDOUT unless defined $color_output; if(@ARGV && $ARGV[0] eq '-') { - $stdin = 1; + $stdin = 1; } if($color_output) { - $red = "\x1b[1;31m"; - $yellow = "\x1b[1;33m"; - $green = "\x1b[1;32m"; - $color_off = "\x1b[0m"; + $red = "\x1b[1;31m"; + $yellow = "\x1b[1;33m"; + $green = "\x1b[1;32m"; + $color_off = "\x1b[0m"; } else { - $red = ""; - $yellow = ""; - $green = ""; - $color_off = ""; + $red = ""; + $yellow = ""; + $green = ""; + $color_off = ""; } if($url_head && $url_download) { - die_usage("-u and -d options are mutually exclusive"); + die_usage("-u and -d options are mutually exclusive"); } if($url_head || $url_download) { - if(system("curl --version > /dev/null") != 0) { - die "$SELF: -u and -d options require curl, can't find it in your \$PATH.\n"; - } + if(system("curl --version > /dev/null") != 0) { + die "$SELF: -u and -d options require curl, can't find it in your \$PATH.\n"; + } } if($stdin) { - @ARGV = <STDIN>; - chomp for @ARGV; + @ARGV = <STDIN>; + chomp for @ARGV; } if($recursive_git) { - if(-t STDOUT) { - chomp (my $outfile = "$SELF.log." . `date +%Y%m%d`); - warn "$SELF: stdout is a terminal, redirecting to $outfile\n"; - if(rename $outfile, $outfile . ".old") { - warn "$SELF: renamed old $outfile to $outfile.old\n"; - } - open my $f, ">$outfile" or die $!; - *STDOUT = $f; - } - - @ARGV=(); - my $pwd; - - # find root of the SBo git repo, if we're somewhere inside it. - while(! -d ".git" && ! -d "system") { - chdir(".."); - chomp($pwd = `pwd`); - die "$SELF: -a option only works if you run $SELF from a git worktree\n" if $pwd eq "/"; - } - - chomp($pwd = `pwd`); - - for(`git ls-files '*/*/*.SlackBuild' | cut -d/ -f1,2`) { - chomp; - push @ARGV, $_; - } - - warn "$SELF: linting " . scalar(@ARGV) . " builds from git repo at $pwd\n" unless $quiet; - $quiet = $progress_bar = 1; + if(-t STDOUT) { + chomp (my $outfile = "$SELF.log." . `date +%Y%m%d`); + warn "$SELF: stdout is a terminal, redirecting to $outfile\n"; + if(rename $outfile, $outfile . ".old") { + warn "$SELF: renamed old $outfile to $outfile.old\n"; + } + open my $f, ">$outfile" or die $!; + *STDOUT = $f; + } + + @ARGV=(); + my $pwd; + + # find root of the SBo git repo, if we're somewhere inside it. + while(! -d ".git" && ! -d "system") { + chdir(".."); + chomp($pwd = `pwd`); + die "$SELF: -a option only works if you run $SELF from a git worktree\n" if $pwd eq "/"; + } + + chomp($pwd = `pwd`); + + for(`git ls-files '*/*/*.SlackBuild' | cut -d/ -f1,2`) { + chomp; + push @ARGV, $_; + } + + warn "$SELF: linting " . scalar(@ARGV) . " builds from git repo at $pwd\n" unless $quiet; + $quiet = $progress_bar = 1; } push @ARGV, "." unless @ARGV; @@ -526,843 +526,843 @@ push @ARGV, "." unless @ARGV; $argv_count = 0; $err_warn_count = 0; for(@ARGV) { - run_checks($_); - $g_errcount += $errcount; - $g_warncount += $warncount; - - if($errcount || $warncount) { - $err_warn_count++; - } - - if(!$quiet) { - if($errcount == 0 and $warncount == 0) { - print "$SELF: $buildname checks out " . $green . "OK" . $color_off . "\n"; - } else { - print "$SELF: $buildname: " . $red . "errors $errcount" . $color_off . ", " . $yellow . "warnings $warncount" . $color_off . "\n"; - } - } - - if($progress_bar) { - $argv_count++; - my $pct = ($argv_count / @ARGV) * 100; - printf STDERR " %d/%d, %2.1f%%\r", $argv_count, scalar @ARGV, $pct; - } + run_checks($_); + $g_errcount += $errcount; + $g_warncount += $warncount; + + if($errcount || $warncount) { + $err_warn_count++; + } + + if(!$quiet) { + if($errcount == 0 and $warncount == 0) { + print "$SELF: $buildname checks out " . $green . "OK" . $color_off . "\n"; + } else { + print "$SELF: $buildname: " . $red . "errors $errcount" . $color_off . ", " . $yellow . "warnings $warncount" . $color_off . "\n"; + } + } + + if($progress_bar) { + $argv_count++; + my $pct = ($argv_count / @ARGV) * 100; + printf STDERR " %d/%d, %2.1f%%\r", $argv_count, scalar @ARGV, $pct; + } } if($progress_bar) { - my $t = scalar @ARGV; - my $ok = $t - $err_warn_count; + my $t = scalar @ARGV; + my $ok = $t - $err_warn_count; - printf STDERR "\n%d builds linted. %d (%.2f%%) OK, %d (%.2f%%) failed.\n", - $t, - $ok, 100 * (($ok) / $t), - $err_warn_count, 100 * ($err_warn_count / $t); + printf STDERR "\n%d builds linted. %d (%.2f%%) OK, %d (%.2f%%) failed.\n", + $t, + $ok, 100 * (($ok) / $t), + $err_warn_count, 100 * ($err_warn_count / $t); - chomp (my $now = `date +%s`); - my $elapsed = $now - $^T; - my $min = int($elapsed / 60); - my $sec = $elapsed % 60; + chomp (my $now = `date +%s`); + my $elapsed = $now - $^T; + my $min = int($elapsed / 60); + my $sec = $elapsed % 60; - printf STDERR "Elapsed time %d:%02d\n", $min, $sec; + printf STDERR "Elapsed time %d:%02d\n", $min, $sec; } # print total errs/warns only if >1 build checked if(!$quiet && @ARGV > 1) { - print "$SELF: Total errors: $g_errcount\n"; - print "$SELF: Total warnings: $g_warncount\n" unless $nowarn; + print "$SELF: Total errors: $g_errcount\n"; + print "$SELF: Total warnings: $g_warncount\n" unless $nowarn; } exit ($g_errcount > 0 || (!$nowarn && $g_warncount > 0)); # } sub dequote { - my $a = shift; - #warn "dequote arg: $a\n"; - $a =~ s/^("|')(\S+)(\1)$/$2/; - #warn "dequote ret: $a\n"; - return $a; + my $a = shift; + #warn "dequote arg: $a\n"; + $a =~ s/^("|')(\S+)(\1)$/$2/; + #warn "dequote ret: $a\n"; + return $a; } sub logmsg { - my $severity = shift; - my $format = shift; - printf("$buildname: $severity: $format\n", @_); + my $severity = shift; + my $format = shift; + printf("$buildname: $severity: $format\n", @_); } sub log_error { - logmsg($red . "ERR" . $color_off, @_); - $errcount++; + logmsg($red . "ERR" . $color_off, @_); + $errcount++; } sub log_warning { - return if $nowarn; - logmsg($yellow . "WARN" . $color_off, @_); - $warncount++; + return if $nowarn; + logmsg($yellow . "WARN" . $color_off, @_); + $warncount++; } sub log_note { - return if $nowarn || $nonote; - logmsg($green . "NOTE" . $color_off, @_); - $warncount++ if $notes_as_warnings; + return if $nowarn || $nonote; + logmsg($green . "NOTE" . $color_off, @_); + $warncount++ if $notes_as_warnings; } sub die_usage { - die "$SELF: $_[0] (try --help)\n" + die "$SELF: $_[0] (try --help)\n" } sub chdir_or_die { - chdir($_[0]) or die "$SELF: chdir($_[0]): $!\n"; + chdir($_[0]) or die "$SELF: chdir($_[0]): $!\n"; } sub get_mode { - 07777 & ((stat($_[0]))[2]); + 07777 & ((stat($_[0]))[2]); } sub make_temp_dir { - return if $tempdir; - my $tmp = $ENV{TMP} || "/tmp"; - $tempdir = "$tmp/$SELF." . int(rand(2**32-1)); - system("rm -rf $tempdir"); - system("mkdir -p $tempdir"); - if(! -d $tempdir) { - die "$SELF: can't create temp dir $tempdir\n"; - } + return if $tempdir; + my $tmp = $ENV{TMP} || "/tmp"; + $tempdir = "$tmp/$SELF." . int(rand(2**32-1)); + system("rm -rf $tempdir"); + system("mkdir -p $tempdir"); + if(! -d $tempdir) { + die "$SELF: can't create temp dir $tempdir\n"; + } } sub rm_temp_dir { - if($tempdir && (-d $tempdir)) { - system("rm -rf $tempdir"); - $tempdir = 0; - } + if($tempdir && (-d $tempdir)) { + system("rm -rf $tempdir"); + $tempdir = 0; + } } sub check_tarball_mime { - my $file = shift; - - ### This stuff is a little pedantic. It also relies on having a recent-ish - ### version of GNU file (the one in Slack 15.0 works fine). - my %types = ( - 'tar' => 'application/x-tar', - 'tar.gz' => 'application/gzip', - 'tar.bz2' => 'application/x-bzip2', - 'tar.xz' => 'application/x-xz', - ); - - (my $basename = $file) =~ s,.*/,,; - if($basename =~ /^\./) { - log_error("$file: tarball filename begins with a . (hidden, WTF?)"); - return; - } - my $ext; - if($basename =~ /\.(tar(?:\.(?:gz|bz2|xz))?)$/) { - $ext = $1; - } else { - log_error("$file: bad tarball filename, not .tar or .tar.(gz|bz2|xz), will be rejected by upload form"); - return; - } - - ### warn "\$basename is \"$basename\", \$ext is \"$ext\""; - - my $mime = `file --brief --mime-type $file`; - chomp $mime; - - if(!grep { $_ eq $mime } values %types) { - log_error("$file is not a tarball (mime type is '$mime')"); - } elsif($types{$ext} ne $mime) { - log_error("$file mime type '$mime' doesn't match filename (should be $types{$ext})"); - } elsif($ext ne 'tar') { - my $realmime = `file -z --brief --mime-type $file`; - chomp $realmime; - if($realmime ne 'application/x-tar') { - log_error("$file doesn't contain a tar archive (content mime type is $realmime, should be application/x-tar)"); - } - } + my $file = shift; + + ### This stuff is a little pedantic. It also relies on having a recent-ish + ### version of GNU file (the one in Slack 15.0 works fine). + my %types = ( + 'tar' => 'application/x-tar', + 'tar.gz' => 'application/gzip', + 'tar.bz2' => 'application/x-bzip2', + 'tar.xz' => 'application/x-xz', + ); + + (my $basename = $file) =~ s,.*/,,; + if($basename =~ /^\./) { + log_error("$file: tarball filename begins with a . (hidden, WTF?)"); + return; + } + my $ext; + if($basename =~ /\.(tar(?:\.(?:gz|bz2|xz))?)$/) { + $ext = $1; + } else { + log_error("$file: bad tarball filename, not .tar or .tar.(gz|bz2|xz), will be rejected by upload form"); + return; + } + + ### warn "\$basename is \"$basename\", \$ext is \"$ext\""; + + my $mime = `file --brief --mime-type $file`; + chomp $mime; + + if(!grep { $_ eq $mime } values %types) { + log_error("$file is not a tarball (mime type is '$mime')"); + } elsif($types{$ext} ne $mime) { + log_error("$file mime type '$mime' doesn't match filename (should be $types{$ext})"); + } elsif($ext ne 'tar') { + my $realmime = `file -z --brief --mime-type $file`; + chomp $realmime; + if($realmime ne 'application/x-tar') { + log_error("$file doesn't contain a tar archive (content mime type is $realmime, should be application/x-tar)"); + } + } } sub check_tarball { - my $file = shift; - - ### First, mime type checks. None of this will be fatal (no return 0 on error). - check_tarball_mime($file); - - ### one more pre-extraction check: - if(-s "$file" > $MAX_TARBALL_SIZE) { - log_warning("$file is larger than $MAX_TARBALL_SIZE bytes, upload may be rejected"); - } - - ### now call tar to list the contents, and start returning 0 on failure. - my @list = split "\n", `tar tf $file`; - if($?) { - log_error("$file: tar failed to list contents"); - return 0; - } - - if(!@list) { - log_error("$file is empty archive?"); - return 0; - } - - ### Used to do this: -# if($list[0] ne "$buildname/") { -# log_error("$file not a SBo-compliant tarball, first element should be '$buildname/', not '$list[0]'"); -# return 0; -# } + my $file = shift; + + ### First, mime type checks. None of this will be fatal (no return 0 on error). + check_tarball_mime($file); + + ### one more pre-extraction check: + if(-s "$file" > $MAX_TARBALL_SIZE) { + log_warning("$file is larger than $MAX_TARBALL_SIZE bytes, upload may be rejected"); + } + + ### now call tar to list the contents, and start returning 0 on failure. + my @list = split "\n", `tar tf $file`; + if($?) { + log_error("$file: tar failed to list contents"); + return 0; + } + + if(!@list) { + log_error("$file is empty archive?"); + return 0; + } + + ### Used to do this: +# if($list[0] ne "$buildname/") { +# log_error("$file not a SBo-compliant tarball, first element should be '$buildname/', not '$list[0]'"); +# return 0; +# } ### ...but it turns out some tools (file-roller) put the directory *last* - ### in the tarball. And furthermore, you can easily create a tarball - ### without the directory at all (try "tar cvf dir/*", there will be no + ### in the tarball. And furthermore, you can easily create a tarball + ### without the directory at all (try "tar cvf dir/*", there will be no ### separate entry for dir/). There's nothing wrong with such tarballs, - ### tar can extract them just fine, so we allow them here. + ### tar can extract them just fine, so we allow them here. - my $foundsb = 0; - ### shift @list; # 1st element is dirname/, we already checked it + my $foundsb = 0; + ### shift @list; # 1st element is dirname/, we already checked it - for(@list) { - my $bn = quotemeta($buildname); # some builds have + in the name - if(not /^$bn\//) { - log_error("$file not a SBo-compliant tarball, contains extra junk '$_'"); - return 0; - } + for(@list) { + my $bn = quotemeta($buildname); # some builds have + in the name + if(not /^$bn\//) { + log_error("$file not a SBo-compliant tarball, contains extra junk '$_'"); + return 0; + } - if(/^$bn\/$bn.SlackBuild$/) { - $foundsb = 1; - } - } + if(/^$bn\/$bn.SlackBuild$/) { + $foundsb = 1; + } + } - if(not $foundsb) { - log_error("$file not a SBo-compliant tarball, doesn't contain '$buildname/$buildname.SlackBuild'"); - return 0; - } + if(not $foundsb) { + log_error("$file not a SBo-compliant tarball, doesn't contain '$buildname/$buildname.SlackBuild'"); + return 0; + } - return 1; + return 1; } sub extract_tarball { - my $file = shift; - $file = `readlink -n -e $file`; - make_temp_dir(); - chdir_or_die($tempdir); - system("tar xf $file"); - - # 20260602 bkw: check permissions on the enclosing dir. If it's - # not +x, the upload form will fail. - my $gotmode = get_mode("$tempdir/$buildname"); - if($gotmode != 0755) { - my $p = sprintf("%04o", $gotmode); - log_error("$file not a SBo-compliant tarball, permission of $buildname/ should be 0755, not $p."); - } - - return "$tempdir/$buildname"; + my $file = shift; + $file = `readlink -n -e $file`; + make_temp_dir(); + chdir_or_die($tempdir); + system("tar xf $file"); + + # 20260602 bkw: check permissions on the enclosing dir. If it's + # not +x, the upload form will fail. + my $gotmode = get_mode("$tempdir/$buildname"); + if($gotmode != 0755) { + my $p = sprintf("%04o", $gotmode); + log_error("$file not a SBo-compliant tarball, permission of $buildname/ should be 0755, not $p."); + } + + return "$tempdir/$buildname"; } # run_checks will extract its argument (then cd to it) if it's a tarball, # otherwise cd to its argument if it's a dir, otherwise error. sub run_checks { - $build = shift; - my $checking_tarball = 0; - my $in_git_repo = 0; - my $oldcwd = getcwd(); - - $errcount = $warncount = 0; - - if(-f $build || -l $build) { - ($buildname = $build) =~ s,\.tar(\..*)?$,,; - $buildname =~ s,.*/,,; - if(check_tarball($build)) { - chdir_or_die(extract_tarball($build)); - $checking_tarball++; - } else { - return 0; - } - } elsif(-d $build) { - chdir_or_die($build); - } else { - die_usage "'$build' not a file or a directory."; - } - - # last component of directory is the build name - $buildname = `readlink -n -e .`; - $buildname =~ s,.*/,,; - - # are we in a git repo? build scripts are mode 0644 there, plus - # the junkfile check is skipped. - if(!$checking_tarball) { - $in_git_repo = system("git rev-parse >/dev/null 2>/dev/null") == 0; - } - - # what permissions are allowed for the SlackBuild? 2 choices: - # in a git repo, it has to be 644. - # anywhere else, 644 and 755 are allowed. - # 20260603 bkw: this changed. we used to enforce 755 in tarballs, but - # there's no point in it: we don't use the submission tarball as the - # final downloadable file on the site. everything goes through git, - # with a git hook that changes the script perms to 0644... then when - # the update happens and the site tarballs get generated, the script - # that does that, sets the script perms to 0755. so it really doesn't - # matter what they are in the submission tarball. - if($in_git_repo) { - @script_perms = (0644); - } else { - @script_perms = (0644, 0755); - } - - if(script_exists()) { - my @checks = ( - \&check_package_list, - \&check_readme, - \&check_slackdesc, - \&check_info, - \&check_script, - \&check_doinst, - \&check_images, - \&check_patches, - \&check_empty_hidden, - ); - - # we only care about the junkfiles check for tarballs; don't - # try to second-guess the user otherwise. - push @checks, \&check_junkfiles if $checking_tarball; - - push @checks, \¬_in_git if $in_git_repo; - - for(@checks) { - $_->($build); - } - } - - chdir_or_die($oldcwd); - rm_temp_dir(); + $build = shift; + my $checking_tarball = 0; + my $in_git_repo = 0; + my $oldcwd = getcwd(); + + $errcount = $warncount = 0; + + if(-f $build || -l $build) { + ($buildname = $build) =~ s,\.tar(\..*)?$,,; + $buildname =~ s,.*/,,; + if(check_tarball($build)) { + chdir_or_die(extract_tarball($build)); + $checking_tarball++; + } else { + return 0; + } + } elsif(-d $build) { + chdir_or_die($build); + } else { + die_usage "'$build' not a file or a directory."; + } + + # last component of directory is the build name + $buildname = `readlink -n -e .`; + $buildname =~ s,.*/,,; + + # are we in a git repo? build scripts are mode 0644 there, plus + # the junkfile check is skipped. + if(!$checking_tarball) { + $in_git_repo = system("git rev-parse >/dev/null 2>/dev/null") == 0; + } + + # what permissions are allowed for the SlackBuild? 2 choices: + # in a git repo, it has to be 644. + # anywhere else, 644 and 755 are allowed. + # 20260603 bkw: this changed. we used to enforce 755 in tarballs, but + # there's no point in it: we don't use the submission tarball as the + # final downloadable file on the site. everything goes through git, + # with a git hook that changes the script perms to 0644... then when + # the update happens and the site tarballs get generated, the script + # that does that, sets the script perms to 0755. so it really doesn't + # matter what they are in the submission tarball. + if($in_git_repo) { + @script_perms = (0644); + } else { + @script_perms = (0644, 0755); + } + + if(script_exists()) { + my @checks = ( + \&check_package_list, + \&check_readme, + \&check_slackdesc, + \&check_info, + \&check_script, + \&check_doinst, + \&check_images, + \&check_patches, + \&check_empty_hidden, + ); + + # we only care about the junkfiles check for tarballs; don't + # try to second-guess the user otherwise. + push @checks, \&check_junkfiles if $checking_tarball; + + push @checks, \¬_in_git if $in_git_repo; + + for(@checks) { + $_->($build); + } + } + + chdir_or_die($oldcwd); + rm_temp_dir(); } sub check_mode { - my ($file, $wantmode) = @_; - if(! -e $file) { - log_error("$file does not exist"); - return 0; - } - - my $gotmode = get_mode($file); - if($wantmode != $gotmode) { - log_error("$file must be mode %04o, not %04o", $wantmode, $gotmode); - return 0; - } - - return 1; + my ($file, $wantmode) = @_; + if(! -e $file) { + log_error("$file does not exist"); + return 0; + } + + my $gotmode = get_mode($file); + if($wantmode != $gotmode) { + log_error("$file must be mode %04o, not %04o", $wantmode, $gotmode); + return 0; + } + + return 1; } sub check_crlf { - my $file = shift; - for(@_) { - if(/\r/) { - log_error("$file has DOS-style CRLF line endings"); - return 0; - } - } - return 1; + my $file = shift; + for(@_) { + if(/\r/) { + log_error("$file has DOS-style CRLF line endings"); + return 0; + } + } + return 1; } sub check_and_read { - my ($file, $mode) = @_; - - my $crlf_err; - my @lines; - my $lastline_nonl; - - check_mode($file, $mode) if defined $mode; - - if(open my $fh, "<$file") { - while(<$fh>) { - $lastline_nonl = 1 unless /\n$/; - chomp; - $crlf_err = 1 if s/\r$//; - push @lines, $_; - } - if(scalar @lines == 0) { - log_error("$file exists but is empty"); - } - } - - if($file =~ /\.(diff|patch)$/i) { - log_note("$file has DOS-style CRLF line endings, git may mess it up unless you gzip it") if $crlf_err; - # 20260523 bkw: do not complain if patches lack EOF at end! - } else { - log_error("$file has DOS-style CRLF line endings") if $crlf_err; - log_error("$file has no newline at EOF") if $lastline_nonl; - } - - return @lines; + my ($file, $mode) = @_; + + my $crlf_err; + my @lines; + my $lastline_nonl; + + check_mode($file, $mode) if defined $mode; + + if(open my $fh, "<$file") { + while(<$fh>) { + $lastline_nonl = 1 unless /\n$/; + chomp; + $crlf_err = 1 if s/\r$//; + push @lines, $_; + } + if(scalar @lines == 0) { + log_error("$file exists but is empty"); + } + } + + if($file =~ /\.(diff|patch)$/i) { + log_note("$file has DOS-style CRLF line endings, git may mess it up unless you gzip it") if $crlf_err; + # 20260523 bkw: do not complain if patches lack EOF at end! + } else { + log_error("$file has DOS-style CRLF line endings") if $crlf_err; + log_error("$file has no newline at EOF") if $lastline_nonl; + } + + return @lines; } # 20220315 bkw: warn if a file isn't ASCII or UTF-8 without BOM. # Used for README and slack-desc... sub check_encoding { - my $file = shift; - my $ascii_only = shift; - my $ftype; - - # 20220314 bkw: the -e options make file faster and turn off checks - # we don't need, ones that sometimes cause false detection too. - chomp($ftype = `file -b -e cdf -e compress -e csv -e elf -e json -e soft -e tar $file`); - - if($ascii_only && ($ftype !~ /ASCII text/)) { - log_warning("$file must be ASCII text, not $ftype"); - } - - if($ftype =~ /ASCII text/ || $ftype =~ /UTF-8/) { - # encoding is OK, but: - if($ftype =~ /BOM/) { - log_warning("$file has BOM, remove with: LANG=C sed -i '1s/^\\xEF\\xBB\\xBF//' $file"); - } - } elsif($ftype =~ /ISO-8859/) { - log_warning("$file has ISO-8859 encoding, fix with: mv $file $file.old; iconv -f iso-8859-1 -t utf-8 $file.old > $file; rm $file.old"); - } else { - log_warning("$file isn't ASCII or UTF-8, file(1) says it's '$ftype'"); - } + my $file = shift; + my $ascii_only = shift; + my $ftype; + + # 20220314 bkw: the -e options make file faster and turn off checks + # we don't need, ones that sometimes cause false detection too. + chomp($ftype = `file -b -e cdf -e compress -e csv -e elf -e json -e soft -e tar $file`); + + if($ascii_only && ($ftype !~ /ASCII text/)) { + log_warning("$file must be ASCII text, not $ftype"); + } + + if($ftype =~ /ASCII text/ || $ftype =~ /UTF-8/) { + # encoding is OK, but: + if($ftype =~ /BOM/) { + log_warning("$file has BOM, remove with: LANG=C sed -i '1s/^\\xEF\\xBB\\xBF//' $file"); + } + } elsif($ftype =~ /ISO-8859/) { + log_warning("$file has ISO-8859 encoding, fix with: mv $file $file.old; iconv -f iso-8859-1 -t utf-8 $file.old > $file; rm $file.old"); + } else { + log_warning("$file isn't ASCII or UTF-8, file(1) says it's '$ftype'"); + } } sub check_empty_lines { - my $empties = 0; - - while(defined($_[0])) { - if($_[0] =~ /^\s*$/) { - $empties++; - } else { - last; - } - shift; - } - - return $empties; + my $empties = 0; + + while(defined($_[0])) { + if($_[0] =~ /^\s*$/) { + $empties++; + } else { + last; + } + shift; + } + + return $empties; } sub check_leading_empty_lines { - my $file = shift; - my $count = check_empty_lines(@_); - return unless $count; - log_error("$file begins with $count blank line" . ($count == 1 ? "" : "s")); + my $file = shift; + my $count = check_empty_lines(@_); + return unless $count; + log_error("$file begins with $count blank line" . ($count == 1 ? "" : "s")); } sub check_trailing_empty_lines { - my $file = shift; - my $count = check_empty_lines(reverse @_); - return unless $count; - my $msg = "$file ends with $count blank line"; - if($count == 1) { - log_note($msg); - } else { - log_error($msg . "s"); - } + my $file = shift; + my $count = check_empty_lines(reverse @_); + return unless $count; + my $msg = "$file ends with $count blank line"; + if($count == 1) { + log_note($msg); + } else { + log_error($msg . "s"); + } } sub check_readme { - my $maxlen = $ENV{'SBOLINT_README_MAX'} || 72; - my @lines = check_and_read("README", 0644); - return unless @lines; + my $maxlen = $ENV{'SBOLINT_README_MAX'} || 72; + my @lines = check_and_read("README", 0644); + return unless @lines; - check_encoding("README", 0); + check_encoding("README", 0); - if(grep { /\t/ } @lines) { - log_warning("README has tabs, these should be replaced with spaces"); - } + if(grep { /\t/ } @lines) { + log_warning("README has tabs, these should be replaced with spaces"); + } - check_leading_empty_lines('README', @lines); - check_trailing_empty_lines('README', @lines); + check_leading_empty_lines('README', @lines); + check_trailing_empty_lines('README', @lines); - return if $suppress_readme_len; + return if $suppress_readme_len; - # 20220205 bkw: don't complain about long lines if they're URLs, - # not much we can do about them. - # 20260608 bkw: also commands beginning with a prompt character, - # # or $. - # 20260819 bkw: also 'export' commands (e.g. python3-cython-opt) - if(grep { !/^export\s+[A-Z]/ && !/^[#\$] / && !/^\s*(ftp|https?):\/\// && length > $maxlen } @lines) { - log_warning("README has lines >$maxlen characters"); - } + # 20220205 bkw: don't complain about long lines if they're URLs, + # not much we can do about them. + # 20260608 bkw: also commands beginning with a prompt character, + # # or $. + # 20260819 bkw: also 'export' commands (e.g. python3-cython-opt) + if(grep { !/^export\s+[A-Z]/ && !/^[#\$] / && !/^\s*(ftp|https?):\/\// && length > $maxlen } @lines) { + log_warning("README has lines >$maxlen characters"); + } } # the slack-desc checking code offends me (the author), on the one hand it's # overly complex, and on the other hand it assumes the slack-desc is at # least close to being right... sub check_slackdesc { - my @lines = check_and_read("slack-desc", 0644); - return unless scalar @lines; - - check_encoding("slack-desc", 1); - - if(grep { /\t/ } @lines) { - log_warning("slack-desc has tabs, these should be replaced with spaces"); - } - - my $lineno = 1; - - if($lines[0] =~ /^# HOW TO EDIT THIS FILE:$/) { - shift @lines; - $lineno++; - } else { - log_warning("slack-desc doesn't start with how-to-edit comment"); - } - - my $count = 0; - while($lines[0] =~ /^#/) { - $count++; - $lineno++; - shift @lines; - } - - if($count != 5) { - log_warning("slack-desc doesn't have standard how-to-edit stanza"); - } - - $count = 0; - while($lines[0] eq "") { - $count++; - $lineno++; - shift @lines; - } - - if($count == 0) { - log_warning("slack-desc missing blank line before handy-ruler"); - } elsif($count > 1) { - log_warning("slack-desc has extra blank lines before handy-ruler"); - } - - if($lines[0] =~ /handy-ruler/) { - my $ruler = shift @lines; - $lineno++; - my ($spaces, $prefix, $hr, $suffix, $junk) = ($ruler =~ /^( *)(\|-+)(handy-ruler)(-+\|)(.*)$/); - - if(length($spaces) != length($buildname)) { - log_error("slack-desc:$lineno: handy-ruler has wrong number of indent spaces (%d, should be %d)", - length($spaces), - length($buildname)); - } - - if(length($junk) > 0) { - log_error("slack-desc:$lineno: handy-ruler has %d characters of trailing junk after last |", length($junk)); - } - - my $rlen = length($prefix . $hr . $suffix); - if($rlen != 72) { - log_error("slack-desc:$lineno: handy-ruler must be 72 characters, not %d", $rlen); - } elsif(length($prefix) != 6) { - log_error("slack-desc:$lineno: handy-ruler malformed, has '$prefix' instead of '|-----'"); - } - } else { - log_error("slack-desc missing handy-ruler"); - } - - $count = 0; - for(@lines) { - $count++; - if(my ($prefix, $text) = /^([^\s]+:)(.*)/) { - if($prefix ne "$buildname:") { - log_error("slack-desc:$lineno: wrong prefix '$prefix', should be '$buildname:'"); - } elsif($text =~ /^\s+$/) { - log_error("slack-desc:$lineno: trailing whitespace after colon, on otherwise-blank line"); - } elsif(length($text) && $text !~ /^ /) { - log_error("slack-desc:$lineno: missing whitespace after colon, on non-blank line"); - } elsif(/\(short description of app\)/) { - log_error("slack-desc:$lineno: bad description: literally 'short description of app'"); - } else { - # The world is not ready for this: - ###if($text =~ /\s$/) { - ### log_error("slack-desc:$lineno: trailing whitespace on description line"); - ###} - if(length($text) > 71) { - log_error("slack-desc:$lineno: text too long, %d characters, should be <= 71", length($text)); - } - } - - my $bn = quotemeta($buildname); # some builds have + in the name - if(($count == 1) && ($text !~ /^ $bn \(.+\)$/)) { - log_warning("slack-desc:$lineno: first description line should be '$buildname: $buildname (short desc)'"); - } - } else { - log_error("slack-desc:$lineno: malformed line in description section"); - } - - $lineno++; - } - - if($count < 11) { - log_error("slack-desc only has $count description lines, should be 11 (add some empties)"); - } elsif($count > 11) { - log_error("slack-desc has too many description lines ($count, should be 11)"); - } + my @lines = check_and_read("slack-desc", 0644); + return unless scalar @lines; + + check_encoding("slack-desc", 1); + + if(grep { /\t/ } @lines) { + log_warning("slack-desc has tabs, these should be replaced with spaces"); + } + + my $lineno = 1; + + if($lines[0] =~ /^# HOW TO EDIT THIS FILE:$/) { + shift @lines; + $lineno++; + } else { + log_warning("slack-desc doesn't start with how-to-edit comment"); + } + + my $count = 0; + while($lines[0] =~ /^#/) { + $count++; + $lineno++; + shift @lines; + } + + if($count != 5) { + log_warning("slack-desc doesn't have standard how-to-edit stanza"); + } + + $count = 0; + while($lines[0] eq "") { + $count++; + $lineno++; + shift @lines; + } + + if($count == 0) { + log_warning("slack-desc missing blank line before handy-ruler"); + } elsif($count > 1) { + log_warning("slack-desc has extra blank lines before handy-ruler"); + } + + if($lines[0] =~ /handy-ruler/) { + my $ruler = shift @lines; + $lineno++; + my ($spaces, $prefix, $hr, $suffix, $junk) = ($ruler =~ /^( *)(\|-+)(handy-ruler)(-+\|)(.*)$/); + + if(length($spaces) != length($buildname)) { + log_error("slack-desc:$lineno: handy-ruler has wrong number of indent spaces (%d, should be %d)", + length($spaces), + length($buildname)); + } + + if(length($junk) > 0) { + log_error("slack-desc:$lineno: handy-ruler has %d characters of trailing junk after last |", length($junk)); + } + + my $rlen = length($prefix . $hr . $suffix); + if($rlen != 72) { + log_error("slack-desc:$lineno: handy-ruler must be 72 characters, not %d", $rlen); + } elsif(length($prefix) != 6) { + log_error("slack-desc:$lineno: handy-ruler malformed, has '$prefix' instead of '|-----'"); + } + } else { + log_error("slack-desc missing handy-ruler"); + } + + $count = 0; + for(@lines) { + $count++; + if(my ($prefix, $text) = /^([^\s]+:)(.*)/) { + if($prefix ne "$buildname:") { + log_error("slack-desc:$lineno: wrong prefix '$prefix', should be '$buildname:'"); + } elsif($text =~ /^\s+$/) { + log_error("slack-desc:$lineno: trailing whitespace after colon, on otherwise-blank line"); + } elsif(length($text) && $text !~ /^ /) { + log_error("slack-desc:$lineno: missing whitespace after colon, on non-blank line"); + } elsif(/\(short description of app\)/) { + log_error("slack-desc:$lineno: bad description: literally 'short description of app'"); + } else { + # The world is not ready for this: + ###if($text =~ /\s$/) { + ### log_error("slack-desc:$lineno: trailing whitespace on description line"); + ###} + if(length($text) > 71) { + log_error("slack-desc:$lineno: text too long, %d characters, should be <= 71", length($text)); + } + } + + my $bn = quotemeta($buildname); # some builds have + in the name + if(($count == 1) && ($text !~ /^ $bn \(.+\)$/)) { + log_warning("slack-desc:$lineno: first description line should be '$buildname: $buildname (short desc)'"); + } + } else { + log_error("slack-desc:$lineno: malformed line in description section"); + } + + $lineno++; + } + + if($count < 11) { + log_error("slack-desc only has $count description lines, should be 11 (add some empties)"); + } elsif($count > 11) { + log_error("slack-desc has too many description lines ($count, should be 11)"); + } } sub check_multiples { - my $ext = shift; - my @i; - push @i, <*.$ext>; - push @i, <*/*.$ext>; - push @i, <*/*/*.$ext>; - my $count = scalar @i; - - if($count > 1) { - log_error("multiple .$ext files found: " . join(" ", @i)); - } + my $ext = shift; + my @i; + push @i, <*.$ext>; + push @i, <*/*.$ext>; + push @i, <*/*/*.$ext>; + my $count = scalar @i; + + if($count > 1) { + log_error("multiple .$ext files found: " . join(" ", @i)); + } } # This is a damn mess. Needs refactoring badly. sub check_info { check_multiples('info'); - my $file = $buildname . ".info"; - my @lines = check_and_read($file, 0644); - return unless scalar @lines; - - my $lineno = 0; - my @expected = qw/PRGNAM VERSION HOMEPAGE - DOWNLOAD MD5SUM - DOWNLOAD_x86_64 MD5SUM_x86_64 - REQUIRES MAINTAINER EMAIL/; - my $next_exp = 0; - my @keys; - my $continuation = 0; - - my $fixable = 0; - - # pass 1: just check for continuations. keys that have multiple - # values *must* be broken up with \ (not all on one line with spaces). - for(@lines) { - $lineno++; - next unless /^(DOWNLOAD(?:_x86_64)?|MD5SUM(?:_x86_64)?)/; - my $k = $1; - if(/\s\s/) { - log_warning("$file:$lineno: $k has sequences of multiple spaces; collapse them into one"); - } elsif (/\s[^\\]/) { - log_error("$file:$lineno: $k has multiple values and must be split into multiple lines with \\"); - } - } - - # pass 2: parse and bitch about bad syntax... - $lineno = 0; - for(@lines) { - $lineno++; - if($continuation) { - s/^\s*//; - $_ = "$continuation $_"; - $continuation = 0; - } - - if(s/\s*\\$//) { - if(/^(PRGNAM|VERSION|HOMEPAGE|REQUIRES|MAINTAINER|EMAIL)/) { - log_error("$file:$lineno: $1 may not be broken up into multiple lines with \\"); - } - $continuation = $_; - next; - } - - if(/^\s*$/) { - log_error("$file:$lineno: blank line (get rid of it)"); - $fixable++; - next; - } - - unless(/=/) { - log_error("$file:$lineno: malformed line (no = sign, missing \\ on prev line?)"); - $fixable++; - next; - } - - if(s/^\s+//) { - log_error("$file:$lineno: leading whitespace before key"); - $fixable++; - } - - if(s/\s+$//) { - log_error("$file:$lineno: trailing whitespace at EOL"); - $fixable++; - } - - if(/\t/) { - log_error("$file:$lineno: tab characters are not allowed"); - } - - if(/\r/) { - log_error("$file:$lineno: carriage returns (\\r) are not allowed"); - } - - if(my ($k, $s1, $s2, $q1, $val, $q2) = /^(\w+)(\s*)=(\s*)("?)(.*?)("?)$/) { - if(!grep { $k eq $_ } @expected) { - log_error("$file:$lineno: invalid key '$k'"); - } else { - if($k ne $expected[$next_exp]) { - log_warning("$file:$lineno: out of order, expected $expected[$next_exp], got $k"); - $fixable++; - } - $next_exp++; - } - - if(not $q1) { - log_error("$file:$lineno: missing opening double-quote"); - $fixable++; - } - - if(not $q2) { - log_error("$file:$lineno: missing closing double-quote"); - $fixable++; - } - - if(length($s1) || length($s2)) { - log_error("$file:$lineno: no spaces allowed before/after = sign"); - $fixable++; - } - - my $oldval = $val; - if($val =~ s/^\s+//) { - log_error("$file:$lineno: leading space in value: \"$oldval\""); - $fixable++; - } - - if($val =~ s/\s+$//) { - log_error("$file:$lineno: trailing space in value: \"$oldval\""); - $fixable++; - } - - $info{$k} = $val; - } else { - log_error("$file:$lineno: malformed line"); - $fixable++; - } - } - - if($fixable) { - logmsg("NOTE", $fixable . " possibly-fixable errors found. suggest running sbofixinfo."); - } - - # parsing done, now for semantic checks - - my @missing; - for(@expected) { - if(not exists($info{$_})) { - push @missing, $_; - } - } - - log_error("$file: missing required key(s): " . (join ", ", @missing)) if @missing; - - # init this to avoid checking undef values below - $info{$_} ||= "" for @expected; - - if($info{PRGNAM} && ($info{PRGNAM} ne $buildname)) { - log_error("$file: PRGNAM is '$info{PRGNAM}', should be '$buildname'"); - } - - if($info{PRGNAM} =~ /[^-+._A-Za-z0-9]/) { - log_error("$file: PRGNAM has invalid characters, only A-Z, a-z, 0-9, - + . _ are allowed"); - } - - if($info{REQUIRES} =~ /[^- %+._A-Za-z0-9]/) { - log_error("$file: REQUIRES has invalid characters, only space, A-Z, a-z, 0-9, - + . _ % are allowed"); - } - - if($info{VERSION} =~ /-/) { - log_error("$file: VERSION may not contain - (dash) characters"); - } - - if($info{VERSION} =~ / /) { - log_error("$file: VERSION may not contain whitespace"); - } - - if(!check_url($info{HOMEPAGE})) { - log_error("$file: HOMEPAGE=\"%s\" doesn't look like a valid URL (http, https, or ftp)", $info{HOMEPAGE}); - } - - # use a HEAD request for homepage, even if downloading other files - if($url_head || $url_download) { - curl_head_request($file, $info{HOMEPAGE}) || do { - log_warning("$file: HOMEPAGE URL broken?"); - }; - } - - if($info{MD5SUM} =~ /^\s*$/) { - log_error("$file: MD5SUM is missing or blank") unless $info{DOWNLOAD} eq 'UNSUPPORTED'; - } else { - check_dl_and_md5($file, ""); - } - - my $dl64 = $info{DOWNLOAD_x86_64}; - if($dl64 =~ /^(?:|UNSUPPORTED|UNTESTED)$/) { - if($info{MD5SUM_x86_64} ne "") { - log_error("$file: MD5SUM_x86_64 must be blank if DOWNLOAD_x86_64 is not set"); - } - } elsif($info{MD5SUM_x86_64} eq "") { - log_error("$file: MD5SUM_x86_64 may not be blank if DOWNLOAD_x86_64 is set"); - } else { - check_dl_and_md5($file, "_x86_64"); - } + my $file = $buildname . ".info"; + my @lines = check_and_read($file, 0644); + return unless scalar @lines; + + my $lineno = 0; + my @expected = qw/PRGNAM VERSION HOMEPAGE + DOWNLOAD MD5SUM + DOWNLOAD_x86_64 MD5SUM_x86_64 + REQUIRES MAINTAINER EMAIL/; + my $next_exp = 0; + my @keys; + my $continuation = 0; + + my $fixable = 0; + + # pass 1: just check for continuations. keys that have multiple + # values *must* be broken up with \ (not all on one line with spaces). + for(@lines) { + $lineno++; + next unless /^(DOWNLOAD(?:_x86_64)?|MD5SUM(?:_x86_64)?)/; + my $k = $1; + if(/\s\s/) { + log_warning("$file:$lineno: $k has sequences of multiple spaces; collapse them into one"); + } elsif (/\s[^\\]/) { + log_error("$file:$lineno: $k has multiple values and must be split into multiple lines with \\"); + } + } + + # pass 2: parse and bitch about bad syntax... + $lineno = 0; + for(@lines) { + $lineno++; + if($continuation) { + s/^\s*//; + $_ = "$continuation $_"; + $continuation = 0; + } + + if(s/\s*\\$//) { + if(/^(PRGNAM|VERSION|HOMEPAGE|REQUIRES|MAINTAINER|EMAIL)/) { + log_error("$file:$lineno: $1 may not be broken up into multiple lines with \\"); + } + $continuation = $_; + next; + } + + if(/^\s*$/) { + log_error("$file:$lineno: blank line (get rid of it)"); + $fixable++; + next; + } + + unless(/=/) { + log_error("$file:$lineno: malformed line (no = sign, missing \\ on prev line?)"); + $fixable++; + next; + } + + if(s/^\s+//) { + log_error("$file:$lineno: leading whitespace before key"); + $fixable++; + } + + if(s/\s+$//) { + log_error("$file:$lineno: trailing whitespace at EOL"); + $fixable++; + } + + if(/\t/) { + log_error("$file:$lineno: tab characters are not allowed"); + } + + if(/\r/) { + log_error("$file:$lineno: carriage returns (\\r) are not allowed"); + } + + if(my ($k, $s1, $s2, $q1, $val, $q2) = /^(\w+)(\s*)=(\s*)("?)(.*?)("?)$/) { + if(!grep { $k eq $_ } @expected) { + log_error("$file:$lineno: invalid key '$k'"); + } else { + if($k ne $expected[$next_exp]) { + log_warning("$file:$lineno: out of order, expected $expected[$next_exp], got $k"); + $fixable++; + } + $next_exp++; + } + + if(not $q1) { + log_error("$file:$lineno: missing opening double-quote"); + $fixable++; + } + + if(not $q2) { + log_error("$file:$lineno: missing closing double-quote"); + $fixable++; + } + + if(length($s1) || length($s2)) { + log_error("$file:$lineno: no spaces allowed before/after = sign"); + $fixable++; + } + + my $oldval = $val; + if($val =~ s/^\s+//) { + log_error("$file:$lineno: leading space in value: \"$oldval\""); + $fixable++; + } + + if($val =~ s/\s+$//) { + log_error("$file:$lineno: trailing space in value: \"$oldval\""); + $fixable++; + } + + $info{$k} = $val; + } else { + log_error("$file:$lineno: malformed line"); + $fixable++; + } + } + + if($fixable) { + logmsg("NOTE", $fixable . " possibly-fixable errors found. suggest running sbofixinfo."); + } + + # parsing done, now for semantic checks + + my @missing; + for(@expected) { + if(not exists($info{$_})) { + push @missing, $_; + } + } + + log_error("$file: missing required key(s): " . (join ", ", @missing)) if @missing; + + # init this to avoid checking undef values below + $info{$_} ||= "" for @expected; + + if($info{PRGNAM} && ($info{PRGNAM} ne $buildname)) { + log_error("$file: PRGNAM is '$info{PRGNAM}', should be '$buildname'"); + } + + if($info{PRGNAM} =~ /[^-+._A-Za-z0-9]/) { + log_error("$file: PRGNAM has invalid characters, only A-Z, a-z, 0-9, - + . _ are allowed"); + } + + if($info{REQUIRES} =~ /[^- %+._A-Za-z0-9]/) { + log_error("$file: REQUIRES has invalid characters, only space, A-Z, a-z, 0-9, - + . _ % are allowed"); + } + + if($info{VERSION} =~ /-/) { + log_error("$file: VERSION may not contain - (dash) characters"); + } + + if($info{VERSION} =~ / /) { + log_error("$file: VERSION may not contain whitespace"); + } + + if(!check_url($info{HOMEPAGE})) { + log_error("$file: HOMEPAGE=\"%s\" doesn't look like a valid URL (http, https, or ftp)", $info{HOMEPAGE}); + } + + # use a HEAD request for homepage, even if downloading other files + if($url_head || $url_download) { + curl_head_request($file, $info{HOMEPAGE}) || do { + log_warning("$file: HOMEPAGE URL broken?"); + }; + } + + if($info{MD5SUM} =~ /^\s*$/) { + log_error("$file: MD5SUM is missing or blank") unless $info{DOWNLOAD} eq 'UNSUPPORTED'; + } else { + check_dl_and_md5($file, ""); + } + + my $dl64 = $info{DOWNLOAD_x86_64}; + if($dl64 =~ /^(?:|UNSUPPORTED|UNTESTED)$/) { + if($info{MD5SUM_x86_64} ne "") { + log_error("$file: MD5SUM_x86_64 must be blank if DOWNLOAD_x86_64 is not set"); + } + } elsif($info{MD5SUM_x86_64} eq "") { + log_error("$file: MD5SUM_x86_64 may not be blank if DOWNLOAD_x86_64 is set"); + } else { + check_dl_and_md5($file, "_x86_64"); + } } sub check_dl_and_md5 { - my($file, $suffix) = @_; - my $md5key = "MD5SUM" . $suffix; - my $dlkey = "DOWNLOAD" . $suffix; - - my @dlurls = split /\s+/, $info{$dlkey}; - my @md5s = split /\s+/, $info{$md5key}; - - if(@md5s != @dlurls) { - log_error("$file: we have " . @dlurls . " $dlkey URLs but " . @md5s . " $md5key" . " values"); - } - - for my $u (@dlurls) { - if(!check_url($u)) { - log_error("%s: %s URL \"%s\" doesn't look like a valid URL (http, https, or ftp)", $file, $dlkey, $u); - next; - } - - check_github_url($file, $u); - check_pypi_url($file, $u); - - if($url_head) { - curl_head_request($file, $u) || do { - #warn '$u is '. $u; - log_warning("%s: %s URL \"%s\" broken?", $file, $dlkey, $u); - }; - } elsif($url_download) { - warn "$SELF: -d option not yet implemented\n"; - } - } - - for(@md5s) { - unless(/^[0-9a-f]{32}$/) { - log_error("$file: $md5key '$_' is invalid (must be 32 hex digits)"); - } - } - - # TODO: maybe actually download and check md5sums. + my($file, $suffix) = @_; + my $md5key = "MD5SUM" . $suffix; + my $dlkey = "DOWNLOAD" . $suffix; + + my @dlurls = split /\s+/, $info{$dlkey}; + my @md5s = split /\s+/, $info{$md5key}; + + if(@md5s != @dlurls) { + log_error("$file: we have " . @dlurls . " $dlkey URLs but " . @md5s . " $md5key" . " values"); + } + + for my $u (@dlurls) { + if(!check_url($u)) { + log_error("%s: %s URL \"%s\" doesn't look like a valid URL (http, https, or ftp)", $file, $dlkey, $u); + next; + } + + check_github_url($file, $u); + check_pypi_url($file, $u); + + if($url_head) { + curl_head_request($file, $u) || do { + #warn '$u is '. $u; + log_warning("%s: %s URL \"%s\" broken?", $file, $dlkey, $u); + }; + } elsif($url_download) { + warn "$SELF: -d option not yet implemented\n"; + } + } + + for(@md5s) { + unless(/^[0-9a-f]{32}$/) { + log_error("$file: $md5key '$_' is invalid (must be 32 hex digits)"); + } + } + + # TODO: maybe actually download and check md5sums. } sub check_url { - # url is bad if: - return 0 if $_[0] =~ /\s/; # ...it contains a space, - return 0 if $_[0] !~ /\./; # ...it has no dots, or - return 0 if $_[0] !~ /\//; # ...it has no slashes, or - return 0 if $_[0] =~ /\$/; # ...it contains a dollar sign, or - return ($_[0] =~ /^(?:ftp|https?):\/\//); # ...it doesn't have a known protocol, - # ...which doesn't necessarily mean it's a good URL either. + # url is bad if: + return 0 if $_[0] =~ /\s/; # ...it contains a space, + return 0 if $_[0] !~ /\./; # ...it has no dots, or + return 0 if $_[0] !~ /\//; # ...it has no slashes, or + return 0 if $_[0] =~ /\$/; # ...it contains a dollar sign, or + return ($_[0] =~ /^(?:ftp|https?):\/\//); # ...it doesn't have a known protocol, + # ...which doesn't necessarily mean it's a good URL either. } sub curl_head_request { - my $file = $_[0]; - my $client_filename = $_[1]; - $client_filename =~ s,.*/,,; - - my @curlcmd = qw/curl --max-time 60 --head --location --silent --fail/; - push @curlcmd, $_[1]; - open my $pipe, "-|", @curlcmd; - - while(<$pipe>) { - chomp; - s/\r//; - if(/^content-disposition:\s+attachment;\s+filename=["']?(.*?)["']?$/i) { - #warn $1; - if(defined($client_filename) && ($client_filename ne $1)) { - log_warning("%s: download filename varies based on content disposition: '%s' vs. '%s'", $file, $1, $client_filename); - } - } - } - return close($pipe); + my $file = $_[0]; + my $client_filename = $_[1]; + $client_filename =~ s,.*/,,; + + my @curlcmd = qw/curl --max-time 60 --head --location --silent --fail/; + push @curlcmd, $_[1]; + open my $pipe, "-|", @curlcmd; + + while(<$pipe>) { + chomp; + s/\r//; + if(/^content-disposition:\s+attachment;\s+filename=["']?(.*?)["']?$/i) { + #warn $1; + if(defined($client_filename) && ($client_filename ne $1)) { + log_warning("%s: download filename varies based on content disposition: '%s' vs. '%s'", $file, $1, $client_filename); + } + } + } + return close($pipe); } # github is a mess... @@ -1382,116 +1382,116 @@ sub curl_head_request { # https://github.com/jeremysalwen/lv2file/archive/upstream/0.95.tar.gz sub check_github_url { - my $file = shift; - my $url = shift; - my $new_url; - my $ext; - my $tag; - my $ver; - my $dir; - - # do not police releases/ or raw/ URLs, only archive/ - # 20241008 bkw: also only police URLs that are in the main github.com - # domain, not e.g. raw.github.com or gists.github.com. - return unless $url =~ m{//github\.com/[^/]*/[^/]*/archive/}; - - # allow *and ignore* refs/tags - $url =~ s,refs/tags/,,; - - #https: // site/ .../ .../ archive/ ...everything else. - (my $proto, undef, undef, $user, $proj, undef, @parts) = split /\//, $url; - - log_error "$file: github URLs must be https://" unless $proto eq 'https:'; - - my $filename = pop @parts; - $filename =~ m,(\.tar\.gz|\.zip)$,; - $ext = $1; - - if(!defined $ext) { - log_warning("$file: github URL should end in .tar.gz or .zip"); - $ext = ""; - } - - if(@parts == 0) { - # filename loox like: tag.tar.gz - ($tag = $filename) =~ s,(\.tar\.gz|\.zip)$,,; - log_error "$file: github URL is non-canonical (not enough components)"; - $dir = $tag; - } elsif(@parts == 1) { - $tag = $dir = $parts[0]; - if($tag =~ /^[0-9a-f]{7,}$/ && $tag !~ /^20\d{6,}/) { - # commit hash. the /^20\d{6,}/ is to exclude ISO dates like 20240402 - if(length($tag) < 40) { - # shortened, maybe the full hash is in the filename? - if($filename =~ /([0-9a-f]{40})\./) { - $tag = $1; # leave $dir alone! it's allowed to be shortened. - } else { - # if not, we give up. - log_error("$file: github commit URL needs full 40-digit commit hash in filename"); - return; - } - } - } - } else { - $tag = join("-", @parts); - $dir = join("/", @parts); - } - - ($ver = $tag) =~ s,^v(\d),$1,i; - - # TODO: commit hashes have to be complete in the filename, and may be - # truncated in the dir name after archive/ - - if(defined $filename && $filename ne "$proj-$ver$ext") { - log_error "$file: github URL has wrong filename $filename"; - } - - $new_url = "https://github.com/$user/$proj/archive/$dir/$proj-$ver$ext"; - - if($url ne $new_url) { - log_warning("$file: canonical github URL should be: $new_url"); - } + my $file = shift; + my $url = shift; + my $new_url; + my $ext; + my $tag; + my $ver; + my $dir; + + # do not police releases/ or raw/ URLs, only archive/ + # 20241008 bkw: also only police URLs that are in the main github.com + # domain, not e.g. raw.github.com or gists.github.com. + return unless $url =~ m{//github\.com/[^/]*/[^/]*/archive/}; + + # allow *and ignore* refs/tags + $url =~ s,refs/tags/,,; + + #https: // site/ .../ .../ archive/ ...everything else. + (my $proto, undef, undef, $user, $proj, undef, @parts) = split /\//, $url; + + log_error "$file: github URLs must be https://" unless $proto eq 'https:'; + + my $filename = pop @parts; + $filename =~ m,(\.tar\.gz|\.zip)$,; + $ext = $1; + + if(!defined $ext) { + log_warning("$file: github URL should end in .tar.gz or .zip"); + $ext = ""; + } + + if(@parts == 0) { + # filename loox like: tag.tar.gz + ($tag = $filename) =~ s,(\.tar\.gz|\.zip)$,,; + log_error "$file: github URL is non-canonical (not enough components)"; + $dir = $tag; + } elsif(@parts == 1) { + $tag = $dir = $parts[0]; + if($tag =~ /^[0-9a-f]{7,}$/ && $tag !~ /^20\d{6,}/) { + # commit hash. the /^20\d{6,}/ is to exclude ISO dates like 20240402 + if(length($tag) < 40) { + # shortened, maybe the full hash is in the filename? + if($filename =~ /([0-9a-f]{40})\./) { + $tag = $1; # leave $dir alone! it's allowed to be shortened. + } else { + # if not, we give up. + log_error("$file: github commit URL needs full 40-digit commit hash in filename"); + return; + } + } + } + } else { + $tag = join("-", @parts); + $dir = join("/", @parts); + } + + ($ver = $tag) =~ s,^v(\d),$1,i; + + # TODO: commit hashes have to be complete in the filename, and may be + # truncated in the dir name after archive/ + + if(defined $filename && $filename ne "$proj-$ver$ext") { + log_error "$file: github URL has wrong filename $filename"; + } + + $new_url = "https://github.com/$user/$proj/archive/$dir/$proj-$ver$ext"; + + if($url ne $new_url) { + log_warning("$file: canonical github URL should be: $new_url"); + } } sub check_pypi_url { - my $file = shift; - my $url = shift; - my $filename; - my $initial; - my $newurl; - my $srcnam; - my $host; - - return unless $url =~ m{^(https?)://(files\.pythonhosted\.org|pypi\.python\.org)/}; - - if($1 ne 'https') { - log_error("$file: pypi URL must be https://"); - } - - # don't mess with URLs that don't have the 60-digit hex hash. - return unless $url =~ m{/[0-9a-f]{60}/}; - - ($filename = $url) =~ s,.*/,,; - $initial = substr($filename, 0, 1); - # FIXME: assumes no - in the version number. So far that's true... - ($srcnam = $filename) =~ s,-\d[^-]*\.tar\.gz$,,; - - # 20260819 bkw: the pypi.python.org URLs just redirect to the equivalent - # files.pythonhosted.org URL, so make hosted the default to avoid an extra - # HTTPS transaction. - $newurl = "https://files.pythonhosted.org/packages/source/$initial/$srcnam/$filename"; - if($url ne $newurl) { - log_note("$file: canonical pypi URL should be $newurl"); - } + my $file = shift; + my $url = shift; + my $filename; + my $initial; + my $newurl; + my $srcnam; + my $host; + + return unless $url =~ m{^(https?)://(files\.pythonhosted\.org|pypi\.python\.org)/}; + + if($1 ne 'https') { + log_error("$file: pypi URL must be https://"); + } + + # don't mess with URLs that don't have the 60-digit hex hash. + return unless $url =~ m{/[0-9a-f]{60}/}; + + ($filename = $url) =~ s,.*/,,; + $initial = substr($filename, 0, 1); + # FIXME: assumes no - in the version number. So far that's true... + ($srcnam = $filename) =~ s,-\d[^-]*\.tar\.gz$,,; + + # 20260819 bkw: the pypi.python.org URLs just redirect to the equivalent + # files.pythonhosted.org URL, so make hosted the default to avoid an extra + # HTTPS transaction. + $newurl = "https://files.pythonhosted.org/packages/source/$initial/$srcnam/$filename"; + if($url ne $newurl) { + log_note("$file: canonical pypi URL should be $newurl"); + } } sub script_exists { - my $file = $buildname . ".SlackBuild"; - unless(-e $file) { - log_error("$file does not exist, this is not a valid SlackBuild dir"); - return 0; - } - return 1; + my $file = $buildname . ".SlackBuild"; + unless(-e $file) { + log_error("$file does not exist, this is not a valid SlackBuild dir"); + return 0; + } + return 1; } # NOT going to police the script too much. Would end up rewriting most of @@ -1512,446 +1512,446 @@ sub script_exists { sub check_script { check_multiples('SlackBuild'); - my $file = $buildname . ".SlackBuild"; - - my $gotmode = get_mode($file); - my $mode_ok = 0; - my @octalmodes = (); - - for(@script_perms) { - push @octalmodes, sprintf("%04o", $_); - $mode_ok++ if $gotmode == $_; - } - - # warn "allowed modes: " . join(", ", @octalmodes); - - if(!$mode_ok) { - my $modes = join " or ", @octalmodes; - log_error("$file must have mode $modes, not %04o", $gotmode); - } - - my @lines = check_and_read($file); - return unless scalar @lines; - - my $bash_e_opt; - if($lines[0] !~ /^#!/) { - log_error("$file:1: missing or invalid shebang line (should be '#!/bin/bash')"); - } elsif($lines[0] =~ m,#!/bin/bash(?:\s+(-e|-eu|-ue|-e -u|-u -e))?\s*$,) { - my $arg = $1; - $bash_e_opt = 1 if defined($arg) && $arg =~ /e/; - } else { - log_warning("$file:1: shebang line should be #!/bin/bash (possibly with -e/-u arg(s)), not '$lines[0]'"); - } - - my $lineno = 0; - my ($prgnam, $version, $build, $tag, $need_doinst, $need_douninst, $slackdesc, $makepkg, $install); - my ($cdpkg, $codestart, $lint_enabled, $print_pkg_name, $pkg_type, $arch_lineno); - my ($old_arch, $old_flags, $have_py2, $have_py3); - my ($libsuf_set, $flags_set, $libsuf_used, $flags_used); - my ($set_e, $or_exit_1); - $lint_enabled = 1; - - for(@lines) { - $lineno++; - - if(/^\s*[^#]/ && !defined($codestart)) { - $codestart = $lineno; - if(not /^cd\s+"?\$\(\s*dirname\s+"?\$0.*CWD=.*pwd/) { - log_error("$file:$lineno: first line of code must be 'cd \$(dirname \$0) ; CWD=\$(pwd)'"); - } - } - - if(/^###sbolint\s*(\S+)/) { - my $arg = $1; - if(lc($arg) eq "on") { - $lint_enabled = 1; - } elsif(lc($arg) eq "off") { - $lint_enabled = 0; - } else { - log_warning("$file:$lineno: unknown ###sbolint argument '$arg' (should be 'on' or 'off')"); - } - } - - next unless $lint_enabled; - - # TODO: cp without -a (or -p, or a couple other flags) is OK. -## if(/^[^#]*cp\s+(?:-\w+\s+)*[\"\$\{]*CWD/) { -## log_error("$file:$lineno: copying files from CWD with cp (use cat instead)"); -## } - - if(/^PRGNAM=(\S+)/) { - if($prgnam) { - log_error("$file:$lineno: PRGNAM redefined"); - } - $prgnam = dequote($1); - if($prgnam ne $buildname) { - log_error("$file:$lineno: PRGNAM doesn't match dir name ($prgnam != $buildname)"); - } - } elsif(/^VERSION=(\S+)/ && ($lineno <= $codestart + 10)) { - $version = dequote($1); - if(not ($version =~ s/\$\{VERSION:-([^}]+)\}/$1/)) { - log_warning("$file:$lineno: VERSION ignores environment, try VERSION=\${VERSION:-$version}"); - } - $version = dequote($1); - if($version ne $info{VERSION}) { - log_error("$file:$lineno: VERSION ($version) doesn't match VERSION in the .info file ($info{VERSION})"); - } - } elsif(/^BUILD=(\S+)/) { - $build = dequote($1); - if(not ($build =~ /\d/)) { - log_error("$file:$lineno: BUILD is non-numeric"); - } elsif(not ($build =~ /\$\{BUILD:-\d+}/)) { - log_warning("$file:$lineno: BUILD ignores environment (try BUILD=\${BUILD:-$build}"); - } - } elsif(/^TAG=(\S+)/) { - $tag = dequote($1); - if($tag !~ /\$\{TAG:-(?:_SBo|("|')_SBo(\1))\}/) { - log_error("$file:$lineno: TAG=\${TAG:-_SBo} is required"); - } - } elsif(/^TMP=(\S+)/) { - $tmp = dequote($1); - if($tmp !~ m,\$\{TMP:-(?:/tmp/SBo|(["'])/tmp/SBo\1)\},) { - log_error("$file:$lineno: TMP=\${TMP:-/tmp/SBo} is required"); - } - } elsif(/^PKG=(\S+)/) { - $pkg = dequote($1); - $pkg =~ s,\$\{([A-Z]+)\},\$$1,; # de-brace - if($pkg ne '$TMP/package-$PRGNAM' && $pkg ne '$TMP/package-${PRGNAM}') { - log_error("$file:$lineno: PKG=\$TMP/package-\$PRGNAM is required"); - } - } elsif(/^OUTPUT=(\S+)/) { - $output = dequote($1); - if($output !~ m,\$\{OUTPUT:-(?:/tmp|(["'])/tmp\1)\},) { - log_error("$file:$lineno: OUTPUT=\${OUTPUT:-/tmp} is required"); - } - } elsif(/^[^#]*\$\{?CWD\}?\/doinst\.sh(?:"|'|\s|>)/) { - # 20220205 bkw: some scripts don't have a doinst.sh in the - # script dir, but they create one with >> (the jack rt audio stuff - # does this). - $need_doinst = $lineno; - } elsif(/^[^#]*\$\{?CWD\}?\/douninst\.sh(?:"|'|\s|>)/) { - $need_douninst = $lineno; - } elsif(/^[^#]*slack-desc/) { - $slackdesc = $lineno; - $install = $lineno if m,install/,; # assume OK - } elsif(/^[^#]*?cd\s+[{\$"]*PKG[}"]*/) { - $cdpkg = $lineno; - } elsif(/^[^#]*?["{\$]+PKG[}"]*\/install/) { - $install = $lineno; - } elsif($cdpkg && /^[^#]*mkdir[^#]*install/) { - $install = $lineno; - } elsif(/^[^#]*makepkg/) { - if(/\$\{PKGTYPE:-/) { - log_error("$file:$lineno: makepkg PKGTYPE doesn't match 15.0 template"); - } - if($makepkg) { - log_error("$file:$lineno: makepkg called twice (here and line $makepkg"); - } - $makepkg = $lineno; - } elsif(/^\s*?CWD=/) { - log_warning("$file:$lineno: lone CWD= assignment is redundant in 15.0 template"); - } elsif(/^\s*?chown\s/) { - if(!chown_ok($_)) { - log_warning("$file:$lineno: chown should use : instead of . for user:group separator"); - } - } elsif(/^[^#]*(SLCKFLAGS|PRGMAN|PGK)/) { - log_warning("$file:$lineno: $1 looks like a typo"); - } elsif(/^[^#]*npm\s+audit\s+fix/) { - log_error("$file:$lineno: scripts must not call 'npm audit fix'"); - } - - if(/^[^#]*<documentation>/) { - log_error("$file:$lineno: copy actual documentation, not <documentation>"); - } - - my $line = $_; - if(grep { $line =~ /$_/ } @boilerplate) { - log_warning("$file:$lineno: template comment should be removed"); - } - - # special case here: don't complain about this comment if it's a perl-* build - if($file !~ /^perl-/) { - if($line =~ /#\s*Remove perllocal.pod and other special files/) { - log_warning("$file:$lineno: template comment should be removed"); - } - } - - # 20220312 bkw: 15.0 template - if(/^[^#]*\$.*PRINT_PACKAGE_NAME/) { - $print_pkg_name = $lineno; - } - - # 20230204 bkw: more 15.0 template - if(/^PKGTYPE=/) { - $pkg_type = $lineno; - if(not /:-tgz/) { - log_error("$file:$lineno: PKGTYPE doesn't default to tgz"); - } - } - - if((not defined $arch_lineno) && (/\bARCH:?=/)) { - $arch_lineno = $lineno; - } - - # 20240402 bkw: we have a few scripts that do things like "ARCH=i386 make", - # this line should only detect bare assignments or "case". - if(/^[^#]*\bARCH=['"]?i[34]86['"]?[;\s]*$/) { - $old_arch = $lineno; - } - - if(/^[^#]*\s-march=['"]?i[34]86/) { - $old_flags = $lineno; - } - - if(/^\s*python\s/) { - log_note("$file:$lineno: suggest replacing 'python' with 'python2' for future-proofing"); - $have_py2 = $lineno; - } - - if(/^\s*python2\s/) { - $have_py2 = $lineno; - } - - if(/^\s*python3\s/) { - $have_py3 = $lineno; - } - - if(/^[^#]*LIBDIRSUFFIX=/) { - $libsuf_set = $lineno; - } - if(/^[^#]*SLKCFLAGS=/) { - $flags_set = $lineno; - } - if(/^[^#]*\$\{?LIBDIRSUFFIX/) { - $libsuf_used = $lineno; - } - if(/^[^#]*\$\{?SLKCFLAGS/) { - $flags_used = $lineno; - } - - if(/^[^#]*set\s+([^#]+)/) { - my $arg = $1; - $set_e = $lineno if $arg =~ /e/; - } - - if(/^[^#]*\|\|\s+exit\s+1/) { - $or_exit_1 = $lineno; - } - } - - if(not defined($prgnam)) { - log_error("$file: no PRGNAM= line"); - } - - if(not defined($version)) { - log_error("$file: no VERSION= line"); - } - - if(not defined($build)) { - log_error("$file: no BUILD= line"); - } - - if(not defined($tag)) { - log_error("$file: no TAG= line"); - } - - if(not defined($tmp)) { - log_error("$file: no TMP= line"); - } - - if(not defined($pkg)) { - log_error("$file: no PKG= line"); - } - - if(not defined($output)) { - log_error("$file: no OUTPUT= line"); - } - - if(not defined($slackdesc)) { - log_error("$file: doesn't seem to install slack-desc in \$PKG/install"); - } - - if(not defined($makepkg)) { - log_error("$file: no makepkg command found"); - } - - # 20230204 bkw: better support for 15.0 template. - if(defined($print_pkg_name)) { - if((!defined $pkg_type) || ($pkg_type > $print_pkg_name)) { - log_error("$file: PKGTYPE not defined before PRINT_PACKAGE_NAME stanza (Slackware >= 15.0)"); - } - if((!defined $arch_lineno) || ($arch_lineno > $print_pkg_name)) { - log_error("$file: ARCH not defined before PRINT_PACKAGE_NAME stanza (Slackware >= 15.0)"); - } - } else { - log_error("$file: missing PRINT_PACKAGE_NAME stanza (Slackware >= 15.0)"); - } - - if(not defined($install)) { - log_error("$file: nothing gets installed in \$PKG/install"); - } - - my $have_doinst = (-f "doinst.sh"); - my $have_douninst = (-f "douninst.sh"); - - if($have_doinst) { - check_and_read("doinst.sh", 0644); - } - - if($have_douninst) { - check_and_read("douninst.sh", 0644); - } - - if($need_doinst && !$have_doinst) { - log_error("$file:$need_doinst: script installs doinst.sh, but it doesn't exist"); - } elsif($have_doinst && !$need_doinst) { - log_error("$file: doinst.sh exists, but the script doesn't install it"); - } - - if($need_douninst && !$have_douninst) { - log_error("$file:$need_douninst: script installs douninst.sh, but it doesn't exist"); - } elsif($have_douninst && !$need_douninst) { - log_error("$file: douninst.sh exists, but the script doesn't install it"); - } - - if($old_arch) { - # checking for the flags is supposed to let us tell the difference between - # source builds and binary repacks. since we have 30 or so old binary repack - # builds that use ARCH=i386 or ARCH=i486, we make it a warning, not an error. - if($old_flags) { - log_error("$file:$old_arch: compiling for i386 or i486 is no longer supported"); - } else { - log_warning("$file:$old_arch: outdated ARCH, please update to i586"); - } - } elsif($old_flags) { - log_error("$file:$old_flags: archaic -march= compiler flag (we support i586 and up)"); - } - - if($have_py2 && $have_py3) { - log_note("$file: it looks like this build includes both python2 and python3 code. consider splitting it into separate python2- and python3- builds."); - } - - # SLKCFLAGS and LIBDIRSUFFIX are notes, not errs/warns, because there are - # over 2000 existing builds from before this was added. anyway, unused - # variables don't really hurt anything. - if($flags_set && (!$flags_used)) { - log_note("$file:$flags_set: SLKCFLAGS gets set, but never used."); - } - - if($libsuf_set && (!$libsuf_used)) { - log_note("$file:$libsuf_set: LIBDIRSUFFIX gets set, but never used."); - } - - ## warn "\$set_e: " . ($set_e || 0); - ## warn "\$bash_e_opt: " . ($bash_e_opt || 0); - ## warn "\$or_exit_1: " . ($or_exit_1 || 0); - - if(!(defined $set_e || defined $bash_e_opt || defined $or_exit_1)) { - log_error("$file: this script has no error checking (need bash -e option, 'set -e', or '|| exit 1')."); - } + my $file = $buildname . ".SlackBuild"; + + my $gotmode = get_mode($file); + my $mode_ok = 0; + my @octalmodes = (); + + for(@script_perms) { + push @octalmodes, sprintf("%04o", $_); + $mode_ok++ if $gotmode == $_; + } + + # warn "allowed modes: " . join(", ", @octalmodes); + + if(!$mode_ok) { + my $modes = join " or ", @octalmodes; + log_error("$file must have mode $modes, not %04o", $gotmode); + } + + my @lines = check_and_read($file); + return unless scalar @lines; + + my $bash_e_opt; + if($lines[0] !~ /^#!/) { + log_error("$file:1: missing or invalid shebang line (should be '#!/bin/bash')"); + } elsif($lines[0] =~ m,#!/bin/bash(?:\s+(-e|-eu|-ue|-e -u|-u -e))?\s*$,) { + my $arg = $1; + $bash_e_opt = 1 if defined($arg) && $arg =~ /e/; + } else { + log_warning("$file:1: shebang line should be #!/bin/bash (possibly with -e/-u arg(s)), not '$lines[0]'"); + } + + my $lineno = 0; + my ($prgnam, $version, $build, $tag, $need_doinst, $need_douninst, $slackdesc, $makepkg, $install); + my ($cdpkg, $codestart, $lint_enabled, $print_pkg_name, $pkg_type, $arch_lineno); + my ($old_arch, $old_flags, $have_py2, $have_py3); + my ($libsuf_set, $flags_set, $libsuf_used, $flags_used); + my ($set_e, $or_exit_1); + $lint_enabled = 1; + + for(@lines) { + $lineno++; + + if(/^\s*[^#]/ && !defined($codestart)) { + $codestart = $lineno; + if(not /^cd\s+"?\$\(\s*dirname\s+"?\$0.*CWD=.*pwd/) { + log_error("$file:$lineno: first line of code must be 'cd \$(dirname \$0) ; CWD=\$(pwd)'"); + } + } + + if(/^###sbolint\s*(\S+)/) { + my $arg = $1; + if(lc($arg) eq "on") { + $lint_enabled = 1; + } elsif(lc($arg) eq "off") { + $lint_enabled = 0; + } else { + log_warning("$file:$lineno: unknown ###sbolint argument '$arg' (should be 'on' or 'off')"); + } + } + + next unless $lint_enabled; + + # TODO: cp without -a (or -p, or a couple other flags) is OK. +## if(/^[^#]*cp\s+(?:-\w+\s+)*[\"\$\{]*CWD/) { +## log_error("$file:$lineno: copying files from CWD with cp (use cat instead)"); +## } + + if(/^PRGNAM=(\S+)/) { + if($prgnam) { + log_error("$file:$lineno: PRGNAM redefined"); + } + $prgnam = dequote($1); + if($prgnam ne $buildname) { + log_error("$file:$lineno: PRGNAM doesn't match dir name ($prgnam != $buildname)"); + } + } elsif(/^VERSION=(\S+)/ && ($lineno <= $codestart + 10)) { + $version = dequote($1); + if(not ($version =~ s/\$\{VERSION:-([^}]+)\}/$1/)) { + log_warning("$file:$lineno: VERSION ignores environment, try VERSION=\${VERSION:-$version}"); + } + $version = dequote($1); + if($version ne $info{VERSION}) { + log_error("$file:$lineno: VERSION ($version) doesn't match VERSION in the .info file ($info{VERSION})"); + } + } elsif(/^BUILD=(\S+)/) { + $build = dequote($1); + if(not ($build =~ /\d/)) { + log_error("$file:$lineno: BUILD is non-numeric"); + } elsif(not ($build =~ /\$\{BUILD:-\d+}/)) { + log_warning("$file:$lineno: BUILD ignores environment (try BUILD=\${BUILD:-$build}"); + } + } elsif(/^TAG=(\S+)/) { + $tag = dequote($1); + if($tag !~ /\$\{TAG:-(?:_SBo|("|')_SBo(\1))\}/) { + log_error("$file:$lineno: TAG=\${TAG:-_SBo} is required"); + } + } elsif(/^TMP=(\S+)/) { + $tmp = dequote($1); + if($tmp !~ m,\$\{TMP:-(?:/tmp/SBo|(["'])/tmp/SBo\1)\},) { + log_error("$file:$lineno: TMP=\${TMP:-/tmp/SBo} is required"); + } + } elsif(/^PKG=(\S+)/) { + $pkg = dequote($1); + $pkg =~ s,\$\{([A-Z]+)\},\$$1,; # de-brace + if($pkg ne '$TMP/package-$PRGNAM' && $pkg ne '$TMP/package-${PRGNAM}') { + log_error("$file:$lineno: PKG=\$TMP/package-\$PRGNAM is required"); + } + } elsif(/^OUTPUT=(\S+)/) { + $output = dequote($1); + if($output !~ m,\$\{OUTPUT:-(?:/tmp|(["'])/tmp\1)\},) { + log_error("$file:$lineno: OUTPUT=\${OUTPUT:-/tmp} is required"); + } + } elsif(/^[^#]*\$\{?CWD\}?\/doinst\.sh(?:"|'|\s|>)/) { + # 20220205 bkw: some scripts don't have a doinst.sh in the + # script dir, but they create one with >> (the jack rt audio stuff + # does this). + $need_doinst = $lineno; + } elsif(/^[^#]*\$\{?CWD\}?\/douninst\.sh(?:"|'|\s|>)/) { + $need_douninst = $lineno; + } elsif(/^[^#]*slack-desc/) { + $slackdesc = $lineno; + $install = $lineno if m,install/,; # assume OK + } elsif(/^[^#]*?cd\s+[{\$"]*PKG[}"]*/) { + $cdpkg = $lineno; + } elsif(/^[^#]*?["{\$]+PKG[}"]*\/install/) { + $install = $lineno; + } elsif($cdpkg && /^[^#]*mkdir[^#]*install/) { + $install = $lineno; + } elsif(/^[^#]*makepkg/) { + if(/\$\{PKGTYPE:-/) { + log_error("$file:$lineno: makepkg PKGTYPE doesn't match 15.0 template"); + } + if($makepkg) { + log_error("$file:$lineno: makepkg called twice (here and line $makepkg"); + } + $makepkg = $lineno; + } elsif(/^\s*?CWD=/) { + log_warning("$file:$lineno: lone CWD= assignment is redundant in 15.0 template"); + } elsif(/^\s*?chown\s/) { + if(!chown_ok($_)) { + log_warning("$file:$lineno: chown should use : instead of . for user:group separator"); + } + } elsif(/^[^#]*(SLCKFLAGS|PRGMAN|PGK)/) { + log_warning("$file:$lineno: $1 looks like a typo"); + } elsif(/^[^#]*npm\s+audit\s+fix/) { + log_error("$file:$lineno: scripts must not call 'npm audit fix'"); + } + + if(/^[^#]*<documentation>/) { + log_error("$file:$lineno: copy actual documentation, not <documentation>"); + } + + my $line = $_; + if(grep { $line =~ /$_/ } @boilerplate) { + log_warning("$file:$lineno: template comment should be removed"); + } + + # special case here: don't complain about this comment if it's a perl-* build + if($file !~ /^perl-/) { + if($line =~ /#\s*Remove perllocal.pod and other special files/) { + log_warning("$file:$lineno: template comment should be removed"); + } + } + + # 20220312 bkw: 15.0 template + if(/^[^#]*\$.*PRINT_PACKAGE_NAME/) { + $print_pkg_name = $lineno; + } + + # 20230204 bkw: more 15.0 template + if(/^PKGTYPE=/) { + $pkg_type = $lineno; + if(not /:-tgz/) { + log_error("$file:$lineno: PKGTYPE doesn't default to tgz"); + } + } + + if((not defined $arch_lineno) && (/\bARCH:?=/)) { + $arch_lineno = $lineno; + } + + # 20240402 bkw: we have a few scripts that do things like "ARCH=i386 make", + # this line should only detect bare assignments or "case". + if(/^[^#]*\bARCH=['"]?i[34]86['"]?[;\s]*$/) { + $old_arch = $lineno; + } + + if(/^[^#]*\s-march=['"]?i[34]86/) { + $old_flags = $lineno; + } + + if(/^\s*python\s/) { + log_note("$file:$lineno: suggest replacing 'python' with 'python2' for future-proofing"); + $have_py2 = $lineno; + } + + if(/^\s*python2\s/) { + $have_py2 = $lineno; + } + + if(/^\s*python3\s/) { + $have_py3 = $lineno; + } + + if(/^[^#]*LIBDIRSUFFIX=/) { + $libsuf_set = $lineno; + } + if(/^[^#]*SLKCFLAGS=/) { + $flags_set = $lineno; + } + if(/^[^#]*\$\{?LIBDIRSUFFIX/) { + $libsuf_used = $lineno; + } + if(/^[^#]*\$\{?SLKCFLAGS/) { + $flags_used = $lineno; + } + + if(/^[^#]*set\s+([^#]+)/) { + my $arg = $1; + $set_e = $lineno if $arg =~ /e/; + } + + if(/^[^#]*\|\|\s+exit\s+1/) { + $or_exit_1 = $lineno; + } + } + + if(not defined($prgnam)) { + log_error("$file: no PRGNAM= line"); + } + + if(not defined($version)) { + log_error("$file: no VERSION= line"); + } + + if(not defined($build)) { + log_error("$file: no BUILD= line"); + } + + if(not defined($tag)) { + log_error("$file: no TAG= line"); + } + + if(not defined($tmp)) { + log_error("$file: no TMP= line"); + } + + if(not defined($pkg)) { + log_error("$file: no PKG= line"); + } + + if(not defined($output)) { + log_error("$file: no OUTPUT= line"); + } + + if(not defined($slackdesc)) { + log_error("$file: doesn't seem to install slack-desc in \$PKG/install"); + } + + if(not defined($makepkg)) { + log_error("$file: no makepkg command found"); + } + + # 20230204 bkw: better support for 15.0 template. + if(defined($print_pkg_name)) { + if((!defined $pkg_type) || ($pkg_type > $print_pkg_name)) { + log_error("$file: PKGTYPE not defined before PRINT_PACKAGE_NAME stanza (Slackware >= 15.0)"); + } + if((!defined $arch_lineno) || ($arch_lineno > $print_pkg_name)) { + log_error("$file: ARCH not defined before PRINT_PACKAGE_NAME stanza (Slackware >= 15.0)"); + } + } else { + log_error("$file: missing PRINT_PACKAGE_NAME stanza (Slackware >= 15.0)"); + } + + if(not defined($install)) { + log_error("$file: nothing gets installed in \$PKG/install"); + } + + my $have_doinst = (-f "doinst.sh"); + my $have_douninst = (-f "douninst.sh"); + + if($have_doinst) { + check_and_read("doinst.sh", 0644); + } + + if($have_douninst) { + check_and_read("douninst.sh", 0644); + } + + if($need_doinst && !$have_doinst) { + log_error("$file:$need_doinst: script installs doinst.sh, but it doesn't exist"); + } elsif($have_doinst && !$need_doinst) { + log_error("$file: doinst.sh exists, but the script doesn't install it"); + } + + if($need_douninst && !$have_douninst) { + log_error("$file:$need_douninst: script installs douninst.sh, but it doesn't exist"); + } elsif($have_douninst && !$need_douninst) { + log_error("$file: douninst.sh exists, but the script doesn't install it"); + } + + if($old_arch) { + # checking for the flags is supposed to let us tell the difference between + # source builds and binary repacks. since we have 30 or so old binary repack + # builds that use ARCH=i386 or ARCH=i486, we make it a warning, not an error. + if($old_flags) { + log_error("$file:$old_arch: compiling for i386 or i486 is no longer supported"); + } else { + log_warning("$file:$old_arch: outdated ARCH, please update to i586"); + } + } elsif($old_flags) { + log_error("$file:$old_flags: archaic -march= compiler flag (we support i586 and up)"); + } + + if($have_py2 && $have_py3) { + log_note("$file: it looks like this build includes both python2 and python3 code. consider splitting it into separate python2- and python3- builds."); + } + + # SLKCFLAGS and LIBDIRSUFFIX are notes, not errs/warns, because there are + # over 2000 existing builds from before this was added. anyway, unused + # variables don't really hurt anything. + if($flags_set && (!$flags_used)) { + log_note("$file:$flags_set: SLKCFLAGS gets set, but never used."); + } + + if($libsuf_set && (!$libsuf_used)) { + log_note("$file:$libsuf_set: LIBDIRSUFFIX gets set, but never used."); + } + + ## warn "\$set_e: " . ($set_e || 0); + ## warn "\$bash_e_opt: " . ($bash_e_opt || 0); + ## warn "\$or_exit_1: " . ($or_exit_1 || 0); + + if(!(defined $set_e || defined $bash_e_opt || defined $or_exit_1)) { + log_error("$file: this script has no error checking (need bash -e option, 'set -e', or '|| exit 1')."); + } } sub check_doinst { - my $file = "doinst.sh"; - return unless -f $file; - my @lines = check_and_read($file); - return unless scalar @lines; - - my $lineno = 0; - my ($config_defined, $icon_theme_check, $pp_defined); - - for(@lines) { - $lineno++; - s,#.*,,; - s,^\s*,,; - s,\s*$,,; - next unless /./; - - if(/chmod/) { - log_note("$file:$lineno: doinst.sh should not use chmod; set file permissions while building the package."); - } elsif(/\$\{?PKG\}?/ || /"\$PKG"/) { - log_error("$file:$lineno: doinst.sh must not use \$PKG; package root is the current directory."); - } elsif(/^config\(\)/) { - $config_defined = $lineno; - } elsif(/^config\s+/) { - # the [\@\$] is intended to skip stuff like $NEW, or a for loop variable, - # or something intended to be sedded like @PATH@. - if(/^config\s+\//) { - log_error("$file:$lineno: 'config' uses absolute path."); - } - if(!/[\@\$]/ && !/\.new["']?$/) { - log_error("$file:$lineno: 'config' filename missing .new suffix."); - } - if(!$config_defined) { - log_error("$file:$lineno: 'config' function used, but not defined."); - } - } elsif(/^preserve_perms\(\)/) { - $pp_defined = $lineno; - } elsif(/^preserve_perms\s+/) { - if(/^preserve_perms\s+\//) { - log_error("$file:$lineno: 'preserve_perms' uses absolute path."); - } - if(!/[\@\$]/ && !/\.new["']?$/) { - log_error("$file:$lineno: 'preserve_perms' filename missing .new suffix."); - } - if(!$pp_defined) { - log_error("$file:$lineno: 'preserve_perms' function used, but not defined."); - } - } elsif(m,-e\s+(\/usr)?\S*icon-theme\.cache,) { - if(defined $1) { - log_error("$file:$lineno: bad icon cache check (/usr/, should be usr/)"); - } - $icon_theme_check = $lineno; - } elsif(m,^[^[#]*gtk-update-icon-cache,) { - if(!$icon_theme_check) { - log_error("$file:$lineno: icon cache created unconditionally!"); - } - undef $icon_theme_check; # in case there's multiple icon dirs - } - } + my $file = "doinst.sh"; + return unless -f $file; + my @lines = check_and_read($file); + return unless scalar @lines; + + my $lineno = 0; + my ($config_defined, $icon_theme_check, $pp_defined); + + for(@lines) { + $lineno++; + s,#.*,,; + s,^\s*,,; + s,\s*$,,; + next unless /./; + + if(/chmod/) { + log_note("$file:$lineno: doinst.sh should not use chmod; set file permissions while building the package."); + } elsif(/\$\{?PKG\}?/ || /"\$PKG"/) { + log_error("$file:$lineno: doinst.sh must not use \$PKG; package root is the current directory."); + } elsif(/^config\(\)/) { + $config_defined = $lineno; + } elsif(/^config\s+/) { + # the [\@\$] is intended to skip stuff like $NEW, or a for loop variable, + # or something intended to be sedded like @PATH@. + if(/^config\s+\//) { + log_error("$file:$lineno: 'config' uses absolute path."); + } + if(!/[\@\$]/ && !/\.new["']?$/) { + log_error("$file:$lineno: 'config' filename missing .new suffix."); + } + if(!$config_defined) { + log_error("$file:$lineno: 'config' function used, but not defined."); + } + } elsif(/^preserve_perms\(\)/) { + $pp_defined = $lineno; + } elsif(/^preserve_perms\s+/) { + if(/^preserve_perms\s+\//) { + log_error("$file:$lineno: 'preserve_perms' uses absolute path."); + } + if(!/[\@\$]/ && !/\.new["']?$/) { + log_error("$file:$lineno: 'preserve_perms' filename missing .new suffix."); + } + if(!$pp_defined) { + log_error("$file:$lineno: 'preserve_perms' function used, but not defined."); + } + } elsif(m,-e\s+(\/usr)?\S*icon-theme\.cache,) { + if(defined $1) { + log_error("$file:$lineno: bad icon cache check (/usr/, should be usr/)"); + } + $icon_theme_check = $lineno; + } elsif(m,^[^[#]*gtk-update-icon-cache,) { + if(!$icon_theme_check) { + log_error("$file:$lineno: icon cache created unconditionally!"); + } + undef $icon_theme_check; # in case there's multiple icon dirs + } + } } sub chown_ok { - my $cmd = shift; - $cmd =~ s/#.*//; # get rid of comment, if any - $cmd =~ s/^\s+//; # get rid of leading whitespace, if any - - # assign 1st element to undef, to get rid of the chown command itself - my (undef, @args) = split /\s+/, $cmd; - - # what remains should include user:group or user.group. if it doesn't, - # don't complain: possibly the --reference option is being used. - # dots are OK in file paths (e.g. chown root:root /etc/blah.d/blah). - # we can't easily tell which is which, but *something* should have a colon. - my $dot; - for my $arg (@args) { - return 1 if /:/; # found :, we're OK. - next if /\//; # if there's a /, it's a filename (dots are OK). - $dot++ if /\./; # found a dot, might be not OK. - } - - # if we get here, there are no colons. if there *is* a dot, return failure. - return !$dot; + my $cmd = shift; + $cmd =~ s/#.*//; # get rid of comment, if any + $cmd =~ s/^\s+//; # get rid of leading whitespace, if any + + # assign 1st element to undef, to get rid of the chown command itself + my (undef, @args) = split /\s+/, $cmd; + + # what remains should include user:group or user.group. if it doesn't, + # don't complain: possibly the --reference option is being used. + # dots are OK in file paths (e.g. chown root:root /etc/blah.d/blah). + # we can't easily tell which is which, but *something* should have a colon. + my $dot; + for my $arg (@args) { + return 1 if /:/; # found :, we're OK. + next if /\//; # if there's a /, it's a filename (dots are OK). + $dot++ if /\./; # found a dot, might be not OK. + } + + # if we get here, there are no colons. if there *is* a dot, return failure. + return !$dot; } sub findem { - my ($findcmd, $errmsg) = @_; - open my $fh, "-|", "$findcmd"; - while(<$fh>) { - chomp; - s,^\./,,; - log_error("$errmsg: $_"); - } - close $fh; + my ($findcmd, $errmsg) = @_; + open my $fh, "-|", "$findcmd"; + while(<$fh>) { + chomp; + s,^\./,,; + log_error("$errmsg: $_"); + } + close $fh; } # empty/hidden files/dirs. sub check_empty_hidden { - findem("find . -type d -a -empty", "empty directory"); - findem("find . -type f -a -empty", "empty file"); - findem("find . -type d -a -name '.*' -a ! -name . -a ! -name ..", "hidden directory"); - findem("find . -type f -a -name '.*'", "hidden file"); + findem("find . -type d -a -empty", "empty directory"); + findem("find . -type f -a -empty", "empty file"); + findem("find . -type d -a -name '.*' -a ! -name . -a ! -name ..", "hidden directory"); + findem("find . -type f -a -name '.*'", "hidden file"); } # stuff like editor backups and dangling symlinks. @@ -1961,140 +1961,140 @@ sub check_empty_hidden { # directories are OK, but hidden dirs are not. # note that this check only gets called when checking a tarball (not a dir). sub check_junkfiles { - my @sources = split(/\s+/, $info{DOWNLOAD} . " " . $info{DOWNLOAD_x86_64}); - s,.*/,, for @sources; - @sources = grep { $_ !~ /^(?:\s*|UNTESTED|UNSUPPORTED)$/ } @sources; - if(!grep { $_ =~ /^v$info{VERSION}\./ } @sources) { - push @sources, "v$info{VERSION}.$_" for qw /zip tar.gz tar.bz2 tar.xz/; - } - - open my $fh, "-|", "find . ! -type d -print0 | xargs -0 file --mime-type"; - FILE: while(<$fh>) { - chomp; - my ($file, $type) = split /: */, $_, 2; - $file =~ s,^\./,,; - - # skip the files caught by other checks - next if $file eq "$buildname.SlackBuild"; - next if $file eq "$buildname.info"; - next if $file eq "README"; - next if $file eq "slack-desc"; - next if $file =~ /(?:diff|patch)$/; - - check_mode($file, 0644); - - if(grep { $_ eq $file } @sources) { - log_error("source archive found: $file"); - next FILE; - } - - for($file) { - (/\.swp\w*$/ || /#/ || /~/ ) && do { - log_error("editor backup found: $file"); - next FILE; - }; - /^\./ && do { - log_error("hidden file found: $file"); - next FILE; - }; - /\.(?:orig|bak|old)[^.]*$/ && do { - log_warning("$file looks like sort some of backup file"); - next FILE; - }; - /^(?:build.log|strace.out)/ && do { - log_warning("$file is a build log"); - next FILE; - }; - /\.rej$/ && do { - log_warning("$file is a patch reject"); - next FILE; - }; - /\.desktop$/ && do { - system("desktop-file-validate $file"); - if($? != 0) { - log_warning("$file fails desktop-file-validate"); - next FILE; - } - } - } - - for($type) { - ($_ eq "inode/x-empty") && do { - log_error("$file is empty (0 bytes long)"); - next FILE; - }; - ($_ =~ /^inode/) && do { - log_error("$file is $type, not a regular file or directory"); - next FILE; - }; - ($_ =~ m,application/x-(?:executable|dosexec|object|coredump),) && do { - log_error("$file is object code ($type)"); - next FILE; - }; - } - - my $size = -s $file; - if($size > 1024 * 100) { - log_warning("$file is large ($size bytes), may be rejected by submission form"); - } - } - close $fh; - - open $fh, "-|", "find . -type d -mindepth 1"; - while(<$fh>) { - chomp; - s,\./,,; - - if(/^\./) { - log_error("found hidden directory: $_"); - next; - } - - if(glob("$_/*.o")) { - log_error("$_ contains compiled object files (leftover source tree?)"); - next; - } - - for my $badfile (qw/Makefile configure CmakeLists.txt makefile.pl SConstruct/) { - if(-f "$_/$badfile") { - log_error("$_ looks like extracted source tree (contains $badfile)"); - } - } - } - close $fh; - -# # this won't always catch everything (e.g. PRGNAM=foo VERSION=1, but the -# # extracted dir is foo1 or foo_1 or foo-source-1). -# if(-d "$buildname-$version") { -# log_warning("$buildname-$version/ looks like extracted source dir"); -# } + my @sources = split(/\s+/, $info{DOWNLOAD} . " " . $info{DOWNLOAD_x86_64}); + s,.*/,, for @sources; + @sources = grep { $_ !~ /^(?:\s*|UNTESTED|UNSUPPORTED)$/ } @sources; + if(!grep { $_ =~ /^v$info{VERSION}\./ } @sources) { + push @sources, "v$info{VERSION}.$_" for qw /zip tar.gz tar.bz2 tar.xz/; + } + + open my $fh, "-|", "find . ! -type d -print0 | xargs -0 file --mime-type"; + FILE: while(<$fh>) { + chomp; + my ($file, $type) = split /: */, $_, 2; + $file =~ s,^\./,,; + + # skip the files caught by other checks + next if $file eq "$buildname.SlackBuild"; + next if $file eq "$buildname.info"; + next if $file eq "README"; + next if $file eq "slack-desc"; + next if $file =~ /(?:diff|patch)$/; + + check_mode($file, 0644); + + if(grep { $_ eq $file } @sources) { + log_error("source archive found: $file"); + next FILE; + } + + for($file) { + (/\.swp\w*$/ || /#/ || /~/ ) && do { + log_error("editor backup found: $file"); + next FILE; + }; + /^\./ && do { + log_error("hidden file found: $file"); + next FILE; + }; + /\.(?:orig|bak|old)[^.]*$/ && do { + log_warning("$file looks like sort some of backup file"); + next FILE; + }; + /^(?:build.log|strace.out)/ && do { + log_warning("$file is a build log"); + next FILE; + }; + /\.rej$/ && do { + log_warning("$file is a patch reject"); + next FILE; + }; + /\.desktop$/ && do { + system("desktop-file-validate $file"); + if($? != 0) { + log_warning("$file fails desktop-file-validate"); + next FILE; + } + } + } + + for($type) { + ($_ eq "inode/x-empty") && do { + log_error("$file is empty (0 bytes long)"); + next FILE; + }; + ($_ =~ /^inode/) && do { + log_error("$file is $type, not a regular file or directory"); + next FILE; + }; + ($_ =~ m,application/x-(?:executable|dosexec|object|coredump),) && do { + log_error("$file is object code ($type)"); + next FILE; + }; + } + + my $size = -s $file; + if($size > 1024 * 100) { + log_warning("$file is large ($size bytes), may be rejected by submission form"); + } + } + close $fh; + + open $fh, "-|", "find . -type d -mindepth 1"; + while(<$fh>) { + chomp; + s,\./,,; + + if(/^\./) { + log_error("found hidden directory: $_"); + next; + } + + if(glob("$_/*.o")) { + log_error("$_ contains compiled object files (leftover source tree?)"); + next; + } + + for my $badfile (qw/Makefile configure CmakeLists.txt makefile.pl SConstruct/) { + if(-f "$_/$badfile") { + log_error("$_ looks like extracted source tree (contains $badfile)"); + } + } + } + close $fh; + +# this won't always catch everything (e.g. PRGNAM=foo VERSION=1, but the +# extracted dir is foo1 or foo_1 or foo-source-1). +# if(-d "$buildname-$version") { +# log_warning("$buildname-$version/ looks like extracted source dir"); +# } } # 20250114 bkw: if we're in a git repo and these files exist, but are # not checked in to git, that generally means someone forgot to 'git # add' them. sub not_in_git { - open my $gitpipe, "git status --porcelain=2 . |"; - if(!$gitpipe) { - log_error("can't run 'git status' but we're in a git repo"); - return; - } - - while(<$gitpipe>) { - chomp; - - my ($file) = (/^\?\s(.*)/); - next unless $file; - - for($file) { - my $msg = "$file not in git repo, did you mean to add it?"; - if(/^.*\.(?:diff|patch|sh|desktop)/) { - log_warning($msg); - } else { - log_note($msg); - } - } - } + open my $gitpipe, "git status --porcelain=2 . |"; + if(!$gitpipe) { + log_error("can't run 'git status' but we're in a git repo"); + return; + } + + while(<$gitpipe>) { + chomp; + + my ($file) = (/^\?\s(.*)/); + next unless $file; + + for($file) { + my $msg = "$file not in git repo, did you mean to add it?"; + if(/^.*\.(?:diff|patch|sh|desktop)/) { + log_warning($msg); + } else { + log_note($msg); + } + } + } } # if anything *.diff or *.patch contains \r, warn the @@ -2102,10 +2102,10 @@ sub not_in_git { # 20231223 bkw: this check relies on check_and_read special-casing # filenames ending in *.diff or *.patch. sub check_patches { - my $patches = `find . \\( -iname '*.diff' -o -iname '*.patch' \\) -print0`; - for(split /\x00/, $patches) { - check_and_read($_, 0644); - } + my $patches = `find . \\( -iname '*.diff' -o -iname '*.patch' \\) -print0`; + for(split /\x00/, $patches) { + check_and_read($_, 0644); + } } # checking an image is a bit of a PITA. "file" can tell us if it's @@ -2114,43 +2114,43 @@ sub check_patches { # "convert" will, but it always returns 0/success, so we have to # parse its output. sub im_check_img { - our %ext2mime; - my $mime; - my $ok = 1; - - %ext2mime = ( - png => 'image/png', - jpg => 'image/jpeg', - xpm => 'image/x-xpm', - gif => 'image/gif', - ) unless %ext2mime; - - my $img = shift; - my $ext = $img; - $ext =~ s,.*\.,,; - $ext = lc $ext; - - chomp($mime = `file -L --brief --mime "$img"`); - if($mime !~ /$ext2mime{$ext}/) { - log_error("$img has wrong extension $ext (MIME type is $mime)"); - return; - } - - open my $im, "convert \"$img\" png:/dev/null 2>&1 |"; - while(<$im>) { - $ok = 0 if /premature|corrupt/i; - } - close $im; - - log_error("$img appears to be corrupt") unless $ok; + our %ext2mime; + my $mime; + my $ok = 1; + + %ext2mime = ( + png => 'image/png', + jpg => 'image/jpeg', + xpm => 'image/x-xpm', + gif => 'image/gif', + ) unless %ext2mime; + + my $img = shift; + my $ext = $img; + $ext =~ s,.*\.,,; + $ext = lc $ext; + + chomp($mime = `file -L --brief --mime "$img"`); + if($mime !~ /$ext2mime{$ext}/) { + log_error("$img has wrong extension $ext (MIME type is $mime)"); + return; + } + + open my $im, "convert \"$img\" png:/dev/null 2>&1 |"; + while(<$im>) { + $ok = 0 if /premature|corrupt/i; + } + close $im; + + log_error("$img appears to be corrupt") unless $ok; } sub check_images { - my $images = `find . \\( -iname '*.jpg' -o -iname '*.png' -o -iname '*.xpm' -o -iname '*.gif' \\) -print0`; - for(split /\x00/, $images) { - check_mode($_, 0644); - im_check_img($_); - } + my $images = `find . \\( -iname '*.jpg' -o -iname '*.png' -o -iname '*.xpm' -o -iname '*.gif' \\) -print0`; + for(split /\x00/, $images) { + check_mode($_, 0644); + im_check_img($_); + } } # 20260816 bkw: all these *_package_list() functions are here to @@ -2158,131 +2158,131 @@ sub check_images { # package list (pkglist.txt) can be in the script directory or # share/ under the PREFIX. sub find_package_list { - (my $cur) = (abs_path($0) =~ m,^(.*)/,); - my @check = ( $cur, '@PREFIX@/share/sbo-maintainer-tools' ); + (my $cur) = (abs_path($0) =~ m,^(.*)/,); + my @check = ( $cur, '@PREFIX@/share/sbo-maintainer-tools' ); - for(@check) { - my $path = "$_/pkglist.txt"; - return $path if -e $path; - } + for(@check) { + my $path = "$_/pkglist.txt"; + return $path if -e $path; + } - return undef; + return undef; } # only gets called once per run (even when linting multiple builds) sub load_package_list { - my $file = find_package_list(); - if(not defined $file) { - warn "$SELF: no pkglist.txt, not checking package name (try -U)\n"; - return; - } - - ## warn "loading packages from $file\n"; - open my $fh, "<", $file or die "$SELF: $file: $!"; - while(<$fh>) { - chomp; - $pkglist{lc $_}++; - } - close $fh; - - ## warn "pkglist.txt loaded, " . (keys %pkglist) . " packages\n"; + my $file = find_package_list(); + if(not defined $file) { + warn "$SELF: no pkglist.txt, not checking package name (try -U)\n"; + return; + } + + ## warn "loading packages from $file\n"; + open my $fh, "<", $file or die "$SELF: $file: $!"; + while(<$fh>) { + chomp; + $pkglist{lc $_}++; + } + close $fh; + + ## warn "pkglist.txt loaded, " . (keys %pkglist) . " packages\n"; } # logs an error if pkglist.txt has the same package name. note that this is # case-insensitive, so if someone tries to submit "mplayer", Slackware's # "MPlayer" will match. sub check_package_list { - if(!$pkglist_tried) { - load_package_list; - $pkglist_tried++; - } + if(!$pkglist_tried) { + load_package_list; + $pkglist_tried++; + } - return unless %pkglist; + return unless %pkglist; - if($pkglist{lc $buildname}) { - log_error("$buildname is already in core Slackware!"); - } + if($pkglist{lc $buildname}) { + log_error("$buildname is already in core Slackware!"); + } } # 20260816 bkw: find the right pair of PACKAGES.TXT files for this Slackware release. sub get_package_list_urls { - my $urlbase = $ENV{SBOLINT_MIRROR} || "https://slackware.uk/slackware"; - $urlbase =~ s,/*$,,; - - my $bits = ""; - my $stable = 0; - my $slackver; - my $is_slackware = 0; - my $arch; - - # 20260816 bkw: I got a question. Why the hell doesn't /etc/os-release define - # an ARCH= key? I have to look at the "pretty name" to get the arch... - open my $f, "</etc/os-release" or die "$SELF: /etc/os-release: $!\n"; - while(<$f>) { - chomp; - $is_slackware++ if /^NAME=Slackware$/; - $arch = $1 if /^PRETTY_NAME.*\s+(\S+)"/; - $stable = 1 if /^VERSION_CODENAME=stable/; - $slackver = $1 if /^VERSION_ID=(.*)$/; - } - close $f; - - if($arch eq 'x86_64') { - $bits = 64; - } elsif($arch =~ /^i\d86/) { - $bits = ""; - } else { - die "$SELF: -U only works for i?86 or x86_64, not '$arch'\n"; - } - - die "$SELF: can't update package list for non-Slackware OS\n" unless $is_slackware; - die "$SELF: can't update package list for -current\n" unless $stable; - die "$SELF: can't tell what version of Slackware this is\n" unless defined $slackver; - - return ( - "$urlbase/slackware$bits-$slackver/PACKAGES.TXT", - "$urlbase/slackware$bits-$slackver/patches/PACKAGES.TXT"); + my $urlbase = $ENV{SBOLINT_MIRROR} || "https://slackware.uk/slackware"; + $urlbase =~ s,/*$,,; + + my $bits = ""; + my $stable = 0; + my $slackver; + my $is_slackware = 0; + my $arch; + + # 20260816 bkw: I got a question. Why the hell doesn't /etc/os-release define + # an ARCH= key? I have to look at the "pretty name" to get the arch... + open my $f, "</etc/os-release" or die "$SELF: /etc/os-release: $!\n"; + while(<$f>) { + chomp; + $is_slackware++ if /^NAME=Slackware$/; + $arch = $1 if /^PRETTY_NAME.*\s+(\S+)"/; + $stable = 1 if /^VERSION_CODENAME=stable/; + $slackver = $1 if /^VERSION_ID=(.*)$/; + } + close $f; + + if($arch eq 'x86_64') { + $bits = 64; + } elsif($arch =~ /^i\d86/) { + $bits = ""; + } else { + die "$SELF: -U only works for i?86 or x86_64, not '$arch'\n"; + } + + die "$SELF: can't update package list for non-Slackware OS\n" unless $is_slackware; + die "$SELF: can't update package list for -current\n" unless $stable; + die "$SELF: can't tell what version of Slackware this is\n" unless defined $slackver; + + return ( + "$urlbase/slackware$bits-$slackver/PACKAGES.TXT", + "$urlbase/slackware$bits-$slackver/patches/PACKAGES.TXT"); } # 20260816 bkw: note: don't use die() here, use warn() followed by exit(1). sub update_package_list { - my @urls = get_package_list_urls(); - my $file = find_package_list(); - - if(not defined $file) { - warn "$SELF: can't find pkglist.txt, create it manually (with touch)\n"; - exit 1; - } - - warn "$SELF: updating $file from $urls[0] and $urls[1]\n"; - - my $count = 0; - open my $curl, "-|", "curl", "-sS", $urls[0], $urls[1] or do { - warn "$SELF: curl: $!\n"; - exit 1; - }; - - my %pkgs; - while(<$curl>) { - chomp; - next unless /^PACKAGE DESCRIPTION/; - chomp(my $p = <$curl>); - $p =~ s/:.*//; - $pkgs{$p}++; - } - close $curl; - - open my $pl, ">", $file or die "$SELF: $file: $!\n"; - for(sort keys %pkgs) { - $count++; - print $pl $_ . "\n"; - } - close $pl; - - warn "$SELF: $count package names written to $file\n"; - if($count < 1000) { - warn "$SELF: $count doesn't seem like enough packages for a Slackware release, does it?\n"; - exit 1; - } - exit 0; + my @urls = get_package_list_urls(); + my $file = find_package_list(); + + if(not defined $file) { + warn "$SELF: can't find pkglist.txt, create it manually (with touch)\n"; + exit 1; + } + + warn "$SELF: updating $file from $urls[0] and $urls[1]\n"; + + my $count = 0; + open my $curl, "-|", "curl", "-sS", $urls[0], $urls[1] or do { + warn "$SELF: curl: $!\n"; + exit 1; + }; + + my %pkgs; + while(<$curl>) { + chomp; + next unless /^PACKAGE DESCRIPTION/; + chomp(my $p = <$curl>); + $p =~ s/:.*//; + $pkgs{$p}++; + } + close $curl; + + open my $pl, ">", $file or die "$SELF: $file: $!\n"; + for(sort keys %pkgs) { + $count++; + print $pl $_ . "\n"; + } + close $pl; + + warn "$SELF: $count package names written to $file\n"; + if($count < 1000) { + warn "$SELF: $count doesn't seem like enough packages for a Slackware release, does it?\n"; + exit 1; + } + exit 0; } |
