Updated bash script
This commit is contained in:
parent
8ce337233c
commit
1c8e4dff47
1 changed files with 12 additions and 20 deletions
|
@ -30,37 +30,29 @@ EOF
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
RESPONSE="$(curl -s -F "token={{ token }}" -F "upload=@${1}" {{ upload_url }})";
|
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
|
if [[ "$(echo "${RESPONSE}" | jq -r '.message')" == "OK" ]]; then
|
||||||
URL="$(echo "${RESPONSE}" | jq -r '.url')";
|
URL="$(echo "${RESPONSE}" | jq -r '.url')";
|
||||||
if [ "${DESKTOP_SESSION}" != "" ]; then
|
if [ "${DESKTOP_SESSION}" != "" ]; then
|
||||||
echo "${URL}" | xclip -selection c;
|
echo "${URL}" | xclip -selection c;
|
||||||
notify-send "Upload completed!" "${URL}";
|
notify-send "Upload completed!" "${URL}";
|
||||||
exit 0;
|
|
||||||
else
|
else
|
||||||
echo "${URL}";
|
echo "${URL}";
|
||||||
exit 0;
|
|
||||||
fi
|
fi
|
||||||
|
exit 0;
|
||||||
else
|
else
|
||||||
if [ "${DESKTOP_SESSION}" != "" ]; then
|
MESSAGE="$(echo "${RESPONSE}" | jq -r '.message')";
|
||||||
notify-send "Error!" "$(echo "${RESPONSE}" | jq -r '.message')";
|
if [ $? -ne 0 ]; then
|
||||||
exit 1;
|
echo "Unexpected response:";
|
||||||
else
|
echo "${RESPONSE}";
|
||||||
echo "Error! $(echo "${RESPONSE}" | jq -r '.message')";
|
exit 1;
|
||||||
exit 1;
|
|
||||||
fi
|
fi
|
||||||
|
if [ "${DESKTOP_SESSION}" != "" ]; then
|
||||||
|
notify-send "Error!" "${MESSAGE}";
|
||||||
|
else
|
||||||
|
echo "Error! ${MESSAGE}";
|
||||||
|
fi
|
||||||
|
exit 1;
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue