Skip to content

Instantly share code, notes, and snippets.

@swetland
Created November 17, 2022 09:35
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 swetland/b09793f4bda7e81b53ac593e61328960 to your computer and use it in GitHub Desktop.
Save swetland/b09793f4bda7e81b53ac593e61328960 to your computer and use it in GitHub Desktop.
a script to add mastodon follows to lists using madonctl
#!/bin/bash
# 1. Get and build madonctl from https://github.com/McKael/madonctl.git and login
#
# 2. set this to your server name, as local accounts are stored without @server.name:
SERVER="chaos.social"
#
# 3. Fetch account and list name->id maps:
# ./edit-lists.sh setup
#
# 4. Add people to LISTS, where LISTS contains lines with either:
# ListName or @account@server.name
#
# 5. Issue commands to add those people to lists (without "doit" for a dry run):
# ./edit-lists.sh doit < LISTS
if [[ "$1" == "setup" ]] ; then
./madonctl lists show --all --template '{{"listid[\""}}{{.title}}{{"\"]="}}{{.id}}{{"\n"}}' > list.ids
./madonctl accounts following --all --template '{{"acctid[\""}}{{.acct}}{{"\"]="}}{{.id}}{{"\n"}}' > acct.ids
exit 0
fi
declare -A listid
source list.ids
declare -A acctid
source acct.ids
LIST=""
while read line ; do
if [[ "$line" == "" ]] ; then
continue
fi
if [[ "${line:0:1}" == "@" ]] ; then
ACCT="${line:1}"
# if ACCT ends with @SERVER, remove it
if [[ "${ACCT#*@}" == "$SERVER" ]] ; then
ACCT="${ACCT%@*}"
fi
echo ADD $ACCT TO $LIST
if [[ "$LIST" == "" ]] ; then
echo Error: cannot add account to unknown list: $LIST
continue
fi
AID="${acctid[$ACCT]}"
if [[ "$AID" == "" ]] ; then
echo Error: cannot find account: $ACCT
continue
fi
if [[ "$1" == "doit" ]] ; then
./madonctl list add-accounts --list-id $LID --account-ids $AID
else
echo ./madonctl list add-accounts --list-id $LID --account-ids $AID
fi
else
LID="${listid[$line]}"
if [[ "$LID" == "" ]] ; then
echo Error: cannot find list: $line
LIST=""
continue
fi
LIST="$line"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment