Created
May 5, 2021 16:51
-
-
Save IC-Tech/9d7b9bafd7040ce90dac959d7ce6227f to your computer and use it in GitHub Desktop.
pastebin.sh easy cli uploads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| dev_key_file="$HOME/.config/pastebin/developer.key" | |
| user_key_file="$HOME/.config/pastebin/user.key" | |
| warn_file="$HOME/.config/pastebin/no_user_key" | |
| if [[ ! -r $dev_key_file ]]; then | |
| nl=1 | |
| echo 'warning developer key is missing, you cannot upload files without a key. run --help' | |
| dev_key='' | |
| else | |
| dev_key="$(cat $dev_key_file)" | |
| fi | |
| if [[ $1 != '--user-login' ]] && [[ $1 != '--no-user-key' ]] && [[ ! -e $warn_file ]] && [[ ! -r $user_key_file ]]; then | |
| nl=1 | |
| echo 'warning user key is missing, run --no-user-key for stop warning' | |
| user_key='' | |
| else | |
| user_key="$(cat $user_key_file)" | |
| fi | |
| if [[ $nl = 1 ]]; then | |
| echo '' | |
| fi | |
| if [[ $1 == '--no-user-key' ]]; then | |
| touch "$HOME/.config/pastebin/no_user_key" | |
| elif [[ $1 == '--user-login' ]]; then | |
| read -p "Username: " user | |
| read -sp "Password: " pass | |
| echo "" | |
| key="$(curl -sS -X POST -d "api_dev_key=$dev_key" -d "api_user_name=$user" -d "api_user_password=$pass" "https://pastebin.com/api/api_login.php")" | |
| echo "> $key" | |
| if [[ $key = Bad* ]]; then | |
| exit 1 | |
| fi | |
| read -p "save this as user key? (Y/n): " confirm | |
| if [[ $confirm == '' || $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then | |
| echo -n "$key" > $user_key_file | |
| fi | |
| elif [[ $1 = '--login' ]]; then | |
| mkdir -p "$HOME/.config/pastebin" | |
| echo "if you don't want to change keys, just hit enter" | |
| echo "if you don't have a user key, run --user-login" | |
| read -p "developer key: " dev_key | |
| if [[ $dev_key = '' ]] ; then | |
| echo "developer key will not change" | |
| else | |
| echo -n "$dev_key" > $dev_key_file | |
| fi | |
| read -p "user key: " user_key | |
| if [[ $dev_key = '' ]] ; then | |
| echo "user key will not change" | |
| else | |
| echo -n "$dev_key" > $user_key_file | |
| fi | |
| elif [[ $1 = '--user' ]] || [[ $1 = '--user-info' ]]; then | |
| curl -sS -X POST -d "api_dev_key=$dev_key" -d "api_user_key=$user_key" -d "api_option=userdetails" "https://pastebin.com/api/api_post.php" | |
| echo "" | |
| elif [[ $1 = '--delete' ]] || [[ $1 = '-d' ]]; then | |
| key=$2 | |
| if [[ $key = '' ]]; then | |
| read -p "Paste key: " key | |
| fi | |
| if [[ key != '' ]]; then | |
| curl -sS -X POST -d "api_dev_key=$dev_key" -d "api_user_key=$user_key" -d 'api_option=delete' -d "api_paste_key=$key" "https://pastebin.com/api/api_post.php" | |
| echo "" | |
| fi | |
| elif [[ -r "$1" ]]; then | |
| read -p "Paste Name / Title: " title | |
| read -p "Paste as a guest (y/N): " guest | |
| if [[ $guest == [yY] || $guest == [yY][eE][sS] ]]; then | |
| user_key='' | |
| fi | |
| read -p "Paste Exposure (public=0 / unlisted=1 / private=2) (0): " vis | |
| if [[ $vis = '' ]]; then | |
| vis=0 | |
| fi | |
| read -p "Paste Expiration (N): " exp | |
| if [[ $exp = '' ]]; then | |
| exp=N | |
| fi | |
| read -p "Syntax Highlighting: " hig | |
| curl -sS -X POST \ | |
| -d "api_dev_key=$dev_key" \ | |
| -d "api_user_key=$user_key" \ | |
| -d "api_option=paste" \ | |
| -d "api_paste_private=$vis" \ | |
| -d "api_paste_name=$title" \ | |
| -d "api_paste_expire_date=$exp" \ | |
| -d "api_paste_format=$hig" \ | |
| -d "api_paste_code=$(cat "$1")" \ | |
| "https://pastebin.com/api/api_post.php" | |
| echo "" | |
| else | |
| echo "Usage: pastebin.sh [option] [files...] | |
| Setup: | |
| login to your pastebin account on browser, visit to https://pastebin.com/doc_api copy your \"Developer API Key\" | |
| run \"./pastebin.sh --user-login\" and get a user key. | |
| then run \"./pastebin.sh --login\" to save your key files. | |
| you don't have to use user key, if you upload as a guest. | |
| key files are located in \$HOME/.config/pastebin/ | |
| Options: | |
| --user-login login to account | |
| --login login with keys | |
| --user, --user-info see user info | |
| --delete, -d delete paste | |
| Example: | |
| create paste | |
| ./pastebin.sh file.txt | |
| delete paste | |
| ./pastebin.sh -d | |
| ./pastebin.sh -d XXXXXX" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment