summaryrefslogtreecommitdiffstats
path: root/ompload
diff options
context:
space:
mode:
authorFlorian Pritz <f-p@gmx.at>2009-05-31 11:30:31 +0200
committerFlorian Pritz <f-p@gmx.at>2009-05-31 11:30:31 +0200
commit672454da6cdd8c0b776de01a6207a9ca94632f47 (patch)
tree40c20c65e431fe1390efb8fce3524a059b4652d2 /ompload
parent235d99c531d685be2eaf365923bc4cb2092fe1c1 (diff)
downloadaur-packages-672454da6cdd8c0b776de01a6207a9ca94632f47.tar.gz
aur-packages-672454da6cdd8c0b776de01a6207a9ca94632f47.tar.xz
update
Diffstat (limited to 'ompload')
-rw-r--r--ompload/PKGBUILD17
-rw-r--r--ompload/ompload151
2 files changed, 168 insertions, 0 deletions
diff --git a/ompload/PKGBUILD b/ompload/PKGBUILD
new file mode 100644
index 0000000..96969b6
--- /dev/null
+++ b/ompload/PKGBUILD
@@ -0,0 +1,17 @@
+#Maintainer: FallenWizard <fallenwiz@gmail.com>
+
+pkgname=ompload
+pkgver=20090529
+pkgrel=1
+pkgdesc="Script to upload files to omploader.org"
+arch=('i686' 'x86_64')
+license=('GPL')
+depends=('ruby>=1.8' 'curl')
+url="http://omploader.org"
+source=(${pkgname})
+md5sums=('184394e71161d7c41401a6c42d78f5e6')
+
+build() {
+ cd ${startdir}/src
+ install -D -m755 ${pkgname} ${startdir}/pkg/usr/bin/${pkgname}
+}
diff --git a/ompload/ompload b/ompload/ompload
new file mode 100644
index 0000000..d639f3c
--- /dev/null
+++ b/ompload/ompload
@@ -0,0 +1,151 @@
+#!/usr/bin/env ruby
+#
+# Copyright 2007-2009 David Shakaryan <omp@gentoo.org>
+# Copyright 2007-2009 Brenden Matthews <brenden@rty.ca>
+#
+# Distributed under the terms of the GNU General Public License v3
+#
+
+require 'tempfile'
+
+argv = Array.new
+
+quiet = false
+url_only = false
+help = false
+skip = false
+filename = 'pasta'
+
+$stdin.fcntl(4, File::NONBLOCK)
+stdin = $stdin.read if !$stdin.eof
+unless stdin.nil?
+ argv << ''
+end
+
+ARGV.each_index do |i|
+ if skip
+ skip = false
+ next
+ end
+ if ARGV[i] =~ /-q|--quiet/
+ quiet = true
+ elsif ARGV[i] =~ /-u|--url/
+ url_only = true
+ elsif ARGV[i] =~ /-h|--help/
+ help = true
+ elsif ARGV[i] =~ /-f|--filename/
+ filename = ARGV[i + 1]
+ skip = true
+ else
+ argv << ARGV[i]
+ end
+end
+
+nocurl = false
+curl = %x{curl --version 2> /dev/null}
+if curl.empty?
+ nocurl = true
+ $stderr.puts 'Error: curl missing or not in path. Cannot continue.'
+ $stderr.puts
+end
+
+if (ARGV.size < 1 and (stdin.nil? or stdin.empty?)) or help or nocurl
+ $stderr.puts 'Usage: ompload [-h|--help] [options] [file(s)]'
+ $stderr.puts ' -q, --quiet Only output errors and warnings'
+ $stderr.puts ' -u, --url Only output URL when finished'
+ $stderr.puts ' -f, --filename Filename to use when posting data'
+ $stderr.puts ' from stdin'
+ $stderr.puts
+ $stderr.puts ' You can supply a list of files or data via stdin (or both)'
+ $stderr.puts
+ $stderr.puts ' This script requires a copy of cURL in the path.'
+ Process.exit
+end
+
+errors = 0
+
+wait = 5
+
+Url = 'http://omploader.org/'
+Max_size = 2**30
+
+used_stdin = false
+first = true
+
+argv.each do |arg|
+
+ if stdin.nil? and !used_stdin and !File.file?(arg)
+ $stderr.puts "Invalid argument '#{arg}': file does not exist (or is not a regular file)."
+ errors += 1
+ next
+ elsif File.size(arg) > Max_size
+ $stderr.puts "Error omploading '#{arg}': file exceeds " + (Max_size).to_s + " bytes (size was " + File.size(arg).to_s + ")."
+ errors += 1
+ next
+ end
+
+ if !first
+ # try not to hammer the server
+ puts 'Sleeping for ' + wait.to_s + 's' if !quiet and !url_only
+ sleep(wait)
+ else
+ first = false
+ end
+
+ tmp = Tempfile.new(filename)
+ if !stdin.nil? and !used_stdin
+ # upload from stdin
+ puts "Progress for '#{arg}'" if !quiet and !url_only
+ if quiet or url_only
+ p = IO.popen("curl -s -F 'file1=@-;filename=\"#{filename}\"' #{Url}upload -o '#{tmp.path}'", "w+")
+ else
+ p = IO.popen("curl -# -F 'file1=@-;filename=\"#{filename}\"' #{Url}upload -o '#{tmp.path}'", "w+")
+ end
+ p.puts stdin
+ p.close_write
+ Process.wait
+ used_stdin = true
+ else
+ # upload file
+ puts "Progress for '#{arg}'" if !quiet and !url_only
+ # escape quotes
+ tmp_path = arg.gsub('"', '\"')
+ if quiet or url_only
+ %x{curl -s -F file1=@"#{tmp_path}" #{Url}upload -o '#{tmp.path}'}
+ else
+ %x{curl -# -F file1=@"#{tmp_path}" #{Url}upload -o '#{tmp.path}'}
+ end
+ end
+ if !File.size?(tmp.path)
+ $stderr.puts "Error omploading '#{arg}'"
+ errors += 1
+ next
+ end
+ output = IO.read(tmp.path)
+
+ # parse for an ID
+ if output =~ /View file: <a href="v([A-Za-z0-9+\/]+)">/
+ id = $1
+ puts "Omploaded '#{arg}' to #{Url}v#{id}" if !quiet
+ wait = 5
+ elsif output =~ /Slow down there, cowboy\./
+ wait += 60
+ argv << arg
+ $stderr.puts "Got throttled when trying to ompload '#{arg}'"
+ $stderr.puts "Increasing wait and attempting to continue..."
+ errors += 1
+ else
+ $stderr.puts "Error omploading '#{arg}'"
+ errors += 1
+ end
+
+end
+
+if !quiet and !url_only
+ if errors < 1
+ puts "Success."
+ else
+ puts "Finished with #{errors} errors."
+ end
+end
+