Bob Mottram 7 years ago
parent
commit
fa8f96bfdb

+ 171
- 167
src/freedombone-app-mediagoblin View File

@@ -71,7 +71,7 @@ function mediagoblin_fix_email {
71 71
     if ! grep -q 'import os' $mgfile; then
72 72
         sed -i '/import sys/a import os' $mgfile
73 73
     fi
74
-    sed -i "s|return mhost.sendmail(from_addr, to_addrs, message.as_string())|return os.system(\"echo '\" + message_body + \"' \| mail -s '\" + message['Subject'] + \"' \" + message['To'])|g" $mgfile
74
+    sed -i "s|return mhost.sendmail(from_addr, to_addrs, message.as_string())|return os.system(\"echo '\" + message_body + \"' \\| mail -s '\" + message['Subject'] + \"' \" + message['To'])|g" $mgfile
75 75
 }
76 76
 
77 77
 function install_interactive_mediagoblin {
@@ -92,7 +92,7 @@ function configure_interactive_mediagoblin {
92 92
     dialog --title $"Mediagoblin" \
93 93
            --backtitle $"Freedombone Control Panel" \
94 94
            --defaultno \
95
-           --yesno $"\nAllow registration of new users?" 10 60
95
+           --yesno $"\\nAllow registration of new users?" 10 60
96 96
     sel=$?
97 97
     case $sel in
98 98
         0)
@@ -139,7 +139,7 @@ function reconfigure_mediagoblin {
139 139
 }
140 140
 
141 141
 function upgrade_mediagoblin {
142
-    CURR_MEDIAGOBLIN_COMMIT=$(cat $COMPLETION_FILE | grep "mediagoblin commit" | awk -F ':' '{print $2}')
142
+    CURR_MEDIAGOBLIN_COMMIT=$(grep "mediagoblin commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
143 143
     if [[ "$CURR_MEDIAGOBLIN_COMMIT" != "$MEDIAGOBLIN_COMMIT" ]]; then
144 144
         MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
145 145
         su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git stash && git pull" - mediagoblin
@@ -182,6 +182,7 @@ function restore_local_mediagoblin {
182 182
         else
183 183
             cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
184 184
         fi
185
+        # shellcheck disable=SC2181
185 186
         if [ ! "$?" = "0" ]; then
186 187
             function_check restore_directory_from_usb
187 188
             set_user_permissions
@@ -195,6 +196,7 @@ function restore_local_mediagoblin {
195 196
         else
196 197
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
197 198
         fi
199
+        # shellcheck disable=SC2181
198 200
         if [ ! "$?" = "0" ]; then
199 201
             function_check set_user_permissions
200 202
             set_user_permissions
@@ -214,24 +216,25 @@ function backup_remote_mediagoblin {
214 216
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
215 217
     if [ -d /etc/mediagoblin ]; then
216 218
         echo $"Backing up mediagoblin"
217
-        backup_directory_to_friend $MEDIAGOBLIN_BASE_DIR mediagoblin
219
+        backup_directory_to_friend "$MEDIAGOBLIN_BASE_DIR" mediagoblin
218 220
         backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
219 221
     fi
220 222
 }
221 223
 
222 224
 function restore_remote_mediagoblin {
223 225
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
224
-    if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
226
+    if [ -d "$SERVER_DIRECTORY/backup/mediagoblin" ]; then
225 227
         temp_restore_dir=/root/tempmediagoblin
226 228
         function_check get_completion_param
227 229
         MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
228 230
         function_check restore_directory_from_friend
229 231
         restore_directory_from_friend $temp_restore_dir mediagoblin
230
-        if [ -d ${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR ]; then
231
-            cp -r ${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR/* $MEDIAGOBLIN_BASE_DIR/
232
+        if [ -d "${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR" ]; then
233
+            cp -r "${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR/*" "$MEDIAGOBLIN_BASE_DIR/"
232 234
         else
233
-            cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
235
+            cp -r "${temp_restore_dir}/*" "$MEDIAGOBLIN_BASE_DIR/"
234 236
         fi
237
+        # shellcheck disable=SC2181
235 238
         if [ ! "$?" = "0" ]; then
236 239
             exit 264824
237 240
         fi
@@ -241,12 +244,13 @@ function restore_remote_mediagoblin {
241 244
         else
242 245
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
243 246
         fi
247
+        # shellcheck disable=SC2181
244 248
         if [ ! "$?" = "0" ]; then
245 249
             exit 268492
246 250
         fi
247 251
         rm -rf ${temp_restore_dir}
248 252
         rm -rf ${temp_restore_dir}2
249
-        chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
253
+        chown -hR mediagoblin:www-data "$MEDIAGOBLIN_BASE_DIR"
250 254
         chown -hR mediagoblin:www-data /var/lib/mediagoblin
251 255
         chmod -R g+wx /var/lib/mediagoblin
252 256
     fi
@@ -264,17 +268,17 @@ function remove_mediagoblin {
264 268
 
265 269
     function_check remove_onion_service
266 270
     remove_onion_service mediagoblin ${MEDIAGOBLIN_ONION_PORT}
267
-    nginx_dissite $MEDIAGOBLIN_DOMAIN_NAME
268
-    remove_certs $MEDIAGOBLIN_DOMAIN_NAME
271
+    nginx_dissite "$MEDIAGOBLIN_DOMAIN_NAME"
272
+    remove_certs "$MEDIAGOBLIN_DOMAIN_NAME"
269 273
     if [ -d /var/lib/mediagoblin ]; then
270 274
         rm -rf /var/lib/mediagoblin
271 275
     fi
272
-    if [ -d $MEDIAGOBLIN_BASE_DIR ]; then
273
-        rm -rf $MEDIAGOBLIN_BASE_DIR
276
+    if [ -d "$MEDIAGOBLIN_BASE_DIR" ]; then
277
+        rm -rf "$MEDIAGOBLIN_BASE_DIR"
274 278
     fi
275 279
     remove_completion_param "install_mediagoblin"
276 280
     remove_completion_param "mediagoblin domain"
277
-    sed -i '/mediagoblin/d' $COMPLETION_FILE
281
+    sed -i '/mediagoblin/d' "$COMPLETION_FILE"
278 282
 
279 283
     remove_nodejs mediagoblin
280 284
 
@@ -282,11 +286,11 @@ function remove_mediagoblin {
282 286
     userdel -r mediagoblin
283 287
 
284 288
     function_check remove_ddns_domain
285
-    remove_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
289
+    remove_ddns_domain "$MEDIAGOBLIN_DOMAIN_NAME"
286 290
 }
287 291
 
288 292
 function install_mediagoblin {
289
-    if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
293
+    if [ ! "$MEDIAGOBLIN_DOMAIN_NAME" ]; then
290 294
         return
291 295
     fi
292 296
 
@@ -304,17 +308,17 @@ function install_mediagoblin {
304 308
     useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
305 309
     usermod --append -G mediagoblin mediagoblin
306 310
     mkdir -p /var/lib/mediagoblin
307
-    mkdir -p $MEDIAGOBLIN_BASE_DIR
308
-    chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
311
+    mkdir -p "$MEDIAGOBLIN_BASE_DIR"
312
+    chown -hR mediagoblin:www-data "$MEDIAGOBLIN_BASE_DIR"
309 313
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
310 314
     chmod -R g+wx /var/lib/mediagoblin
311 315
 
312 316
     if [ -d /repos/mediagoblin ]; then
313
-        mkdir -p $MEDIAGOBLIN_BASE_DIR/mediagoblin
314
-        cp -r -p /repos/mediagoblin/. $MEDIAGOBLIN_BASE_DIR/mediagoblin
315
-        cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
317
+        mkdir -p "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
318
+        cp -r -p /repos/mediagoblin/. "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
319
+        cd "$MEDIAGOBLIN_BASE_DIR/mediagoblin" || exit 347593563
316 320
         git pull
317
-        chown -R mediagoblin:mediagoblin $MEDIAGOBLIN_BASE_DIR/mediagoblin
321
+        chown -R mediagoblin:mediagoblin "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
318 322
     else
319 323
         su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
320 324
     fi
@@ -340,7 +344,7 @@ function install_mediagoblin {
340 344
             gstreamer1.0-plugins-ugly \
341 345
             gstreamer1.0-libav \
342 346
             python-gst-1.0 python3-gst-1.0
343
-    cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
347
+    cd "$MEDIAGOBLIN_BASE_DIR/mediagoblin" || exit 76345672472
344 348
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
345 349
 
346 350
     # Audio plugin
@@ -349,14 +353,14 @@ function install_mediagoblin {
349 353
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
350 354
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/pip install scikits.audiolab" - mediagoblin
351 355
 
352
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
353
-        MEDIAGOBLIN_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
356
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
357
+        MEDIAGOBLIN_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
354 358
     else
355
-        if [ ! $MEDIAGOBLIN_ADMIN_PASSWORD ]; then
356
-            MEDIAGOBLIN_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
359
+        if [ ! "$MEDIAGOBLIN_ADMIN_PASSWORD" ]; then
360
+            MEDIAGOBLIN_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
357 361
         fi
358 362
     fi
359
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a mediagoblin -p "$MEDIAGOBLIN_ADMIN_PASSWORD"
363
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a mediagoblin -p "$MEDIAGOBLIN_ADMIN_PASSWORD"
360 364
 
361 365
     MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
362 366
     set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
@@ -365,157 +369,157 @@ function install_mediagoblin {
365 369
 
366 370
     if [[ $ONION_ONLY == "no" ]]; then
367 371
         function_check nginx_http_redirect
368
-        nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
369
-        echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
370
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
371
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
372
-        echo '    include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
373
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
374
-        echo '    autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
375
-        echo '    default_type  application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
376
-        echo '    sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
377
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
372
+        nginx_http_redirect "$MEDIAGOBLIN_DOMAIN_NAME"
373
+        { echo 'server {';
374
+          echo '    listen 443 ssl;';
375
+          echo '    #listen [::]:443 ssl;';
376
+          echo '    include /etc/nginx/mime.types;';
377
+          echo '';
378
+          echo '    autoindex off;';
379
+          echo '    default_type  application/octet-stream;';
380
+          echo '    sendfile on;';
381
+          echo ''; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
378 382
         function_check nginx_ssl
379
-        nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
383
+        nginx_ssl "$MEDIAGOBLIN_DOMAIN_NAME"
380 384
         function_check nginx_disable_sniffing
381
-        nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
385
+        nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
382 386
         function_check nginx_limits
383
-        nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
384
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
385
-        echo '    client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
386
-        echo '    client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
387
-        echo '    send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
388
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
389
-        echo '    fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
390
-        echo '    fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
391
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
392
-        echo '    gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
393
-        echo '    gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
394
-        echo '    gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
395
-        echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
396
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
397
-        echo "    server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
398
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
399
-        echo '    error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
400
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
401
-
402
-        echo '    location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
403
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
404
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
405
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
406
-        echo '    location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
407
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
408
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
409
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
410
-        echo '    location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
411
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
412
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
413
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
414
-        echo '    location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
415
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
416
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
417
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
418
-        echo '    location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
419
-        echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
420
-        echo '        include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
421
-        echo '        fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
422
-        echo '        fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
423
-        echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
424
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
425
-        echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
387
+        nginx_limits "$MEDIAGOBLIN_DOMAIN_NAME" 800m
388
+        { echo '';
389
+          echo '    client_header_timeout 10m;';
390
+          echo '    client_body_timeout 10m;';
391
+          echo '    send_timeout 10m;';
392
+          echo '';
393
+          echo '    fastcgi_read_timeout 600;';
394
+          echo '    fastcgi_send_timeout 600;';
395
+          echo '';
396
+          echo '    gzip on;';
397
+          echo '    gzip_min_length 1024;';
398
+          echo '    gzip_buffers 4 32k;';
399
+          echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;';
400
+          echo '';
401
+          echo "    server_name $MEDIAGOBLIN_DOMAIN_NAME;";
402
+          echo '    access_log /dev/null;';
403
+          echo '    error_log /dev/null;';
404
+          echo '';
405
+
406
+          echo '    location /mgoblin_static/ {';
407
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;";
408
+          echo '    }';
409
+          echo '';
410
+          echo '    location /mgoblin_media/ {';
411
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;";
412
+          echo '    }';
413
+          echo '';
414
+          echo '    location /theme_static/ {';
415
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;";
416
+          echo '    }';
417
+          echo '';
418
+          echo '    location /plugin_static/ {';
419
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;";
420
+          echo '    }';
421
+          echo '';
422
+          echo '    location / {';
423
+          echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;";
424
+          echo '        include /etc/nginx/fastcgi_params;';
425
+          echo "        fastcgi_param PATH_INFO \$fastcgi_script_name;";
426
+          echo '        fastcgi_param SCRIPT_NAME "";';
427
+          echo '        fastcgi_read_timeout 30;';
428
+          echo '    }';
429
+          echo '}'; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
426 430
     else
427
-        echo -n '' > /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
431
+        echo -n '' > "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
428 432
     fi
429
-    echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
430
-    echo "    listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
431
-    echo '    include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
432
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
433
-    echo '    autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
434
-    echo '    default_type  application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
435
-    echo '    sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
436
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
433
+    { echo 'server {';
434
+      echo "    listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;";
435
+      echo '    include /etc/nginx/mime.types;';
436
+      echo '';
437
+      echo '    autoindex off;';
438
+      echo '    default_type  application/octet-stream;';
439
+      echo '    sendfile on;';
440
+      echo ''; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
437 441
     function_check nginx_disable_sniffing
438
-    nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
442
+    nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
439 443
     function_check nginx_limits
440
-    nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
441
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
442
-    echo '    client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
443
-    echo '    client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
444
-    echo '    send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
445
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
446
-    echo '    fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
447
-    echo '    fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
448
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
449
-    echo '    gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
450
-    echo '    gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
451
-    echo '    gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
452
-    echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
453
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
454
-    echo "    server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
455
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
456
-    echo '    error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
457
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
458
-
459
-    echo '    location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
460
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
461
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
462
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
463
-    echo '    location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
464
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
465
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
466
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
467
-    echo '    location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
468
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
469
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
470
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
471
-    echo '    location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
472
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
473
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
474
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
475
-    echo '    location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
476
-    echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
477
-    echo '        include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
478
-    echo '        fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
479
-    echo '        fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
480
-    echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
481
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
482
-    echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
483
-
484
-    echo '[Unit]' > /etc/systemd/system/mediagoblin.service
485
-    echo 'Description=Media service' >> /etc/systemd/system/mediagoblin.service
486
-    echo 'Requires=network.target' >> /etc/systemd/system/mediagoblin.service
487
-    echo 'After=network.target' >> /etc/systemd/system/mediagoblin.service
488
-    echo '' >> /etc/systemd/system/mediagoblin.service
489
-    echo '[Service]' >> /etc/systemd/system/mediagoblin.service
490
-    echo 'Type=simple' >> /etc/systemd/system/mediagoblin.service
491
-    echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin.service
492
-    echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin.service
493
-    echo "WorkingDirectory=$MEDIAGOBLIN_BASE_DIR/mediagoblin/" >> /etc/systemd/system/mediagoblin.service
494
-    echo "ExecStart=$MEDIAGOBLIN_BASE_DIR/mediagoblin/lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=$MEDIAGOBLIN_PORT" >> /etc/systemd/system/mediagoblin.service
495
-    echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini CELERY_ALWAYS_EAGER=true" >> /etc/systemd/system/mediagoblin.service
496
-    echo 'Restart=always' >> /etc/systemd/system/mediagoblin.service
497
-    echo 'RestartSec=10' >> /etc/systemd/system/mediagoblin.service
498
-    echo '' >> /etc/systemd/system/mediagoblin.service
499
-    echo '[Install]' >> /etc/systemd/system/mediagoblin.service
500
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin.service
444
+    nginx_limits "$MEDIAGOBLIN_DOMAIN_NAME" 800m
445
+    { echo '';
446
+      echo '    client_header_timeout 10m;';
447
+      echo '    client_body_timeout 10m;';
448
+      echo '    send_timeout 10m;';
449
+      echo '';
450
+      echo '    fastcgi_read_timeout 600;';
451
+      echo '    fastcgi_send_timeout 600;';
452
+      echo '';
453
+      echo '    gzip on;';
454
+      echo '    gzip_min_length 1024;';
455
+      echo '    gzip_buffers 4 32k;';
456
+      echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;';
457
+      echo '';
458
+      echo "    server_name $MEDIAGOBLIN_ONION_HOSTNAME;";
459
+      echo '    access_log /dev/null;';
460
+      echo '    error_log /dev/null;';
461
+      echo '';
462
+
463
+      echo '    location /mgoblin_static/ {';
464
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;";
465
+      echo '    }';
466
+      echo '';
467
+      echo '    location /mgoblin_media/ {';
468
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;";
469
+      echo '    }';
470
+      echo '';
471
+      echo '    location /theme_static/ {';
472
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;";
473
+      echo '    }';
474
+      echo '';
475
+      echo '    location /plugin_static/ {';
476
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;";
477
+      echo '    }';
478
+      echo '';
479
+      echo '    location / {';
480
+      echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;";
481
+      echo '        include /etc/nginx/fastcgi_params;';
482
+      echo "        fastcgi_param PATH_INFO \$fastcgi_script_name;";
483
+      echo '        fastcgi_param SCRIPT_NAME "";';
484
+      echo '        fastcgi_read_timeout 30;';
485
+      echo '    }';
486
+      echo '}'; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
487
+
488
+    { echo '[Unit]';
489
+      echo 'Description=Media service';
490
+      echo 'Requires=network.target';
491
+      echo 'After=network.target';
492
+      echo '';
493
+      echo '[Service]';
494
+      echo 'Type=simple';
495
+      echo 'User=mediagoblin';
496
+      echo 'Group=mediagoblin';
497
+      echo "WorkingDirectory=$MEDIAGOBLIN_BASE_DIR/mediagoblin/";
498
+      echo "ExecStart=$MEDIAGOBLIN_BASE_DIR/mediagoblin/lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=$MEDIAGOBLIN_PORT";
499
+      echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini CELERY_ALWAYS_EAGER=true";
500
+      echo 'Restart=always';
501
+      echo 'RestartSec=10';
502
+      echo '';
503
+      echo '[Install]';
504
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/mediagoblin.service
501 505
     chmod +x /etc/systemd/system/mediagoblin.service
502 506
 
503 507
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
504 508
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
505 509
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg makeadmin $MY_USERNAME" - mediagoblin
506 510
 
507
-    sed -i 's|email_debug_mode.*|email_debug_mode = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
508
-    sed -i "s|email_sender_address.*|email_sender_address = \"noreply@${DEFAULT_DOMAIN_NAME}\"|g" $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
511
+    sed -i 's|email_debug_mode.*|email_debug_mode = false|g' "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
512
+    sed -i "s|email_sender_address.*|email_sender_address = \"noreply@${DEFAULT_DOMAIN_NAME}\"|g" "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
509 513
 
510
-    sed -i 's|allow_reporting.*|allow_reporting = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
514
+    sed -i 's|allow_reporting.*|allow_reporting = false|g' "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
511 515
 
512
-    if ! grep -q '[[[skip_transcode]]]' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini; then
513
-        echo '[[[skip_transcode]]]' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
514
-        echo 'mime_types = video/webm, video/ogg, video/mp4, audio/ogg, application/ogg, application/x-annodex' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
515
-        echo 'container_formats = Matroska, Ogg, ISO MP4/M4A' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
516
-        echo 'video_codecs = VP8 video, VP9 video, Theora, H.264, H.264 / AVC, MPEG-4 video' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
517
-        echo 'audio_codecs = Vorbis, MPEG-4 AAC' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
518
-        echo 'dimensions_match = false' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
516
+    if ! grep -q '[[[skip_transcode]]]' "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"; then
517
+        { echo '[[[skip_transcode]]]';
518
+          echo 'mime_types = video/webm, video/ogg, video/mp4, audio/ogg, application/ogg, application/x-annodex';
519
+          echo 'container_formats = Matroska, Ogg, ISO MP4/M4A';
520
+          echo 'video_codecs = VP8 video, VP9 video, Theora, H.264, H.264 / AVC, MPEG-4 video';
521
+          echo 'audio_codecs = Vorbis, MPEG-4 AAC';
522
+          echo 'dimensions_match = false'; } >> "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
519 523
     fi
520 524
 
521 525
     systemctl enable mediagoblin
@@ -529,18 +533,18 @@ function install_mediagoblin {
529 533
     fi
530 534
 
531 535
     function_check create_site_certificate
532
-    create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME 'yes'
536
+    create_site_certificate "$MEDIAGOBLIN_DOMAIN_NAME" 'yes'
533 537
 
534 538
     function_check configure_php
535 539
     configure_php
536 540
 
537
-    nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
541
+    nginx_ensite "$MEDIAGOBLIN_DOMAIN_NAME"
538 542
 
539 543
     systemctl restart php7.0-fpm
540 544
     systemctl restart nginx
541 545
 
542 546
     function_check add_ddns_domain
543
-    add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
547
+    add_ddns_domain "$MEDIAGOBLIN_DOMAIN_NAME"
544 548
 
545 549
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
546 550
     chmod -R g+wx /var/lib/mediagoblin

+ 206
- 206
src/freedombone-app-movim View File

@@ -58,19 +58,19 @@ function logging_off_movim {
58 58
 function remove_user_movim {
59 59
     remove_username="$1"
60 60
 
61
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp movim
61
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp movim
62 62
 }
63 63
 
64 64
 function add_user_movim {
65 65
     new_username="$1"
66 66
     new_user_password="$2"
67 67
 
68
-    ${PROJECT_NAME}-pass -u $new_username -a movim -p "$new_user_password"
68
+    "${PROJECT_NAME}-pass" -u "$new_username" -a movim -p "$new_user_password"
69 69
     echo '0'
70 70
 }
71 71
 
72 72
 function install_interactive_movim {
73
-    if [ ! $ONION_ONLY ]; then
73
+    if [ ! "$ONION_ONLY" ]; then
74 74
         ONION_ONLY='no'
75 75
     fi
76 76
 
@@ -80,39 +80,38 @@ function install_interactive_movim {
80 80
         MOVIM_DETAILS_COMPLETE=
81 81
         while [ ! $MOVIM_DETAILS_COMPLETE ]
82 82
         do
83
-            data=$(tempfile 2>/dev/null)
84
-            trap "rm -f $data" 0 1 2 5 15
83
+            data=$(mktemp 2>/dev/null)
85 84
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
86 85
                 dialog --backtitle $"Freedombone Configuration" \
87 86
                        --title $"Movim Configuration" \
88
-                       --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
87
+                       --form $"\\nPlease enter your Movim details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
89 88
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
90 89
                        $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
91
-                       2> $data
90
+                       2> "$data"
92 91
             else
93 92
                 dialog --backtitle $"Freedombone Configuration" \
94 93
                        --title $"Movim Configuration" \
95
-                       --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
94
+                       --form $"\\nPlease enter your Movim details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
96 95
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
97
-                       2> $data
96
+                       2> "$data"
98 97
             fi
99 98
             sel=$?
100 99
             case $sel in
101 100
                 1) exit 1;;
102 101
                 255) exit 1;;
103 102
             esac
104
-            MOVIM_DOMAIN_NAME=$(cat $data | sed -n 1p)
105
-            if [ $MOVIM_DOMAIN_NAME ]; then
103
+            MOVIM_DOMAIN_NAME=$(sed -n 1p < "$data")
104
+            if [ "$MOVIM_DOMAIN_NAME" ]; then
106 105
                 TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
107 106
                 validate_domain_name
108
-                if [[ $TEST_DOMAIN_NAME != $MOVIM_DOMAIN_NAME ]]; then
107
+                if [[ "$TEST_DOMAIN_NAME" != "$MOVIM_DOMAIN_NAME" ]]; then
109 108
                     MOVIM_DOMAIN_NAME=
110 109
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
111 110
                 else
112 111
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
113
-                        MOVIM_CODE=$(cat $data | sed -n 2p)
112
+                        MOVIM_CODE=$(sed -n 2p < "$data")
114 113
                         validate_freedns_code "$MOVIM_CODE"
115
-                        if [ ! $VALID_CODE ]; then
114
+                        if [ ! "$VALID_CODE" ]; then
116 115
                             MOVIM_DOMAIN_NAME=
117 116
                         fi
118 117
                     fi
@@ -121,6 +120,7 @@ function install_interactive_movim {
121 120
             if [ $MOVIM_DOMAIN_NAME ]; then
122 121
                 MOVIM_DETAILS_COMPLETE="yes"
123 122
             fi
123
+            rm -f "$data"
124 124
         done
125 125
 
126 126
         # save the results in the config file
@@ -136,23 +136,23 @@ function change_password_movim {
136 136
 
137 137
     read_config_param 'MOVIM_DOMAIN_NAME'
138 138
 
139
-    ${PROJECT_NAME}-pass -u "$curr_username" -a movim -p "$new_user_password"
139
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a movim -p "$new_user_password"
140 140
 }
141 141
 
142 142
 function movim_create_database {
143
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
144
-        MOVIM_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
143
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
144
+        MOVIM_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
145 145
     else
146
-        if [ ! $MOVIM_ADMIN_PASSWORD ]; then
147
-            MOVIM_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
146
+        if [ ! "$MOVIM_ADMIN_PASSWORD" ]; then
147
+            MOVIM_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
148 148
         fi
149 149
     fi
150
-    if [ ! $MOVIM_ADMIN_PASSWORD ]; then
150
+    if [ ! "$MOVIM_ADMIN_PASSWORD" ]; then
151 151
         return
152 152
     fi
153 153
 
154 154
     function_check create_database
155
-    create_database movim "$MOVIM_ADMIN_PASSWORD" $MY_USERNAME
155
+    create_database movim "$MOVIM_ADMIN_PASSWORD" "$MY_USERNAME"
156 156
 }
157 157
 
158 158
 function reconfigure_movim {
@@ -165,35 +165,35 @@ function upgrade_movim {
165 165
         return
166 166
     fi
167 167
 
168
-    if grep -q "movim domain" $COMPLETION_FILE; then
168
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
169 169
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
170 170
     fi
171 171
 
172 172
     # update to the next commit
173 173
     function_check set_repo_commit
174
-    set_repo_commit /var/www/$MOVIM_DOMAIN_NAME/htdocs "movim commit" "$MOVIM_COMMIT" $MOVIM_REPO
174
+    set_repo_commit "/var/www/$MOVIM_DOMAIN_NAME/htdocs" "movim commit" "$MOVIM_COMMIT" "$MOVIM_REPO"
175 175
 
176
-    cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
176
+    cd "/var/www/${MOVIM_DOMAIN_NAME}/htdocs" || exit 6734824522
177 177
     php composer.phar install
178 178
     php mud.php db --set
179
-    chown -R www-data:www-data /var/www/${MOVIM_DOMAIN_NAME}/htdocs
179
+    chown -R www-data:www-data "/var/www/${MOVIM_DOMAIN_NAME}/htdocs"
180 180
 }
181 181
 
182 182
 
183 183
 function backup_local_movim {
184 184
     MOVIM_DOMAIN_NAME='movim'
185
-    if grep -q "movim domain" $COMPLETION_FILE; then
185
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
186 186
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
187 187
     fi
188 188
 
189
-    source_directory=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
190
-    if [ -d $source_directory ]; then
189
+    source_directory="/var/www/${MOVIM_DOMAIN_NAME}/htdocs"
190
+    if [ -d "$source_directory" ]; then
191 191
         dest_directory=movim
192 192
         function_check suspend_site
193
-        suspend_site ${MOVIM_DOMAIN_NAME}
193
+        suspend_site "${MOVIM_DOMAIN_NAME}"
194 194
 
195 195
         function_check backup_directory_to_usb
196
-        backup_directory_to_usb $source_directory $dest_directory
196
+        backup_directory_to_usb "$source_directory" "$dest_directory"
197 197
 
198 198
         function_check backup_database_to_usb
199 199
         backup_database_to_usb movim
@@ -204,28 +204,28 @@ function backup_local_movim {
204 204
 }
205 205
 
206 206
 function restore_local_movim {
207
-    if ! grep -q "movim domain" $COMPLETION_FILE; then
207
+    if ! grep -q "movim domain" "$COMPLETION_FILE"; then
208 208
         return
209 209
     fi
210 210
     MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
211
-    if [ $MOVIM_DOMAIN_NAME ]; then
211
+    if [ "$MOVIM_DOMAIN_NAME" ]; then
212 212
         echo $"Restoring movim"
213 213
         temp_restore_dir=/root/tempmovim
214 214
         movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
215 215
         # stop the daemons
216
-        cd $movim_dir
216
+        cd "$movim_dir" || exit 7856724252
217 217
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
218 218
 
219 219
         function_check movim_create_database
220 220
         movim_create_database
221 221
 
222
-        restore_database movim ${MOVIM_DOMAIN_NAME}
222
+        restore_database movim "${MOVIM_DOMAIN_NAME}"
223 223
         if [ -d $temp_restore_dir ]; then
224 224
             rm -rf $temp_restore_dir
225 225
         fi
226 226
 
227
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
228
-        cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
227
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
228
+        cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs/config" || exit 2468724682
229 229
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
230 230
         MARIADB_PASSWORD=
231 231
 
@@ -234,18 +234,18 @@ function restore_local_movim {
234 234
 }
235 235
 
236 236
 function backup_remote_movim {
237
-    if grep -q "movim domain" $COMPLETION_FILE; then
237
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
238 238
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
239 239
         temp_backup_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
240
-        if [ -d $temp_backup_dir ]; then
240
+        if [ -d "$temp_backup_dir" ]; then
241 241
             function_check suspend_site
242
-            suspend_site ${MOVIM_DOMAIN_NAME}
242
+            suspend_site "${MOVIM_DOMAIN_NAME}"
243 243
 
244 244
             function_check backup_database_to_friend
245 245
             backup_database_to_friend movim
246 246
 
247 247
             function_check backup_directory_to_friend
248
-            backup_directory_to_friend $temp_backup_dir movim
248
+            backup_directory_to_friend "$temp_backup_dir" movim
249 249
 
250 250
             function_check restart_site
251 251
             restart_site
@@ -256,25 +256,25 @@ function backup_remote_movim {
256 256
 }
257 257
 
258 258
 function restore_remote_movim {
259
-    if grep -q "movim domain" $COMPLETION_FILE; then
259
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
260 260
         echo $"Restoring movim"
261 261
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
262 262
 
263 263
         # stop the daemons
264
-        cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
264
+        cd "/var/www/${MOVIM_DOMAIN_NAME}/htdocs" || exit 524792846827
265 265
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
266 266
 
267 267
         function_check movim_create_database
268 268
         movim_create_database
269 269
 
270 270
         function_check restore_database_from_friend
271
-        restore_database_from_friend movim ${MOVIM_DOMAIN_NAME}
271
+        restore_database_from_friend movim "${MOVIM_DOMAIN_NAME}"
272 272
         if [ -d /root/tempmovim ]; then
273 273
             rm -rf /root/tempmovim
274 274
         fi
275 275
 
276
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
277
-        cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
276
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
277
+        cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs/config" || exit 4242462487
278 278
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
279 279
         MARIADB_PASSWORD=
280 280
 
@@ -298,14 +298,14 @@ function remove_movim {
298 298
 
299 299
     read_config_param "MY_USERNAME"
300 300
     echo "Removing $MOVIM_DOMAIN_NAME"
301
-    nginx_dissite $MOVIM_DOMAIN_NAME
302
-    remove_certs $MOVIM_DOMAIN_NAME
301
+    nginx_dissite "$MOVIM_DOMAIN_NAME"
302
+    remove_certs "$MOVIM_DOMAIN_NAME"
303 303
 
304
-    if [ -d /var/www/$MOVIM_DOMAIN_NAME ]; then
305
-        rm -rf /var/www/$MOVIM_DOMAIN_NAME
304
+    if [ -d "/var/www/$MOVIM_DOMAIN_NAME" ]; then
305
+        rm -rf "/var/www/$MOVIM_DOMAIN_NAME"
306 306
     fi
307
-    if [ -f /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME ]; then
308
-        rm /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
307
+    if [ -f "/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME" ]; then
308
+        rm "/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME"
309 309
     fi
310 310
     function_check drop_database
311 311
     drop_database movim
@@ -316,15 +316,15 @@ function remove_movim {
316 316
     fi
317 317
     remove_app movim
318 318
     remove_completion_param install_movim
319
-    sed -i '/movim/d' $COMPLETION_FILE
319
+    sed -i '/movim/d' "$COMPLETION_FILE"
320 320
     remove_backup_database_local movim
321 321
 
322 322
     function_check remove_ddns_domain
323
-    remove_ddns_domain $MOVIM_DOMAIN_NAME
323
+    remove_ddns_domain "$MOVIM_DOMAIN_NAME"
324 324
 }
325 325
 
326 326
 function install_movim {
327
-    if [ ! $MOVIM_DOMAIN_NAME ]; then
327
+    if [ ! "$MOVIM_DOMAIN_NAME" ]; then
328 328
         echo $'No domain name was given for movim'
329 329
         exit 72572
330 330
     fi
@@ -333,7 +333,7 @@ function install_movim {
333 333
         return
334 334
     fi
335 335
 
336
-    movim_hourly_script movim $MOVIM_DOMAIN_NAME
336
+    movim_hourly_script movim "$MOVIM_DOMAIN_NAME"
337 337
 
338 338
     function_check install_mariadb
339 339
     install_mariadb
@@ -347,221 +347,221 @@ function install_movim {
347 347
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
348 348
     apt-get -yq install php-memcached php-intl exiftool php-imagick libfcgi0ldbl
349 349
 
350
-    if [ ! -d /var/www/$MOVIM_DOMAIN_NAME ]; then
351
-        mkdir /var/www/$MOVIM_DOMAIN_NAME
350
+    if [ ! -d "/var/www/$MOVIM_DOMAIN_NAME" ]; then
351
+        mkdir "/var/www/$MOVIM_DOMAIN_NAME"
352 352
     fi
353
-    if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
353
+    if [ ! -d "/var/www/$MOVIM_DOMAIN_NAME/htdocs" ]; then
354 354
 
355 355
         if [ -d /repos/movim ]; then
356
-            mkdir /var/www/$MOVIM_DOMAIN_NAME/htdocs
357
-            cp -r -p /repos/movim/. /var/www/$MOVIM_DOMAIN_NAME/htdocs
358
-            cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
356
+            mkdir "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
357
+            cp -r -p /repos/movim/. "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
358
+            cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 3768568325
359 359
             git pull
360 360
         else
361 361
             function_check git_clone
362
-            git_clone $MOVIM_REPO /var/www/$MOVIM_DOMAIN_NAME/htdocs
362
+            git_clone "$MOVIM_REPO" "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
363 363
         fi
364 364
 
365
-        if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
365
+        if [ ! -d "/var/www/$MOVIM_DOMAIN_NAME/htdocs" ]; then
366 366
             echo $'Unable to clone movim repo'
367 367
             exit 76285
368 368
         fi
369 369
     fi
370 370
 
371
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
371
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 7345247242
372 372
     git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
373 373
     set_completion_param "movim commit" "$MOVIM_COMMIT"
374 374
 
375 375
     # default login
376
-    if [ ! -f /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php ]; then
376
+    if [ ! -f "/var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php" ]; then
377 377
         echo $'Unable to find Config.php'
378 378
         exit 72352
379 379
     fi
380
-    sed -i "s|'admin'|'${MY_USERNAME}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
381
-    sed -i "s|'password'|'${MOVIM_ADMIN_PASSWORD}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
380
+    sed -i "s|'admin'|'${MY_USERNAME}'|g" "/var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php"
381
+    sed -i "s|'password'|'${MOVIM_ADMIN_PASSWORD}'|g" "/var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php"
382 382
 
383 383
     # Fix typo
384 384
     sed -i 's|weksocket|websocket|g' app/widgets/AdminTest/admintest.js
385 385
 
386
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
386
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 784368245224
387 387
     install_composer
388 388
 
389
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
389
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs/config" || exit 6428764224
390 390
     cp db.example.inc.php db.inc.php
391 391
     sed -i "s|'username'.*|'username'    => 'root',|g" db.inc.php
392 392
     sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
393 393
     sed -i "s|'database'.*|'database'    => 'movim'|g" db.inc.php
394 394
     php mud.php db --set
395 395
 
396
-    chmod u+rwx /var/www/$MOVIM_DOMAIN_NAME/htdocs
397
-    chown -R www-data:www-data /var/www/$MOVIM_DOMAIN_NAME/htdocs
396
+    chmod u+rwx "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
397
+    chown -R www-data:www-data "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
398 398
 
399 399
     function_check movim_create_database
400 400
     movim_create_database
401 401
 
402 402
     function_check add_ddns_domain
403
-    add_ddns_domain $MOVIM_DOMAIN_NAME
403
+    add_ddns_domain "$MOVIM_DOMAIN_NAME"
404 404
 
405 405
     MOVIM_ONION_HOSTNAME=$(add_onion_service movim 80 ${MOVIM_ONION_PORT})
406 406
 
407
-    echo '[Unit]' > /etc/systemd/system/movim.service
408
-    echo 'Description=Movim daemon' >> /etc/systemd/system/movim.service
409
-    echo 'After=network.target nginx.target' >> /etc/systemd/system/movim.service
410
-    echo '' >> /etc/systemd/system/movim.service
411
-    echo '[Service]' >> /etc/systemd/system/movim.service
412
-    echo 'Type=simple' >> /etc/systemd/system/movim.service
413
-    echo 'User=www-data' >> /etc/systemd/system/movim.service
414
-    echo "WorkingDirectory=/var/www/$MOVIM_DOMAIN_NAME/htdocs" >> /etc/systemd/system/movim.service
407
+    { echo '[Unit]';
408
+      echo 'Description=Movim daemon';
409
+      echo 'After=network.target nginx.target';
410
+      echo '';
411
+      echo '[Service]';
412
+      echo 'Type=simple';
413
+      echo 'User=www-data';
414
+      echo "WorkingDirectory=/var/www/$MOVIM_DOMAIN_NAME/htdocs"; } > /etc/systemd/system/movim.service
415 415
     if [[ $ONION_ONLY == 'no' ]]; then
416 416
         echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=https://$MOVIM_DOMAIN_NAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
417 417
     else
418 418
         echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=http://$MOVIM_ONION_HOSTNAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
419 419
     fi
420
-    echo 'StandardOutput=syslog' >> /etc/systemd/system/movim.service
421
-    echo 'SyslogIdentifier=movim' >> /etc/systemd/system/movim.service
422
-    echo 'PIDFile=/run/movim.pid' >> /etc/systemd/system/movim.service
423
-    echo 'Restart=on-failure' >> /etc/systemd/system/movim.service
424
-    echo 'RestartSec=10' >> /etc/systemd/system/movim.service
425
-    echo '' >> /etc/systemd/system/movim.service
426
-    echo '[Install]' >> /etc/systemd/system/movim.service
427
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/movim.service
420
+    { echo 'StandardOutput=syslog';
421
+      echo 'SyslogIdentifier=movim';
422
+      echo 'PIDFile=/run/movim.pid';
423
+      echo 'Restart=on-failure';
424
+      echo 'RestartSec=10';
425
+      echo '';
426
+      echo '[Install]';
427
+      echo 'WantedBy=multi-user.target'; } >> /etc/systemd/system/movim.service
428 428
     systemctl enable movim
429 429
     systemctl daemon-reload
430 430
 
431 431
     movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
432 432
     if [[ $ONION_ONLY == "no" ]]; then
433 433
         function_check nginx_http_redirect
434
-        nginx_http_redirect $MOVIM_DOMAIN_NAME "index index.php"
435
-        echo 'server {' >> $movim_nginx_site
436
-        echo '  listen 443 ssl;' >> $movim_nginx_site
437
-        echo '  #listen [::]:443 ssl;' >> $movim_nginx_site
438
-        echo "  server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
439
-        echo '' >> $movim_nginx_site
434
+        nginx_http_redirect "$MOVIM_DOMAIN_NAME" "index index.php"
435
+        { echo 'server {';
436
+          echo '  listen 443 ssl;';
437
+          echo '  #listen [::]:443 ssl;';
438
+          echo "  server_name $MOVIM_DOMAIN_NAME;";
439
+          echo ''; } >> "$movim_nginx_site"
440 440
         function_check nginx_compress
441
-        nginx_compress $MOVIM_DOMAIN_NAME
442
-        echo '' >> $movim_nginx_site
443
-        echo '  # Security' >> $movim_nginx_site
441
+        nginx_compress "$MOVIM_DOMAIN_NAME"
442
+        echo '' >> "$movim_nginx_site"
443
+        echo '  # Security' >> "$movim_nginx_site"
444 444
         function_check nginx_ssl
445
-        nginx_ssl $MOVIM_DOMAIN_NAME
445
+        nginx_ssl "$MOVIM_DOMAIN_NAME"
446 446
 
447 447
         function_check nginx_disable_sniffing
448
-        nginx_disable_sniffing $MOVIM_DOMAIN_NAME
449
-
450
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $movim_nginx_site
451
-        echo '' >> $movim_nginx_site
452
-        echo '  # Logs' >> $movim_nginx_site
453
-        echo '  access_log /dev/null;' >> $movim_nginx_site
454
-        echo '  error_log /dev/null;' >> $movim_nginx_site
455
-        echo '' >> $movim_nginx_site
456
-        echo '  # Root' >> $movim_nginx_site
457
-        echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
458
-        echo '' >> $movim_nginx_site
459
-        echo '  # Index' >> $movim_nginx_site
460
-        echo '  index index.php;' >> $movim_nginx_site
461
-        echo '' >> $movim_nginx_site
462
-        echo '  # PHP' >> $movim_nginx_site
463
-        echo '  location ~ \.php {' >> $movim_nginx_site
464
-        echo '    include snippets/fastcgi-php.conf;' >> $movim_nginx_site
465
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $movim_nginx_site
466
-        echo '    fastcgi_read_timeout 30;' >> $movim_nginx_site
467
-        echo '  }' >> $movim_nginx_site
468
-        echo '' >> $movim_nginx_site
469
-        echo '  # Location' >> $movim_nginx_site
470
-        echo '  location / {' >> $movim_nginx_site
448
+        nginx_disable_sniffing "$MOVIM_DOMAIN_NAME"
449
+
450
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
451
+          echo '';
452
+          echo '  # Logs';
453
+          echo '  access_log /dev/null;';
454
+          echo '  error_log /dev/null;';
455
+          echo '';
456
+          echo '  # Root';
457
+          echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;";
458
+          echo '';
459
+          echo '  # Index';
460
+          echo '  index index.php;';
461
+          echo '';
462
+          echo '  # PHP';
463
+          echo '  location ~ \.php {';
464
+          echo '    include snippets/fastcgi-php.conf;';
465
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
466
+          echo '    fastcgi_read_timeout 30;';
467
+          echo '  }';
468
+          echo '';
469
+          echo '  # Location';
470
+          echo '  location / {'; } >> "$movim_nginx_site"
471 471
         function_check nginx_limits
472
-        nginx_limits $MOVIM_DOMAIN_NAME '15m'
473
-        echo '    try_files $uri $uri/ @movim;' >> $movim_nginx_site
474
-        echo '  }' >> $movim_nginx_site
475
-        echo '' >> $movim_nginx_site
476
-        echo '  location /ws/ {' >> $movim_nginx_site
477
-        echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
478
-        echo '    proxy_http_version 1.1;' >> $movim_nginx_site
479
-        echo '    proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
480
-        echo '    proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
481
-        echo '    proxy_set_header Host $host;' >> $movim_nginx_site
482
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
483
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
484
-        echo '    proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
485
-        echo '    proxy_redirect off;' >> $movim_nginx_site
486
-        echo '  }' >> $movim_nginx_site
487
-        echo '' >> $movim_nginx_site
488
-        echo '  # Fancy URLs' >> $movim_nginx_site
489
-        echo '  location @movim {' >> $movim_nginx_site
490
-        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
491
-        echo '  }' >> $movim_nginx_site
492
-        echo '' >> $movim_nginx_site
493
-        echo '  # Restrict access that is unnecessary anyway' >> $movim_nginx_site
494
-        echo '  location ~ /\.(ht|git) {' >> $movim_nginx_site
495
-        echo '    deny all;' >> $movim_nginx_site
496
-        echo '  }' >> $movim_nginx_site
497
-        echo '' >> $movim_nginx_site
498
-        echo '}' >> $movim_nginx_site
472
+        nginx_limits "$MOVIM_DOMAIN_NAME" '15m'
473
+        { echo "    try_files \$uri \$uri/ @movim;";
474
+          echo '  }';
475
+          echo '';
476
+          echo '  location /ws/ {';
477
+          echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;";
478
+          echo '    proxy_http_version 1.1;';
479
+          echo "    proxy_set_header Upgrade \$http_upgrade;";
480
+          echo '    proxy_set_header Connection "Upgrade";';
481
+          echo "    proxy_set_header Host \$host;";
482
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
483
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
484
+          echo '    proxy_set_header X-Forwarded-Proto https;';
485
+          echo '    proxy_redirect off;';
486
+          echo '  }';
487
+          echo '';
488
+          echo '  # Fancy URLs';
489
+          echo '  location @movim {';
490
+          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
491
+          echo '  }';
492
+          echo '';
493
+          echo '  # Restrict access that is unnecessary anyway';
494
+          echo '  location ~ /\.(ht|git) {';
495
+          echo '    deny all;';
496
+          echo '  }';
497
+          echo '';
498
+          echo '}'; } >> "$movim_nginx_site"
499 499
     else
500
-        echo -n '' > $movim_nginx_site
500
+        echo -n '' > "$movim_nginx_site"
501 501
     fi
502
-    echo 'server {' >> $movim_nginx_site
503
-    echo "    listen 127.0.0.1:$MOVIM_ONION_PORT default_server;" >> $movim_nginx_site
504
-    echo "    server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
505
-    echo '' >> $movim_nginx_site
502
+    { echo 'server {';
503
+      echo "    listen 127.0.0.1:$MOVIM_ONION_PORT default_server;";
504
+      echo "    server_name $MOVIM_DOMAIN_NAME;";
505
+      echo ''; } >> "$movim_nginx_site"
506 506
     function_check nginx_compress
507
-    nginx_compress $MOVIM_DOMAIN_NAME
508
-    echo '' >> $movim_nginx_site
507
+    nginx_compress "$MOVIM_DOMAIN_NAME"
508
+    echo '' >> "$movim_nginx_site"
509 509
     function_check nginx_disable_sniffing
510
-    nginx_disable_sniffing $MOVIM_DOMAIN_NAME
511
-    echo '' >> $movim_nginx_site
512
-    echo '  # Logs' >> $movim_nginx_site
513
-    echo '  access_log /dev/null;' >> $movim_nginx_site
514
-    echo '  error_log /dev/null;' >> $movim_nginx_site
515
-    echo '' >> $movim_nginx_site
516
-    echo '  # Root' >> $movim_nginx_site
517
-    echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
518
-    echo '' >> $movim_nginx_site
519
-    echo '  # Index' >> $movim_nginx_site
520
-    echo '  index index.php;' >> $movim_nginx_site
521
-    echo '' >> $movim_nginx_site
522
-    echo '  # PHP' >> $movim_nginx_site
523
-    echo '  location ~ \.php {' >> $movim_nginx_site
524
-    echo '    include snippets/fastcgi-php.conf;' >> $movim_nginx_site
525
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $movim_nginx_site
526
-    echo '    fastcgi_read_timeout 30;' >> $movim_nginx_site
527
-    echo '  }' >> $movim_nginx_site
528
-    echo '' >> $movim_nginx_site
529
-    echo '  # Location' >> $movim_nginx_site
530
-    echo '  location / {' >> $movim_nginx_site
510
+    nginx_disable_sniffing "$MOVIM_DOMAIN_NAME"
511
+    { echo '';
512
+      echo '  # Logs';
513
+      echo '  access_log /dev/null;';
514
+      echo '  error_log /dev/null;';
515
+      echo '';
516
+      echo '  # Root';
517
+      echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;";
518
+      echo '';
519
+      echo '  # Index';
520
+      echo '  index index.php;';
521
+      echo '';
522
+      echo '  # PHP';
523
+      echo '  location ~ \.php {';
524
+      echo '    include snippets/fastcgi-php.conf;';
525
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
526
+      echo '    fastcgi_read_timeout 30;';
527
+      echo '  }';
528
+      echo '';
529
+      echo '  # Location';
530
+      echo '  location / {'; } >> "$movim_nginx_site"
531 531
     function_check nginx_limits
532
-    nginx_limits $MOVIM_DOMAIN_NAME '15m'
533
-    echo '    try_files $uri $uri/ @movim;' >> $movim_nginx_site
534
-    echo '  }' >> $movim_nginx_site
535
-    echo '' >> $movim_nginx_site
536
-    echo '  location /ws/ {' >> $movim_nginx_site
537
-    echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
538
-    echo '    proxy_http_version 1.1;' >> $movim_nginx_site
539
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
540
-    echo '    proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
541
-    echo '    proxy_set_header Host $host;' >> $movim_nginx_site
542
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
543
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
544
-    echo '    proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
545
-    echo '    proxy_redirect off;' >> $movim_nginx_site
546
-    echo '  }' >> $movim_nginx_site
547
-    echo '' >> $movim_nginx_site
548
-    echo '  # Fancy URLs' >> $movim_nginx_site
549
-    echo '  location @movim {' >> $movim_nginx_site
550
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
551
-    echo '  }' >> $movim_nginx_site
552
-    echo '' >> $movim_nginx_site
553
-    echo '  # Restrict access that is unnecessary anyway' >> $movim_nginx_site
554
-    echo '  location ~ /\.(ht|git) {' >> $movim_nginx_site
555
-    echo '    deny all;' >> $movim_nginx_site
556
-    echo '  }' >> $movim_nginx_site
557
-    echo '' >> $movim_nginx_site
558
-    echo '}' >> $movim_nginx_site
532
+    nginx_limits "$MOVIM_DOMAIN_NAME" '15m'
533
+    { echo "    try_files \$uri \$uri/ @movim;";
534
+      echo '  }';
535
+      echo '';
536
+      echo '  location /ws/ {';
537
+      echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;";
538
+      echo '    proxy_http_version 1.1;';
539
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
540
+      echo '    proxy_set_header Connection "Upgrade";';
541
+      echo "    proxy_set_header Host \$host;";
542
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
543
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
544
+      echo '    proxy_set_header X-Forwarded-Proto https;';
545
+      echo '    proxy_redirect off;';
546
+      echo '  }';
547
+      echo '';
548
+      echo '  # Fancy URLs';
549
+      echo '  location @movim {';
550
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
551
+      echo '  }';
552
+      echo '';
553
+      echo '  # Restrict access that is unnecessary anyway';
554
+      echo '  location ~ /\.(ht|git) {';
555
+      echo '    deny all;';
556
+      echo '  }';
557
+      echo '';
558
+      echo '}'; } >> "$movim_nginx_site"
559 559
 
560 560
     function_check configure_php
561 561
     configure_php
562 562
 
563 563
     function_check create_site_certificate
564
-    create_site_certificate $MOVIM_DOMAIN_NAME 'yes'
564
+    create_site_certificate "$MOVIM_DOMAIN_NAME" 'yes'
565 565
 
566 566
     # Ensure that the database gets backed up locally, if remote
567 567
     # backups are not being used
@@ -572,9 +572,9 @@ function install_movim {
572 572
     backup_database_local movim
573 573
 
574 574
     function_check nginx_ensite
575
-    nginx_ensite $MOVIM_DOMAIN_NAME
575
+    nginx_ensite "$MOVIM_DOMAIN_NAME"
576 576
 
577
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a movim -p "$MOVIM_ADMIN_PASSWORD"
577
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a movim -p "$MOVIM_ADMIN_PASSWORD"
578 578
 
579 579
     set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
580 580
 

+ 37
- 36
src/freedombone-app-mumble View File

@@ -86,7 +86,7 @@ function upgrade_mumble {
86 86
         usermod -a -G ssl-cert mumble-server
87 87
     fi
88 88
 
89
-    if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
89
+    if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
90 90
         if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
91 91
             sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
92 92
             sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
@@ -117,17 +117,18 @@ function backup_local_mumble {
117 117
 }
118 118
 
119 119
 function restore_local_mumble {
120
-    if [ -d $USB_MOUNT/backup/mumble ]; then
120
+    if [ -d "$USB_MOUNT/backup/mumble" ]; then
121 121
         echo $"Restoring mumble settings"
122 122
         temp_restore_dir=/root/tempmumble
123 123
         function_check restore_directory_from_usb
124 124
         restore_directory_from_usb $temp_restore_dir voip
125 125
         restore_directory_from_usb $temp_restore_dir mumble
126
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
127
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
126
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
127
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini" /etc/
128 128
         else
129 129
             cp -f $temp_restore_dir/mumble-server.ini /etc/
130 130
         fi
131
+        # shellcheck disable=SC2181
131 132
         if [ ! "$?" = "0" ]; then
132 133
             rm -rf $temp_restore_dir
133 134
             function_check set_user_permissions
@@ -136,11 +137,12 @@ function restore_local_mumble {
136 137
             backup_unmount_drive
137 138
             exit 3679
138 139
         fi
139
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
140
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
140
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
141
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite" /var/lib/mumble-server/
141 142
         else
142 143
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
143 144
         fi
145
+        # shellcheck disable=SC2181
144 146
         if [ ! "$?" = "0" ]; then
145 147
             rm -rf $temp_restore_dir
146 148
             function_check set_user_permissions
@@ -171,29 +173,27 @@ function backup_remote_mumble {
171 173
 }
172 174
 
173 175
 function restore_remote_mumble {
174
-    if [ -d $SERVER_DIRECTORY/backup/mumble ]; then
176
+    if [ -d "$SERVER_DIRECTORY/backup/mumble" ]; then
175 177
         echo $"Restoring Mumble settings"
176 178
         temp_restore_dir=/root/tempmumble
177 179
         function_check restore_directory_from_friend
178 180
         restore_directory_from_friend $temp_restore_dir mumble
179
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
180
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
181
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
182
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini" /etc/
181 183
         else
182 184
             cp -f $temp_restore_dir/mumble-server.ini /etc/
183 185
         fi
186
+        # shellcheck disable=SC2181
184 187
         if [ ! "$?" = "0" ]; then
185 188
             rm -rf $temp_restore_dir
186 189
             exit 7823
187 190
         fi
188
-        if [ ! "$?" = "0" ]; then
189
-            rm -rf $temp_restore_dir
190
-            exit 7823
191
-        fi
192
-        if [ $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
193
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
191
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
192
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite" /var/lib/mumble-server/
194 193
         else
195 194
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
196 195
         fi
196
+        # shellcheck disable=SC2181
197 197
         if [ ! "$?" = "0" ]; then
198 198
             rm -rf $temp_restore_dir
199 199
             exit 276
@@ -221,7 +221,7 @@ function remove_mumble {
221 221
     fi
222 222
     function_check remove_onion_service
223 223
     remove_onion_service mumble ${MUMBLE_PORT}
224
-    sed -i '/mumble/d' $COMPLETION_FILE
224
+    sed -i '/mumble/d' "$COMPLETION_FILE"
225 225
 }
226 226
 
227 227
 function configure_firewall_for_mumble {
@@ -238,34 +238,34 @@ function configure_firewall_for_mumble {
238 238
 function install_mumble {
239 239
     apt-get -yq install mumble-server
240 240
 
241
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
242
-        MUMBLE_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
241
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
242
+        MUMBLE_SERVER_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
243 243
     else
244
-        if [ ! $MUMBLE_SERVER_PASSWORD ]; then
245
-            MUMBLE_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
246
-            if [ ${#MUMBLE_SERVER_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
247
-                MUMBLE_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
244
+        if [ ! "$MUMBLE_SERVER_PASSWORD" ]; then
245
+            MUMBLE_SERVER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
246
+            if [ ${#MUMBLE_SERVER_PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
247
+                MUMBLE_SERVER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
248 248
             fi
249 249
         fi
250 250
     fi
251 251
 
252 252
     if [[ ${ONION_ONLY} == 'no' ]]; then
253
-        if [ ! -d /var/www/${DEFAULT_DOMAIN_NAME}/htdocs ]; then
254
-            mkdir /var/www/${DEFAULT_DOMAIN_NAME}/htdocs
253
+        if [ ! -d "/var/www/${DEFAULT_DOMAIN_NAME}/htdocs" ]; then
254
+            mkdir "/var/www/${DEFAULT_DOMAIN_NAME}/htdocs"
255 255
         fi
256
-        if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
257
-            if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt ]; then
258
-                rm /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt
256
+        if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
257
+            if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
258
+                rm "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt"
259 259
             fi
260
-            if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam ]; then
261
-                rm /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam
260
+            if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam" ]; then
261
+                rm "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam"
262 262
             fi
263 263
             echo $'Obtaining certificate for the main domain'
264 264
             function_check create_site_certificate
265
-            create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
266
-            chmod 755 /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam
265
+            create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
266
+            chmod 755 "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam"
267 267
 
268
-            if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt ]; then
268
+            if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
269 269
                 echo $'Incorrect certificate generated'
270 270
                 exit 78352
271 271
             fi
@@ -276,9 +276,9 @@ function install_mumble {
276 276
 
277 277
 
278 278
     # Make an ssl cert for the server
279
-    if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
279
+    if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
280 280
         if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
281
-            ${PROJECT_NAME}-addcert -h mumble --dhkey $DH_KEYLENGTH
281
+            "${PROJECT_NAME}-addcert" -h mumble --dhkey "$DH_KEYLENGTH"
282 282
             function_check check_certificates
283 283
             check_certificates mumble
284 284
         fi
@@ -318,7 +318,7 @@ function install_mumble {
318 318
         echo 'allowping=False' >> /etc/mumble-server.ini
319 319
     fi
320 320
     sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
321
-    if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
321
+    if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
322 322
         sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
323 323
         sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
324 324
     else
@@ -335,7 +335,8 @@ function install_mumble {
335 335
     sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
336 336
     sed -i "s|port=.*|port=${MUMBLE_PORT}|g" /etc/mumble-server.ini
337 337
 
338
-    MUMBLE_ONION_HOSTNAME=$(add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT})
338
+    #MUMBLE_ONION_HOSTNAME=$(add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT})
339
+    add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT}
339 340
 
340 341
     # turn off logs by default
341 342
     sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini

+ 229
- 242
src/freedombone-app-nextcloud View File

@@ -60,14 +60,14 @@ function logging_off_nextcloud {
60 60
 function remove_user_nextcloud {
61 61
     remove_username="$1"
62 62
 
63
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp nextcloud
63
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp nextcloud
64 64
 }
65 65
 
66 66
 function add_user_nextcloud {
67 67
     new_username="$1"
68 68
     new_user_password="$2"
69 69
 
70
-    ${PROJECT_NAME}-pass -u $new_username -a nextcloud -p "$new_user_password"
70
+    "${PROJECT_NAME}-pass" -u "$new_username" -a nextcloud -p "$new_user_password"
71 71
     echo '0'
72 72
 }
73 73
 
@@ -76,12 +76,12 @@ function change_password_nextcloud {
76 76
 
77 77
     export OC_PASS="$2"
78 78
     su -s /bin/sh www-data -c "php occ user:resetpassword --password-from-env $curr_username"
79
-    ${PROJECT_NAME}-pass -u $curr_username -a nextcloud -p "$OC_PASS"
79
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a nextcloud -p "$OC_PASS"
80 80
     export OC_PASS=""
81 81
 }
82 82
 
83 83
 function install_interactive_nextcloud {
84
-    if [ ! $ONION_ONLY ]; then
84
+    if [ ! "$ONION_ONLY" ]; then
85 85
         ONION_ONLY='no'
86 86
     fi
87 87
 
@@ -91,42 +91,40 @@ function install_interactive_nextcloud {
91 91
         NEXTCLOUD_DETAILS_COMPLETE=
92 92
         while [ ! $NEXTCLOUD_DETAILS_COMPLETE ]
93 93
         do
94
-            data=$(tempfile 2>/dev/null)
95
-            trap "rm -f $data" 0 1 2 5 15
94
+            data=$(mktemp 2>/dev/null)
96 95
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
97 96
                 dialog --backtitle $"Freedombone Configuration" \
98 97
                        --title $"NextCloud Configuration" \
99
-                       --form $"\nPlease enter your NextCloud details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
98
+                       --form $"\\nPlease enter your NextCloud details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
100 99
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
101 100
                        $"Code:" 2 1 "$(grep 'NEXTCLOUD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
102
-                       2> $data
101
+                       2> "$data"
103 102
             else
104 103
                 dialog --backtitle $"Freedombone Configuration" \
105 104
                        --title $"NextCloud Configuration" \
106
-                       --form $"\nPlease enter your NextCloud 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 \
105
+                       --form $"\\nPlease enter your NextCloud details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 2 \
107 106
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
108
-                       2> $data
107
+                       2> "$data"
109 108
             fi
110 109
             sel=$?
111 110
             case $sel in
112
-                1) exit 1;;
113
-                255) exit 1;;
111
+                1) rm -f "$data"
112
+                   exit 1;;
113
+                255) rm -f "$data"
114
+                     exit 1;;
114 115
             esac
115
-            NEXTCLOUD_DOMAIN_NAME=$(cat $data | sed -n 1p)
116
-            if [ ${#img_url} -gt 1 ]; then
117
-                NEXTCLOUD_BACKGROUND_IMAGE_URL=$img_url
118
-            fi
119
-            if [ $NEXTCLOUD_DOMAIN_NAME ]; then
116
+            NEXTCLOUD_DOMAIN_NAME=$(sed -n 1p < "$data")
117
+            if [ "$NEXTCLOUD_DOMAIN_NAME" ]; then
120 118
                 TEST_DOMAIN_NAME=$NEXTCLOUD_DOMAIN_NAME
121 119
                 validate_domain_name
122
-                if [[ $TEST_DOMAIN_NAME != $NEXTCLOUD_DOMAIN_NAME ]]; then
120
+                if [[ "$TEST_DOMAIN_NAME" != "$NEXTCLOUD_DOMAIN_NAME" ]]; then
123 121
                     NEXTCLOUD_DOMAIN_NAME=
124 122
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
125 123
                 else
126 124
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
127
-                        NEXTCLOUD_CODE=$(cat $data | sed -n 2p)
125
+                        NEXTCLOUD_CODE=$(sed -n 2p < "$data")
128 126
                         validate_freedns_code "$NEXTCLOUD_CODE"
129
-                        if [ ! $VALID_CODE ]; then
127
+                        if [ ! "$VALID_CODE" ]; then
130 128
                             NEXTCLOUD_DOMAIN_NAME=
131 129
                         fi
132 130
                     fi
@@ -135,11 +133,12 @@ function install_interactive_nextcloud {
135 133
             if [ $NEXTCLOUD_DOMAIN_NAME ]; then
136 134
                 NEXTCLOUD_DETAILS_COMPLETE="yes"
137 135
             fi
136
+            rm -f "$data"
138 137
         done
139 138
 
140 139
         # remove any invalid characters
141 140
         if [ ${#NEXTCLOUD_TITLE} -gt 0 ]; then
142
-            new_title=$(echo "$NEXTCLOUD_TITLE" | sed "s|'||g")
141
+            new_title=${"$NEXTCLOUD_TITLE"//\'//}
143 142
             NEXTCLOUD_TITLE="$new_title"
144 143
         fi
145 144
 
@@ -156,23 +155,23 @@ function change_password_nextcloud {
156 155
 
157 156
     read_config_param ${NEXTCLOUD_DOMAIN_NAME}
158 157
 
159
-    ${PROJECT_NAME}-pass -u "$curr_username" -a nextcloud -p "$new_user_password"
158
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a nextcloud -p "$new_user_password"
160 159
 }
161 160
 
162 161
 function nextcloud_create_database {
163
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
164
-        NEXTCLOUD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
162
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
163
+        NEXTCLOUD_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
165 164
     else
166
-        if [ ! $NEXTCLOUD_ADMIN_PASSWORD ]; then
167
-            NEXTCLOUD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
165
+        if [ ! "$NEXTCLOUD_ADMIN_PASSWORD" ]; then
166
+            NEXTCLOUD_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
168 167
         fi
169 168
     fi
170
-    if [ ! $NEXTCLOUD_ADMIN_PASSWORD ]; then
169
+    if [ ! "$NEXTCLOUD_ADMIN_PASSWORD" ]; then
171 170
         return
172 171
     fi
173 172
 
174 173
     function_check create_database
175
-    create_database nextcloud "$NEXTCLOUD_ADMIN_PASSWORD" $MY_USERNAME
174
+    create_database nextcloud "$NEXTCLOUD_ADMIN_PASSWORD" "$MY_USERNAME"
176 175
 }
177 176
 
178 177
 function reconfigure_nextcloud {
@@ -186,7 +185,7 @@ function configure_interactive_nextcloud {
186 185
 function upgrade_nextcloud_base {
187 186
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
188 187
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/data
189
-    cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
188
+    cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 232547985
190 189
     sudo -u www-data ./occ maintenance:repair
191 190
     sudo -u www-data ./occ files:cleanup
192 191
     sudo -u www-data ./occ files:scan --all
@@ -200,13 +199,13 @@ function upgrade_nextcloud {
200 199
         return
201 200
     fi
202 201
 
203
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
202
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
204 203
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
205 204
     fi
206 205
 
207 206
     # update to the next commit
208 207
     function_check set_repo_commit
209
-    set_repo_commit /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs "nextcloud commit" "$NEXTCLOUD_COMMIT" $NEXTCLOUD_REPO
208
+    set_repo_commit "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" "nextcloud commit" "$NEXTCLOUD_COMMIT" "$NEXTCLOUD_REPO"
210 209
 
211 210
     upgrade_nextcloud_base
212 211
     sudo -u www-data ./occ upgrade
@@ -215,22 +214,22 @@ function upgrade_nextcloud {
215 214
 
216 215
 function backup_local_nextcloud {
217 216
     NEXTCLOUD_DOMAIN_NAME='nextcloud'
218
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
217
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
219 218
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
220 219
     fi
221 220
 
222 221
     source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
223
-    if [ -d $source_directory ]; then
222
+    if [ -d "$source_directory" ]; then
224 223
         function_check suspend_site
225
-        suspend_site ${NEXTCLOUD_DOMAIN_NAME}
224
+        suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
226 225
 
227 226
         dest_directory=nextcloudfiles
228 227
         function_check backup_directory_to_usb
229
-        backup_directory_to_usb $source_directory $dest_directory
228
+        backup_directory_to_usb "$source_directory" "$dest_directory"
230 229
 
231 230
         source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
232 231
         dest_directory=nextcloudconfig
233
-        backup_directory_to_usb $source_directory $dest_directory
232
+        backup_directory_to_usb "$source_directory" "$dest_directory"
234 233
 
235 234
         function_check backup_database_to_usb
236 235
         backup_database_to_usb nextcloud
@@ -241,26 +240,26 @@ function backup_local_nextcloud {
241 240
 }
242 241
 
243 242
 function restore_local_nextcloud {
244
-    if ! grep -q "nextcloud domain" $COMPLETION_FILE; then
243
+    if ! grep -q "nextcloud domain" "$COMPLETION_FILE"; then
245 244
         return
246 245
     fi
247 246
     NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
248
-    if [ $NEXTCLOUD_DOMAIN_NAME ]; then
247
+    if [ "$NEXTCLOUD_DOMAIN_NAME" ]; then
249 248
 
250 249
         temp_restore_dir=/root/tempnextcloud
251 250
         function_check nextcloud_create_database
252 251
         nextcloud_create_database
253
-        restore_database nextcloud ${NEXTCLOUD_DOMAIN_NAME}
252
+        restore_database nextcloud "${NEXTCLOUD_DOMAIN_NAME}"
254 253
 
255 254
         temp_restore_dir=/root/tempnextcloudfiles
256 255
         restore_directory_from_usb $temp_restore_dir nextcloudfiles
257 256
 
258
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data ]; then
259
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data /var/www/${NEXTCLOUD_DOMAIN_NAME}/
257
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" ]; then
258
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
260 259
         else
261
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/
260
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
262 261
         fi
263
-
262
+        # shellcheck disable=SC2181
264 263
         if [ ! "$?" = "0" ]; then
265 264
             set_user_permissions
266 265
             backup_unmount_drive
@@ -271,12 +270,13 @@ function restore_local_nextcloud {
271 270
         temp_restore_dir=/root/tempnextcloudconfig
272 271
         restore_directory_from_usb $temp_restore_dir nextcloudconfig
273 272
 
274
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config ]; then
275
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
273
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" ]; then
274
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
276 275
         else
277
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/
276
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/"
278 277
         fi
279 278
 
279
+        # shellcheck disable=SC2181
280 280
         if [ ! "$?" = "0" ]; then
281 281
             set_user_permissions
282 282
             backup_unmount_drive
@@ -284,9 +284,9 @@ function restore_local_nextcloud {
284 284
         fi
285 285
         rm -rf ${temp_restore_dir}
286 286
 
287
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
288
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/data
289
-        cd $nextcloud_dir
287
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
288
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/data"
289
+        cd "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs" || exit 14893545875
290 290
         sudo -u www-data ./occ maintenance:repair
291 291
         sudo -u www-data ./occ files:cleanup
292 292
         sudo -u www-data ./occ files:scan --all
@@ -294,21 +294,21 @@ function restore_local_nextcloud {
294 294
 }
295 295
 
296 296
 function backup_remote_nextcloud {
297
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
297
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
298 298
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
299 299
         temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
300
-        if [ -d $temp_backup_dir ]; then
300
+        if [ -d "$temp_backup_dir" ]; then
301 301
             function_check suspend_site
302
-            suspend_site ${NEXTCLOUD_DOMAIN_NAME}
302
+            suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
303 303
 
304 304
             function_check backup_database_to_friend
305 305
             backup_database_to_friend nextcloud
306 306
 
307 307
             function_check backup_directory_to_friend
308
-            backup_directory_to_friend $temp_backup_dir nextclouddata
308
+            backup_directory_to_friend "$temp_backup_dir" nextclouddata
309 309
 
310 310
             temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
311
-            backup_directory_to_friend $temp_backup_dir nextcloudconfig
311
+            backup_directory_to_friend "$temp_backup_dir" nextcloudconfig
312 312
 
313 313
             function_check restart_site
314 314
             restart_site
@@ -319,7 +319,7 @@ function backup_remote_nextcloud {
319 319
 }
320 320
 
321 321
 function restore_remote_nextcloud {
322
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
322
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
323 323
         echo $"Restoring nextcloud"
324 324
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
325 325
 
@@ -327,7 +327,7 @@ function restore_remote_nextcloud {
327 327
         nextcloud_create_database
328 328
 
329 329
         function_check restore_database_from_friend
330
-        restore_database_from_friend nextcloud ${NEXTCLOUD_DOMAIN_NAME}
330
+        restore_database_from_friend nextcloud "${NEXTCLOUD_DOMAIN_NAME}"
331 331
         if [ -d /root/tempnextcloud ]; then
332 332
             rm -rf /root/tempnextcloud
333 333
         fi
@@ -335,12 +335,12 @@ function restore_remote_nextcloud {
335 335
         temp_restore_dir=/root/tempnextcloudfiles
336 336
         restore_directory_from_friend $temp_restore_dir nextcloudfiles
337 337
 
338
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data ]; then
339
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data /var/www/${NEXTCLOUD_DOMAIN_NAME}/
338
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" ]; then
339
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
340 340
         else
341
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/
341
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
342 342
         fi
343
-
343
+        # shellcheck disable=SC2181
344 344
         if [ ! "$?" = "0" ]; then
345 345
             exit 768254
346 346
         fi
@@ -349,20 +349,21 @@ function restore_remote_nextcloud {
349 349
         temp_restore_dir=/root/tempnextcloudconfig
350 350
         restore_directory_from_friend $temp_restore_dir nextcloudconfig
351 351
 
352
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config ]; then
353
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
352
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" ]; then
353
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
354 354
         else
355
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/
355
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/"
356 356
         fi
357 357
 
358
+        # shellcheck disable=SC2181
358 359
         if [ ! "$?" = "0" ]; then
359 360
             exit 573427
360 361
         fi
361 362
         rm -rf ${temp_restore_dir}
362 363
 
363
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
364
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/data
365
-        cd /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
364
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
365
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/data"
366
+        cd "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs" || exit 2642846824
366 367
         sudo -u www-data ./occ maintenance:repair
367 368
         sudo -u www-data ./occ files:cleanup
368 369
         sudo -u www-data ./occ files:scan --all
@@ -381,13 +382,13 @@ function remove_nextcloud {
381 382
     read_config_param "NEXTCLOUD_DOMAIN_NAME"
382 383
     read_config_param "MY_USERNAME"
383 384
     echo "Removing $NEXTCLOUD_DOMAIN_NAME"
384
-    nginx_dissite $NEXTCLOUD_DOMAIN_NAME
385
-    remove_certs $NEXTCLOUD_DOMAIN_NAME
386
-    if [ -d /var/www/$NEXTCLOUD_DOMAIN_NAME ]; then
387
-        rm -rf /var/www/$NEXTCLOUD_DOMAIN_NAME
385
+    nginx_dissite "$NEXTCLOUD_DOMAIN_NAME"
386
+    remove_certs "$NEXTCLOUD_DOMAIN_NAME"
387
+    if [ -d "/var/www/$NEXTCLOUD_DOMAIN_NAME" ]; then
388
+        rm -rf "/var/www/$NEXTCLOUD_DOMAIN_NAME"
388 389
     fi
389
-    if [ -f /etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME ]; then
390
-        rm /etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
390
+    if [ -f "/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME" ]; then
391
+        rm "/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME"
391 392
     fi
392 393
     function_check drop_database
393 394
     drop_database nextcloud
@@ -395,17 +396,17 @@ function remove_nextcloud {
395 396
     remove_onion_service nextcloud ${NEXTCLOUD_ONION_PORT}
396 397
     remove_app nextcloud
397 398
     remove_completion_param install_nextcloud
398
-    sed -i '/nextcloud/d' $COMPLETION_FILE
399
+    sed -i '/nextcloud/d' "$COMPLETION_FILE"
399 400
     remove_backup_database_local nextcloud
400 401
 
401 402
     function_check remove_ddns_domain
402
-    remove_ddns_domain $NEXTCLOUD_DOMAIN_NAME
403
+    remove_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
403 404
     systemctl restart nginx
404 405
     systemctl restart php7.0-fpm
405 406
 }
406 407
 
407 408
 function install_nextcloud_main {
408
-    if [ ! $NEXTCLOUD_DOMAIN_NAME ]; then
409
+    if [ ! "$NEXTCLOUD_DOMAIN_NAME" ]; then
409 410
         echo $'No domain name was given for nextcloud'
410 411
         exit 7359
411 412
     fi
@@ -434,34 +435,34 @@ function install_nextcloud_main {
434 435
     fi
435 436
     sed -i 's|;env[PATH]|env[PATH]|g' /etc/php/7.0/fpm/pool.d/www.conf
436 437
 
437
-    if [ ! -d /var/www/$NEXTCLOUD_DOMAIN_NAME ]; then
438
-        mkdir /var/www/$NEXTCLOUD_DOMAIN_NAME
438
+    if [ ! -d "/var/www/$NEXTCLOUD_DOMAIN_NAME" ]; then
439
+        mkdir "/var/www/$NEXTCLOUD_DOMAIN_NAME"
439 440
     fi
440
-    if [ ! -d /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs ]; then
441
+    if [ ! -d "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" ]; then
441 442
 
442 443
         if [ -d /repos/nextcloud ]; then
443
-            mkdir /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
444
-            cp -r -p /repos/nextcloud/. /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
445
-            cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
444
+            mkdir "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
445
+            cp -r -p /repos/nextcloud/. "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
446
+            cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 2783539793
446 447
             git pull
447 448
         else
448 449
             function_check git_clone
449
-            git_clone $NEXTCLOUD_REPO /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
450
+            git_clone "$NEXTCLOUD_REPO" "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
450 451
         fi
451 452
 
452
-        if [ ! -d /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs ]; then
453
+        if [ ! -d "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" ]; then
453 454
             echo $'Unable to clone nextcloud repo'
454 455
             exit 87525
455 456
         fi
456 457
     fi
457 458
 
458
-    cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
459
+    cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 3468346834
459 460
     git submodule update --init
460 461
     git checkout $NEXTCLOUD_COMMIT -b $NEXTCLOUD_COMMIT
461 462
     set_completion_param "nextcloud commit" "$NEXTCLOUD_COMMIT"
462 463
 
463
-    chmod g+w /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
464
-    chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
464
+    chmod g+w "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
465
+    chown -R www-data:www-data "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
465 466
 
466 467
     function_check nextcloud_create_database
467 468
     nextcloud_create_database
@@ -474,154 +475,154 @@ function install_nextcloud_main {
474 475
     fi
475 476
 
476 477
     function_check add_ddns_domain
477
-    add_ddns_domain $NEXTCLOUD_DOMAIN_NAME
478
+    add_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
478 479
 
479 480
     nextcloud_nginx_site=/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
480 481
     if [[ $ONION_ONLY == "no" ]]; then
481 482
         function_check nginx_http_redirect
482
-        nginx_http_redirect $NEXTCLOUD_DOMAIN_NAME
483
-        echo 'server {' >> $nextcloud_nginx_site
484
-        echo '  listen 443 ssl;' >> $nextcloud_nginx_site
485
-        echo '  #listen [::]:443 ssl;' >> $nextcloud_nginx_site
486
-        echo "  server_name $NEXTCLOUD_DOMAIN_NAME;" >> $nextcloud_nginx_site
487
-        echo '' >> $nextcloud_nginx_site
488
-        echo '  # Security' >> $nextcloud_nginx_site
483
+        nginx_http_redirect "$NEXTCLOUD_DOMAIN_NAME"
484
+        { echo 'server {';
485
+          echo '  listen 443 ssl;';
486
+          echo '  #listen [::]:443 ssl;';
487
+          echo "  server_name $NEXTCLOUD_DOMAIN_NAME;";
488
+          echo '';
489
+          echo '  # Security'; } >> "$nextcloud_nginx_site"
489 490
         function_check nginx_ssl
490
-        nginx_ssl $NEXTCLOUD_DOMAIN_NAME mobile
491
+        nginx_ssl "$NEXTCLOUD_DOMAIN_NAME" mobile
491 492
 
492 493
         function_check nginx_disable_sniffing
493
-        nginx_disable_sniffing $NEXTCLOUD_DOMAIN_NAME
494
-
495
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $nextcloud_nginx_site
496
-        echo '' >> $nextcloud_nginx_site
497
-        echo '  # Logs' >> $nextcloud_nginx_site
498
-        echo '  access_log /dev/null;' >> $nextcloud_nginx_site
499
-        echo '  error_log /dev/null;' >> $nextcloud_nginx_site
500
-        echo '' >> $nextcloud_nginx_site
501
-        echo '  # Root' >> $nextcloud_nginx_site
502
-        echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;" >> $nextcloud_nginx_site
503
-        echo '' >> $nextcloud_nginx_site
504
-        echo '  # Index' >> $nextcloud_nginx_site
505
-        echo '  index index.php;' >> $nextcloud_nginx_site
506
-        echo '' >> $nextcloud_nginx_site
507
-
508
-        # By default nextcloud advertises highly specific version information
509
-        # on status.php, which can obviously be used by adversaries.
510
-        # Blocking status.php prevents this information leak
511
-        echo '  location = /status.php {' >> $nextcloud_nginx_site
512
-        echo '    return 404;' >> $nextcloud_nginx_site
513
-        echo '  }' >> $nextcloud_nginx_site
514
-        echo '' >> $nextcloud_nginx_site
515
-
516
-        echo '  # PHP' >> $nextcloud_nginx_site
517
-        echo '  location ~ \.php {' >> $nextcloud_nginx_site
518
-        echo '    include snippets/fastcgi-php.conf;' >> $nextcloud_nginx_site
519
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $nextcloud_nginx_site
520
-        echo '    fastcgi_read_timeout 30;' >> $nextcloud_nginx_site
521
-        echo '  }' >> $nextcloud_nginx_site
522
-        echo '' >> $nextcloud_nginx_site
523
-        echo '  # Location' >> $nextcloud_nginx_site
524
-        echo '  location / {' >> $nextcloud_nginx_site
494
+        nginx_disable_sniffing "$NEXTCLOUD_DOMAIN_NAME"
495
+
496
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
497
+          echo '';
498
+          echo '  # Logs';
499
+          echo '  access_log /dev/null;';
500
+          echo '  error_log /dev/null;';
501
+          echo '';
502
+          echo '  # Root';
503
+          echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;";
504
+          echo '';
505
+          echo '  # Index';
506
+          echo '  index index.php;';
507
+          echo '';
508
+
509
+          # By default nextcloud advertises highly specific version information
510
+          # on status.php, which can obviously be used by adversaries.
511
+          # Blocking status.php prevents this information leak
512
+          echo '  location = /status.php {';
513
+          echo '    return 404;';
514
+          echo '  }';
515
+          echo '';
516
+
517
+          echo '  # PHP';
518
+          echo '  location ~ \.php {';
519
+          echo '    include snippets/fastcgi-php.conf;';
520
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
521
+          echo '    fastcgi_read_timeout 30;';
522
+          echo '  }';
523
+          echo '';
524
+          echo '  # Location';
525
+          echo '  location / {'; } >> "$nextcloud_nginx_site"
525 526
         function_check nginx_limits
526
-        nginx_limits $NEXTCLOUD_DOMAIN_NAME '15m'
527
-        echo '    try_files $uri $uri/ @nextcloud;' >> $nextcloud_nginx_site
528
-        echo '  }' >> $nextcloud_nginx_site
529
-        echo '' >> $nextcloud_nginx_site
530
-        echo '  # Fancy URLs' >> $nextcloud_nginx_site
531
-        echo '  location @nextcloud {' >> $nextcloud_nginx_site
532
-        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $nextcloud_nginx_site
533
-        echo '  }' >> $nextcloud_nginx_site
534
-        echo '' >> $nextcloud_nginx_site
535
-        echo '  # Restrict access that is unnecessary anyway' >> $nextcloud_nginx_site
536
-        echo '  location ~ /\.(ht|git) {' >> $nextcloud_nginx_site
537
-        echo '    deny all;' >> $nextcloud_nginx_site
538
-        echo '  }' >> $nextcloud_nginx_site
539
-        echo '' >> $nextcloud_nginx_site
540
-        echo '  location = /.well-known/carddav {' >> $nextcloud_nginx_site
541
-        echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
542
-        echo '  }' >> $nextcloud_nginx_site
543
-        echo '  location = /.well-known/caldav {' >> $nextcloud_nginx_site
544
-        echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
545
-        echo '  }' >> $nextcloud_nginx_site
546
-        echo '' >> $nextcloud_nginx_site
547
-        echo '  location /.well-known/acme-challenge { }' >> $nextcloud_nginx_site
548
-        echo '}' >> $nextcloud_nginx_site
527
+        nginx_limits "$NEXTCLOUD_DOMAIN_NAME" '15m'
528
+        { echo "    try_files \$uri \$uri/ @nextcloud;";
529
+          echo '  }';
530
+          echo '';
531
+          echo '  # Fancy URLs';
532
+          echo '  location @nextcloud {';
533
+          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
534
+          echo '  }';
535
+          echo '';
536
+          echo '  # Restrict access that is unnecessary anyway';
537
+          echo '  location ~ /\.(ht|git) {';
538
+          echo '    deny all;';
539
+          echo '  }';
540
+          echo '';
541
+          echo '  location = /.well-known/carddav {';
542
+          echo "    return 301 \$scheme://\$host/remote.php/dav;";
543
+          echo '  }';
544
+          echo '  location = /.well-known/caldav {';
545
+          echo "    return 301 \$scheme://\$host/remote.php/dav;";
546
+          echo '  }';
547
+          echo '';
548
+          echo '  location /.well-known/acme-challenge { }';
549
+          echo '}'; } >> "$nextcloud_nginx_site"
549 550
     else
550
-        echo -n '' > $nextcloud_nginx_site
551
+        echo -n '' > "$nextcloud_nginx_site"
551 552
     fi
552
-    echo 'server {' >> $nextcloud_nginx_site
553
-    echo "    listen 127.0.0.1:$NEXTCLOUD_ONION_PORT default_server;" >> $nextcloud_nginx_site
554
-    echo "    server_name $NEXTCLOUD_DOMAIN_NAME;" >> $nextcloud_nginx_site
555
-    echo '' >> $nextcloud_nginx_site
553
+    { echo 'server {';
554
+      echo "    listen 127.0.0.1:$NEXTCLOUD_ONION_PORT default_server;";
555
+      echo "    server_name $NEXTCLOUD_DOMAIN_NAME;";
556
+      echo ''; } >> "$nextcloud_nginx_site"
556 557
     function_check nginx_disable_sniffing
557
-    nginx_disable_sniffing $NEXTCLOUD_DOMAIN_NAME
558
-    echo '' >> $nextcloud_nginx_site
559
-    echo '  # Logs' >> $nextcloud_nginx_site
560
-    echo '  access_log /dev/null;' >> $nextcloud_nginx_site
561
-    echo '  error_log /dev/null;' >> $nextcloud_nginx_site
562
-    echo '' >> $nextcloud_nginx_site
563
-    echo '  # Root' >> $nextcloud_nginx_site
564
-    echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;" >> $nextcloud_nginx_site
565
-    echo '' >> $nextcloud_nginx_site
566
-    echo '  # Index' >> $nextcloud_nginx_site
567
-    echo '  index index.php;' >> $nextcloud_nginx_site
568
-    echo '' >> $nextcloud_nginx_site
569
-
570
-    # By default nextcloud advertises highly specific version information
571
-    # on status.php, which can obviously be used by adversaries.
572
-    # Blocking status.php prevents this information leak
573
-    echo '  location = /status.php {' >> $nextcloud_nginx_site
574
-    echo '    return 404;' >> $nextcloud_nginx_site
575
-    echo '  }' >> $nextcloud_nginx_site
576
-    echo '' >> $nextcloud_nginx_site
577
-
578
-    echo '  # PHP' >> $nextcloud_nginx_site
579
-    echo '  location ~ \.php {' >> $nextcloud_nginx_site
580
-    echo '    include snippets/fastcgi-php.conf;' >> $nextcloud_nginx_site
581
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $nextcloud_nginx_site
582
-    echo '    fastcgi_read_timeout 30;' >> $nextcloud_nginx_site
583
-    echo '  }' >> $nextcloud_nginx_site
584
-    echo '' >> $nextcloud_nginx_site
585
-    echo '  # Location' >> $nextcloud_nginx_site
586
-    echo '  location / {' >> $nextcloud_nginx_site
558
+    nginx_disable_sniffing "$NEXTCLOUD_DOMAIN_NAME"
559
+    { echo '';
560
+      echo '  # Logs';
561
+      echo '  access_log /dev/null;';
562
+      echo '  error_log /dev/null;';
563
+      echo '';
564
+      echo '  # Root';
565
+      echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;";
566
+      echo '';
567
+      echo '  # Index';
568
+      echo '  index index.php;';
569
+      echo '';
570
+
571
+      # By default nextcloud advertises highly specific version information
572
+      # on status.php, which can obviously be used by adversaries.
573
+      # Blocking status.php prevents this information leak
574
+      echo '  location = /status.php {';
575
+      echo '    return 404;';
576
+      echo '  }';
577
+      echo '';
578
+
579
+      echo '  # PHP';
580
+      echo '  location ~ \.php {';
581
+      echo '    include snippets/fastcgi-php.conf;';
582
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
583
+      echo '    fastcgi_read_timeout 30;';
584
+      echo '  }';
585
+      echo '';
586
+      echo '  # Location';
587
+      echo '  location / {'; } >> "$nextcloud_nginx_site"
587 588
     function_check nginx_limits
588
-    nginx_limits $NEXTCLOUD_DOMAIN_NAME '15m'
589
-    echo '    try_files $uri $uri/ @nextcloud;' >> $nextcloud_nginx_site
590
-    echo '  }' >> $nextcloud_nginx_site
591
-    echo '' >> $nextcloud_nginx_site
592
-    echo '  # Fancy URLs' >> $nextcloud_nginx_site
593
-    echo '  location @nextcloud {' >> $nextcloud_nginx_site
594
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $nextcloud_nginx_site
595
-    echo '  }' >> $nextcloud_nginx_site
596
-    echo '' >> $nextcloud_nginx_site
597
-    echo '  # Restrict access that is unnecessary anyway' >> $nextcloud_nginx_site
598
-    echo '  location ~ /\.(ht|git) {' >> $nextcloud_nginx_site
599
-    echo '    deny all;' >> $nextcloud_nginx_site
600
-    echo '  }' >> $nextcloud_nginx_site
601
-    echo '' >> $nextcloud_nginx_site
602
-    echo '  location = /.well-known/carddav {' >> $nextcloud_nginx_site
603
-    echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
604
-    echo '  }' >> $nextcloud_nginx_site
605
-    echo '  location = /.well-known/caldav {' >> $nextcloud_nginx_site
606
-    echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
607
-    echo '  }' >> $nextcloud_nginx_site
608
-    echo '' >> $nextcloud_nginx_site
609
-    echo '  location /.well-known/acme-challenge { }' >> $nextcloud_nginx_site
610
-    echo '}' >> $nextcloud_nginx_site
611
-
612
-    sed -i 's| DENY;| SAMEORIGIN;|g' $nextcloud_nginx_site
589
+    nginx_limits "$NEXTCLOUD_DOMAIN_NAME" '15m'
590
+    { echo "    try_files \$uri \$uri/ @nextcloud;";
591
+      echo '  }';
592
+      echo '';
593
+      echo '  # Fancy URLs';
594
+      echo '  location @nextcloud {';
595
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
596
+      echo '  }';
597
+      echo '';
598
+      echo '  # Restrict access that is unnecessary anyway';
599
+      echo '  location ~ /\.(ht|git) {';
600
+      echo '    deny all;';
601
+      echo '  }';
602
+      echo '';
603
+      echo '  location = /.well-known/carddav {';
604
+      echo "    return 301 \$scheme://\$host/remote.php/dav;";
605
+      echo '  }';
606
+      echo '  location = /.well-known/caldav {';
607
+      echo "    return 301 \$scheme://\$host/remote.php/dav;";
608
+      echo '  }';
609
+      echo '';
610
+      echo '  location /.well-known/acme-challenge { }';
611
+      echo '}'; } >> "$nextcloud_nginx_site"
612
+
613
+    sed -i 's| DENY;| SAMEORIGIN;|g' "$nextcloud_nginx_site"
613 614
 
614 615
     # NextCloud doesn't like content-security-policy at all
615
-    sed -i '/Content-Security-Policy/d' $nextcloud_nginx_site
616
+    sed -i '/Content-Security-Policy/d' "$nextcloud_nginx_site"
616 617
 
617 618
     function_check configure_php
618 619
     configure_php
619 620
 
620 621
     function_check create_site_certificate
621
-    create_site_certificate $NEXTCLOUD_DOMAIN_NAME 'yes'
622
+    create_site_certificate "$NEXTCLOUD_DOMAIN_NAME" 'yes'
622 623
 
623
-    if [[ $ONION_ONLY == "no" ]]; then
624
-        if [ ! -f /etc/ssl/certs/${NEXTCLOUD_DOMAIN_NAME}.pem ]; then
624
+    if [[ "$ONION_ONLY" == "no" ]]; then
625
+        if [ ! -f "/etc/ssl/certs/${NEXTCLOUD_DOMAIN_NAME}.pem" ]; then
625 626
             echo $'Certificate not generated for nextcloud'
626 627
             exit 725762
627 628
         fi
@@ -636,31 +637,18 @@ function install_nextcloud_main {
636 637
     backup_database_local nextcloud
637 638
 
638 639
     function_check nginx_ensite
639
-    nginx_ensite $NEXTCLOUD_DOMAIN_NAME
640
-
641
-    # NOTE: For the typical case always enable SSL and only
642
-    # disable it if in onion only mode. This is due to complexities
643
-    # with the way URLs are generated by nextcloud
644
-    nextcloud_ssl='always'
645
-    if [[ $ONION_ONLY != 'no' ]]; then
646
-        nextcloud_ssl='never'
647
-    fi
640
+    nginx_ensite "$NEXTCLOUD_DOMAIN_NAME"
648 641
 
649 642
     NEXTCLOUD_ONION_HOSTNAME=$(add_onion_service nextcloud 80 ${NEXTCLOUD_ONION_PORT})
650 643
 
651
-    NEXTCLOUD_SERVER=${NEXTCLOUD_DOMAIN_NAME}
652
-    if [[ $ONION_ONLY != 'no' ]]; then
653
-        NEXTCLOUD_SERVER=${NEXTCLOUD_ONION_HOSTNAME}
654
-    fi
655
-
656 644
     systemctl restart php7.0-fpm
657 645
     systemctl restart nginx
658 646
 
659
-    ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$NEXTCLOUD_DOMAIN_NAME" -g nextcloud --public no
647
+    "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$NEXTCLOUD_DOMAIN_NAME" -g nextcloud --public no
660 648
 
661
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a nextcloud -p "$NEXTCLOUD_ADMIN_PASSWORD"
649
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a nextcloud -p "$NEXTCLOUD_ADMIN_PASSWORD"
662 650
 
663
-    cd /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
651
+    cd "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs" || exit 2467245247
664 652
     if [ -d config ]; then
665 653
         chown -R www-data:www-data config
666 654
     fi
@@ -669,7 +657,7 @@ function install_nextcloud_main {
669 657
     fi
670 658
 
671 659
     chmod +x occ
672
-    ./occ maintenance:install --database-name nextcloud --admin-user ${MY_USERNAME} --admin-pass "${NEXTCLOUD_ADMIN_PASSWORD}" --database mysql --database-user root --database-pass "${MARIADB_PASSWORD}"
660
+    ./occ maintenance:install --database-name nextcloud --admin-user "${MY_USERNAME}" --admin-pass "${NEXTCLOUD_ADMIN_PASSWORD}" --database mysql --database-user root --database-pass "${MARIADB_PASSWORD}"
673 661
     if [ ! -d data ]; then
674 662
         echo $'Nextcloud data directory was not found. This probably means that the installation failed.'
675 663
         echo ''
@@ -683,20 +671,19 @@ function install_nextcloud_main {
683 671
     sudo -u www-data ./occ status
684 672
     sudo -u www-data ./occ app:list
685 673
     sudo -u www-data ./occ app:enable encryption
686
-    sudo -u www-data ./occ encryption:enable
687
-    if [ ! "$?" = "0" ]; then
674
+    if ! sudo -u www-data ./occ encryption:enable; then
688 675
         echo $'Encryption not enabled'
689 676
         exit 73527
690 677
     fi
691 678
     sudo -u www-data ./occ encryption:status
692 679
     sudo -u www-data ./occ config:system:set appstoreenabled --value=false
693
-    chmod g+w /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php
694
-    chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
680
+    chmod g+w "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php"
681
+    chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
695 682
     chmod 0644 .htaccess
696 683
     chmod 0750 data
697
-    chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/data
698
-    sudo -u www-data ./occ config:system:set trusted_domains 1 --value=$NEXTCLOUD_DOMAIN_NAME
699
-    sudo -u www-data ./occ config:system:set trusted_domains 2 --value=$NEXTCLOUD_ONION_HOSTNAME
684
+    chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/data"
685
+    sudo -u www-data ./occ config:system:set trusted_domains 1 --value="$NEXTCLOUD_DOMAIN_NAME"
686
+    sudo -u www-data ./occ config:system:set trusted_domains 2 --value="$NEXTCLOUD_ONION_HOSTNAME"
700 687
     sudo -u www-data ./occ files:cleanup
701 688
     sudo -u www-data ./occ files:scan --all
702 689
     sudo -u www-data ./occ maintenance:repair
@@ -705,8 +692,8 @@ function install_nextcloud_main {
705 692
     systemctl restart mariadb
706 693
 
707 694
     # move the data directory
708
-    mv /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/data /var/www/${NEXTCLOUD_DOMAIN_NAME}/
709
-    sed -i "s|'datadirectory'.*|'datadirectory' => '/var/www/$NEXTCLOUD_DOMAIN_NAME/data',|g" /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php
695
+    mv "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/data" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
696
+    sed -i "s|'datadirectory'.*|'datadirectory' => '/var/www/$NEXTCLOUD_DOMAIN_NAME/data',|g" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php"
710 697
 
711 698
     set_completion_param "nextcloud domain" "$NEXTCLOUD_DOMAIN_NAME"
712 699
 
@@ -714,7 +701,7 @@ function install_nextcloud_main {
714 701
 }
715 702
 
716 703
 function install_nextcloud {
717
-    if [ ! $ONION_ONLY ]; then
704
+    if [ ! "$ONION_ONLY" ]; then
718 705
         ONION_ONLY='no'
719 706
     fi
720 707
 

+ 331
- 334
src/freedombone-app-peertube View File

@@ -55,14 +55,14 @@ peertube_variables=(PEERTUBE_DOMAIN_NAME
55 55
                     MY_EMAIL_ADDRESS)
56 56
 
57 57
 function peertube_create_database {
58
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
59
-        PEERTUBE_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
58
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
59
+        PEERTUBE_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
60 60
     else
61
-        if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
62
-            PEERTUBE_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
61
+        if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
62
+            PEERTUBE_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
63 63
         fi
64 64
     fi
65
-    if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
65
+    if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
66 66
         return
67 67
     fi
68 68
 
@@ -82,7 +82,8 @@ function logging_off_peertube {
82 82
 }
83 83
 
84 84
 function remove_user_peertube {
85
-    remove_username="$1"
85
+    echo -n ''
86
+#    remove_username="$1"
86 87
 }
87 88
 
88 89
 function add_user_peertube {
@@ -91,14 +92,14 @@ function add_user_peertube {
91 92
         return
92 93
     fi
93 94
 
94
-    new_username="$1"
95
-    new_user_password="$2"
95
+#    new_username="$1"
96
+#    new_user_password="$2"
96 97
 
97 98
     echo '0'
98 99
 }
99 100
 
100 101
 function install_interactive_peertube {
101
-    if [ ! $ONION_ONLY ]; then
102
+    if [ ! "$ONION_ONLY" ]; then
102 103
         ONION_ONLY='no'
103 104
     fi
104 105
 
@@ -113,15 +114,14 @@ function install_interactive_peertube {
113 114
 }
114 115
 
115 116
 function peertube_set_admin_email {
116
-    read_config_param $MY_EMAIL_ADDRESS
117
-    data=$(tempfile 2>/dev/null)
118
-    trap "rm -f $data" 0 1 2 5 15
117
+    read_config_param "$MY_EMAIL_ADDRESS"
118
+    data=$(mktemp 2>/dev/null)
119 119
     dialog --title $"Set PeerTube administrator email address" \
120 120
            --backtitle $"Freedombone Control Panel" \
121
-           --inputbox $"Admin email address" 8 75 "$MY_EMAIL_ADDRESS" 2>$data
121
+           --inputbox $"Admin email address" 8 75 "$MY_EMAIL_ADDRESS" 2>"$data"
122 122
     sel=$?
123 123
     case $sel in
124
-        0)  peertube_email=$(<$data)
124
+        0)  peertube_email=$(<"$data")
125 125
             if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
126 126
                 if [ ${#peertube_email} -gt 8 ]; then
127 127
                     sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
@@ -132,13 +132,13 @@ function peertube_set_admin_email {
132 132
             fi
133 133
             ;;
134 134
     esac
135
-    rm $data
135
+    rm -f "$data"
136 136
 }
137 137
 
138 138
 function peertube_disable_signups {
139 139
     dialog --title $"Disable PeerTube signups" \
140 140
            --backtitle $"Freedombone Control Panel" \
141
-           --yesno $"\nDo you wish to disable further PeerTube signups?" 8 75
141
+           --yesno $"\\nDo you wish to disable further PeerTube signups?" 8 75
142 142
     sel=$?
143 143
     case $sel in
144 144
         0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
@@ -152,35 +152,36 @@ function peertube_disable_signups {
152 152
 function configure_interactive_peertube {
153 153
     while true
154 154
     do
155
-        data=$(tempfile 2>/dev/null)
156
-        trap "rm -f $data" 0 1 2 5 15
155
+        data=$(mktemp 2>/dev/null)
157 156
         dialog --backtitle $"Freedombone Control Panel" \
158 157
                --title $"PeerTube" \
159 158
                --radiolist $"Choose an operation:" 10 70 4 \
160 159
                1 $"Set administrator email address" off \
161 160
                2 $"Disable or enable signups" off \
162
-               3 $"Exit" on 2> $data
161
+               3 $"Exit" on 2> "$data"
163 162
         sel=$?
164 163
         case $sel in
165 164
             1) break;;
166 165
             255) break;;
167 166
         esac
168
-        case $(cat $data) in
167
+        case $(cat "$data") in
169 168
             1) peertube_set_admin_email;;
170 169
             2) peertube_disable_signups;;
171
-            3) break;;
170
+            3) rm -f "$data"
171
+               break;;
172 172
         esac
173
+        rm -f "$data"
173 174
     done
174 175
 }
175 176
 
176 177
 function change_password_peertube {
177
-    PEERTUBE_USERNAME="$1"
178
+#    PEERTUBE_USERNAME="$1"
178 179
     PEERTUBE_PASSWORD="$2"
179 180
     if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
180 181
         echo $'Peertube password is too short'
181 182
         return
182 183
     fi
183
-    #${PROJECT_NAME}-pass -u $PEERTUBE_USERNAME -a peertube -p "$PEERTUBE_PASSWORD"
184
+    #"${PROJECT_NAME}-pass" -u "$PEERTUBE_USERNAME" -a peertube -p "$PEERTUBE_PASSWORD"
184 185
 }
185 186
 
186 187
 function reconfigure_peertube {
@@ -195,7 +196,7 @@ function upgrade_peertube {
195 196
 
196 197
     read_config_param PEERTUBE_DOMAIN_NAME
197 198
     systemctl stop peertube
198
-    cd $PEERTUBE_DIR
199
+    cd "$PEERTUBE_DIR" || exit 7824552627
199 200
 
200 201
     function_check set_repo_commit
201 202
     set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
@@ -207,7 +208,7 @@ function upgrade_peertube {
207 208
 
208 209
 function backup_local_peertube {
209 210
     PEERTUBE_DOMAIN_NAME='peertube.local'
210
-    if grep -q "peertube domain" $COMPLETION_FILE; then
211
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
211 212
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
212 213
     fi
213 214
 
@@ -219,7 +220,7 @@ function backup_local_peertube {
219 220
 
220 221
     peertube_path=$PEERTUBE_DIR/videos
221 222
     if [ -d $peertube_path ]; then
222
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
223
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
223 224
         systemctl stop peertube
224 225
         backup_directory_to_usb $peertube_path peertubevideos
225 226
         systemctl start peertube
@@ -229,11 +230,11 @@ function backup_local_peertube {
229 230
 
230 231
 function restore_local_peertube {
231 232
     PEERTUBE_DOMAIN_NAME='peertube.local'
232
-    if grep -q "peertube domain" $COMPLETION_FILE; then
233
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
233 234
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
234 235
     fi
235
-    if [ $PEERTUBE_DOMAIN_NAME ]; then
236
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
236
+    if [ "$PEERTUBE_DOMAIN_NAME" ]; then
237
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
237 238
         systemctl stop peertube
238 239
 
239 240
         USE_POSTGRESQL=1
@@ -259,7 +260,7 @@ function restore_local_peertube {
259 260
 
260 261
 function backup_remote_peertube {
261 262
     PEERTUBE_DOMAIN_NAME='peertube.local'
262
-    if grep -q "peertube domain" $COMPLETION_FILE; then
263
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
263 264
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
264 265
     fi
265 266
 
@@ -272,7 +273,7 @@ function backup_remote_peertube {
272 273
     temp_backup_dir=$PEERTUBE_DIR/videos
273 274
     if [ -d $temp_backup_dir ]; then
274 275
         systemctl stop peertube
275
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
276
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
276 277
         backup_directory_to_friend $temp_backup_dir peertubevideos
277 278
         restart_site
278 279
         systemctl start peertube
@@ -284,13 +285,14 @@ function backup_remote_peertube {
284 285
 
285 286
 function restore_remote_peertube {
286 287
     PEERTUBE_DOMAIN_NAME='peertube.local'
287
-    if grep -q "peertube domain" $COMPLETION_FILE; then
288
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
288 289
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
289 290
     fi
290
-    suspend_site ${PEERTUBE_DOMAIN_NAME}
291
+    suspend_site "${PEERTUBE_DOMAIN_NAME}"
291 292
 
292 293
     systemctl stop peertube
293 294
 
295
+    # shellcheck disable=SC2034
294 296
     USE_POSTGRESQL=1
295 297
     function_check restore_database_from_friend
296 298
     restore_database_from_friend peertube
@@ -326,20 +328,20 @@ function remove_peertube {
326 328
     remove_nodejs peertube
327 329
 
328 330
     read_config_param "PEERTUBE_DOMAIN_NAME"
329
-    nginx_dissite $PEERTUBE_DOMAIN_NAME
330
-    remove_certs ${PEERTUBE_DOMAIN_NAME}
331
-    if [ -f /etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME ]; then
332
-        rm -f /etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
331
+    nginx_dissite "$PEERTUBE_DOMAIN_NAME"
332
+    remove_certs "${PEERTUBE_DOMAIN_NAME}"
333
+    if [ -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME" ]; then
334
+        rm -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME"
333 335
     fi
334
-    if [ -d /var/www/$PEERTUBE_DOMAIN_NAME ]; then
335
-        rm -rf /var/www/$PEERTUBE_DOMAIN_NAME
336
+    if [ -d "/var/www/$PEERTUBE_DOMAIN_NAME" ]; then
337
+        rm -rf "/var/www/$PEERTUBE_DOMAIN_NAME"
336 338
     fi
337 339
     remove_config_param PEERTUBE_DOMAIN_NAME
338 340
     remove_config_param PEERTUBE_CODE
339 341
     function_check remove_onion_service
340 342
     remove_onion_service peertube ${PEERTUBE_ONION_PORT}
341 343
     remove_completion_param "install_peertube"
342
-    sed -i '/peertube/d' $COMPLETION_FILE
344
+    sed -i '/peertube/d' "$COMPLETION_FILE"
343 345
 
344 346
     function_check drop_database_postgresql
345 347
     drop_database_postgresql peertube peertube
@@ -352,188 +354,189 @@ function remove_peertube {
352 354
     fi
353 355
 
354 356
     function_check remove_ddns_domain
355
-    remove_ddns_domain $PEERTUBE_DOMAIN_NAME
357
+    remove_ddns_domain "$PEERTUBE_DOMAIN_NAME"
356 358
 }
357 359
 
358 360
 function peertube_setup_web {
359 361
     peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
360 362
 
361 363
     if [[ $ONION_ONLY == "no" ]]; then
362
-        echo 'server {' > $peertube_nginx_file
363
-        echo '  listen 80;' >> $peertube_nginx_file
364
-        echo '  listen [::]:80;' >> $peertube_nginx_file
365
-        echo "  server_name $PEERTUBE_DOMAIN_NAME;" >> $peertube_nginx_file
366
-        echo '  rewrite ^ https://$server_name$request_uri? permanent;' >> $peertube_nginx_file
367
-        echo '}' >> $peertube_nginx_file
368
-        echo '' >> $peertube_nginx_file
369
-        echo 'server {' >> $peertube_nginx_file
370
-        echo '  listen 443 ssl http2;' >> $peertube_nginx_file
371
-        echo '  #listen [::]:443 ssl http2;' >> $peertube_nginx_file
372
-        echo "  server_name $PEERTUBE_DOMAIN_NAME;" >> $peertube_nginx_file
373
-        echo '' >> $peertube_nginx_file
364
+        { echo 'server {';
365
+          echo '  listen 80;';
366
+          echo '  listen [::]:80;';
367
+          echo "  server_name $PEERTUBE_DOMAIN_NAME;";
368
+          echo "  rewrite ^ https://\$server_name\$request_uri? permanent;";
369
+          echo '}';
370
+          echo '';
371
+          echo 'server {';
372
+          echo '  listen 443 ssl http2;';
373
+          echo '  #listen [::]:443 ssl http2;';
374
+          echo "  server_name $PEERTUBE_DOMAIN_NAME;";
375
+          echo ''; } > "$peertube_nginx_file"
374 376
         function_check nginx_ssl
375
-        nginx_ssl $PEERTUBE_DOMAIN_NAME mobile
377
+        nginx_ssl "$PEERTUBE_DOMAIN_NAME" mobile
376 378
 
377 379
         function_check nginx_disable_sniffing
378
-        nginx_disable_sniffing $PEERTUBE_DOMAIN_NAME
379
-
380
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $peertube_nginx_file
381
-        echo '' >> $peertube_nginx_file
382
-        echo '  location / {' >> $peertube_nginx_file
383
-        echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
384
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
385
-        echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
386
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
387
-        echo '' >> $peertube_nginx_file
388
-        echo '    # For the video upload' >> $peertube_nginx_file
389
-        echo '    client_max_body_size 2G;' >> $peertube_nginx_file
390
-        echo '  }' >> $peertube_nginx_file
391
-        echo '' >> $peertube_nginx_file
392
-        echo '  location /static/webseed {' >> $peertube_nginx_file
393
-        echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
394
-        echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
395
-        echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
396
-        echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
397
-        echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
398
-        echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
399
-        echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
400
-        echo '      return 204;' >> $peertube_nginx_file
401
-        echo '    }' >> $peertube_nginx_file
402
-        echo '' >> $peertube_nginx_file
403
-        echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
404
-        echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
405
-        echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
406
-        echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
407
-        echo '    }' >> $peertube_nginx_file
408
-        echo '' >> $peertube_nginx_file
409
-        echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
410
-        echo '  }' >> $peertube_nginx_file
411
-        echo '' >> $peertube_nginx_file
412
-        echo '  # Websocket tracker' >> $peertube_nginx_file
413
-        echo '  location /tracker/socket {' >> $peertube_nginx_file
414
-        echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
415
-        echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
416
-        echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
417
-        echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
418
-        echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
419
-        echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
420
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
421
-        echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
422
-        echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
423
-        echo '  }' >> $peertube_nginx_file
424
-        echo '}' >> $peertube_nginx_file
380
+        nginx_disable_sniffing "$PEERTUBE_DOMAIN_NAME"
381
+
382
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
383
+          echo '';
384
+          echo '  location / {';
385
+          echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
386
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
387
+          echo "    proxy_set_header Host \$host;";
388
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
389
+          echo '';
390
+          echo '    # For the video upload';
391
+          echo '    client_max_body_size 2G;';
392
+          echo '  }';
393
+          echo '';
394
+          echo '  location /static/webseed {';
395
+          echo "    if (\$request_method = 'OPTIONS') {";
396
+          echo "      add_header 'Access-Control-Allow-Origin' '*';";
397
+          echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
398
+          echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
399
+          echo "      add_header 'Access-Control-Max-Age' 1728000;";
400
+          echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
401
+          echo "      add_header 'Content-Length' 0;";
402
+          echo '      return 204;';
403
+          echo '    }';
404
+          echo '';
405
+          echo "    if (\$request_method = 'GET') {";
406
+          echo "      add_header 'Access-Control-Allow-Origin' '*';";
407
+          echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
408
+          echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
409
+          echo '    }';
410
+          echo '';
411
+          echo "    alias $PEERTUBE_DIR/videos;";
412
+          echo '  }';
413
+          echo '';
414
+          echo '  # Websocket tracker';
415
+          echo '  location /tracker/socket {';
416
+          echo '    # Peers send a message to the tracker every 15 minutes';
417
+          echo '    # Dont close the websocket before this time';
418
+          echo '    proxy_read_timeout 1200s;';
419
+          echo "    proxy_set_header Upgrade \$http_upgrade;";
420
+          echo '    proxy_set_header Connection "upgrade";';
421
+          echo '    proxy_http_version 1.1;';
422
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
423
+          echo "    proxy_set_header Host \$host;";
424
+          echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
425
+          echo '  }';
426
+          echo '}'; } >> "$peertube_nginx_file"
425 427
     else
426
-        echo -n '' > $peertube_nginx_file
427
-    fi
428
-    echo 'server {' >> $peertube_nginx_file
429
-    echo "  listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;" >> $peertube_nginx_file
430
-    echo "  server_name $PEERTUBE_ONION_HOSTNAME;" >> $peertube_nginx_file
431
-    echo '' >> $peertube_nginx_file
432
-    echo '  location / {' >> $peertube_nginx_file
433
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
434
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
435
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
436
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
437
-    echo '' >> $peertube_nginx_file
438
-    echo '    # For the video upload' >> $peertube_nginx_file
439
-    echo '    client_max_body_size 2G;' >> $peertube_nginx_file
440
-    echo '  }' >> $peertube_nginx_file
441
-    echo '' >> $peertube_nginx_file
442
-    echo '  location /static/webseed {' >> $peertube_nginx_file
443
-    echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
444
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
445
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
446
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
447
-    echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
448
-    echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
449
-    echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
450
-    echo '      return 204;' >> $peertube_nginx_file
451
-    echo '    }' >> $peertube_nginx_file
452
-    echo '' >> $peertube_nginx_file
453
-    echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
454
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
455
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
456
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
457
-    echo '    }' >> $peertube_nginx_file
458
-    echo '' >> $peertube_nginx_file
459
-    echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
460
-    echo '  }' >> $peertube_nginx_file
461
-    echo '' >> $peertube_nginx_file
462
-    echo '  # Websocket tracker' >> $peertube_nginx_file
463
-    echo '  location /tracker/socket {' >> $peertube_nginx_file
464
-    echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
465
-    echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
466
-    echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
467
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
468
-    echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
469
-    echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
470
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
471
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
472
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
473
-    echo '  }' >> $peertube_nginx_file
474
-    echo '}' >> $peertube_nginx_file
428
+        echo -n '' > "$peertube_nginx_file"
429
+    fi
430
+    { echo 'server {';
431
+      echo "  listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;";
432
+      echo "  server_name $PEERTUBE_ONION_HOSTNAME;";
433
+      echo '';
434
+      echo '  location / {';
435
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
436
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
437
+      echo "    proxy_set_header Host \$host;";
438
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
439
+      echo '';
440
+      echo '    # For the video upload';
441
+      echo '    client_max_body_size 2G;';
442
+      echo '  }';
443
+      echo '';
444
+      echo '  location /static/webseed {';
445
+      echo "    if (\$request_method = 'OPTIONS') {";
446
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
447
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
448
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
449
+      echo "      add_header 'Access-Control-Max-Age' 1728000;";
450
+      echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
451
+      echo "      add_header 'Content-Length' 0;";
452
+      echo '      return 204;';
453
+      echo '    }';
454
+      echo '';
455
+      echo "    if (\$request_method = 'GET') {";
456
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
457
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
458
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
459
+      echo '    }';
460
+      echo '';
461
+      echo "    alias $PEERTUBE_DIR/videos;";
462
+      echo '  }';
463
+      echo '';
464
+      echo '  # Websocket tracker';
465
+      echo '  location /tracker/socket {';
466
+      echo '    # Peers send a message to the tracker every 15 minutes';
467
+      echo '    # Dont close the websocket before this time';
468
+      echo '    proxy_read_timeout 1200s;';
469
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
470
+      echo '    proxy_set_header Connection "upgrade";';
471
+      echo '    proxy_http_version 1.1;';
472
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
473
+      echo "    proxy_set_header Host \$host;";
474
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
475
+      echo '  }';
476
+      echo '}'; } >> "$peertube_nginx_file"
475 477
 
476 478
     # CSP currently causes an error
477
-    sed -i '/Content-Security-Policy/d' $peertube_nginx_file
479
+    sed -i '/Content-Security-Policy/d' "$peertube_nginx_file"
478 480
 
479 481
     function_check create_site_certificate
480
-    create_site_certificate $PEERTUBE_DOMAIN_NAME 'yes'
482
+    create_site_certificate "$PEERTUBE_DOMAIN_NAME" 'yes'
481 483
 
482 484
     function_check nginx_ensite
483
-    nginx_ensite $PEERTUBE_DOMAIN_NAME
485
+    nginx_ensite "$PEERTUBE_DOMAIN_NAME"
484 486
 }
485 487
 
486 488
 function mesh_peertube_setup_web {
489
+    # shellcheck disable=SC2154
487 490
     peertube_nginx_file=$rootdir/etc/nginx/sites-available/peertube
488 491
 
489
-    echo 'server {' >> $peertube_nginx_file
490
-    echo "  listen $MESH_PEERTUBE_PORT http2;" >> $peertube_nginx_file
491
-    echo '  listen [::]:$MESH_PEERTUBE_PORT http2;' >> $peertube_nginx_file
492
-    echo '  server_name $HOSTNAME;' >> $peertube_nginx_file
493
-    echo '' >> $peertube_nginx_file
494
-    echo '  location / {' >> $peertube_nginx_file
495
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
496
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
497
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
498
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
499
-    echo '' >> $peertube_nginx_file
500
-    echo '    # For the video upload' >> $peertube_nginx_file
501
-    echo '    client_max_body_size 2G;' >> $peertube_nginx_file
502
-    echo '  }' >> $peertube_nginx_file
503
-    echo '' >> $peertube_nginx_file
504
-    echo '  location /static/webseed {' >> $peertube_nginx_file
505
-    echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
506
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
507
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
508
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
509
-    echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
510
-    echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
511
-    echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
512
-    echo '      return 204;' >> $peertube_nginx_file
513
-    echo '    }' >> $peertube_nginx_file
514
-    echo '' >> $peertube_nginx_file
515
-    echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
516
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
517
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
518
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
519
-    echo '    }' >> $peertube_nginx_file
520
-    echo '' >> $peertube_nginx_file
521
-    echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
522
-    echo '  }' >> $peertube_nginx_file
523
-    echo '' >> $peertube_nginx_file
524
-    echo '  # Websocket tracker' >> $peertube_nginx_file
525
-    echo '  location /tracker/socket {' >> $peertube_nginx_file
526
-    echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
527
-    echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
528
-    echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
529
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
530
-    echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
531
-    echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
532
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
533
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
534
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
535
-    echo '  }' >> $peertube_nginx_file
536
-    echo '}' >> $peertube_nginx_file
492
+    { echo 'server {';
493
+      echo "  listen $MESH_PEERTUBE_PORT http2;";
494
+      echo "  listen [::]:\$MESH_PEERTUBE_PORT http2;";
495
+      echo "  server_name \$HOSTNAME;";
496
+      echo '';
497
+      echo '  location / {';
498
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
499
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
500
+      echo "    proxy_set_header Host \$host;";
501
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
502
+      echo '';
503
+      echo '    # For the video upload';
504
+      echo '    client_max_body_size 2G;';
505
+      echo '  }';
506
+      echo '';
507
+      echo '  location /static/webseed {';
508
+      echo "    if (\$request_method = 'OPTIONS') {";
509
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
510
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
511
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
512
+      echo "      add_header 'Access-Control-Max-Age' 1728000;";
513
+      echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
514
+      echo "      add_header 'Content-Length' 0;";
515
+      echo '      return 204;';
516
+      echo '    }';
517
+      echo '';
518
+      echo "    if (\$request_method = 'GET') {";
519
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
520
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
521
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
522
+      echo '    }';
523
+      echo '';
524
+      echo "    alias $PEERTUBE_DIR/videos;";
525
+      echo '  }';
526
+      echo '';
527
+      echo '  # Websocket tracker';
528
+      echo '  location /tracker/socket {';
529
+      echo '    # Peers send a message to the tracker every 15 minutes';
530
+      echo '    # Dont close the websocket before this time';
531
+      echo '    proxy_read_timeout 1200s;';
532
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
533
+      echo "    proxy_set_header Connection \"upgrade\";";
534
+      echo '    proxy_http_version 1.1;';
535
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
536
+      echo "    proxy_set_header Host \$host;";
537
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
538
+      echo '  }';
539
+      echo '}'; } > "$peertube_nginx_file"
537 540
 }
538 541
 
539 542
 function peertube_create_config {
@@ -541,84 +544,84 @@ function peertube_create_config {
541 544
 
542 545
     peertube_config_file=$peertube_prefix$PEERTUBE_DIR/config/production.yaml
543 546
 
544
-    echo 'listen:' > $peertube_config_file
545
-    echo "  port: $PEERTUBE_PORT" >> $peertube_config_file
546
-    echo '' >> $peertube_config_file
547
-    echo '# Correspond to your reverse proxy "listen" configuration' >> $peertube_config_file
548
-    echo 'webserver:' >> $peertube_config_file
549
-    if [ ! $peertube_prefix ]; then
550
-        if [[ $ONION_ONLY == 'no' ]]; then
551
-            echo '  https: true' >> $peertube_config_file
552
-            echo "  hostname: '$PEERTUBE_DOMAIN_NAME'" >> $peertube_config_file
553
-            echo '  port: 443' >> $peertube_config_file
547
+    { echo 'listen:';
548
+      echo "  port: $PEERTUBE_PORT";
549
+      echo '';
550
+      echo '# Correspond to your reverse proxy "listen" configuration';
551
+      echo 'webserver:'; } > "$peertube_config_file"
552
+    if [ ! "$peertube_prefix" ]; then
553
+        if [[ "$ONION_ONLY" == 'no' ]]; then
554
+            { echo '  https: true';
555
+              echo "  hostname: '$PEERTUBE_DOMAIN_NAME'";
556
+              echo '  port: 443'; } >> "$peertube_config_file"
554 557
         else
555
-            echo '  https: false' >> $peertube_config_file
556
-            echo "  hostname: '$PEERTUBE_ONION_HOSTNAME'" >> $peertube_config_file
557
-            echo '  port: 80' >> $peertube_config_file
558
+            { echo '  https: false';
559
+              echo "  hostname: '$PEERTUBE_ONION_HOSTNAME'";
560
+              echo '  port: 80'; } >> "$peertube_config_file"
558 561
         fi
559 562
     else
560
-        echo '  https: false' >> $peertube_config_file
561
-        echo "  hostname: ''" >> $peertube_config_file
562
-        echo "  port: $MESH_PEERTUBE_PORT" >> $peertube_config_file
563
-    fi
564
-    echo '' >> $peertube_config_file
565
-    echo '# Your database name will be "peertube"+database.suffix' >> $peertube_config_file
566
-    echo 'database:' >> $peertube_config_file
567
-    echo "  hostname: 'localhost'" >> $peertube_config_file
568
-    echo '  port: 5432' >> $peertube_config_file
569
-    echo "  suffix: ''" >> $peertube_config_file
570
-    echo "  username: 'peertube'" >> $peertube_config_file
571
-    if [ ! $peertube_prefix ]; then
572
-        echo "  password: '$PEERTUBE_ADMIN_PASSWORD'" >> $peertube_config_file
563
+        { echo '  https: false';
564
+          echo "  hostname: ''";
565
+          echo "  port: $MESH_PEERTUBE_PORT"; } >> "$peertube_config_file"
566
+    fi
567
+    { echo '';
568
+      echo '# Your database name will be "peertube"+database.suffix';
569
+      echo 'database:';
570
+      echo "  hostname: 'localhost'";
571
+      echo '  port: 5432';
572
+      echo "  suffix: ''";
573
+      echo "  username: 'peertube'"; } >> "$peertube_config_file"
574
+    if [ ! "$peertube_prefix" ]; then
575
+        echo "  password: '$PEERTUBE_ADMIN_PASSWORD'" >> "$peertube_config_file"
573 576
     else
574
-        echo "  password: ''" >> $peertube_config_file
575
-    fi
576
-    echo '' >> $peertube_config_file
577
-    echo '# From the project root directory' >> $peertube_config_file
578
-    echo 'storage:' >> $peertube_config_file
579
-    echo "  certs: 'certs/'" >> $peertube_config_file
580
-    echo "  videos: 'videos/'" >> $peertube_config_file
581
-    echo "  logs: 'logs/'" >> $peertube_config_file
582
-    echo "  previews: 'previews/'" >> $peertube_config_file
583
-    echo "  thumbnails: 'thumbnails/'" >> $peertube_config_file
584
-    echo "  torrents: 'torrents/'" >> $peertube_config_file
585
-    echo "  cache: 'cache/'" >> $peertube_config_file
586
-    echo '' >> $peertube_config_file
587
-    echo 'cache:' >> $peertube_config_file
588
-    echo '  previews:' >> $peertube_config_file
589
-    echo '    size: 10 # Max number of previews you want to cache' >> $peertube_config_file
590
-    echo '' >> $peertube_config_file
591
-    echo 'admin:' >> $peertube_config_file
592
-    # This is deliberately a dummy email address
593
-    echo "  email: 'testuser@testdomain.net'" >> $peertube_config_file
594
-    echo '' >> $peertube_config_file
595
-    echo 'signup:' >> $peertube_config_file
596
-    echo '  enabled: true' >> $peertube_config_file
597
-    echo '  limit: 5 # When the limit is reached, registrations are disabled. -1 == unlimited' >> $peertube_config_file
598
-    echo '' >> $peertube_config_file
599
-    echo 'user:' >> $peertube_config_file
600
-    echo '  # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).' >> $peertube_config_file
601
-    echo '  # -1 == unlimited' >> $peertube_config_file
602
-    echo '  video_quota: -1' >> $peertube_config_file
603
-    echo '' >> $peertube_config_file
604
-    echo '# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag' >> $peertube_config_file
605
-    echo '# Uses a lot of CPU!' >> $peertube_config_file
606
-    echo 'transcoding:' >> $peertube_config_file
607
-    echo '  enabled: true' >> $peertube_config_file
608
-    echo '  threads: 2' >> $peertube_config_file
609
-    echo '  resolutions: # Only created if the original video has a higher resolution' >> $peertube_config_file
610
-    echo '    240p: true' >> $peertube_config_file
611
-    echo '    360p: false' >> $peertube_config_file
612
-    echo '    480p: false' >> $peertube_config_file
613
-    echo '    720p: false' >> $peertube_config_file
614
-    echo '    1080p: false' >> $peertube_config_file
577
+        echo "  password: ''" >> "$peertube_config_file"
578
+    fi
579
+    { echo '';
580
+      echo '# From the project root directory';
581
+      echo 'storage:';
582
+      echo "  certs: 'certs/'";
583
+      echo "  videos: 'videos/'";
584
+      echo "  logs: 'logs/'";
585
+      echo "  previews: 'previews/'";
586
+      echo "  thumbnails: 'thumbnails/'";
587
+      echo "  torrents: 'torrents/'";
588
+      echo "  cache: 'cache/'";
589
+      echo '';
590
+      echo 'cache:';
591
+      echo '  previews:';
592
+      echo '    size: 10 # Max number of previews you want to cache';
593
+      echo '';
594
+      echo 'admin:';
595
+      # This is deliberately a dummy email address
596
+      echo "  email: 'testuser@testdomain.net'";
597
+      echo '';
598
+      echo 'signup:';
599
+      echo '  enabled: true';
600
+      echo '  limit: 5 # When the limit is reached, registrations are disabled. -1 == unlimited';
601
+      echo '';
602
+      echo 'user:';
603
+      echo '  # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).';
604
+      echo '  # -1 == unlimited';
605
+      echo '  video_quota: -1';
606
+      echo '';
607
+      echo '# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag';
608
+      echo '# Uses a lot of CPU!';
609
+      echo 'transcoding:';
610
+      echo '  enabled: true';
611
+      echo '  threads: 2';
612
+      echo '  resolutions: # Only created if the original video has a higher resolution';
613
+      echo '    240p: true';
614
+      echo '    360p: false';
615
+      echo '    480p: false';
616
+      echo '    720p: false';
617
+      echo '    1080p: false'; } >> "$peertube_config_file"
615 618
 }
616 619
 
617 620
 function mesh_install_peertube {
618
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
621
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
619 622
         return
620 623
     fi
621
-    if [[ $ARCHITECTURE != 'x86_64' && $ARCHITECTURE != 'amd64' ]]; then
624
+    if [[ "$ARCHITECTURE" != 'x86_64' && "$ARCHITECTURE" != 'amd64' ]]; then
622 625
         return
623 626
     fi
624 627
 
@@ -627,22 +630,21 @@ function mesh_install_peertube {
627 630
     function_check install_postgresql
628 631
     install_postgresql
629 632
 
630
-    if [ -d $rootdir$PEERTUBE_DIR ]; then
631
-        rm -rf $rootdir$PEERTUBE_DIR
633
+    if [ -d "$rootdir$PEERTUBE_DIR" ]; then
634
+        rm -rf "$rootdir$PEERTUBE_DIR"
632 635
     fi
633 636
 
634
-    git clone $PEERTUBE_REPO $rootdir$PEERTUBE_DIR
637
+    git clone "$PEERTUBE_REPO" "$rootdir$PEERTUBE_DIR"
635 638
 
636 639
     chroot "$rootdir" groupadd peertube
637 640
     chroot "$rootdir" useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
638 641
 
639
-    cd $rootdir$PEERTUBE_DIR
642
+    cd "$rootdir$PEERTUBE_DIR" || exit 246824524
640 643
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
641 644
 
642
-
643 645
     get_npm_arch
644 646
 
645
-    cat <<EOF > $rootdir/usr/bin/install_peertube
647
+    cat <<EOF > "$rootdir/usr/bin/install_peertube"
646 648
 #!/bin/bash
647 649
 cd $PEERTUBE_DIR
648 650
 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
@@ -683,34 +685,33 @@ if [ ! "\$?" = "0" ]; then
683 685
     exit 5293593
684 686
 fi
685 687
 EOF
686
-    chmod +x $rootdir/usr/bin/install_peertube
687
-    chroot "$rootdir" /usr/bin/install_peertube
688
-    if [ ! "$?" = "0" ]; then
688
+    chmod +x "$rootdir/usr/bin/install_peertube"
689
+    if ! chroot "$rootdir" /usr/bin/install_peertube; then
689 690
         echo $'PeerTube install failed'
690 691
         exit 735638
691 692
     fi
692 693
 
693
-    echo '[Unit]' > $rootdir/etc/systemd/system/peertube.service
694
-    echo 'Description=PeerTube Decentralized video streaming platform' >> $rootdir/etc/systemd/system/peertube.service
695
-    echo 'After=syslog.target' >> $rootdir/etc/systemd/system/peertube.service
696
-    echo 'After=network.target' >> $rootdir/etc/systemd/system/peertube.service
697
-    echo '' >> $rootdir/etc/systemd/system/peertube.service
698
-    echo '[Service]' >> $rootdir/etc/systemd/system/peertube.service
699
-    echo 'User=peertube' >> $rootdir/etc/systemd/system/peertube.service
700
-    echo 'Group=peertube' >> $rootdir/etc/systemd/system/peertube.service
701
-    echo "WorkingDirectory=$PEERTUBE_DIR" >> $rootdir/etc/systemd/system/peertube.service
702
-    echo "ExecStart=/usr/local/bin/npm start" >> $rootdir/etc/systemd/system/peertube.service
703
-    echo "ExecStop=/usr/local/bin/npm stop" >> $rootdir/etc/systemd/system/peertube.service
704
-    echo 'StandardOutput=syslog' >> $rootdir/etc/systemd/system/peertube.service
705
-    echo 'StandardError=syslog' >> $rootdir/etc/systemd/system/peertube.service
706
-    echo 'SyslogIdentifier=peertube' >> $rootdir/etc/systemd/system/peertube.service
707
-    echo 'Restart=always' >> $rootdir/etc/systemd/system/peertube.service
708
-    echo "Environment=NODE_ENV=production" >> $rootdir/etc/systemd/system/peertube.service
709
-    echo '' >> $rootdir/etc/systemd/system/peertube.service
710
-    echo '[Install]' >> $rootdir/etc/systemd/system/peertube.service
711
-    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/peertube.service
712
-
713
-    peertube_create_config $rootdir
694
+    { echo '[Unit]';
695
+      echo 'Description=PeerTube Decentralized video streaming platform';
696
+      echo 'After=syslog.target';
697
+      echo 'After=network.target';
698
+      echo '';
699
+      echo '[Service]';
700
+      echo 'User=peertube';
701
+      echo 'Group=peertube';
702
+      echo "WorkingDirectory=$PEERTUBE_DIR";
703
+      echo "ExecStart=/usr/local/bin/npm start";
704
+      echo "ExecStop=/usr/local/bin/npm stop";
705
+      echo 'StandardOutput=syslog';
706
+      echo 'StandardError=syslog';
707
+      echo 'SyslogIdentifier=peertube';
708
+      echo 'Restart=always';
709
+      echo "Environment=NODE_ENV=production";
710
+      echo '';
711
+      echo '[Install]';
712
+      echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/peertube.service"
713
+
714
+    peertube_create_config "$rootdir"
714 715
 
715 716
     chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
716 717
 
@@ -730,7 +731,7 @@ function install_peertube {
730 731
         ONION_ONLY='no'
731 732
     fi
732 733
 
733
-    if [ ! $PEERTUBE_DOMAIN_NAME ]; then
734
+    if [ ! "$PEERTUBE_DOMAIN_NAME" ]; then
734 735
         echo $'The peertube domain name was not specified'
735 736
         exit 783523
736 737
     fi
@@ -740,8 +741,8 @@ function install_peertube {
740 741
     function_check install_postgresql
741 742
     install_postgresql
742 743
 
743
-    if [ ! -d /var/www/$PEERTUBE_DOMAIN_NAME/htdocs ]; then
744
-        mkdir -p /var/www/$PEERTUBE_DOMAIN_NAME/htdocs
744
+    if [ ! -d "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs" ]; then
745
+        mkdir -p "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs"
745 746
     fi
746 747
 
747 748
     if [ -d $PEERTUBE_DIR ]; then
@@ -759,60 +760,56 @@ function install_peertube {
759 760
     if [ -d /repos/peertube ]; then
760 761
         mkdir -p $PEERTUBE_DIR
761 762
         cp -r -p /repos/peertube/. $PEERTUBE_DIR
762
-        cd $PEERTUBE_DIR
763
+        cd "$PEERTUBE_DIR" || exit 642874682
763 764
         git pull
764 765
     else
765 766
         function_check git_clone
766 767
         git_clone $PEERTUBE_REPO $PEERTUBE_DIR
767 768
     fi
768 769
 
769
-    cd $PEERTUBE_DIR
770
+    cd "$PEERTUBE_DIR" || exit 27492742
770 771
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
771 772
     set_completion_param "peertube commit" "$PEERTUBE_COMMIT"
772 773
 
773
-    npm install -g yarn
774
-    if [ ! "$?" = "0" ]; then
774
+    if ! npm install -g yarn; then
775 775
         echo $'Failed to install yarn'
776 776
         exit 79353234
777 777
     fi
778 778
     yarn add -D webpack --network-concurrency 1
779
-    yarn install
780
-    if [ ! "$?" = "0" ]; then
779
+    if ! yarn install; then
781 780
         echo $'Failed to run yarn install'
782 781
         exit 63754235
783 782
     fi
784
-    npm install
785
-    if [ ! "$?" = "0" ]; then
783
+    if ! npm install; then
786 784
         echo $'Failed to install peertube'
787 785
         exit 7835243
788 786
     fi
789
-    npm run build
790
-    if [ ! "$?" = "0" ]; then
787
+    if ! npm run build; then
791 788
         echo $'Failed to build peertube'
792 789
         exit 5293593
793 790
     fi
794 791
 
795 792
     PEERTUBE_ONION_HOSTNAME=$(add_onion_service peertube 80 ${PEERTUBE_ONION_PORT})
796 793
 
797
-    echo '[Unit]' > /etc/systemd/system/peertube.service
798
-    echo 'Description=PeerTube Decentralized video streaming platform' >> /etc/systemd/system/peertube.service
799
-    echo 'After=syslog.target' >> /etc/systemd/system/peertube.service
800
-    echo 'After=network.target' >> /etc/systemd/system/peertube.service
801
-    echo '' >> /etc/systemd/system/peertube.service
802
-    echo '[Service]' >> /etc/systemd/system/peertube.service
803
-    echo 'User=peertube' >> /etc/systemd/system/peertube.service
804
-    echo 'Group=peertube' >> /etc/systemd/system/peertube.service
805
-    echo "WorkingDirectory=$PEERTUBE_DIR" >> /etc/systemd/system/peertube.service
806
-    echo "ExecStart=/usr/local/bin/npm start" >> /etc/systemd/system/peertube.service
807
-    echo "ExecStop=/usr/local/bin/npm stop" >> /etc/systemd/system/peertube.service
808
-    echo 'StandardOutput=syslog' >> /etc/systemd/system/peertube.service
809
-    echo 'StandardError=syslog' >> /etc/systemd/system/peertube.service
810
-    echo 'SyslogIdentifier=peertube' >> /etc/systemd/system/peertube.service
811
-    echo 'Restart=always' >> /etc/systemd/system/peertube.service
812
-    echo "Environment=NODE_ENV=production" >> /etc/systemd/system/peertube.service
813
-    echo '' >> /etc/systemd/system/peertube.service
814
-    echo '[Install]' >> /etc/systemd/system/peertube.service
815
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/peertube.service
794
+    { echo '[Unit]';
795
+      echo 'Description=PeerTube Decentralized video streaming platform';
796
+      echo 'After=syslog.target';
797
+      echo 'After=network.target';
798
+      echo '';
799
+      echo '[Service]';
800
+      echo 'User=peertube';
801
+      echo 'Group=peertube';
802
+      echo "WorkingDirectory=$PEERTUBE_DIR";
803
+      echo "ExecStart=/usr/local/bin/npm start";
804
+      echo "ExecStop=/usr/local/bin/npm stop";
805
+      echo 'StandardOutput=syslog';
806
+      echo 'StandardError=syslog';
807
+      echo 'SyslogIdentifier=peertube';
808
+      echo 'Restart=always';
809
+      echo "Environment=NODE_ENV=production";
810
+      echo '';
811
+      echo '[Install]';
812
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/peertube.service
816 813
 
817 814
     peertube_create_config
818 815
 
@@ -820,10 +817,10 @@ function install_peertube {
820 817
 
821 818
     peertube_setup_web
822 819
 
823
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a peertube -p "$PEERTUBE_ADMIN_PASSWORD"
820
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a peertube -p "$PEERTUBE_ADMIN_PASSWORD"
824 821
 
825 822
     function_check add_ddns_domain
826
-    add_ddns_domain $PEERTUBE_DOMAIN_NAME
823
+    add_ddns_domain "$PEERTUBE_DOMAIN_NAME"
827 824
 
828 825
     systemctl enable peertube
829 826
     systemctl daemon-reload

+ 282
- 272
src/freedombone-app-pelican View File

@@ -50,12 +50,12 @@ pelican_variables=(MY_USERNAME
50 50
                    PELICAN_BLOG_CODE)
51 51
 
52 52
 function pelican_remove_bad_blog_links {
53
-    find ./ -type f -name *.css -exec sed -i -e '/googleapi/d' {} \;
54
-    find ./ -type f -name *.scss -exec sed -i -e '/googleapi/d' {} \;
55
-    find ./ -type f -name *.html -exec sed -i -e '/googleapi/d' {} \;
56
-    find ./ -type f -name *.css -exec sed -i -e '/bootstrapcdn/d' {} \;
57
-    find ./ -type f -name *.scss -exec sed -i -e '/bootstrapcdn/d' {} \;
58
-    find ./ -type f -name *.html -exec sed -i -e '/bootstrapcdn/d' {} \;
53
+    find ./ -type f -name "*.css" -exec sed -i -e '/googleapi/d' {} \;
54
+    find ./ -type f -name "*.scss" -exec sed -i -e '/googleapi/d' {} \;
55
+    find ./ -type f -name "*.html" -exec sed -i -e '/googleapi/d' {} \;
56
+    find ./ -type f -name "*.css" -exec sed -i -e '/bootstrapcdn/d' {} \;
57
+    find ./ -type f -name "*.scss" -exec sed -i -e '/bootstrapcdn/d' {} \;
58
+    find ./ -type f -name "*.html" -exec sed -i -e '/bootstrapcdn/d' {} \;
59 59
 }
60 60
 
61 61
 function logging_on_pelican {
@@ -73,104 +73,104 @@ function install_pelican_website {
73 73
     fi
74 74
     function_check nginx_http_redirect
75 75
     nginx_http_redirect $PELICAN_DOMAIN_NAME
76
-    echo 'server {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
77
-    echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
78
-    echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
79
-    echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
80
-    echo "    server_name ${PELICAN_DOMAIN_NAME};" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
81
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
82
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
83
-    echo '    index index.html;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
84
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
76
+    { echo 'server {';
77
+      echo '    listen 443 ssl;';
78
+      echo '    #listen [::]:443 ssl;';
79
+      echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
80
+      echo "    server_name ${PELICAN_DOMAIN_NAME};";
81
+      echo '    access_log /dev/null;';
82
+      echo "    error_log /dev/null;";
83
+      echo '    index index.html;';
84
+      echo '    charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
85 85
     function_check nginx_ssl
86
-    nginx_ssl $PELICAN_DOMAIN_NAME
86
+    nginx_ssl "$PELICAN_DOMAIN_NAME"
87 87
     function_check nginx_disable_sniffing
88
-    nginx_disable_sniffing $PELICAN_DOMAIN_NAME
89
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
90
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
91
-    echo '    location / {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
88
+    nginx_disable_sniffing "$PELICAN_DOMAIN_NAME"
89
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
90
+      echo '';
91
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
92 92
     function_check nginx_limits
93
-    nginx_limits $PELICAN_DOMAIN_NAME
94
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
95
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
96
-    echo '    # block these file types' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
97
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
98
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
99
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
100
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
101
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
102
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
103
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
104
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
105
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
106
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
107
-    echo '      deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
108
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
109
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
110
-    echo '      deny  all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
111
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
112
-    echo '}' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
113
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
93
+    nginx_limits "$PELICAN_DOMAIN_NAME"
94
+    { echo '    }';
95
+      echo '';
96
+      echo '    # block these file types';
97
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
98
+      echo '        deny all;';
99
+      echo '    }';
100
+      echo '';
101
+      echo '    # deny access to all dot files';
102
+      echo '    location ~ /\. {';
103
+      echo '        deny all;';
104
+      echo '    }';
105
+      echo '';
106
+      echo '    location ~ /(data|conf|bin|inc)/ {';
107
+      echo '      deny all;';
108
+      echo '    }';
109
+      echo '    location ~ /\.ht {';
110
+      echo '      deny  all;';
111
+      echo '    }';
112
+      echo '}';
113
+      echo ''; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
114 114
 
115 115
     function_check create_site_certificate
116
-    create_site_certificate $PELICAN_DOMAIN_NAME 'yes'
116
+    create_site_certificate "$PELICAN_DOMAIN_NAME" 'yes'
117 117
 }
118 118
 
119 119
 function install_pelican_website_onion {
120
-    echo 'server {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
121
-    echo "    listen 127.0.0.1:${PELICAN_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
122
-    echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
123
-    echo "    server_name ${PELICAN_DOMAIN_NAME};" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
124
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
125
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
126
-    echo '    index index.html;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
127
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
120
+    { echo 'server {';
121
+      echo "    listen 127.0.0.1:${PELICAN_ONION_PORT} default_server;";
122
+      echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
123
+      echo "    server_name ${PELICAN_DOMAIN_NAME};";
124
+      echo '    access_log /dev/null;';
125
+      echo "    error_log /dev/null;";
126
+      echo '    index index.html;';
127
+      echo '    charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
128 128
     function_check nginx_disable_sniffing
129
-    nginx_disable_sniffing $PELICAN_DOMAIN_NAME
130
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
131
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
132
-    echo '    location / {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
129
+    nginx_disable_sniffing "$PELICAN_DOMAIN_NAME"
130
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
131
+      echo '';
132
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
133 133
     function_check nginx_limits
134
-    nginx_limits $PELICAN_DOMAIN_NAME
135
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
136
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
137
-    echo '    # block these file types' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
138
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
139
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
140
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
141
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
142
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
143
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
144
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
145
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
146
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
147
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
148
-    echo '      deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
149
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
150
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
151
-    echo '      deny  all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
152
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
153
-    echo '}' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
134
+    nginx_limits "$PELICAN_DOMAIN_NAME"
135
+    { echo '    }';
136
+      echo '';
137
+      echo '    # block these file types';
138
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
139
+      echo '        deny all;';
140
+      echo '    }';
141
+      echo '';
142
+      echo '    # deny access to all dot files';
143
+      echo '    location ~ /\. {';
144
+      echo '        deny all;';
145
+      echo '    }';
146
+      echo '';
147
+      echo '    location ~ /(data|conf|bin|inc)/ {';
148
+      echo '      deny all;';
149
+      echo '    }';
150
+      echo '    location ~ /\.ht {';
151
+      echo '      deny  all;';
152
+      echo '    }';
153
+      echo '}'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
154 154
 }
155 155
 
156 156
 function pelican_editor_config {
157 157
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican ]; then
158
-        echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)" > $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
159
-        echo '(setq org-support-shift-select t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
160
-        echo '(setq standard-indent 4)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
161
-        echo '(setq-default tab-width 4)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
162
-        echo '(setq c-basic-offset 4)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
163
-        echo '(mouse-wheel-mode t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
164
-        echo '(setq make-backup-files t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
165
-        echo '(setq version-control t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
166
-        echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
167
-        echo "(setq default-major-mode 'text-mode)" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
168
-        echo "(dolist (hook '(text-mode-hook))" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
169
-        echo '    (add-hook hook (lambda () (flyspell-mode 1))))' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
170
-        echo '(setq-default fill-column 72)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
171
-        echo '(setq auto-fill-mode 0)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
172
-        echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
173
-        echo "(setq-default auto-fill-function 'do-auto-fill)" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
158
+        { echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)";
159
+          echo '(setq org-support-shift-select t)';
160
+          echo '(setq standard-indent 4)';
161
+          echo '(setq-default tab-width 4)';
162
+          echo '(setq c-basic-offset 4)';
163
+          echo '(mouse-wheel-mode t)';
164
+          echo '(setq make-backup-files t)';
165
+          echo '(setq version-control t)';
166
+          echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))';
167
+          echo "(setq default-major-mode 'text-mode)";
168
+          echo "(dolist (hook '(text-mode-hook))";
169
+          echo '    (add-hook hook (lambda () (flyspell-mode 1))))';
170
+          echo '(setq-default fill-column 72)';
171
+          echo '(setq auto-fill-mode 0)';
172
+          echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)";
173
+          echo "(setq-default auto-fill-function 'do-auto-fill)"; } > "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican"
174 174
     fi
175 175
 }
176 176
 
@@ -179,7 +179,7 @@ function pelican_regenerate_blog {
179 179
     echo ''
180 180
     echo $'Regenerating blog...'
181 181
 
182
-    cd $PELICAN_BLOG_INSTALL_DIR
182
+    cd "$PELICAN_BLOG_INSTALL_DIR" || exit 463856348
183 183
     make html
184 184
     cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
185 185
     chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
@@ -189,19 +189,19 @@ function pelican_new_blog {
189 189
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
190 190
 
191 191
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry ]; then
192
-        echo $'Title: Blog Post Title' > $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
193
-        echo $"Date: ${DATESTR}" >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
194
-        echo $"Author: $(toxid --showuser)" >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
195
-        echo $'Category: default' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
196
-        echo $'Tags: blog, tag' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
197
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
198
-        echo $'Add your text here' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
199
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
200
-        echo -n $'To include an image copy it into the /etc/blog/content/images directory, ' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
201
-        echo $'then link to it with:' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
202
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
203
-        echo $'![My image]({filename}images/myimage.jpg)' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
204
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
192
+        { echo $'Title: Blog Post Title';
193
+          echo $"Date: ${DATESTR}";
194
+          echo $"Author: $(toxid --showuser)";
195
+          echo $'Category: default';
196
+          echo $'Tags: blog, tag';
197
+          echo  '';
198
+          echo $'Add your text here';
199
+          echo  '';
200
+          echo -n $'To include an image copy it into the /etc/blog/content/images directory, ';
201
+          echo $'then link to it with:';
202
+          echo  '';
203
+          echo $'![My image]({filename}images/myimage.jpg)';
204
+          echo  ''; } > $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
205 205
     fi
206 206
 
207 207
     if [ -f /usr/bin/emacs ]; then
@@ -222,7 +222,7 @@ function pelican_new_blog {
222 222
 
223 223
     # move to the content directory
224 224
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
225
-    mv $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry $BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md
225
+    mv "$PELICAN_BLOG_INSTALL_DIR/.new-blog-entry" "$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md"
226 226
 
227 227
     # increment the index
228 228
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
@@ -238,14 +238,14 @@ function pelican_edit_blog {
238 238
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
239 239
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
240 240
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
241
-    if [ ! -f $LAST_BLOG_ENTRY ]; then
241
+    if [ ! -f "$LAST_BLOG_ENTRY" ]; then
242 242
         return
243 243
     fi
244 244
 
245 245
     if [ -f /usr/bin/emacs ]; then
246
-        emacs -q --load $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican $LAST_BLOG_ENTRY
246
+        emacs -q --load "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican" "$LAST_BLOG_ENTRY"
247 247
     else
248
-        editor $LAST_BLOG_ENTRY
248
+        editor "$LAST_BLOG_ENTRY"
249 249
     fi
250 250
 
251 251
     pelican_regenerate_blog
@@ -258,18 +258,18 @@ function pelican_delete_blog {
258 258
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
259 259
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
260 260
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
261
-    if [ ! -f $LAST_BLOG_ENTRY ]; then
261
+    if [ ! -f "$LAST_BLOG_ENTRY" ]; then
262 262
         return
263 263
     fi
264 264
 
265 265
     dialog --title $"Delete the previous blog entry" \
266 266
            --backtitle $"Freedombone Mesh" \
267 267
            --defaultno \
268
-           --yesno $"\nAre you sure that you wish to delete the previous blog entry?" 8 60
268
+           --yesno $"\\nAre you sure that you wish to delete the previous blog entry?" 8 60
269 269
     sel=$?
270 270
     case $sel in
271
-        0) rm $LAST_BLOG_ENTRY
272
-           if [ $CURRENT_INDEX -gt 0 ]; then
271
+        0) rm "$LAST_BLOG_ENTRY"
272
+           if [ "$CURRENT_INDEX" -gt 0 ]; then
273 273
                CURRENT_INDEX=$PREVIOUS_INDEX
274 274
                echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
275 275
            else
@@ -297,8 +297,8 @@ function pelican_change_theme {
297 297
     for a in "${THEMES[@]}"
298 298
     do
299 299
         is_selected='off'
300
-        if [ $curr_theme_index ]; then
301
-            if [ $n -eq $curr_theme_index ]; then
300
+        if [ "$curr_theme_index" ]; then
301
+            if [ $n -eq "$curr_theme_index" ]; then
302 302
                 is_selected='on'
303 303
             fi
304 304
         else
@@ -308,28 +308,30 @@ function pelican_change_theme {
308 308
         fi
309 309
 
310 310
         themelist="$themelist $n $a $is_selected"
311
-        n=$[n+1]
312
-        theme_index=$[theme_index+1]
311
+        n=$((n+1))
312
+        theme_index=$((theme_index+1))
313 313
     done
314 314
 
315
-    data=$(tempfile 2>/dev/null)
316
-    trap "rm -f $data" 0 1 2 5 15
315
+    data=$(mktemp 2>/dev/null)
317 316
     dialog --backtitle $"Freedombone Mesh" \
318 317
            --title $"Select Blog Theme" \
319 318
            --radiolist $'Choose:' \
320
-           80 40 20 $themelist 2> $data
319
+           80 40 20 "$themelist" 2> "$data"
321 320
     sel=$?
322 321
     case $sel in
323
-        1) return;;
324
-        255) return;;
322
+        1) rm -f "$data"
323
+           return;;
324
+        255) rm -f "$data"
325
+             return;;
325 326
     esac
326
-    CHOSEN_THEME_INDEX=$(cat $data)
327
+    CHOSEN_THEME_INDEX=$(cat "$data")
328
+    rm -f "$data"
327 329
     echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
328 330
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
329 331
 
330 332
     CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
331 333
 
332
-    cd $PELICAN_BLOG_INSTALL_DIR/themes/$CHOSEN_THEME
334
+    cd "$PELICAN_BLOG_INSTALL_DIR/themes/$CHOSEN_THEME" || exit 2648268284
333 335
     pelican_remove_bad_blog_links
334 336
 
335 337
     if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
@@ -341,8 +343,7 @@ function pelican_change_theme {
341 343
 }
342 344
 
343 345
 function configure_interactive_pelican {
344
-    data=$(tempfile 2>/dev/null)
345
-    trap "rm -f $data" 0 1 2 5 15
346
+    data=$(mktemp 2>/dev/null)
346 347
     dialog --backtitle $"Freedombone Configuration" \
347 348
            --title $"Pelican Blogging" \
348 349
            --radiolist $"Choose an operation:" 18 50 11 \
@@ -350,23 +351,25 @@ function configure_interactive_pelican {
350 351
            2 $"Edit the previous blog entry" off \
351 352
            3 $"Delete the previous blog entry" off \
352 353
            4 $"Change theme" off \
353
-           5 $"Exit" off 2> $data
354
+           5 $"Exit" off 2> "$data"
354 355
     sel=$?
355 356
     case $sel in
356
-        1) return;;
357
-        255) return;;
357
+        1) rm -f "$data"
358
+           return;;
359
+        255) rm -f "$data"
360
+             return;;
358 361
     esac
359
-    case $(cat $data) in
362
+    case $(cat "$data") in
360 363
         1) pelican_new_blog;;
361 364
         2) pelican_edit_blog;;
362 365
         3) pelican_delete_blog;;
363 366
         4) pelican_change_theme;;
364
-        5) break;;
365 367
     esac
368
+    rm -f "$data"
366 369
 }
367 370
 
368 371
 function install_interactive_pelican {
369
-    if [ ! $ONION_ONLY ]; then
372
+    if [ ! "$ONION_ONLY" ]; then
370 373
         ONION_ONLY='no'
371 374
     fi
372 375
 
@@ -376,42 +379,43 @@ function install_interactive_pelican {
376 379
         PELICAN_DETAILS_COMPLETE=
377 380
         while [ ! $PELICAN_DETAILS_COMPLETE ]
378 381
         do
379
-            data=$(tempfile 2>/dev/null)
380
-            trap "rm -f $data" 0 1 2 5 15
382
+            data=$(mktemp 2>/dev/null)
381 383
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
382 384
                 dialog --backtitle $"Freedombone Configuration" \
383 385
                        --title $"Pelican Blog Configuration" \
384
-                       --form $"\nPlease enter your blog details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
386
+                       --form $"\\nPlease enter your blog details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
385 387
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
386 388
                        $"Code:" 2 1 "$(grep 'PELICAN_BLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
387
-                       2> $data
389
+                       2> "$data"
388 390
             else
389 391
                 dialog --backtitle $"Freedombone Configuration" \
390 392
                        --title $"Pelican Blog Configuration" \
391
-                       --form $"\nPlease enter your GNU Social details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
393
+                       --form $"\\nPlease enter your GNU Social details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
392 394
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
393
-                       2> $data
395
+                       2> "$data"
394 396
             fi
395 397
             sel=$?
396 398
             case $sel in
397
-                1) exit 1;;
398
-                255) exit 1;;
399
+                1) rm -f "$data"
400
+                   exit 1;;
401
+                255) rm -f "$data"
402
+                     exit 1;;
399 403
             esac
400
-            PELICAN_DOMAIN_NAME=$(cat $data | sed -n 1p)
401
-            if [ $PELICAN_DOMAIN_NAME ]; then
404
+            PELICAN_DOMAIN_NAME=$(sed -n 1p < "$data")
405
+            if [ "$PELICAN_DOMAIN_NAME" ]; then
402 406
                 if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
403 407
                     PELICAN_DOMAIN_NAME=""
404 408
                 fi
405 409
                 TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
406 410
                 validate_domain_name
407
-                if [[ $TEST_DOMAIN_NAME != $PELICAN_DOMAIN_NAME ]]; then
411
+                if [[ "$TEST_DOMAIN_NAME" != "$PELICAN_DOMAIN_NAME" ]]; then
408 412
                     PELICAN_DOMAIN_NAME=
409 413
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
410 414
                 else
411 415
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
412
-                        PELICAN_BLOG_CODE=$(cat $data | sed -n 2p)
416
+                        PELICAN_BLOG_CODE=$(sed -n 2p < "$data")
413 417
                         validate_freedns_code "$PELICAN_BLOG_CODE"
414
-                        if [ ! $VALID_CODE ]; then
418
+                        if [ ! "$VALID_CODE" ]; then
415 419
                             PELICAN_DOMAIN_NAME=
416 420
                         fi
417 421
                     fi
@@ -420,6 +424,7 @@ function install_interactive_pelican {
420 424
             if [ $PELICAN_DOMAIN_NAME ]; then
421 425
                 PELICAN_DETAILS_COMPLETE="yes"
422 426
             fi
427
+            rm -f "$data"
423 428
         done
424 429
 
425 430
         # save the results in the config file
@@ -454,7 +459,7 @@ function backup_local_pelican {
454 459
 
455 460
 function restore_local_pelican {
456 461
     if [ -d /etc/blog ]; then
457
-        if [ -d $USB_MOUNT_DLNA/backup/pelican ]; then
462
+        if [ -d "$USB_MOUNT_DLNA/backup/pelican" ]; then
458 463
             temp_restore_dir=/root/temppelican
459 464
             function_check restore_directory_from_usb
460 465
             restore_directory_from_usb $temp_restore_dir pelican
@@ -463,6 +468,7 @@ function restore_local_pelican {
463 468
             else
464 469
                 cp -r $temp_restore_dir/* /etc/blog/
465 470
             fi
471
+            # shellcheck disable=SC2181
466 472
             if [ ! "$?" = "0" ]; then
467 473
                 rm -rf $temp_restore_dir
468 474
                 function_check set_user_permissions
@@ -475,7 +481,7 @@ function restore_local_pelican {
475 481
         fi
476 482
     fi
477 483
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
478
-        if [ -d $USB_MOUNT_DLNA/backup/pelican-site ]; then
484
+        if [ -d "$USB_MOUNT_DLNA/backup/pelican-site" ]; then
479 485
             temp_restore_dir=/root/temppelican-site
480 486
             function_check restore_directory_from_usb
481 487
             restore_directory_from_usb $temp_restore_dir pelican-site
@@ -484,6 +490,7 @@ function restore_local_pelican {
484 490
             else
485 491
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
486 492
             fi
493
+            # shellcheck disable=SC2181
487 494
             if [ ! "$?" = "0" ]; then
488 495
                 rm -rf $temp_restore_dir
489 496
                 function_check set_user_permissions
@@ -508,7 +515,7 @@ function backup_remote_pelican {
508 515
 
509 516
 function restore_remote_pelican {
510 517
     if [ -d /etc/blog ]; then
511
-        if [ -d $SERVER_DIRECTORY/backup/pelican ]; then
518
+        if [ -d "$SERVER_DIRECTORY/backup/pelican" ]; then
512 519
             temp_restore_dir=/root/temppelican
513 520
             function_check restore_directory_from_friend
514 521
             restore_directory_from_friend $temp_restore_dir pelican
@@ -517,6 +524,7 @@ function restore_remote_pelican {
517 524
             else
518 525
                 cp -r $temp_restore_dir/* /etc/blog/
519 526
             fi
527
+            # shellcheck disable=SC2181
520 528
             if [ ! "$?" = "0" ]; then
521 529
                 exit 782352
522 530
             fi
@@ -524,7 +532,7 @@ function restore_remote_pelican {
524 532
         fi
525 533
     fi
526 534
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
527
-        if [ -d $SERVER_DIRECTORY/backup/pelican-site ]; then
535
+        if [ -d "$SERVER_DIRECTORY/backup/pelican-site" ]; then
528 536
             temp_restore_dir=/root/temppelican-site
529 537
             function_check restore_directory_from_friend
530 538
             restore_directory_from_friend $temp_restore_dir pelican-site
@@ -533,6 +541,7 @@ function restore_remote_pelican {
533 541
             else
534 542
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
535 543
             fi
544
+            # shellcheck disable=SC2181
536 545
             if [ ! "$?" = "0" ]; then
537 546
                 exit 76382562
538 547
             fi
@@ -561,112 +570,112 @@ function remove_pelican {
561 570
 }
562 571
 
563 572
 function create_pelican_conf {
564
-    STATIC_BLOG_FILE=$1
565
-
566
-    echo '#!/usr/bin/env python' > $STATIC_BLOG_FILE
567
-    echo '# -*- coding: utf-8 -*- #' >> $STATIC_BLOG_FILE
568
-    echo 'from __future__ import unicode_literals' >> $STATIC_BLOG_FILE
569
-    echo '' >> $STATIC_BLOG_FILE
570
-    echo "AUTHOR=u\"$MY_USERNAME\"" >> $STATIC_BLOG_FILE
571
-    echo "SITENAME=u'$DEFAULT_BLOG_TITLE'" >> $STATIC_BLOG_FILE
572
-    echo "SITEURL=''" >> $STATIC_BLOG_FILE
573
-    echo "PATH='content'" >> $STATIC_BLOG_FILE
574
-    echo 'TIMEZONE=u"Europe/London"' >> $STATIC_BLOG_FILE
575
-    echo "DEFAULT_LANG=u'en'" >> $STATIC_BLOG_FILE
576
-    echo '' >> $STATIC_BLOG_FILE
577
-    echo 'FEED_ALL_ATOM=None' >> $STATIC_BLOG_FILE
578
-    echo 'CATEGORY_FEED_ATOM=None' >> $STATIC_BLOG_FILE
579
-    echo 'TRANSLATION_FEED_ATOM=None' >> $STATIC_BLOG_FILE
580
-    echo 'AUTHOR_FEED_ATOM=None' >> $STATIC_BLOG_FILE
581
-    echo 'AUTHOR_FEED_RSS=None' >> $STATIC_BLOG_FILE
582
-    echo '' >> $STATIC_BLOG_FILE
583
-    echo 'DEFAULT_PAGINATION=False' >> $STATIC_BLOG_FILE
584
-    echo 'RELATIVE_URLS=True' >> $STATIC_BLOG_FILE
585
-    echo "THEME='themes/nice-blog'" >> $STATIC_BLOG_FILE
573
+    STATIC_BLOG_FILE="$1"
574
+
575
+    { echo '#!/usr/bin/env python';
576
+      echo '# -*- coding: utf-8 -*- #';
577
+      echo 'from __future__ import unicode_literals';
578
+      echo '';
579
+      echo "AUTHOR=u\"$MY_USERNAME\"";
580
+      echo "SITENAME=u'$DEFAULT_BLOG_TITLE'";
581
+      echo "SITEURL=''";
582
+      echo "PATH='content'";
583
+      echo 'TIMEZONE=u"Europe/London"';
584
+      echo "DEFAULT_LANG=u'en'";
585
+      echo '';
586
+      echo 'FEED_ALL_ATOM=None';
587
+      echo 'CATEGORY_FEED_ATOM=None';
588
+      echo 'TRANSLATION_FEED_ATOM=None';
589
+      echo 'AUTHOR_FEED_ATOM=None';
590
+      echo 'AUTHOR_FEED_RSS=None';
591
+      echo '';
592
+      echo 'DEFAULT_PAGINATION=False';
593
+      echo 'RELATIVE_URLS=True';
594
+      echo "THEME='themes/nice-blog'"; } > "$STATIC_BLOG_FILE"
586 595
 }
587 596
 
588 597
 function create_pelican_makefile {
589
-    STATIC_BLOG_FILE=$1
590
-
591
-    echo 'PY?=python' > $STATIC_BLOG_FILE
592
-    echo 'PELICAN?=pelican' >> $STATIC_BLOG_FILE
593
-    echo 'PELICANOPTS=' >> $STATIC_BLOG_FILE
594
-    echo '' >> $STATIC_BLOG_FILE
595
-    echo 'BASEDIR=$(CURDIR)' >> $STATIC_BLOG_FILE
596
-    echo 'INPUTDIR=$(BASEDIR)/content' >> $STATIC_BLOG_FILE
597
-    echo "OUTPUTDIR=$PELICAN_BLOG_PATH" >> $STATIC_BLOG_FILE
598
-    echo 'CONFFILE=$(BASEDIR)/pelicanconf.py' >> $STATIC_BLOG_FILE
599
-    echo 'PUBLISHCONF=$(BASEDIR)/publishconf.py' >> $STATIC_BLOG_FILE
600
-    echo '' >> $STATIC_BLOG_FILE
601
-    echo 'DEBUG ?= 0' >> $STATIC_BLOG_FILE
602
-    echo 'ifeq ($(DEBUG), 1)' >> $STATIC_BLOG_FILE
603
-    echo -e '\tPELICANOPTS += -D' >> $STATIC_BLOG_FILE
604
-    echo 'endif' >> $STATIC_BLOG_FILE
605
-    echo '' >> $STATIC_BLOG_FILE
606
-    echo 'RELATIVE ?= 0' >> $STATIC_BLOG_FILE
607
-    echo 'ifeq ($(RELATIVE), 1)' >> $STATIC_BLOG_FILE
608
-    echo -e '\tPELICANOPTS += --relative-urls' >> $STATIC_BLOG_FILE
609
-    echo 'endif' >> $STATIC_BLOG_FILE
610
-    echo '' >> $STATIC_BLOG_FILE
611
-    echo 'html:' >> $STATIC_BLOG_FILE
612
-    echo -e '\t$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
613
-    echo '' >> $STATIC_BLOG_FILE
614
-    echo 'clean:' >> $STATIC_BLOG_FILE
615
-    echo -e '\t[ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)' >> $STATIC_BLOG_FILE
616
-    echo '' >> $STATIC_BLOG_FILE
617
-    echo 'regenerate:' >> $STATIC_BLOG_FILE
618
-    echo -e '\t$(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
619
-    echo '' >> $STATIC_BLOG_FILE
620
-    echo 'serve:' >> $STATIC_BLOG_FILE
621
-    echo 'ifdef PORT' >> $STATIC_BLOG_FILE
622
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT)' >> $STATIC_BLOG_FILE
623
-    echo 'else' >> $STATIC_BLOG_FILE
624
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server' >> $STATIC_BLOG_FILE
625
-    echo 'endif' >> $STATIC_BLOG_FILE
626
-    echo '' >> $STATIC_BLOG_FILE
627
-    echo 'serve-global:' >> $STATIC_BLOG_FILE
628
-    echo 'ifdef SERVER' >> $STATIC_BLOG_FILE
629
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER)' >> $STATIC_BLOG_FILE
630
-    echo 'else' >> $STATIC_BLOG_FILE
631
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0' >> $STATIC_BLOG_FILE
632
-    echo 'endif' >> $STATIC_BLOG_FILE
633
-    echo '' >> $STATIC_BLOG_FILE
634
-    echo 'devserver:' >> $STATIC_BLOG_FILE
635
-    echo 'ifdef PORT' >> $STATIC_BLOG_FILE
636
-    echo -e '\t$(BASEDIR)/develop_server.sh restart $(PORT)' >> $STATIC_BLOG_FILE
637
-    echo 'else' >> $STATIC_BLOG_FILE
638
-    echo -e '\t$(BASEDIR)/develop_server.sh restart' >> $STATIC_BLOG_FILE
639
-    echo 'endif' >> $STATIC_BLOG_FILE
640
-    echo '' >> $STATIC_BLOG_FILE
641
-    echo 'stopserver:' >> $STATIC_BLOG_FILE
642
-    echo -e '\t$(BASEDIR)/develop_server.sh stop' >> $STATIC_BLOG_FILE
643
-    echo -e '\t@echo "Stopped Pelican and SimpleHTTPServer processes running in background."' >> $STATIC_BLOG_FILE
644
-    echo '' >> $STATIC_BLOG_FILE
645
-    echo 'publish:' >> $STATIC_BLOG_FILE
646
-    echo -e '\t$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
647
-    echo '' >> $STATIC_BLOG_FILE
648
-    echo '.PHONY: html clean regenerate serve serve-global devserver publish' >> $STATIC_BLOG_FILE
598
+    STATIC_BLOG_FILE="$1"
599
+
600
+    { echo 'PY?=python';
601
+      echo 'PELICAN?=pelican';
602
+      echo 'PELICANOPTS=';
603
+      echo '';
604
+      echo "BASEDIR=\$(CURDIR)";
605
+      echo "INPUTDIR=\$(BASEDIR)/content";
606
+      echo "OUTPUTDIR=$PELICAN_BLOG_PATH";
607
+      echo "CONFFILE=\$(BASEDIR)/pelicanconf.py";
608
+      echo "PUBLISHCONF=\$(BASEDIR)/publishconf.py";
609
+      echo '';
610
+      echo 'DEBUG ?= 0';
611
+      echo "ifeq (\$(DEBUG), 1)";
612
+      echo -e '\tPELICANOPTS += -D';
613
+      echo 'endif';
614
+      echo '';
615
+      echo 'RELATIVE ?= 0';
616
+      echo "ifeq (\$(RELATIVE), 1)";
617
+      echo -e '\tPELICANOPTS += --relative-urls';
618
+      echo 'endif';
619
+      echo '';
620
+      echo 'html:';
621
+      echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
622
+      echo '';
623
+      echo 'clean:';
624
+      echo -e "\\t[ ! -d \$(OUTPUTDIR) ] || rm -rf \$(OUTPUTDIR)";
625
+      echo '';
626
+      echo 'regenerate:';
627
+      echo -e "\\t\$(PELICAN) -r \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
628
+      echo '';
629
+      echo 'serve:';
630
+      echo 'ifdef PORT';
631
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server \$(PORT)";
632
+      echo 'else';
633
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server";
634
+      echo 'endif';
635
+      echo '';
636
+      echo 'serve-global:';
637
+      echo 'ifdef SERVER';
638
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 \$(SERVER)";
639
+      echo 'else';
640
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 0.0.0.0";
641
+      echo 'endif';
642
+      echo '';
643
+      echo 'devserver:';
644
+      echo 'ifdef PORT';
645
+      echo -e "\\t\$(BASEDIR)/develop_server.sh restart \$(PORT)";
646
+      echo 'else';
647
+      echo -e "\\t\$(BASEDIR)/develop_server.sh restart";
648
+      echo 'endif';
649
+      echo '';
650
+      echo 'stopserver:';
651
+      echo -e "\\t\$(BASEDIR)/develop_server.sh stop";
652
+      echo -e '\t@echo "Stopped Pelican and SimpleHTTPServer processes running in background."';
653
+      echo '';
654
+      echo 'publish:';
655
+      echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(PUBLISHCONF) \$(PELICANOPTS)";
656
+      echo '';
657
+      echo '.PHONY: html clean regenerate serve serve-global devserver publish'; } > "$STATIC_BLOG_FILE"
649 658
 }
650 659
 
651 660
 function create_pelican_publish_conf {
652 661
     STATIC_BLOG_FILE=$1
653 662
 
654
-    echo '#!/usr/bin/env python' > $STATIC_BLOG_FILE
655
-    echo '# -*- coding: utf-8 -*- #' >> $STATIC_BLOG_FILE
656
-    echo 'from __future__ import unicode_literals' >> $STATIC_BLOG_FILE
657
-    echo '' >> $STATIC_BLOG_FILE
658
-    echo 'import os' >> $STATIC_BLOG_FILE
659
-    echo 'import sys' >> $STATIC_BLOG_FILE
660
-    echo 'sys.path.append(os.curdir)' >> $STATIC_BLOG_FILE
661
-    echo 'from pelicanconf import *' >> $STATIC_BLOG_FILE
662
-    echo '' >> $STATIC_BLOG_FILE
663
-    echo "SITEURL = ''" >> $STATIC_BLOG_FILE
664
-    echo 'RELATIVE_URLS = True' >> $STATIC_BLOG_FILE
665
-    echo '' >> $STATIC_BLOG_FILE
666
-    echo "FEED_ALL_ATOM = 'feeds/all.atom.xml'" >> $STATIC_BLOG_FILE
667
-    echo "CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'" >> $STATIC_BLOG_FILE
668
-    echo '' >> $STATIC_BLOG_FILE
669
-    echo 'DELETE_OUTPUT_DIRECTORY = True' >> $STATIC_BLOG_FILE
663
+    { echo '#!/usr/bin/env python';
664
+      echo '# -*- coding: utf-8 -*- #';
665
+      echo 'from __future__ import unicode_literals';
666
+      echo '';
667
+      echo 'import os';
668
+      echo 'import sys';
669
+      echo 'sys.path.append(os.curdir)';
670
+      echo 'from pelicanconf import *';
671
+      echo '';
672
+      echo "SITEURL = ''";
673
+      echo 'RELATIVE_URLS = True';
674
+      echo '';
675
+      echo "FEED_ALL_ATOM = 'feeds/all.atom.xml'";
676
+      echo "CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'";
677
+      echo '';
678
+      echo 'DELETE_OUTPUT_DIRECTORY = True'; } > "$STATIC_BLOG_FILE"
670 679
 }
671 680
 
672 681
 function pelican_themes {
@@ -747,10 +756,11 @@ function pelican_themes {
747 756
 }
748 757
 
749 758
 function mesh_install_pelican {
750
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
759
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" && "$VARIANT" != "usb" ]]; then
751 760
         return
752 761
     fi
753 762
 
763
+    # shellcheck disable=SC2154
754 764
     chroot "$rootdir" apt-get -yq install python-pip
755 765
     chroot "$rootdir" pip install ipython
756 766
     chroot "$rootdir" pip install Markdown
@@ -760,34 +770,34 @@ function mesh_install_pelican {
760 770
     PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
761 771
     PELICAN_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
762 772
 
763
-    if [ ! -d $rootdir$PELICAN_BLOG_INSTALL_DIR ]; then
764
-        mkdir -p $rootdir$PELICAN_BLOG_INSTALL_DIR
773
+    if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR" ]; then
774
+        mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR"
765 775
     fi
766 776
 
767
-    if [ ! -d $rootdir$PELICAN_BLOG_PATH ]; then
768
-        mkdir -p $rootdir$PELICAN_BLOG_PATH
777
+    if [ ! -d "$rootdir$PELICAN_BLOG_PATH" ]; then
778
+        mkdir -p "$rootdir$PELICAN_BLOG_PATH"
769 779
     fi
770 780
 
771
-    if [ ! -d $rootdir$PELICAN_BLOG_INSTALL_DIR/content/images ]; then
772
-        mkdir -p $rootdir$PELICAN_BLOG_INSTALL_DIR/content/images
781
+    if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images" ]; then
782
+        mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images"
773 783
     fi
774 784
 
775
-    create_pelican_conf $rootdir$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
776
-    create_pelican_makefile $rootdir$PELICAN_BLOG_INSTALL_DIR/Makefile
777
-    create_pelican_publish_conf $rootdir$PELICAN_BLOG_INSTALL_DIR/publishconf.py
785
+    create_pelican_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
786
+    create_pelican_makefile "$rootdir$PELICAN_BLOG_INSTALL_DIR/Makefile"
787
+    create_pelican_publish_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
778 788
 
779
-    mkdir -p $rootdir$PELICAN_BLOG_INSTALL_DIR/themes
780
-    cd $rootdir$PELICAN_BLOG_INSTALL_DIR/themes
789
+    mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes"
790
+    cd "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes" || exit 74624524
781 791
     pelican_themes
782 792
 
783 793
     #git clone --recursive $PELICAN_PLUGINS_REPO $rootdir$PELICAN_BLOG_INSTALL_DIR/plugins
784 794
 
785
-    chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME $PELICAN_BLOG_INSTALL_DIR
786
-    chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Public
795
+    chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
796
+    chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/Public"
787 797
 }
788 798
 
789 799
 function install_pelican {
790
-    if [ $INSTALLING_MESH ]; then
800
+    if [ "$INSTALLING_MESH" ]; then
791 801
         mesh_install_pelican
792 802
         return
793 803
     fi
@@ -800,29 +810,29 @@ function install_pelican {
800 810
 
801 811
     PELICAN_BLOG_PATH=/var/www/$PELICAN_DOMAIN_NAME/htdocs
802 812
 
803
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR ]; then
804
-        mkdir -p $PELICAN_BLOG_INSTALL_DIR
813
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR" ]; then
814
+        mkdir -p "$PELICAN_BLOG_INSTALL_DIR"
805 815
     fi
806 816
 
807 817
     if [ ! -d $PELICAN_BLOG_PATH ]; then
808 818
         mkdir -p $PELICAN_BLOG_PATH
809 819
     fi
810 820
 
811
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR/content ]; then
812
-        mkdir -p $PELICAN_BLOG_INSTALL_DIR/content
821
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/content" ]; then
822
+        mkdir -p "$PELICAN_BLOG_INSTALL_DIR/content"
813 823
     fi
814 824
 
815
-    create_pelican_conf $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
816
-    create_pelican_makefile $PELICAN_BLOG_INSTALL_DIR/Makefile
817
-    create_pelican_publish_conf $PELICAN_BLOG_INSTALL_DIR/publishconf.py
825
+    create_pelican_conf "$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
826
+    create_pelican_makefile "$PELICAN_BLOG_INSTALL_DIR/Makefile"
827
+    create_pelican_publish_conf "$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
818 828
 
819
-    mkdir -p $PELICAN_THEMES_REPO $PELICAN_BLOG_INSTALL_DIR/themes
820
-    cd $PELICAN_THEMES_REPO $PELICAN_BLOG_INSTALL_DIR/themes
829
+    mkdir -p "$PELICAN_THEMES_REPO" "$PELICAN_BLOG_INSTALL_DIR/themes"
830
+    cd "$PELICAN_BLOG_INSTALL_DIR/themes" || exit 45357282883
821 831
     pelican_themes
822 832
 
823 833
     #git clone --recursive $PELICAN_PLUGINS_REPO $PELICAN_BLOG_INSTALL_DIR/plugins
824 834
 
825
-    chown -R $MY_USERNAME:$MY_USERNAME $PELICAN_BLOG_INSTALL_DIR
835
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
826 836
     chown -R www-data:www-data $PELICAN_BLOG_PATH
827 837
 
828 838
     pelican_editor_config
@@ -834,7 +844,7 @@ function install_pelican {
834 844
     install_pelican_website_onion
835 845
 
836 846
     pelican_regenerate_blog
837
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR/output ]; then
847
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/output" ]; then
838 848
         echo $'Failed to generate pelican blog'
839 849
         exit 521892
840 850
     fi

+ 54
- 48
src/freedombone-app-pihole View File

@@ -66,17 +66,17 @@ function pihole_copy_files {
66 66
     if [ ! -d /etc/.pihole ]; then
67 67
         mkdir /etc/.pihole
68 68
     fi
69
-    cp $INSTALL_DIR/pihole/adlists.default /etc/.pihole/adlists.default
70
-    cp $INSTALL_DIR/pihole/adlists.default $piholeDir/adlists.default
69
+    cp "$INSTALL_DIR/pihole/adlists.default" /etc/.pihole/adlists.default
70
+    cp "$INSTALL_DIR/pihole/adlists.default" $piholeDir/adlists.default
71 71
     if [ ! -f $PIHOLE_CUSTOM_ADLIST ]; then
72
-        cp $INSTALL_DIR/pihole/adlists.default $PIHOLE_CUSTOM_ADLIST
72
+        cp "$INSTALL_DIR/pihole/adlists.default" $PIHOLE_CUSTOM_ADLIST
73 73
     fi
74
-    cp $INSTALL_DIR/pihole/advanced/Scripts/* /opt/$piholeBasename
74
+    cp "$INSTALL_DIR/pihole/advanced/Scripts/*" /opt/$piholeBasename
75 75
     if [ -f /etc/dnsmasq.d/01-pihole.conf ]; then
76 76
         rm /etc/dnsmasq.d/01-pihole.conf
77 77
     fi
78
-    cp $INSTALL_DIR/pihole/advanced/pihole.cron /etc/cron.d/pihole
79
-    cp $INSTALL_DIR/pihole/gravity.sh /opt/$piholeBasename
78
+    cp "$INSTALL_DIR/pihole/advanced/pihole.cron" /etc/cron.d/pihole
79
+    cp "$INSTALL_DIR/pihole/gravity.sh" /opt/$piholeBasename
80 80
     chmod +x /opt/pihole/*.sh
81 81
 }
82 82
 
@@ -95,7 +95,7 @@ function pihole_update {
95 95
         return
96 96
     fi
97 97
 
98
-    if [ ! -f $HOME/${PROJECT_NAME}-wifi.cfg ]; then
98
+    if [ ! -f "$HOME/${PROJECT_NAME}-wifi.cfg" ]; then
99 99
         PIHOLE_IFACE=eth0
100 100
     else
101 101
         read_config_param WIFI_INTERFACE
@@ -114,13 +114,13 @@ function pihole_update {
114 114
     echo "piholeDNS1=${PIHOLE_DNS1}" >> ${setupVars}
115 115
     echo "piholeDNS2=${PIHOLE_DNS1}" >> ${setupVars}
116 116
 
117
-    echo 'domain-needed' > /etc/dnsmasq.conf
118
-    echo 'bogus-priv' >> /etc/dnsmasq.conf
119
-    echo 'no-resolv' >> /etc/dnsmasq.conf
120
-    echo "server=${PIHOLE_DNS1}" >> /etc/dnsmasq.conf
121
-    echo "server=${PIHOLE_DNS2}" >> /etc/dnsmasq.conf
122
-    echo "interface=${PIHOLE_IFACE}" >> /etc/dnsmasq.conf
123
-    echo 'listen-address=127.0.0.1' >> /etc/dnsmasq.conf
117
+    { echo 'domain-needed';
118
+      echo 'bogus-priv';
119
+      echo 'no-resolv';
120
+      echo "server=${PIHOLE_DNS1}";
121
+      echo "server=${PIHOLE_DNS2}";
122
+      echo "interface=${PIHOLE_IFACE}";
123
+      echo 'listen-address=127.0.0.1'; } > /etc/dnsmasq.conf
124 124
 
125 125
     pihole -g
126 126
     systemctl restart dnsmasq
@@ -132,8 +132,7 @@ function pihole_update {
132 132
 }
133 133
 
134 134
 function pihole_change_upstream_dns {
135
-    data=$(tempfile 2>/dev/null)
136
-    trap "rm -f $data" 0 1 2 5 15
135
+    data=$(mktemp 2>/dev/null)
137 136
     dialog --backtitle $"Ad Blocker Upstream DNS" \
138 137
            --radiolist $"Pick a domain name service (DNS):" 28 50 19 \
139 138
            1 $"Digital Courage" on \
@@ -154,13 +153,15 @@ function pihole_change_upstream_dns {
154 153
            16 $"DNS.Watch" off \
155 154
            17 $"uncensoreddns.org" off \
156 155
            18 $"Lorraine Data Network" off \
157
-           19 $"Google" off 2> $data
156
+           19 $"Google" off 2> "$data"
158 157
     sel=$?
159 158
     case $sel in
160
-        1) exit 1;;
161
-        255) exit 1;;
159
+        1) rm -f "$data"
160
+           exit 1;;
161
+        255) rm -f "$data"
162
+             exit 1;;
162 163
     esac
163
-    case $(cat $data) in
164
+    case $(cat "$data") in
164 165
         1) PIHOLE_DNS1='85.214.73.63'
165 166
            PIHOLE_DNS2='213.73.91.35'
166 167
            ;;
@@ -218,10 +219,12 @@ function pihole_change_upstream_dns {
218 219
         19) PIHOLE_DNS1='8.8.8.8'
219 220
             PIHOLE_DNS2='4.4.4.4'
220 221
             dialog --title $"WARNING" \
221
-                   --msgbox $"\nGoogle's main purpose for providing DNS resolvers is to spy upon people and know which sites they are visiting.\n\nThis is something to consider, and you should only really be using Google DNS as a last resort if other resolvers are unavailable." 12 60
222
+                   --msgbox $"\\nGoogle's main purpose for providing DNS resolvers is to spy upon people and know which sites they are visiting.\\n\\nThis is something to consider, and you should only really be using Google DNS as a last resort if other resolvers are unavailable." 12 60
222 223
             ;;
223
-        255) exit 1;;
224
+        255) rm -f "$data"
225
+             exit 1;;
224 226
     esac
227
+    rm -f "$data"
225 228
     write_config_param "PIHOLE_DNS1" "$PIHOLE_DNS1"
226 229
     write_config_param "PIHOLE_DNS2" "$PIHOLE_DNS2"
227 230
 }
@@ -252,8 +255,7 @@ function pihole_resume {
252 255
 function configure_interactive_pihole {
253 256
     while true
254 257
     do
255
-        data=$(tempfile 2>/dev/null)
256
-        trap "rm -f $data" 0 1 2 5 15
258
+        data=$(mktemp 2>/dev/null)
257 259
         dialog --backtitle $"Freedombone Control Panel" \
258 260
                --title $"Ad Blocker" \
259 261
                --radiolist $"Choose an operation:" 16 70 7 \
@@ -263,13 +265,15 @@ function configure_interactive_pihole {
263 265
                4 $"Change upstream DNS servers" off \
264 266
                5 $"Pause blocker" off \
265 267
                6 $"Resume blocker" off \
266
-               7 $"Exit" on 2> $data
268
+               7 $"Exit" on 2> "$data"
267 269
         sel=$?
268 270
         case $sel in
269
-            1) exit 1;;
270
-            255) exit 1;;
271
+            1) rm -f "$data"
272
+               exit 1;;
273
+            255) rm -f "$data"
274
+                 exit 1;;
271 275
         esac
272
-        case $(cat $data) in
276
+        case $(cat "$data") in
273 277
             1) editor $PIHOLE_CUSTOM_ADLIST
274 278
                update_pihole_interactive
275 279
                ;;
@@ -286,8 +290,10 @@ function configure_interactive_pihole {
286 290
                ;;
287 291
             6) pihole_resume
288 292
                ;;
289
-            7) break;;
293
+            7) rm -f "$data"
294
+               break;;
290 295
         esac
296
+        rm -f "$data"
291 297
     done
292 298
 }
293 299
 
@@ -306,7 +312,7 @@ function upgrade_pihole {
306 312
     fi
307 313
 
308 314
     function_check set_repo_commit
309
-    set_repo_commit $INSTALL_DIR/pihole "pihole commit" "$PIHOLE_COMMIT" $PIHOLE_REPO
315
+    set_repo_commit "$INSTALL_DIR/pihole" "pihole commit" "$PIHOLE_COMMIT" $PIHOLE_REPO
310 316
 
311 317
     pihole_copy_files
312 318
     pihole_update
@@ -367,8 +373,8 @@ function remove_pihole {
367 373
         rm /etc/cron.d/pihole
368 374
     fi
369 375
 
370
-    if [ -d $INSTALL_DIR/pihole ]; then
371
-        rm -rf $INSTALL_DIR/pihole
376
+    if [ -d "$INSTALL_DIR/pihole" ]; then
377
+        rm -rf "$INSTALL_DIR/pihole"
372 378
     fi
373 379
 
374 380
     firewall_remove 53
@@ -391,27 +397,27 @@ function install_pihole {
391 397
 
392 398
     systemctl enable dnsmasq
393 399
 
394
-    if [ ! -d $INSTALL_DIR ]; then
395
-        mkdir -p $INSTALL_DIR
400
+    if [ ! -d "$INSTALL_DIR" ]; then
401
+        mkdir -p "$INSTALL_DIR"
396 402
     fi
397 403
 
398
-    if [ ! -d $INSTALL_DIR/pihole ]; then
399
-        cd $INSTALL_DIR
404
+    if [ ! -d "$INSTALL_DIR/pihole" ]; then
405
+        cd "$INSTALL_DIR" || exit 78245624527
400 406
 
401 407
         if [ -d /repos/pihole ]; then
402 408
             mkdir pihole
403 409
             cp -r -p /repos/pihole/. pihole
404
-            cd pihole
410
+            cd pihole || exit 24572424684
405 411
             git pull
406 412
         else
407 413
             git_clone $PIHOLE_REPO pihole
408 414
         fi
409 415
 
410
-        if [ ! -d $INSTALL_DIR/pihole ]; then
416
+        if [ ! -d "$INSTALL_DIR/pihole" ]; then
411 417
             exit 523925
412 418
         fi
413
-        cd $INSTALL_DIR/pihole
414
-        git checkout $PIHOLE_COMMIT -b $PIHOLE_COMMIT
419
+        cd "$INSTALL_DIR/pihole" || exit 2682468242
420
+        git checkout "$PIHOLE_COMMIT" -b "$PIHOLE_COMMIT"
415 421
         set_completion_param "pihole commit" "$PIHOLE_COMMIT"
416 422
     fi
417 423
 
@@ -420,21 +426,21 @@ function install_pihole {
420 426
     fi
421 427
 
422 428
     # blank file which takes the place of ads
423
-    echo '<html>' > /var/www/pihole/htdocs/index.html
424
-    echo '<body>' >> /var/www/pihole/htdocs/index.html
425
-    echo '</body>' >> /var/www/pihole/htdocs/index.html
426
-    echo '</html>' >> /var/www/pihole/htdocs/index.html
429
+    { echo '<html>';
430
+      echo '<body>';
431
+      echo '</body>';
432
+      echo '</html>'; } > /var/www/pihole/htdocs/index.html
427 433
 
428
-    if [ ! -f $INSTALL_DIR/pihole/gravity.sh ]; then
434
+    if [ ! -f "$INSTALL_DIR/pihole/gravity.sh" ]; then
429 435
         exit 26738
430 436
     fi
431
-    cp $INSTALL_DIR/pihole/gravity.sh /usr/local/bin/gravity.sh
437
+    cp "$INSTALL_DIR/pihole/gravity.sh" /usr/local/bin/gravity.sh
432 438
     chmod 755 /usr/local/bin/gravity.sh
433 439
 
434
-    if [ ! -f $INSTALL_DIR/pihole/pihole ]; then
440
+    if [ ! -f "$INSTALL_DIR/pihole/pihole" ]; then
435 441
         exit 52935
436 442
     fi
437
-    cp $INSTALL_DIR/pihole/pihole /usr/local/bin/pihole
443
+    cp "$INSTALL_DIR/pihole/pihole" /usr/local/bin/pihole
438 444
     chmod 755 /usr/local/bin/pihole
439 445
 
440 446
     if [ ! -d $piholeDir ]; then

+ 331
- 333
src/freedombone-app-pleroma
File diff suppressed because it is too large
View File


+ 278
- 275
src/freedombone-app-postactiv
File diff suppressed because it is too large
View File


+ 161
- 157
src/freedombone-app-privatebin View File

@@ -56,7 +56,7 @@ function secure_privatebin {
56 56
     find "${pbpath}/" -type d -print0 | xargs -0 chmod 0550
57 57
 
58 58
     chown -R ${rootuser}:${htgroup} "${pbpath}/"
59
-    chown -R www-data:www-data ${pbdata}
59
+    chown -R www-data:www-data "${pbdata}"
60 60
 }
61 61
 
62 62
 function logging_on_privatebin {
@@ -68,63 +68,65 @@ function logging_off_privatebin {
68 68
 }
69 69
 
70 70
 function remove_user_privatebin {
71
-    remove_username="$1"
71
+    echo -n ''
72
+#    remove_username="$1"
72 73
 }
73 74
 
74 75
 function add_user_privatebin {
75
-    new_username="$1"
76
-    new_user_password="$2"
76
+#    new_username="$1"
77
+#    new_user_password="$2"
77 78
 
78 79
     echo '0'
79 80
 }
80 81
 
81 82
 function install_interactive_privatebin {
82
-    if [ ! $ONION_ONLY ]; then
83
+    if [ ! "$ONION_ONLY" ]; then
83 84
         ONION_ONLY='no'
84 85
     fi
85 86
 
86
-    if [[ $ONION_ONLY != "no" ]]; then
87
+    if [[ "$ONION_ONLY" != "no" ]]; then
87 88
         PRIVATEBIN_DOMAIN_NAME='privatebin.local'
88 89
     else
89 90
         PRIVATEBIN_DETAILS_COMPLETE=
90 91
         while [ ! $PRIVATEBIN_DETAILS_COMPLETE ]
91 92
         do
92
-            data=$(tempfile 2>/dev/null)
93
-            trap "rm -f $data" 0 1 2 5 15
93
+            data=$(mktemp 2>/dev/null)
94 94
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
95 95
                 dialog --backtitle $"Freedombone Configuration" \
96 96
                        --title $"PrivateBin Configuration" \
97
-                       --form $"\nPlease enter your PrivateBin details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
97
+                       --form $"\\nPlease enter your PrivateBin details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
98 98
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
99 99
                        $"Code:" 2 1 "$(grep 'PRIVATEBIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
100
-                       2> $data
100
+                       2> "$data"
101 101
             else
102 102
                 dialog --backtitle $"Freedombone Configuration" \
103 103
                        --title $"PrivateBin Configuration" \
104
-                       --form $"\nPlease enter your PrivateBin details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
104
+                       --form $"\\nPlease enter your PrivateBin details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
105 105
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
106
-                       2> $data
106
+                       2> "$data"
107 107
             fi
108 108
             sel=$?
109 109
             case $sel in
110
-                1) exit 1;;
111
-                255) exit 1;;
110
+                1) rm -f "$data"
111
+                   exit 1;;
112
+                255) rm -f "$data"
113
+                     exit 1;;
112 114
             esac
113
-            PRIVATEBIN_DOMAIN_NAME=$(cat $data | sed -n 1p)
114
-            if [ $PRIVATEBIN_DOMAIN_NAME ]; then
115
-                if [[ $PRIVATEBIN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
115
+            PRIVATEBIN_DOMAIN_NAME=$(sed -n 1p < "$data")
116
+            if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
117
+                if [[ "$PRIVATEBIN_DOMAIN_NAME" == "$HUBZILLA_DOMAIN_NAME" ]]; then
116 118
                     PRIVATEBIN_DOMAIN_NAME=""
117 119
                 fi
118 120
                 TEST_DOMAIN_NAME=$PRIVATEBIN_DOMAIN_NAME
119 121
                 validate_domain_name
120
-                if [[ $TEST_DOMAIN_NAME != $PRIVATEBIN_DOMAIN_NAME ]]; then
122
+                if [[ "$TEST_DOMAIN_NAME" != "$PRIVATEBIN_DOMAIN_NAME" ]]; then
121 123
                     PRIVATEBIN_DOMAIN_NAME=
122 124
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
123 125
                 else
124 126
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
125
-                        PRIVATEBIN_CODE=$(cat $data | sed -n 2p)
127
+                        PRIVATEBIN_CODE=$(sed -n 2p < "$data")
126 128
                         validate_freedns_code "$PRIVATEBIN_CODE"
127
-                        if [ ! $VALID_CODE ]; then
129
+                        if [ ! "$VALID_CODE" ]; then
128 130
                             PRIVATEBIN_DOMAIN_NAME=
129 131
                         fi
130 132
                     fi
@@ -133,6 +135,7 @@ function install_interactive_privatebin {
133 135
             if [ $PRIVATEBIN_DOMAIN_NAME ]; then
134 136
                 PRIVATEBIN_DETAILS_COMPLETE="yes"
135 137
             fi
138
+            rm -f "$data"
136 139
         done
137 140
 
138 141
         write_config_param "PRIVATEBIN_CODE" "$PRIVATEBIN_CODE"
@@ -142,8 +145,9 @@ function install_interactive_privatebin {
142 145
 }
143 146
 
144 147
 function change_password_privatebin {
145
-    curr_username="$1"
146
-    new_user_password="$2"
148
+#    curr_username="$1"
149
+#    new_user_password="$2"
150
+    echo -n ''
147 151
 }
148 152
 
149 153
 function reconfigure_privatebin {
@@ -156,13 +160,13 @@ function upgrade_privatebin {
156 160
         return
157 161
     fi
158 162
 
159
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
163
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
160 164
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
161 165
     fi
162 166
 
163 167
     # update to the next commit
164 168
     function_check set_repo_commit
165
-    set_repo_commit /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs "privatebin commit" "$PRIVATEBIN_COMMIT" $PRIVATEBIN_REPO
169
+    set_repo_commit "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" "privatebin commit" "$PRIVATEBIN_COMMIT" "$PRIVATEBIN_REPO"
166 170
 
167 171
     secure_privatebin
168 172
 }
@@ -170,40 +174,40 @@ function upgrade_privatebin {
170 174
 
171 175
 function backup_local_privatebin {
172 176
     PRIVATEBIN_DOMAIN_NAME='privatebin'
173
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
177
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
174 178
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
175 179
     fi
176 180
 
177
-    source_directory=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
181
+    source_directory="/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data"
178 182
 
179 183
     function_check suspend_site
180
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
184
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
181 185
 
182 186
     function_check backup_directory_to_usb
183 187
     dest_directory=privatebin
184
-    backup_directory_to_usb $source_directory $dest_directory
188
+    backup_directory_to_usb "$source_directory" "$dest_directory"
185 189
 
186 190
     function_check restart_site
187 191
     restart_site
188 192
 }
189 193
 
190 194
 function restore_local_privatebin {
191
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
195
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
192 196
         return
193 197
     fi
194 198
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
195
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
199
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
196 200
         echo $"Restoring privatebin"
197 201
         temp_restore_dir=/root/tempprivatebin
198
-        privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
202
+        privatebin_dir="/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data"
199 203
 
200 204
         function_check restore_directory_from_usb
201 205
         restore_directory_from_usb $temp_restore_dir privatebin
202 206
         if [ -d $temp_restore_dir ]; then
203
-            if [ -d cp $temp_restore_dir$privatebin_dir ]; then
204
-                cp -rp $temp_restore_dir$privatebin_dir/* $privatebin_dir/
207
+            if [ -d "$temp_restore_dir$privatebin_dir" ]; then
208
+                cp -rp "$temp_restore_dir$privatebin_dir/*" "$privatebin_dir/"
205 209
             else
206
-                cp -rp $temp_restore_dir/* $privatebin_dir/
210
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
207 211
             fi
208 212
             secure_privatebin
209 213
             rm -rf $temp_restore_dir
@@ -215,39 +219,39 @@ function restore_local_privatebin {
215 219
 
216 220
 function backup_remote_privatebin {
217 221
     PRIVATEBIN_DOMAIN_NAME='privatebin'
218
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
222
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
219 223
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
220 224
     fi
221 225
 
222
-    source_directory=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
226
+    source_directory="/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data"
223 227
 
224 228
     function_check suspend_site
225
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
229
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
226 230
 
227 231
     function_check backup_directory_to_friend
228 232
     dest_directory=privatebin
229
-    backup_directory_to_friend $source_directory $dest_directory
233
+    backup_directory_to_friend "$source_directory" "$dest_directory"
230 234
 
231 235
     function_check restart_site
232 236
     restart_site
233 237
 }
234 238
 
235 239
 function restore_remote_privatebin {
236
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
240
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
237 241
         return
238 242
     fi
239 243
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
240
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
244
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
241 245
         temp_restore_dir=/root/tempprivatebin
242 246
         privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
243 247
 
244 248
         function_check restore_directory_from_friend
245 249
         restore_directory_from_friend $temp_restore_dir privatebin
246 250
         if [ -d $temp_restore_dir ]; then
247
-            if [ -d cp $temp_restore_dir$privatebin_dir ]; then
248
-                cp -rp $temp_restore_dir$privatebin_dir/* $privatebin_dir/
251
+            if [ -d "$temp_restore_dir$privatebin_dir" ]; then
252
+                cp -rp "$temp_restore_dir$privatebin_dir/*" "$privatebin_dir/"
249 253
             else
250
-                cp -rp $temp_restore_dir/* $privatebin_dir/
254
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
251 255
             fi
252 256
             secure_privatebin
253 257
             rm -rf $temp_restore_dir
@@ -262,14 +266,14 @@ function remove_privatebin {
262 266
     read_config_param "PRIVATEBIN_DOMAIN_NAME"
263 267
     read_config_param "MY_USERNAME"
264 268
     echo "Removing $PRIVATEBIN_DOMAIN_NAME"
265
-    nginx_dissite $PRIVATEBIN_DOMAIN_NAME
266
-    remove_certs $PRIVATEBIN_DOMAIN_NAME
269
+    nginx_dissite "$PRIVATEBIN_DOMAIN_NAME"
270
+    remove_certs "$PRIVATEBIN_DOMAIN_NAME"
267 271
 
268
-    if [ -d /var/www/$PRIVATEBIN_DOMAIN_NAME ]; then
269
-        rm -rf /var/www/$PRIVATEBIN_DOMAIN_NAME
272
+    if [ -d "/var/www/$PRIVATEBIN_DOMAIN_NAME" ]; then
273
+        rm -rf "/var/www/$PRIVATEBIN_DOMAIN_NAME"
270 274
     fi
271
-    if [ -f /etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME ]; then
272
-        rm /etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
275
+    if [ -f "/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME" ]; then
276
+        rm "/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME"
273 277
     fi
274 278
     function_check remove_onion_service
275 279
     remove_onion_service privatebin ${PRIVATEBIN_ONION_PORT}
@@ -278,18 +282,18 @@ function remove_privatebin {
278 282
     fi
279 283
     remove_app privatebin
280 284
     remove_completion_param install_privatebin
281
-    sed -i '/privatebin/d' $COMPLETION_FILE
285
+    sed -i '/privatebin/d' "$COMPLETION_FILE"
282 286
 
283 287
     function_check remove_ddns_domain
284
-    remove_ddns_domain $PRIVATEBIN_DOMAIN_NAME
288
+    remove_ddns_domain "$PRIVATEBIN_DOMAIN_NAME"
285 289
 }
286 290
 
287 291
 function install_privatebin {
288
-    if [ ! $ONION_ONLY ]; then
292
+    if [ ! "$ONION_ONLY" ]; then
289 293
         ONION_ONLY='no'
290 294
     fi
291 295
 
292
-    if [ ! $PRIVATEBIN_DOMAIN_NAME ]; then
296
+    if [ ! "$PRIVATEBIN_DOMAIN_NAME" ]; then
293 297
         echo $'No domain name was given for privatebin'
294 298
         exit 7359
295 299
     fi
@@ -298,153 +302,153 @@ function install_privatebin {
298 302
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
299 303
     apt-get -yq install php-libsodium libsodium18 php-mcrypt
300 304
 
301
-    if [ ! -d /var/www/$PRIVATEBIN_DOMAIN_NAME ]; then
302
-        mkdir /var/www/$PRIVATEBIN_DOMAIN_NAME
305
+    if [ ! -d "/var/www/$PRIVATEBIN_DOMAIN_NAME" ]; then
306
+        mkdir "/var/www/$PRIVATEBIN_DOMAIN_NAME"
303 307
     fi
304
-    if [ ! -d /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs ]; then
308
+    if [ ! -d "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" ]; then
305 309
 
306 310
         if [ -d /repos/privatebin ]; then
307
-            mkdir /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
308
-            cp -r -p /repos/privatebin/. /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
309
-            cd /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
311
+            mkdir "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
312
+            cp -r -p /repos/privatebin/. "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
313
+            cd "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" || exit 3468246824
310 314
             git pull
311 315
         else
312 316
             function_check git_clone
313
-            git_clone $PRIVATEBIN_REPO /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
317
+            git_clone "$PRIVATEBIN_REPO" "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
314 318
         fi
315 319
 
316
-        if [ ! -d /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs ]; then
320
+        if [ ! -d "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" ]; then
317 321
             echo $'Unable to clone privatebin repo'
318 322
             exit 63763873
319 323
         fi
320 324
     fi
321 325
 
322
-    cd /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
323
-    git checkout $PRIVATEBIN_COMMIT -b $PRIVATEBIN_COMMIT
326
+    cd "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" || exit 24682462
327
+    git checkout "$PRIVATEBIN_COMMIT" -b "$PRIVATEBIN_COMMIT"
324 328
     set_completion_param "privatebin commit" "$PRIVATEBIN_COMMIT"
325 329
 
326
-    chmod g+w /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
327
-    chown -R www-data:www-data /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
330
+    chmod g+w "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
331
+    chown -R www-data:www-data "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
328 332
 
329 333
     function_check add_ddns_domain
330
-    add_ddns_domain $PRIVATEBIN_DOMAIN_NAME
334
+    add_ddns_domain "$PRIVATEBIN_DOMAIN_NAME"
331 335
 
332 336
     PRIVATEBIN_ONION_HOSTNAME=$(add_onion_service privatebin 80 ${PRIVATEBIN_ONION_PORT})
333 337
 
334 338
     privatebin_nginx_site=/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
335 339
     if [[ $ONION_ONLY == "no" ]]; then
336 340
         function_check nginx_http_redirect
337
-        nginx_http_redirect $PRIVATEBIN_DOMAIN_NAME "index index.php"
338
-        echo 'server {' >> $privatebin_nginx_site
339
-        echo '  listen 443 ssl;' >> $privatebin_nginx_site
340
-        echo '  #listen [::]:443 ssl;' >> $privatebin_nginx_site
341
-        echo "  server_name $PRIVATEBIN_DOMAIN_NAME;" >> $privatebin_nginx_site
342
-        echo '' >> $privatebin_nginx_site
341
+        nginx_http_redirect "$PRIVATEBIN_DOMAIN_NAME" "index index.php"
342
+        { echo 'server {';
343
+          echo '  listen 443 ssl;';
344
+          echo '  #listen [::]:443 ssl;';
345
+          echo "  server_name $PRIVATEBIN_DOMAIN_NAME;";
346
+          echo ''; } >> "$privatebin_nginx_site"
343 347
         function_check nginx_compress
344
-        nginx_compress $PRIVATEBIN_DOMAIN_NAME
345
-        echo '' >> $privatebin_nginx_site
346
-        echo '  # Security' >> $privatebin_nginx_site
348
+        nginx_compress "$PRIVATEBIN_DOMAIN_NAME"
349
+        echo '' >> "$privatebin_nginx_site"
350
+        echo '  # Security' >> "$privatebin_nginx_site"
347 351
         function_check nginx_ssl
348
-        nginx_ssl $PRIVATEBIN_DOMAIN_NAME
352
+        nginx_ssl "$PRIVATEBIN_DOMAIN_NAME"
349 353
 
350 354
         function_check nginx_disable_sniffing
351
-        nginx_disable_sniffing $PRIVATEBIN_DOMAIN_NAME
352
-
353
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $privatebin_nginx_site
354
-        echo '' >> $privatebin_nginx_site
355
-        echo '  # Logs' >> $privatebin_nginx_site
356
-        echo '  access_log /dev/null;' >> $privatebin_nginx_site
357
-        echo '  error_log /dev/null;' >> $privatebin_nginx_site
358
-        echo '' >> $privatebin_nginx_site
359
-        echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;" >> $privatebin_nginx_site
360
-        echo '' >> $privatebin_nginx_site
361
-        echo '  index index.php;' >> $privatebin_nginx_site
362
-        echo '' >> $privatebin_nginx_site
363
-        echo '  location ~ \.php {' >> $privatebin_nginx_site
364
-        echo '    include snippets/fastcgi-php.conf;' >> $privatebin_nginx_site
365
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $privatebin_nginx_site
366
-        echo '    fastcgi_read_timeout 30;' >> $privatebin_nginx_site
367
-        echo '  }' >> $privatebin_nginx_site
368
-        echo '' >> $privatebin_nginx_site
369
-        echo '  # Location' >> $privatebin_nginx_site
370
-        echo '  location / {' >> $privatebin_nginx_site
355
+        nginx_disable_sniffing "$PRIVATEBIN_DOMAIN_NAME"
356
+
357
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
358
+          echo '';
359
+          echo '  # Logs';
360
+          echo '  access_log /dev/null;';
361
+          echo '  error_log /dev/null;';
362
+          echo '';
363
+          echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;";
364
+          echo '';
365
+          echo '  index index.php;';
366
+          echo '';
367
+          echo '  location ~ \.php {';
368
+          echo '    include snippets/fastcgi-php.conf;';
369
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
370
+          echo '    fastcgi_read_timeout 30;';
371
+          echo '  }';
372
+          echo '';
373
+          echo '  # Location';
374
+          echo '  location / {'; } >> "$privatebin_nginx_site"
371 375
         function_check nginx_limits
372
-        nginx_limits $PRIVATEBIN_DOMAIN_NAME '15m'
373
-        echo '    try_files $uri $uri/ @privatebin;' >> $privatebin_nginx_site
374
-        echo '  }' >> $privatebin_nginx_site
375
-        echo '' >> $privatebin_nginx_site
376
-        echo '  # Restrict access that is unnecessary anyway' >> $privatebin_nginx_site
377
-        echo '  location ~ /\.(ht|git) {' >> $privatebin_nginx_site
378
-        echo '    deny all;' >> $privatebin_nginx_site
379
-        echo '  }' >> $privatebin_nginx_site
380
-        echo '}' >> $privatebin_nginx_site
381
-        echo '' >> $privatebin_nginx_site
376
+        nginx_limits "$PRIVATEBIN_DOMAIN_NAME" '15m'
377
+        { echo '    try_files $uri $uri/ @privatebin;';
378
+          echo '  }';
379
+          echo '';
380
+          echo '  # Restrict access that is unnecessary anyway';
381
+          echo '  location ~ /\.(ht|git) {';
382
+          echo '    deny all;';
383
+          echo '  }';
384
+          echo '}';
385
+          echo ''; } >> "$privatebin_nginx_site"
382 386
     else
383
-        echo -n '' > $privatebin_nginx_site
387
+        echo -n '' > "$privatebin_nginx_site"
384 388
     fi
385
-    echo 'server {' >> $privatebin_nginx_site
386
-    echo "    listen 127.0.0.1:$PRIVATEBIN_ONION_PORT default_server;" >> $privatebin_nginx_site
387
-    echo "    server_name $PRIVATEBIN_ONION_HOSTNAME;" >> $privatebin_nginx_site
388
-    echo '' >> $privatebin_nginx_site
389
+    { echo 'server {';
390
+      echo "    listen 127.0.0.1:$PRIVATEBIN_ONION_PORT default_server;";
391
+      echo "    server_name $PRIVATEBIN_ONION_HOSTNAME;";
392
+      echo ''; } >> "$privatebin_nginx_site"
389 393
     function_check nginx_compress
390
-    nginx_compress $PRIVATEBIN_DOMAIN_NAME
391
-    echo '' >> $privatebin_nginx_site
394
+    nginx_compress "$PRIVATEBIN_DOMAIN_NAME"
395
+    echo '' >> "$privatebin_nginx_site"
392 396
     function_check nginx_disable_sniffing
393
-    nginx_disable_sniffing $PRIVATEBIN_DOMAIN_NAME
394
-    echo '' >> $privatebin_nginx_site
395
-    echo '  # Logs' >> $privatebin_nginx_site
396
-    echo '  access_log /dev/null;' >> $privatebin_nginx_site
397
-    echo '  error_log /dev/null;' >> $privatebin_nginx_site
398
-    echo '' >> $privatebin_nginx_site
399
-    echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;" >> $privatebin_nginx_site
400
-    echo '' >> $privatebin_nginx_site
401
-    echo '  index index.php;' >> $privatebin_nginx_site
402
-    echo '' >> $privatebin_nginx_site
403
-    echo '  location ~ \.php {' >> $privatebin_nginx_site
404
-    echo '    include snippets/fastcgi-php.conf;' >> $privatebin_nginx_site
405
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $privatebin_nginx_site
406
-    echo '    fastcgi_read_timeout 30;' >> $privatebin_nginx_site
407
-    echo '  }' >> $privatebin_nginx_site
408
-    echo '' >> $privatebin_nginx_site
409
-    echo '  # Location' >> $privatebin_nginx_site
410
-    echo '  location / {' >> $privatebin_nginx_site
397
+    nginx_disable_sniffing "$PRIVATEBIN_DOMAIN_NAME"
398
+    { echo '';
399
+      echo '  # Logs';
400
+      echo '  access_log /dev/null;';
401
+      echo '  error_log /dev/null;';
402
+      echo '';
403
+      echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;";
404
+      echo '';
405
+      echo '  index index.php;';
406
+      echo '';
407
+      echo '  location ~ \.php {';
408
+      echo '    include snippets/fastcgi-php.conf;';
409
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
410
+      echo '    fastcgi_read_timeout 30;';
411
+      echo '  }';
412
+      echo '';
413
+      echo '  # Location';
414
+      echo '  location / {'; } >> "$privatebin_nginx_site"
411 415
     function_check nginx_limits
412
-    nginx_limits $PRIVATEBIN_DOMAIN_NAME '15m'
413
-    echo '    try_files $uri $uri/ @privatebin;' >> $privatebin_nginx_site
414
-    echo '  }' >> $privatebin_nginx_site
415
-    echo '' >> $privatebin_nginx_site
416
-    echo '  # Restrict access that is unnecessary anyway' >> $privatebin_nginx_site
417
-    echo '  location ~ /\.(ht|git) {' >> $privatebin_nginx_site
418
-    echo '    deny all;' >> $privatebin_nginx_site
419
-    echo '  }' >> $privatebin_nginx_site
420
-    echo '}' >> $privatebin_nginx_site
416
+    nginx_limits "$PRIVATEBIN_DOMAIN_NAME" '15m'
417
+    { echo '    try_files $uri $uri/ @privatebin;';
418
+      echo '  }';
419
+      echo '';
420
+      echo '  # Restrict access that is unnecessary anyway';
421
+      echo '  location ~ /\.(ht|git) {';
422
+      echo '    deny all;';
423
+      echo '  }';
424
+      echo '}'; } >> "$privatebin_nginx_site"
421 425
 
422 426
     function_check configure_php
423 427
     configure_php
424 428
 
425 429
     function_check create_site_certificate
426
-    create_site_certificate $PRIVATEBIN_DOMAIN_NAME 'yes'
430
+    create_site_certificate "$PRIVATEBIN_DOMAIN_NAME" 'yes'
427 431
 
428 432
     function_check nginx_ensite
429
-    nginx_ensite $PRIVATEBIN_DOMAIN_NAME
433
+    nginx_ensite "$PRIVATEBIN_DOMAIN_NAME"
430 434
 
431
-    cp /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.sample.php /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
435
+    cp "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.sample.php" "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
432 436
 
433 437
     # Change some defaults
434
-    sed -i 's|; qrcode|qrcode|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
435
-    sed -i 's|default =.*|default = "1day"|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
436
-    sed -i 's|languagedefault =.*|languagedefault = "en"|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
437
-    sed -i 's|1week =|; 1week =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
438
-    sed -i 's|1month =|; 1month =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
439
-    sed -i 's|1year =|; 1year =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
440
-    sed -i 's|never =|; never =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
441
-    sed -i 's|limit = 10|limit = 30|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
442
-    sed -i 's|limit = 300|limit = 0|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
443
-    sed -i 's|batchsize =.*|batchsize = 100|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
444
-    sed -i 's|sizelimit =.*|sizelimit = 32768|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
445
-    sed -i 's|defaultformatter =.*|defaultformatter = "markdown"|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
446
-
447
-    mkdir -p /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/data
438
+    sed -i 's|; qrcode|qrcode|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
439
+    sed -i 's|default =.*|default = "1day"|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
440
+    sed -i 's|languagedefault =.*|languagedefault = "en"|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
441
+    sed -i 's|1week =|; 1week =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
442
+    sed -i 's|1month =|; 1month =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
443
+    sed -i 's|1year =|; 1year =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
444
+    sed -i 's|never =|; never =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
445
+    sed -i 's|limit = 10|limit = 30|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
446
+    sed -i 's|limit = 300|limit = 0|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
447
+    sed -i 's|batchsize =.*|batchsize = 100|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
448
+    sed -i 's|sizelimit =.*|sizelimit = 32768|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
449
+    sed -i 's|defaultformatter =.*|defaultformatter = "markdown"|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
450
+
451
+    mkdir -p "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/data"
448 452
 
449 453
     secure_privatebin
450 454
 

+ 114
- 113
src/freedombone-app-profanity View File

@@ -57,12 +57,13 @@ function logging_off_profanity {
57 57
 }
58 58
 
59 59
 function remove_user_profanity {
60
-    remove_username="$1"
60
+    echo -n ''
61
+#    remove_username="$1"
61 62
 }
62 63
 
63 64
 function add_user_profanity {
64
-    new_username="$1"
65
-    new_user_password="$2"
65
+#    new_username="$1"
66
+#    new_user_password="$2"
66 67
 
67 68
     echo '0'
68 69
 }
@@ -82,19 +83,19 @@ function change_password_profanity {
82 83
 
83 84
     read_config_param DEFAULT_DOMAIN_NAME
84 85
 
85
-    ${PROJECT_NAME}-pass -u $curr_username -a xmpp -p "$new_user_password"
86
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a xmpp -p "$new_user_password"
86 87
 
87 88
     # TODO: this is currently interactive. Really there needs to be a
88 89
     # non-interactive password change option for prosodyctl
89 90
     clear
90 91
     echo ''
91 92
     echo $'Currently Prosody requires password changes to be done interactively'
92
-    prosodyctl passwd ${curr_username}@${DEFAULT_DOMAIN_NAME}
93
+    prosodyctl passwd "${curr_username}@${DEFAULT_DOMAIN_NAME}"
93 94
 
94 95
     XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
95 96
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
96
-    if [ -f $XMPP_CLIENT_ACCOUNTS ]; then
97
-        sed -i "s|password=.*|password=$new_user_password|g" $XMPP_CLIENT_ACCOUNTS
97
+    if [ -f "$XMPP_CLIENT_ACCOUNTS" ]; then
98
+        sed -i "s|password=.*|password=$new_user_password|g" "$XMPP_CLIENT_ACCOUNTS"
98 99
     fi
99 100
 }
100 101
 
@@ -110,11 +111,11 @@ function upgrade_profanity {
110 111
 
111 112
     rm -rf /tmp/*
112 113
 
113
-    CURR_LIBMESODE_COMMIT=$(cat $COMPLETION_FILE | grep "libmesode commit" | awk -F ':' '{print $2}')
114
+    CURR_LIBMESODE_COMMIT=$(grep "libmesode commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
114 115
     if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
115 116
         function_check set_repo_commit
116
-        set_repo_commit $INSTALL_DIR/libmesode "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
117
-        cd $INSTALL_DIR/libmesode
117
+        set_repo_commit "$INSTALL_DIR/libmesode" "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
118
+        cd "$INSTALL_DIR/libmesode" || exit 42682682
118 119
         ./bootstrap.sh
119 120
         ./configure
120 121
         make
@@ -124,42 +125,42 @@ function upgrade_profanity {
124 125
 
125 126
     rm -rf /tmp/*
126 127
 
127
-    CURR_PROFANITY_COMMIT=$(cat $COMPLETION_FILE | grep "profanity commit" | awk -F ':' '{print $2}')
128
+    CURR_PROFANITY_COMMIT=$(grep "profanity commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
128 129
     if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
129 130
         function_check set_repo_commit
130
-        set_repo_commit $INSTALL_DIR/profanity "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
131
-        cd $INSTALL_DIR/profanity
131
+        set_repo_commit "$INSTALL_DIR/profanity" "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
132
+        cd "$INSTALL_DIR/profanity" || exit 248242684
132 133
         ./bootstrap.sh
133 134
         ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
134 135
         make
135 136
         make install
136 137
     fi
137 138
 
138
-    CURR_PROFANITY_OMEMO_PLUGIN_COMMIT=$(cat $COMPLETION_FILE | grep "profanity omemo plugin commit" | awk -F ':' '{print $2}')
139
+    CURR_PROFANITY_OMEMO_PLUGIN_COMMIT=$(grep "profanity omemo plugin commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
139 140
     if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
140 141
         # upgrade omemo plugins for all users
141
-        set_repo_commit $INSTALL_DIR/profanity-omemo-plugin "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
142
-        cd $INSTALL_DIR/profanity-omemo-plugin
143
-        sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
142
+        set_repo_commit "$INSTALL_DIR/profanity-omemo-plugin" "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
143
+        cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 2468246284
144
+        sed -i 's|python setup.py|python2.7 setup.py|g' "$INSTALL_DIR/profanity-omemo-plugin/install.sh"
144 145
         pip uninstall -y profanity-omemo-plugin
145 146
         ./install.sh
146 147
         for d in /home/*/ ; do
147 148
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
148 149
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
149
-                if [ ! -d /home/$USERNAME/.local/share/profanity/plugins ]; then
150
-                    mkdir -p /home/$USERNAME/.local/share/profanity/plugins
150
+                if [ ! -d "/home/$USERNAME/.local/share/profanity/plugins" ]; then
151
+                    mkdir -p "/home/$USERNAME/.local/share/profanity/plugins"
151 152
                 fi
152
-                if [ -f $INSTALL_DIR/profanity-omemo-plugin/omemo.py ]; then
153
-                    rm $INSTALL_DIR/profanity-omemo-plugin/omemo.*
153
+                if [ -f "$INSTALL_DIR/profanity-omemo-plugin/omemo.py" ]; then
154
+                    rm "$INSTALL_DIR/profanity-omemo-plugin/omemo.*"
154 155
                 fi
155
-                cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$USERNAME/.local/share/profanity/plugins
156
-                chown -R $USERNAME:$USERNAME /home/$USERNAME/.local
156
+                cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/home/$USERNAME/.local/share/profanity/plugins"
157
+                chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.local"
157 158
             fi
158 159
         done
159 160
         if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
160 161
             rm /etc/skel/.local/share/profanity/plugins/omemo.*
161 162
         fi
162
-        cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
163
+        cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/etc/skel/.local/share/profanity/plugins"
163 164
     fi
164 165
 
165 166
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
@@ -183,11 +184,11 @@ function restore_remote_profanity {
183 184
 
184 185
 function remove_profanity {
185 186
     if [ -f /usr/local/bin/profanity ]; then
186
-        cd $INSTALL_DIR/profanity
187
+        cd "$INSTALL_DIR/profanity" || exit 4628462848
187 188
         make uninstall
188 189
 
189 190
         remove_completion_param install_profanity
190
-        sed -i '/profanity/d' $COMPLETION_FILE
191
+        sed -i '/profanity/d' "$COMPLETION_FILE"
191 192
     fi
192 193
 }
193 194
 
@@ -197,8 +198,8 @@ function install_profanity {
197 198
         return
198 199
     fi
199 200
     # install profanity from source in order to get OMEMO support
200
-    if [ ! -d $INSTALL_DIR ]; then
201
-        mkdir -p $INSTALL_DIR
201
+    if [ ! -d "$INSTALL_DIR" ]; then
202
+        mkdir -p "$INSTALL_DIR"
202 203
     fi
203 204
 
204 205
     apt-get -yq install automake autoconf autoconf-archive libtool build-essential
@@ -207,15 +208,15 @@ function install_profanity {
207 208
 
208 209
     # dependency for profanity not available in debian
209 210
     if [ -d /repos/libmesode ]; then
210
-        mkdir $INSTALL_DIR/libmesode
211
-        cp -r -p /repos/libmesode/. $INSTALL_DIR/libmesode
212
-        cd $INSTALL_DIR/libmesode
211
+        mkdir "$INSTALL_DIR/libmesode"
212
+        cp -r -p /repos/libmesode/. "$INSTALL_DIR/libmesode"
213
+        cd "$INSTALL_DIR/libmesode" || exit 46287642846872
213 214
         git pull
214 215
     else
215
-        git_clone $LIBMESODE_REPO $INSTALL_DIR/libmesode
216
+        git_clone "$LIBMESODE_REPO" "$INSTALL_DIR/libmesode"
216 217
     fi
217 218
 
218
-    cd $INSTALL_DIR/libmesode
219
+    cd "$INSTALL_DIR/libmesode" || exit 2468246284
219 220
     git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
220 221
     ./bootstrap.sh
221 222
     ./configure
@@ -225,15 +226,15 @@ function install_profanity {
225 226
 
226 227
     # build profanity
227 228
     if [ -d /repos/profanity ]; then
228
-        mkdir $INSTALL_DIR/profanity
229
-        cp -r -p /repos/profanity/. $INSTALL_DIR/profanity
230
-        cd $INSTALL_DIR/profanity
229
+        mkdir "$INSTALL_DIR/profanity"
230
+        cp -r -p /repos/profanity/. "$INSTALL_DIR/profanity"
231
+        cd "$INSTALL_DIR/profanity" || exit 2468246824
231 232
         git pull
232 233
     else
233
-        git_clone $PROFANITY_REPO $INSTALL_DIR/profanity
234
+        git_clone "$PROFANITY_REPO" "$INSTALL_DIR/profanity"
234 235
     fi
235 236
 
236
-    cd $INSTALL_DIR/profanity
237
+    cd "$INSTALL_DIR/profanity" || exit 54287452858
237 238
     git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
238 239
     ./bootstrap.sh
239 240
     ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
@@ -249,116 +250,116 @@ function install_profanity {
249 250
     apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev
250 251
 
251 252
     if [ -d /repos/profanity-omemo ]; then
252
-        mkdir $INSTALL_DIR/profanity-omemo-plugin
253
-        cp -r -p /repos/profanity-omemo/. $INSTALL_DIR/profanity-omemo-plugin
254
-        cd $INSTALL_DIR/profanity-omemo-plugin
253
+        mkdir "$INSTALL_DIR/profanity-omemo-plugin"
254
+        cp -r -p /repos/profanity-omemo/. "$INSTALL_DIR/profanity-omemo-plugin"
255
+        cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 24682462842
255 256
         git pull
256 257
     else
257
-        git_clone $PROFANITY_OMEMO_PLUGIN_REPO $INSTALL_DIR/profanity-omemo-plugin
258
+        git_clone "$PROFANITY_OMEMO_PLUGIN_REPO" "$INSTALL_DIR/profanity-omemo-plugin"
258 259
     fi
259 260
 
260
-    cd $INSTALL_DIR/profanity-omemo-plugin
261
+    cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 6428468248
261 262
     git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT
262
-    if [ ! -f $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py ]; then
263
+    if [ ! -f "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" ]; then
263 264
         echo $'prof_omemo_plugin.py not found'
264 265
         exit 389225
265 266
     fi
266
-    sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
267
+    sed -i 's|python setup.py|python2.7 setup.py|g' "$INSTALL_DIR/profanity-omemo-plugin/install.sh"
267 268
     ./install.sh
268 269
 
269 270
     mkdir -p /etc/skel/.local/share/profanity/plugins
270
-    cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
271
-    cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$MY_USERNAME/.local/share/profanity/plugins
272
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
271
+    cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" /etc/skel/.local/share/profanity/plugins
272
+    cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" /home/$MY_USERNAME/.local/share/profanity/plugins
273
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.local"
273 274
 
274 275
     XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
275 276
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
276
-    if [ ! -d $XMPP_CLIENT_DIR ]; then
277
-        mkdir -p $XMPP_CLIENT_DIR
277
+    if [ ! -d "$XMPP_CLIENT_DIR" ]; then
278
+        mkdir -p "$XMPP_CLIENT_DIR"
278 279
     fi
279 280
 
280 281
     XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
281
-    MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME")
282
+    #MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME")
282 283
 
283 284
     if [[ $ONION_ONLY == 'no' ]]; then
284
-        echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
285
-        echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
286
-        echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
287
-        echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
288
-        # There is a bug where profanity doesn't refresh the screen
289
-        # after gpg-agent has asked for a password, so for now
290
-        # don't set the gpg key by default
291
-        #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
292
-        echo "pgp.keyid=" >> $XMPP_CLIENT_ACCOUNTS
293
-        echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
294
-        echo "muc.service=chat.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
295
-        echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
296
-        echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
297
-        echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
298
-        echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
299
-        echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
300
-        echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
301
-        echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
302
-        echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
285
+        { echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]";
286
+          echo 'enabled=true';
287
+          echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}";
288
+          echo "server=$XMPP_ONION_HOSTNAME";
289
+          # There is a bug where profanity doesn't refresh the screen
290
+          # after gpg-agent has asked for a password, so for now
291
+          # don't set the gpg key by default
292
+          #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID";
293
+          echo "pgp.keyid=";
294
+          echo 'resource=profanity';
295
+          echo "muc.service=chat.${DEFAULT_DOMAIN_NAME}";
296
+          echo "muc.nick=${MY_USERNAME}";
297
+          echo 'presence.last=online';
298
+          echo 'presence.login=online';
299
+          echo 'priority.online=0';
300
+          echo 'priority.chat=0';
301
+          echo 'priority.away=0';
302
+          echo 'priority.xa=0';
303
+          echo 'priority.dnd=0'; } > "$XMPP_CLIENT_ACCOUNTS"
303 304
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
304
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
305
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
305 306
         fi
306 307
     fi
307 308
 
308 309
     if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
309
-        echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
310
+        echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> "$XMPP_CLIENT_ACCOUNTS"
310 311
         if [[ $ONION_ONLY == 'no' ]]; then
311
-            echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
312
+            echo 'enabled=false' >> "$XMPP_CLIENT_ACCOUNTS"
312 313
         else
313
-            echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
314
+            echo 'enabled=true' >> "$XMPP_CLIENT_ACCOUNTS"
314 315
         fi
315
-        echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
316
-        echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
317
-        # There is a bug where profanity doesn't refresh the screen
318
-        # after gpg-agent has asked for a password, so for now
319
-        # don't set the gpg key by default
320
-        #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
321
-        echo "pgp.keyid=" >> $XMPP_CLIENT_ACCOUNTS
322
-        echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
323
-        echo "muc.service=${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
324
-        echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
325
-        echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
326
-        echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
327
-        echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
328
-        echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
329
-        echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
330
-        echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
331
-        echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
316
+        { echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}";
317
+          echo "server=$XMPP_ONION_HOSTNAME";
318
+          # There is a bug where profanity doesn't refresh the screen
319
+          # after gpg-agent has asked for a password, so for now
320
+          # don't set the gpg key by default
321
+          #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID";
322
+          echo "pgp.keyid=";
323
+          echo 'resource=profanity';
324
+          echo "muc.service=${XMPP_ONION_HOSTNAME}";
325
+          echo "muc.nick=${MY_USERNAME}";
326
+          echo 'presence.last=online';
327
+          echo 'presence.login=online';
328
+          echo 'priority.online=0';
329
+          echo 'priority.chat=0';
330
+          echo 'priority.away=0';
331
+          echo 'priority.xa=0';
332
+          echo 'priority.dnd=0'; } >> "$XMPP_CLIENT_ACCOUNTS"
332 333
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
333
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
334
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
334 335
         fi
335 336
     fi
336 337
 
337
-    if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
338
-        mkdir -p /home/$MY_USERNAME/.config/profanity
338
+    if [ ! -d "/home/$MY_USERNAME/.config/profanity" ]; then
339
+        mkdir -p "/home/$MY_USERNAME/.config/profanity"
339 340
     fi
340
-    echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
341
+    echo '[connection]' > "/home/$MY_USERNAME/.config/profanity/profrc"
341 342
     if [[ $ONION_ONLY == 'no' ]]; then
342
-        echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
343
+        echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc"
343 344
     else
344
-        echo "account=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
345
+        echo "account=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc"
345 346
     fi
346
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
347
-    echo '[plugins]' >> /home/$MY_USERNAME/.config/profanity/profrc
348
-    echo 'load=prof_omemo_plugin.py;' >> /home/$MY_USERNAME/.config/profanity/profrc
349
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
350
-    echo '[otr]' >> /home/$MY_USERNAME/.config/profanity/profrc
351
-    echo 'policy=opportunistic' >> /home/$MY_USERNAME/.config/profanity/profrc
352
-    echo 'log=off' >> /home/$MY_USERNAME/.config/profanity/profrc
353
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
354
-    echo '[pgp]' >> /home/$MY_USERNAME/.config/profanity/profrc
355
-    echo 'log=off' >> /home/$MY_USERNAME/.config/profanity/profrc
356
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
357
-    echo '[ui]' >> /home/$MY_USERNAME/.config/profanity/profrc
358
-    echo 'enc.warn=true' >> /home/$MY_USERNAME/.config/profanity/profrc
359
-
360
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
361
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
347
+    { echo '';
348
+      echo '[plugins]';
349
+      echo 'load=prof_omemo_plugin.py;';
350
+      echo '';
351
+      echo '[otr]';
352
+      echo 'policy=opportunistic';
353
+      echo 'log=off';
354
+      echo '';
355
+      echo '[pgp]';
356
+      echo 'log=off';
357
+      echo '';
358
+      echo '[ui]';
359
+      echo 'enc.warn=true'; } >> "/home/$MY_USERNAME/.config/profanity/profrc"
360
+
361
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.local"
362
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.config"
362 363
 
363 364
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
364 365
     APP_INSTALLED=1

+ 157
- 153
src/freedombone-app-radicale View File

@@ -61,15 +61,15 @@ function logging_off_radicale {
61 61
 function remove_user_radicale {
62 62
     remove_username="$1"
63 63
 
64
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp radicale
64
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp radicale
65 65
 
66 66
     if grep -q "${remove_username}:" ${RADICALE_USERS}; then
67 67
         sed -i "/${remove_username}:/d" ${RADICALE_USERS}
68
-        if [ -d /var/www/radicale/collections/${remove_username} ]; then
69
-            rm -rf /var/www/radicale/collections/${remove_username}
68
+        if [ -d "/var/www/radicale/collections/${remove_username}" ]; then
69
+            rm -rf "/var/www/radicale/collections/${remove_username}"
70 70
         fi
71
-        if [ -f /var/www/radicale/collections/${remove_username}.props ]; then
72
-            rm /var/www/radicale/collections/${remove_username}.props
71
+        if [ -f "/var/www/radicale/collections/${remove_username}.props" ]; then
72
+            rm "/var/www/radicale/collections/${remove_username}.props"
73 73
         fi
74 74
         systemctl restart radicale
75 75
     fi
@@ -79,7 +79,7 @@ function add_user_radicale {
79 79
     new_username="$1"
80 80
     new_user_password="$2"
81 81
 
82
-    ${PROJECT_NAME}-pass -u $new_username -a radicale -p "$new_user_password"
82
+    "${PROJECT_NAME}-pass" -u "$new_username" -a radicale -p "$new_user_password"
83 83
 
84 84
     if [ ! -f ${RADICALE_USERS} ]; then
85 85
         touch ${RADICALE_USERS}
@@ -88,13 +88,13 @@ function add_user_radicale {
88 88
     if ! grep -q "$new_username:" ${RADICALE_USERS}; then
89 89
         htpasswd -bd ${RADICALE_USERS} "$new_username" "$new_user_password"
90 90
 
91
-        echo '{"ICAL:calendar-color": "#9e50df"}' > /var/www/radicale/collections/${new_username}.props
92
-        mkdir /var/www/radicale/collections/${new_username}
93
-        echo '{"ICAL:calendar-color": "#de631a", "tag": "VCALENDAR"}' > /var/www/radicale/collections/${new_username}/calendar.props
94
-        echo 'BEGIN:VCALENDAR' > /var/www/radicale/collections/${new_username}/calendar
95
-        echo 'PRODID:-//Radicale//NONSGML Radicale Server//EN' >> /var/www/radicale/collections/${new_username}/calendar
96
-        echo 'VERSION:2.0' >> /var/www/radicale/collections/${new_username}/calendar
97
-        echo 'END:VCALENDAR' >> /var/www/radicale/collections/${new_username}/calendar
91
+        echo '{"ICAL:calendar-color": "#9e50df"}' > "/var/www/radicale/collections/${new_username}.props"
92
+        mkdir "/var/www/radicale/collections/${new_username}"
93
+        echo '{"ICAL:calendar-color": "#de631a", "tag": "VCALENDAR"}' > "/var/www/radicale/collections/${new_username}/calendar.props"
94
+        { echo 'BEGIN:VCALENDAR';
95
+          echo 'PRODID:-//Radicale//NONSGML Radicale Server//EN';
96
+          echo 'VERSION:2.0';
97
+          echo 'END:VCALENDAR'; } >> "/var/www/radicale/collections/${new_username}/calendar"
98 98
 
99 99
         chown -R www-data:www-data /var/www/radicale
100 100
         chmod -R 755 /var/www/radicale/*
@@ -107,7 +107,7 @@ function change_password_radicale {
107 107
     existing_username="$1"
108 108
     new_user_password="$2"
109 109
 
110
-    ${PROJECT_NAME}-pass -u $existing_username -a radicale -p "$new_user_password"
110
+    "${PROJECT_NAME}-pass" -u "$existing_username" -a radicale -p "$new_user_password"
111 111
 
112 112
     if grep -q "${existing_username}:" ${RADICALE_USERS}; then
113 113
         sed -i "/${existing_username}:/d" ${RADICALE_USERS}
@@ -127,14 +127,14 @@ function reconfigure_radicale {
127 127
     rm -rf /var/log/radicale/*
128 128
 
129 129
     # create an admin password
130
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
131
-        RADICALE_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
130
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
131
+        RADICALE_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
132 132
     else
133
-        RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
133
+        RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
134 134
     fi
135 135
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
136 136
 
137
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a radicale -p "$RADICALE_PASSWORD"
137
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a radicale -p "$RADICALE_PASSWORD"
138 138
 
139 139
     touch /var/log/radicale/radicale.log
140 140
     chown -R www-data:www-data /var/log/radicale
@@ -145,7 +145,7 @@ function upgrade_radicale {
145 145
         return
146 146
     fi
147 147
 
148
-    if ! grep -q "radicale version:" $COMPLETION_FILE; then
148
+    if ! grep -q "radicale version:" "$COMPLETION_FILE"; then
149 149
         return
150 150
     fi
151 151
 
@@ -155,7 +155,7 @@ function upgrade_radicale {
155 155
     fi
156 156
 
157 157
     # get the source
158
-    cd /var/www/radicale
158
+    cd /var/www/radicale || exit 62784628468
159 159
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
160 160
 
161 161
     # check the hash
@@ -170,7 +170,7 @@ function upgrade_radicale {
170 170
         exit 73529
171 171
     fi
172 172
     rm Radicale-${RADICALE_VERSION}.tar.gz
173
-    cd Radicale-${RADICALE_VERSION}
173
+    cd "Radicale-${RADICALE_VERSION}" || exit 264824684
174 174
 
175 175
     # move the old command
176 176
     mv /usr/local/bin/radicale /usr/local/bin/radicale_previous
@@ -186,9 +186,9 @@ function upgrade_radicale {
186 186
     fi
187 187
 
188 188
     # remove the old source
189
-    rm -rf Radicale-${CURR_RADICALE_VERSION}
189
+    rm -rf "Radicale-${CURR_RADICALE_VERSION}" || exit 6842684282
190 190
 
191
-    sed -i "s|radicale version.*|radicale version:$RADICALE_VERSION|g" ${COMPLETION_FILE}
191
+    sed -i "s|radicale version.*|radicale version:$RADICALE_VERSION|g" "${COMPLETION_FILE}"
192 192
     chown -R www-data:www-data /var/www/radicale
193 193
     systemctl restart radicale
194 194
     systemctl restart nginx
@@ -219,6 +219,7 @@ function restore_local_radicale {
219 219
         else
220 220
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
221 221
         fi
222
+        # shellcheck disable=SC2181
222 223
         if [ ! "$?" = "0" ]; then
223 224
             function_check backup_unmount_drive
224 225
             backup_unmount_drive
@@ -233,6 +234,7 @@ function restore_local_radicale {
233 234
         else
234 235
             cp -r $temp_restore_dir/* /var/www/radicale/*
235 236
         fi
237
+        # shellcheck disable=SC2181
236 238
         if [ ! "$?" = "0" ]; then
237 239
             function_check backup_unmount_drive
238 240
             backup_unmount_drive
@@ -264,6 +266,7 @@ function restore_remote_radicale {
264 266
         else
265 267
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
266 268
         fi
269
+        # shellcheck disable=SC2181
267 270
         if [ ! "$?" = "0" ]; then
268 271
             exit 236746
269 272
         fi
@@ -276,6 +279,7 @@ function restore_remote_radicale {
276 279
         else
277 280
             cp -r $temp_restore_dir/* /var/www/radicale
278 281
         fi
282
+        # shellcheck disable=SC2181
279 283
         if [ ! "$?" = "0" ]; then
280 284
             exit 3674284
281 285
         fi
@@ -332,17 +336,17 @@ function remove_radicale {
332 336
     fi
333 337
 
334 338
     remove_completion_param install_radicale
335
-    sed -i '/radicale/d' $COMPLETION_FILE
336
-    sed -i '/# Start radicale/,/# End radicale/d' /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
339
+    sed -i '/radicale/d' "$COMPLETION_FILE"
340
+    sed -i '/# Start radicale/,/# End radicale/d' "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
337 341
     systemctl restart nginx
338 342
 }
339 343
 
340 344
 function install_radicale {
341 345
     if [[ $ONION_ONLY == 'no' ]]; then
342 346
         # obtain a cert for the default domain
343
-        if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "0" ]]; then
347
+        if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}" pem)" == "0" ]]; then
344 348
             echo $'Obtaining certificate for the main domain'
345
-            create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
349
+            create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
346 350
         fi
347 351
     fi
348 352
 
@@ -368,7 +372,7 @@ function install_radicale {
368 372
     fi
369 373
 
370 374
     # get the source
371
-    cd /var/www/radicale
375
+    cd /var/www/radicale || exit 462874628
372 376
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
373 377
 
374 378
     # check the hash
@@ -383,7 +387,7 @@ function install_radicale {
383 387
         exit 623252
384 388
     fi
385 389
     rm Radicale-${RADICALE_VERSION}.tar.gz
386
-    cd Radicale-${RADICALE_VERSION}
390
+    cd "Radicale-${RADICALE_VERSION}" || exit 872462842
387 391
     python setup.py install
388 392
     if [ ! -f /usr/local/bin/radicale ]; then
389 393
         echo $'Radicale did not install'
@@ -398,52 +402,52 @@ function install_radicale {
398 402
     fi
399 403
 
400 404
     # create the configuration
401
-    echo '[server]' >  ${RADICALE_DIRECTORY}/config
402
-    echo 'hosts=localhost:52322' >> ${RADICALE_DIRECTORY}/config
403
-    echo 'ssl = False' >> ${RADICALE_DIRECTORY}/config
404
-    echo 'daemon = False' >> ${RADICALE_DIRECTORY}/config
405
-    echo 'base_prefix=/radicale/' >> ${RADICALE_DIRECTORY}/config
406
-    echo '' >> ${RADICALE_DIRECTORY}/config
407
-    echo '[storage]' >> ${RADICALE_DIRECTORY}/config
408
-    echo 'type = filesystem' >> ${RADICALE_DIRECTORY}/config
409
-    echo "filesystem_folder = /var/www/radicale/collections" >> ${RADICALE_DIRECTORY}/config
410
-    echo '' >> ${RADICALE_DIRECTORY}/config
411
-    echo '[well-known]' >> ${RADICALE_DIRECTORY}/config
412
-    echo "caldav = '/%(user)s/caldav/'" >> ${RADICALE_DIRECTORY}/config
413
-    echo "carddav = '/%(user)s/carddav/'" >> ${RADICALE_DIRECTORY}/config
414
-    echo '' >> ${RADICALE_DIRECTORY}/config
415
-    echo '#[auth]' >> ${RADICALE_DIRECTORY}/config
416
-    echo '#imap_hostname = localhost' >> ${RADICALE_DIRECTORY}/config
417
-    echo '#imap_port = 143' >> ${RADICALE_DIRECTORY}/config
418
-    echo '#imap_ssl = False' >> ${RADICALE_DIRECTORY}/config
419
-    echo '' >> ${RADICALE_DIRECTORY}/config
420
-    echo '[logging]' >> ${RADICALE_DIRECTORY}/config
421
-    echo 'debug = False' >> ${RADICALE_DIRECTORY}/config
405
+    { echo '[server]';
406
+      echo 'hosts=localhost:52322';
407
+      echo 'ssl = False';
408
+      echo 'daemon = False';
409
+      echo 'base_prefix=/radicale/';
410
+      echo '';
411
+      echo '[storage]';
412
+      echo 'type = filesystem';
413
+      echo "filesystem_folder = /var/www/radicale/collections";
414
+      echo '';
415
+      echo '[well-known]';
416
+      echo "caldav = '/%(user)s/caldav/'";
417
+      echo "carddav = '/%(user)s/carddav/'";
418
+      echo '';
419
+      echo '#[auth]';
420
+      echo '#imap_hostname = localhost';
421
+      echo '#imap_port = 143';
422
+      echo '#imap_ssl = False';
423
+      echo '';
424
+      echo '[logging]';
425
+      echo 'debug = False'; } > "${RADICALE_DIRECTORY}/config"
422 426
 
423 427
     # create an admin password
424 428
     if [ ${#RADICALE_PASSWORD} -lt 8 ]; then
425
-        if [ -f $IMAGE_PASSWORD_FILE ]; then
426
-            RADICALE_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
429
+        if [ -f "$IMAGE_PASSWORD_FILE" ]; then
430
+            RADICALE_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
427 431
         else
428
-            RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
432
+            RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
429 433
         fi
430 434
     fi
431 435
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
432 436
 
433
-    echo '[Unit]' > /etc/systemd/system/radicale.service
434
-    echo 'Description=Radicale CalDAV Server' >> /etc/systemd/system/radicale.service
435
-    echo 'After=network.target' >> /etc/systemd/system/radicale.service
436
-    echo '' >> /etc/systemd/system/radicale.service
437
-    echo '[Service]' >> /etc/systemd/system/radicale.service
438
-    echo 'Type=simple' >> /etc/systemd/system/radicale.service
439
-    echo 'User=www-data' >> /etc/systemd/system/radicale.service
440
-    echo 'Group=www-data' >> /etc/systemd/system/radicale.service
441
-    echo "ExecStart=/usr/local/bin/radicale --config ${RADICALE_DIRECTORY}/config" >> /etc/systemd/system/radicale.service
442
-    echo 'Restart=on-failure' >> /etc/systemd/system/radicale.service
443
-    echo 'RestartSec=10' >> /etc/systemd/system/radicale.service
444
-    echo '' >> /etc/systemd/system/radicale.service
445
-    echo '[Install]' >> /etc/systemd/system/radicale.service
446
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/radicale.service
437
+    { echo '[Unit]';
438
+      echo 'Description=Radicale CalDAV Server';
439
+      echo 'After=network.target';
440
+      echo '';
441
+      echo '[Service]';
442
+      echo 'Type=simple';
443
+      echo 'User=www-data';
444
+      echo 'Group=www-data';
445
+      echo "ExecStart=/usr/local/bin/radicale --config ${RADICALE_DIRECTORY}/config";
446
+      echo 'Restart=on-failure';
447
+      echo 'RestartSec=10';
448
+      echo '';
449
+      echo '[Install]';
450
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/radicale.service
447 451
 
448 452
     addresses_str=$"Addresses"
449 453
     echo "{\"tag\": \"VADDRESSBOOK\", \"D:displayname\": \"${addresses_str}\"}" > /var/www/radicale/collections/addresses.props
@@ -461,107 +465,107 @@ function install_radicale {
461 465
     systemctl enable radicale
462 466
     systemctl start radicale
463 467
 
464
-    if [ ! -f /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME} ]; then
468
+    if [ ! -f "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}" ]; then
465 469
         # create a new site config
466 470
         RADICALE_ONION_HOSTNAME=$(add_onion_service radicale 80 ${RADICALE_ONION_PORT})
467 471
 
468 472
         if [[ $ONION_ONLY == 'no' ]]; then
469
-            echo 'server {' > /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
470
-            echo "    listen 443 ssl;" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
471
-            echo "    #listen [::]:443 ssl;" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
472
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
473
+            { echo 'server {';
474
+              echo "    listen 443 ssl;";
475
+              echo "    #listen [::]:443 ssl;";
476
+              echo ''; } > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
473 477
             function_check nginx_ssl
474
-            nginx_ssl ${DEFAULT_DOMAIN_NAME} mobile
478
+            nginx_ssl "${DEFAULT_DOMAIN_NAME}" mobile
475 479
             function_check nginx_disable_sniffing
476
-            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
477
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
478
-            echo "    server_name ${DEFAULT_DOMAIN_NAME};" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
479
-
480
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
481
-            echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
482
-            echo '    error_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
483
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
484
-            echo '    # Start radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
485
-            echo '    location @radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
486
-            echo '        auth_basic "Radicale";' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
487
-            echo '        auth_basic_user_file /var/www/radicale/users;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
488
-            echo '        proxy_pass http://localhost:52322;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
489
-            echo '        proxy_buffering off;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
490
-            echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
491
-            echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
492
-            echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
493
-            echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
494
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
495
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
496
-            echo '    location /radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
497
-            echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
498
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
499
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
500
-            echo '    location /.well-known/carddav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
501
-            echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
502
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
503
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
504
-            echo '    location /.well-known/caldav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
505
-            echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
506
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
507
-            echo '    # End radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
508
-            echo '}' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
509
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
480
+            nginx_disable_sniffing "${DEFAULT_DOMAIN_NAME}"
481
+            { echo '';
482
+              echo "    server_name ${DEFAULT_DOMAIN_NAME};";
483
+
484
+              echo '';
485
+              echo '    access_log /dev/null;';
486
+              echo '    error_log /dev/null;';
487
+              echo '';
488
+              echo '    # Start radicale';
489
+              echo '    location @radicale {';
490
+              echo '        auth_basic "Radicale";';
491
+              echo '        auth_basic_user_file /var/www/radicale/users;';
492
+              echo '        proxy_pass http://localhost:52322;';
493
+              echo '        proxy_buffering off;';
494
+              echo "        proxy_set_header Host \$host;";
495
+              echo "        proxy_set_header X-Real-IP \$remote_addr;";
496
+              echo "        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
497
+              echo "        proxy_set_header X-Forwarded-Proto \$scheme;";
498
+              echo '    }';
499
+              echo '';
500
+              echo '    location /radicale {';
501
+              echo "        try_files \$uri @radicale;";
502
+              echo '    }';
503
+              echo '';
504
+              echo '    location /.well-known/carddav {';
505
+              echo "        try_files \$uri @radicale;";
506
+              echo '    }';
507
+              echo '';
508
+              echo '    location /.well-known/caldav {';
509
+              echo "        try_files \$uri @radicale;";
510
+              echo '    }';
511
+              echo '    # End radicale';
512
+              echo '}';
513
+              echo ''; } >> "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
510 514
         else
511
-            echo -n '' > /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
515
+            echo -n '' > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
512 516
         fi
513
-        echo 'server {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
514
-        echo "    listen localhost:${RADICALE_ONION_PORT} default_server;" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
515
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
516
-        echo "    server_name ${RADICALE_ONION_HOSTNAME};" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
517
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
518
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
519
-        echo '    error_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
520
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
521
-        echo '    # Start radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
522
-        echo '    location @radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
523
-        echo '        auth_basic "Radicale";' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
524
-        echo '        auth_basic_user_file /var/www/radicale/users;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
525
-        echo '        proxy_pass http://localhost:52322;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
526
-        echo '        proxy_buffering off;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
527
-        echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
528
-        echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
529
-        echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
530
-        echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
531
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
532
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
533
-        echo '    location /radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
534
-        echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
535
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
536
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
537
-        echo '    location /.well-known/carddav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
538
-        echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
539
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
540
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
541
-        echo '    location /.well-known/caldav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
542
-        echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
543
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
544
-        echo '    # End radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
545
-        echo '}' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
517
+        { echo 'server {';
518
+          echo "    listen localhost:${RADICALE_ONION_PORT} default_server;";
519
+          echo '';
520
+          echo "    server_name ${RADICALE_ONION_HOSTNAME};";
521
+          echo '';
522
+          echo '    access_log /dev/null;';
523
+          echo '    error_log /dev/null;';
524
+          echo '';
525
+          echo '    # Start radicale';
526
+          echo '    location @radicale {';
527
+          echo '        auth_basic "Radicale";';
528
+          echo '        auth_basic_user_file /var/www/radicale/users;';
529
+          echo '        proxy_pass http://localhost:52322;';
530
+          echo '        proxy_buffering off;';
531
+          echo "        proxy_set_header Host \$host;";
532
+          echo "        proxy_set_header X-Real-IP \$remote_addr;";
533
+          echo "        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
534
+          echo "        proxy_set_header X-Forwarded-Proto \$scheme;";
535
+          echo '    }';
536
+          echo '';
537
+          echo '    location /radicale {';
538
+          echo "        try_files \$uri @radicale;";
539
+          echo '    }';
540
+          echo '';
541
+          echo '    location /.well-known/carddav {';
542
+          echo "        try_files \$uri @radicale;";
543
+          echo '    }';
544
+          echo '';
545
+          echo '    location /.well-known/caldav {';
546
+          echo "        try_files \$uri @radicale;";
547
+          echo '    }';
548
+          echo '    # End radicale';
549
+          echo '}'; } >> "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
546 550
 
547 551
         set_completion_param "radicale onion domain" "${RADICALE_ONION_HOSTNAME}"
548 552
     else
549 553
         # alter the existing site config
550
-        if ! grep -q "# Start radicale" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}; then
551
-            sed -i '/]:443/a    # Start radicale\n  location @radicale {\n    auth_basic "Radicale";\n    auth_basic_user_file \/var\/www\/radicale\/users;\n    proxy_pass http:\/\/localhost:52322;\n    proxy_buffering off;\n    proxy_set_header Host $host;\n    proxy_set_header X-Real-IP $remote_addr;\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header X-Forwarded-Proto $scheme;\n  }\n\n  location \/radicale {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/carddav {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/caldav {\n      try_files $uri @radicale;\n  }\n  # End radicale' /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
552
-            sed -i '/listen localhost/a    # Start radicale\n  location @radicale {\n    auth_basic "Radicale";\n    auth_basic_user_file \/var\/www\/radicale\/users;\n    proxy_pass http:\/\/localhost:52322;\n    proxy_buffering off;\n    proxy_set_header Host $host;\n    proxy_set_header X-Real-IP $remote_addr;\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header X-Forwarded-Proto $scheme;\n  }\n\n  location \/radicale {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/carddav {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/caldav {\n      try_files $uri @radicale;\n  }\n  # End radicale' /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
554
+        if ! grep -q "# Start radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"; then
555
+            sed -i "/]:443/a    # Start radicale\\n  location @radicale {\\n    auth_basic \"Radicale\";\\n    auth_basic_user_file \\/var\\/www\\/radicale\\/users;\\n    proxy_pass http:\\/\\/localhost:52322;\\n    proxy_buffering off;\\n    proxy_set_header Host $host;\\n    proxy_set_header X-Real-IP $remote_addr;\\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\\n    proxy_set_header X-Forwarded-Proto $scheme;\\n  }\\n\\n  location \\/radicale {\\n      try_files $uri @radicale;\\n  }\n\n  location \\/.well-known\\/carddav {\\n      try_files $uri @radicale;\\n  }\\n\\n  location \\/.well-known\\/caldav {\\n      try_files $uri @radicale;\\n  }\n  # End radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
556
+            sed -i "/listen localhost/a    # Start radicale\\n  location @radicale {\\n    auth_basic \"Radicale\";\\n    auth_basic_user_file \\/var\\/www\\/radicale\\/users;\\n    proxy_pass http:\\/\\/localhost:52322;\\n    proxy_buffering off;\\n    proxy_set_header Host $host;\\n    proxy_set_header X-Real-IP $remote_addr;\\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\\n    proxy_set_header X-Forwarded-Proto $scheme;\\n  }\\n\\n  location \/radicale {\\n      try_files $uri @radicale;\\n  }\\n\\n  location \\/.well-known\\/carddav {\\n      try_files $uri @radicale;\\n  }\\n\\n  location \\/.well-known\\/caldav {\\n      try_files $uri @radicale;\\n  }\\n  # End radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
553 557
         fi
554 558
     fi
555 559
 
556 560
     # create a certificate
557
-    if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
558
-        if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt ]; then
559
-            ${PROJECT_NAME}-addcert -h $DEFAULT_DOMAIN_NAME --dhkey ${DH_KEYLENGTH}
560
-            check_certificates $DEFAULT_DOMAIN_NAME
561
+    if [ ! -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
562
+        if [ ! -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
563
+            "${PROJECT_NAME}-addcert" -h "$DEFAULT_DOMAIN_NAME" --dhkey "${DH_KEYLENGTH}"
564
+            check_certificates "$DEFAULT_DOMAIN_NAME"
561 565
         fi
562 566
     fi
563 567
 
564
-    if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
568
+    if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
565 569
         sed -i "s|radicale.crt|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
566 570
         sed -i "s|radicale.pem|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
567 571
     fi
@@ -572,13 +576,13 @@ function install_radicale {
572 576
 
573 577
     systemctl restart nginx
574 578
 
575
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a radicale -p "$RADICALE_PASSWORD"
579
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a radicale -p "$RADICALE_PASSWORD"
576 580
 
577 581
     # keep track of the version so we can check for upgrades
578
-    if ! grep -q "radicale version:" ${COMPLETION_FILE}; then
579
-        echo "radicale version:${RADICALE_VERSION}" >> ${COMPLETION_FILE}
582
+    if ! grep -q "radicale version:" "${COMPLETION_FILE}"; then
583
+        echo "radicale version:${RADICALE_VERSION}" >> "${COMPLETION_FILE}"
580 584
     else
581
-        sed -i "s|radicale version.*|radicale version:${RADICALE_VERSION}|g" ${COMPLETION_FILE}
585
+        sed -i "s|radicale version.*|radicale version:${RADICALE_VERSION}|g" "${COMPLETION_FILE}"
582 586
     fi
583 587
 
584 588
     APP_INSTALLED=1

+ 89
- 87
src/freedombone-app-riot View File

@@ -76,39 +76,40 @@ function install_interactive_riot {
76 76
         RIOT_DETAILS_COMPLETE=
77 77
         while [ ! $RIOT_DETAILS_COMPLETE ]
78 78
         do
79
-            data=$(tempfile 2>/dev/null)
80
-            trap "rm -f $data" 0 1 2 5 15
79
+            data=$(mktemp 2>/dev/null)
81 80
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
82 81
                 dialog --backtitle $"Freedombone Configuration" \
83 82
                        --title $"Riot Web user interface for Matrix" \
84
-                       --form $"\nPlease enter your details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
83
+                       --form $"\\nPlease enter your details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
85 84
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
86 85
                        $"Code:" 2 1 "$(grep 'RIOT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
87
-                       2> $data
86
+                       2> "$data"
88 87
             else
89 88
                 dialog --backtitle $"Freedombone Configuration" \
90 89
                        --title $"Riot Web user interface for Matrix" \
91
-                       --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 \
90
+                       --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 \
92 91
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
93
-                       2> $data
92
+                       2> "$data"
94 93
             fi
95 94
             sel=$?
96 95
             case $sel in
97
-                1) exit 1;;
98
-                255) exit 1;;
96
+                1) rm -f "$data"
97
+                   exit 1;;
98
+                255) rm -f "$data"
99
+                     exit 1;;
99 100
             esac
100
-            RIOT_DOMAIN_NAME=$(cat $data | sed -n 1p)
101
-            if [ $RIOT_DOMAIN_NAME ]; then
101
+            RIOT_DOMAIN_NAME=$(sed -n 1p < "$data")
102
+            if [ "$RIOT_DOMAIN_NAME" ]; then
102 103
                 TEST_DOMAIN_NAME=$RIOT_DOMAIN_NAME
103 104
                 validate_domain_name
104
-                if [[ $TEST_DOMAIN_NAME != $RIOT_DOMAIN_NAME ]]; then
105
+                if [[ "$TEST_DOMAIN_NAME" != "$RIOT_DOMAIN_NAME" ]]; then
105 106
                     RIOT_DOMAIN_NAME=
106 107
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
107 108
                 else
108 109
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
109
-                        RIOT_CODE=$(cat $data | sed -n 2p)
110
+                        RIOT_CODE=$(sed -n 2p < "$data")
110 111
                         validate_freedns_code "$RIOT_CODE"
111
-                        if [ ! $VALID_CODE ]; then
112
+                        if [ ! "$VALID_CODE" ]; then
112 113
                             RIOT_DOMAIN_NAME=
113 114
                         fi
114 115
                     fi
@@ -117,6 +118,7 @@ function install_interactive_riot {
117 118
             if [ $RIOT_DOMAIN_NAME ]; then
118 119
                 RIOT_DETAILS_COMPLETE="yes"
119 120
             fi
121
+            rm -f "$data"
120 122
         done
121 123
 
122 124
         # save the results in the config file
@@ -132,14 +134,14 @@ function reconfigure_riot {
132 134
 
133 135
 function riot_download {
134 136
     # download
135
-    if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
136
-        wget ${RIOT_DOWNLOAD_URL}/${RIOT_FILENAME}.tar.gz -O $INSTALL_DIR/${RIOT_FILENAME}.tar.gz
137
+    if [ ! -f "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz" ]; then
138
+        wget "${RIOT_DOWNLOAD_URL}/${RIOT_FILENAME}.tar.gz" -O "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz"
137 139
     fi
138
-    if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
140
+    if [ ! -f "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz" ]; then
139 141
         echo $'Unable to download Riot Web from releases'
140 142
         exit 62836
141 143
     fi
142
-    cd $INSTALL_DIR
144
+    cd "$INSTALL_DIR" || exit 2468724628
143 145
 
144 146
     # check the hash
145 147
     curr_hash=$(sha256sum ${RIOT_FILENAME}.tar.gz | awk -F ' ' '{print $1}')
@@ -149,17 +151,17 @@ function riot_download {
149 151
     fi
150 152
 
151 153
     tar -xzvf ${RIOT_FILENAME}.tar.gz
152
-    if [ ! -d $INSTALL_DIR/${RIOT_FILENAME} ]; then
154
+    if [ ! -d "$INSTALL_DIR/${RIOT_FILENAME}" ]; then
153 155
         echo $'Unable to extract Riot Web tarball'
154 156
         exit 542826
155 157
     fi
156
-    cp -r $INSTALL_DIR/${RIOT_FILENAME}/* /var/www/$RIOT_DOMAIN_NAME/htdocs
158
+    cp -r "$INSTALL_DIR/${RIOT_FILENAME}/*" "/var/www/$RIOT_DOMAIN_NAME/htdocs"
157 159
 
158
-    chown -R www-data:www-data /var/www/$RIOT_DOMAIN_NAME/htdocs
160
+    chown -R www-data:www-data "/var/www/$RIOT_DOMAIN_NAME/htdocs"
159 161
 }
160 162
 
161 163
 function upgrade_riot {
162
-    if ! grep -q 'riot version:' $COMPLETION_FILE; then
164
+    if ! grep -q 'riot version:' "$COMPLETION_FILE"; then
163 165
         return
164 166
     fi
165 167
 
@@ -171,7 +173,7 @@ function upgrade_riot {
171 173
     fi
172 174
 
173 175
     riot_download
174
-    sed -i "s|riot version.*|riot version:$RIOT_VERSION|g" ${COMPLETION_FILE}
176
+    sed -i "s|riot version.*|riot version:$RIOT_VERSION|g" "${COMPLETION_FILE}"
175 177
     riot_remove_bad_links
176 178
 
177 179
     systemctl restart nginx
@@ -207,7 +209,7 @@ function remove_riot {
207 209
     fi
208 210
 
209 211
     remove_completion_param install_riot
210
-    sed -i '/riot /d' $COMPLETION_FILE
212
+    sed -i '/riot /d' "$COMPLETION_FILE"
211 213
 }
212 214
 
213 215
 function install_riot {
@@ -216,7 +218,7 @@ function install_riot {
216 218
     fi
217 219
 
218 220
     # check that matrix has been installed
219
-    if [ ! $MATRIX_DOMAIN_NAME ]; then
221
+    if [ ! "$MATRIX_DOMAIN_NAME" ]; then
220 222
         exit 687292
221 223
     fi
222 224
     if [[ "$MATRIX_DOMAIN_NAME" != *'.'* ]]; then
@@ -235,32 +237,32 @@ function install_riot {
235 237
         mkdir -p /var/www/$RIOT_DOMAIN_NAME/htdocs
236 238
     fi
237 239
 
238
-    if [ ! -d $INSTALL_DIR ]; then
239
-        mkdir $INSTALL_DIR
240
+    if [ ! -d "$INSTALL_DIR" ]; then
241
+        mkdir "$INSTALL_DIR"
240 242
     fi
241 243
 
242 244
     riot_download
243 245
 
244
-    cd /var/www/$RIOT_DOMAIN_NAME/htdocs
246
+    cd "/var/www/$RIOT_DOMAIN_NAME/htdocs" || exit 4628462876
245 247
 
246
-    if [[ $ONION_ONLY == 'no' ]]; then
248
+    if [[ "$ONION_ONLY" == 'no' ]]; then
247 249
         riot_config_file="config.${RIOT_DOMAIN_NAME}.json"
248 250
         cp config.sample.json $riot_config_file
249
-        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" $riot_config_file
250
-        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" $riot_config_file
251
-        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"https://${MATRIX_DOMAIN_NAME}/bugs\",|g" $riot_config_file
252
-        sed -i "/\"servers\":/a \"${MATRIX_DOMAIN_NAME}\"," $riot_config_file
251
+        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" "$riot_config_file"
252
+        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" "$riot_config_file"
253
+        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"https://${MATRIX_DOMAIN_NAME}/bugs\",|g" "$riot_config_file"
254
+        sed -i "/\"servers\":/a \"${MATRIX_DOMAIN_NAME}\"," "$riot_config_file"
253 255
     else
254 256
         riot_config_file="config.${MATRIX_ONION_DOMAIN_NAME}.json"
255
-        cp config.sample.json $riot_config_file
256
-        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" $riot_config_file
257
-        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" $riot_config_file
258
-        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}/bugs\",|g" $riot_config_file
259
-        sed -i "/\"servers\":/a \"${MATRIX_ONION_DOMAIN_NAME}\"," $riot_config_file
257
+        cp config.sample.json "$riot_config_file"
258
+        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" "$riot_config_file"
259
+        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" "$riot_config_file"
260
+        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}/bugs\",|g" "$riot_config_file"
261
+        sed -i "/\"servers\":/a \"${MATRIX_ONION_DOMAIN_NAME}\"," "$riot_config_file"
260 262
     fi
261
-    sed -i "s|\"integrations_ui_url\":.*|\"integrations_ui_url\": \"\",|g" $riot_config_file
262
-    sed -i "s|\"integrations_rest_url\":.*|\"integrations_rest_url\": \"\",|g" $riot_config_file
263
-    sed -i 's|https://piwik.riot.im/||g' $riot_config_file
263
+    sed -i "s|\"integrations_ui_url\":.*|\"integrations_ui_url\": \"\",|g" "$riot_config_file"
264
+    sed -i "s|\"integrations_rest_url\":.*|\"integrations_rest_url\": \"\",|g" "$riot_config_file"
265
+    sed -i 's|https://piwik.riot.im/||g' "$riot_config_file"
264 266
 
265 267
     RIOT_ONION_HOSTNAME=$(add_onion_service riot 80 ${RIOT_ONION_PORT})
266 268
 
@@ -268,68 +270,68 @@ function install_riot {
268 270
     if [[ $ONION_ONLY == "no" ]]; then
269 271
         function_check nginx_http_redirect
270 272
         nginx_http_redirect $RIOT_DOMAIN_NAME
271
-        echo 'server {' >> $riot_nginx_site
272
-        echo '  listen 443 ssl;' >> $riot_nginx_site
273
-        echo '  #listen [::]:443 ssl;' >> $riot_nginx_site
274
-        echo "  server_name $RIOT_DOMAIN_NAME;" >> $riot_nginx_site
275
-        echo '' >> $riot_nginx_site
276
-        echo '  # Security' >> $riot_nginx_site
273
+        { echo 'server {';
274
+          echo '  listen 443 ssl;';
275
+          echo '  #listen [::]:443 ssl;';
276
+          echo "  server_name $RIOT_DOMAIN_NAME;";
277
+          echo '';
278
+          echo '  # Security'; } >> $riot_nginx_site
277 279
         function_check nginx_ssl
278 280
         nginx_ssl $RIOT_DOMAIN_NAME
279 281
 
280 282
         function_check nginx_disable_sniffing
281 283
         nginx_disable_sniffing $RIOT_DOMAIN_NAME
282 284
 
283
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $riot_nginx_site
284
-        echo '' >> $riot_nginx_site
285
-        echo '  # Logs' >> $riot_nginx_site
286
-        echo '  access_log /dev/null;' >> $riot_nginx_site
287
-        echo '  error_log /dev/null;' >> $riot_nginx_site
288
-        echo '' >> $riot_nginx_site
289
-        echo '  # Root' >> $riot_nginx_site
290
-        echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;" >> $riot_nginx_site
291
-        echo '' >> $riot_nginx_site
292
-        echo '  index index.html;' >> $riot_nginx_site
293
-        echo '' >> $riot_nginx_site
294
-        echo '  location / {' >> $riot_nginx_site
285
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
286
+          echo '';
287
+          echo '  # Logs';
288
+          echo '  access_log /dev/null;';
289
+          echo '  error_log /dev/null;';
290
+          echo '';
291
+          echo '  # Root';
292
+          echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;";
293
+          echo '';
294
+          echo '  index index.html;';
295
+          echo '';
296
+          echo '  location / {'; } >> $riot_nginx_site
295 297
         function_check nginx_limits
296 298
         nginx_limits $RIOT_DOMAIN_NAME '15m'
297
-        echo '  }' >> $riot_nginx_site
298
-        echo '}' >> $riot_nginx_site
299
-        echo '' >> $riot_nginx_site
299
+        { echo '  }';
300
+          echo '}';
301
+          echo ''; } >> $riot_nginx_site
300 302
     else
301 303
         echo -n '' > $riot_nginx_site
302 304
     fi
303
-    echo 'server {' >> $riot_nginx_site
304
-    echo "    listen 127.0.0.1:$RIOT_ONION_PORT default_server;" >> $riot_nginx_site
305
-    echo "    server_name $RIOT_ONION_HOSTNAME;" >> $riot_nginx_site
306
-    echo '' >> $riot_nginx_site
305
+    { echo 'server {';
306
+      echo "    listen 127.0.0.1:$RIOT_ONION_PORT default_server;";
307
+      echo "    server_name $RIOT_ONION_HOSTNAME;";
308
+      echo ''; } >> $riot_nginx_site
307 309
     function_check nginx_disable_sniffing
308 310
     nginx_disable_sniffing $RIOT_DOMAIN_NAME
309
-    echo '' >> $riot_nginx_site
310
-    echo '  # Logs' >> $riot_nginx_site
311
-    echo '  access_log /dev/null;' >> $riot_nginx_site
312
-    echo '  error_log /dev/null;' >> $riot_nginx_site
313
-    echo '' >> $riot_nginx_site
314
-    echo '  # Root' >> $riot_nginx_site
315
-    echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;" >> $riot_nginx_site
316
-    echo '' >> $riot_nginx_site
317
-    echo '  index index.html;' >> $riot_nginx_site
318
-    echo '' >> $riot_nginx_site
319
-    echo '  location / {' >> $riot_nginx_site
311
+    { echo '';
312
+      echo '  # Logs';
313
+      echo '  access_log /dev/null;';
314
+      echo '  error_log /dev/null;';
315
+      echo '';
316
+      echo '  # Root';
317
+      echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;";
318
+      echo '';
319
+      echo '  index index.html;';
320
+      echo '';
321
+      echo '  location / {'; } >> $riot_nginx_site
320 322
     function_check nginx_limits
321 323
     nginx_limits $RIOT_DOMAIN_NAME '15m'
322
-    echo '  }' >> $riot_nginx_site
323
-    echo '}' >> $riot_nginx_site
324
+    echo '  }' >> "$riot_nginx_site"
325
+    echo '}' >> "$riot_nginx_site"
324 326
 
325
-    sed '/Content-Security-Policy/d' $riot_nginx_site
326
-    sed -i 's| DENY;| SAMEORIGIN;|g' $riot_nginx_site
327
-    sed -i 's|limit_conn conn_limit_per_ip.*|limit_conn conn_limit_per_ip 50;|g' $riot_nginx_site
328
-    sed -i 's|limit_req zone.*|limit_req zone=req_limit_per_ip burst=20 nodelay;|g' $riot_nginx_site
327
+    sed '/Content-Security-Policy/d' "$riot_nginx_site"
328
+    sed -i 's| DENY;| SAMEORIGIN;|g' "$riot_nginx_site"
329
+    sed -i 's|limit_conn conn_limit_per_ip.*|limit_conn conn_limit_per_ip 50;|g' "$riot_nginx_site"
330
+    sed -i 's|limit_req zone.*|limit_req zone=req_limit_per_ip burst=20 nodelay;|g' "$riot_nginx_site"
329 331
 
330 332
     function_check create_site_certificate
331
-    if [ ! -f /etc/ssl/certs/${RIOT_DOMAIN_NAME}.pem ]; then
332
-        create_site_certificate $RIOT_DOMAIN_NAME 'yes'
333
+    if [ ! -f "/etc/ssl/certs/${RIOT_DOMAIN_NAME}.pem" ]; then
334
+        create_site_certificate "$RIOT_DOMAIN_NAME" 'yes'
333 335
     fi
334 336
 
335 337
     function_check nginx_ensite
@@ -344,10 +346,10 @@ function install_riot {
344 346
     systemctl restart nginx
345 347
 
346 348
     set_completion_param "riot domain" "$RIOT_DOMAIN_NAME"
347
-    if ! grep -q "riot version:" ${COMPLETION_FILE}; then
348
-        echo "riot version:${RIOT_VERSION}" >> ${COMPLETION_FILE}
349
+    if ! grep -q "riot version:" "${COMPLETION_FILE}"; then
350
+        echo "riot version:${RIOT_VERSION}" >> "${COMPLETION_FILE}"
349 351
     else
350
-        sed -i "s|riot version.*|riot version:${RIOT_VERSION}|g" ${COMPLETION_FILE}
352
+        sed -i "s|riot version.*|riot version:${RIOT_VERSION}|g" "${COMPLETION_FILE}"
351 353
     fi
352 354
     APP_INSTALLED=1
353 355
 }

+ 196
- 192
src/freedombone-app-rss View File

@@ -62,12 +62,13 @@ function logging_off_rss {
62 62
 }
63 63
 
64 64
 function remove_user_rss {
65
-    remove_username="$1"
65
+    echo -n ''
66
+#    remove_username="$1"
66 67
 }
67 68
 
68 69
 function add_user_rss {
69
-    new_username="$1"
70
-    new_user_password="$2"
70
+#    new_username="$1"
71
+#    new_user_password="$2"
71 72
     echo '0'
72 73
 }
73 74
 
@@ -77,26 +78,27 @@ function install_interactive_rss {
77 78
 }
78 79
 
79 80
 function change_password_rss {
80
-    curr_username="$1"
81
-    new_user_password="$2"
81
+    echo -n ''
82
+#    curr_username="$1"
83
+#    new_user_password="$2"
82 84
 
83 85
     #${PROJECT_NAME}-pass -u "$curr_username" -a rss -p "$new_user_password"
84 86
 }
85 87
 
86 88
 function rss_create_database {
87
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
88
-        RSS_READER_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
89
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
90
+        RSS_READER_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
89 91
     else
90
-        if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
91
-            RSS_READER_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
92
+        if [ ! "$RSS_READER_ADMIN_PASSWORD" ]; then
93
+            RSS_READER_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
92 94
         fi
93 95
     fi
94
-    if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
96
+    if [ ! "$RSS_READER_ADMIN_PASSWORD" ]; then
95 97
         return
96 98
     fi
97 99
 
98 100
     function_check create_database
99
-    create_database ttrss "$RSS_READER_ADMIN_PASSWORD" $MY_USERNAME
101
+    create_database ttrss "$RSS_READER_ADMIN_PASSWORD" "$MY_USERNAME"
100 102
 }
101 103
 
102 104
 function reconfigure_rss {
@@ -131,8 +133,8 @@ function upgrade_rss {
131 133
         # remove any previous install
132 134
         if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
133 135
             if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
134
-                sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
135
-                sed -i '/rss mobile reader commit/d' $COMPLETION_FILE
136
+                sed -i '/install_rss_mobile_reader/d' "$COMPLETION_FILE"
137
+                sed -i '/rss mobile reader commit/d' "$COMPLETION_FILE"
136 138
                 rm -rf $RSS_READER_PATH/g2ttree-mobile
137 139
             fi
138 140
         fi
@@ -184,6 +186,7 @@ function restore_local_rss {
184 186
                 fi
185 187
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
186 188
             fi
189
+            # shellcheck disable=SC2181
187 190
             if [ ! "$?" = "0" ]; then
188 191
                 function_check set_user_permissions
189 192
                 set_user_permissions
@@ -207,14 +210,14 @@ function restore_local_rss {
207 210
     function_check rss_modifications
208 211
     rss_modifications
209 212
 
210
-    if [ -d $USB_MOUNT/backup/ttrss ]; then
213
+    if [ -d "$USB_MOUNT/backup/ttrss" ]; then
211 214
         chown -R www-data:www-data /etc/share/tt-rss
212 215
         if [ -d $temp_restore_dir ]; then
213 216
             rm -rf $temp_restore_dir
214 217
         fi
215 218
     fi
216 219
 
217
-    MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
220
+    MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
218 221
     sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
219 222
     MARIADB_PASSWORD=
220 223
 }
@@ -245,7 +248,7 @@ function backup_remote_rss {
245 248
 
246 249
 function restore_remote_rss {
247 250
     temp_restore_dir=/root/tempttrss
248
-    if grep -q "rss reader domain" $COMPLETION_FILE; then
251
+    if grep -q "rss reader domain" "$COMPLETION_FILE"; then
249 252
         echo $"Restoring ttrss"
250 253
         function_check get_mariadb_password
251 254
         get_mariadb_password
@@ -263,6 +266,7 @@ function restore_remote_rss {
263 266
                 fi
264 267
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
265 268
             fi
269
+            # shellcheck disable=SC2181
266 270
             if [ ! "$?" = "0" ]; then
267 271
                 exit 6391
268 272
             fi
@@ -280,14 +284,14 @@ function restore_remote_rss {
280 284
         function_check rss_modifications
281 285
         rss_modifications
282 286
 
283
-        if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
287
+        if [ -d "$SERVER_DIRECTORY/backup/ttrss" ]; then
284 288
             chown -R www-data:www-data /etc/share/tt-rss
285 289
         fi
286 290
         if [ -d /root/tempttrss ]; then
287 291
             rm -rf /root/tempttrss
288 292
         fi
289 293
 
290
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
294
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
291 295
         sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
292 296
         MARIADB_PASSWORD=
293 297
 
@@ -313,9 +317,9 @@ function remove_rss {
313 317
     function_check drop_database
314 318
     drop_database ttrss
315 319
     remove_completion_param install_rss
316
-    sed -i '/RSS /d' $COMPLETION_FILE
317
-    sed -i '/rss /d' $COMPLETION_FILE
318
-    sed -i '/rss_/d' $COMPLETION_FILE
320
+    sed -i '/RSS /d' "$COMPLETION_FILE"
321
+    sed -i '/rss /d' "$COMPLETION_FILE"
322
+    sed -i '/rss_/d' "$COMPLETION_FILE"
319 323
     remove_backup_database_local ttrss
320 324
 }
321 325
 
@@ -329,15 +333,15 @@ function rss_modifications {
329 333
 
330 334
     # ensure that socks5 proxy is used
331 335
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/plugins/af_unburn/init.php; then
332
-        sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/plugins/af_unburn/init.php
336
+        sed -i "/curl_setopt(\$ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\\\t\\t\\t\\t\\tcurl_setopt(\$ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);" "$RSS_READER_PATH/plugins/af_unburn/init.php"
333 337
         rss_modified=1
334 338
     fi
335 339
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/include/functions.php; then
336
-        sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/include/functions.php
340
+        sed -i "/curl_setopt(\$ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\\\t\\t\\t\\tcurl_setopt(\$ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);" "$RSS_READER_PATH/include/functions.php"
337 341
         rss_modified=1
338 342
     fi
339 343
     if [ $rss_modified ]; then
340
-        cd $RSS_READER_PATH
344
+        cd $RSS_READER_PATH || exit 564286428
341 345
         git commit -a -m"Modify for Tor proxying"
342 346
     fi
343 347
     chown -R www-data:www-data $RSS_READER_PATH
@@ -358,12 +362,12 @@ function install_rss_main {
358 362
     if [ ! -d /etc/share ]; then
359 363
         mkdir /etc/share
360 364
     fi
361
-    cd /etc/share
365
+    cd /etc/share || exit 46284628
362 366
 
363 367
     if [ -d /repos/rss ]; then
364 368
         mkdir tt-rss
365 369
         cp -r -p /repos/rss/. tt-rss
366
-        cd tt-rss
370
+        cd tt-rss || exit 462846822
367 371
         git pull
368 372
     else
369 373
         function_check git_clone
@@ -374,7 +378,7 @@ function install_rss_main {
374 378
         echo $'Could not clone RSS reader repo'
375 379
         exit 52925
376 380
     fi
377
-    cd $RSS_READER_PATH
381
+    cd $RSS_READER_PATH || exit 42479825792593
378 382
     git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
379 383
     set_completion_param "rss reader commit" "$RSS_READER_COMMIT"
380 384
 
@@ -397,151 +401,151 @@ function install_rss_main {
397 401
     USE_V2_ONION_ADDRESS=1
398 402
     RSS_MOBILE_READER_ONION_HOSTNAME=$(add_onion_service mobilerss 80 ${RSS_MOBILE_READER_ONION_PORT})
399 403
 
400
-    echo 'server {' > /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
401
-    echo "  listen 127.0.0.1:$RSS_MOBILE_READER_ONION_PORT;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
402
-    echo "  server_name $RSS_MOBILE_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
403
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
404
-    echo '  access_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
405
-    echo '  error_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
406
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
407
-    echo '  root /etc/share/ttrss-mobile;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
408
-    echo '  index index.html index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
409
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
410
-    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
411
-    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
412
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
413
-    echo '    fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
414
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
415
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
416
-    echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
417
-    echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
418
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
419
-    echo '  location /tt-rss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
420
-    echo '    try_files $uri $uri/ @ttrss_base;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
421
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
422
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
423
-    echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
424
-    echo '    rewrite ^(.*)$ /index.html?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
425
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
426
-    echo '  location @ttrss_base {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
427
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
428
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
429
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
430
-    echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
431
-    echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
432
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
433
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
434
-    echo '  add_header X-XSS-Protection "1; mode=block";' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
435
-    echo '  add_header X-Robots-Tag none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
436
-    echo '  add_header X-Download-Options noopen;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
437
-    echo '  add_header X-Permitted-Cross-Domain-Policies none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
438
-    echo '  add_header X-Frame-Options SAMEORIGIN;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
439
-    echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
440
-    echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
441
-    echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
442
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
443
-    echo 'server {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
444
-    echo "  listen 127.0.0.1:$RSS_READER_ONION_PORT default_server;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
445
-    echo "  server_name $RSS_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
446
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
447
-    echo '  access_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
448
-    echo '  error_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
449
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
450
-    echo '  root /etc/share/tt-rss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
451
-    echo '  index index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
452
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
453
-    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
454
-    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
455
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
456
-    echo '    fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
457
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
458
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
459
-    echo '  set $mobile_rewrite do_not_perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
460
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
461
-    echo '  ## chi http_user_agent for mobile / smart phones ##' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
462
-    echo '  if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
463
-    echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
464
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
465
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
466
-    echo '  if ($http_user_agent ~* "^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-)") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
467
-    echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
468
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
469
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
470
-    echo '  if ($mobile_rewrite = perform) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
471
-    echo "    rewrite ^/(.*) http://$RSS_MOBILE_READER_ONION_HOSTNAME permanent;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
472
-    echo '    break;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
473
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
474
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
475
-    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
476
-    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
477
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
478
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
479
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
480
-    echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
481
-    echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
482
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
483
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
484
-    echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
485
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
486
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
487
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
488
-    echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
489
-    echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
490
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
491
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
492
-    echo '  add_header X-XSS-Protection "1; mode=block";' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
493
-    echo '  add_header X-Robots-Tag none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
494
-    echo '  add_header X-Download-Options noopen;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
495
-    echo '  add_header X-Permitted-Cross-Domain-Policies none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
496
-    echo '  add_header X-Frame-Options SAMEORIGIN;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
497
-    echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
498
-    echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
499
-    echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
404
+    { echo 'server {';
405
+      echo "  listen 127.0.0.1:$RSS_MOBILE_READER_ONION_PORT;";
406
+      echo "  server_name $RSS_MOBILE_READER_ONION_HOSTNAME;";
407
+      echo '';
408
+      echo '  access_log /dev/null;';
409
+      echo '  error_log /dev/null;';
410
+      echo '';
411
+      echo '  root /etc/share/ttrss-mobile;';
412
+      echo '  index index.html index.php;';
413
+      echo '';
414
+      echo '  location ~ \.php {';
415
+      echo '    include snippets/fastcgi-php.conf;';
416
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
417
+      echo '    fastcgi_read_timeout 30;';
418
+      echo '  }';
419
+      echo '';
420
+      echo '  location / {';
421
+      echo "    try_files \$uri \$uri/ @ttrss;";
422
+      echo '  }';
423
+      echo '  location /tt-rss {';
424
+      echo "    try_files \$uri \$uri/ @ttrss_base;";
425
+      echo '  }';
426
+      echo '';
427
+      echo '  location @ttrss {';
428
+      echo "    rewrite ^(.*)\$ /index.html?p=\$1 last;";
429
+      echo '  }';
430
+      echo '  location @ttrss_base {';
431
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
432
+      echo '  }';
433
+      echo '';
434
+      echo '  location ~ /\.(git) {';
435
+      echo '    deny all;';
436
+      echo '  }';
437
+      echo '';
438
+      echo '  add_header X-XSS-Protection "1; mode=block";';
439
+      echo '  add_header X-Robots-Tag none;';
440
+      echo '  add_header X-Download-Options noopen;';
441
+      echo '  add_header X-Permitted-Cross-Domain-Policies none;';
442
+      echo '  add_header X-Frame-Options SAMEORIGIN;';
443
+      echo '  add_header X-Content-Type-Options nosniff;';
444
+      echo '  client_max_body_size 15m;';
445
+      echo '}';
446
+      echo '';
447
+      echo 'server {';
448
+      echo "  listen 127.0.0.1:$RSS_READER_ONION_PORT default_server;";
449
+      echo "  server_name $RSS_READER_ONION_HOSTNAME;";
450
+      echo '';
451
+      echo '  access_log /dev/null;';
452
+      echo '  error_log /dev/null;';
453
+      echo '';
454
+      echo '  root /etc/share/tt-rss;';
455
+      echo '  index index.php;';
456
+      echo '';
457
+      echo '  location ~ \.php {';
458
+      echo '    include snippets/fastcgi-php.conf;';
459
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
460
+      echo '    fastcgi_read_timeout 30;';
461
+      echo '  }';
462
+      echo '';
463
+      echo "  set \$mobile_rewrite do_not_perform;";
464
+      echo '';
465
+      echo '  ## chi http_user_agent for mobile / smart phones ##';
466
+      echo "  if (\$http_user_agent ~* \"(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino\") {";
467
+      echo "    set \$mobile_rewrite perform;";
468
+      echo '  }';
469
+      echo '';
470
+      echo "  if (\$http_user_agent ~* \"^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-)\") {";
471
+      echo "    set \$mobile_rewrite perform;";
472
+      echo '  }';
473
+      echo '';
474
+      echo "  if (\$mobile_rewrite = perform) {";
475
+      echo "    rewrite ^/(.*) http://$RSS_MOBILE_READER_ONION_HOSTNAME permanent;";
476
+      echo '    break;';
477
+      echo '  }';
478
+      echo '';
479
+      echo '  location ~ \.php {';
480
+      echo '    include snippets/fastcgi-php.conf;';
481
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
482
+      echo '  }';
483
+      echo '';
484
+      echo '  location / {';
485
+      echo "    try_files \$uri \$uri/ @ttrss;";
486
+      echo '  }';
487
+      echo '';
488
+      echo '  location @ttrss {';
489
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
490
+      echo '  }';
491
+      echo '';
492
+      echo '  location ~ /\.(git) {';
493
+      echo '    deny all;';
494
+      echo '  }';
495
+      echo '';
496
+      echo '  add_header X-XSS-Protection "1; mode=block";';
497
+      echo '  add_header X-Robots-Tag none;';
498
+      echo '  add_header X-Download-Options noopen;';
499
+      echo '  add_header X-Permitted-Cross-Domain-Policies none;';
500
+      echo '  add_header X-Frame-Options SAMEORIGIN;';
501
+      echo '  add_header X-Content-Type-Options nosniff;';
502
+      echo '  client_max_body_size 15m;';
503
+      echo '}'; } > "/etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME"
500 504
 
501 505
     if [ ! -f $RSS_READER_PATH/config.php ]; then
502 506
         # generate a config file
503 507
         RSS_FEED_CRYPT_KEY="$(create_password 24)"
504
-        echo '<?php' > $RSS_READER_PATH/config.php
505
-        echo "  define('_CURL_HTTP_PROXY', '127.0.0.1:9050');" >> $RSS_READER_PATH/config.php
506
-        echo "  define('DB_TYPE', 'mysql');" >> $RSS_READER_PATH/config.php
507
-        echo "  define('DB_HOST', 'localhost');" >> $RSS_READER_PATH/config.php
508
-        echo "  define('DB_USER', 'root');" >> $RSS_READER_PATH/config.php
509
-        echo "  define('DB_NAME', 'ttrss');" >> $RSS_READER_PATH/config.php
510
-        echo "  define('DB_PASS', '${MARIADB_PASSWORD}');" >> $RSS_READER_PATH/config.php
511
-        echo "  define('DB_PORT', '3306');" >> $RSS_READER_PATH/config.php
512
-        echo "  define('MYSQL_CHARSET', 'UTF8');" >> $RSS_READER_PATH/config.php
513
-        echo "  define('SELF_URL_PATH', 'http://${RSS_READER_ONION_HOSTNAME}/');" >> $RSS_READER_PATH/config.php
514
-        echo "  define('FEED_CRYPT_KEY', '${RSS_FEED_CRYPT_KEY}');" >> $RSS_READER_PATH/config.php
515
-        echo "  define('SINGLE_USER_MODE', false);" >> $RSS_READER_PATH/config.php
516
-        echo "  define('SIMPLE_UPDATE_MODE', false);" >> $RSS_READER_PATH/config.php
517
-        echo "  define('PHP_EXECUTABLE', '/usr/bin/php');" >> $RSS_READER_PATH/config.php
518
-        echo "  define('LOCK_DIRECTORY', 'lock');" >> $RSS_READER_PATH/config.php
519
-        echo "  define('CACHE_DIR', 'cache');" >> $RSS_READER_PATH/config.php
520
-        echo "  define('ICONS_DIR', \"feed-icons\");" >> $RSS_READER_PATH/config.php
521
-        echo "  define('ICONS_URL', \"feed-icons\");" >> $RSS_READER_PATH/config.php
522
-        echo "  define('AUTH_AUTO_CREATE', true);" >> $RSS_READER_PATH/config.php
523
-        echo "  define('AUTH_AUTO_LOGIN', true);" >> $RSS_READER_PATH/config.php
524
-        echo "  define('FORCE_ARTICLE_PURGE', 0);" >> $RSS_READER_PATH/config.php
525
-        echo "  define('PUBSUBHUBBUB_HUB', '');" >> $RSS_READER_PATH/config.php
526
-        echo "  define('PUBSUBHUBBUB_ENABLED', false);" >> $RSS_READER_PATH/config.php
527
-        echo "  define('SPHINX_SERVER', 'localhost:9312');" >> $RSS_READER_PATH/config.php
528
-        echo "  define('SPHINX_INDEX', 'ttrss, delta');" >> $RSS_READER_PATH/config.php
529
-        echo "  define('ENABLE_REGISTRATION', false);" >> $RSS_READER_PATH/config.php
530
-        echo "  define('REG_NOTIFY_ADDRESS', '${MY_EMAIL_ADDRESS}');" >> $RSS_READER_PATH/config.php
531
-        echo "  define('REG_MAX_USERS', 10);" >> $RSS_READER_PATH/config.php
532
-        echo "  define('SESSION_COOKIE_LIFETIME', 86400);" >> $RSS_READER_PATH/config.php
533
-        echo "  define('SMTP_FROM_NAME', 'Tiny Tiny RSS');" >> $RSS_READER_PATH/config.php
534
-        echo "  define('SMTP_FROM_ADDRESS', 'noreply@${RSS_READER_ONION_HOSTNAME}');" >> $RSS_READER_PATH/config.php
535
-        echo "  define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');" >> $RSS_READER_PATH/config.php
536
-        echo "  define('SMTP_SERVER', '');" >> $RSS_READER_PATH/config.php
537
-        echo "  define('SMTP_LOGIN', '');" >> $RSS_READER_PATH/config.php
538
-        echo "  define('SMTP_PASSWORD', '');" >> $RSS_READER_PATH/config.php
539
-        echo "  define('SMTP_SECURE', '');" >> $RSS_READER_PATH/config.php
540
-        echo "  define('CHECK_FOR_UPDATES', false);" >> $RSS_READER_PATH/config.php
541
-        echo "  define('ENABLE_GZIP_OUTPUT', false);" >> $RSS_READER_PATH/config.php
542
-        echo "  define('PLUGINS', 'auth_internal, note, gnusocial');" >> $RSS_READER_PATH/config.php
543
-        echo "  define('LOG_DESTINATION', 'sql');" >> $RSS_READER_PATH/config.php
544
-        echo "  define('CONFIG_VERSION', 26);" >> $RSS_READER_PATH/config.php
508
+        { echo '<?php';
509
+          echo "  define('_CURL_HTTP_PROXY', '127.0.0.1:9050');";
510
+          echo "  define('DB_TYPE', 'mysql');";
511
+          echo "  define('DB_HOST', 'localhost');";
512
+          echo "  define('DB_USER', 'root');";
513
+          echo "  define('DB_NAME', 'ttrss');";
514
+          echo "  define('DB_PASS', '${MARIADB_PASSWORD}');";
515
+          echo "  define('DB_PORT', '3306');";
516
+          echo "  define('MYSQL_CHARSET', 'UTF8');";
517
+          echo "  define('SELF_URL_PATH', 'http://${RSS_READER_ONION_HOSTNAME}/');";
518
+          echo "  define('FEED_CRYPT_KEY', '${RSS_FEED_CRYPT_KEY}');";
519
+          echo "  define('SINGLE_USER_MODE', false);";
520
+          echo "  define('SIMPLE_UPDATE_MODE', false);";
521
+          echo "  define('PHP_EXECUTABLE', '/usr/bin/php');";
522
+          echo "  define('LOCK_DIRECTORY', 'lock');";
523
+          echo "  define('CACHE_DIR', 'cache');";
524
+          echo "  define('ICONS_DIR', \"feed-icons\");";
525
+          echo "  define('ICONS_URL', \"feed-icons\");";
526
+          echo "  define('AUTH_AUTO_CREATE', true);";
527
+          echo "  define('AUTH_AUTO_LOGIN', true);";
528
+          echo "  define('FORCE_ARTICLE_PURGE', 0);";
529
+          echo "  define('PUBSUBHUBBUB_HUB', '');";
530
+          echo "  define('PUBSUBHUBBUB_ENABLED', false);";
531
+          echo "  define('SPHINX_SERVER', 'localhost:9312');";
532
+          echo "  define('SPHINX_INDEX', 'ttrss, delta');";
533
+          echo "  define('ENABLE_REGISTRATION', false);";
534
+          echo "  define('REG_NOTIFY_ADDRESS', '${MY_EMAIL_ADDRESS}');";
535
+          echo "  define('REG_MAX_USERS', 10);";
536
+          echo "  define('SESSION_COOKIE_LIFETIME', 86400);";
537
+          echo "  define('SMTP_FROM_NAME', 'Tiny Tiny RSS');";
538
+          echo "  define('SMTP_FROM_ADDRESS', 'noreply@${RSS_READER_ONION_HOSTNAME}');";
539
+          echo "  define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');";
540
+          echo "  define('SMTP_SERVER', '');";
541
+          echo "  define('SMTP_LOGIN', '');";
542
+          echo "  define('SMTP_PASSWORD', '');";
543
+          echo "  define('SMTP_SECURE', '');";
544
+          echo "  define('CHECK_FOR_UPDATES', false);";
545
+          echo "  define('ENABLE_GZIP_OUTPUT', false);";
546
+          echo "  define('PLUGINS', 'auth_internal, note, gnusocial');";
547
+          echo "  define('LOG_DESTINATION', 'sql');";
548
+          echo "  define('CONFIG_VERSION', 26);"; } > $RSS_READER_PATH/config.php
545 549
     fi
546 550
 
547 551
     # initialize the database
@@ -569,28 +573,28 @@ function install_rss_main {
569 573
     systemctl restart nginx
570 574
 
571 575
     # daemon to update feeds
572
-    echo '[Unit]' > /etc/systemd/system/ttrss.service
573
-    echo 'Description=ttrss_backend' >> /etc/systemd/system/ttrss.service
574
-    echo 'After=network.target mariadb.service' >> /etc/systemd/system/ttrss.service
575
-    echo 'After=tor.service' >> /etc/systemd/system/ttrss.service
576
-    echo '' >> /etc/systemd/system/ttrss.service
577
-    echo '[Service]' >> /etc/systemd/system/ttrss.service
578
-    echo 'User=www-data' >> /etc/systemd/system/ttrss.service
579
-    echo "ExecStart=/usr/bin/php $RSS_READER_PATH/update.php --daemon" >> /etc/systemd/system/ttrss.service
580
-    echo '' >> /etc/systemd/system/ttrss.service
581
-    echo '[Install]' >> /etc/systemd/system/ttrss.service
582
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ttrss.service
576
+    { echo '[Unit]';
577
+      echo 'Description=ttrss_backend';
578
+      echo 'After=network.target mariadb.service';
579
+      echo 'After=tor.service';
580
+      echo '';
581
+      echo '[Service]';
582
+      echo 'User=www-data';
583
+      echo "ExecStart=/usr/bin/php $RSS_READER_PATH/update.php --daemon";
584
+      echo '';
585
+      echo '[Install]';
586
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/ttrss.service
583 587
     systemctl enable ttrss
584 588
     systemctl daemon-reload
585 589
     systemctl start ttrss
586 590
 
587
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a rss -p "$RSS_READER_ADMIN_PASSWORD"
591
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a rss -p "$RSS_READER_ADMIN_PASSWORD"
588 592
 
589 593
     install_completed rss_main
590 594
 }
591 595
 
592 596
 function install_rss_gnusocial {
593
-    if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
597
+    if [ ! "$GNUSOCIAL_DOMAIN_NAME" ]; then
594 598
         return
595 599
     fi
596 600
 
@@ -608,19 +612,19 @@ function install_rss_gnusocial {
608 612
         return
609 613
     fi
610 614
 
611
-    if [ ! -d $INSTALL_DIR ]; then
612
-        mkdir -p $INSTALL_DIR
615
+    if [ ! -d "$INSTALL_DIR" ]; then
616
+        mkdir -p "$INSTALL_DIR"
613 617
     fi
614 618
 
615
-    cd $INSTALL_DIR
619
+    cd "$INSTALL_DIR" || exit 7246284
616 620
     function_check git_clone
617 621
     git_clone $RSS_READER_GNUSOCIAL_REPO ttrss-gnusocial
618
-    if [ ! -d $INSTALL_DIR/ttrss-gnusocial ]; then
622
+    if [ ! -d "$INSTALL_DIR/ttrss-gnusocial" ]; then
619 623
         echo $'Could not clone repo for RSS reader gnusocial plugin'
620 624
         exit 52838
621 625
     fi
622
-    cp -r $INSTALL_DIR/ttrss-gnusocial $RSS_READER_GNUSOCIAL_PATH
623
-    cd $RSS_READER_GNUSOCIAL_PATH
626
+    cp -r "$INSTALL_DIR/ttrss-gnusocial" $RSS_READER_GNUSOCIAL_PATH
627
+    cd "$RSS_READER_GNUSOCIAL_PATH" || exit 782462424
624 628
     git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
625 629
     set_completion_param "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT"
626 630
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
@@ -642,8 +646,8 @@ function install_rss_mobile_reader {
642 646
     # remove any previous install
643 647
     if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
644 648
         if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
645
-            sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
646
-            sed -i '/rss mobile reader commit/d' $COMPLETION_FILE
649
+            sed -i '/install_rss_mobile_reader/d' "$COMPLETION_FILE"
650
+            sed -i '/rss mobile reader commit/d' "$COMPLETION_FILE"
647 651
             rm -rf $RSS_READER_PATH/g2ttree-mobile
648 652
         fi
649 653
     fi
@@ -652,12 +656,12 @@ function install_rss_mobile_reader {
652 656
         return
653 657
     fi
654 658
 
655
-    cd /etc/share
659
+    cd /etc/share || exit 7498264462
656 660
 
657 661
     if [ -d /repos/rss-mobile ]; then
658 662
         mkdir ttrss-mobile
659 663
         cp -r -p /repos/rss-mobile/. ttrss-mobile
660
-        cd ttrss-mobile
664
+        cd ttrss-mobile || exit 462846284682
661 665
         git pull
662 666
     else
663 667
         function_check git_clone
@@ -668,7 +672,7 @@ function install_rss_mobile_reader {
668 672
         echo $'Could not clone RSS mobile reader repo'
669 673
         exit 24816
670 674
     fi
671
-    cd $RSS_MOBILE_READER_PATH
675
+    cd "$RSS_MOBILE_READER_PATH" || exit 462846246824
672 676
     git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
673 677
     set_completion_param "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT"
674 678
 

+ 173
- 168
src/freedombone-app-scuttlebot View File

@@ -61,39 +61,44 @@ function scuttlebot_create_invite {
61 61
     invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
62 62
 
63 63
     clear
64
-    echo -e '\n\nYour Scuttlebot invite code is:\n\n'${invite_string}'\n\n'
64
+    echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${invite_string}\\n\\n"
65
+    # shellcheck disable=SC2034
65 66
     read -n1 -r -p $"Press any key to continue..." key
66 67
 }
67 68
 
68 69
 function configure_interactive_scuttlebot {
69 70
     while true
70 71
     do
71
-        data=$(tempfile 2>/dev/null)
72
-        trap "rm -f $data" 0 1 2 5 15
72
+        data=$(mktemp 2>/dev/null)
73 73
         dialog --backtitle $"Freedombone Control Panel" \
74 74
                --title $"Scuttlebot" \
75 75
                --radiolist $"Choose an operation:" 10 50 2 \
76 76
                1 $"Create an invite" off \
77
-               2 $"Exit" on 2> $data
77
+               2 $"Exit" on 2> "$data"
78 78
         sel=$?
79 79
         case $sel in
80
-            1) return;;
81
-            255) return;;
80
+            1) rm -f "$data"
81
+               return;;
82
+            255) rm -f "$data"
83
+                 return;;
82 84
         esac
83
-        case $(cat $data) in
85
+        case $(cat "$data") in
84 86
             1) scuttlebot_create_invite;;
85
-            2) break;;
87
+            2) rm -f "$data"
88
+               break;;
86 89
         esac
90
+        rm -f "$data"
87 91
     done
88 92
 }
89 93
 
90 94
 function remove_user_scuttlebot {
91
-    remove_username="$1"
95
+    echo -n ''
96
+#    remove_username="$1"
92 97
 }
93 98
 
94 99
 function add_user_scuttlebot {
95
-    new_username="$1"
96
-    new_user_password="$2"
100
+#    new_username="$1"
101
+#    new_user_password="$2"
97 102
     echo '0'
98 103
 }
99 104
 
@@ -109,8 +114,8 @@ function install_interactive_scuttlebot {
109 114
 }
110 115
 
111 116
 function change_password_scuttlebot {
112
-    new_username="$1"
113
-    new_user_password="$2"
117
+#    new_username="$1"
118
+#    new_user_password="$2"
114 119
     echo '0'
115 120
 }
116 121
 
@@ -123,7 +128,7 @@ function reconfigure_scuttlebot {
123 128
 }
124 129
 
125 130
 function upgrade_scuttlebot {
126
-    if ! grep -q 'scuttlebot version:' $COMPLETION_FILE; then
131
+    if ! grep -q 'scuttlebot version:' $"COMPLETION_FILE"; then
127 132
         return
128 133
     fi
129 134
 
@@ -134,11 +139,10 @@ function upgrade_scuttlebot {
134 139
         return
135 140
     fi
136 141
 
137
-    npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save
138
-    if [ ! "$?" = "0" ]; then
142
+    if ! npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save; then
139 143
         return
140 144
     fi
141
-    sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
145
+    sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
142 146
 }
143 147
 
144 148
 function backup_local_scuttlebot {
@@ -218,71 +222,72 @@ function remove_scuttlebot {
218 222
     fi
219 223
 
220 224
     remove_completion_param install_scuttlebot
221
-    sed -i '/scuttlebot /d' $COMPLETION_FILE
225
+    sed -i '/scuttlebot /d' "$COMPLETION_FILE"
222 226
 }
223 227
 
224 228
 function git_ssb_script {
225 229
     if [[ "$1" == "mesh" ]]; then
230
+        # shellcheck disable=SC2154
226 231
         git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
227 232
         git_ssb_daemon_filename=$rootdir/etc/systemd/system/git_ssb.service
228 233
     else
229 234
         git_ssb_script_name=/usr/bin/git-ssb-create
230 235
         git_ssb_daemon_filename=/etc/systemd/system/git_ssb.service
231 236
     fi
232
-    echo '#!/bin/bash' > $git_ssb_script_name
233
-    echo 'reponame="$1"' >> $git_ssb_script_name
234
-    echo '' >> $git_ssb_script_name
235
-    echo 'if [[ "$reponame" != "" ]]; then' >> $git_ssb_script_name
236
-    echo '  mkdir $reponame' >> $git_ssb_script_name
237
-    echo '  cd $reponame' >> $git_ssb_script_name
238
-    echo '  git init' >> $git_ssb_script_name
239
-    echo '  git ssb create ssb $reponame' >> $git_ssb_script_name
240
-    echo '  git push --tags ssb master' >> $git_ssb_script_name
241
-    echo 'fi' >> $git_ssb_script_name
242
-    echo 'exit 0' >> $git_ssb_script_name
237
+    { echo '#!/bin/bash';
238
+      echo "reponame=\"\$1\"";
239
+      echo '';
240
+      echo "if [[ \"\$reponame\" != \"\" ]]; then";
241
+      echo "  mkdir \$reponame";
242
+      echo "  cd \$reponame";
243
+      echo '  git init';
244
+      echo "  git ssb create ssb \$reponame";
245
+      echo '  git push --tags ssb master';
246
+      echo 'fi';
247
+      echo 'exit 0'; } > $git_ssb_script_name
243 248
     chmod +x $git_ssb_script_name
244 249
 
245
-    echo '[Unit]' > $git_ssb_daemon_filename
246
-    echo 'Description=Git SSB (SSB git web interface)' >> $git_ssb_daemon_filename
247
-    echo 'After=syslog.target' >> $git_ssb_daemon_filename
248
-    echo 'After=network.target' >> $git_ssb_daemon_filename
249
-    echo 'After=scuttlebot.target' >> $git_ssb_daemon_filename
250
-    echo '' >> $git_ssb_daemon_filename
251
-    echo '[Service]' >> $git_ssb_daemon_filename
252
-    echo 'Type=simple' >> $git_ssb_daemon_filename
253
-    echo 'User=scuttlebot' >> $git_ssb_daemon_filename
254
-    echo 'Group=scuttlebot' >> $git_ssb_daemon_filename
255
-    echo "WorkingDirectory=/etc/scuttlebot" >> $git_ssb_daemon_filename
256
-    echo "ExecStart=/usr/bin/git ssb web --public localhost:$GIT_SSB_PORT" >> $git_ssb_daemon_filename
257
-    echo 'Restart=always' >> $git_ssb_daemon_filename
258
-    echo 'Environment="USER=scuttlebot"' >> $git_ssb_daemon_filename
259
-    echo '' >> $git_ssb_daemon_filename
260
-    echo '[Install]' >> $git_ssb_daemon_filename
261
-    echo 'WantedBy=multi-user.target' >> $git_ssb_daemon_filename
250
+    { echo '[Unit]';
251
+      echo 'Description=Git SSB (SSB git web interface)';
252
+      echo 'After=syslog.target';
253
+      echo 'After=network.target';
254
+      echo 'After=scuttlebot.target';
255
+      echo '';
256
+      echo '[Service]';
257
+      echo 'Type=simple';
258
+      echo 'User=scuttlebot';
259
+      echo 'Group=scuttlebot';
260
+      echo "WorkingDirectory=/etc/scuttlebot";
261
+      echo "ExecStart=/usr/bin/git ssb web --public localhost:$GIT_SSB_PORT";
262
+      echo 'Restart=always';
263
+      echo 'Environment="USER=scuttlebot"';
264
+      echo '';
265
+      echo '[Install]';
266
+      echo 'WantedBy=multi-user.target'; } > $git_ssb_daemon_filename
262 267
 }
263 268
 
264 269
 function scuttlebot_git_setup {
265 270
     if [[ "$1" == "mesh" ]]; then
266
-        if [ ! -d $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight ]; then
267
-            mkdir $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight
271
+        if [ ! -d "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight" ]; then
272
+            mkdir "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight"
268 273
         fi
269
-        if [ ! -f $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css ]; then
274
+        if [ ! -f "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css" ]; then
270 275
             echo $'Could not find foundation.css'
271 276
             exit 347687245
272 277
         fi
273
-        cp $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css
278
+        cp "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css" "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css"
274 279
 
275 280
         git_ssb_nginx_site=$rootdir/etc/nginx/sites-available/git_ssb
276
-        echo 'server {' > $git_ssb_nginx_site
277
-        echo "  listen $NGINX_GIT_SSB_PORT default_server;" >> $git_ssb_nginx_site
278
-        echo "  server_name P${PEER_ID}.local;" >> $git_ssb_nginx_site
279
-        echo '' >> $git_ssb_nginx_site
280
-        echo '  access_log /dev/null;' >> $git_ssb_nginx_site
281
-        echo '  error_log /dev/null;' >> $git_ssb_nginx_site
282
-        echo '' >> $git_ssb_nginx_site
283
-        echo '  add_header X-XSS-Protection "1; mode=block";' >> $git_ssb_nginx_site
284
-        echo '  add_header X-Content-Type-Options nosniff;' >> $git_ssb_nginx_site
285
-        echo '  add_header X-Frame-Options SAMEORIGIN;' >> $git_ssb_nginx_site
281
+        { echo 'server {';
282
+          echo "  listen $NGINX_GIT_SSB_PORT default_server;";
283
+          echo "  server_name P${PEER_ID}.local;";
284
+          echo '';
285
+          echo '  access_log /dev/null;';
286
+          echo '  error_log /dev/null;';
287
+          echo '';
288
+          echo '  add_header X-XSS-Protection "1; mode=block";';
289
+          echo '  add_header X-Content-Type-Options nosniff;';
290
+          echo '  add_header X-Frame-Options SAMEORIGIN;'; } > "$git_ssb_nginx_site"
286 291
     else
287 292
         if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
288 293
             exit 7357225
@@ -300,15 +305,15 @@ function scuttlebot_git_setup {
300 305
         git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
301 306
         function_check nginx_http_redirect
302 307
         nginx_http_redirect $SCUTTLEBOT_DOMAIN_NAME "index index.html"
303
-        echo 'server {' >> $git_ssb_nginx_site
304
-        echo '  listen 443 ssl;' >> $git_ssb_nginx_site
305
-        echo '  #listen [::]:443 ssl;' >> $git_ssb_nginx_site
306
-        echo "  server_name $SCUTTLEBOT_DOMAIN_NAME;" >> $git_ssb_nginx_site
307
-        echo '' >> $git_ssb_nginx_site
308
+        { echo 'server {';
309
+          echo '  listen 443 ssl;';
310
+          echo '  #listen [::]:443 ssl;';
311
+          echo "  server_name $SCUTTLEBOT_DOMAIN_NAME;";
312
+          echo ''; } >> $git_ssb_nginx_site
308 313
         function_check nginx_compress
309 314
         nginx_compress $SCUTTLEBOT_DOMAIN_NAME
310
-        echo '' >> $git_ssb_nginx_site
311
-        echo '  # Security' >> $git_ssb_nginx_site
315
+        echo '' >> "$git_ssb_nginx_site"
316
+        echo '  # Security' >> "$git_ssb_nginx_site"
312 317
         function_check nginx_ssl
313 318
         nginx_ssl $SCUTTLEBOT_DOMAIN_NAME
314 319
 
@@ -316,45 +321,45 @@ function scuttlebot_git_setup {
316 321
         nginx_disable_sniffing $SCUTTLEBOT_DOMAIN_NAME
317 322
     fi
318 323
 
319
-    echo '' >> $git_ssb_nginx_site
320
-    echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;' >> $git_ssb_nginx_site
321
-    echo '' >> $git_ssb_nginx_site
322
-    echo '  location = / {' >> $git_ssb_nginx_site
323
-    echo "    proxy_pass http://localhost:${GIT_SSB_PORT};" >> $git_ssb_nginx_site
324
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $git_ssb_nginx_site
325
-    echo '    proxy_set_header Host $host;' >> $git_ssb_nginx_site
326
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $git_ssb_nginx_site
327
-    echo '    proxy_http_version 1.1;' >> $git_ssb_nginx_site
328
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $git_ssb_nginx_site
329
-    echo '    proxy_set_header Connection upgrade;' >> $git_ssb_nginx_site
330
-    echo '  }' >> $git_ssb_nginx_site
331
-    echo '}' >> $git_ssb_nginx_site
332
-
333
-    if [ $SCUTTLEBOT_ONION_HOSTNAME ]; then
334
-        echo '' >> $git_ssb_nginx_site
335
-        echo 'server {' >> $git_ssb_nginx_site
336
-        echo "  listen 127.0.0.1:${SCUTTLEBOT_ONION_PORT} default_server;" >> $git_ssb_nginx_site
337
-        echo "  server_name ${SCUTTLEBOT_ONION_HOSTNAME};" >> $git_ssb_nginx_site
338
-        echo '' >> $git_ssb_nginx_site
339
-        echo '  access_log /dev/null;' >> $git_ssb_nginx_site
340
-        echo '  error_log /dev/null;' >> $git_ssb_nginx_site
341
-        echo '' >> $git_ssb_nginx_site
342
-        echo '  add_header X-XSS-Protection "1; mode=block";' >> $git_ssb_nginx_site
343
-        echo '  add_header X-Content-Type-Options nosniff;' >> $git_ssb_nginx_site
344
-        echo '  add_header X-Frame-Options SAMEORIGIN;' >> $git_ssb_nginx_site
345
-        echo '' >> $git_ssb_nginx_site
346
-        echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;' >> $git_ssb_nginx_site
347
-        echo '' >> $git_ssb_nginx_site
348
-        echo '  location = / {' >> $git_ssb_nginx_site
349
-        echo "    proxy_pass http://localhost:${GIT_SSB_PORT};" >> $git_ssb_nginx_site
350
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $git_ssb_nginx_site
351
-        echo '    proxy_set_header Host $host;' >> $git_ssb_nginx_site
352
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $git_ssb_nginx_site
353
-        echo '    proxy_http_version 1.1;' >> $git_ssb_nginx_site
354
-        echo '    proxy_set_header Upgrade $http_upgrade;' >> $git_ssb_nginx_site
355
-        echo '    proxy_set_header Connection upgrade;' >> $git_ssb_nginx_site
356
-        echo '  }' >> $git_ssb_nginx_site
357
-        echo '}' >> $git_ssb_nginx_site
324
+    { echo '';
325
+      echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;';
326
+      echo '';
327
+      echo '  location = / {';
328
+      echo "    proxy_pass http://localhost:${GIT_SSB_PORT};";
329
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
330
+      echo "    proxy_set_header Host \$host;";
331
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
332
+      echo '    proxy_http_version 1.1;';
333
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
334
+      echo '    proxy_set_header Connection upgrade;';
335
+      echo '  }';
336
+      echo '}'; } >> $git_ssb_nginx_site
337
+
338
+    if [ "$SCUTTLEBOT_ONION_HOSTNAME" ]; then
339
+        { echo '';
340
+          echo 'server {';
341
+          echo "  listen 127.0.0.1:${SCUTTLEBOT_ONION_PORT} default_server;";
342
+          echo "  server_name ${SCUTTLEBOT_ONION_HOSTNAME};";
343
+          echo '';
344
+          echo '  access_log /dev/null;';
345
+          echo '  error_log /dev/null;';
346
+          echo '';
347
+          echo '  add_header X-XSS-Protection "1; mode=block";';
348
+          echo '  add_header X-Content-Type-Options nosniff;';
349
+          echo '  add_header X-Frame-Options SAMEORIGIN;';
350
+          echo '';
351
+          echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;';
352
+          echo '';
353
+          echo '  location = / {';
354
+          echo "    proxy_pass http://localhost:${GIT_SSB_PORT};";
355
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
356
+          echo "    proxy_set_header Host \$host;";
357
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
358
+          echo '    proxy_http_version 1.1;';
359
+          echo "    proxy_set_header Upgrade \$http_upgrade;";
360
+          echo '    proxy_set_header Connection upgrade;';
361
+          echo '  }';
362
+          echo '}'; } >> $git_ssb_nginx_site
358 363
     fi
359 364
     if [[ "$1" != "mesh" ]]; then
360 365
         nginx_ensite git_ssb
@@ -364,23 +369,23 @@ function scuttlebot_git_setup {
364 369
 function mesh_install_dat {
365 370
     get_npm_arch
366 371
 
367
-    cat <<EOF > $rootdir/usr/bin/install_dat
372
+    cat <<EOF > "$rootdir/usr/bin/install_dat"
368 373
 #!/bin/bash
369 374
 npm install --arch=$NPM_ARCH -g dat
370 375
 npm install --arch=$NPM_ARCH -g @garbados/dat-boi
371 376
 npm install --arch=$NPM_ARCH -g add-to-systemd
372
-add-to-systemd dat-boi --user $(whoami) `which dat-boi`
377
+add-to-systemd dat-boi --user "$(whoami)" "$(which dat-boi)"
373 378
 EOF
374 379
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
375 380
     chroot "$rootdir" /usr/bin/install_dat
376
-    rm $rootdir/usr/bin/install_dat
381
+    rm "$rootdir/usr/bin/install_dat"
377 382
 }
378 383
 
379 384
 function install_dat {
380 385
     npm install -g dat
381 386
     npm install -g @garbados/dat-boi
382 387
     npm install -g add-to-systemd
383
-    add-to-systemd dat-boi --user $(whoami) `which dat-boi`
388
+    add-to-systemd dat-boi --user "$(whoami)" "$(which dat-boi)"
384 389
 }
385 390
 
386 391
 function mesh_install_scuttlebot {
@@ -390,7 +395,7 @@ function mesh_install_scuttlebot {
390 395
 
391 396
     get_npm_arch
392 397
 
393
-    cat <<EOF > $rootdir/usr/bin/install_scuttlebot
398
+    cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
394 399
 #!/bin/bash
395 400
 npm install --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}
396 401
 npm install --arch=$NPM_ARCH -g git-ssb
@@ -398,37 +403,37 @@ npm install --arch=$NPM_ARCH -g git-remote-ssb
398 403
 EOF
399 404
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
400 405
     chroot "$rootdir" /usr/bin/install_scuttlebot
401
-    rm $rootdir/usr/bin/install_scuttlebot
406
+    rm "$rootdir/usr/bin/install_scuttlebot"
402 407
 
403
-    if [ ! -f $rootdir/usr/local/bin/sbot ]; then
408
+    if [ ! -f "$rootdir/usr/local/bin/sbot" ]; then
404 409
         echo $'Scuttlebot was not installed'
405 410
         exit 528253
406 411
     fi
407 412
 
408
-    if [ ! -d $rootdir/etc/scuttlebot ]; then
409
-        mkdir -p $rootdir/etc/scuttlebot
413
+    if [ ! -d "$rootdir/etc/scuttlebot" ]; then
414
+        mkdir -p "$rootdir/etc/scuttlebot"
410 415
     fi
411 416
 
412 417
     # an unprivileged user to run as
413 418
     chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
414 419
 
415 420
     # daemon
416
-    echo '[Unit]' > $rootdir/etc/systemd/system/scuttlebot.service
417
-    echo 'Description=Scuttlebot (messaging system)' >> $rootdir/etc/systemd/system/scuttlebot.service
418
-    echo 'After=syslog.target' >> $rootdir/etc/systemd/system/scuttlebot.service
419
-    echo 'After=network.target' >> $rootdir/etc/systemd/system/scuttlebot.service
420
-    echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
421
-    echo '[Service]' >> $rootdir/etc/systemd/system/scuttlebot.service
422
-    echo 'Type=simple' >> $rootdir/etc/systemd/system/scuttlebot.service
423
-    echo 'User=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
424
-    echo 'Group=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
425
-    echo "WorkingDirectory=/etc/scuttlebot" >> $rootdir/etc/systemd/system/scuttlebot.service
426
-    echo 'ExecStart=/usr/local/bin/sbot server' >> $rootdir/etc/systemd/system/scuttlebot.service
427
-    echo 'Restart=always' >> $rootdir/etc/systemd/system/scuttlebot.service
428
-    echo 'Environment="USER=scuttlebot"' >> $rootdir/etc/systemd/system/scuttlebot.service
429
-    echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
430
-    echo '[Install]' >> $rootdir/etc/systemd/system/scuttlebot.service
431
-    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/scuttlebot.service
421
+    { echo '[Unit]';
422
+      echo 'Description=Scuttlebot (messaging system)';
423
+      echo 'After=syslog.target';
424
+      echo 'After=network.target';
425
+      echo '';
426
+      echo '[Service]';
427
+      echo 'Type=simple';
428
+      echo 'User=scuttlebot';
429
+      echo 'Group=scuttlebot';
430
+      echo "WorkingDirectory=/etc/scuttlebot";
431
+      echo 'ExecStart=/usr/local/bin/sbot server';
432
+      echo 'Restart=always';
433
+      echo 'Environment="USER=scuttlebot"';
434
+      echo '';
435
+      echo '[Install]';
436
+      echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/scuttlebot.service"
432 437
 
433 438
     scuttlebot_git_setup mesh
434 439
     git_ssb_script mesh
@@ -455,22 +460,22 @@ function install_scuttlebot {
455 460
     useradd -d /etc/scuttlebot/ scuttlebot
456 461
 
457 462
     # daemon
458
-    echo '[Unit]' > /etc/systemd/system/scuttlebot.service
459
-    echo 'Description=Scuttlebot (messaging system)' >> /etc/systemd/system/scuttlebot.service
460
-    echo 'After=syslog.target' >> /etc/systemd/system/scuttlebot.service
461
-    echo 'After=network.target' >> /etc/systemd/system/scuttlebot.service
462
-    echo '' >> /etc/systemd/system/scuttlebot.service
463
-    echo '[Service]' >> /etc/systemd/system/scuttlebot.service
464
-    echo 'Type=simple' >> /etc/systemd/system/scuttlebot.service
465
-    echo 'User=scuttlebot' >> /etc/systemd/system/scuttlebot.service
466
-    echo 'Group=scuttlebot' >> /etc/systemd/system/scuttlebot.service
467
-    echo "WorkingDirectory=/etc/scuttlebot" >> /etc/systemd/system/scuttlebot.service
468
-    echo 'ExecStart=/usr/local/bin/sbot server' >> /etc/systemd/system/scuttlebot.service
469
-    echo 'Restart=always' >> /etc/systemd/system/scuttlebot.service
470
-    echo 'Environment="USER=scuttlebot"' >> /etc/systemd/system/scuttlebot.service
471
-    echo '' >> /etc/systemd/system/scuttlebot.service
472
-    echo '[Install]' >> /etc/systemd/system/scuttlebot.service
473
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/scuttlebot.service
463
+    { echo '[Unit]';
464
+      echo 'Description=Scuttlebot (messaging system)';
465
+      echo 'After=syslog.target';
466
+      echo 'After=network.target';
467
+      echo '';
468
+      echo '[Service]';
469
+      echo 'Type=simple';
470
+      echo 'User=scuttlebot';
471
+      echo 'Group=scuttlebot';
472
+      echo "WorkingDirectory=/etc/scuttlebot";
473
+      echo 'ExecStart=/usr/local/bin/sbot server';
474
+      echo 'Restart=always';
475
+      echo 'Environment="USER=scuttlebot"';
476
+      echo '';
477
+      echo '[Install]';
478
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/scuttlebot.service
474 479
 
475 480
     chown -R scuttlebot:scuttlebot /etc/scuttlebot
476 481
 
@@ -489,24 +494,24 @@ function install_scuttlebot {
489 494
         exit 73528
490 495
     fi
491 496
 
492
-    echo '{' > /etc/scuttlebot/.ssb/config
493
-    echo "  \"host\": \"${DEFAULT_DOMAIN_NAME}\"," >> /etc/scuttlebot/.ssb/config
494
-    echo "  \"port\": ${SCUTTLEBOT_PORT}," >> /etc/scuttlebot/.ssb/config
495
-    echo '  "timeout": 30000,' >> /etc/scuttlebot/.ssb/config
496
-    echo '  "pub": true,' >> /etc/scuttlebot/.ssb/config
497
-    echo '  "local": true,' >> /etc/scuttlebot/.ssb/config
498
-    echo '  "friends": {' >> /etc/scuttlebot/.ssb/config
499
-    echo '    "dunbar": 150,' >> /etc/scuttlebot/.ssb/config
500
-    echo '    "hops": 3' >> /etc/scuttlebot/.ssb/config
501
-    echo '  },' >> /etc/scuttlebot/.ssb/config
502
-    echo '  "gossip": {' >> /etc/scuttlebot/.ssb/config
503
-    echo '    "connections": 2' >> /etc/scuttlebot/.ssb/config
504
-    echo '  },' >> /etc/scuttlebot/.ssb/config
505
-    echo '  "master": [],' >> /etc/scuttlebot/.ssb/config
506
-    echo '  "logging": {' >> /etc/scuttlebot/.ssb/config
507
-    echo '    "level": "error"' >> /etc/scuttlebot/.ssb/config
508
-    echo '  }' >> /etc/scuttlebot/.ssb/config
509
-    echo '}' >> /etc/scuttlebot/.ssb/config
497
+    { echo '{';
498
+      echo "  \"host\": \"${DEFAULT_DOMAIN_NAME}\",";
499
+      echo "  \"port\": ${SCUTTLEBOT_PORT},";
500
+      echo '  "timeout": 30000,';
501
+      echo '  "pub": true,';
502
+      echo '  "local": true,';
503
+      echo '  "friends": {';
504
+      echo '    "dunbar": 150,';
505
+      echo '    "hops": 3';
506
+      echo '  },';
507
+      echo '  "gossip": {';
508
+      echo '    "connections": 2';
509
+      echo '  },';
510
+      echo '  "master": [],';
511
+      echo '  "logging": {';
512
+      echo '    "level": "error"';
513
+      echo '  }';
514
+      echo '}'; } > /etc/scuttlebot/.ssb/config
510 515
     chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
511 516
     systemctl restart scuttlebot.service
512 517
 
@@ -527,10 +532,10 @@ function install_scuttlebot {
527 532
 
528 533
     systemctl restart nginx
529 534
 
530
-    if ! grep -q "scuttlebot version:" ${COMPLETION_FILE}; then
531
-        echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> ${COMPLETION_FILE}
535
+    if ! grep -q "scuttlebot version:" "${COMPLETION_FILE}"; then
536
+        echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> "${COMPLETION_FILE}"
532 537
     else
533
-        sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
538
+        sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
534 539
     fi
535 540
 
536 541
     APP_INSTALLED=1

+ 607
- 611
src/freedombone-app-searx
File diff suppressed because it is too large
View File