Skip to content

Instantly share code, notes, and snippets.

@koddsson koddsson/n
Created Jun 26, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.