diff --git a/script/matrix-purge-rooms b/script/matrix-purge-rooms new file mode 100755 index 0000000..e2b11dd --- /dev/null +++ b/script/matrix-purge-rooms @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# +# matrix-purge-rooms purges Matrix rooms with no users. +# Expects to connect to Synapse on localhost:8008. + +set -euo pipefail +IFS=$'\n\t' + +roomstopurge=$(curl -s --header "Authorization: Bearer $SYNAPSE_ACCESS_TOKEN" 'http://localhost:8008/_synapse/admin/v1/rooms?limit=300' | jq -r '.rooms[] | select(.joined_local_members == 0) | .room_id') +for roomid in $roomstopurge; do + echo "Purging room: $roomid" + curl -X DELETE -H "Authorization: Bearer $SYNAPSE_ACCESS_TOKEN" -H "Content-Type: application/json" -d "{\"purge\": true, \"force_purge\": true}" "http://localhost:8008/_synapse/admin/v1/rooms/$roomid" + echo +done