Want more features on Pastebin? Sign Up, it's FREE!
Guest

pbget.sh

By: a guest on May 23rd, 2013  |  syntax: Bash  |  size: 2.50 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2. #
  3. #    pbput, pbputs, pbget - put and get binary files to/from pastebin.com
  4. #    Copyright (C) 2010 Dustin Kirkland <dustin.kirkland@gmail.com>
  5. #
  6. #    Authors: Dustin Kirkland <dustin.kirkland@gmail.com>
  7. #
  8. #    This program is free software; you can redistribute it and/or modify
  9. #    it under the terms of the GNU General Public License as published by
  10. #    the Free Software Foundation; either version 2 of the License, or
  11. #    (at your option) any later version.
  12. #
  13. #    This program is distributed in the hope that it will be useful,
  14. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #    GNU General Public License for more details.
  17. #
  18. #    You should have received a copy of the GNU General Public License along
  19. #    with this program; if not, write to the Free Software Foundation, Inc.,
  20. #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21.  
  22. PROG=$(basename $0)
  23. URL="http://pastebin.com"
  24. TEMPLATE="$PROG.XXXXXXXXXX"
  25. [ -d "$TMPDIR" ] && TEMPLATE="$TMPDIR/$TEMPLATE" || TEMPLATE="/tmp/$TEMPLATE"
  26.  
  27. # Create a secure tempfiles
  28. TEMP=$(mktemp $TEMPLATE)
  29. TEMP2=$(mktemp $TEMPLATE)
  30. trap "rm -f $TEMP $TEMP2 2>/dev/null || true" EXIT HUP INT QUIT TERM
  31.  
  32. case "$PROG" in
  33.         pbget)
  34.                 url=$(echo "$1" | sed -e "s:.com/:.com/download.php?i=:")
  35.                 wget -q -O- "$url" | base64 -d | lzma -d > "$TEMP"
  36.                 # Support secure uploads
  37.                 if gpg -d "$TEMP" >"$TEMP2" 2>/dev/null; then
  38.                         # Upload was encrypted
  39.                         mv -f "$TEMP2" "$TEMP"
  40.                 fi
  41.                 if LC=C file "$TEMP" | grep -qs "^$TEMP: POSIX tar archive"; then
  42.                         # Download is a tarball; unpack safely
  43.                         [ -d "$2" ] && DIR="$2" || DIR=$(mktemp -d $TEMPLATE)
  44.                         tar -C "$DIR" -xvf "$TEMP" 2>/dev/null || cat "$TEMP"
  45.                         echo "INFO: Output is in [$DIR]"
  46.                 else
  47.                         # Upload came from stdin, so display on stdout
  48.                         cat "$TEMP"
  49.                 fi
  50.         ;;
  51.         pbput|pbputs)
  52.                 if [ -r "$1" ]; then
  53.                         # Read file from argument
  54.                         tar cf "$TEMP" "$1"
  55.                         # Second argument indicates a target user in the gpg keyring
  56.                         [ -z "$2" ] && GPG_OPTS="-c" || GPG_OPTS="-s -e -r $2"
  57.                 else
  58.                         # Read from standard in
  59.                         cat /dev/stdin > "$TEMP"
  60.                         # Argument indicates a target user in the gpg keyring
  61.                         [ -z "$1" ] && GPG_OPTS="-c" || GPG_OPTS="-s -e -r $1"
  62.                 fi
  63.                 if [ "$PROG" = "pbputs" ]; then
  64.                         mv -f "$TEMP" "$TEMP".in
  65.                         cat "$TEMP".in | gpg $GPG_OPTS > "$TEMP"
  66.                         rm -f "$TEMP".in
  67.                 fi
  68.                 lzma -9 -f -c "$TEMP" | base64 | pastebinit -b "$URL"
  69.         ;;
  70.         *)
  71.                 echo "ERROR" 1>&2
  72.                 exit 1
  73.         ;;
  74. esac
clone this paste RAW Paste Data