Advertisement
Guest User

Untitled

a guest
May 29th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # pomf.se uploader
  3. # requires: curl
  4. # use, bash pomfscript.bash /Path/To/Image
  5. # Image must be in PNG format to upload
  6.  
  7. dest_url='http://pomf.se/upload.php'
  8. return_url='http://a.pomf.se'
  9.  
  10. if [[ -n "${1}" ]]; then
  11. file="${1}"
  12. if [ -f "${file}" ]; then
  13. printf "Uploading ${file}..."
  14. my_output=$(curl --silent -sf -F files[]="@${file}" "${dest_url}")
  15. n=0 # Multipe tries
  16. while [[ $n -le 3 ]]; do
  17. printf "try #${n}..."
  18. if [[ "${my_output}" =~ '"success":true,' ]]; then
  19. return_file=$(echo "$my_output" | grep -Eo '"url":"[A-Za-z0-9]+.png",' | sed 's/"url":"//;s/",//')
  20. printf 'done.\n'
  21. break
  22. else
  23. printf 'failed.\n'
  24. ((n = n +1))
  25. fi
  26. done
  27. if [[ -n ${return_file} ]]; then
  28. printf "File can be found at: ${return_url}/${return_file}.\n"
  29. else
  30. printf 'Error! File not uploaded.\n'
  31. fi
  32. else
  33. printf 'Error! File does not exist!\n'
  34. exit 1
  35. fi
  36. else
  37. printf 'Error! You must supply a filename to upload!\n'
  38. exit 1
  39. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement