The simplest possible CLI tool for posting to Mastodon.
2.3K
The simplest possible CLI tool for posting to Mastodon, ideally suited for use in simple bots.
mastodon-post [OPTIONS] -text "text to post"
-text: Text to post. Required.-visibility: Visibility of the post. One of public, unlisted, or private. Defaults to public.-help: Print help and exit.-version: Print version and exit.Credentials and the server's address are provided via the environment variables MASTODON_SERVER, MASTODON_CLIENT_ID, MASTODON_CLIENT_SECRET, and MASTODON_ACCESS_TOKEN.
MASTODON_SERVER is the URL of your Mastodon server (for example, https://mastodon.social).
To get a Client ID/Secret and Access Token:
urn:ietf:wg:oauth:2.0:oob for the Redirect URIwrite:statusesYou can optionally provide these environment variables by placing a .env file in the working directory from which you run mastodon-post. The program will read the file if it exists and set the environment variables automatically.
If running the program via Docker, you can pass the same file to the --env-file option.
An empty .env file is included in this repository to help you get started: .env.template.
brew install cdzombak/oss/mastodon-post
Install my Debian repository if you haven't already:
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://dist.cdzombak.net/deb.key | sudo gpg --dearmor -o /etc/apt/keyrings/dist-cdzombak-net.gpg
sudo chmod 0644 /etc/apt/keyrings/dist-cdzombak-net.gpg
echo -e "deb [signed-by=/etc/apt/keyrings/dist-cdzombak-net.gpg] https://dist.cdzombak.net/deb/oss any oss\n" | sudo tee -a /etc/apt/sources.list.d/dist-cdzombak-net.list > /dev/null
sudo apt-get update
Then install mastodon-post via apt-get:
sudo apt-get install mastodon-post
Pre-built binaries for Linux and macOS on various architectures are downloadable from each GitHub Release. Debian packages for each release are available as well.
git clone https://github.com/cdzombak/mastodon-post.git
cd mastodon-post
make build
cp out/mastodon-post $INSTALL_DIR
Docker images are available for a variety of Linux architectures from Docker Hub and GHCR. Images are based on the scratch image and are as small as possible.
Run them via, for example:
docker run --rm --env-file /path/to/.env cdzombak/mastodon-post:1 -text "message to post"
docker run --rm --env-file /path/to/.env ghcr.io/cdzombak/mastodon-post:1 -text "message to post"
See:
MIT; see LICENSE in this repository.
Content type
Image
Digest
sha256:d26e0dff4…
Size
4.3 MB
Last updated
almost 3 years ago
docker pull cdzombak/mastodon-post