From 1c8e4dff47b6f9dc51df3bf9d4ce3c1d122e7913 Mon Sep 17 00:00:00 2001 From: Sergio Brighenti Date: Tue, 20 Oct 2020 19:28:22 +0200 Subject: [PATCH] Updated bash script --- .../scripts/xbackbone_uploader.sh.twig | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/resources/templates/scripts/xbackbone_uploader.sh.twig b/resources/templates/scripts/xbackbone_uploader.sh.twig index 17bf065..19ac0f5 100755 --- a/resources/templates/scripts/xbackbone_uploader.sh.twig +++ b/resources/templates/scripts/xbackbone_uploader.sh.twig @@ -30,37 +30,29 @@ EOF upload() { RESPONSE="$(curl -s -F "token={{ token }}" -F "upload=@${1}" {{ upload_url }})"; - - if jq -e . >/dev/null 2>&1 <<<"$RESPONSE"; then - # Response is JSON - echo "Upload Completed."; - else - if [ "${DESKTOP_SESSION}" != "" ]; then - notify-send "Error: Uploading returned unexpected response" "Response: ${RESPONSE}"; - else - echo "Error: Uploading returned unexpected response: ${RESPONSE}" - fi - exit 1; - fi if [[ "$(echo "${RESPONSE}" | jq -r '.message')" == "OK" ]]; then URL="$(echo "${RESPONSE}" | jq -r '.url')"; if [ "${DESKTOP_SESSION}" != "" ]; then echo "${URL}" | xclip -selection c; notify-send "Upload completed!" "${URL}"; - exit 0; else echo "${URL}"; - exit 0; fi + exit 0; else - if [ "${DESKTOP_SESSION}" != "" ]; then - notify-send "Error!" "$(echo "${RESPONSE}" | jq -r '.message')"; - exit 1; - else - echo "Error! $(echo "${RESPONSE}" | jq -r '.message')"; - exit 1; + MESSAGE="$(echo "${RESPONSE}" | jq -r '.message')"; + if [ $? -ne 0 ]; then + echo "Unexpected response:"; + echo "${RESPONSE}"; + exit 1; fi + if [ "${DESKTOP_SESSION}" != "" ]; then + notify-send "Error!" "${MESSAGE}"; + else + echo "Error! ${MESSAGE}"; + fi + exit 1; fi }