Advertisement
dheadshot

PasteBin API Shell Script

Feb 28th, 2019
4,663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.17 KB | None | 0 0
  1. #!/bin/sh
  2. #pastebin script
  3. if test -e ~/.pb_api_key; then
  4.   API_KEY=`cat ~/.pb_api_key`
  5. else
  6.   echo "API Key not set!  Place your API key into ~/.pb_api_key."
  7.   exit
  8. fi
  9. if test -e ~/.pb_login_key; then
  10.   LOGIN_KEY=`cat ~/.pb_login_key`
  11. fi
  12. if test "$1" = "--help" -o "$1" = "help"; then
  13.   if test "$2" = "format"; then
  14.     echo "Formats:"
  15.     echo " -  4cs: 4CS"
  16.     echo " -  6502acme: 6502 ACME Cross Assembler"
  17.     echo " -  6502kickass: 6502 Kick Assembler"
  18.     echo " -  6502tasm: 6502 TASM/64TASS"
  19.     echo " -  abap: ABAP"
  20.     echo " -  actionscript: ActionScript"
  21.     echo " -  actionscript3: ActionScript 3"
  22.     echo " -  ada: Ada"
  23.     echo " -  aimms: AIMMS"
  24.     echo " -  algol68: ALGOL 68"
  25.     echo " -  apache: Apache Log"
  26.     echo " -  applescript: AppleScript"
  27.     echo " -  apt_sources: APT Sources"
  28.     echo " -  arduino: Arduino"
  29.     echo " -  arm: ARM"
  30.     echo " -  asm: ASM (NASM)"
  31.     echo " -  asp: ASP"
  32.     echo " -  asymptote: Asymptote"
  33.     echo " -  autoconf: autoconf"
  34.     echo " -  autohotkey: Autohotkey"
  35.     echo " -  autoit: AutoIt"
  36.     echo " -  avisynth: Avisynth"
  37.     echo " -  awk: Awk"
  38.     echo " -  bascomavr: BASCOM AVR"
  39.     echo " -  bash: Bash"
  40.     echo " -  basic4gl: Basic4GL"
  41.     echo " -  dos: Batch"
  42.     echo " -  bibtex: BibTeX"
  43.     echo " -  blitzbasic: Blitz Basic"
  44.     echo " -  b3d: Blitz3D"
  45.     echo " -  bmx: BlitzMax"
  46.     echo " -  bnf: BNF"
  47.     echo " -  boo: BOO"
  48.     echo " -  bf: BrainFuck"
  49.     echo " -  c: C"
  50.     echo " -  c_winapi: C (WinAPI)"
  51.     echo " -  c_mac: C for Macs"
  52.     echo " -  cil: C Intermediate Language"
  53.     echo " -  csharp: C#"
  54.     echo " -  cpp: C++"
  55.     echo " -  cpp-winapi: C++ (WinAPI)"
  56.     echo " -  cpp-qt: C++ (with Qt extension)"
  57.     echo " -  c_loadrunner: C: Loadrunner"
  58.     echo " -  caddcl: CAD DCL"
  59.     echo " -  cadlisp: CAD Lisp"
  60.     echo " -  ceylon: Ceylon"
  61.     echo " -  cfdg: CFDG"
  62.     echo " -  chaiscript: ChaiScript"
  63.     echo " -  chapel: Chapel"
  64.     echo " -  clojure: Clojure"
  65.     echo " -  klonec: Clone C"
  66.     echo " -  klonecpp: Clone C++"
  67.     echo " -  cmake: CMake"
  68.     echo " -  cobol: COBOL"
  69.     echo " -  coffeescript: CoffeeScript"
  70.     echo " -  cfm: ColdFusion"
  71.     echo " -  css: CSS"
  72.     echo " -  cuesheet: Cuesheet"
  73.     echo " -  d: D"
  74.     echo " -  dart: Dart"
  75.     echo " -  dcl: DCL"
  76.     echo " -  dcpu16: DCPU-16"
  77.     echo " -  dcs: DCS"
  78.     echo " -  delphi: Delphi"
  79.     echo " -  oxygene: Delphi Prism (Oxygene)"
  80.     echo " -  diff: Diff"
  81.     echo " -  div: DIV"
  82.     echo " -  dot: DOT"
  83.     echo " -  e: E"
  84.     echo " -  ezt: Easytrieve"
  85.     echo " -  ecmascript: ECMAScript"
  86.     echo " -  eiffel: Eiffel"
  87.     echo " -  email: Email"
  88.     echo " -  epc: EPC"
  89.     echo " -  erlang: Erlang"
  90.     echo " -  euphoria: Euphoria"
  91.     echo " -  fsharp: F#"
  92.     echo " -  falcon: Falcon"
  93.     echo " -  filemaker: Filemaker"
  94.     echo " -  fo: FO Language"
  95.     echo " -  f1: Formula One"
  96.     echo " -  fortran: Fortran"
  97.     echo " -  freebasic: FreeBasic"
  98.     echo " -  freeswitch: FreeSWITCH"
  99.     echo " -  gambas: GAMBAS"
  100.     echo " -  gml: Game Maker"
  101.     echo " -  gdb: GDB"
  102.     echo " -  genero: Genero"
  103.     echo " -  genie: Genie"
  104.     echo " -  gettext: GetText"
  105.     echo " -  go: Go"
  106.     echo " -  groovy: Groovy"
  107.     echo " -  gwbasic: GwBasic"
  108.     echo " -  haskell: Haskell"
  109.     echo " -  haxe: Haxe"
  110.     echo " -  hicest: HicEst"
  111.     echo " -  hq9plus: HQ9 Plus"
  112.     echo " -  html4strict: HTML"
  113.     echo " -  html5: HTML 5"
  114.     echo " -  icon: Icon"
  115.     echo " -  idl: IDL"
  116.     echo " -  ini: INI file"
  117.     echo " -  inno: Inno Script"
  118.     echo " -  intercal: INTERCAL"
  119.     echo " -  io: IO"
  120.     echo " -  ispfpanel: ISPF Panel Definition"
  121.     echo " -  j: J"
  122.     echo " -  java: Java"
  123.     echo " -  java5: Java 5"
  124.     echo " -  javascript: JavaScript"
  125.     echo " -  jcl: JCL"
  126.     echo " -  jquery: jQuery"
  127.     echo " -  json: JSON"
  128.     echo " -  julia: Julia"
  129.     echo " -  kixtart: KiXtart"
  130.     echo " -  kotlin: Kotlin"
  131.     echo " -  latex: Latex"
  132.     echo " -  ldif: LDIF"
  133.     echo " -  lb: Liberty BASIC"
  134.     echo " -  lsl2: Linden Scripting"
  135.     echo " -  lisp: Lisp"
  136.     echo " -  llvm: LLVM"
  137.     echo " -  locobasic: Loco Basic"
  138.     echo " -  logtalk: Logtalk"
  139.     echo " -  lolcode: LOL Code"
  140.     echo " -  lotusformulas: Lotus Formulas"
  141.     echo " -  lotusscript: Lotus Script"
  142.     echo " -  lscript: LScript"
  143.     echo " -  lua: Lua"
  144.     echo " -  m68k: M68000 Assembler"
  145.     echo " -  magiksf: MagikSF"
  146.     echo " -  make: Make"
  147.     echo " -  mapbasic: MapBasic"
  148.     echo " -  markdown: Markdown"
  149.     echo " -  matlab: MatLab"
  150.     echo " -  mirc: mIRC"
  151.     echo " -  mmix: MIX Assembler"
  152.     echo " -  modula2: Modula 2"
  153.     echo " -  modula3: Modula 3"
  154.     echo " -  68000devpac: Motorola 68000 HiSoft Dev"
  155.     echo " -  mpasm: MPASM"
  156.     echo " -  mxml: MXML"
  157.     echo " -  mysql: MySQL"
  158.     echo " -  nagios: Nagios"
  159.     echo " -  netrexx: NetRexx"
  160.     echo " -  newlisp: newLISP"
  161.     echo " -  nginx: Nginx"
  162.     echo " -  nim: Nim"
  163.     echo " -  text: None"
  164.     echo " -  nsis: NullSoft Installer"
  165.     echo " -  oberon2: Oberon 2"
  166.     echo " -  objeck: Objeck Programming Language"
  167.     echo " -  objc: Objective C"
  168.     echo " -  ocaml: OCaml"
  169.     echo " -  ocaml-brief: OCaml Brief"
  170.     echo " -  octave: Octave"
  171.     echo " -  oorexx: Open Object Rexx"
  172.     echo " -  pf: OpenBSD PACKET FILTER"
  173.     echo " -  glsl: OpenGL Shading"
  174.     echo " -  oobas: Openoffice BASIC"
  175.     echo " -  oracle11: Oracle 11"
  176.     echo " -  oracle8: Oracle 8"
  177.     echo " -  oz: Oz"
  178.     echo " -  parasail: ParaSail"
  179.     echo " -  parigp: PARI/GP"
  180.     echo " -  pascal: Pascal"
  181.     echo " -  pawn: Pawn"
  182.     echo " -  pcre: PCRE"
  183.     echo " -  per: Per"
  184.     echo " -  perl: Perl"
  185.     echo " -  perl6: Perl 6"
  186.     echo " -  php: PHP"
  187.     echo " -  php-brief: PHP Brief"
  188.     echo " -  pic16: Pic 16"
  189.     echo " -  pike: Pike"
  190.     echo " -  pixelbender: Pixel Bender"
  191.     echo " -  pli: PL/I"
  192.     echo " -  plsql: PL/SQL"
  193.     echo " -  postgresql: PostgreSQL"
  194.     echo " -  postscript: PostScript"
  195.     echo " -  povray: POV-Ray"
  196.     echo " -  powerbuilder: PowerBuilder"
  197.     echo " -  powershell: PowerShell"
  198.     echo " -  proftpd: ProFTPd"
  199.     echo " -  progress: Progress"
  200.     echo " -  prolog: Prolog"
  201.     echo " -  properties: Properties"
  202.     echo " -  providex: ProvideX"
  203.     echo " -  puppet: Puppet"
  204.     echo " -  purebasic: PureBasic"
  205.     echo " -  pycon: PyCon"
  206.     echo " -  python: Python"
  207.     echo " -  pys60: Python for S60"
  208.     echo " -  q: q/kdb+"
  209.     echo " -  qbasic: QBasic"
  210.     echo " -  qml: QML"
  211.     echo " -  rsplus: R"
  212.     echo " -  racket: Racket"
  213.     echo " -  rails: Rails"
  214.     echo " -  rbs: RBScript"
  215.     echo " -  rebol: REBOL"
  216.     echo " -  reg: REG"
  217.     echo " -  rexx: Rexx"
  218.     echo " -  robots: Robots"
  219.     echo " -  rpmspec: RPM Spec"
  220.     echo " -  ruby: Ruby"
  221.     echo " -  gnuplot: Ruby Gnuplot"
  222.     echo " -  rust: Rust"
  223.     echo " -  sas: SAS"
  224.     echo " -  scala: Scala"
  225.     echo " -  scheme: Scheme"
  226.     echo " -  scilab: Scilab"
  227.     echo " -  scl: SCL"
  228.     echo " -  sdlbasic: SdlBasic"
  229.     echo " -  smalltalk: Smalltalk"
  230.     echo " -  smarty: Smarty"
  231.     echo " -  spark: SPARK"
  232.     echo " -  sparql: SPARQL"
  233.     echo " -  sqf: SQF"
  234.     echo " -  sql: SQL"
  235.     echo " -  standardml: StandardML"
  236.     echo " -  stonescript: StoneScript"
  237.     echo " -  sclang: SuperCollider"
  238.     echo " -  swift: Swift"
  239.     echo " -  systemverilog: SystemVerilog"
  240.     echo " -  tsql: T-SQL"
  241.     echo " -  tcl: TCL"
  242.     echo " -  teraterm: Tera Term"
  243.     echo " -  thinbasic: thinBasic"
  244.     echo " -  typoscript: TypoScript"
  245.     echo " -  unicon: Unicon"
  246.     echo " -  uscript: UnrealScript"
  247.     echo " -  upc: UPC"
  248.     echo " -  urbi: Urbi"
  249.     echo " -  vala: Vala"
  250.     echo " -  vbnet: VB.NET"
  251.     echo " -  vbscript: VBScript"
  252.     echo " -  vedit: Vedit"
  253.     echo " -  verilog: VeriLog"
  254.     echo " -  vhdl: VHDL"
  255.     echo " -  vim: VIM"
  256.     echo " -  visualprolog: Visual Pro Log"
  257.     echo " -  vb: VisualBasic"
  258.     echo " -  visualfoxpro: VisualFoxPro"
  259.     echo " -  whitespace: WhiteSpace"
  260.     echo " -  whois: WHOIS"
  261.     echo " -  winbatch: Winbatch"
  262.     echo " -  xbasic: XBasic"
  263.     echo " -  xml: XML"
  264.     echo " -  xorg_conf: Xorg Config"
  265.     echo " -  xpp: XPP"
  266.     echo " -  yaml: YAML"
  267.     echo " -  z80: Z80 Assembler"
  268.     echo " -  zxbasic: ZXBasic"
  269.   else
  270.     echo "Commands:"
  271.     echo " -  help: show this screen"
  272.     echo " -  login: log into pastebin with '$0 login username password'"
  273.     echo " -  paste: Paste something with '$0 paste pastedata [name] [format] [expire] [privacy] [asguest]' e.g. '$0 paste some_code Code z80 2W public Y'."
  274.     echo " -  pastefile: Paste some file with '$0 pastefile filename [name] [format] [expire] [privacy] [asguest]' e.g. '$0 pastefile ~/test.c Code c 2W public Y'."
  275.     echo "Expiries:"
  276.     echo " -  N: Never"
  277.     echo " -  10M: 10 Minutes"
  278.     echo " -  1H: 1 Hour"
  279.     echo " -  1D: 1 Day"
  280.     echo " -  1W: 1 Week"
  281.     echo " -  2W: 2 Weeks"
  282.     echo " -  1M: 1 Month"
  283.     echo " -  6M: 6 Months"
  284.     echo " -  1Y: 1 Year"
  285.     echo "Privacies:"
  286.     echo " -  public"
  287.     echo " -  unlisted"
  288.     echo " -  private"
  289.     echo "For formats, use '$0 help format'"
  290.   fi
  291. elif test "$1" = "login"; then
  292.   curl --data-urlencode "api_dev_key=$API_KEY" --data-urlencode "api_user_name=$2" --data-urlencode "api_user_password=$3" "https://pastebin.com/api/api_login.php" >~/.pb_temp_login_key
  293.   if grep -i '^Bad' ~/.pb_temp_login_key; then
  294.     echo "Error logging in: " `cat  ~/.pb_temp_login_key`
  295.     rm  ~/.pb_temp_login_key
  296.   elif test -s  ~/.pb_temp_login_key; then
  297.     echo "Logging in appears to be successful!"
  298.     mv  ~/.pb_temp_login_key  ~/.pb_login_key
  299.   else
  300.     echo "Login process interrupted.  Do you have internet?"
  301.   fi
  302. elif test "$1" = "paste"; then
  303. #'$0 paste pastedata [name] [format] [expire] [privacy] [asguest]' e.g. '$0 paste some_code Code z80 2W public Y'."
  304.   if test -z "$2"; then
  305.     echo "No paste data specified!"
  306.     exit
  307.   fi
  308.   if test ! -z "$3"; then
  309.     PB_NAME="api_paste_name=$3"
  310.   fi
  311.   if test ! -z "$4"; then
  312.     PB_FORMAT="api_paste_format=$4"
  313.   else
  314.     PB_FORMAT="api_paste_format=text"
  315.   fi
  316.   if test ! -z "$5"; then
  317.     if test "$5" = "10M" -o "$5" = "1H" -o "$5" = "1D" -o "$5" = "1W" -o "$5" = "2W" -o "$5" = "1M" -o "$5" = "6M" -o "$5" = "1Y"; then
  318.       PB_EXPIRE="api_paste_expire_date=$5"
  319.     else
  320.       echo "Invalid expiry time '$5'!"
  321.       exit
  322.     fi
  323.   else
  324.     PB_EXPIRE="api_paste_expire_date=N"
  325.   fi
  326.   if test "$6" = "public" -o -z "$6"; then
  327.     PB_PRIVACY="api_paste_private=0"
  328.   elif test "$6" = "unlisted"; then
  329.     PB_PRIVACY="api_paste_private=1"
  330.   elif test "$6" = "private"; then
  331.     PB_PRIVACY="api_paste_private=2"
  332.   else
  333.     echo "Unknown privacy level '$6'!"
  334.     exit
  335.   fi
  336.   if test -z "$7" -o "$7" = "N"; then
  337.     PB_USER="api_user_key=$LOGIN_KEY"
  338.   fi
  339.   curl --data-urlencode "api_dev_key=$API_KEY" --data-urlencode "api_option=paste"  --data-urlencode "api_paste_code=$2" --data-urlencode "$PB_NAME" --data-urlencode "$PB_FORMAT" --data-urlencode "$PB_EXPIRE" --data-urlencode "$PB_PRIVACY" --data-urlencode "$PB_USER" "https://pastebin.com/api/api_post.php" >~/.pb_temp_response
  340.   if grep -i '^Bad' ~/.pb_temp_response; then
  341.     echo "Error sending paste data: " `cat  ~/.pb_temp_response`
  342.     rm  ~/.pb_temp_response
  343.   elif test -s  ~/.pb_temp_response; then
  344.     echo "Pasting appears to be successful!"
  345.     echo "Your paste is at: " `cat ~/.pb_temp_response`
  346.     mv  ~/.pb_temp_response ~/.pb_last_url
  347.   else
  348.     echo "Paste process interrupted.  Do you have internet?"
  349.   fi
  350. elif test "$1" = "pastefile"; then
  351. #'$0 pastefile filename [name] [format] [expire] [privacy] [asguest]' e.g. '$0 paste ~/test.c Code c 2W public Y'."
  352.   if test ! -z "$2"; then
  353.     PASTE_FILE=`cat $2`
  354.     PB_DATA="api_paste_code=$PASTE_FILE"
  355.   else
  356.     echo "No paste file specified!"
  357.     exit
  358.   fi
  359.   if test ! -z "$3"; then
  360.     PB_NAME="api_paste_name=$3"
  361.   fi
  362.   if test ! -z "$4"; then
  363.     PB_FORMAT="api_paste_format=$4"
  364.   else
  365.     PB_FORMAT="api_paste_format=text"
  366.   fi
  367.   if test ! -z "$5"; then
  368.     if test "$5" = "10M" -o "$5" = "1H" -o "$5" = "1D" -o "$5" = "1W" -o "$5" = "2W" -o "$5" = "1M" -o "$5" = "6M" -o "$5" = "1Y"; then
  369.       PB_EXPIRE="api_paste_expire_date=$5"
  370.     else
  371.       echo "Invalid expiry time '$5'!"
  372.       exit
  373.     fi
  374.   else
  375.     PB_EXPIRE="api_paste_expire_date=N"
  376.   fi
  377.   if test "$6" = "public" -o -z "$6"; then
  378.     PB_PRIVACY="api_paste_private=0"
  379.   elif test "$6" = "unlisted"; then
  380.     PB_PRIVACY="api_paste_private=1"
  381.   elif test "$6" = "private"; then
  382.     PB_PRIVACY="api_paste_private=2"
  383.   else
  384.     echo "Unknown privacy level '$6'!"
  385.     exit
  386.   fi
  387.   if test -z "$7" -o "$7" = "N"; then
  388.     PB_USER="api_user_key=$LOGIN_KEY"
  389.   fi
  390.   curl --data-urlencode "api_dev_key=$API_KEY" --data-urlencode "api_option=paste"  --data-urlencode "$PB_DATA" --data-urlencode "$PB_NAME" --data-urlencode "$PB_FORMAT" --data-urlencode "$PB_EXPIRE" --data-urlencode "$PB_PRIVACY" --data-urlencode "$PB_USER" "https://pastebin.com/api/api_post.php" >~/.pb_temp_response
  391.   if grep -i '^Bad' ~/.pb_temp_response; then
  392.     echo "Error sending paste data: " `cat  ~/.pb_temp_response`
  393.     rm  ~/.pb_temp_response
  394.   elif test -s  ~/.pb_temp_response; then
  395.     echo "Pasting appears to be successful!"
  396.     echo "Your paste is at: " `cat ~/.pb_temp_response`
  397.     mv  ~/.pb_temp_response ~/.pb_last_url
  398.   else
  399.     echo "Paste process interrupted.  Do you have internet?"
  400.   fi
  401. else
  402.   echo "Unknown command '$1' - use '$0 help' for help."
  403. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement