selfpaste.default.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 GNU General Public License as published by
  4. # the Free Software Foundation, either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  14. #
  15. # 2019 - 2023 https://://www.bananas-playground.net/projekt/selfpaste
  16. command -v curl >/dev/null 2>&1 || { echo >&2 "I require curl (https://curl.haxx.se/) but it's not installed. Aborting."; exit 1; }
  17. 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; }
  18. if [ $# -lt 1 ]; then
  19. echo "You need to provide a file to paste";
  20. echo "selfpaste.sh /path/to/file";
  21. exit 2;
  22. fi;
  23. ENDPOINT="http://your.tld/selfpaste/webroot/";
  24. SELFPASTE_UPLOAD_SECRET="PLEASE CHANGE YOUR SECRET";
  25. FILENAME="$1";
  26. if [[ -r $FILENAME ]]; then
  27. # add --verbose if you need some more information
  28. RESPONSE=$(curl -sS --header "Content-Type:multipart/form-data" --form "pasty=@$FILENAME" --form "dl=$SELFPASTE_UPLOAD_SECRET" $ENDPOINT);
  29. # uncomment the following line for more debug info
  30. #echo "$RESPONSE";
  31. RESPONSE_STATUS=$(echo "$RESPONSE" | jq -r .status);
  32. RESPONSE_MESSAGE=$(echo "$RESPONSE" | jq -r .message);
  33. if [[ $RESPONSE_STATUS == 200 ]]; then
  34. echo "$RESPONSE_MESSAGE";
  35. else
  36. echo "ERROR. Either your request is invalid (size, type or secret) or something on the endpoint went wrong.";
  37. echo "Response message: $RESPONSE_MESSAGE";
  38. exit 4;
  39. fi;
  40. else
  41. echo "Provided file is not accessible."
  42. exit 3;
  43. fi;