aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-04-02 13:19:47 -0400
committerB. Watson <urchlay@slackware.uk>2024-04-02 13:20:43 -0400
commit4ec9e1c470394e99e21ce669fb42d853c950dd94 (patch)
tree0984f4fde1e877d82cc9db975b857d1b8dd3f640
parente930dd2b0b82d133176e93a6a9855ac2a2d367c8 (diff)
downloadsbo-maintainer-tools-4ec9e1c470394e99e21ce669fb42d853c950dd94.tar.gz
sbofixinfo: fix non-canonical github archive/ URLs.
-rwxr-xr-xsbofixinfo56
1 files changed, 56 insertions, 0 deletions
diff --git a/sbofixinfo b/sbofixinfo
index a1eff12..7b1e9ed 100755
--- a/sbofixinfo
+++ b/sbofixinfo
@@ -83,6 +83,28 @@ original and 'corrected' key names using your own eyeballs and brain.
If there is no PRGNAM, it will be generated from the .info file's name
(minus the I<.info> extension).
+=item -
+
+Github archive/ download URLs will be "canonized". This means URLs of these
+forms:
+
+ https://github.com/user/project/archive/v1.2.3.tar.gz
+ https://github.com/user/project/archive/refs/tags/v1.2.3.tar.gz
+ https://github.com/user/project/archive/1.2.3.tar.gz
+ https://github.com/user/project/archive/refs/tags/1.2.3.tar.gz
+
+...will be rewritten as:
+
+ https://github.com/user/project/archive/<tag>/project-1.2.3.tar.gz
+
+..where <tag> will be v1.2.3 or 1.2.3, depending on whether the "v" was in the
+original URL.
+
+The purpose of this is to give a stable download filename, which won't vary depending
+on whether a browser or wget/curl is used to download the file.
+
+See https://slackbuilds.org/GITHUB_URLs.txt for more information.
+
=back
B<sbofixinfo> doesn't attempt to detect any other errors or dubious
@@ -138,6 +160,24 @@ B<sbolint>(1), B<sbopkglint>(1), B<sbodl>(1), B<sbopkg>(8), B<sboinstall>(1)
EMAIL
};
+sub fix_github_url {
+ my $url = shift;
+ return $url unless $url =~ m,/archive/,;
+
+ $url =~ s,refs/tags/,,;
+
+ (my $proto, undef, undef, $user, $proj, undef, $tag, $filename) = split /\//, $url;
+ return $url if defined $filename;
+
+ return $url unless $tag =~ s,\.tar\.gz$,,;
+ my $ver = $tag;
+ $ver =~ s,^v(\d),$1,;
+
+ $url = "https://github.com/$user/$proj/archive/$tag/$proj-$ver.tar.gz";
+ return $url;
+}
+
+## main()
$arg0 = @ARGV ? $ARGV[0] : undef;
for($arg0) {
defined || last;
@@ -303,6 +343,22 @@ sub fix_info {
}
close $fh;
+ # 20240331 bkw: fix github URLs, if needed.
+ for my $key (qw/DOWNLOAD DOWNLOAD_x86_64/) {
+ if($info{$key}) {
+ my @urls = split " ", $info{$key};
+ my @newurls;
+ for my $url (@urls) {
+ my $newurl = $url;
+ if($url =~ m,https://github.com/,) {
+ $newurl = fix_github_url($url);
+ }
+ push @newurls, $newurl;
+ }
+ $info{$key} = join " ", @newurls;
+ }
+ }
+
system("mv $file $file.bak");
open $fh, ">$file" or do {