Initial implementation
This commit is contained in:
49
upload.sh
Executable file
49
upload.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
# ask password, upload file to https://%%UPLOADHOST%%/upload.php?password=<given password>
|
||||
|
||||
# function to upload file with password
|
||||
upload() {
|
||||
# $1 is file
|
||||
# $2 is password
|
||||
echo "Uploading $1"
|
||||
curl -F "file=@$1" https://%%UPLOADHOST%%/upload.php?password=$2
|
||||
# if failed exit
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Upload $1 failed"
|
||||
exit 1
|
||||
fi
|
||||
echo "Upload $1 done"
|
||||
}
|
||||
|
||||
# verify argument is existing file
|
||||
if [ ! -f "$1" ]; then
|
||||
echo "File not found: $1"
|
||||
exit 1
|
||||
fi
|
||||
# ask password
|
||||
read -s -p "Password: " password
|
||||
|
||||
# If file larger than 5M then split it to pieces and make extension .split
|
||||
if [ $(stat -c%s "$1") -gt 1500000 ]; then
|
||||
# retrieve sha512 hash of file to variable sum
|
||||
sum=$(sha512sum "$1" | cut -d' ' -f1)
|
||||
split -b 1500000 "$1" "$1".split
|
||||
#rm "$1"
|
||||
echo "File too large, split to pieces"
|
||||
# touch final file that has ending .split.final
|
||||
touch "$1".split.final
|
||||
# Now upload them all same way as other files
|
||||
for file in "$1".split*; do
|
||||
upload $file $password
|
||||
done
|
||||
# Upload final file
|
||||
# upload "$1.split.final" $password
|
||||
# Delete all generated files
|
||||
rm "$1".split*
|
||||
# show hash of file
|
||||
echo "sha512sum of file: $sum"
|
||||
else
|
||||
upload $1 $password
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user