diff options
-rwxr-xr-x | mkslackinfo | 47 |
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,.*/,,; |