random

- collection of un-sorted bollocks
git clone git://git.acid.vegas/random.git
Log | Files | Refs | Archive

pastebin (2600B)

      1 #!/bin/sh
      2 # posix shell script for the pastebin api - developed by acidvegas (https://git.acid.vegas/random)
      3 
      4 # https://pastebin.com/doc_api
      5 # https://pastebin.com/doc_scraping_api
      6 
      7 api_key=""
      8 api_user_key=""
      9 
     10 usage() {
     11 	echo "pastebin <path>    | create a new paste with the contents of <path>"
     12 	echo "pastebin pastes    | list metadata for all of your pastes"
     13 	echo "pastebin userkey   | retrieve your api_user_key (required for some commands)"
     14 	echo "pastebin del <id>  | delete a paste   (<id> is the ending of your paste url or can be retrieved from the `pastebin pastes` output)"
     15 	echo "pastebin read <id> | read a raw paste (<id> is the ending of your paste url or can be retrieved from the `pastebin pastes` output)"
     16 }
     17 
     18 [ -z api_key ] && echo "error: no api_key defined (visit https://pastebin.com/doc_api for more help)" && exit 1
     19 if [ $# = 1 ]; then
     20 	if [ $1 = 'pastes'  ]; then
     21 		[ -z $api_user_key ] && echo "error: no api_user_key defined (run ./pastebin userkey to get your api_user_key)" && exit 1
     22 		curl -X POST -d 'api_dev_key=$api_key' -d 'api_user_key=$api_user_key' -d 'api_option=list' -d 'api_results_limit=1000' "https://pastebin.com/api/api_post.php"
     23 	elif [ $1 = 'userkey' ]; then
     24 		read -p  'username: ' username
     25 		read -sp 'password: ' password
     26 		curl -X POST -d 'api_dev_key=$api_key' -d 'api_user_name=$username' -d 'api_user_password=$password' "https://pastebin.com/api/api_login.php"
     27 	elif [ $1 = 'user' ]; then
     28 		curl -X POST -d 'api_dev_key=$api_key' -d 'api_user_key=$api_user_key' -d 'api_option=userdetails' "https://pastebin.com/api/api_post.php"
     29 	elif [ -f $1 ]; then
     30 		curl -X POST -d 'api_dev_key=$api_key' -d 'api_paste_code=$(cat $1)' -d 'api_option=paste' "https://pastebin.com/api/api_post.php"
     31 		# optional arguments:
     32 		#	-d 'api_paste_name='
     33 		#	-d 'api_paste_format='      # https://pastebin.com/doc_api#5
     34 		#	-d 'api_paste_private='     # 0 public | 1 unlisted | 2 private (api_user_key required for private)
     35 		#	-d 'api_paste_expire_date=' # N 10M 1H 1D 1W 2W 1M 6M 1Y
     36 		#	-d 'api_user_key='
     37 		#	-d 'api_folder_key='
     38 	fi
     39 elif [ $# = 3 ]; then
     40 	if [ $1 = 'del' ]; then
     41 		curl -X POST -d 'api_dev_key=$api_key' -d 'api_user_key=$api_user_key' -d 'api_option=delete' -d 'api_paste_key=$2' "https://pastebin.com/api/api_post.php"
     42 	elif [ $1 = 'read' ]; then
     43 		[ -z $api_user_key ] && echo "error: no api_user_key defined (run ./pastebin userkey to get your api_user_key)" && exit 1
     44 		curl -X POST -d 'api_dev_key=$api_key' -d 'api_user_key=$api_user_key' -d 'api_option=show_paste' -d 'api_paste_key=$2' "https://pastebin.com/api/api_post.php"
     45 	fi
     46 fi
     47 
     48 
     49