Updated scripts. This works a bit better

This commit is contained in:
2026-04-17 09:16:44 -06:00
parent f04794a128
commit fa93db1a5b
3 changed files with 79 additions and 59 deletions
+22
View File
@@ -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
View File
@@ -14,20 +14,26 @@ fi
ROOM_ID="$1" ROOM_ID="$1"
# Config BASE_URL="${MATRIX_BASE_URL}/_synapse/admin/v2"
export BASE_URL="${MATRIX_BASE_URL}" TOKEN="${MATRIX_TOKEN}"
export TOKEN="${MATRIX_TOKEN}"
echo "Deleting room $ROOM_ID from server entirely..." echo "=== Deleting room $ROOM_ID from server entirely ==="
# Delete the room :D result=$(curl -s -X DELETE "${BASE_URL}/rooms/${ROOM_ID}" \
curl -X DELETE "${BASE_URL}/_synapse/admin/v2/rooms/${ROOM_ID}" \
-H "Authorization: Bearer ${TOKEN}" \ -H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"purge": true, "purge": true,
"force_purge": true, "force_purge": true,
"block": 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."
+43 -51
View File
@@ -1,105 +1,97 @@
#!/bin/bash #!/bin/bash
# This script is meant to help deal with several issues with Continuwuity # Maintenance script for Continuwuity
# 1. Clears all pushers... as of now they do not clear when one signs absolutely # 1. Clears all pushers (they don't clear on sign-out)
# 2. Sets all notifications to read # 2. Marks all rooms as read
# Config
if [ -z "$MATRIX_BASE_URL" ] || [ -z "$MATRIX_TOKEN" ]; then if [ -z "$MATRIX_BASE_URL" ] || [ -z "$MATRIX_TOKEN" ]; then
echo "Error: MATRIX_BASE_URL and MATRIX_TOKEN environment variables must be set." echo "Error: MATRIX_BASE_URL and MATRIX_TOKEN environment variables must be set."
exit 1 exit 1
fi fi
export BASE_URL="${MATRIX_BASE_URL}/_matrix/client/v3" BASE_URL="${MATRIX_BASE_URL}/_matrix/client/v3"
export TOKEN="${MATRIX_TOKEN}" TOKEN="${MATRIX_TOKEN}"
echo "=== Removing dangling pushers ===" echo "=== Removing dangling pushers ==="
# Fetch pushers
response=$(curl -s -X GET "${BASE_URL}/pushers" \ response=$(curl -s -X GET "${BASE_URL}/pushers" \
-H "Authorization: Bearer ${TOKEN}" \ -H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json") -H "Content-Type: application/json")
# Loop over pushers if [ -n "$response" ] && echo "$response" | jq -e '.pushers' >/dev/null 2>&1; then
if [ -n "$response" ] && echo "$response" | jq -e '.pushers' >/dev/null; then count=$(echo "$response" | jq '.pushers | length')
echo "Found ${count} pusher(s)."
echo "$response" | jq -c '.pushers[]' | while read -r pusher; do echo "$response" | jq -c '.pushers[]' | while read -r pusher; do
app_id=$(echo "$pusher" | jq -r '.app_id') app_id=$(echo "$pusher" | jq -r '.app_id')
pushkey=$(echo "$pusher" | jq -r '.pushkey') pushkey=$(echo "$pusher" | jq -r '.pushkey')
echo "Removing pusher: ${app_id}..." echo "Removing pusher: ${app_id} (${pushkey})..."
# Delete pusher result=$(curl -s -X POST "${BASE_URL}/pushers/set" \
curl -s -X POST "${BASE_URL}/pushers/set" \
-H "Authorization: Bearer ${TOKEN}" \ -H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$(jq -n --arg id "$app_id" --arg key "$pushkey" \ -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}')")
echo " Done." 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 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 else
echo "No pushers found or failed to fetch pushers." echo "No pushers found or failed to fetch pushers."
fi fi
echo "" echo ""
echo "=== Clearing all notifications ===" echo "=== Clearing all notifications (marking rooms as read) ==="
# Get all rooms
rooms_response=$(curl -s -X GET "${BASE_URL}/joined_rooms" \ rooms_response=$(curl -s -X GET "${BASE_URL}/joined_rooms" \
-H "Authorization: Bearer ${TOKEN}" \ -H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json") -H "Content-Type: application/json")
if [ -n "$rooms_response" ] && echo "$rooms_response" | jq -e '.joined_rooms' >/dev/null; then 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')
export -f process_room || true echo "Found ${room_count} joined room(s)."
process_room() { 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) 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" \ 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 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" \ curl -s -X POST "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/read_markers" \
-H "Authorization: Bearer ${TOKEN}" \ -H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \ -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}" \ curl -s -X POST "${BASE_URL}/rooms/${ENCODED_ROOM_ID}/receipt/m.read/${ENCODED_LATEST}" \
-H "Authorization: Bearer ${TOKEN}" \ -H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "{}" > /dev/null -d "{}" > /dev/null
echo "Marked as read: ${room_id}"
else
echo "No events in: ${room_id}"
fi fi
} }
export -f process_room 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 else
echo "No joined rooms found or failed to fetch rooms." echo "No joined rooms found or failed to fetch rooms."
fi fi