summaryrefslogtreecommitdiffstats
path: root/fb.in
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-10-09 21:35:40 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-10-09 21:40:21 +0200
commit942fdab5b8d541fc405706c94d47d25c19caed29 (patch)
tree900f2d122f6bb322ca7fdf36f245466e83148c49 /fb.in
parent09a5d52abf492c170c071aa3962135d661aba15e (diff)
Lowercase most variable names
I don't like the look of everything being upper case and it certainly complicates writing the variable names. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'fb.in')
-rw-r--r--fb.in198
1 files changed, 99 insertions, 99 deletions
diff --git a/fb.in b/fb.in
index d6f76cb..6afab40 100644
--- a/fb.in
+++ b/fb.in
@@ -10,33 +10,33 @@
# Optional dependency: xclip
#----------------------------------------------------
-PASTEBIN="http://paste.xinu.at"
-WARNSIZE=10485760
-LIBDIR="@LIBDIR@"
+pastebin="http://paste.xinu.at"
+warnsize=10485760
+libdir="@LIBDIR@"
# the calling conventions for stat(1) are highly system dependent
-STAT='stat -c %s' # GNU stat(1) is the default since most people have it
+stat='stat -c %s' # GNU stat(1) is the default since most people have it
-CLIPBOARD_CMD=xclip
+clipboard_cmd=xclip
case "`uname -s`" in
- *BSD) STAT='stat -f %z';;
- Minix) STAT='stat -size';;
+ *BSD) stat='stat -f %z';;
+ Minix) stat='stat -size';;
Darwin)
- STAT='stat -f %z'
- CLIPBOARD_CMD=pbcopy
+ stat='stat -f %z'
+ clipboard_cmd=pbcopy
;;
esac
-VERSION="@VERSION@"
-DELETE=
-EXTENSION=""
-GET=
-TAR=
-COMPRESS=0
-DISPLAYHISTORY=
-CLIPBOARD=""
-EXITCODE=0
+version="@VERSION@"
+delete=
+extension=""
+get=
+tar=
+compress=0
+display_history=
+clipboard=""
+exitcode=0
base64_encode() {
if type base64 2>&1 >/dev/null; then
@@ -56,30 +56,30 @@ request_helper() {
file=$3
# if available use the external helper, else fall back to calling curl
- if [ -x "$LIBDIR/fb-helper" ]; then
- $LIBDIR/fb-helper "$mode" "$url" "$file"
+ if [ -x "$libdir/fb-helper" ]; then
+ $libdir/fb-helper "$mode" "$url" "$file"
else
- USERAGENT="fb-client/shell-$VERSION"
- CURLOPTS="-# -n -L -A $USERAGENT"
+ useragent="fb-client/shell-$version"
+ curlopts="-# -n -L -A $useragent"
if [ "$mode" = "d" ]; then
- CURLOPTS="$CURLOPTS -s"
+ curlopts="$curlopts -s"
fi
if [ "$mode" = "u" ]; then
basefilename=`basename -- "$file"`
- if [ "`$STAT -- "$file"`" -eq "0" ] || printf "%s" "$basefilename" | grep -F -q ","; then
+ if [ "`$stat -- "$file"`" -eq "0" ] || printf "%s" "$basefilename" | grep -F -q ","; then
if [ "`wc -c < "$file"`" -eq "0" ]; then
printf "%s\n" "Error: skipping 0-byte file: \"$file\"" >&2
return 1
fi
base64fn="`base64_encode "$basefilename"`"
- curl $CURLOPTS -F "file=@-" -F "filename=$base64fn" "$url" < "$file" -o /dev/stdout
+ curl $curlopts -F "file=@-" -F "filename=$base64fn" "$url" < "$file" -o /dev/stdout
else
- curl $CURLOPTS -F "file=@$file" "$url" -o /dev/stdout
+ curl $curlopts -F "file=@$file" "$url" -o /dev/stdout
fi
else
- curl $CURLOPTS "$url"
+ curl $curlopts "$url"
fi
fi
}
@@ -99,22 +99,22 @@ is_url() {
}
do_tar_upload() {
- if [ "$COMPRESS" = "1" ]; then
- file="$TMPDIR/upload.tar.gz"
+ if [ "$compress" = "1" ]; then
+ file="$tmpdir/upload.tar.gz"
tar -cf - -- "$@" | gzip -c > "$file" || return 1
- elif [ "$COMPRESS" = "2" ]; then
- file="$TMPDIR/upload.tar.xz"
+ elif [ "$compress" = "2" ]; then
+ file="$tmpdir/upload.tar.xz"
tar -cf - -- "$@" | xz -c > "$file" || return 1
else
- file="$TMPDIR/upload.tar"
+ file="$tmpdir/upload.tar"
tar -cf "$file" -- "$@" || return 1
fi
- COMPRESS=0
+ compress=0
do_upload "$file" || return 1
}
do_upload() {
- local EXTRA=""
+ local extra=""
file="$1"
basefilename="`basename -- "$file"`"
basedirname="`dirname -- "$file"`"
@@ -127,45 +127,45 @@ do_upload() {
if [ -d "$file" ]; then
cd "$basedirname"
- if [ "$COMPRESS" = "1" ]; then
- file="$TMPDIR/$basefilename.tar.gz"
+ if [ "$compress" = "1" ]; then
+ file="$tmpdir/$basefilename.tar.gz"
tar -cf - -- "$basefilename" | gzip -c > "$file" || return 1
- elif [ "$COMPRESS" = "2" ]; then
- file="$TMPDIR/$basefilename.tar.xz"
+ elif [ "$compress" = "2" ]; then
+ file="$tmpdir/$basefilename.tar.xz"
tar -cf - -- "$basefilename" | xz -c > "$file" || return 1
else
- file="$TMPDIR/$basefilename.tar"
+ file="$tmpdir/$basefilename.tar"
tar -cf "$file" -- "$basefilename" || return 1
fi
else
- if [ "$COMPRESS" = "1" ]; then
- gzip -c -- "$file" > "$TMPDIR/$basefilename.gz" || return 1
- file="$TMPDIR/$basefilename.gz"
- elif [ "$COMPRESS" = "2" ]; then
- xz -c -- "$file" > "$TMPDIR/$basefilename.xz" || return 1
- file="$TMPDIR/$basefilename.xz"
+ if [ "$compress" = "1" ]; then
+ gzip -c -- "$file" > "$tmpdir/$basefilename.gz" || return 1
+ file="$tmpdir/$basefilename.gz"
+ elif [ "$compress" = "2" ]; then
+ xz -c -- "$file" > "$tmpdir/$basefilename.xz" || return 1
+ file="$tmpdir/$basefilename.xz"
fi
fi
- TMPFILE=`mktemp "$TMPDIR/data.XXXXXX"`
- if [ "`$STAT -- "$file"`" -gt "$WARNSIZE" ]; then
- WARNSIZE=`request_helper d "$PASTEBIN/file/get_max_size"`
- if [ "`$STAT -- "$file"`" -gt "$WARNSIZE" ]; then
- printf "%s\n" "Warning: Your upload is too big and would be rejected. Maximum size is: $WARNSIZE bytes. Skipping..." >&2
+ tmpfile=`mktemp "$tmpdir/data.XXXXXX"`
+ if [ "`$stat -- "$file"`" -gt "$warnsize" ]; then
+ warnsize=`request_helper d "$pastebin/file/get_max_size"`
+ if [ "`$stat -- "$file"`" -gt "$warnsize" ]; then
+ printf "%s\n" "Warning: Your upload is too big and would be rejected. Maximum size is: $warnsize bytes. Skipping..." >&2
return 1
fi
fi
- request_helper u "$PASTEBIN/file/do_upload" "$file" > $TMPFILE || return 1
+ request_helper u "$pastebin/file/do_upload" "$file" > $tmpfile || return 1
- sed '$d' $TMPFILE >&2
- URL=`tail -1 $TMPFILE`"$EXTENSION"
- printf "%s\n" "$URL"
- if printf "%s" "$URL" | grep -qE "^https?://"; then
- if [ -z "$CLIPBOARD" ]; then
- CLIPBOARD="$URL"
+ sed '$d' $tmpfile >&2
+ url=`tail -1 $tmpfile`"$extension"
+ printf "%s\n" "$url"
+ if printf "%s" "$url" | grep -qE "^https?://"; then
+ if [ -z "$clipboard" ]; then
+ clipboard="$url"
else
- CLIPBOARD="$CLIPBOARD $URL"
+ clipboard="$clipboard $url"
fi
fi
}
@@ -187,7 +187,7 @@ id_from_arg() {
help() {
cat <<!
-fb-client version $VERSION
+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.
@@ -213,100 +213,100 @@ if ! type getopts >/dev/null 2>&1; then
exit 1
fi
-while getopts "e:gdhHtcv" OPTION; do
- case $OPTION in
- e) EXTENSION="$OPTARG";;
- g) GET=1;;
- c) COMPRESS=`expr $COMPRESS + 1`;;
- t) TAR=1;;
- d) DELETE=1;;
- H) DISPLAYHISTORY=1;;
- v) printf "%s\n" "$VERSION"; exit 0;;
+while getopts "e:gdhHtcv" option; do
+ case $option in
+ e) extension="$OPTARG";;
+ g) get=1;;
+ c) compress=`expr $compress + 1`;;
+ t) tar=1;;
+ d) delete=1;;
+ H) display_history=1;;
+ v) printf "%s\n" "$version"; exit 0;;
h|\?) help; exit 0;;
esac
done
shift `expr $OPTIND - 1`
-if [ "$COMPRESS" = "1" ]; then
+if [ "$compress" = "1" ]; then
require_executable gzip
-elif [ "$COMPRESS" = "2" ]; then
+elif [ "$compress" = "2" ]; then
require_executable xz
fi
-TMPDIR="`mktemp -dt "fb.XXXXXX"`"
-trap "rm -rf '${TMPDIR}'" EXIT TERM
+tmpdir="`mktemp -dt "fb.XXXXXX"`"
+trap "rm -rf '${tmpdir}'" EXIT TERM
-if [ "$DELETE" ] || [ "$GET" ]; then
+if [ "$delete" ] || [ "$get" ]; then
if [ $# -eq 0 ]; then
printf "%s\n" "Error: no ID specified" >&2
exit 1
fi
for i in "$@"; do
i=$(id_from_arg "$i")
- if [ "$DELETE" ]; then
- request_helper d "$PASTEBIN/file/delete/$i" || EXITCODE=1
-
- elif [ "$GET" ]; then
- if [ "$COMPRESS" = "1" ]; then
- request_helper d "$PASTEBIN/$i" | gzip -cd || EXITCODE=1
- elif [ "$COMPRESS" = "2" ]; then
- request_helper d "$PASTEBIN/$i" | xz -cd || EXITCODE=1
+ if [ "$delete" ]; then
+ request_helper d "$pastebin/file/delete/$i" || exitcode=1
+
+ elif [ "$get" ]; then
+ if [ "$compress" = "1" ]; then
+ request_helper d "$pastebin/$i" | gzip -cd || exitcode=1
+ elif [ "$compress" = "2" ]; then
+ request_helper d "$pastebin/$i" | xz -cd || exitcode=1
else
- request_helper d "$PASTEBIN/$i" || EXITCODE=1
+ request_helper d "$pastebin/$i" || exitcode=1
fi
fi
done
-elif [ "$DISPLAYHISTORY" ]; then
- request_helper d "$PASTEBIN/file/upload_history" || EXITCODE=1
+elif [ "$display_history" ]; then
+ request_helper d "$pastebin/file/upload_history" || exitcode=1
elif [ $# -eq 0 ]; then
- if [ "$TAR" ]; then
+ if [ "$tar" ]; then
printf "%s\n" "Error: -t is not supported when operating on stdin" >&2
exit 1
fi
- read_stdin "$TMPDIR/stdin"
- do_upload "$TMPDIR/stdin" || EXITCODE=1
+ read_stdin "$tmpdir/stdin"
+ do_upload "$tmpdir/stdin" || exitcode=1
else
- if [ "$TAR" ]; then
- HAVE_URL=
+ if [ "$tar" ]; then
+ have_url=
for i in "$@"; do
if is_url "$i"; then
- HAVE_URL=1
+ have_url=1
fi
done
- if [ "$HAVE_URL" ]; then
+ if [ "$have_url" ]; then
# TODO: support -t when passing URLs as arguments
printf "%s\n" "Error: -t is not yet supported when operating on a URL" >&2
exit 1
else
- do_tar_upload "$@" || EXITCODE=1
+ do_tar_upload "$@" || exitcode=1
fi
else
for i in "$@"; do
if is_url "$i"; then
- cd $TMPDIR
+ cd $tmpdir
if ! request_helper d "$i" > "`basename "$i"`"; then
- EXITCODE=1
+ exitcode=1
continue
fi
for f in *; do
if ! do_upload "$f"; then
- EXITCODE=1
+ exitcode=1
fi
rm -f -- "$f"
done
else
- do_upload "$i" || EXITCODE=1
+ do_upload "$i" || exitcode=1
fi
done
fi
fi
-if [ "$CLIPBOARD" != "" ]; then
- type $CLIPBOARD_CMD >/dev/null 2>&1 && printf "%s" "$CLIPBOARD" | nohup $CLIPBOARD_CMD >/dev/null 2>&1
+if [ "$clipboard" != "" ]; then
+ type $clipboard_cmd >/dev/null 2>&1 && printf "%s" "$clipboard" | nohup $clipboard_cmd >/dev/null 2>&1
fi
-exit $EXITCODE
+exit $exitcode
#vim: set noet: