This commit is contained in:
creme 2021-08-01 14:34:00 +02:00
commit 490b2ecba7
No known key found for this signature in database
GPG key ID: C147C3B7FBDF08D0
39 changed files with 5451 additions and 0 deletions

View file

@ -0,0 +1,58 @@
#!/usr/bin/env bash
#
# you dont need to stop synapse.
#
DOMAIN=''
TOKEN=''
file_rooms='/tmp/matrix_rooms.txt'
file_obsolet_rooms='/tmp/matrix_obsolet_rooms.txt'
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
d) DOMAIN="$OPTARG" ;;
t) TOKEN="$OPTARG" ;;
\?) printf 'Invalid option: -%s\n\n' "$OPTARG" ; print_usage ;;
h|*) print_usage ;;
esac
done
if [ -z "$DOMAIN" ] || [ "$DOMAIN" == '-t' ]; 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=10000" | \
jq -M '.rooms[] | .room_id' > $file_rooms
sed -i 's/"//g' $file_rooms
while IFS= read -r room_id
do
curl -s -X GET -H "Authorization: Bearer $TOKEN" "https://$DOMAIN/_synapse/admin/v1/rooms/$room_id/state" | \
jq -M '.state[] | select(.type == "m.room.tombstone") | .room_id' >> $file_obsolet_rooms
done < $file_rooms
sed -i 's/"//g' $file_obsolet_rooms
printf '\nobsolet rooms:\n'
cat $file_obsolet_rooms
#while IFS= read -r room_id
#do
# printf 'remove room %s\n' "$room_id"
# curl -s -X POST -H "Authorization: Bearer $TOKEN" "https://$DOMAIN/_synapse/admin/v1/rooms/$room_id/delete" \
# -d "{ \"new_room_user_id\": \"@notices:$DOMAIN\", \"room_name\": \"Content Notification\", \"message\": \"remove obsolet room $room_id.\", \"block\": false, \"purge\": true, \"force-purge\": true }"
# printf 'done.\n'
#done < $file_obsolet_rooms
rm $file_rooms $file_obsolet_rooms
#
exit 0

View file

@ -0,0 +1,47 @@
#!/usr/bin/env bash
#
# you dont need to stop synapse.
#
DOMAIN=''
TOKEN=''
tmp_file='/tmp/matrix_rooms_to_purge.txt'
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
d) DOMAIN="$OPTARG" ;;
t) TOKEN="$OPTARG" ;;
\?) printf 'Invalid option: -%s\n\n' "$OPTARG" ; print_usage ;;
h|*) print_usage ;;
esac
done
if [ -z "$DOMAIN" ] || [ "$DOMAIN" == '-t' ]; 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=10000" | \
jq -M '.rooms[] | select(.joined_local_members == 0) | .room_id' > $tmp_file
sed -i 's/"//g' $tmp_file
while IFS= read -r room_id
do
printf 'remove room %s ' "$room_id"
curl -s -X POST -H "Authorization: Bearer $TOKEN" "https://$DOMAIN/_synapse/admin/v1/purge_room" \
-H "Content-Type: application/json" -d "{ \"room_id\": \"$room_id\" }"
printf ' done.\n'
done < $tmp_file
rm $tmp_file
#
exit 0

View file

@ -0,0 +1,76 @@
#!/bin/sh
#
# you dont need to stop synapse.
#
# from: https://jo-so.de/2018-03/Matrix.html#state_groups_stateaufrumen
#
# this script used:
# https://github.com/matrix-org/rust-synapse-compress-state
#
## start task via:
# $ sudo systemd-run --nice=4 -pCPUSchedulingPolicy=batch \
# -pIOSchedulingClass=idle --uid=matrix-synapse --collect \
# --unit=synapse-clear-state ~/bin/synapse-clear-state
#
## watch task-log via:
# $ journalctl -Stoday -u synapse-clear-state -f
#
set -e -u
username='matrix'
db='matrix'
conn_str="host=localhost user=$username dbname=$db application_name=state_compress"
###
export RUST_BACKTRACE=short LC_ALL=C.UTF-8
if which time >/dev/null
then
export TIME='%E elapsed %M rss'
time=time
else
time=
fi
cd "$(mktemp -d)"
echo "Writing SQL files to $PWD"
if [ $# -eq 0 ]
then
set -- $(psql -X -t -A -U "$username" -c 'SELECT room_id FROM state_groups
GROUP BY room_id ORDER BY count(*)' $db)
fi
echo 'Disabling autovacuum on state_groups_state'
psql -X -q -b -U "$username" -c 'alter table state_groups_state set (autovacuum_enabled = false);' $db
no=0
for room in $*
do
echo '--------------------'
echo
sql_file=state-compress-$((no += 1)).sql
echo "Writing SQL commands to $sql_file"
$time synapse-compress-state -t -p "$conn_str" -o "$sql_file" -r "$room" -m 1000
if test -s "$sql_file"
then
$time psql -X -q -b -U "$username" -c '\set ON_ERROR_STOP on' -f "$sql_file" $db
else
rm "$sql_file"
fi
done
echo 'Enabling autovacuum on state_groups_state'
psql -X -q -b -U "$username" -c 'alter table state_groups_state set (autovacuum_enabled = true);' $db
echo 'Running VACUUM and ANALYZE for state_groups_state ...'
$time psql -X -q -b -U "$username" -c 'VACUUM FULL ANALYZE state_groups_state' $db
echo "All SQL scripts are in $PWD"
exit 0

View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
[ "$(id -u)" -ne 0 ] && printf 'Please run as root!\n' && exit 1
ver="$1"
[ -z "$ver" ] && printf 'use: %s <version>\n' "${0##*/}" && exit 1
systemctl stop matrix-media.service
wget -O /opt/matrix-media-repo/media_repo-linux-x64 https://github.com/turt2live/matrix-media-repo/releases/download/v"$ver"/media_repo-linux-x64
chmod +x /opt/matrix-media-repo/media_repo-linux-x64
wget -O /opt/matrix-media-repo/config.sample.yaml https://raw.githubusercontent.com/turt2live/matrix-media-repo/master/config.sample.yaml
systemctl start matrix-media.service
exit 0

45
usr/local/bin/update_riot.sh Executable file
View file

@ -0,0 +1,45 @@
#!/usr/bin/env bash
[[ ! -d /opt/Riot/resources ]] && mkdir -p /opt/Riot/resources
cd /opt/Riot/resources
old_version="v$(cat webapp/version)"
version="latest"
if [[ ! -z "$1" ]]; then
version="tags/$1"
fi
echo "Fetching latest release info from GitHub"
version_info=$(curl -s "https://api.github.com/repositories/39487546/releases/$version")
new_version=$(echo "$version_info" | jq -r '.name')
URL=$(echo "$version_info" | jq -r '.assets[0].browser_download_url')
if [[ "$new_version" == "$old_version" ]]; then
echo "No updates found"
exit
fi
# Remove previous backup riot
rm -rf riot.bak
# Create temp directory for new riot
mkdir riot.new
cd riot.new
echo "Downloading Riot $new_version"
curl -L "$URL" -o riot-tmp.tar.gz
echo "Unpacking archive"
tar -xzf riot-tmp.tar.gz --strip-components=1
rm -f riot-tmp.tar.gz
echo "Replacing files"
cd ..
cp -f webapp/config.json riot.new/config.json
# Back up old version and activate new version
mv webapp webapp.bak
mv riot.new webapp
echo "Updated to Riot from $old_version to $new_version"
exit 0