Advertisement
bigdavedev

Untitled

Jun 25th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.40 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -euo pipefail
  4. IFS=$'\n\t'
  5.  
  6. readonly LOG_FILE="/tmp/pastebin_$(date --iso-8601=minutes).log"
  7. function log_info()    { echo "[INFO   ]    $@" | tee -a "$LOG_FILE" >&2 ; }
  8. function log_warning() { echo "[WARNING]    $@" | tee -a "$LOG_FILE" >&2 ; }
  9. function log_error()   { echo "[ERROR  ]    $@" | tee -a "$LOG_FILE" >&2 ; }
  10. function log_fatal()   { echo "[FATAL  ]    $@" | tee -a "$LOG_FILE" >&2 ; exit 1 ; }
  11.  
  12. DEV_KEY=""
  13. LANGUAGE=""
  14.  
  15. USERNAME=""
  16.  
  17. function check_prerequisites() {
  18.     function check() {
  19.         [[ ! -z $(which "${1}") ]] || log_fatal "${1} does not exist; please install"
  20.     }
  21.  
  22.     for req in tee curl; do
  23.         check "${req}"
  24.     done
  25. }
  26.  
  27. function parse_config() {
  28.     readonly CFG_FILE=.pastebinrc
  29.  
  30.     if [ -f "/home/${USER}/${CFG_FILE}" ]; then
  31.         source <(grep = "/home/${USER}/${CFG_FILE}")
  32.         DEV_KEY="${devkey}"
  33.         LANGUAGE="${language}"
  34.         USERNAME="${username}"
  35.     else
  36.         log_fatal "No config file found; exiting."
  37.     fi
  38. }
  39.  
  40. function generate_user_key() {
  41.     read -s -p "Password: " password
  42.     echo
  43.  
  44.     log_info "${password}"
  45. }
  46.  
  47. function upload() {
  48.     declare -r PASTEBIN_URL="https://pastebin.com/api/api_post.php"
  49.  
  50.     curl --silent --show-error --data "api_dev_key=${DEV_KEY}&api_option=paste&api_paste_format=${LANGUAGE}" --data-urlencode "api_paste_code=${CONTENTS}" \
  51.         "${PASTEBIN_URL}"
  52. }
  53.  
  54. check_prerequisites
  55. parse_config
  56.  
  57. generate_user_key
  58.  
  59. CONTENTS=$(cat /dev/stdin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement