2021-08-01 14:34:00 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-03-16 11:44:49 +01:00
|
|
|
# this script removed all room's without local members.
|
2021-08-01 14:34:00 +02:00
|
|
|
#
|
|
|
|
|
2024-12-26 16:10:00 +01:00
|
|
|
domain=''
|
|
|
|
token=''
|
2021-08-01 14:34:00 +02:00
|
|
|
|
|
|
|
print_usage() {
|
|
|
|
printf '%s\n\n' "${0##*/}"
|
|
|
|
printf 'usage:\n'
|
|
|
|
printf ' -h print this help\n'
|
|
|
|
printf ' -d domain\n'
|
|
|
|
printf ' -t token\n'
|
|
|
|
printf 'example:\n'
|
|
|
|
printf ' %s -d "domain.com" -t "token"\n' "${0##*/}"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts ":d:t:h" opt "${@}"; do
|
|
|
|
case $opt in
|
2024-12-26 16:10:00 +01:00
|
|
|
d) domain="$OPTARG" ;;
|
|
|
|
t) token="$OPTARG" ;;
|
2021-08-01 14:34:00 +02:00
|
|
|
\?) printf 'Invalid option: -%s\n\n' "$OPTARG" ; print_usage ;;
|
|
|
|
h|*) print_usage ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-12-26 16:10:00 +01:00
|
|
|
if [ -z "$domain" ] || [ "$domain" == '-t' ]; then print_usage; fi
|
|
|
|
if [ -z "$token" ] || [ "$token" == '-d' ]; then print_usage; fi
|
2021-08-01 14:34:00 +02:00
|
|
|
|
2024-12-26 16:10:00 +01:00
|
|
|
TOPURGE=$(curl -s -X GET -H "Authorization: Bearer $token" -H "Content-Type: application/json" -d '{}' \
|
|
|
|
'https://'"$domain"'/_synapse/admin/v1/rooms?limit=1000000' | jq -Mr '.rooms[] | select(.joined_local_members == 0) | .room_id')
|
2021-08-01 14:34:00 +02:00
|
|
|
|
2024-12-26 16:10:00 +01:00
|
|
|
for room in $TOPURGE
|
2021-08-01 14:34:00 +02:00
|
|
|
do
|
2024-12-26 16:10:00 +01:00
|
|
|
printf 'processing room %s ..\n' "$room"
|
|
|
|
curl -w "\nResponse code: %{response_code}\n\n" -s \
|
|
|
|
-X DELETE \
|
|
|
|
-H "Authorization: Bearer $token" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
-d '{}' \
|
|
|
|
'https://'"$domain"'/_synapse/admin/v1/rooms/'"$room"''
|
|
|
|
done
|
2021-08-01 14:34:00 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
exit 0
|