2020-04-07 00:44:57 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# pstsrv
|
2023-06-19 17:56:43 +02:00
|
|
|
# Written in 2020-2021,2023 by Lucas
|
2020-04-07 00:44:57 +02:00
|
|
|
# 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
|
|
|
|
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
2023-06-19 17:56:43 +02:00
|
|
|
printf "Usage: %s [-x proxy] service file [file ...]\n" "${0##*/}" >&2
|
2020-04-07 00:44:57 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
err()
|
|
|
|
{
|
|
|
|
printf "%s: %s\n" "${0##*/}" "$*" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
check_runtime()
|
2020-04-07 00:44:57 +02:00
|
|
|
{
|
2023-06-19 17:56:43 +02:00
|
|
|
_s=
|
|
|
|
|
|
|
|
for _prog; do
|
|
|
|
command -v "$_prog" >/dev/null 2>&1 || _s=${_s:+"$_s "}$_prog
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$_s" ]; then
|
|
|
|
err "missing required programs: $_s"
|
2020-04-07 00:44:57 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
_curl()
|
2020-04-07 00:44:57 +02:00
|
|
|
{
|
2023-06-19 17:56:43 +02:00
|
|
|
curl ${proxy:+-x "$proxy"} -Ss
|
2020-04-07 00:44:57 +02:00
|
|
|
}
|
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
impl_catbox_moe()
|
2020-04-07 00:44:57 +02:00
|
|
|
{
|
2023-06-19 17:56:43 +02:00
|
|
|
check_runtime curl
|
|
|
|
|
|
|
|
_curl -F "reqtype=fileupload" -F "fileToUpload=@$1" \
|
2020-04-07 00:44:57 +02:00
|
|
|
https://catbox.moe/user/api.php
|
|
|
|
}
|
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
impl_pst_moe()
|
2020-04-07 00:44:57 +02:00
|
|
|
{
|
2023-06-19 17:56:43 +02:00
|
|
|
check_runtime curl
|
2020-04-07 00:44:57 +02:00
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
_curl -F "content=<$1" -F "expire_after=86400" https://pst.moe/paste
|
2020-08-01 22:27:19 +02:00
|
|
|
}
|
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
impl_uguu()
|
2020-04-07 00:44:57 +02:00
|
|
|
{
|
2023-06-19 17:56:43 +02:00
|
|
|
check_runtime curl jq
|
2020-04-07 00:44:57 +02:00
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
_jq_prog='
|
|
|
|
if .success then
|
|
|
|
(.files[] | [.url, .name] | @tsv)
|
|
|
|
else
|
|
|
|
"Error \(.errorcode): \(.description)"
|
|
|
|
end
|
|
|
|
'
|
|
|
|
|
|
|
|
for _f; do
|
|
|
|
shift
|
|
|
|
set -- "$@" -F "files[]=@$_f"
|
|
|
|
done
|
|
|
|
_curl "$@" "https://$uguu_host/upload.php" | jq -r "$_jq_prog"
|
2020-04-07 00:44:57 +02:00
|
|
|
}
|
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
proxy=
|
|
|
|
while getopts x: flag; do
|
2020-04-07 00:44:57 +02:00
|
|
|
case $flag in
|
2023-06-19 17:56:43 +02:00
|
|
|
x) proxy=$OPTARG ;;
|
2020-04-07 00:44:57 +02:00
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
|
|
|
|
2023-06-19 17:56:43 +02:00
|
|
|
if [ $# -lt 2 ]; then
|
2020-04-07 00:44:57 +02:00
|
|
|
usage
|
|
|
|
fi
|
|
|
|
srv=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
case $srv in
|
|
|
|
catbox.moe)
|
2023-06-19 17:56:43 +02:00
|
|
|
impl=impl_catbox_moe
|
2020-04-07 00:44:57 +02:00
|
|
|
;;
|
2021-12-03 14:53:52 +01:00
|
|
|
pst.moe)
|
2023-06-19 17:56:43 +02:00
|
|
|
impl=impl_pst_moe
|
|
|
|
;;
|
|
|
|
uguu.se|cockfile.com)
|
|
|
|
impl=impl_uguu uguu_host=$srv
|
2020-08-01 22:27:19 +02:00
|
|
|
;;
|
2020-04-07 00:44:57 +02:00
|
|
|
*)
|
2020-05-03 16:47:27 +02:00
|
|
|
err "unknown service $srv"
|
2020-04-07 00:44:57 +02:00
|
|
|
;;
|
|
|
|
esac
|
2023-06-19 17:56:43 +02:00
|
|
|
$impl "$@"
|