Update 2024-12-23 17:32 OpenBSD/amd64-t14

This commit is contained in:
c0dev0id 2024-12-23 17:32:40 +01:00
parent b2c7bcd12a
commit ac58f6baa9

View File

@ -37,6 +37,24 @@ remote_list() {
&& ls -1tr" && ls -1tr"
} }
copy_and_print() {
echo "$_weburi/$(basename "$1")" \
| sed 's/ /%20/g' \
| xclip -f -r
echo
}
# handle stdin
if [[ ! -t 0 ]]
then
fname="$1"
[ -z "$fname" ] \
&& fname="$(date +"%Y-%m-%d_%H%M%S").txt"
cat - | ssh $_sshhost "cat - > \"$_rpath/$fname\""
copy_and_print "$fname"
exit 0
fi
if [ -n "$_ls" ] if [ -n "$_ls" ]
then then
remote_list \ remote_list \
@ -97,75 +115,92 @@ then
exit 0 exit 0
fi fi
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 item in "$@"
do do
[ ! -e "$file" ] \ # the whole handling shall run in a subshell so all variables
&& echo "File or directory not found: $file" \ # are reset when we leave the scope
# note, that this requires us to return, instead fo continue
# to leave the loop iteration
(
[ ! -e "$item" ] \
&& echo "File or directory not found: $item" \
&& exit 1 && exit 1
# target filename
file="$(basename "$item")$_ext"
# handle file (plain), no archive mode # handle file (plain), no archive mode
if [ -f "$file" ] && [ -z "$_tgz" ] && [ -z "$_gz" ] if [ -f "$item" ] && [ -z "$_tgz" ] && [ -z "$_gz" ]
then then
# make sure the file is least owner rw and group r # make sure the file is least owner rw and group r
# the sticky bit in the destiation folder will assign user+group # the sticky bit in the destiation folder will assign user+group
chmod u+rw,g+r "$file" chmod u+rw,g+r "$item"
echo "Uploading $file" echo "Uploading $item as $file"
scp -q "$file" "$_sshhost:$_rpath/${file}${_ext}" scp -q "$item" "$_sshhost:\"$_rpath/$file\""
copy_and_print "${file}${_ext}" copy_and_print "$file"
continue return
fi fi
# directories can only be handled as tgz archive # directories can only be handled as tgz archive
[ -d "$file" ] && _tgz=1 [ -d "$item" ] && _tgz=1
# handle file or directory (tgz mode) # handle file or directory (tgz mode)
if [ -n "$_tgz" ] if [ -n "$_tgz" ]
then then
echo "Uploading $file as ${file}${_ext}" file="$file.tgz"
_ext="$_ext.tgz" echo "Uploading $item as $file"
tar czf - "$file" \ # moving closer to the item to not archive the whole path
| ssh $_sshhost "pv - > $_rpath/${file}${_ext}" cd $(dirname "$item")
copy_and_print "${file}${_ext}" tar czf - "$(basename "$item")" \
continue | ssh $_sshhost "pv - > \"$_rpath/$file\""
copy_and_print "$file"
return
fi fi
# handle file (gz mode) # handle file (gz mode)
if [ -f "$file" ] && [ -n "$_gz" ] if [ -f "$item" ] && [ -n "$_gz" ]
then then
echo "Uploading $file as ${file}${_ext}" file="$file.gz"
_ext="$_ext.gz" echo "Uploading \"$item\" as \"$file\""
cat "$file" gzip -o - "$file" \ cat "$item" | gzip \
| $_sshhost "pv - > $_rpath/${file}${_ext}" | ssh $_sshhost "pv - > \"$_rpath/$file\""
copy_and_print "${file}${_ext}" copy_and_print "$file"
continue return
fi fi
# hopefully never reached # hopefully never reached
echo "Unhandled situation for: $file" echo "Unhandled situation for: $item"
) # leave scope & reset variables
done done
fi fi
if [ $# -eq 0 ] if [ $# -eq 0 ]
then then
echo "usage: upload [command] [ext] [<files>]" echo "usage: upload [command] [ext] [<files>]"
echo " commands:" echo " upload [filename] < file"
echo " cat file | upload [filename]"
echo
echo " <files> - files or directories to upload"
echo
echo " Commands:"
echo " rm <files> - remove files" echo " rm <files> - remove files"
echo " rml - 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 " ren <oldname> <newname> - rename file" echo " ren <oldname> <newname> - rename file"
echo " renl <newname> - rename last uploaded file" echo " renl <newname> - rename last uploaded file"
echo " extensions:" echo
echo " Extensions:"
echo " sh, ksh, txt, log - add extension to file" echo " sh, ksh, txt, log - add extension to file"
echo " <files> - upload files" echo
echo "Special Case:"
echo " When data is piped to the script it expects only one"
echo " optional argument, which would be the target filename."
echo
exit 2 exit 2
fi fi