New Paste

From jason, 5 Months ago, written in Plain Text, viewed 3 times.
URL https://casjay.cc/view/435c984a Embed
Download Paste or View Raw
  1. #!/usr/bin/env bash
  2. # shellcheck shell=bash
  3. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  4. ##@Version           :  202208141743-git
  5. # @@Author           :  Jason Hempstead
  6. # @@Contact          :  jason@casjaysdev.com
  7. # @@License          :  WTFPL
  8. # @@ReadME           :  pb --help
  9. # @@Copyright        :  Copyright: (c) 2022 Jason Hempstead, Casjays Developments
  10. # @@Created          :  Sunday, Aug 14, 2022 17:43 EDT
  11. # @@File             :  pb
  12. # @@Description      :  Send output to a pastebin
  13. # @@Changelog        :  New script
  14. # @@TODO             :  Better documentation
  15. # @@Other            :
  16. # @@Resource         :
  17. # @@Terminal App     :  no
  18. # @@sudo/root        :  no
  19. # @@Template         :  bash/system
  20. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  21. APPNAME="$(basename "$0" 2>/dev/null)"
  22. VERSION="202208141743-git"
  23. HOME="${USER_HOME:-$HOME}"
  24. USER="${SUDO_USER:-$USER}"
  25. RUN_USER="${SUDO_USER:-$USER}"
  26. SCRIPT_SRC_DIR="${BASH_SOURCE%/*}"
  27. PB_REQUIRE_SUDO="${PB_REQUIRE_SUDO:-no}"
  28. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  29. # Reopen in a terminal
  30. #if [ ! -t 0 ] && { [ "$1" = --term ] || [ $# = 0 ]; }; then { [ "$1" = --term ] && shift 1 || true; } && TERMINAL_APP="TRUE" myterminal -e "$APPNAME $*" && exit || exit 1; fi
  31. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  32. # Initial debugging
  33. [ "$1" = "--debug" ] && set -x && export SCRIPT_OPTS="--debug" && export _DEBUG="on"
  34. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  35. # Disables colorization
  36. [ "$1" = "--raw" ] && export SHOW_RAW="true"
  37. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  38. # pipes fail
  39. set -o pipefail
  40. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  41. # Import functions
  42. CASJAYSDEVDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}"
  43. SCRIPTSFUNCTDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}/functions"
  44. SCRIPTSFUNCTFILE="${SCRIPTSAPPFUNCTFILE:-testing.bash}"
  45. SCRIPTSFUNCTURL="${SCRIPTSAPPFUNCTURL:-https://github.com/dfmgr/installer/raw/main/functions}"
  46. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  47. if [ -f "$PWD/$SCRIPTSFUNCTFILE" ]; then
  48.   . "$PWD/$SCRIPTSFUNCTFILE"
  49. elif [ -f "$SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE" ]; then
  50.   . "$SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE"
  51. else
  52.   echo "Can not load the functions file: $SCRIPTSFUNCTDIR/$SCRIPTSFUNCTFILE" 1>&2
  53.   exit 1
  54. fi
  55. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  56. # Options are: *_install
  57. # desktopmgr devenvmgr dfmgr dockermgr fontmgr iconmgr
  58. #   pkmgr system systemmgr thememgr user wallpapermgr
  59. user_install && __options "$@"
  60. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  61. # Send all output to /dev/null
  62. __devnull() {
  63.   tee &>/dev/null && exitCode=0 || exitCode=1
  64.   return ${exitCode:-$?}
  65. }
  66. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
  67. # Send errors to /dev/null
  68. __devnull2() {
  69.   [ -n "$1" ] && local cmd="$1" && shift 1 || return 1
  70.   eval $cmd "$*" 2>/dev/null && exitCode=0 || exitCode=1
  71.   return ${exitCode:-$?}
  72. }
  73. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
  74. # See if the executable exists
  75. __cmd_exists() {
  76.   exitCode=0
  77.   [ -n "$1" ] && local exitCode="" || return 0
  78.   for cmd in "$@"; do
  79.     builtin command -v "$cmd" &>/dev/null && exitCode+=$(($exitCode + 0)) || exitCode+=$(($exitCode + 1))
  80.   done
  81.   [ $exitCode -eq 0 ] || exitCode=3
  82.   return ${exitCode:-$?}
  83. }
  84. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  85. # Check for a valid internet connection
  86. __am_i_online() {
  87.   local exitCode=0
  88.   curl -q -LSsfI --max-time 1 --retry 0 "${1:-http://1.1.1.1}" 2>&1 | grep -qi 'server:.*cloudflare' || exitCode=4
  89.   return ${exitCode:-$?}
  90. }
  91. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  92. # colorization
  93. if [ "$SHOW_RAW" = "true" ]; then
  94.   printf_color() { printf '%b' "$1" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; }
  95. else
  96.   printf_color() { printf "%b" "$(tput setaf "${2:-7}" 2>/dev/null)" "$1" "$(tput sgr0 2>/dev/null)"; }
  97. fi
  98. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  99. # Additional printf_ colors
  100. __printf_head() { printf_blue "$1"; }
  101. __printf_opts() { printf_purple "$1"; }
  102. __printf_line() { printf_cyan "$1"; }
  103. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  104. # output version
  105. __version() { printf_cyan "$VERSION"; }
  106. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  107. # list options
  108. __list_options() {
  109.   printf_color "$1: " "$5"
  110.   echo -ne "$2" | sed 's|:||g;s/'$3'/ '$4'/g'
  111.   printf_newline
  112. }
  113. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  114. # create the config file
  115. __gen_config() {
  116.   local NOTIFY_CLIENT_NAME="$APPNAME"
  117.   if [ "$INIT_CONFIG" != "TRUE" ]; then
  118.     printf_blue "Generating the config file in"
  119.     printf_cyan "$PB_CONFIG_DIR/$PB_CONFIG_FILE"
  120.   fi
  121.   [ -d "$PB_CONFIG_DIR" ] || mkdir -p "$PB_CONFIG_DIR"
  122.   [ -d "$PB_CONFIG_BACKUP_DIR" ] || mkdir -p "$PB_CONFIG_BACKUP_DIR"
  123.   [ -f "$PB_CONFIG_DIR/$PB_CONFIG_FILE" ] &&
  124.     cp -Rf "$PB_CONFIG_DIR/$PB_CONFIG_FILE" "$PB_CONFIG_BACKUP_DIR/$PB_CONFIG_FILE.$$"
  125.   cat <<EOF >"$PB_CONFIG_DIR/$PB_CONFIG_FILE"
  126. # Settings for pb
  127. PB_SAVED_FILE="${PB_SAVED_FILE:-}"
  128. PB_PRIVATE_URL="${PRIVATE_PASTEBIN_URL:-}"
  129. PB_PRIVATE_API_URL="${PRIVATE_PASTEBIN_API_URL:-}"
  130. PB_PRIVATE_API_KEY="${PRIVATE_PASTEBIN_API_KEY:-}"
  131. PB_PASTEBIN_COM_API_DEV="${PB_PASTEBIN_COM_API_DEV:-}"
  132. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  133. # Color Settings
  134. PB_OUTPUT_COLOR_1="${PB_OUTPUT_COLOR_1:-}"
  135. PB_OUTPUT_COLOR_2="${PB_OUTPUT_COLOR_2:-}"
  136. PB_OUTPUT_COLOR_GOOD="${PB_OUTPUT_COLOR_GOOD:-}"
  137. PB_OUTPUT_COLOR_ERROR="${PB_OUTPUT_COLOR_ERROR:-}"
  138. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  139. # Notification Settings
  140. PB_NOTIFY_ENABLED="${PB_NOTIFY_ENABLED:-}"
  141. PB_GOOD_NAME="${PB_GOOD_NAME:-}"
  142. PB_ERROR_NAME="${PB_ERROR_NAME:-}"
  143. PB_GOOD_MESSAGE="${PB_GOOD_MESSAGE:-}"
  144. PB_ERROR_MESSAGE="${PB_ERROR_MESSAGE:-}"
  145. PB_NOTIFY_CLIENT_NAME="${PB_NOTIFY_CLIENT_NAME:-}"
  146. PB_NOTIFY_CLIENT_ICON="${PB_NOTIFY_CLIENT_ICON:-}"
  147. PB_NOTIFY_CLIENT_URGENCY="${PB_NOTIFY_CLIENT_URGENCY:-}"
  148.  
  149. EOF
  150.   if builtin type -t __gen_config_local | grep -q 'function'; then __gen_config_local; fi
  151.   if [ -f "$PB_CONFIG_DIR/$PB_CONFIG_FILE" ]; then
  152.     [ "$INIT_CONFIG" = "TRUE" ] || printf_green "Your config file for $APPNAME has been created"
  153.     . "$PB_CONFIG_DIR/$PB_CONFIG_FILE"
  154.     exitCode=0
  155.   else
  156.     printf_red "Failed to create the config file"
  157.     exitCode=1
  158.   fi
  159.   return ${exitCode:-$?}
  160. }
  161. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  162. # Help function - Align to 50
  163. __help() {
  164.   __printf_head "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  165.   __printf_opts "pb:  Send output to a pastebin - $VERSION"
  166.   __printf_head "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  167.   __printf_line "Usage: pb [options] [commands]"
  168.   __printf_line " - "
  169.   __printf_line " - "
  170.   __printf_line "--dir                           - Sets the working directory"
  171.   __printf_head "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  172.   __printf_opts "Other Options"
  173.   __printf_head "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  174.   __printf_line "--help                          - Shows this message"
  175.   __printf_line "--config                        - Generate user config file"
  176.   __printf_line "--version                       - Show script version"
  177.   __printf_line "--options                       - Shows all available options"
  178.   __printf_line "--debug                         - Enables script debugging"
  179.   __printf_line "--raw                           - Removes all formatting on output"
  180.   __printf_head "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
  181. }
  182. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  183. # Is current user root
  184. __user_is_root() {
  185.   { [ $(id -u) -eq 0 ] || [ $EUID -eq 0 ] || [ "$WHOAMI" = "root" ]; } && return 0 || return 1
  186. }
  187. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  188. # Is current user not root
  189. __user_is_not_root() {
  190.   { [ $(id -u) -ne 0 ] || [ $EUID -ne 0 ] || [ "$WHOAMI" != "root" ]; } && return 0 || return 1
  191. }
  192. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  193. # Check if user is a member of sudo
  194. __sudo_group() {
  195.   grep -s "${1:-$USER}" "/etc/group" | grep -Eq 'wheel|adm|sudo' || return 1
  196. }
  197. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  198. # # Get sudo password
  199. __sudoask() {
  200.   ask_for_password sudo true && return 0 || return 1
  201. }
  202. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  203. # Run sudo
  204. __sudorun() {
  205.   __sudoif && __cmd_exists sudo && sudo -HE "$@" || { __sudoif && eval "$@"; }
  206.   return $?
  207. }
  208. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  209. # Test if user has access to sudo
  210. __can_i_sudo() {
  211.   (sudo -vn && sudo -ln) 2>&1 | grep -vq 'may not' >/dev/null && return 0
  212.   __sudo_group "${1:-$USER}" || __sudoif || __sudo true &>/dev/null || return 1
  213. }
  214. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  215. # User can run sudo
  216. __sudoif() {
  217.   __user_is_root && return 0
  218.   __can_i_sudo "${RUN_USER:-$USER}" && return 0
  219.   __user_is_not_root && __sudoask && return 0 || return 1
  220. }
  221. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  222. # Run command as root
  223. requiresudo() {
  224.   if [ "$PB_REQUIRE_SUDO" = "yes" ] && [ -z "$PB_REQUIRE_SUDO_RUN" ]; then
  225.     export PB_REQUIRE_SUDO="no"
  226.     export PB_REQUIRE_SUDO_RUN="true"
  227.     __sudo "$@"
  228.     exit $?
  229.   else
  230.     return 0
  231.   fi
  232. }
  233. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  234. # Execute sudo
  235. __sudo() {
  236.   CMD="${1:-echo}" && shift 1
  237.   CMD_ARGS="${*:--e "${RUN_USER:-$USER}"}"
  238.   SUDO="$(builtin command -v sudo 2>/dev/null || echo 'eval')"
  239.   [ "$(basename "$SUDO" 2>/dev/null)" = "sudo" ] && OPTS="--preserve-env=PATH -HE"
  240.   if __sudoif; then
  241.     export PATH="$PATH"
  242.     $SUDO ${OPTS:-} $CMD $CMD_ARGS && true || false
  243.     exitCode=$?
  244.   else
  245.     printf '%s\n' "This requires root to run"
  246.     exitCode=1
  247.   fi
  248.   return ${exitCode:-1}
  249. }
  250. # End of sudo functions
  251. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  252. __trap_exit() {
  253.   exitCode=${exitCode:-$?}
  254.   [ -f "$PB_TEMP_FILE" ] && rm -Rf "$PB_TEMP_FILE" &>/dev/null
  255.   if builtin type -t __trap_exit_local | grep -q 'function'; then __trap_exit_local; fi
  256.   return $exitCode
  257. }
  258. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  259. # User defined functions
  260. __private() {
  261.   if [ -n "$PB_PRIVATE_API_KEY" ] && [ "$PB_PRIVATE_API_KEY" != "no_api_key_needed_for_casjay_cc" ]; then
  262.     res="$(printf "%s\n" "$ARG" | curl -q -LSsf -H "Accept: application/json" -H 'Authorization: Bearer '$PB_PRIVATE_API_KEY'' -d lang="$language" -d name="$name" --data-urlencode text@- "${PB_PRIVATE_API_URL:-https://casjay.cc/api/create}" 2>/dev/null | grep '^')"
  263.   else
  264.     res="$(printf "%s\n" "$ARG" | curl -q -LSsf -d lang="$language" -d name="$name" --data-urlencode text@- "${PB_PRIVATE_API_URL:-https://casjay.cc/api/create}" 2>/dev/null | grep '^')"
  265.   fi
  266.   [ -n "$res" ] && printf '%s\n' "$res" || printf ''
  267. }
  268. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  269. __execute_pb() {
  270.   printf_cyan "Attempting to send data to $1"
  271.   local paste="" savedir="" date="" service=""
  272.   service="$1"
  273.   date="$(date +'%a %b %d, %Y at %H:%M:%S %Z')"
  274.   savedir="$(dirname "$PB_SAVED_FILE" | grep '^' || echo "$HOME/Documents")"
  275.   case "$1" in
  276.   ix | ix.io)
  277.     shift 1
  278.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" 'f:1=<-' "http://ix.io" <"$ARG" 2>/dev/null | grep '^')"
  279.     ;;
  280.   0x0 | null | nullbyte | 0*)
  281.     shift 1
  282.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'file=@-' "https://0x0.st" <"$ARG" 2>/dev/null | grep '^')"
  283.     ;;
  284.   sprunge | sprunge.us | s*)
  285.     shift 1
  286.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'sprunge=<-' "http://sprunge.us" <"$ARG" 2>/dev/null | grep '^')"
  287.     ;;
  288.   iotek | iopaste | p.iotek.org | iop*)
  289.     shift 1
  290.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -sT- "https://p.iotek.org" <"$ARG" 2>/dev/null | grep '^')"
  291.     ;;
  292.   clbin | clbin.com | cl*)
  293.     shift 1
  294.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'clbin=<-' "https://clbin.com" <"$ARG" 2>/dev/null | grep '^')"
  295.     ;;
  296.   uguu | uguu.se | u*)
  297.     shift 1
  298.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'file=@-' "https://uguu.se/api.php?d=upload-tool" <"$ARG" 2>/dev/null | grep '^')"
  299.     ;;
  300.   lewd | lewd.se | l*)
  301.     shift 1
  302.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'file=@-' "https://lewd.se/api.php?d=upload-tool" <"$ARG" 2>/dev/null | grep '^')"
  303.     ;;
  304.   fiery | fiery.me | f*)
  305.     shift 1
  306.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'files[]=@-' "https://safe.fiery.me/api/upload" <"$ARG" 2>/dev/null | grep -Po '"url":"[A-Za-z0-9]+.*?"' | sed 's/"url":"//;s/"//' | grep '^')"
  307.     ;;
  308.   catbox | catbox.moe | cat*)
  309.     shift 1
  310.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'reqtype=fileupload' -F 'fileToUpload=@-' "https://catbox.moe/user/api.php" <"$ARG" 2>/dev/null | grep '^')"
  311.     ;;
  312.   dmca | dmca.gripe | gripe | dm*)
  313.     shift 1
  314.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -F 'files[]=@-' "http://dmca.gripe/api/upload" <"$ARG" 2>/dev/null | grep -Po '"url":"[A-Za-z0-9]+.*?"' | sed 's/"url":"//;s/"//;s/[\]//g' | grep '^')"
  315.     ;;
  316.   dumpz | dumpz.org | du*)
  317.     shift 1
  318.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -s --data-binary @- "https://dumpz.org" <"$ARG" 2>/dev/null | sed 's/http/&s/;s!$!/text/!' | grep '^')"
  319.     ;;
  320.   w1r3 | wire | w1r3.net | w*)
  321.     shift 1
  322.     get_response="$(curl -q -LSsf -F 'upload=@-' "https://w1r3.net" <"$ARG" 2>/dev/null | grep '^')"
  323.     ;;
  324.   pb | pastebin | pastebin.com)
  325.     shift 1
  326.     qs="api_option=paste&api_dev_key=${PB_PASTEBIN_COM_API_DEV:-97d4dbcc849cf72fe005154e40904f71}&api_paste_expire_date=N&api_paste_private=public&api_paste_name=$(basename "${ARG}")"
  327.     get_response="$(curl -q -LSsf -A "$PB_USER_AGENT" -d "${qs}" --data-urlencode "api_paste_code=$(<"$ARG")" "https://pastebin.com/api" 2>/dev/null | grep '^')"
  328.     ;;
  329.   private)
  330.     shift 1
  331.     get_response="$(__private | grep '^')"
  332.     ;;
  333.   *)
  334.     echo "$ARRAY" | prinf_column $PB_OUTPUT_COLOR_2
  335.     exit 1
  336.     ;;
  337.   esac
  338.   if [ -n "$get_response" ]; then
  339.     printf '%s\n' "$get_response" | printf_readline $PB_OUTPUT_COLOR_2
  340.     printf 'Paste from %s: %s\n' "$date" "$get_response" >>"$PB_SAVED_FILE"
  341.     __cmd_exists clipboard && printf '%s\n' "$get_response" | NOTIFY_CLIENT_NAME="$PB_NOTIFY_CLIENT_NAME" clipboard
  342.     return 0
  343.   else
  344.     return 1
  345.   fi
  346. }
  347. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  348. # User defined variables/import external variables
  349.  
  350. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  351. # Application Folders
  352. PB_CONFIG_FILE="${PB_CONFIG_FILE:-settings.conf}"
  353. PB_CONFIG_DIR="${PB_CONFIG_DIR:-$HOME/.config/myscripts/pb}"
  354. PB_CONFIG_BACKUP_DIR="${PB_CONFIG_BACKUP_DIR:-$HOME/.local/share/myscripts/pb/backups}"
  355. PB_LOG_DIR="${PB_LOG_DIR:-$HOME/.local/log/pb}"
  356. PB_TEMP_DIR="${PB_TEMP_DIR:-$HOME/.local/tmp/system_scripts/pb}"
  357. PB_CACHE_DIR="${PB_CACHE_DIR:-$HOME/.cache/pb}"
  358. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  359. # Color Settings
  360. PB_OUTPUT_COLOR_1="${PB_OUTPUT_COLOR_1:-4}"
  361. PB_OUTPUT_COLOR_2="${PB_OUTPUT_COLOR_2:-5}"
  362. PB_OUTPUT_COLOR_GOOD="${PB_OUTPUT_COLOR_GOOD:-2}"
  363. PB_OUTPUT_COLOR_ERROR="${PB_OUTPUT_COLOR_ERROR:-1}"
  364. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  365. # Notification Settings
  366. PB_NOTIFY_ENABLED="${PB_NOTIFY_ENABLED:-yes}"
  367. PB_GOOD_NAME="${PB_GOOD_NAME:-Great:}"
  368. PB_ERROR_NAME="${PB_ERROR_NAME:-Error:}"
  369. PB_GOOD_MESSAGE="${PB_GOOD_MESSAGE:-No errors reported}"
  370. PB_ERROR_MESSAGE="${PB_ERROR_MESSAGE:-Errors were reported}"
  371. PB_NOTIFY_CLIENT_NAME="${PB_NOTIFY_CLIENT_NAME:-$APPNAME}"
  372. PB_NOTIFY_CLIENT_ICON="${PB_NOTIFY_CLIENT_ICON:-notification-new}"
  373. PB_NOTIFY_CLIENT_URGENCY="${PB_NOTIFY_CLIENT_URGENCY:-normal}"
  374. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  375. # Additional Variables
  376. PB_SAVED_FILE="${PB_SAVED_FILE:-$HOME/Documents/pb_links.txt}"
  377. PB_PRIVATE_URL="${PRIVATE_PASTEBIN_URL:-https://casjay.cc}"
  378. PB_PRIVATE_API_URL="${PRIVATE_PASTEBIN_API_URL:-https://casjay.cc/api/create}"
  379. PB_PRIVATE_API_KEY="${PRIVATE_PASTEBIN_API_KEY:-no_api_key_needed_for_casjay_cc}"
  380. PB_PASTEBIN_COM_API_DEV="${PB_PASTEBIN_COM_API_DEV:-97d4dbcc849cf72fe005154e40904f71}"
  381. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  382. # Generate config files
  383. [ -f "$PB_CONFIG_DIR/$PB_CONFIG_FILE" ] ||
  384.   [ "$*" = "--config" ] || INIT_CONFIG="${INIT_CONFIG:-TRUE}" __gen_config ${SETARGS:-$@}
  385. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  386. # Import config
  387. [ -f "$PB_CONFIG_DIR/$PB_CONFIG_FILE" ] &&
  388.   . "$PB_CONFIG_DIR/$PB_CONFIG_FILE"
  389. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  390. # Ensure Directories exist
  391. [ -d "$PB_LOG_DIR" ] ||
  392.   mkdir -p "$PB_LOG_DIR" |& __devnull
  393. [ -d "$PB_TEMP_DIR" ] ||
  394.   mkdir -p "$PB_TEMP_DIR" |& __devnull
  395. [ -d "$PB_CACHE_DIR" ] ||
  396.   mkdir -p "$PB_CACHE_DIR" |& __devnull
  397. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  398. PB_TEMP_FILE="${PB_TEMP_FILE:-$(mktemp $PB_TEMP_DIR/XXXXXX 2>/dev/null)}"
  399. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  400. # Setup trap to remove temp file
  401. trap '__trap_exit' EXIT
  402. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  403. # Setup notification function
  404. __notifications() {
  405.   __cmd_exists notifications || return
  406.   [ "$PB_NOTIFY_ENABLED" = "yes" ] || return
  407.   [ "$SEND_NOTIFICATION" = "no" ] && return
  408.   (
  409.     set +x
  410.     export SCRIPT_OPTS="" _DEBUG=""
  411.     export NOTIFY_GOOD_MESSAGE="${NOTIFY_GOOD_MESSAGE:-$PB_GOOD_MESSAGE}"
  412.     export NOTIFY_ERROR_MESSAGE="${NOTIFY_ERROR_MESSAGE:-$PB_ERROR_MESSAGE}"
  413.     export NOTIFY_CLIENT_ICON="${NOTIFY_CLIENT_ICON:-$PB_NOTIFY_CLIENT_ICON}"
  414.     export NOTIFY_CLIENT_NAME="${NOTIFY_CLIENT_NAME:-$PB_NOTIFY_CLIENT_NAME}"
  415.     export NOTIFY_CLIENT_URGENCY="${NOTIFY_CLIENT_URGENCY:-$PB_NOTIFY_CLIENT_URGENCY}"
  416.     notifications "$@"
  417.     retval=$?
  418.     return $retval
  419.   ) |& __devnull &
  420. }
  421. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  422. # Set custom actions
  423. unset title
  424. unset private
  425. unset language
  426. unset expire
  427. unset reply
  428. name=${SUDO_USER:-$USER}
  429. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  430. # Argument/Option settings
  431. SETARGS=("$@")
  432. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  433. SHORTOPTS="t:,n:,p,l:,e:,r:,b:,a:"
  434. SHORTOPTS+=""
  435. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  436. LONGOPTS="completions:,config,debug,dir:,help,options,raw,version,silent"
  437. LONGOPTS+=",title:,name:,private,language:,expire:,reply:,apikey:"
  438. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  439. ARRAY="ix 0x0 nullbyte sprunge iopaste clbin uguu lewd fiery catbox dmca dumpz w1r3 pastebin private"
  440. ARRAY+=""
  441. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  442. LIST=""
  443. LIST+=""
  444. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  445. # Setup application options
  446. setopts=$(getopt -o "$SHORTOPTS" --long "$LONGOPTS" -a -n "$APPNAME" -- "$@" 2>/dev/null)
  447. eval set -- "${setopts[@]}" 2>/dev/null
  448. while :; do
  449.   case "$1" in
  450.   --raw)
  451.     shift 1
  452.     export SHOW_RAW="true"
  453.     printf_column() { tee | grep '^'; }
  454.     printf_color() { printf '%b' "$1" | tr -d '\t' | sed '/^%b$/d;s,\x1B\[ 0-9;]*[a-zA-Z],,g'; }
  455.     ;;
  456.   --debug)
  457.     shift 1
  458.     set -xo pipefail
  459.     export SCRIPT_OPTS="--debug"
  460.     export _DEBUG="on"
  461.     __devnull() { tee || return 1; }
  462.     __devnull2() { eval "$@" |& tee || return 1; }
  463.     ;;
  464.   --completions)
  465.     if [ "$2" = "short" ]; then
  466.       printf '%s\n' "-$SHORTOPTS" | sed 's|"||g;s|:||g;s|,|,-|g' | tr ',' '\n'
  467.     elif [ "$2" = "long" ]; then
  468.       printf '%s\n' "--$LONGOPTS" | sed 's|"||g;s|:||g;s|,|,--|g' | tr ',' '\n'
  469.     elif [ "$2" = "array" ]; then
  470.       printf '%s\n' "$ARRAY" | sed 's|"||g;s|:||g' | tr ',' '\n'
  471.     elif [ "$2" = "list" ]; then
  472.       printf '%s\n' "$LIST" | sed 's|"||g;s|:||g' | tr ',' '\n'
  473.     else
  474.       exit 1
  475.     fi
  476.     shift 2
  477.     exit $?
  478.     ;;
  479.   --options)
  480.     shift 1
  481.     printf_blue "Current options for ${PROG:-$APPNAME}"
  482.     [ -z "$SHORTOPTS" ] || __list_options "Short Options" "-${SHORTOPTS}" ',' '-' 4
  483.     [ -z "$LONGOPTS" ] || __list_options "Long Options" "--${LONGOPTS}" ',' '--' 4
  484.     [ -z "$ARRAY" ] || __list_options "Base Options" "${ARRAY}" ',' '' 4
  485.     exit $?
  486.     ;;
  487.   --version)
  488.     shift 1
  489.     __version
  490.     exit $?
  491.     ;;
  492.   --help)
  493.     shift 1
  494.     __help
  495.     exit $?
  496.     ;;
  497.   --config)
  498.     shift 1
  499.     __gen_config
  500.     exit $?
  501.     ;;
  502.   --silent)
  503.     shift 1
  504.     PB_SILENT="true"
  505.     ;;
  506.   --dir)
  507.     CWD_IS_SET="TRUE"
  508.     PB_CWD="$2"
  509.     [ -d "$PB_CWD" ] || mkdir -p "$PB_CWD" |& __devnull
  510.     shift 2
  511.     ;;
  512.   -t | --title)
  513.     title="$2"
  514.     shift 2
  515.     ;;
  516.   -n | --name)
  517.     name="$2"
  518.     shift 2
  519.     ;;
  520.   -p | --private)
  521.     shift 1
  522.     private=1
  523.     ;;
  524.   -l | --language)
  525.     language="$2"
  526.     shift 2
  527.     ;;
  528.   -e | --expire)
  529.     expire="$2"
  530.     shift 2
  531.     ;;
  532.   -r | --reply)
  533.     reply="$2"
  534.     shift 2
  535.     ;;
  536.   -b)
  537.     PASTE_URL="$2"
  538.     shift 2
  539.     ;;
  540.   -a | --apikey)
  541.     PASTE_APIKEY="$2"
  542.     shift 2
  543.     ;;
  544.   --)
  545.     shift 1
  546.     break
  547.     ;;
  548.   esac
  549. done
  550. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  551. # Get directory from args
  552. # set -- "$@"
  553. # for arg in "$@"; do
  554. # if [ -d "$arg" ]; then
  555. # PB_CWD="$arg" && shift 1 && SET_NEW_ARGS=("$@") && break
  556. # elif [ -f "$arg" ]; then
  557. # PB_CWD="$(dirname "$arg" 2>/dev/null)" && shift 1 && SET_NEW_ARGS=("$@") && break
  558. # else
  559. # SET_NEW_ARGS+=("$arg")
  560. # fi
  561. # done
  562. # set -- "${SET_NEW_ARGS[@]}"
  563. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  564. # Set directory to first argument
  565. # [ -d "$1" ] && PB_CWD="$1" && shift 1 || PB_CWD="${PB_CWD:-$PWD}"
  566. PB_CWD="$(realpath "${PB_CWD:-$PWD}" 2>/dev/null)"
  567. # if [ -d "$PB_CWD" ] && cd "$PB_CWD"; then
  568. # if [ "$PB_SILENT" != true ]; then
  569. # printf_cyan "Setting working dir to $PB_CWD"
  570. # fi
  571. # else
  572. # printf_exit "? $PB_CWD does not exist ?"
  573. # fi
  574. export PB_CWD
  575. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  576. # Set actions based on variables
  577.  
  578. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  579. # Check for required applications/Network check
  580. #requiresudo "$0" "$@" || exit 2     # exit 2 if errors
  581. cmd_exists --error --ask bash || exit 3 # exit 3 if not found
  582. #am_i_online --error || exit 4           # exit 4 if no internet
  583. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  584. # APP Variables overrides
  585. { [ -p "/dev/stdin" ] && ARG="$(<"/dev/stdin")" || false; } || { [ -f "$2" ] && ARG="$(<"$2")" || false; } || ARG="$(echo -e "${@:-}")"
  586. PROGRAM=${0##*/}
  587. PB_PRIVATE_URL="${PB_PRIVATE_URL:-}"
  588. PB_PRIVATE_API_KEY="${PB_PRIVATE_API_KEY:-$PASTE_APIKEY}"
  589. PB_USER_AGENT=${PB_USER_AGENT:="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"}
  590. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  591. # Actions based on env
  592. [ -n "$ARG" ] || printf_exit "There was no input recieved"
  593. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  594. # begin main app
  595. __execute_pb "$1"
  596. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  597. # Set exit code
  598. exitCode="${exitCode:-$?}"
  599. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  600. # End application
  601. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  602. # lets exit with code
  603. exit ${exitCode:-$?}
  604. # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  605. # end
  606.  

Reply to "New Paste"

Here you can reply to the paste above

captcha