split upload with moar features

This commit is contained in:
Ville Rantanen
2018-03-15 22:29:07 +02:00
parent 61d872fa17
commit acb366120d
5 changed files with 196 additions and 127 deletions

32
code/templates/upload.sh Normal file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
test -n "$1" || {
echo "Add files to upload as argument"
exit 1
}
CAT=$( which cat )
which pv &> /dev/null && CAT=$( which pv )
ROOTURL="{{ rooturl }}"
SHARE="{{ name }}"
TOKEN="{{ token }}"
send_file() {
$CAT "$file_name" | curl -F "file=@-;filename=${base_name}" ${ROOTURL}upload/${SHARE}/${TOKEN}
}
send_folder() {
which pv &> /dev/null && printf -v dusize -- "--size %dk" $( du -s -k "$file_name" | cut -f1 )
tar cz "$file_name" | $CAT $dusize - | curl -F "file=@-;filename=${base_name}.tgz" ${ROOTURL}upload/${SHARE}/${TOKEN}
}
for file_name in "$@"; do
base_name=$( basename "$file_name" )
test -f "$file_name" && {
printf "Sending file: %s\n" "$file_name"
send_file
continue
}
test -d "$file_name" && {
printf "Sending folder: %s\n" "$file_name"
send_folder
continue
}
done