imgur_upload.sh: customize output when no images of failed tests are available

This commit is contained in:
Gautier Pelloux-Prayer 2015-05-29 16:20:25 +02:00
parent 79a297d1a9
commit c6960034f3

View file

@ -1,39 +1,39 @@
#!/usr/bin/env bash
#!/bin/bash -x
# Install underscore-cli for hacking
if ! which underscore &> /dev/null; then
npm install -g underscore-cli
npm install -g underscore-cli
fi
cd Screens
# Prepare location to collect delete commands
if test "$TRAVIS_BUILD_NUMBER" = ""; then
TRAVIS_BUILD_NUMBER="dev"
fi
output_dir="Screens"
download_cmds=""
if "*.png" 2>/dev/null; then
# Prepare location to collect delete commands
if test "$TRAVIS_BUILD_NUMBER" = ""; then
TRAVIS_BUILD_NUMBER="dev"
fi
output_dir="Screens"
download_cmds=""
# curl from http://imgur.com/tools/imgurbash.sh via http://imgur.com/tools
# Documentation: http://code.google.com/p/imgur-api/source/browse/wiki/ImageUploading.wiki?r=82
api_key=$IMGUR_KEY
oIFS=$IFS
IFS=$'\n'
for filepath in $(find . -name '*.png'); do
# echo "File $filepath"
# echo "Command: curl https://api.imgur.com/3/upload.json -H \"Authorization: Client-ID $api_key\" -F "image=@\"$filepath\"""
result="$(curl https://api.imgur.com/3/upload.json -H "Authorization: Client-ID $api_key" -F "image=@\"$filepath\"" )"
# result='{"rsp":{"stat":"ok","image":{"image_hash":"dKZ0YK9","delete_hash":"r0MsZp11K9vawLf","original_image":"http:\/\/i.imgur.com\/dKZ0YK9.png","large_thumbnail":"http:\/\/i.imgur.com\/dKZ0YK9l.jpg","small_thumbnail":"http:\/\/i.imgur.com\/dKZ0YK9s.jpg","imgur_page":"http:\/\/imgur.com\/dKZ0YK9","delete_page":"http:\/\/imgur.com\/delete\/r0MsZp11K9vawLf"}}}'
lol="$(echo $result | underscore extract success)"
if test $lol != "true"; then
echo "There was a problem uploading \"$filepath\"" 1>&2
echo "$result" 1>&2
else
download_cmds="${download_cmds}wget $(echo "$result" | underscore extract 'data.link')\n"
fi
done
IFS=$oIFS
echo "All uploads complete!"
echo ""
echo "Download via:"
echo -e " $download_cmds"
# curl from http://imgur.com/tools/imgurbash.sh via http://imgur.com/tools
# Documentation: http://code.google.com/p/imgur-api/source/browse/wiki/ImageUploading.wiki?r=82
api_key=$IMGUR_KEY
for filepath in *.png; do
# echo "File $filepath"
# echo "Command: curl https://api.imgur.com/3/upload.json -H \"Authorization: Client-ID $api_key\" -F "image=@\"$filepath\"""
result="$(curl https://api.imgur.com/3/upload.json -H "Authorization: Client-ID $api_key" -F "image=@\"$filepath\"" )"
# result='{"rsp":{"stat":"ok","image":{"image_hash":"dKZ0YK9","delete_hash":"r0MsZp11K9vawLf","original_image":"http:\/\/i.imgur.com\/dKZ0YK9.png","large_thumbnail":"http:\/\/i.imgur.com\/dKZ0YK9l.jpg","small_thumbnail":"http:\/\/i.imgur.com\/dKZ0YK9s.jpg","imgur_page":"http:\/\/imgur.com\/dKZ0YK9","delete_page":"http:\/\/imgur.com\/delete\/r0MsZp11K9vawLf"}}}'
succeeded="$(echo $result | underscore extract success)"
if [ "$succeeded" != "true" ]; then
echo "There was a problem uploading \"$filepath\": $result"
else
download_cmds="${download_cmds}wget $(echo "$result" | underscore extract 'data.link')\n"
fi
done
echo "All uploads complete!"
echo ""
echo "Download via: $download_cmds"
else
echo "Could not find any PNG in $PWD, something must be broken!"
fi