Skip to content

Commit

Permalink
Implement --dry-run option, calculating the hashes locally
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Leclanche committed Jan 12, 2014
1 parent 8a0e128 commit e9e31ef
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions mediacrush
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

version=1.0.1
server="https://mediacru.sh"
recursive=false
create_album=false
dry_run=false
recursive=false
uploads=""

usage() {
Expand All @@ -17,6 +18,7 @@ For more details see man mediacrush
-a, --album Create an album from the uploaded files
--open Open the uploaded images (or the album if there is one) in the browser
after upload has completed
--dry-run Do not upload, only display the urls the files would be uploaded to.
-r, --recursive Recursively upload directories
-s, --server=SERVER Specify a different server to upload to (default: https://mediacru.sh)
-h, --help Display this help and exit
Expand All @@ -34,7 +36,7 @@ if [[ $# -eq 0 ]]; then
exit 1
fi

GETOPT=`getopt -o hars: --longoptions help,version,album,open,recursive,server: -- "$@"`
GETOPT=`getopt -o hars: --longoptions help,version,album,dry-run,open,recursive,server: -- "$@"`
if [[ $? != 0 ]]; then
exit 1
fi
Expand All @@ -51,22 +53,26 @@ while true; do
echo $(basename $0) $version
exit
;;
-r|--recursive)
recursive=true
shift 1
;;
-s|--server)
server="$2"
shift 2
;;
-a|--album)
create_album=true
shift 1
;;
--dry-run)
dry_run=true
shift 1
;;
--open)
open_files=true
shift 1
;;
-r|--recursive)
recursive=true
shift 1
;;
-s|--server)
server="$2"
shift 2
;;
--)
shift
break
Expand All @@ -78,6 +84,10 @@ while true; do
esac
done

calculate_hash() {
md5sum $1 | xxd -r -p | base64 | cut -d " " -f 1 | sed "s|+|-|" | sed "s|/|_|" | cut -c 1-12
}

upload() {
for f in "$@"; do

Expand All @@ -91,6 +101,13 @@ upload() {
fi

echo -n "Uploading $f ..."

if [[ $dry_run == true ]]; then
hash=$(calculate_hash $f)
echo -e "\r\033[KUploaded: $server/$hash"
continue
fi

url="$server/api/upload/file"
out=$(curl --silent -F "file=@$f" "$url")

Expand Down

0 comments on commit e9e31ef

Please sign in to comment.