From 43ce10b5a59b75c911c8a93e38463efdee4e820c Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Tue, 13 Feb 2024 09:56:18 -0600 Subject: [PATCH] Add fedi-nuke.sh script, which will remove posts --- fedi-nuke.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 fedi-nuke.sh diff --git a/fedi-nuke.sh b/fedi-nuke.sh new file mode 100644 index 0000000..9749927 --- /dev/null +++ b/fedi-nuke.sh @@ -0,0 +1,63 @@ +#!/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