post-test.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. BASE_URL="https://.../shaarligo.cgi"
  3. BASE_URL="https://demo.shaarli.org/"
  4. USERNAME="demo"
  5. PASSWORD="demo"
  6. # link
  7. # title
  8. # description
  9. # tags
  10. # private
  11. # (linkdate)
  12. # Check preliminaries
  13. curl --version >/dev/null || { echo "apt-get install curl" && exit 1; }
  14. xmllint --version 2> /dev/null || { echo "apt-get install libxml2-utils" && exit 1; }
  15. ruby --version > /dev/null || { echo "apt-get install ruby" && exit 1; }
  16. cd "$(dirname "${0}")"
  17. rm curl.* 2> /dev/null
  18. LOCATION=$(curl --location --get --url "${BASE_URL}" \
  19. --cookie curl.cook --cookie-jar curl.cook \
  20. --location --output curl.tmp.html \
  21. --trace-ascii curl.tmp.trace --dump-header curl.tmp.head \
  22. --data-urlencode "post=https://github.com/sebsauvage/Shaarli/commit/450342737ced8ef2864b4f83a4107a7fafcc4add" \
  23. --data-urlencode "title=Mein Titel" \
  24. --data-urlencode "source=ShaarliGo" \
  25. --write-out '%{url_effective}' 2>/dev/null)
  26. echo "next: ${LOCATION}"
  27. fgrep -v '<?xml ' curl.tmp.html | xmllint --html --nowarning --xmlout --encode utf-8 --nodefdtd - \
  28. | /usr/bin/env ruby loginform.rb "${USERNAME}" "${PASSWORD}" \
  29. > "curl.post.login"
  30. [ -s "curl.post.login" ] && {
  31. rm curl.tmp.*
  32. LOCATION=$(curl --location --url "${LOCATION}" \
  33. --data-urlencode "login=${USERNAME}" \
  34. --data-urlencode "password=${PASSWORD}" \
  35. --data "@curl.post.login" \
  36. --cookie curl.cook --cookie-jar curl.cook \
  37. --output curl.tmp.html \
  38. --trace-ascii curl.tmp.trace --dump-header curl.tmp.head \
  39. --write-out '%{url_effective}' 2>/dev/null)
  40. rm "curl.post.login"
  41. echo "next: ${LOCATION}"
  42. }
  43. fgrep -v '<?xml ' curl.tmp.html | xmllint --html --nowarning --xmlout --encode utf-8 --nodefdtd - \
  44. | /usr/bin/env ruby linkform.rb \
  45. > "curl.post.link"
  46. if [ ! -s "curl.post.link" ] ; then
  47. echo "login failed"
  48. cat curl.tmp.head
  49. cat curl.tmp.html
  50. else
  51. rm curl.tmp.*
  52. LOCATION=$(curl --location --url "${LOCATION}" \
  53. --cookie curl.cook --cookie-jar curl.cook \
  54. --output curl.tmp.html \
  55. --trace-ascii curl.tmp.trace --dump-header curl.tmp.head \
  56. --data-urlencode "lf_tags=t1 t2 t3" \
  57. --data "@curl.post.link" \
  58. --write-out '%{url_effective}' 2>/dev/null)
  59. echo "finish: ${LOCATION}"
  60. fi
  61. rm curl.*