-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·170 lines (133 loc) · 6.94 KB
/
init.sh
File metadata and controls
executable file
·170 lines (133 loc) · 6.94 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
set -e
## this script will set up your matrix server
## from beginning to end.
## you must have a properly modified host.conf file
## to set these values
if ! [ -f host.conf ]; then
echo "no host.conf file found. please create one by modifying templates/host.conf.sample"
exit 1
fi
source host.conf
echo "setting permissions on acme.json"
mkdir -p storage/traefik/config
touch storage/traefik/config/acme.json
chmod 600 storage/traefik/config/acme.json
echo "moving db-init script into place"
mkdir -p storage/postgresql/
cp templates/init-db.sh storage/postgresql/init-db.sh
echo "adding nginx config file"
mkdir -p storage/nginx/
cp templates/nginx.conf.sample storage/nginx/matrix.conf
sed -i "s/REPLACE_WITH_MATRIX_HOST/$MATRIX_HOST/" storage/nginx/matrix.conf
echo "generating initial synapse config file for $HOSTNAME"
docker run --rm -it \
-v "$PWD/storage/synapse/data:/data" \
-e SYNAPSE_SERVER_NAME=$HOSTNAME \
-e SYNAPSE_REPORT_STATS=yes \
-e UID=${UID} \
-e GID=${UID} \
ghcr.io/element-hq/synapse:${SYNAPSE_VERSION_TAG} generate
echo "config file generated in ./storage/synapse/data/homeserver.yaml"
echo "generating initial MAS config file"
mkdir -p storage/mas/data
docker run --rm \
ghcr.io/element-hq/matrix-authentication-service \
config generate > storage/mas/data/config.yaml
echo "config file generated in ./storage/mas/data/config.yaml"
echo "generating initial maubot config file"
docker run --rm -it \
-v "$PWD/storage/maubot/data:/data" \
dock.mau.dev/maubot/maubot:latest
echo "starting with base docker-compose file"
cp templates/docker-compose.yml.sample docker-compose.yml
echo "replacing UID in docker-compose"
sed -i "s/REPLACE_WITH_UID/${UID}/g" docker-compose.yml
echo "replacing container version tags"
sed -i "s/REPLACE_WITH_SYNAPSE_VERSION_TAG/${SYNAPSE_VERSION_TAG}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_MAS_VERSION_TAG/${MAS_VERSION_TAG}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_ELEMENT_VERSION_TAG/${ELEMENT_VERSION_TAG}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_POSTGRES_VERSION_TAG/${POSTGRES_VERSION_TAG}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_MATRIX_JWT_VERSION_TAG/${MATRIX_JWT_VERSION_TAG}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_LIVEKIT_VERSION_TAG/${LIVEKIT_VERSION_TAG}/g" docker-compose.yml
echo "replacing acme email address"
sed -i "s/REPLACE_WITH_ACME_EMAIL/${ACME_EMAIL}/g" docker-compose.yml
echo "updating PostgreSQL password in docker-compose.yml and init script"
sed -i "s/REPLACE_WITH_POSTGRES_PW/${POSTGRES_PW}/g" storage/postgresql/init-db.sh
sed -i "s/REPLACE_WITH_POSTGRES_MAS_PW/${POSTGRES_MAS_PW}/g" storage/postgresql/init-db.sh
sed -i "s/REPLACE_WITH_POSTGRES_ROOT_PW/${POSTGRES_ROOT_PW}/g" docker-compose.yml
echo "updating docker labels in docker-compose.yml"
sed -i "s/REPLACE_WITH_MATRIX_HOST/${MATRIX_HOST}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_MAS_HOST/${MAS_HOST}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_HOSTNAME/${HOSTNAME}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_SITE_HOST/${SITE_HOST}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_REDIRECT_HOST/${REDIRECT_HOST}/g" docker-compose.yml
sed -i "s/REPLACE_WITH_MATRIX_RTC_HOST/${MATRIX_RTC_HOST}/g" docker-compose.yml
echo "starting with base Element config file"
mkdir -p storage/element/data
cp templates/element.config.json.sample storage/element/data/config.json
echo "updating Element config file"
sed -i "s/REPLACE_WITH_MATRIX_HOST/${MATRIX_HOST}/g" storage/element/data/config.json
sed -i "s/REPLACE_WITH_HOSTNAME/${HOSTNAME}/g" storage/element/data/config.json
echo "updating Element docker labels in docker-compose.yml"
sed -i "s/REPLACE_WITH_ELEMENT_HOST/${ELEMENT_HOST}/g" docker-compose.yml
echo "updating maubot labels in docker-compose.yml"
sed -i "s/REPLACE_WITH_MAUBOT_HOST/${MAUBOT_HOST}/g" docker-compose.yml
echo "modifying synapse config to use postgres instead of sqlite"
sed -i "s/^ name: sqlite3/ name: psycopg2/" storage/synapse/data/homeserver.yaml
sed -i "s#^ database: /data/homeserver.db# user: synapse_user\n password: ${POSTGRES_PW}\n database: synapse\n host: database\n cp_min: 5\n cp_max: 10#" storage/synapse/data/homeserver.yaml
echo "modifying MAS config to use postgres and connect to synapse"
sed -i "s#^ issuer: http://\[::\]:8080/##" storage/mas/data/config.yaml
sed -i "s#^ public_base: http://\[::\]:8080/# public_base: https://${MAS_HOST}/#" storage/mas/data/config.yaml
sed -i "s#^ uri: postgresql://# uri: postgresql://mas_user:${POSTGRES_MAS_PW}@database/mas#" storage/mas/data/config.yaml
sed -i "s#^ homeserver: localhost:8008# homeserver: ${HOSTNAME}#" storage/mas/data/config.yaml
sed -i "s#^ endpoint: http://localhost:8008/# endpoint: https://${MATRIX_HOST}#" storage/mas/data/config.yaml
MAS_SYNAPSE_SHARED_SECRET=$(grep ' secret: ' ./storage/mas/data/config.yaml | awk '{print $2}' | tr -d '\r')
sed -i "s/^# vim:ft=yaml//" ./storage/synapse/data/homeserver.yaml
cat << EOF >> ./storage/synapse/data/homeserver.yaml
matrix_authentication_service:
enabled: true
endpoint: https://${MAS_HOST}/
secret: "${MAS_SYNAPSE_SHARED_SECRET}"
EOF
echo "modifying synapse config to support element-call prerequisites"
cat << EOF >> ./storage/synapse/data/homeserver.yaml
experimental_features:
# MSC3266: Room summary API. Used for knocking over federation
msc3266_enabled: true
# MSC4222 needed for syncv2 state_after. This allow clients to
# correctly track the state of the room.
msc4222_enabled: true
# The maximum allowed duration by which sent events can be delayed, as
# per MSC4140.
max_event_delay_duration: 24h
rc_message:
# This needs to match at least e2ee key sharing frequency plus a bit of headroom
# Note key sharing events are bursty
per_second: 0.5
burst_count: 30
rc_delayed_event_mgmt:
# This needs to match at least the heart-beat frequency plus a bit of headroom
# Currently the heart-beat is every 5 seconds which translates into a rate of 0.2s
per_second: 1
burst_count: 20
EOF
echo "starting with sample livekit config file"
mkdir -p ./storage/livekit/data
cp ./templates/livekit.config.sample ./storage/livekit/data/config.yaml
echo "generating key/secret for livekit"
livekit_key=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 10)
livekit_secret=$(tr -dc 'a-zA-Z0-9' < /dev/urandom | head -c 40)
echo "injecting key/secret into livekit config and docker-compose"
sed -i "s/REPLACE_WITH_LIVEKIT_KEY/${livekit_key}/" ./storage/livekit/data/config.yaml ./docker-compose.yml
sed -i "s/REPLACE_WITH_LIVEKIT_SECRET/${livekit_secret}/" ./storage/livekit/data/config.yaml ./docker-compose.yml
#echo "starting everything up..."
#docker compose up -d
echo ""
echo ""
echo "================="
echo 'you can now inspect your generated files. configs and persistent storage is in the folder named "storage".
run "docker compose up -d" to launch your services, and wait a few minutes for SSL certificates to be generated by LetsEncrypt.
interactively create your first matrix user with the ./register.sh script. have fun!'
echo ""
echo "done"