-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtx-riot-install.sh
346 lines (325 loc) · 8 KB
/
mtx-riot-install.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/bash
# Author: @grigruss:matrix.org
echo "Starting the system setup to install matrix-synapse"
echo
echo "The following sources will be added to /etc/apt/sources.list"
echo " 1.http://ftp.debian.org/debian jessie-backports main"
echo " 2.http://matrix.org/packages/debian/ jessie main"
echo
aptq(){
echo "Confirm the changes? [Y/n]:"
read -n -r 1 varapt
aptif
}
aptc(){
if grep "jessie-backports" /etc/apt/sources.list;
then
echo "Have backports"
else
echo "Add backports"
{
echo "# Inserted for installing matrix-synapse & Riot-web"
"deb http://ftp.debian.org/debian jessie-backports main"
} >> /etc/apt/sources.list
fi
if grep "http://matrix.org/packages/debian/ jessie main" /etc/apt/sources.list;
then
echo "Have matrix.org repo"
else
echo "Add matrix.org repo-key"
wget http://matrix.org/packages/debian/repo-key.asc
apt-key add repo-key.asc
rm -rf repo-key.asc
echo "Add matrix.org repo"
{
echo "# Inserted for installing matrix-synapse"
"deb http://matrix.org/packages/debian/ jessie main"
} >> /etc/apt/sources.list
fi
apt-get update
}
aptif(){
if [ "$varapt" == "y" ]
then
echo
aptc
elif [ "$varapt" != "n" ]
then
echo
echo "Only \"y\" or \"n\""
aptq
else
echo
echo "Action canceled, no further installation is not possible."
exit 0
fi
}
aptq
instq(){
echo
echo "Do you want to install matrix-synapse now? [Y/n]"
read -n -r 1 inst
instif
}
instif(){
if [ "$inst" == "y" ]
then
echo
apt-get install python-certbot-apache -t jessie-backports
apt-get install jq curl matrix-synapse
elif [ "$inst" != "n" ]
then
echo
echo "Only \"y\" or \"n\""
instq
else
echo
echo "Action canceled, no further installation is not possible."
exit 0
fi
}
instq
#riotq(){
# echo
# echo "Do you want to install Riot on your site now? [Y/n]"
# read -n -r 1 riot
#}
echo
echo "Enter site path [/var/www/html/]:"
read -r WWW
echo
if [ -z "$WWW" ]
then
WWW="/var/www/html/"
echo "Use the default path"
fi
echo $WWW
content=$(curl https://api.github.com/repos/grigruss/Riot-web-server-update/releases/latest)
download=$(jq -r '.tarball_url' <<<"$content")
echo "Download Riot updator shell script"
curl -Ls "$download" | tar xz --strip-components=1 -C ./
FILE="riot-update.sh"
while read -r LINE; do
if [ "${LINE:5:10}" == "/www/html/" ]
then
www="/www/html/"
echo "${LINE/$www/$WWW}" >> $FILE.new
else
echo "$LINE" >> $FILE.new
fi
done < $FILE
mv $FILE.new $FILE
chmod +x $FILE
echo "Download latest version of Riot-web"
./riot-update.sh
echo
echo "Matrix-synapse and Riot-web are installed."
echo
leq(){
echo
echo "Do you want to receive and configure the Let's Encrypt certificate for your server? [Y/n]"
read -n -r 1 le
leif
}
lem(){
echo
echo "Enter the domain name for matrix-synapse:"
read -r led
if [ -z "$led" ]
then
ler
else
certbot certonly -d "$led" -d "www.$led"
ler
fi
}
ler(){
echo
echo "Do you want to use $led for Riot-web?:"
read -n -r 1 ledr
if [ "$ledr" == "y" ]
then
echo "Ok. Use $led."
lerd=$led
elif [ "$ledr" != "n" ]
then
echo
echo "Only \"y\" or \"n\""
ler
else
echo
echo "Enter the domain name for Riot-web:"
read-r lerd
if [ -z "$lerd" ]
then
ler
else
certbot certonly -d "$lerd" -d "www.$lerd"
fi
fi
}
leif(){
if [ "$le" == "y" ]
then
lem
elif [ "$le" != "n" ]
then
echo
echo "Only \"y\" or \"n\""
leq
else
echo
echo "Action of receive and configure certificate canceled."
fi
}
leq
echo "Domain name for matrix-synapse: $led"
echo "Domain name for Riot-web: $lerd"
python -m synapse.app.homeserver --server-name "$led" --config-path homeserver.yaml --generate-config --report-stats=yes
cp "/etc/letsencrypt/archive/$led/*" /etc/matrix-synapse/
mtxconf(){
HFILE="/etc/matrix-synapse/homeserver.yaml"
while read -r LINE; do
if [[ $LINE == tls_certificate_path* ]]
then
echo "# $LINE">>$HFILE.new
echo "tls_certificate_path: \"/etc/matrix-synapse/cert1.pem\"">>$HFILE.new
elif [[ $LINE == tls_private_key_path* ]]
then
echo "# $LINE">>$HFILE.new
echo "tls_certificate_path: \"/etc/matrix-synapse/privkey1.pem\"">>$HFILE.new
elif [[ $LINE == tls_dh_params_path* ]]
then
echo "# $LINE">>$HFILE.new
echo "tls_certificate_path: \"/etc/matrix-synapse/chain1.pem\"">>$HFILE.new
else
echo "$LINE" >> $HFILE.new
fi
done < $HFILE
mv $HFILE $HFILE.old
mv $HFILE.new $HFILE
echo
echo "Old homeserver.yaml "
}
mtxconfq(){
echo
echo "Do you want to configure matrix-synapse? [y/n]"
read -n -r 1 mtxc
if [ "$mtxc" == "y" ]
then
if [ "$le" == "y" ]
then
mtxconf
fi
echo "homeserver.yaml configured"
elif [ "$mtxc" != "n" ]
then
echo
echo "Only \"y\" or \"n\""
leq
else
echo
echo "Action canceled."
fi
}
mtxconfq
riotconf(){
HFILE="$WWW/config.sample.json"
CFILE="$WWW/config.json"
while read -r LINE; do
if [[ $LINE == *default_hs_url* ]]
then
echo " \"default_hs_url\": \"https://$led:8448\",">>$CFILE
elif [[ $LINE == *default_is_url* ]]
then
echo
echo "Do you want to use your server as an authentication server? [y/n]"
read -n -r 1 ids
if [ "$ids" == "y" ]
then
echo " \"default_is_url\": \"https://$led:8448\",">>$CFILE
else
echo "$LINE" >> $CFILE
fi
elif [[ $LINE == *\"matrix.org\"* ]]
then
echo " \"$lerd\",">>$CFILE
echo "$LINE" >> $CFILE
else
echo "$LINE" >> $CFILE
fi
done < $HFILE
echo
}
riotconfq(){
echo
echo "Do you want to configure Riot-web? [y/n]"
read -n -r 1 mtxc
if [ "$mtxc" == "y" ]
then
if [ "$le" == "y" ]
then
mtxconf
fi
echo "config.json configured"
elif [ "$mtxc" != "n" ]
then
echo
echo "Only \"y\" or \"n\""
leq
else
echo
echo "Action canceled."
fi
}
echo
echo "Setting up a website for Riot-web."
rcf="/etc/apache2/sites-avialable/$lerd.conf"
{
echo "<VirtualHost msg.miacnao.ru:80>"
"RewriteEngine on"
"RewriteCond %{SERVER_NAME} =www.$lerd [OR]"
"RewriteCond %{SERVER_NAME} =$lerd"
"RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]"
"</VirtualHost>"
""
"<IfModule mod_ssl.c>"
"<VirtualHost $lerd:443>"
" ServerAdmin admin@$lerd"
" ServerName $lerd"
" ServerAlias www.$lerd"
" DocumentRoot \"$WWW\""
" DirectoryIndex index.html"
" ErrorLog \"/var/logs/apache2/error.$lerd.log\""
" CustomLog \"/home/www/httpd-logs/access.msg.miacnao.ru.log\" common"
" SSLCertificateFile /etc/letsencrypt/live/$lerd/fullchain.pem"
" SSLCertificateKeyFile /etc/letsencrypt/live/$lerd/privkey.pem"
" Include /etc/letsencrypt/options-ssl-apache.conf"
"</VirtualHost>"
"<Directory $WWW>"
" Options -Indexes"
"</Directory>"
"</IfModule>"
} >> "$rcf"
echo "All done!"
echo "Config files:"
echo "matrix-synapse - /etc/matrix-synapse/homeserver.yaml"
echo "Riot-web - $WWW/config.json"
echo "site for Riot-web - /etc/apache2/sites-avialable/$lerd.conf"
echo
echo "============================================================================"
echo "Check the configuration files, and if everything is OK, run the following commands to start the server:"
echo " systemctl restart matrix-synapse"
echo " systemctl restart apache2"
echo
echo "And follow the link: https://$lerd"
echo "============================================================================"
echo
echo "To automatically update the Riot-web, add the following line to cron (crontab -e):"
echo "============================================================================"
p=$(pwd)
echo "0 0 * * * $p/$FILE"
echo "============================================================================"
echo "This line will cause the update to run every day at 00:00."
echo "The update will only be performed if a new version of Riot-web is available."
echo