selfpaste.default.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  4. # You should have received a copy of the
  5. # COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  6. # along with this program. If not, see http://www.sun.com/cddl/cddl.html
  7. #
  8. # 2019 - 2020 https://://www.bananas-playground.net/projekt/selfpaste
  9. command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl (https://curl.haxx.se/) but it's not installed. Aborting."; exit 1; }
  10. command -v jq >/dev/null 2>&1 || { echo >&2 "I require jq (https://stedolan.github.io/jq/) but it's not installed. Aborting."; exit 1; }
  11. if [ $# -lt 1 ]; then
  12. echo "You need to provide a file to paste";
  13. echo "selfpaste.sh /path/to/file";
  14. exit 2;
  15. fi;
  16. ENDPOINT="http://your.tld/selfpaste/webroot/";
  17. SELFPASTE_UPLOAD_SECRET="PLEASE CHANGE YOUR SECRET TO SOMTHING";
  18. FILENAME="$1";
  19. if [[ -r $FILENAME ]]; then
  20. # add --verbose if you need some more information
  21. RESPONSE=$(curl -sS --header "Content-Type:multipart/form-data" --form "pasty=@$FILENAME" --form "dl=$SELFPASTE_UPLOAD_SECRET" $ENDPOINT);
  22. # uncomment the following line for more debug info
  23. #echo "$RESPONSE";
  24. RESPONSE_STATUS=$(echo "$RESPONSE" | jq -r .status);
  25. RESPONSE_MESSAGE=$(echo "$RESPONSE" | jq -r .message);
  26. if [[ $RESPONSE_STATUS == 200 ]]; then
  27. echo "$RESPONSE_MESSAGE";
  28. else
  29. echo "ERROR. Either your request is invalid (size, type or secret) or something on the endpoint went wrong.";
  30. echo "Response message: $RESPONSE_MESSAGE";
  31. exit 4;
  32. fi;
  33. else
  34. echo "Provided file is not accessable."
  35. exit 3;
  36. fi;