Skip to content

Instantly share code, notes, and snippets.

@DanielFGray
Forked from KittyKatt/pomf
Last active August 29, 2015 14:17
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 DanielFGray/2b469c8e58ab65b1a0e0 to your computer and use it in GitHub Desktop.
Save DanielFGray/2b469c8e58ab65b1a0e0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# pomf.se uploader
# https://gist.github.com/KittyKatt/5818701
# requires: curl
if ! type 'curl' &> /dev/null; then
err 'requires curl to upload'
exit 1
fi
err() {
echo -e "\033[1;31m$1" >&2
}
dest_url='http://pomf.se/upload.php'
return_url='http://a.pomf.se'
if [[ -z "${1}" ]]; then
err 'Error! You must supply a filename to upload!'
exit 1
fi
file="${1}"
ext="${file##*.}"
if [[ ! -f "${file}" ]]; then
err 'Error! File does not exist!'
exit 1
fi
echo -n "Uploading ${file}..."
curloutput=$(curl --silent -sf -F files[]="@${file}" "${dest_url}")
return_file=''
for (( n=0; n < 3; n+=1 )); do
echo -n "try #${n}..."
if [[ "${curloutput}" =~ '"success":true,' ]]; then
#TODO: this sucks
return_file=$(echo "$curloutput" | grep -Eo "\"url\":\"[A-Za-z0-9]+\.${ext}\"," | sed 's/"url":"//;s/",//')
echo 'done'
break
else
err 'failed'
fi
done
if [[ -z ${return_file} ]]; then
err 'Error! File not uploaded'
exit 1
else
echo "File can be found at: ${return_url}/${return_file}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment