Init
This commit is contained in:
parent
78d307fba6
commit
7388991ef9
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Cleanup of local and remote media
|
||||
#
|
||||
|
||||
# Requirements:
|
||||
# You'll need the domain of your server (variable "serverDomain").
|
||||
#
|
||||
# For authentication, you will need the access token of your (admin) account.
|
||||
# You can obtain it in your Element client: "All settings" > "Help & About" > scroll down > click on "<click to reveal>" to get your access token.
|
||||
# Copy this token and paste it further down (variable "token").
|
||||
#
|
||||
# You can also specify another time span for deleting media.
|
||||
# Default is media, which was not accessed over the last 60 days (variable "timestamp60DaysAgo")
|
||||
#
|
||||
# You can automate this script via cron, e.g. cleanup every night:
|
||||
# 0 1 * * * /path/to/scripts/Matrix-Synapse-Helpers/CleanupMedia.sh > /dev/null 2>&1
|
||||
|
||||
serverDomain="matrix.mydomain.com"
|
||||
token="insert-token-here"
|
||||
timestamp60DaysAgo=`date +%s000 --date "60 days ago"`
|
||||
|
||||
# Delete local media
|
||||
echo "Delete local media..."
|
||||
echo ""
|
||||
curlUrl="http://localhost:8008/_synapse/admin/v1/media/$serverDomain/delete?before_ts=$timestamp60DaysAgo&access_token=$token"
|
||||
curl -XPOST $curlUrl
|
||||
echo ""
|
||||
echo "Done"
|
||||
echo ""
|
||||
|
||||
# Purge remote media
|
||||
echo "Purge remote media..."
|
||||
echo ""
|
||||
curlUrl="http://localhost:8008/_synapse/admin/v1/purge_media_cache?before_ts=$timestamp60DaysAgo&access_token=$token"
|
||||
curl -XPOST $curlUrl
|
||||
echo ""
|
||||
echo "Done"
|
||||
echo ""
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
#
|
||||
# Gets the access token of a Matrix Synapse account using curl.
|
||||
#
|
||||
|
||||
# The following variables have to be set individually.
|
||||
serverDomain="matrix.mydomain.com"
|
||||
user="MYUSER"
|
||||
password="MYPASSWORD"
|
||||
|
||||
json="{\"type\":\"m.login.password\", \"user\":\"$user\", \"password\":\"$password\"}"
|
||||
response=$(curl --silent -w "\n%{http_code}" -XPOST -d "$json" "https://$serverDomain/_matrix/client/r0/login")
|
||||
http_code=$(tail -n1 <<< "$response")
|
||||
content=$(sed '$ d' <<< "$response")
|
||||
|
||||
if [[ "$http_code" -ne 200 ]] ; then
|
||||
echo "Error: $content"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Your access token:"
|
||||
echo ""
|
||||
|
||||
echo $content
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
Loading…
Reference in New Issue