mirror of
https://git.envs.net/envs/matrix-conf.git
synced 2025-06-06 22:58:53 -04:00
update matrix-remove-empty-rooms.sh
This commit is contained in:
parent
df1d28aba7
commit
baecabda4d
1 changed files with 17 additions and 17 deletions
|
@ -1,11 +1,9 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this script removed all room's without local members.
|
# this script removed all room's without local members.
|
||||||
# you dont need to stop synapse.
|
|
||||||
#
|
#
|
||||||
|
|
||||||
DOMAIN=''
|
domain=''
|
||||||
TOKEN=''
|
token=''
|
||||||
tmp_file='/tmp/matrix_rooms_to_purge.txt'
|
|
||||||
|
|
||||||
print_usage() {
|
print_usage() {
|
||||||
printf '%s\n\n' "${0##*/}"
|
printf '%s\n\n' "${0##*/}"
|
||||||
|
@ -20,27 +18,29 @@ print_usage() {
|
||||||
|
|
||||||
while getopts ":d:t:h" opt "${@}"; do
|
while getopts ":d:t:h" opt "${@}"; do
|
||||||
case $opt in
|
case $opt in
|
||||||
d) DOMAIN="$OPTARG" ;;
|
d) domain="$OPTARG" ;;
|
||||||
t) TOKEN="$OPTARG" ;;
|
t) token="$OPTARG" ;;
|
||||||
\?) printf 'Invalid option: -%s\n\n' "$OPTARG" ; print_usage ;;
|
\?) printf 'Invalid option: -%s\n\n' "$OPTARG" ; print_usage ;;
|
||||||
h|*) print_usage ;;
|
h|*) print_usage ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$DOMAIN" ] || [ "$DOMAIN" == '-t' ]; then print_usage; fi
|
if [ -z "$domain" ] || [ "$domain" == '-t' ]; then print_usage; fi
|
||||||
if [ -z "$TOKEN" ] || [ "$TOKEN" == '-d' ]; then print_usage; fi
|
if [ -z "$token" ] || [ "$token" == '-d' ]; then print_usage; fi
|
||||||
|
|
||||||
curl -s -X GET -H "Authorization: Bearer $TOKEN" "https://$DOMAIN/_synapse/admin/v1/rooms?limit=1000000" | \
|
TOPURGE=$(curl -s -X GET -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d '{}' \
|
||||||
jq -Mr '.rooms[] | select(.joined_local_members == 0) | .room_id' > $tmp_file
|
'https://'"$domain"'/_synapse/admin/v1/rooms?limit=1000000' | jq -Mr '.rooms[] | select(.joined_local_members == 0) | .room_id')
|
||||||
|
|
||||||
while IFS= read -r room_id
|
for room in $TOPURGE
|
||||||
do
|
do
|
||||||
printf 'remove room %s ' "$room_id"
|
printf 'processing room %s ..\n' "$room"
|
||||||
curl -s -X DELETE -H "Authorization: Bearer $TOKEN" "https://$DOMAIN/_synapse/admin/v1/rooms/$room_id" \
|
curl -w "\nResponse code: %{response_code}\n\n" -s \
|
||||||
-H "Content-Type: application/json" -d "{}"
|
-X DELETE \
|
||||||
printf ' done.\n'
|
-H "Authorization: Bearer $token" \
|
||||||
done < $tmp_file
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{}' \
|
||||||
|
'https://'"$domain"'/_synapse/admin/v1/rooms/'"$room"''
|
||||||
|
done
|
||||||
|
|
||||||
rm $tmp_file
|
|
||||||
#
|
#
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue