summary refs log tree commit diff
path: root/host/Rory-nginx/hooks/post-rebuild.sh
blob: 9b0c17c62daa5cef9fe156e60ccdc17f2f5a18a5 (plain) (blame)
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
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl gnused nix coreutils jq openssl
#set -x
REG_KEY=`cat /var/lib/matrix-synapse/registration_shared_secret.txt`
LOCALPART='rory.gay'
REACHABLE_DOMAIN='http://localhost:8008'

# -- LICENSE: CNPL v7+ - https://thufie.lain.haus/files/CNPLv7.md
# Modified from Nyaaori (https://nyaaori.cat) <+@nyaaori.cat>
# Explicit authorisation to use the code has been granted by the original author
#  for use by members of the Rory& system (https://rory.gay)

# the magic function:
register(){
	echo "Registering $1"
	_nonce=`curl -s http://localhost:8008/_synapse/admin/v1/register | jq -r .nonce`
	#data: nonce, domain, username, password
	_hmac=`printf '%s\0%s\0%s\0%s' "$_nonce" "$1" "$2" "admin" |  openssl dgst -sha1 -hmac "$REG_KEY" |  awk '{print $2}'`
	curl -s -XPOST -d '{"nonce": "'"$_nonce"'", "username": "'"$1"'", "displayname": "'"$1"'", "password": "'"$2"'", "admin": true, "mac": "'"$_hmac"'"}' $REACHABLE_DOMAIN/_synapse/admin/v1/register | tee -a matrix-user-tokens.txt
	echo
}

# -- END OF LICENSED CODE

PASSWD=`cat /etc/matrix-user-pass`
for u in {draupnir,Alicia,Emma,Rory,root,Quetzelle}
do 
	register $u $PASSWD
done