Compare commits

..

3 Enmetoj

Author SHA1 Message Date
Jaidyn Ann 43ce10b5a5 Add fedi-nuke.sh script, which will remove posts 2024-02-13 09:56:18 -06:00
Jaidyn Ann f4721274e7 Add optionally-auth’d archival to fedi-archive
Now even private posts can be fetched, if you
so choose.
2024-02-13 09:55:24 -06:00
Jaidyn Ann 3096ce5347 Don’t hardcode server into fedi-post.sh
It was previously set to jam.xwx.moe, now it’s
exposed as a parameter.
2024-02-13 09:54:58 -06:00
4 changed files with 107 additions and 31 deletions

View File

@ -36,11 +36,16 @@ output_post_of_index() {
# `max_id` can be passed to return only messages older than said message. # `max_id` can be passed to return only messages older than said message.
fetch_page() { fetch_page() {
local server="$1"; local user="$2"; local max_id="$3" local server="$1"; local user="$2"; local max_id="$3"
local url="https://$server/api/v1/accounts/$user/statuses?exclude_replies=true&exclude_reblogs=true&limit=40" local url="https://$server/api/v1/accounts/$user/statuses?exclude_replies=false&exclude_reblogs=true&limit=40"
if test -n "$max_id"; then if test -n "$max_id"; then
url="${url}&max_id=${max_id}" url="${url}&max_id=${max_id}"
fi fi
if test -n "$FEDI_AUTH"; then
curl --header "Authorization: Bearer $FEDI_AUTH" \
"$url"
else
curl "$url" curl "$url"
fi
} }
@ -102,10 +107,15 @@ archive_all_posts() {
usage() { usage() {
echo "usage: $(basename $0) username server" 1>&2 echo "usage: $(basename $0) username server" 1>&2
echo "" 1>&2 echo 1>&2
echo "$(basename $0) is a script that fetches all of a user's Mastodon/Pleroma" 1>&2 echo "$(basename $0) is a script that fetches all of a users Mastodon/Pleroma" 1>&2
echo "posts for archival purposes." 1>&2 echo 'posts for archival purposes.' 1>&2
echo "Mainly for use with fedi-post.sh or pleroma-migrate.sh." 1>&2 echo 'Mainly for use with fedi-post.sh or pleroma-migrate.sh.' 1>&2
echo 1>&2
echo 'Optionally, you can fetch also any private statuses by the account visible' 1>&2
echo 'to you by providing your auth key in the $FEDI_AUTH environment variable.' 1>&2
echo 'You can find your auth key by examining the “Authentication: Bearer” header' 1>&2
echo 'used in requests by your servers web-client. In Firefox, F12→Network.' 1>&2
exit 2; exit 2;
} }

63
fedi-nuke.sh Normal file
View File

@ -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

View File

@ -75,7 +75,7 @@ post_media() {
--header "Content-Type: multipart/form-data" \ --header "Content-Type: multipart/form-data" \
--form "file=@$media_file" \ --form "file=@$media_file" \
--form "description=$description" \ --form "description=$description" \
"https://jam.xwx.moe/api/v1/media" "https://$SERVER/api/v1/media"
} }
@ -89,7 +89,7 @@ post_status() {
--header "Authorization: Bearer $FEDI_AUTH" \ --header "Authorization: Bearer $FEDI_AUTH" \
--header "Content-Type: application/json" \ --header "Content-Type: application/json" \
--data "$(post_json "$message" "$media_ids" "$spoiler" | tr -d '\n')" \ --data "$(post_json "$message" "$media_ids" "$spoiler" | tr -d '\n')" \
"https://jam.xwx.moe/api/v1/statuses" "https://$SERVER/api/v1/statuses"
} }
@ -119,10 +119,10 @@ post_archived_post() {
usage() { usage() {
echo "usage: $(basename "$0") ARCHIVED-POST" 1>&2 echo "usage: $(basename "$0") ARCHIVED-POST" 1>&2
echo "" 1>&2 echo 1>&2
echo "Will post a new status with the same text and attachments as one" 1>&2 echo 'Will post a new status with the same text and attachments as one' 1>&2
echo "from an archived post (in fedi-archive.sh format)." 1>&2 echo 'from an archived post (in fedi-archive.sh format).' 1>&2
echo "Your authorization key must be borrowed from your web-browser and" 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 echo 'placed in the $FEDI_AUTH environment variable.' 1>&2
exit 2 exit 2
} }
@ -130,17 +130,18 @@ usage() {
if test -z "$FEDI_AUTH"; then if test -z "$FEDI_AUTH"; then
echo 'You need to set the environment variable $FEDI_AUTH!' 1>&2 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 '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 'used in requests by your servers web-client.' 1>&2
echo 'In Firefox, F12→Network.' 1>&2 echo 'In Firefox, F12→Network.' 1>&2
echo "" 1>&2 echo 1>&2
usage usage
fi fi
FILE="$1" SERVER="$1"
if test -z "$FILE" -o "$1" = "-h" -o "$1" = "--help"; then FILE="$2"
if test -z "$SERVER" -o -z "$FILE" -o "$1" = "-h" -o "$1" = "--help"; then
usage usage
fi fi
post_archived_post "$FILE" post_archived_post "$SERVER" "$FILE"

View File

@ -10,30 +10,31 @@
#――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
usage() { usage() {
echo "usage: $(basename "$0") USERNAME OLD-SERVER" 1>&2 echo "usage: $(basename "$0") OLD-USERNAME OLD-SERVER NEW-SERVER" 1>&2
echo "" 1>&2 echo 1>&2
echo "Will archive all posts from your old account (fedi-archive.sh)," 1>&2 echo 'Will archive all posts from your old account (fedi-archive.sh),' 1>&2
echo "post them to your new one (fedi-post.sh), and then modify Pleroma's" 1>&2 echo 'post them to your new one (fedi-post.sh), and then modify Pleromas' 1>&2
echo "database to match the copy-posts' creation dates with the original posts." 1>&2 echo 'database to match the copy-posts creation dates with the original posts.' 1>&2
echo 'The env variable $FEDI_AUTH must contain your authentication key from your browser.' 1>&2 echo 'The env variable $FEDI_AUTH must contain your authentication key from your browser.' 1>&2
exit 2 exit 2
} }
USERNAME="$1" USERNAME="$1"
SERVER="$2" OLD_SERVER="$2"
if test -z "$USERNAME" -o -z "$SERVER" -o "$1" = "-h" -o "$1" = "--help"; then NEW_SERVER="$3"
if test -z "$USERNAME" -o -z "$OLD_SERVER" -o -z "$NEW_SERVER" -o "$1" = "-h" -o "$1" = "--help"; then
usage usage
fi fi
mkdir archive mkdir archive
cd archive/ cd archive/
sh ../fedi-archive.sh "$USERNAME" "$SERVER" sh ../fedi-archive.sh "$USERNAME" "$OLD_SERVER"
for file in ./*; do for file in ./*; do
sh ../fedi-post.sh "$file" \ sh ../fedi-post.sh "$NEW_SERVER" "$file" \
>> imports-data.txt >> imports-data.txt
done done
@ -41,12 +42,13 @@ done
IFS=" IFS="
" "
echo "It's time to re-date your posts!" echo 'Its time to re-date your posts!'
echo "Are you suuuuuuuuuuuuure you wanna risk your database? Do a backup, first!" echo 'Are you suuuuuuuuuuuuure you wanna risk your database? Do a backup, first!'
echo "^C now, before you risk it! Hit ENTER, if you're sure." echo '^C now, before you risk it! Hit ENTER, if youre sure.'
read
read read
sleep 5 sleep 5
echo "Alright, then, you brave fellow! I'm touched you trust me so much, though :o" echo 'Alright, then, you brave fellow! Im touched you trust me so much, though :o'
for line in $(cat imports-data.txt); do for line in $(cat imports-data.txt); do
sh ../pleroma-redate.sh "$(echo "$line" | awk '{print $3}')" \ sh ../pleroma-redate.sh "$(echo "$line" | awk '{print $3}')" \