Update 2024-12-23 15:26 OpenBSD/amd64-t14

This commit is contained in:
c0dev0id 2024-12-23 15:26:32 +01:00
parent ae5183fa58
commit 70c63ad427

View File

@ -8,35 +8,44 @@ do
txt) _ext=".txt" ;;
log) _ext=".log" ;;
rm) _rm=1 ;;
rmlast) _rmlast=1 ;;
ls) _ls=1 ;;
-[0-9]?) _last="$arg" ;;
mv) _mv=1 ;;
mvlast) _mvlast=1 ;;
*) break; ;;
esac
shift;
done
if [ ! -z "$_rm" ]
then
for file in "$@"
do
ssh sdk@codevoid.de \
"cd /home/www/htdocs/ptrace/paste/ \
&& rm -v $(basename "$file")" \
|| true
done
exit 0
fi
if [ ! -z "$_ls" ]
then
upload_list() {
ssh sdk@codevoid.de \
"cd /home/www/htdocs/ptrace/paste/ \
&& ls -1tr \
| xargs -n1 -I{} echo \"https://ptrace.org/{} ({})\""
&& ls -1tr"
}
if [ -n "$_ls" ]
then
upload_list \
| while read f
do
echo "https://ptrace.org/$(echo "$f" | sed 's/ /%20/g') ($f)"
done
exit 0
fi
if [ ! -z "$_mv" ]
if [ -n "$_last" ]
then
upload_list \
| tail $_last \
| while read f
do
echo "https://ptrace.org/$(echo "$f" | sed 's/ /%20/g') ($f)"
done
exit 0
fi
if [ -n "$_mv" ]
then
ssh sdk@codevoid.de \
"cd /home/www/htdocs/ptrace/paste/ \
@ -44,17 +53,66 @@ then
exit 0
fi
if [ ! -z "$@" ]
if [ -n "$_mvlast" ]
then
lastfile="$(upload_list | tail -1)"
ssh sdk@codevoid.de \
"cd /home/www/htdocs/ptrace/paste/ \
&& mv -v \"$lastfile\" \"$2\""
exit 0
fi
if [ -n "$_rm" ]
then
for file in "$@"
do
ssh sdk@codevoid.de \
"cd /home/www/htdocs/ptrace/paste/ \
&& rm -v \"$(basename "$file")\"" \
|| true
done
exit 0
fi
if [ -n "$_rmlast" ]
then
lastfile="$(upload_list | tail -1)"
ssh sdk@codevoid.de \
"cd /home/www/htdocs/ptrace/paste/ \
&& rm -v \"$lastfile\"" \
|| true
exit 0
fi
echo $#
if [ $# -gt 0 ]
then
for file in "$@"
do
[ ! -f "$file" ] \
&& echo "file not found: $file" \
&& exit 1
# make sure the file is least owner rw and group r
# the sticky bit in the destiation folder will assign user+group
chmod u+rw,g+r "$file"
scp "$file" "sdk@codevoid.de:/home/www/htdocs/ptrace/paste/${file}${_ext}"
echo "https://ptrace.org/$(basename "$file")" \
echo "https://ptrace.org/$(basename "$file")${_ext}" \
| sed 's/ /%20/g' \
| xclip -f -r
echo
done
fi
if [ $# -eq 0 ]
then
echo "usage: upload [command] [<files>]"
echo " commands:"
echo " rm <files> - remove files"
echo " rmlast - remove last upload"
echo " ls - list files"
echo " -0..N - list N last uploads"
echo " mv <oldname> <newname> - rename file"
echo " <files> - upload files"
exit 2
fi