split upload with moar features
This commit is contained in:
32
code/templates/upload.sh
Normal file
32
code/templates/upload.sh
Normal 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
|
||||
Reference in New Issue
Block a user