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:
-
bap_didInit <did or handle>which will resolve your handle to a DID -
bap_findPDS $savedDIDwhich will retrieve the account's PDS for use -
bap_getKeys $savedDID <password>to log in. The access and refresh tokens are saved in memory and can be written to disk withbap_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:
-
source bash-atproto.sh -
bap_didInit <your did or handle> -
bap_findPDS $savedDID -
bap_getKeys $savedDID <app password> -
bap_postToBluesky "Hello, World!" en -
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.