From 70c63ad4279ed1ab15ce6a89231b0ddacde796ab Mon Sep 17 00:00:00 2001 From: c0dev0id Date: Mon, 23 Dec 2024 15:26:32 +0100 Subject: [PATCH] Update 2024-12-23 15:26 OpenBSD/amd64-t14 --- .bin/upload | 96 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 19 deletions(-) diff --git a/.bin/upload b/.bin/upload index 7eddd18..a6a2df3 100755 --- a/.bin/upload +++ b/.bin/upload @@ -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] []" + echo " commands:" + echo " rm - remove files" + echo " rmlast - remove last upload" + echo " ls - list files" + echo " -0..N - list N last uploads" + echo " mv - rename file" + echo " - upload files" + exit 2 +fi