updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / gomploader / gompload
blobcfe202c8efb9c64b847fac8f0a14e7c6bcc425ca
1 #!/bin/bash
3 ############## Gompload 0.1.1
4 # Author: Scott Garrett <Wintervenom@gmail.com>
5 # Description: A graphical ompload wrapper to upload files to Omploader.
6 # Requires: ompload html2text [(firefox | opera | konqueror | midori | seamonkey)]
7 # Syntax: gompload [FILE1 FILE2 DIR1 DIR2 ...]
8 ##############
11 status="/tmp/gompload_status.html"
12 outfile="/tmp/gompload_tmp.html"
14 function update_status {
15 echo "<html><head><title>Gompload: Uploading Files</title><meta http-equiv='refresh' content='1'></head><body><h1>Gompload: Uploading Files</h1><h3>Uploading file $filenum of $numfiles.</h3><hr /><strong>Current file: </strong> $@<hr /><small><em>Gompload 0.1.1 by Scott Garrett</em></small></body></html>" > $status
16 clear
17 html2text -style pretty $status
20 function upload {
21 sleep 2
22 url="$(ompload "$@" 2>&1 | awk '/Omploaded/ {print $NF}')"
23 if [ $url ]; then
24 suffix=$(echo "$@" | awk -F . '{print $NF}')
25 echo "<li><a target='_blank' href=\"${url}.${suffix}\">$@<div style='font-style: italic'>==&gt; ${url}.${suffix}</div></a></li>" >> $outfile
26 else
27 echo "<li style='color:red'><strong>[UPLOAD FAILED]</strong> <em>$@</em></li>" >> $outfile
31 if [[ $# != 0 ]]; then
32 filenum=0
33 numfiles=$#
34 update_status "<em>Preparing to upload...</em>"
35 if [[ $DISPLAY && ! $gomp_dontopen ]]; then
36 if which firefox &> /dev/null; then
37 $(firefox $status) &> /dev/null
38 elif which opera &> /dev/null; then
39 $(opera $status) &> /dev/null
40 elif which konqueror &> /dev/null; then
41 $(konqueror $status) &> /dev/null
42 elif which midori &> /dev/null; then
43 $(midori $status) &> /dev/null
44 elif which seamonkey &> /dev/null; then
45 $(seamonkey $status) &> /dev/null
48 echo "<html><head><title>Gompload: Upload Complete</title></head><body><h1>Gompload: Upload Complete</h1><h3>Here are the results for your uploaded files.</h3><hr /><ol>" > $outfile
49 until [ -z "$1" ]; do
50 if [ -d "$1" ]; then
51 update_status "<strong>[COUNTING]</strong> <em>$1</em>"
52 files=$(find "$1" -type f)
53 let "numfiles+= $(echo "$files" | wc -l)"
54 let "numfiles-=1"
55 update_status "<strong>[READING]</strong> <em>$1</em>"
56 unset files_a y
57 while read -d $'\0' file; do
58 files_a[y++]="$file"
59 done < <( find "$1" -type f -print0)
60 for (( x=0; x<${#files_a[*]}; x++ )); do
61 let "filenum+=1"
62 update_status "${files_a[x]}<br /><strong>Directory:</strong> $1"
63 upload "${files_a[x]}"
64 done
65 else
66 if [ -f "$1" ]; then
67 let "filenum+=1"
68 update_status "$1"
69 upload "$1"
70 else
71 echo "<li style='color:red'><strong>[NOT FOUND]</strong> <em>$1</em></li>" >> $outfile
74 shift
75 done
76 echo "</ol><hr /><small><em>Gompload 0.1.1 by Scott Garrett</em></small></body></html>" >> $outfile
77 mv -f $outfile $status
78 clear
79 html2text -style pretty $status
80 else
81 if [ $DISPLAY ]; then
82 if which zenity &> /dev/null; then
83 if file=$(zenity --file-selection); then
84 "$0" "$file"
86 exit
88 xmessage -center "Gompload 0.1.1 by Scott Garrett
90 Drag and drop the file(s) and/or folder(s) you wish to upload onto
91 the Gompload icon. Gompload can also be ran from a console:
93 gompload kungfoo.png mycrap/ lolcats.jpg this.txt that/ (and so on)
95 Note that directories will be recursively uploaded.
96 If you don't want Gompload to launch your web browser, use:
98 gomp_dontopen=1 gompload"
99 else
100 echo "Gompload 0.1.1 by Scott Garrett"
101 echo
102 echo "Syntax: gompload kungfoo.png mycrap/ lolcats.jpg this.txt that/ (and so on)"
103 echo "Note that directories will be recursively uploaded."