Don’t hardcode server into fedi-post.sh

It was previously set to jam.xwx.moe, now it’s
exposed as a parameter.
This commit is contained in:
Jaidyn Ann 2024-02-13 09:54:58 -06:00
parent 92b9476c87
commit 3096ce5347
2 changed files with 28 additions and 25 deletions

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}')" \