OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-nopaste
  6. # Copyright (C) 2010 - 2011 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Paste input or file to http://nopaste.opensde.net/
  16. #Alias: paste
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  19. . $SDEROOT/lib/libsde.in
  20. NOPASTE='http://nopaste.opensde.net/'
  21. nopaste_usage() {
  22. local progname="$(echo "${0##*/}" | tr '-' ' ')"
  23. echo "Usage: $progname [<file>]"
  24. }
  25. file= tmpfile=
  26. if [ $# -gt 0 ]; then
  27. if [ -s "$1" ]; then
  28. file="$1"
  29. else
  30. nopaste_usage >&2
  31. exit 1
  32. fi
  33. else
  34. file=$(mktemp)
  35. cat > "$file"
  36. tmpfile=yes
  37. fi
  38. mime=$(file --mime-type "$file" | cut -d' ' -f2)
  39. type=$(file "$file" | cut -d' ' -f2-)
  40. # lang = (bash|c|diff|lua|perl|python|text)
  41. case "$mime" in
  42. text/x-shellscript|application/x-shellscript) lang=bash ;;
  43. text/x-diff) lang=diff ;;
  44. text/x-c) lang=c ;;
  45. *)
  46. case "$type" in
  47. empty) exit ;;
  48. ASCII*) lang=text ;;
  49. "diff output text") lang=diff ;;
  50. *) echo_warning "Assuming plain text (type:$type mime:$mime)"
  51. lang=text ;;
  52. esac
  53. esac
  54. hash=$(curl -si -H 'Expect:' -F "sourcefile=@$file" -F lang=$lang \
  55. $NOPASTE | grep ^Location: | tr -d '\r' | cut -d' ' -f2-)
  56. [ -z "$tmpfile" ] || rm -f "$file"
  57. if [ -z "$hash" ]; then
  58. echo_error "failed to paste to $NOPASTE."
  59. exit 1
  60. fi
  61. echo "$NOPASTE$hash" # "(lang:$lang, mime:$mime, type:$type)"