Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -euo pipefail
- IFS=$'\n\t'
- readonly LOG_FILE="/tmp/pastebin_$(date --iso-8601=minutes).log"
- function log_info() { echo "[INFO ] $@" | tee -a "$LOG_FILE" >&2 ; }
- function log_warning() { echo "[WARNING] $@" | tee -a "$LOG_FILE" >&2 ; }
- function log_error() { echo "[ERROR ] $@" | tee -a "$LOG_FILE" >&2 ; }
- function log_fatal() { echo "[FATAL ] $@" | tee -a "$LOG_FILE" >&2 ; exit 1 ; }
- DEV_KEY=""
- LANGUAGE=""
- USERNAME=""
- function check_prerequisites() {
- function check() {
- [[ ! -z $(which "${1}") ]] || log_fatal "${1} does not exist; please install"
- }
- for req in tee curl; do
- check "${req}"
- done
- }
- function parse_config() {
- readonly CFG_FILE=.pastebinrc
- if [ -f "/home/${USER}/${CFG_FILE}" ]; then
- source <(grep = "/home/${USER}/${CFG_FILE}")
- DEV_KEY="${devkey}"
- LANGUAGE="${language}"
- USERNAME="${username}"
- else
- log_fatal "No config file found; exiting."
- fi
- }
- function generate_user_key() {
- read -s -p "Password: " password
- echo
- log_info "${password}"
- }
- function upload() {
- declare -r PASTEBIN_URL="https://pastebin.com/api/api_post.php"
- curl --silent --show-error --data "api_dev_key=${DEV_KEY}&api_option=paste&api_paste_format=${LANGUAGE}" --data-urlencode "api_paste_code=${CONTENTS}" \
- "${PASTEBIN_URL}"
- }
- check_prerequisites
- parse_config
- generate_user_key
- CONTENTS=$(cat /dev/stdin)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement