Updated scripts. This works a bit better
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
.PHONY: help delete-room notification-purge
|
||||
|
||||
MATRIX_BASE_URL ?=
|
||||
MATRIX_TOKEN ?=
|
||||
ROOM_ID ?=
|
||||
|
||||
help:
|
||||
@echo "Available commands:"
|
||||
@echo " make delete-room ROOM_ID=<room_id> MATRIX_BASE_URL=<url> MATRIX_TOKEN=<token>"
|
||||
@echo " - Deletes a given room."
|
||||
@echo " make notification-purge MATRIX_BASE_URL=<url> MATRIX_TOKEN=<token>"
|
||||
@echo " - Clears all pushers and marks all rooms as read."
|
||||
|
||||
delete-room:
|
||||
@if [ -z "$(ROOM_ID)" ]; then \
|
||||
echo "Error: ROOM_ID is required. Usage: make delete-room ROOM_ID=<room_id>"; \
|
||||
exit 1; \
|
||||
fi
|
||||
@MATRIX_BASE_URL="$(MATRIX_BASE_URL)" MATRIX_TOKEN="$(MATRIX_TOKEN)" ./delete_room.sh "$(ROOM_ID)"
|
||||
|
||||
notification-purge:
|
||||
@MATRIX_BASE_URL="$(MATRIX_BASE_URL)" MATRIX_TOKEN="$(MATRIX_TOKEN)" ./notification_purge.sh
|
||||
+14
-8
@@ -14,20 +14,26 @@ fi
|
||||
|
||||
ROOM_ID="$1"
|
||||
|
||||
# Config
|
||||
export BASE_URL="${MATRIX_BASE_URL}"
|
||||
export TOKEN="${MATRIX_TOKEN}"
|
||||
BASE_URL="${MATRIX_BASE_URL}/_synapse/admin/v2"
|
||||
TOKEN="${MATRIX_TOKEN}"
|
||||
|
||||
echo "Deleting room $ROOM_ID from server entirely..."
|
||||
echo "=== Deleting room $ROOM_ID from server entirely ==="
|
||||
|
||||
# Delete the room :D
|
||||
curl -X DELETE "${BASE_URL}/_synapse/admin/v2/rooms/${ROOM_ID}" \
|
||||
result=$(curl -s -X DELETE "${BASE_URL}/rooms/${ROOM_ID}" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"purge": true,
|
||||
"force_purge": true,
|
||||
"block": true
|
||||
}'
|
||||
}')
|
||||
|
||||
echo -e "\nDone."
|
||||
errcode=$(echo "$result" | jq -r '.errcode // empty' 2>/dev/null)
|
||||
if [ -n "$errcode" ]; then
|
||||
echo " Failed: ${errcode} - $(echo "$result" | jq -r '.error // "Unknown"')"
|
||||
else
|
||||
echo " Done."
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Process finished."
|
||||
|
||||
+42
-50
@@ -1,105 +1,97 @@
|
||||
#!/bin/bash
|
||||
# This script is meant to help deal with several issues with Continuwuity
|
||||
# 1. Clears all pushers... as of now they do not clear when one signs absolutely
|
||||
# 2. Sets all notifications to read
|
||||
# Maintenance script for Continuwuity
|
||||
# 1. Clears all pushers (they don't clear on sign-out)
|
||||
# 2. Marks all rooms as read
|
||||
|
||||
# Config
|
||||
if [ -z "$MATRIX_BASE_URL" ] || [ -z "$MATRIX_TOKEN" ]; then
|
||||
echo "Error: MATRIX_BASE_URL and MATRIX_TOKEN environment variables must be set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export BASE_URL="${MATRIX_BASE_URL}/_matrix/client/v3"
|
||||
export TOKEN="${MATRIX_TOKEN}"
|
||||
BASE_URL="${MATRIX_BASE_URL}/_matrix/client/v3"
|
||||
TOKEN="${MATRIX_TOKEN}"
|
||||
|
||||
echo "=== Removing dangling pushers ==="
|
||||
# Fetch pushers
|
||||
response=$(curl -s -X GET "${BASE_URL}/pushers" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json")
|
||||
|
||||
# Loop over pushers
|
||||
if [ -n "$response" ] && echo "$response" | jq -e '.pushers' >/dev/null; then
|
||||
if [ -n "$response" ] && echo "$response" | jq -e '.pushers' >/dev/null 2>&1; then
|
||||
count=$(echo "$response" | jq '.pushers | length')
|
||||
echo "Found ${count} pusher(s)."
|
||||
|
||||
echo "$response" | jq -c '.pushers[]' | while read -r pusher; do
|
||||
app_id=$(echo "$pusher" | jq -r '.app_id')
|
||||
pushkey=$(echo "$pusher" | jq -r '.pushkey')
|
||||
|
||||
echo "Removing pusher: ${app_id}..."
|
||||
echo "Removing pusher: ${app_id} (${pushkey})..."
|
||||
|
||||
# Delete pusher
|
||||
curl -s -X POST "${BASE_URL}/pushers/set" \
|
||||
result=$(curl -s -X POST "${BASE_URL}/pushers/set" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg id "$app_id" --arg key "$pushkey" \
|
||||
'{app_id: $id, pushkey: $key, kind: null}')" > /dev/null
|
||||
'{app_id: $id, pushkey: $key, kind: null}')")
|
||||
|
||||
errcode=$(echo "$result" | jq -r '.errcode // empty' 2>/dev/null)
|
||||
if [ -n "$errcode" ]; then
|
||||
echo " Failed: ${errcode} - $(echo "$result" | jq -r '.error // "Unknown"')"
|
||||
else
|
||||
echo " Done."
|
||||
fi
|
||||
done
|
||||
|
||||
# Verify all pushers are gone
|
||||
verify=$(curl -s -X GET "${BASE_URL}/pushers" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json")
|
||||
remaining=$(echo "$verify" | jq '.pushers | length' 2>/dev/null)
|
||||
echo "Remaining pushers: ${remaining:-unknown}"
|
||||
else
|
||||
echo "No pushers found or failed to fetch pushers."
|
||||
fi
|
||||
|
||||
|
||||
echo ""
|
||||
echo "=== Clearing all notifications ==="
|
||||
# Get all rooms
|
||||
echo "=== Clearing all notifications (marking rooms as read) ==="
|
||||
rooms_response=$(curl -s -X GET "${BASE_URL}/joined_rooms" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json")
|
||||
|
||||
if [ -n "$rooms_response" ] && echo "$rooms_response" | jq -e '.joined_rooms' >/dev/null; then
|
||||
|
||||
export -f process_room || true
|
||||
if [ -n "$rooms_response" ] && echo "$rooms_response" | jq -e '.joined_rooms' >/dev/null 2>&1; then
|
||||
room_count=$(echo "$rooms_response" | jq '.joined_rooms | length')
|
||||
echo "Found ${room_count} joined room(s)."
|
||||
|
||||
process_room() {
|
||||
room_id="$1"
|
||||
local room_id="$1"
|
||||
local BASE_URL="$2"
|
||||
local TOKEN="$3"
|
||||
local ENCODED_ROOM_ID
|
||||
ENCODED_ROOM_ID=$(echo -n "$room_id" | jq -sRr @uri)
|
||||
|
||||
echo "Processing room: ${room_id}"
|
||||
|
||||
CURRENT_RULE=$(curl -s -X GET "${BASE_URL}/pushrules/global/room/${ENCODED_ROOM_ID}" \
|
||||
-H "Authorization: Bearer ${TOKEN}")
|
||||
CURRENT_ACTION=$(echo "$CURRENT_RULE" | jq -c '.actions' 2>/dev/null)
|
||||
if [ -z "$CURRENT_ACTION" ] || [ "$CURRENT_ACTION" = "null" ]; then
|
||||
CURRENT_ACTION="default (not explicitly set)"
|
||||
fi
|
||||
echo " [Before] Current setting: $CURRENT_ACTION"
|
||||
|
||||
PUT_RESULT=$(curl -s -X PUT "${BASE_URL}/pushrules/global/room/${ENCODED_ROOM_ID}" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"actions\": [\"dont_notify\"]}")
|
||||
|
||||
ERRCODE=$(echo "$PUT_RESULT" | jq -r '.errcode // empty' 2>/dev/null)
|
||||
if [ -n "$ERRCODE" ]; then
|
||||
ERROR_MSG=$(echo "$PUT_RESULT" | jq -r '.error // "Unknown error"' 2>/dev/null)
|
||||
echo " [Error] FAILED to set rule: $ERRCODE - $ERROR_MSG"
|
||||
else
|
||||
NEW_RULE=$(curl -s -X GET "${BASE_URL}/pushrules/global/room/${ENCODED_ROOM_ID}" \
|
||||
-H "Authorization: Bearer ${TOKEN}")
|
||||
NEW_ACTION=$(echo "$NEW_RULE" | jq -c '.actions' 2>/dev/null)
|
||||
echo " [After] New setting verified: $NEW_ACTION"
|
||||
fi
|
||||
|
||||
LATEST_EVENT=$(curl -s -X GET "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/messages?dir=b&limit=1" \
|
||||
-H "Authorization: Bearer ${TOKEN}" | jq -r ".chunk[0].event_id // empty")
|
||||
-H "Authorization: Bearer ${TOKEN}" | jq -r '.chunk[0].event_id // empty')
|
||||
|
||||
if [ -n "$LATEST_EVENT" ]; then
|
||||
ENCODED_LATEST=$(echo -n "$LATEST_EVENT" | jq -sRr @uri)
|
||||
|
||||
curl -s -X POST "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/read_markers" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"m.fully_read\": \"${LATEST_EVENT}\", \"m.read\": \"${LATEST_EVENT}\"}" > /dev/null
|
||||
-d "{\"m.fully_read\": \"${LATEST_EVENT}\", \"m.read\": \"${LATEST_EVENT}\", \"m.read.private\": \"${LATEST_EVENT}\"}" > /dev/null
|
||||
|
||||
ENCODED_LATEST=$(echo -n "$LATEST_EVENT" | jq -sRr @uri)
|
||||
curl -s -X POST "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/receipt/m.read/${ENCODED_LATEST}" \
|
||||
-H "Authorization: Bearer ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{}" > /dev/null
|
||||
|
||||
echo "Marked as read: ${room_id}"
|
||||
else
|
||||
echo "No events in: ${room_id}"
|
||||
fi
|
||||
}
|
||||
export -f process_room
|
||||
|
||||
echo "$rooms_response" | jq -r '.joined_rooms[]' | xargs -P 10 -I {} bash -c 'process_room "$@"' _ {}
|
||||
echo "$rooms_response" | jq -r '.joined_rooms[]' | \
|
||||
xargs -P 10 -I {} bash -c 'process_room "$@"' _ {} "$BASE_URL" "$TOKEN"
|
||||
else
|
||||
echo "No joined rooms found or failed to fetch rooms."
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user