Skip to content

Instantly share code, notes, and snippets.

@koddsson
Created June 26, 2019 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koddsson/f9e3b07ad44eeaff3d2342c2be247f47 to your computer and use it in GitHub Desktop.
Save koddsson/f9e3b07ad44eeaff3d2342c2be247f47 to your computer and use it in GitHub Desktop.
Simple Bash script that let's me post a micropub note from my terminal
#! /bin/bash
ME="https://koddsson.com"
MICROPUB_ENDPOINT="$ME/micropub"
CODE=$(cat token)
STATUS_CODE=$(curl -sw '%{http_code}' -o /dev/null -d "code=$CODE&redirect_uri=http://nonexisting-domain.dev/callback&client_id=$ME" https://indieauth.com/auth)
if [ $STATUS_CODE -eq 404 ]; then
open "https://indieauth.com/auth?me=$ME&client_id=$ME&scope=create+update&response_type=code&redirect_uri=http%3A%2F%2Fnonexisting-domain.dev%2Fcallback"
echo "You need to get a new token"
exit 1
fi
ACCESS_TOKEN=$(curl -s -H 'Accept: application/json' "https://tokens.indieauth.com/token" -d "code=$CODE&redirect_uri=http://nonexisting-domain.dev/callback&grant_type=authorization_code&client_id=$ME&me=$ME" | jq -r '.access_token')
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" -d "h=entry&content=$1" $MICROPUB_ENDPOINT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment