#!/bin/sh #――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # Name: fedi-nuke.sh # Desc: Deletes a given status of yours from a Mastodon-compatible fedi server. # Reqs: curl, jq # Date: 2024-02-13 # Auth: @jadedctrl@jam.xwx.moe #――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # Post a status of the given message and JSON-array of uploaded media-IDs. remove_post() { local status_id="$1" curl --request DELETE \ --header "Authorization: Bearer $FEDI_AUTH" \ "https://$SERVER/api/v1/statuses/$status_id" } # Take a post file generated by fedi-archive.sh, and post it. # Just *do it*. Why not? What're you scared of? Huh, huh? Huh?! remove_archived_post() { local file="$1" IFS=" " local id="$(head -1 "$file" | awk '{print $3}')" remove_post "$id" } usage() { echo "usage: $(basename "$0") SERVER POST-ID" 1>&1 echo " $(basename "$0") SERVER ARCHIVED-POST" 1>&2 echo 1>&2 echo 'Will delete a post from a Mastodon-compatible fedi server by either' 1>&1 echo 'ID or by an archived-post file (in fedi-archive.sh format).' 1>&2 echo 'Your authorization key must be borrowed from your web-browser and' 1>&2 echo 'placed in the $FEDI_AUTH environment variable.' 1>&2 exit 2 } if test -z "$FEDI_AUTH"; then echo 'You need to set the environment variable $FEDI_AUTH!' 1>&2 echo 'You can find your auth key by examining the "Authentication: Bearer" header' 1>&2 echo "used in requests by your server's web-client." 1>&2 echo 'In Firefox, F12→Network.' 1>&2 echo "" 1>&2 usage fi SERVER="$1" TARGET="$2" if test -z "$SERVER" -o -z "$TARGET" -o "$1" = "-h" -o "$1" = "--help"; then usage fi if test -f "$TARGET"; then remove_archived_post "$TARGET" else remove_post "$TARGET" fi