From 2395ee7cbdc3dd6724e5a71fab943a02a69bc53a Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 6 Apr 2020 22:44:57 +0000 Subject: [PATCH] Add pstsrv for centralizing different paste services --- bin/Makefile | 2 +- bin/pstsrv.sh | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 bin/pstsrv.sh diff --git a/bin/Makefile b/bin/Makefile index bcd7ff7..41e826e 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -15,7 +15,7 @@ PREFIX = $(HOME) MANPREFIX = $(PREFIX)/local BIN = ZZZ browser credentials fetch flac2ogg imgresize invidious \ - riot-web-ui rfcopen screenshot sekrit tor-browser \ + pstsrv riot-web-ui rfcopen screenshot sekrit tor-browser \ w3m-copy-link MAN1 = sekrit.1 diff --git a/bin/pstsrv.sh b/bin/pstsrv.sh new file mode 100644 index 0000000..0ce5795 --- /dev/null +++ b/bin/pstsrv.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# pstsrv +# Written in 2020 by Lucas +# CC0 1.0 Universal/Public domain - No rights reserved +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. You should have received a copy of the CC0 Public Domain +# Dedication along with this software. If not, see +# . + +usage() +{ + printf "Usage: %s [-T] service [files...]\n" "${0##*/}" >&2 + exit 1 +} + +err() +{ + printf "%s: %s\n" "${0##*/}" "$*" >&2 + exit 1 +} + +check_prog() +{ + if ! command -v "$1" >/dev/null 2>&1; then + printf "%s: Missing required program \"%s\"\n" \ + "${0##*/}" "$1" >&2 + return 1 + fi + return 0 +} + +check_runtime() +{ + rc=0 + for prog; do + check_prog "$prog" || rc=1 + done + return $rc +} + +pst_catbox_moe() +{ + $torsocks curl -F "reqtype=fileupload" -F "fileToUpload=@$1" \ + https://catbox.moe/user/api.php +} + +pst_ix_io() +{ + $torsocks curl -F "f:1=@$1" http://ix.io/ +} + +do_upload() +{ + uploader=$1 + shift + + rc=0 + if [ $# -eq 0 ]; then + $uploader - || rc=1 + else + for arg; do + $upload "$arg" || rc=1 + done + fi + + return $rc +} + +torsocks=torsocks +while getopts T flag; do + case $flag in + T) torsocks= ;; + *) usage ;; + esac +done +shift $((OPTIND - 1)) + +if [ $# -eq 0 ]; then + usage +fi +srv=$1 +shift + +check_runtime curl $torsocks + +[ $# -eq 0 ] && set -- - +case $srv in +catbox.moe) + do_upload pst_catbox_moe "$@" + ;; +ix.io) + do_upload pst_ix_io "$@" + ;; +*) + err "Unknown service \"$srv\"" + ;; +esac