atproto library for bash scripts
atproto bash-atproto
Shell 100.0%
2 3 0

Clone this repository

https://tangled.org/engielolz.ritsuko.akizuki.best/bash-atproto
git@tangled.org:engielolz.ritsuko.akizuki.best/bash-atproto

For self-hosted knots, clone URLs may differ based on your setup.

README.md

bash-atproto#

bash-atproto is a bare-bones atproto client that I wrote for imasimgbot and the now-defunct 765coverbot. It is a Bash script that uses cURL to authenticate, create records and upload blobs.

It supports the following operations (most API calls are done to the account's PDS):

  • Resolving a handle to did:plc/did:web

  • Resolving an account's PDS from the DID

  • Creating and closing sessions on the PDS

  • Saving and loading a secrets file (contains your access and refresh tokens)

  • Extracting account and token information from the access token

  • Refreshing tokens

  • Creating basic Bluesky text post records

  • Creating Bluesky repost records

  • Preparing an image for Bluesky (including resizing and compressing)

  • Uploading blobs

  • Creating a post with a single embedded image with alt text

Dependencies#

bash-atproto requires cURL 7.76 or later and jq. Posting images (not used by 765coverbot) additionally requires imagemagick, exiftool and uuidgen.

Basic usage#

bash-atproto is loaded with source bash-atproto.sh. From there, most operations will require you to sign-in to an atproto account, which can be done in three functions:

  1. bap_didInit <did or handle> which will resolve your handle to a DID

  2. bap_findPDS $savedDID which will retrieve the account's PDS for use

  3. bap_getKeys $savedDID <password> to log in. The access and refresh tokens are saved in memory and can be written to disk with bap_saveSecrets <file>. It is recommended you use an App Password to log in rather than a normal password.

If bash-atproto is being used with a bot or other service that runs periodically, the calling application should implement a timer to refresh tokens. bash-atproto provides a function to perform a refresh (bap_refreshKeys) and a timestamp to detect when a token refresh should be performed ($bap_savedAccessExpiry), but it does not do so itself.

Standalone usage#

bash-atproto is mainly meant for use as a component for bash scripts that want to use the AT Protocol, but it by itself can be used as a simple atproto client for the command line. The following commands will log in to your PDS, create a Bluesky post and then log out:

  1. source bash-atproto.sh

  2. bap_didInit <your did or handle>

  3. bap_findPDS $savedDID

  4. bap_getKeys $savedDID <app password>

  5. bap_postToBluesky "Hello, World!" en

  6. bap_closeSession

License#

bash-atproto is licensed under the MIT License. Please note that bash-atproto is hobbyist-grade software and I take no responsibility if it is used to post Discourse™ to your account.