This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
forked from austinhuang0131/joinmatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·64 lines (61 loc) · 3.58 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
IFS=$'\n'
Lines=$(cat _includes/matrix_base.md)
Check=1
rm _includes/matrix_prod.md
for Line in $Lines
do
Line=$(echo "$Line" | sed -Ee "s/\\\\\[(\\^[0-9]+)\\\\\]/\[\1\]/g" -Ee "s/\\\\\`/\`/g")
if [[ $Line =~ \[([0-9a-z-]+\.[0-9a-z]+)\] ]]; then
raw="${BASH_REMATCH[1]}"
base=$(curl -Ls -m 10 "https://$raw/.well-known/matrix/server" -A "https://joinmatrix.org/servers" | jq '."m.server"' | sed s/\"//g)
if [[ -z "$base" ]] || [[ "$base" == "null" ]]; then
DNS=$(dig "_matrix._tcp.$raw" SRV +short | sed -E 's/([0-9]+ ){2}//g')
SRV_PORT=$(echo "$DNS" | grep -oE "^[0-9]+")
SRV_DOMAIN=$(echo "$DNS" | grep -oE "([a-z0-9]+\.)+$" | sed 's/\.$//')
if [[ -n "$SRV_DOMAIN" ]]; then
body=$(curl -Ls -m 10 "https://$SRV_DOMAIN/_matrix/federation/v1/version" -A "https://joinmatrix.org/servers")
test=$(echo $body | jq .server)
reg=$(curl -Ls -m 10 -X POST -H "accept: application/json" -H "Content-Type: application/json" "https://$SRV_DOMAIN/_matrix/client/r0/register" -A "https://joinmatrix.org/servers" -d '{}')
if [[ -z "$test" ]] && [[ -n "$SRV_PORT" ]]; then
body=$(curl -Ls -m 10 "https://$SRV_DOMAIN:$SRV_PORT/_matrix/federation/v1/version" -A "https://joinmatrix.org/servers")
fi
else
body=$(curl -Ls -m 10 "https://$raw/_matrix/federation/v1/version" -A "https://joinmatrix.org/servers")
reg=$(curl -Ls -m 10 -X POST -H "accept: application/json" -H "Content-Type: application/json" "https://$raw/_matrix/client/r0/register" -A "https://joinmatrix.org/servers" -d '{}')
test=$(echo $body | jq .server)
if [[ -z "$test" ]]; then
body=$(curl -Ls -m 10 "https://$raw:8448/_matrix/federation/v1/version" -A "https://joinmatrix.org/servers")
fi
fi
else
body=$(curl -Ls -m 10 "https://$base/_matrix/federation/v1/version" -A "https://joinmatrix.org/servers")
client=$(curl -Ls -m 10 "https://$raw/.well-known/matrix/client" -A "https://joinmatrix.org/servers" | jq '."m.homeserver"."base_url"' | sed s/\"//g | sed "s/\/$//g")
reg=$(curl -Ls -m 10 -X POST -H "accept: application/json" -H "Content-Type: application/json" "$client/_matrix/client/r0/register" -A "https://joinmatrix.org/servers" -d '{}')
fi
name=$(echo $body | jq .server.name | sed s/\"//g)
version=$(echo $body | jq .server.version | sed s/\"//g)
closed=$(echo $reg | jq .errcode)
if [[ $Line =~ \[(SSO|Form)\] ]] || [[ $Check -eq 0 ]]; then
closed="null"
fi
if [[ "$name" == "Synapse" ]] && [[ -n "$version" ]] && [[ "$closed" != "\"M_FORBIDDEN\"" ]]; then
echo "$Line $version |" >> _includes/matrix_prod.md
elif [[ -n "$name" ]] && [[ -n "$version" ]] && [[ "$closed" != "\"M_FORBIDDEN\"" ]]; then
echo "$Line $name $version |" >> _includes/matrix_prod.md
elif [[ "$closed" != "\"M_FORBIDDEN\"" ]]; then
echo "$Line Error!! |" >> _includes/matrix_prod.md
fi
elif [[ $Line =~ \|\ \*\* ]]; then
echo >> _includes/matrix_prod.md
echo "$Line **Version** |" >> _includes/matrix_prod.md
elif [[ $Line =~ \|\ \-\- ]]; then
echo "$Line ----------- |" >> _includes/matrix_prod.md
else
echo >> _includes/matrix_prod.md
echo "$Line" >> _includes/matrix_prod.md
if [[ "$Line" == "### Conditional registration" ]]; then
Check=0
fi
fi
done