Browse Source

Merge pull request #1 from joe/dev

dev=>master
master
Joe 1 year ago
parent
commit
d3aa1a6971
3 changed files with 79 additions and 38 deletions
  1. +0
    -38
      matrix-synapse_purge-remote-media.sh
  2. +45
    -0
      rmk.sh
  3. +34
    -0
      tools/vupdate.sh

+ 0
- 38
matrix-synapse_purge-remote-media.sh View File

@ -1,38 +0,0 @@
#!/bin/bash
version=0.0.2
UserInput() {
read -r -p "$(echo -e 'Domain:\n')" domain
read -r -p "$(echo -e 'Time:\n')" time
read -r -p "$(echo -e 'Token:\n')" token
}
ExecutePurge() {
echo 'Purging remote media, please wait.'
UntilLoop "https://$1/_synapse/admin/v1/purge_media_cache?before_ts=$2&access_token=$3" "error"
echo 'Error encountered. Please try again.'
}
UntilLoop() {
until curl -X POST "$1" --data '{}' \
grep -m 1 "$2"; do
sleep 1
done
}
UnixTimeMs() {
unix_time_ms="$(($(date -d "$1" +'%s') * 1000))"
}
EchoVersion() {
echo $version
}
main() {
EchoVersion;
UserInput;
UnixTimeMs "$time";
ExecutePurge "$domain" "$unix_time_ms" "$token"
}
main

+ 45
- 0
rmk.sh View File

@ -0,0 +1,45 @@
#!/bin/bash
name="Remote Media Killer"
version=1.0.0
author="Joe"
license="GNU GPLv3"
UserInput() {
read -r -p "$(echo -e 'Domain:')" domain
read -r -p "$(echo -e 'Time:')" time
read -s -r -p "$(echo -e 'Token:')" token
}
ExecutePurge() {
echo 'Purging remote media, please wait.'
curl -X POST "https://$1/_synapse/admin/v1/purge_media_cache?before_ts=$2&access_token=$3" --data '{}'
}
UnixTimeMs() {
unix_time_ms="$(($(date -d "$1" +'%s') * 1000))"
}
DomainCheck() {
local result=$(perl -pe 's/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)/pass/g' <<< "$1")
if [ "$result" = "pass" ]; then
return 0;
else
echo -e '\nError: Not a valid domain.\n'
exit 1;
fi
}
EchoInfo() {
echo "$name $version - Licensed $license by $author"
}
main() {
EchoInfo;
UserInput;
DomainCheck "$domain";
UnixTimeMs "$time";
ExecutePurge "$domain" "$unix_time_ms" "$token"
}
main

+ 34
- 0
tools/vupdate.sh View File

@ -0,0 +1,34 @@
#!/bin/bash
UserInput() {
read -r -p "$(echo -e 'New version: ')" version
read -e -r -p "$(echo -e 'File: ')" file
}
SedFindReplace() {
local rex='([0-9]{1,}\.[0-9]{1,}\.[0-9]{1,})'
sed -i -E "s/$rex/$1/g" "$2"
}
BashFindReplace() {
in=$2
rex='[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}'
while [[ $in =~ $rex ]]; do
in=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
done
}
main() {
UserInput
SedFindReplace "$version" "$file"
# BashFindReplace "$version" "$file"
}
while getopts a option
do
case "$option" in
a ) SedFindReplace "$2" "matrix-synapse_purge-remote-media.sh"; exit 0;;
esac
done
main

Loading…
Cancel
Save