2020-11-20 07:36:48 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
#
|
2021-02-17 10:47:51 +00:00
|
|
|
# pasta: simple ssh-based paste bin (client)
|
2020-11-20 07:36:48 +00:00
|
|
|
# author: Hiltjo Posthuma <hiltjo@codemass.org>, Dylan Lom <djl@dylanlom.com>
|
|
|
|
# see-also: https://codemadness.org/paste-service.html
|
|
|
|
|
2021-02-17 10:47:51 +00:00
|
|
|
sshdomain="djl@p.dlom.cc"
|
|
|
|
destpath="/usr/local/www/p.dlom.cc"
|
|
|
|
destdomain="http://p.dlom.cc"
|
|
|
|
|
2020-11-20 07:36:48 +00:00
|
|
|
argv0="$0"
|
|
|
|
|
|
|
|
usage() {
|
2021-03-01 05:19:56 +00:00
|
|
|
echo "usage: $argv0 [-p|-c|-g] [-x] filename"
|
2020-11-20 07:36:48 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-02-17 10:47:51 +00:00
|
|
|
while [ "$#" -gt 1 ]; do
|
|
|
|
case "$1" in
|
|
|
|
'-p') png='true'; ;;
|
|
|
|
'-c') concat='true'; ;;
|
2021-03-01 05:19:56 +00:00
|
|
|
'-g') get='true'; ;;
|
|
|
|
'-x') xclip='true'; ;;
|
2021-02-17 10:47:51 +00:00
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
name="$1"
|
|
|
|
[ -z "$name" ] && usage
|
|
|
|
|
2021-03-01 05:19:56 +00:00
|
|
|
if truthy "$xclip"; then
|
|
|
|
command -v xclip > /dev/null \
|
|
|
|
|| (echo "ERROR: xclip not found" && exit 1) \
|
|
|
|
&& (echo "$destdomain/$name" | \
|
|
|
|
tr -d '\n' | \
|
|
|
|
xclip -selection clipboard)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if truthy "$get"; then
|
|
|
|
curl "$destdomain/$name"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-02-23 06:49:52 +00:00
|
|
|
if truthy "$concat"; then
|
|
|
|
ssh "$sshdomain" "cat >> $destpath/$name"
|
2021-02-17 10:47:51 +00:00
|
|
|
else
|
2021-02-23 06:49:52 +00:00
|
|
|
(truthy "$png" && import png:- || cat) | \
|
|
|
|
ssh "$sshdomain" "cat > $destpath/$name"
|
2021-02-17 10:47:51 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$destdomain/$name"
|
2020-11-20 07:36:48 +00:00
|
|
|
|