|
@@ -0,0 +1,288 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# .---. . .
|
|
4
|
+# | | |
|
|
5
|
+# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
+# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
+# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
+#
|
|
9
|
+# Freedom in the Cloud
|
|
10
|
+#
|
|
11
|
+# Riot Web user interface for Matrix
|
|
12
|
+#
|
|
13
|
+# License
|
|
14
|
+# =======
|
|
15
|
+#
|
|
16
|
+# Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
|
|
17
|
+#
|
|
18
|
+# This program is free software: you can redistribute it and/or modify
|
|
19
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
20
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
21
|
+# (at your option) any later version.
|
|
22
|
+#
|
|
23
|
+# This program is distributed in the hope that it will be useful,
|
|
24
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26
|
+# GNU Affero General Public License for more details.
|
|
27
|
+#
|
|
28
|
+# You should have received a copy of the GNU Affero General Public License
|
|
29
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30
|
+
|
|
31
|
+VARIANTS='full full-vim chat'
|
|
32
|
+
|
|
33
|
+IN_DEFAULT_INSTALL=0
|
|
34
|
+SHOW_ON_ABOUT=1
|
|
35
|
+
|
|
36
|
+RIOT_VERSION='0.9.9'
|
|
37
|
+RIOT_FILENAME="vector-v${RIOT_VERSION}"
|
|
38
|
+RIOT_HASH='209cd3eee841c208dfb8ec1c4558667471b0c4373d87138210205b83f1a7c97b'
|
|
39
|
+RIOT_DOWNLOAD_URL="https://github.com/vector-im/riot-web/releases/download/v${RIOT_VERSION}"
|
|
40
|
+RIOT_ONION_PORT=8115
|
|
41
|
+RIOT_ONION_HOSTNAME=
|
|
42
|
+RIOT_DOMAIN_NAME=
|
|
43
|
+RIOT_CODE=
|
|
44
|
+
|
|
45
|
+riot_variables=(MY_USERNAME
|
|
46
|
+ RIOT_DOMAIN_NAME
|
|
47
|
+ MATRIX_DOMAIN_NAME
|
|
48
|
+ SYSTEM_TYPE
|
|
49
|
+ DDNS_PROVIDER)
|
|
50
|
+
|
|
51
|
+function remove_user_riot {
|
|
52
|
+ echo -n ''
|
|
53
|
+}
|
|
54
|
+
|
|
55
|
+function add_user_riot {
|
|
56
|
+ echo '0'
|
|
57
|
+}
|
|
58
|
+
|
|
59
|
+function install_interactive_riot {
|
|
60
|
+ if [[ $ONION_ONLY != "no" ]]; then
|
|
61
|
+ RIOT_DOMAIN_NAME='riot.local'
|
|
62
|
+ else
|
|
63
|
+ RIOT_DETAILS_COMPLETE=
|
|
64
|
+ while [ ! $RIOT_DETAILS_COMPLETE ]
|
|
65
|
+ do
|
|
66
|
+ data=$(tempfile 2>/dev/null)
|
|
67
|
+ trap "rm -f $data" 0 1 2 5 15
|
|
68
|
+ if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
|
|
69
|
+ dialog --backtitle $"Freedombone Configuration" \
|
|
70
|
+ --title $"Riot Web user interface for Matrix" \
|
|
71
|
+ --form $"\nPlease enter your details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
|
|
72
|
+ $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
|
|
73
|
+ $"Code:" 2 1 "$(grep 'RIOT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
|
|
74
|
+ 2> $data
|
|
75
|
+ else
|
|
76
|
+ dialog --backtitle $"Freedombone Configuration" \
|
|
77
|
+ --title $"Riot Web user interface for Matrix" \
|
|
78
|
+ --form $"\nPlease enter your details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 2 \
|
|
79
|
+ $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
|
|
80
|
+ 2> $data
|
|
81
|
+ fi
|
|
82
|
+ sel=$?
|
|
83
|
+ case $sel in
|
|
84
|
+ 1) exit 1;;
|
|
85
|
+ 255) exit 1;;
|
|
86
|
+ esac
|
|
87
|
+ RIOT_DOMAIN_NAME=$(cat $data | sed -n 1p)
|
|
88
|
+ if [ $RIOT_DOMAIN_NAME ]; then
|
|
89
|
+ TEST_DOMAIN_NAME=$RIOT_DOMAIN_NAME
|
|
90
|
+ validate_domain_name
|
|
91
|
+ if [[ $TEST_DOMAIN_NAME != $RIOT_DOMAIN_NAME ]]; then
|
|
92
|
+ RIOT_DOMAIN_NAME=
|
|
93
|
+ dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
|
|
94
|
+ else
|
|
95
|
+ if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
|
|
96
|
+ RIOT_CODE=$(cat $data | sed -n 2p)
|
|
97
|
+ validate_freedns_code "$RIOT_CODE"
|
|
98
|
+ if [ ! $VALID_CODE ]; then
|
|
99
|
+ RIOT_DOMAIN_NAME=
|
|
100
|
+ fi
|
|
101
|
+ fi
|
|
102
|
+ fi
|
|
103
|
+ fi
|
|
104
|
+ if [ $RIOT_DOMAIN_NAME ]; then
|
|
105
|
+ RIOT_DETAILS_COMPLETE="yes"
|
|
106
|
+ fi
|
|
107
|
+ done
|
|
108
|
+
|
|
109
|
+ # save the results in the config file
|
|
110
|
+ write_config_param "RIOT_CODE" "$RIOT_CODE"
|
|
111
|
+ fi
|
|
112
|
+ write_config_param "RIOT_DOMAIN_NAME" "$RIOT_DOMAIN_NAME"
|
|
113
|
+ APP_INSTALLED=1
|
|
114
|
+}
|
|
115
|
+
|
|
116
|
+function reconfigure_riot {
|
|
117
|
+ echo -n ''
|
|
118
|
+}
|
|
119
|
+
|
|
120
|
+function upgrade_riot {
|
|
121
|
+ set_repo_commit /var/www/$RIOT_DOMAIN_NAME/htdocs "riot commit" "$RIOT_COMMIT" $RIOT_REPO
|
|
122
|
+}
|
|
123
|
+
|
|
124
|
+function backup_local_riot {
|
|
125
|
+ echo -n ''
|
|
126
|
+}
|
|
127
|
+
|
|
128
|
+function restore_local_riot {
|
|
129
|
+ echo -n ''
|
|
130
|
+}
|
|
131
|
+
|
|
132
|
+function backup_remote_riot {
|
|
133
|
+ echo -n ''
|
|
134
|
+}
|
|
135
|
+
|
|
136
|
+function restore_remote_riot {
|
|
137
|
+ echo -n ''
|
|
138
|
+}
|
|
139
|
+
|
|
140
|
+function remove_riot {
|
|
141
|
+ function_check remove_onion_service
|
|
142
|
+ remove_onion_service riot ${RIOT_ONION_PORT}
|
|
143
|
+ nginx_dissite $RIOT_DOMAIN_NAME
|
|
144
|
+ if [ -f /etc/nginx/sites-available/$RIOT_DOMAIN_NAME ]; then
|
|
145
|
+ rm /etc/nginx/sites-available/$RIOT_DOMAIN_NAME
|
|
146
|
+ fi
|
|
147
|
+ remove_completion_param install_riot
|
|
148
|
+ sed -i '/riot /d' $COMPLETION_FILE
|
|
149
|
+}
|
|
150
|
+
|
|
151
|
+function install_riot {
|
|
152
|
+ # check that matrix has been installed
|
|
153
|
+ if [ ! $MATRIX_DOMAIN_NAME ]; then
|
|
154
|
+ exit 687292
|
|
155
|
+ fi
|
|
156
|
+ if [[ "$MATRIX_DOMAIN_NAME" != *'.'* ]]; then
|
|
157
|
+ exit 256288
|
|
158
|
+ fi
|
|
159
|
+ if [ ! -d /var/lib/matrix ]; then
|
|
160
|
+ exit 827334
|
|
161
|
+ fi
|
|
162
|
+
|
|
163
|
+ apt-get -yq install wget
|
|
164
|
+
|
|
165
|
+ if [ ! -d /var/www/$RIOT_DOMAIN_NAME/htdocs ]; then
|
|
166
|
+ mkdir -p /var/www/$RIOT_DOMAIN_NAME/htdocs
|
|
167
|
+ fi
|
|
168
|
+
|
|
169
|
+ if [ ! -d $INSTALL_DIR ]; then
|
|
170
|
+ mkdir $INSTALL_DIR
|
|
171
|
+ fi
|
|
172
|
+
|
|
173
|
+ # download
|
|
174
|
+ if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
|
|
175
|
+ wget ${RIOT_DOWNLOAD_URL}/${RIOT_FILENAME}.tar.gz -O $INSTALL_DIR/${RIOT_FILENAME}.tar.gz
|
|
176
|
+ fi
|
|
177
|
+ if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
|
|
178
|
+ echo $'Unable to download Riot Web from releases'
|
|
179
|
+ exit 62836
|
|
180
|
+ fi
|
|
181
|
+ cd $INSTALL_DIR
|
|
182
|
+
|
|
183
|
+ # check the hash
|
|
184
|
+ curr_hash=$(sha256sum ${RIOT_FILENAME}.tar.gz | awk -F ' ' '{print $1}')
|
|
185
|
+ if [[ "$curr_hash" != "$RIOT_HASH" ]]; then
|
|
186
|
+ echo $'Riot download hash does not match'
|
|
187
|
+ exit 78352
|
|
188
|
+ fi
|
|
189
|
+
|
|
190
|
+ tar -xzvf ${RIOT_FILENAME}.tar.gz
|
|
191
|
+ if [ ! -d $INSTALL_DIR/${RIOT_FILENAME} ]; then
|
|
192
|
+ echo $'Unable to extract Riot Web tarball'
|
|
193
|
+ exit 542826
|
|
194
|
+ fi
|
|
195
|
+ cp -r $INSTALL_DIR/${RIOT_FILENAME}/* /var/www/$RIOT_DOMAIN_NAME/htdocs
|
|
196
|
+ cd /var/www/$RIOT_DOMAIN_NAME/htdocs
|
|
197
|
+ cp config.sample.json config.json
|
|
198
|
+
|
|
199
|
+ sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" config.json
|
|
200
|
+ sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" config.json
|
|
201
|
+ sed -i "s|\"integrations_ui_url\":.*|\"integrations_ui_url\": \"https://${MATRIX_DOMAIN_NAME}/\",|g" config.json
|
|
202
|
+ sed -i "s|\"integrations_rest_url\":.*|\"integrations_rest_url\": \"https://${MATRIX_DOMAIN_NAME}/api\",|g" config.json
|
|
203
|
+ sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"https://${MATRIX_DOMAIN_NAME}/bugs\",|g" config.json
|
|
204
|
+
|
|
205
|
+ RIOT_ONION_HOSTNAME=$(add_onion_service riot 80 ${RIOT_ONION_PORT})
|
|
206
|
+
|
|
207
|
+ riot_nginx_site=/etc/nginx/sites-available/$RIOT_DOMAIN_NAME
|
|
208
|
+ if [[ $ONION_ONLY == "no" ]]; then
|
|
209
|
+ function_check nginx_http_redirect
|
|
210
|
+ nginx_http_redirect $RIOT_DOMAIN_NAME
|
|
211
|
+ echo 'server {' >> $riot_nginx_site
|
|
212
|
+ echo ' listen 443 ssl;' >> $riot_nginx_site
|
|
213
|
+ echo ' listen [::]:443 ssl;' >> $riot_nginx_site
|
|
214
|
+ echo " server_name $RIOT_DOMAIN_NAME;" >> $riot_nginx_site
|
|
215
|
+ echo '' >> $riot_nginx_site
|
|
216
|
+ echo ' # Security' >> $riot_nginx_site
|
|
217
|
+ function_check nginx_ssl
|
|
218
|
+ nginx_ssl $RIOT_DOMAIN_NAME
|
|
219
|
+
|
|
220
|
+ function_check nginx_disable_sniffing
|
|
221
|
+ nginx_disable_sniffing $RIOT_DOMAIN_NAME
|
|
222
|
+
|
|
223
|
+ echo ' add_header Strict-Transport-Security max-age=15768000;' >> $riot_nginx_site
|
|
224
|
+ echo '' >> $riot_nginx_site
|
|
225
|
+ echo ' # Logs' >> $riot_nginx_site
|
|
226
|
+ echo ' access_log /dev/null;' >> $riot_nginx_site
|
|
227
|
+ echo ' error_log /dev/null;' >> $riot_nginx_site
|
|
228
|
+ echo '' >> $riot_nginx_site
|
|
229
|
+ echo ' # Root' >> $riot_nginx_site
|
|
230
|
+ echo " root /var/www/$RIOT_DOMAIN_NAME/htdocs;" >> $riot_nginx_site
|
|
231
|
+ echo '' >> $riot_nginx_site
|
|
232
|
+ echo ' index index.html' >> $riot_nginx_site
|
|
233
|
+ echo '' >> $riot_nginx_site
|
|
234
|
+ echo ' location / {' >> $riot_nginx_site
|
|
235
|
+ function_check nginx_limits
|
|
236
|
+ nginx_limits $RIOT_DOMAIN_NAME '15m'
|
|
237
|
+ echo ' }' >> $riot_nginx_site
|
|
238
|
+ echo '' >> $riot_nginx_site
|
|
239
|
+ nginx_keybase ${RIOT_DOMAIN_NAME}
|
|
240
|
+ echo '}' >> $riot_nginx_site
|
|
241
|
+ echo '' >> $riot_nginx_site
|
|
242
|
+ else
|
|
243
|
+ echo -n '' > $riot_nginx_site
|
|
244
|
+ fi
|
|
245
|
+ echo 'server {' >> $riot_nginx_site
|
|
246
|
+ echo " listen 127.0.0.1:$RIOT_ONION_PORT default_server;" >> $riot_nginx_site
|
|
247
|
+ echo " server_name $RIOT_ONION_HOSTNAME;" >> $riot_nginx_site
|
|
248
|
+ echo '' >> $riot_nginx_site
|
|
249
|
+ function_check nginx_disable_sniffing
|
|
250
|
+ nginx_disable_sniffing $RIOT_DOMAIN_NAME
|
|
251
|
+ echo '' >> $riot_nginx_site
|
|
252
|
+ echo ' # Logs' >> $riot_nginx_site
|
|
253
|
+ echo ' access_log /dev/null;' >> $riot_nginx_site
|
|
254
|
+ echo ' error_log /dev/null;' >> $riot_nginx_site
|
|
255
|
+ echo '' >> $riot_nginx_site
|
|
256
|
+ echo ' # Root' >> $riot_nginx_site
|
|
257
|
+ echo " root /var/www/$RIOT_DOMAIN_NAME/htdocs;" >> $riot_nginx_site
|
|
258
|
+ echo '' >> $riot_nginx_site
|
|
259
|
+ echo ' index index.html' >> $riot_nginx_site
|
|
260
|
+ echo '' >> $riot_nginx_site
|
|
261
|
+ echo ' location / {' >> $riot_nginx_site
|
|
262
|
+ function_check nginx_limits
|
|
263
|
+ nginx_limits $RIOT_DOMAIN_NAME '15m'
|
|
264
|
+ echo ' }' >> $riot_nginx_site
|
|
265
|
+ echo '' >> $riot_nginx_site
|
|
266
|
+ nginx_keybase ${RIOT_DOMAIN_NAME}
|
|
267
|
+ echo '}' >> $riot_nginx_site
|
|
268
|
+
|
|
269
|
+ function_check create_site_certificate
|
|
270
|
+ if [ ! -f /etc/ssl/certs/${RIOT_DOMAIN_NAME}.pem ]; then
|
|
271
|
+ create_site_certificate $RIOT_DOMAIN_NAME 'yes'
|
|
272
|
+ fi
|
|
273
|
+
|
|
274
|
+ function_check nginx_ensite
|
|
275
|
+ nginx_ensite $RIOT_DOMAIN_NAME
|
|
276
|
+
|
|
277
|
+ function_check add_ddns_domain
|
|
278
|
+ add_ddns_domain $RIOT_DOMAIN_NAME
|
|
279
|
+
|
|
280
|
+ chown -R www-data:www-data /var/www/$RIOT_DOMAIN_NAME/htdocs
|
|
281
|
+
|
|
282
|
+ systemctl restart nginx
|
|
283
|
+
|
|
284
|
+ set_completion_param "riot domain" "$RIOT_DOMAIN_NAME"
|
|
285
|
+ APP_INSTALLED=1
|
|
286
|
+}
|
|
287
|
+
|
|
288
|
+# NOTE: deliberately no exit 0
|