Update 2024-12-23 16:36 OpenBSD/amd64-t14
This commit is contained in:
parent
70c63ad427
commit
e2edc9d2b6
129
.bin/upload
129
.bin/upload
@ -1,5 +1,15 @@
|
|||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# manage files in a webroot
|
||||||
|
# needs: sh (cp,rm), openssh (ssh,scp), gzip, tar, sed, tail, xclip
|
||||||
|
|
||||||
|
# remote patch uploaded files should go
|
||||||
|
_rpath="/home/www/htdocs/ptrace/paste"
|
||||||
|
# web url where the uploaded files can be accessed
|
||||||
|
_weburi="https://ptrace.org"
|
||||||
|
# ssh user@host
|
||||||
|
_sshhost="sdk@codevoid.de"
|
||||||
|
|
||||||
for arg in "$@"
|
for arg in "$@"
|
||||||
do
|
do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
@ -7,57 +17,60 @@ do
|
|||||||
ksh) _ext=".ksh" ;;
|
ksh) _ext=".ksh" ;;
|
||||||
txt) _ext=".txt" ;;
|
txt) _ext=".txt" ;;
|
||||||
log) _ext=".log" ;;
|
log) _ext=".log" ;;
|
||||||
|
gz) _gz=1 ;;
|
||||||
|
tgz) _tgz=1 ;;
|
||||||
rm) _rm=1 ;;
|
rm) _rm=1 ;;
|
||||||
rmlast) _rmlast=1 ;;
|
rml) _rmlast=1 ;;
|
||||||
ls) _ls=1 ;;
|
ls) _ls=1 ;;
|
||||||
-[0-9]?) _last="$arg" ;;
|
l|last) _last="-1" ;;
|
||||||
mv) _mv=1 ;;
|
-[0-9]*) _last="$arg" ;;
|
||||||
mvlast) _mvlast=1 ;;
|
ren|mv) _mv=1 ;;
|
||||||
|
renl|mvl) _mvlast=1 ;;
|
||||||
*) break; ;;
|
*) break; ;;
|
||||||
esac
|
esac
|
||||||
shift;
|
shift;
|
||||||
done
|
done
|
||||||
|
|
||||||
upload_list() {
|
remote_list() {
|
||||||
ssh sdk@codevoid.de \
|
ssh $_sshhost \
|
||||||
"cd /home/www/htdocs/ptrace/paste/ \
|
"cd $_rpath/ \
|
||||||
&& ls -1tr"
|
&& ls -1tr"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -n "$_ls" ]
|
if [ -n "$_ls" ]
|
||||||
then
|
then
|
||||||
upload_list \
|
remote_list \
|
||||||
| while read f
|
| while read f
|
||||||
do
|
do
|
||||||
echo "https://ptrace.org/$(echo "$f" | sed 's/ /%20/g') ($f)"
|
echo "$_weburi/$(echo "$f" | sed 's/ /%20/g') ($f)"
|
||||||
done
|
done
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$_last" ]
|
if [ -n "$_last" ]
|
||||||
then
|
then
|
||||||
upload_list \
|
remote_list \
|
||||||
| tail $_last \
|
| tail $_last \
|
||||||
| while read f
|
| while read f
|
||||||
do
|
do
|
||||||
echo "https://ptrace.org/$(echo "$f" | sed 's/ /%20/g') ($f)"
|
echo "$_weburi/$(echo "$f" | sed 's/ /%20/g') ($f)"
|
||||||
done
|
done
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$_mv" ]
|
if [ -n "$_mv" ]
|
||||||
then
|
then
|
||||||
ssh sdk@codevoid.de \
|
ssh $_sshhost \
|
||||||
"cd /home/www/htdocs/ptrace/paste/ \
|
"cd $_rpath/ \
|
||||||
&& mv -v \"$1\" \"$2\""
|
&& mv -v \"$1\" \"$2\""
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$_mvlast" ]
|
if [ -n "$_mvlast" ]
|
||||||
then
|
then
|
||||||
lastfile="$(upload_list | tail -1)"
|
lastfile="$(remote_list | tail -1)"
|
||||||
ssh sdk@codevoid.de \
|
ssh $_sshhost \
|
||||||
"cd /home/www/htdocs/ptrace/paste/ \
|
"cd $_rpath/ \
|
||||||
&& mv -v \"$lastfile\" \"$2\""
|
&& mv -v \"$lastfile\" \"$2\""
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@ -66,8 +79,8 @@ if [ -n "$_rm" ]
|
|||||||
then
|
then
|
||||||
for file in "$@"
|
for file in "$@"
|
||||||
do
|
do
|
||||||
ssh sdk@codevoid.de \
|
ssh $_sshhost \
|
||||||
"cd /home/www/htdocs/ptrace/paste/ \
|
"cd $_rpath/ \
|
||||||
&& rm -v \"$(basename "$file")\"" \
|
&& rm -v \"$(basename "$file")\"" \
|
||||||
|| true
|
|| true
|
||||||
done
|
done
|
||||||
@ -76,43 +89,81 @@ fi
|
|||||||
|
|
||||||
if [ -n "$_rmlast" ]
|
if [ -n "$_rmlast" ]
|
||||||
then
|
then
|
||||||
lastfile="$(upload_list | tail -1)"
|
lastfile="$(remote_list | tail -1)"
|
||||||
ssh sdk@codevoid.de \
|
ssh $_sshhost \
|
||||||
"cd /home/www/htdocs/ptrace/paste/ \
|
"cd $_rpath/ \
|
||||||
&& rm -v \"$lastfile\"" \
|
&& rm -v \"$lastfile\"" \
|
||||||
|| true
|
|| true
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $#
|
copy_and_print() {
|
||||||
|
echo "$_weburi/$(basename "$1")" \
|
||||||
|
| sed 's/ /%20/g' \
|
||||||
|
| xclip -f -r
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
if [ $# -gt 0 ]
|
if [ $# -gt 0 ]
|
||||||
then
|
then
|
||||||
for file in "$@"
|
for file in "$@"
|
||||||
do
|
do
|
||||||
[ ! -f "$file" ] \
|
[ ! -e "$file" ] \
|
||||||
&& echo "file not found: $file" \
|
&& echo "File or directory not found: $file" \
|
||||||
&& exit 1
|
&& exit 1
|
||||||
# make sure the file is least owner rw and group r
|
|
||||||
# the sticky bit in the destiation folder will assign user+group
|
# handle file (plain), no archive mode
|
||||||
chmod u+rw,g+r "$file"
|
if [ -f "$file" ] && [ -z "$_tgz" ] && [ -z "$_gz" ]
|
||||||
scp "$file" "sdk@codevoid.de:/home/www/htdocs/ptrace/paste/${file}${_ext}"
|
then
|
||||||
echo "https://ptrace.org/$(basename "$file")${_ext}" \
|
# make sure the file is least owner rw and group r
|
||||||
| sed 's/ /%20/g' \
|
# the sticky bit in the destiation folder will assign user+group
|
||||||
| xclip -f -r
|
chmod u+rw,g+r "$file"
|
||||||
echo
|
echo "Uploading $file"
|
||||||
|
scp -q "$file" "$_sshhost:$_rpath/${file}${_ext}"
|
||||||
|
copy_and_print "${file}${_ext}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# directories can only be handled as tgz archive
|
||||||
|
[ -d "$file" ] && _tgz=1
|
||||||
|
|
||||||
|
# handle file or directory (tgz mode)
|
||||||
|
if [ -n "$_tgz" ]
|
||||||
|
then
|
||||||
|
echo "Uploading $file as ${file}${_ext}"
|
||||||
|
_ext="$_ext.tgz"
|
||||||
|
tar czf - "$file" | ssh $_sshhost "pv - > $_rpath/${file}${_ext}"
|
||||||
|
copy_and_print "${file}${_ext}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# handle file (gz mode)
|
||||||
|
if [ -f "$file" ] && [ -n "$_gz" ]
|
||||||
|
then
|
||||||
|
echo "Uploading $file as ${file}${_ext}"
|
||||||
|
_ext="$_ext.gz"
|
||||||
|
cat "$file" gzip -o - "$file" | $_sshhost "pv - > $_rpath/${file}${_ext}"
|
||||||
|
copy_and_print "${file}${_ext}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# hopefully never reached
|
||||||
|
echo "Unhandled situation for: $file"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
then
|
then
|
||||||
echo "usage: upload [command] [<files>]"
|
echo "usage: upload [command] [ext] [<files>]"
|
||||||
echo " commands:"
|
echo " commands:"
|
||||||
echo " rm <files> - remove files"
|
echo " rm <files> - remove files"
|
||||||
echo " rmlast - remove last upload"
|
echo " rml - remove last upload"
|
||||||
echo " ls - list files"
|
echo " ls - list files"
|
||||||
echo " -0..N - list N last uploads"
|
echo " -0..N - list N last uploads"
|
||||||
echo " mv <oldname> <newname> - rename file"
|
echo " ren <oldname> <newname> - rename file"
|
||||||
echo " <files> - upload files"
|
echo " renl <newname> - rename last uploaded file"
|
||||||
|
echo " extensions:"
|
||||||
|
echo " sh, ksh, txt, log - add extension to file"
|
||||||
|
echo " <files> - upload files"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user