summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-10-23 19:21:34 +0200
committerFlorian Pritz <bluewind@xssn.at>2010-10-23 19:21:34 +0200
commit9359b2ecfd4b9e8e5782a910b567d6149e2d02f8 (patch)
tree2752ac40e5b6bda032b70d31f40397b3a7489469
parent821dcb21299a0c9e8994dcab6a98b690c81cd3c0 (diff)
downloadbin-9359b2ecfd4b9e8e5782a910b567d6149e2d02f8.tar.gz
bin-9359b2ecfd4b9e8e5782a910b567d6149e2d02f8.tar.xz
fb: add compress and tar support
Files will be compress with gz or xz before uploading if -c or -cc are specified. Directories will be tared automatically and if -c or -cc is specified the tar file will also be compressed with gz or xz. If the -t switch is used all arguments will be combined into one single tar file which will be compressed with gz or xz if -c or -cc is specified. Signed-off-by: Florian Pritz <bluewind@xssn.at>
-rwxr-xr-xfb100
1 files changed, 72 insertions, 28 deletions
diff --git a/fb b/fb
index 6b0eabd..741831c 100755
--- a/fb
+++ b/fb
@@ -11,11 +11,15 @@
# Optional: xclip
#----------------------------------------------------
-VERSION="0.6.7.1"
+VERSION="0.6.8"
DELETE=
EXTENSION=""
GET=
+TAR=
+COMPRESS=0
+TAREXT=".tar"
+TAROPTS=""
PASTEBIN="http://paste.xinu.at"
WARNSIZE=10485760
USERAGENT="fb-client/$VERSION"
@@ -24,19 +28,37 @@ 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 "$1"` -gt "$WARNSIZE" ]; then
+ if [ `stat -c %s "$file"` -gt "$WARNSIZE" ]; then
WARNSIZE=`curl -s "$PASTEBIN/file/get_max_size"`
- if [ `stat -c %s "$1"` -gt "$WARNSIZE" ]; then
+ 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
- if ! curl -# -n -L -A $USERAGENT $EXTRA -F "file=@$1" "$PASTEBIN/file/do_upload" > $TMPFILE; then
+ if ! curl -# -n -L -A $USERAGENT $EXTRA -F "file=@$file" "$PASTEBIN/file/do_upload" > $TMPFILE; then
EXITCODE=1
return 1
fi
@@ -56,23 +78,38 @@ read_stdin() {
help() {
cat <<!
fb-client version $VERSION
-usage: [cat |] `basename "$0"` [switches] [file(s)|ID(s)]
+usage: [cat |] `basename "$0"` [switches] [options] [file(s)|ID(s)]
Upload/nopaste file(s)/stdin to paste.xinu.at and copy URL(s) to clipboard.
~/.netrc: machine paste.xinu.at password PASSWORD
Switches:
- -e EXTENSION extension for default highlighting (e.g. "diff")
-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
+
+ 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:gdh" OPTION; do
+while getopts "e:gdhtc" 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;;
h|\?) help; exit 0;;
esac
@@ -88,28 +125,35 @@ if [ $# -eq 0 ]; then
read_stdin "$TMPDIR/stdin"
do_upload "$TMPDIR/stdin"
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
+ 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
- for f in *; do
- do_upload "$f" && rm -f "$f"
- done
- else
- do_upload "$i"
- fi
- done
+ done
+ fi
fi
[ "`which xclip 2>/dev/null`" ] && echo -n $CLIPBOARD | nohup xclip >/dev/null 2>&1