|
@@ -215,6 +215,162 @@ function remove_cryptpad {
|
215
|
215
|
userdel -r cryptpad
|
216
|
216
|
}
|
217
|
217
|
|
|
218
|
+function mesh_install_cryptpad {
|
|
219
|
+ if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
|
|
220
|
+ return
|
|
221
|
+ fi
|
|
222
|
+
|
|
223
|
+ if [ ! -d $rootdir/var/www/cryptpad ]; then
|
|
224
|
+ mkdir $rootdir/var/www/cryptpad
|
|
225
|
+ fi
|
|
226
|
+ if [ -d $rootdir$CRYPTPAD_DIR ]; then
|
|
227
|
+ rm -rf $rootdir$CRYPTPAD_DIR
|
|
228
|
+ fi
|
|
229
|
+
|
|
230
|
+ git_clone $CRYPTPAD_REPO $rootdir$CRYPTPAD_DIR
|
|
231
|
+
|
|
232
|
+ if [ ! -d $rootdir$CRYPTPAD_DIR ]; then
|
|
233
|
+ echo $'Unable to clone cryptpad repo'
|
|
234
|
+ exit 783251
|
|
235
|
+ fi
|
|
236
|
+
|
|
237
|
+ # an unprivileged user to run as
|
|
238
|
+ chroot "$rootdir" useradd -d $CRYPTPAD_DIR/ cryptpad
|
|
239
|
+
|
|
240
|
+ cd $rootdir$CRYPTPAD_DIR
|
|
241
|
+ git checkout $CRYPTPAD_COMMIT -b $CRYPTPAD_COMMIT
|
|
242
|
+
|
|
243
|
+ chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
|
|
244
|
+
|
|
245
|
+ cryptpad_nginx_site=$rootdir/etc/nginx/sites-available/cryptpad
|
|
246
|
+ echo 'server {' > $cryptpad_nginx_site
|
|
247
|
+ echo " listen 80 default_server;" >> $cryptpad_nginx_site
|
|
248
|
+ echo " server_name P${PEER_ID}.local;" >> $cryptpad_nginx_site
|
|
249
|
+ echo '' >> $cryptpad_nginx_site
|
|
250
|
+ echo ' # Logs' >> $cryptpad_nginx_site
|
|
251
|
+ echo ' access_log /dev/null;' >> $cryptpad_nginx_site
|
|
252
|
+ echo ' error_log /dev/null;' >> $cryptpad_nginx_site
|
|
253
|
+ echo '' >> $cryptpad_nginx_site
|
|
254
|
+ echo ' # Root' >> $cryptpad_nginx_site
|
|
255
|
+ echo " root $CRYPTPAD_DIR;" >> $cryptpad_nginx_site
|
|
256
|
+ echo '' >> $cryptpad_nginx_site
|
|
257
|
+ echo ' index index.html;' >> $cryptpad_nginx_site
|
|
258
|
+ echo '' >> $cryptpad_nginx_site
|
|
259
|
+ echo ' add_header X-XSS-Protection "1; mode=block";' >> $cryptpad_nginx_site
|
|
260
|
+ echo ' add_header X-Content-Type-Options nosniff;' >> $cryptpad_nginx_site
|
|
261
|
+ echo ' add_header X-Frame-Options SAMEORIGIN;' >> $cryptpad_nginx_site
|
|
262
|
+ echo '' >> $cryptpad_nginx_site
|
|
263
|
+ echo ' if ($uri = /pad/inner.html) {' >> $cryptpad_nginx_site
|
|
264
|
+ echo " set \$scriptSrc \"'self' 'unsafe-eval' 'unsafe-inline'\";" >> $cryptpad_nginx_site
|
|
265
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
266
|
+ echo '' >> $cryptpad_nginx_site
|
|
267
|
+ echo ' location = /cryptpad_websocket {' >> $cryptpad_nginx_site
|
|
268
|
+ echo " proxy_pass http://localhost:$CRYPTPAD_PORT;" >> $cryptpad_nginx_site
|
|
269
|
+ echo ' proxy_set_header X-Real-IP $remote_addr;' >> $cryptpad_nginx_site
|
|
270
|
+ echo ' proxy_set_header Host $host;' >> $cryptpad_nginx_site
|
|
271
|
+ echo ' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $cryptpad_nginx_site
|
|
272
|
+ echo '' >> $cryptpad_nginx_site
|
|
273
|
+ echo ' # WebSocket support (nginx 1.4)' >> $cryptpad_nginx_site
|
|
274
|
+ echo ' proxy_http_version 1.1;' >> $cryptpad_nginx_site
|
|
275
|
+ echo ' proxy_set_header Upgrade $http_upgrade;' >> $cryptpad_nginx_site
|
|
276
|
+ echo ' proxy_set_header Connection upgrade;' >> $cryptpad_nginx_site
|
|
277
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
278
|
+ echo '' >> $cryptpad_nginx_site
|
|
279
|
+
|
|
280
|
+ echo ' location ^~ /customize.dist/ {' >> $cryptpad_nginx_site
|
|
281
|
+ echo ' # This is needed in order to prevent infinite recursion between /customize/ and the root' >> $cryptpad_nginx_site
|
|
282
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
283
|
+ echo ' location ^~ /customize/ {' >> $cryptpad_nginx_site
|
|
284
|
+ echo ' rewrite ^/customize/(.*)$ $1 break;' >> $cryptpad_nginx_site
|
|
285
|
+ echo ' try_files /customize/$uri /customize.dist/$uri;' >> $cryptpad_nginx_site
|
|
286
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
287
|
+ echo ' location = /api/config {' >> $cryptpad_nginx_site
|
|
288
|
+ echo ' default_type text/javascript;' >> $cryptpad_nginx_site
|
|
289
|
+ echo ' rewrite ^.*$ /customize/api/config break;' >> $cryptpad_nginx_site
|
|
290
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
291
|
+ echo '' >> $cryptpad_nginx_site
|
|
292
|
+ echo ' location ^~ /blob/ {' >> $cryptpad_nginx_site
|
|
293
|
+ echo ' try_files $uri =404;' >> $cryptpad_nginx_site
|
|
294
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
295
|
+ echo '' >> $cryptpad_nginx_site
|
|
296
|
+ echo ' location ^~ /register/ {' >> $cryptpad_nginx_site
|
|
297
|
+ echo ' try_files $uri =404;' >> $cryptpad_nginx_site
|
|
298
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
299
|
+ echo '' >> $cryptpad_nginx_site
|
|
300
|
+ echo ' location ^~ /login/ {' >> $cryptpad_nginx_site
|
|
301
|
+ echo ' try_files $uri =404;' >> $cryptpad_nginx_site
|
|
302
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
303
|
+ echo '' >> $cryptpad_nginx_site
|
|
304
|
+ echo ' location ^~ /about.html {' >> $cryptpad_nginx_site
|
|
305
|
+ echo ' try_files $uri =404;' >> $cryptpad_nginx_site
|
|
306
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
307
|
+ echo '' >> $cryptpad_nginx_site
|
|
308
|
+ echo ' location ^~ /contact.html {' >> $cryptpad_nginx_site
|
|
309
|
+ echo ' try_files $uri =404;' >> $cryptpad_nginx_site
|
|
310
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
311
|
+ echo '' >> $cryptpad_nginx_site
|
|
312
|
+ echo ' location ^~ /contact.html {' >> $cryptpad_nginx_site
|
|
313
|
+ echo ' try_files $uri =404;' >> $cryptpad_nginx_site
|
|
314
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
315
|
+ echo '' >> $cryptpad_nginx_site
|
|
316
|
+ echo ' location ^~ /what-is-cryptpad.html {' >> $cryptpad_nginx_site
|
|
317
|
+ echo ' try_files $uri =404;' >> $cryptpad_nginx_site
|
|
318
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
319
|
+ echo '' >> $cryptpad_nginx_site
|
|
320
|
+ echo ' location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media)$ {' >> $cryptpad_nginx_site
|
|
321
|
+ echo ' rewrite ^(.*)$ $1/ redirect;' >> $cryptpad_nginx_site
|
|
322
|
+ echo ' }' >> $cryptpad_nginx_site
|
|
323
|
+ echo '' >> $cryptpad_nginx_site
|
|
324
|
+ echo ' try_files /www/$uri /www/$uri/index.html /customize/$uri;' >> $cryptpad_nginx_site
|
|
325
|
+ echo '}' >> $cryptpad_nginx_site
|
|
326
|
+ ln -s $cryptpad_nginx_site $rootdir/etc/nginx/sites-enabled/cryptpad
|
|
327
|
+
|
|
328
|
+ cd $rootdir$CRYPTPAD_DIR
|
|
329
|
+
|
|
330
|
+ get_npm_arch
|
|
331
|
+
|
|
332
|
+ cat <<EOF > $rootdir/usr/bin/install_cryptpad
|
|
333
|
+#!/bin/bash
|
|
334
|
+cd $CRYPTPAD_DIR
|
|
335
|
+npm install --arch=$NPM_ARCH --build-from-source
|
|
336
|
+npm install --arch=$NPM_ARCH -g bower@1.8.0
|
|
337
|
+chown -R cryptpad:cryptpad $CRYPTPAD_DIR
|
|
338
|
+su -c 'bower install' - cryptpad
|
|
339
|
+cp config.example.js config.js
|
|
340
|
+EOF
|
|
341
|
+
|
|
342
|
+ if [ ! -f $rootdir$CRYPTPAD_DIR/config.js ]; then
|
|
343
|
+ echo $'Cryptpad config file not found'
|
|
344
|
+ exit 628252
|
|
345
|
+ fi
|
|
346
|
+
|
|
347
|
+ sed -i "s|httpPort:.*|httpPort: $CRYPTPAD_PORT,|g" $rootdir$CRYPTPAD_DIR/config.js
|
|
348
|
+ sed -i "s|// domain:|domain:|g" $rootdir$CRYPTPAD_DIR/config.js
|
|
349
|
+ sed -i 's|openFileLimit:.*|openFileLimit: 1024,|g' $rootdir$CRYPTPAD_DIR/config.js
|
|
350
|
+ sed -i "s|domain:.*|domain: 'http://P${PEER_ID}.local',|g" $rootdir$CRYPTPAD_DIR/config.js
|
|
351
|
+
|
|
352
|
+ chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
|
|
353
|
+
|
|
354
|
+ # daemon
|
|
355
|
+ echo '[Unit]' > $rootdir/etc/systemd/system/cryptpad.service
|
|
356
|
+ echo 'Description=Cryptpad' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
357
|
+ echo 'After=syslog.target' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
358
|
+ echo 'After=network.target' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
359
|
+ echo '' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
360
|
+ echo '[Service]' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
361
|
+ echo 'User=cryptpad' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
362
|
+ echo 'Group=cryptpad' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
363
|
+ echo "WorkingDirectory=$CRYPTPAD_DIR" >> $rootdir/etc/systemd/system/cryptpad.service
|
|
364
|
+ echo "ExecStart=/usr/local/bin/node $CRYPTPAD_DIR/server.js" >> $rootdir/etc/systemd/system/cryptpad.service
|
|
365
|
+ echo 'Environment=PATH=/usr/bin:/usr/local/bin' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
366
|
+ echo 'Environment=NODE_ENV=production' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
367
|
+ echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
368
|
+ echo '' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
369
|
+ echo '[Install]' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
370
|
+ echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/cryptpad.service
|
|
371
|
+ chroot "$rootdir" systemctl enable cryptpad.service
|
|
372
|
+}
|
|
373
|
+
|
218
|
374
|
function install_cryptpad_main {
|
219
|
375
|
if [[ $(app_is_installed cryptpad_main) == "1" ]]; then
|
220
|
376
|
return
|