pleroma-redate.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. #―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  3. # Name: pleroma-redate.sh
  4. # Desc: Changes the creation-date of a post in Pleroma's database.
  5. # Reqs: psql, sudo
  6. # Date: 2023-05-06
  7. # Auth: @jadedctrl@jam.xwx.moe
  8. #―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  9. usage() {
  10. echo "usage: $(basename "$0") URL NEW-DATE" 1>&2
  11. echo "" 1>&2
  12. echo "Will change the stored date of an archived fedi post" 1>&2
  13. echo "in fedi-archive.sh format, by editing directly Pleroma's database." 1>&2
  14. echo "URL ought be the direct /object/ URL, and NEW-DATE ought be ISO-8601" 1>&2
  15. echo "up to the milisecond." 1>&2
  16. echo "Assumes you can sudo as 'postgres' and the database is called 'pleroma'." 1>&2
  17. exit 2
  18. }
  19. URL="$1"
  20. NEWDATE="$2"
  21. if test -z "$URL" -o -z "$NEWDATE" -o "$1" = "-h" -o "$1" = "--help"; then
  22. usage
  23. fi
  24. sudo -u postgres psql --dbname=pleroma \
  25. -c "UPDATE objects
  26. SET data = jsonb_set(data, '{published}', '\"$NEWDATE\"'::jsonb, false)
  27. WHERE CAST(data::json->'id' AS TEXT) = '\"$URL\"' ;"