52 lines
1.5 KiB
Bash
52 lines
1.5 KiB
Bash
#!/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=""
|
|
token=""
|
|
# You may to customize this time span to fit your needs.
|
|
timestamp60DaysAgo=`date +%s000 --date "60 days ago"`
|
|
|
|
if [ -z "$serverDomain" ]
|
|
then
|
|
read -p "Enter the Matrix server domain: (e.g. matrix.mydomain.com): " serverDomain
|
|
echo ""
|
|
fi
|
|
|
|
if [ -z "$token" ]
|
|
then
|
|
read -p "Enter your access token: " token
|
|
echo ""
|
|
fi
|
|
|
|
# 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 "" |