aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2020-11-26 14:11:40 -0500
committerB. Watson <yalhcru@gmail.com>2020-11-26 14:11:40 -0500
commit0457ce3d5601de62f695d8a0759a7c0b6923701c (patch)
treec4d4c6c8ec44e2158d9376d5586a5b5a2120323d
parent9ab3b2a64c3f30cda470f7c1066b4ea6de3b53a3 (diff)
downloadsbostuff-0457ce3d5601de62f695d8a0759a7c0b6923701c.tar.gz
mkslackinfo: add github URL rewriting, check the result against Content-Disposition
-rwxr-xr-xmkslackinfo47
1 files changed, 47 insertions, 0 deletions
diff --git a/mkslackinfo b/mkslackinfo
index 48ef089..40198dd 100755
--- a/mkslackinfo
+++ b/mkslackinfo
@@ -92,12 +92,59 @@ EOF
return $cmd;
}
+sub check_github_disposition {
+ my $url = shift;
+ my $filename = shift;
+ my $disposition;
+
+ warn "Checking github Content-Disposition header\n";
+ open my $fh, "wget --quiet --save-headers -O- $url|";
+ while(<$fh>) {
+ s/\r//;
+ if(/^Content-Disposition:\s*attachment;\s*filename=(.*)$/i) {
+ $disposition = $1;
+ last;
+ }
+ last if /^$/;
+ }
+ close $fh;
+
+ if(not defined $disposition) {
+ die "!!! Got no Content-Disposition header from github!\n";
+ } elsif($filename eq $disposition) {
+ warn "=== URL filename matches Content-Disposition filename, good.\n";
+ } else {
+ die "!!! Content-Disposition filename mismatch:\n!!! local: $filename\n!!! remote: $disposition\n";
+ }
+}
+
+sub fix_github_url {
+ my $u = shift;
+ return $u unless ($u =~ m,https?://github.com/([^/]+)/([^/]+)/archive/([^/]+)(\.(?:tar.gz|zip))$,);
+ my $user = $1;
+ my $proj = $2;
+ my $aversion = $3;
+ my $pversion = $3;
+ my $ext = $4;
+
+ warn "Converting short-form github URL to long form\n";
+ $pversion =~ s/^v//; # maybe other letters?
+ my $filename = "$proj-$pversion$ext";
+ $u = "https://github.com/$user/$proj/archive/$aversion/$proj-$pversion$ext";
+ check_github_disposition($u, $filename);
+ warn "=== Rewrote github URL as: $url\n";
+ return $u;
+}
+
+### main()
$url = shift || &usage;
# Take package name from the current dir
chomp ($package = `pwd`);
$package =~ s,.*/,,;
+$url = fix_github_url($url);
+
# Take filename from last part of URL
($file = $url) =~ s,.*/,,;