Skip to content

Instantly share code, notes, and snippets.

@noktoborus
Created October 20, 2015 08:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noktoborus/a8e36e29a6ef9f3c2ca8 to your computer and use it in GitHub Desktop.
Save noktoborus/a8e36e29a6ef9f3c2ca8 to your computer and use it in GitHub Desktop.
#!/bin/sh
usage()
{
echo "Usage:"
echo " dump <file|image|text> [file] [language]"
echo " dump [file]"
}
_type="$1"
_file="$2"
LANG="$3"
if [ -z "$_file" -a ! -z "$_type" ];
then
_file="$_type"
_type=$(file -bi "$_file" 2>/dev/null | cut -d'/' -f 1)
case "$_type" in
text) ;;
image) ;;
inode)
usage
echo "can't upload inode file type:"
file -i "$_file"
exit 1
;;
*)
_type="file"
;;
esac
fi
if [ ! -z "$_file" -a ! -r "$_file" ];
then
echo "file '$_file' not readable"
exit 1
fi
case $_type in
file)
URL=`curl -w %{redirect_url} -F "file=@$_file" http://dump.bitcheese.net/upload-file?simple`
echo "$URL [$URL/preview]" ;;
image)
URL=`curl -w %{redirect_url} -F "file=@$_file" http://dump.bitcheese.net/upload-image?simple`
echo "$URL [$URL/preview]" ;;
text)
if [ -z $LANG ] ; then
LANG=Plaintext
fi
URL=`curl -w %{redirect_url} -F "lang=$LANG" -F "text=@$_file" http://dump.bitcheese.net/upload-text`
echo $URL ;;
*) usage;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment