diff --git a/toot.sh b/toot.sh index 3662489..996b4b3 100755 --- a/toot.sh +++ b/toot.sh @@ -39,7 +39,7 @@ toot_upload_image(){ exit 1 } -toot_post(){ +toot_post_with_image(){ local status="$1" local image="$2" local sensitive="$3" @@ -52,7 +52,19 @@ toot_post(){ echo $error exit 1 fi +} +toot_post(){ + local status="$1" + local data="status=$status" + local error=$(curl --header "Authorization: Bearer $MASTODON_TOKEN" -sS -X POST https://$MASTODON_SERVER/api/v1/statuses -d "$data" | jq -r .error) + if [ "$error" = "null" ] + then + echo "[$(date)][INFO] Tooted: $status" + else + echo $error + exit 1 + fi } image_to_toot="" @@ -99,9 +111,10 @@ then exit 1 fi -if [ -n $image_to_toot ] && [ -f $image_to_toot ] +if [ "$image_to_toot" != "" ] && [ -f $image_to_toot ] then image_id=$(toot_upload_image "$image_to_toot" "$image_alt") -fi - -toot_post "$*" "$image_id" "$sensitive" + toot_post_with_image "$*" "$image_id" "$sensitive" +else + toot_post "$*" "$image_id" "$sensitive" +fi \ No newline at end of file