summaryrefslogtreecommitdiffstats
path: root/fb.in
diff options
context:
space:
mode:
Diffstat (limited to 'fb.in')
-rw-r--r--fb.in226
1 files changed, 114 insertions, 112 deletions
diff --git a/fb.in b/fb.in
index afd3211..c781c74 100644
--- a/fb.in
+++ b/fb.in
@@ -27,102 +27,102 @@ CLIPBOARD=""
EXITCODE=0
do_upload() {
- local EXTRA=""
- file="$1"
- basefilename="`basename -- "$file"`"
- basedirname="`dirname -- "$file"`"
- if [ -d "$file" ]; then
- cd "$basedirname"
- tar $TAROPTS -cf "$TMPDIR/$basefilename$TAREXT" -- "$basefilename"
- COMPRESS=0
- file="$TMPDIR/$basefilename$TAREXT"
- fi
-
- if [ "$COMPRESS" == "1" ]; then
- gzip -c -- "$file" > "$TMPDIR/$basefilename.gz"
- file="$TMPDIR/$basefilename.gz"
- elif [ "$COMPRESS" == "2" ]; then
- xz -c -- "$file" > "$TMPDIR/$basefilename.xz"
- file="$TMPDIR/$basefilename.xz"
- fi
-
- if [ "$EXTENSION" ]; then
- EXTRA="-F extension=$EXTENSION"
- fi
- TMPFILE=`mktemp "$TMPDIR/data.XXXXXX"`
- if [ `stat -c %s -- "$file"` -gt "$WARNSIZE" ]; then
- WARNSIZE=`curl -s "$PASTEBIN/file/get_max_size"`
- if [ `stat -c %s -- "$file"` -gt "$WARNSIZE" ]; then
- echo "Warning: Your upload is too big and would be rejected. Maximum size is: $WARNSIZE bytes. Skipping..." >&2
- EXITCODE=1
- return 1
- fi
- fi
- CURLOPTS="-# -n -L -A $USERAGENT $EXTRA"
- if [ `stat -c %s -- "$file"` -eq "0" ]; then
- if ! curl $CURLOPTS -F "file=@-;filename=$basefilename" "$PASTEBIN/file/do_upload" < "$file" > $TMPFILE; then
- EXITCODE=1
- return 1
- fi
- else
- if ! curl $CURLOPTS -F "file=@$file" "$PASTEBIN/file/do_upload" > $TMPFILE; then
- EXITCODE=1
- return 1
- fi
- fi
- sed '$d' $TMPFILE >&2
- URL=`tail -1 $TMPFILE`
- echo $URL
- CLIPBOARD="$CLIPBOARD $URL"
+ local EXTRA=""
+ file="$1"
+ basefilename="`basename -- "$file"`"
+ basedirname="`dirname -- "$file"`"
+ if [ -d "$file" ]; then
+ cd "$basedirname"
+ tar $TAROPTS -cf "$TMPDIR/$basefilename$TAREXT" -- "$basefilename"
+ COMPRESS=0
+ file="$TMPDIR/$basefilename$TAREXT"
+ fi
+
+ if [ "$COMPRESS" == "1" ]; then
+ gzip -c -- "$file" > "$TMPDIR/$basefilename.gz"
+ file="$TMPDIR/$basefilename.gz"
+ elif [ "$COMPRESS" == "2" ]; then
+ xz -c -- "$file" > "$TMPDIR/$basefilename.xz"
+ file="$TMPDIR/$basefilename.xz"
+ fi
+
+ if [ "$EXTENSION" ]; then
+ EXTRA="-F extension=$EXTENSION"
+ fi
+ TMPFILE=`mktemp "$TMPDIR/data.XXXXXX"`
+ if [ `stat -c %s -- "$file"` -gt "$WARNSIZE" ]; then
+ WARNSIZE=`curl -s "$PASTEBIN/file/get_max_size"`
+ if [ `stat -c %s -- "$file"` -gt "$WARNSIZE" ]; then
+ echo "Warning: Your upload is too big and would be rejected. Maximum size is: $WARNSIZE bytes. Skipping..." >&2
+ EXITCODE=1
+ return 1
+ fi
+ fi
+ CURLOPTS="-# -n -L -A $USERAGENT $EXTRA"
+ if [ `stat -c %s -- "$file"` -eq "0" ]; then
+ if ! curl $CURLOPTS -F "file=@-;filename=$basefilename" "$PASTEBIN/file/do_upload" < "$file" > $TMPFILE; then
+ EXITCODE=1
+ return 1
+ fi
+ else
+ if ! curl $CURLOPTS -F "file=@$file" "$PASTEBIN/file/do_upload" > $TMPFILE; then
+ EXITCODE=1
+ return 1
+ fi
+ fi
+ sed '$d' $TMPFILE >&2
+ URL=`tail -1 $TMPFILE`
+ echo $URL
+ CLIPBOARD="$CLIPBOARD $URL"
}
read_stdin() {
- if tty -s; then
- echo "^C to exit, ^D to send"
- fi
- cat > "$1"
+ if tty -s; then
+ echo "^C to exit, ^D to send"
+ fi
+ cat > "$1"
}
help() {
- cat <<!
+ cat <<!
fb-client version $VERSION
usage: [cat |] `basename "$0"` [switches] [options] [<file(s)|ID(s)|folder(s)>]
- Upload/nopaste file(s)/stdin to paste.xinu.at and copy URL(s) to clipboard.
- ~/.netrc: machine paste.xinu.at password PASSWORD
+ Upload/nopaste file(s)/stdin to paste.xinu.at and copy URL(s) to clipboard.
+ ~/.netrc: machine paste.xinu.at password PASSWORD
- Switches:
- -d delete the IDs
- -g download the IDs and output on stdout (use with care!)
- -t upload a tar file containing all files (and directories)
- -h this help
- -v show the client version
+ Switches:
+ -d delete the IDs
+ -g download the IDs and output on stdout (use with care!)
+ -t upload a tar file containing all files (and directories)
+ -h this help
+ -v show the client version
- Options:
- These have no effect if used in conjunction with a switch
- -e <extension> extension for default highlighting (e.g. "diff")
- -c compress the file being uploaded with gz or xz if used 2 times
+ Options:
+ These have no effect if used in conjunction with a switch
+ -e <extension> extension for default highlighting (e.g. "diff")
+ -c compress the file being uploaded with gz or xz if used 2 times
!
}
while getopts "e:gdhtcv" OPTION; do
- case $OPTION in
- e) EXTENSION="$OPTARG";;
- g) GET=1;;
- c) COMPRESS=`expr $COMPRESS + 1`
- if [ "$COMPRESS" == "1" ]; then
- TAROPTS="-z"
- TAREXT=".tar.gz"
- elif [ "$COMPRESS" == "2" ]; then
- TAROPTS="-J"
- TAREXT=".tar.xz"
- fi
- ;;
- t) TAR=1;;
- d) DELETE=1;;
- v) echo "$VERSION"; exit 0;;
- h|\?) help; exit 0;;
- esac
+ case $OPTION in
+ e) EXTENSION="$OPTARG";;
+ g) GET=1;;
+ c) COMPRESS=`expr $COMPRESS + 1`
+ if [ "$COMPRESS" == "1" ]; then
+ TAROPTS="-z"
+ TAREXT=".tar.gz"
+ elif [ "$COMPRESS" == "2" ]; then
+ TAROPTS="-J"
+ TAREXT=".tar.xz"
+ fi
+ ;;
+ t) TAR=1;;
+ d) DELETE=1;;
+ v) echo "$VERSION"; exit 0;;
+ h|\?) help; exit 0;;
+ esac
done
shift `expr $OPTIND - 1`
@@ -132,40 +132,42 @@ TMPDIR="`mktemp -d "/tmp/fb.XXXXXX"`"
trap "rm -rf '${TMPDIR}'" EXIT TERM
if [ $# -eq 0 ]; then
- read_stdin "$TMPDIR/stdin"
- do_upload "$TMPDIR/stdin"
+ read_stdin "$TMPDIR/stdin"
+ do_upload "$TMPDIR/stdin"
else
- if [ "$TAR" ]; then
- tar $TAROPTS -cf "$TMPDIR/upload$TAREXT" -- "$@"
- COMPRESS=0
- do_upload "$TMPDIR/upload$TAREXT"
- break
- else
- for i in "$@"; do
- if [ "$DELETE" ]; then
- if ! curl -n -L -A $USERAGENT "$PASTEBIN/file/delete/$i"; then
- EXITCODE=1
- fi
- elif [ "$GET" ]; then
- if ! curl -s -o - -A $USERAGENT "$PASTEBIN/$i"; then
- EXITCODE=1
- fi
- elif echo "$i" | grep -qE "^(f|ht)tp(s)?://.+"; then
- cd $TMPDIR
- if ! curl -# -A $USERAGENT -O "$i"; then
- EXITCODE=1
- continue
- fi
- for f in *; do
- do_upload "$f" && rm -f -- "$f"
- done
- else
- do_upload "$i"
- fi
- done
- fi
+ if [ "$TAR" ]; then
+ tar $TAROPTS -cf "$TMPDIR/upload$TAREXT" -- "$@"
+ COMPRESS=0
+ do_upload "$TMPDIR/upload$TAREXT"
+ break
+ else
+ for i in "$@"; do
+ if [ "$DELETE" ]; then
+ if ! curl -n -L -A $USERAGENT "$PASTEBIN/file/delete/$i"; then
+ EXITCODE=1
+ fi
+ elif [ "$GET" ]; then
+ if ! curl -s -o - -A $USERAGENT "$PASTEBIN/$i"; then
+ EXITCODE=1
+ fi
+ elif echo "$i" | grep -qE "^(f|ht)tp(s)?://.+"; then
+ cd $TMPDIR
+ if ! curl -# -A $USERAGENT -O "$i"; then
+ EXITCODE=1
+ continue
+ fi
+ for f in *; do
+ do_upload "$f" && rm -f -- "$f"
+ done
+ else
+ do_upload "$i"
+ fi
+ done
+ fi
fi
[ "`which xclip 2>/dev/null`" ] && echo -n $CLIPBOARD | nohup xclip >/dev/null 2>&1
exit $EXITCODE
+
+#vim: set noet: