-
-
Save DanielFGray/2b469c8e58ab65b1a0e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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