From 97a7e8464438e173a357ea9a272f91e26a789ac5 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 7 Apr 2015 18:11:06 -0400 Subject: initial commit --- sbosubmit | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100755 sbosubmit (limited to 'sbosubmit') diff --git a/sbosubmit b/sbosubmit new file mode 100755 index 0000000..cbf3040 --- /dev/null +++ b/sbosubmit @@ -0,0 +1,124 @@ +#!/usr/bin/perl -w + +use LWP; +use Getopt::Std; + +@categories = qw/ +Academic +Accessibility +Audio +Business +Desktop +Development +Games +Graphics +Haskell +Libraries +Misc +Multimedia +Network +Office +Perl +Python +Ruby +System +/; + +sub usage { + my $cats = join("\n", @categories); + warn < [-e ] [-C ] [-k ] file + +If no -e option is given, the contents of ~/.sbo_email is used as the +email address (and it's a fatal error if the file's missing). + +The categories for -c are: + +$cats + +The -c argument is case-insensitive, and category names may be abbreviated +to the shortest unique prefix (e.g. "gr" for Graphics is OK, but "g" +is an error because it matches both Graphics and Games). + +No checking is done on the file before it's uploaded (other than its +existence). + +After the file is uploaded, the server's response is displayed via +"links -dump". $0's exit status does NOT reflect success/failure: it +will be zero if an upload was done, or non-zero if there's an error in +the arguments (in which case no upload is done). +EOF + exit($_[0] || 0); +} + +sub die_usage { + warn $_ . "\n" for @_; + usage(1); +} + +sub get_category { + my $in = shift; + my $orig = $in; + my @got; + + $in =~ s/[^A-Za-z]//g; + for(@categories) { + push @got, $_ if /^$in/i; + } + + if(!@got) { + die_usage("Invalid category '$orig'"); + } elsif(@got > 1) { + die_usage("Ambiguous category '$orig', matches: " . join(" ", @got)); + } else { + return $got[0]; + } +} + +if(!@ARGV || $ARGV[0] =~ /--?h(?:elp)?/i) { + usage; +} + +getopts('c:e:C:k:', \%opts); +($userfile, $junk) = @ARGV; + +die_usage("Unknown junk on command line: '$junk'") if $junk; +die_usage("No category (missing required -c arg)") unless $opts{c}; +$category = get_category($opts{c}); +chomp($submail = $opts{e} || `head -n1 ~/.sbo_email`); +die_usage("No email address (use -e or else create ~/.sbo_email)") unless $submail; +$comments = $opts{C} || ""; +$tags = $opts{k} || ""; + +if(! -e $userfile) { + die_usage("File not found: $userfile"); +} + +print STDERR "Uploading..."; + +$ua = LWP::UserAgent->new; +$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); +$resp = $ua->post( + 'http://slackbuilds.org/process_submit/', + [ MAX_FILE_SIZE => '100000', + userfile => [ $userfile ], + category => $category, + tags => $tags, + submail => $submail, + comments => $comments, + submit => 'Upload File' ], + Content_Type => 'form-data', + Referer => 'http://slackbuilds.org/submit/', + ); + +print STDERR "\n"; + +$tmpfile = "/tmp/sbosubmit.$$." . int(rand(10 ** 10)) . ".html"; +open RESULT, ">$tmpfile" or die "$tmpfile: $!"; +print RESULT $resp->content; +close RESULT; +system("links -dump $tmpfile | sed -n '/Upload Results/,/Home.*Change Log/p'"); +unlink $tmpfile; + +warn "*** HTTP response code is " . $resp->code . "\n" unless $resp->code == 200; -- cgit v1.2.3