Bob Mottram 7 年之前
父節點
當前提交
fa8f96bfdb

+ 171
- 167
src/freedombone-app-mediagoblin 查看文件

71
     if ! grep -q 'import os' $mgfile; then
71
     if ! grep -q 'import os' $mgfile; then
72
         sed -i '/import sys/a import os' $mgfile
72
         sed -i '/import sys/a import os' $mgfile
73
     fi
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
 function install_interactive_mediagoblin {
77
 function install_interactive_mediagoblin {
92
     dialog --title $"Mediagoblin" \
92
     dialog --title $"Mediagoblin" \
93
            --backtitle $"Freedombone Control Panel" \
93
            --backtitle $"Freedombone Control Panel" \
94
            --defaultno \
94
            --defaultno \
95
-           --yesno $"\nAllow registration of new users?" 10 60
95
+           --yesno $"\\nAllow registration of new users?" 10 60
96
     sel=$?
96
     sel=$?
97
     case $sel in
97
     case $sel in
98
         0)
98
         0)
139
 }
139
 }
140
 
140
 
141
 function upgrade_mediagoblin {
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
     if [[ "$CURR_MEDIAGOBLIN_COMMIT" != "$MEDIAGOBLIN_COMMIT" ]]; then
143
     if [[ "$CURR_MEDIAGOBLIN_COMMIT" != "$MEDIAGOBLIN_COMMIT" ]]; then
144
         MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
144
         MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
145
         su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git stash && git pull" - mediagoblin
145
         su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git stash && git pull" - mediagoblin
182
         else
182
         else
183
             cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
183
             cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
184
         fi
184
         fi
185
+        # shellcheck disable=SC2181
185
         if [ ! "$?" = "0" ]; then
186
         if [ ! "$?" = "0" ]; then
186
             function_check restore_directory_from_usb
187
             function_check restore_directory_from_usb
187
             set_user_permissions
188
             set_user_permissions
195
         else
196
         else
196
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
197
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
197
         fi
198
         fi
199
+        # shellcheck disable=SC2181
198
         if [ ! "$?" = "0" ]; then
200
         if [ ! "$?" = "0" ]; then
199
             function_check set_user_permissions
201
             function_check set_user_permissions
200
             set_user_permissions
202
             set_user_permissions
214
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
216
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
215
     if [ -d /etc/mediagoblin ]; then
217
     if [ -d /etc/mediagoblin ]; then
216
         echo $"Backing up mediagoblin"
218
         echo $"Backing up mediagoblin"
217
-        backup_directory_to_friend $MEDIAGOBLIN_BASE_DIR mediagoblin
219
+        backup_directory_to_friend "$MEDIAGOBLIN_BASE_DIR" mediagoblin
218
         backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
220
         backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
219
     fi
221
     fi
220
 }
222
 }
221
 
223
 
222
 function restore_remote_mediagoblin {
224
 function restore_remote_mediagoblin {
223
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
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
         temp_restore_dir=/root/tempmediagoblin
227
         temp_restore_dir=/root/tempmediagoblin
226
         function_check get_completion_param
228
         function_check get_completion_param
227
         MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
229
         MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
228
         function_check restore_directory_from_friend
230
         function_check restore_directory_from_friend
229
         restore_directory_from_friend $temp_restore_dir mediagoblin
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
         else
234
         else
233
-            cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
235
+            cp -r "${temp_restore_dir}/*" "$MEDIAGOBLIN_BASE_DIR/"
234
         fi
236
         fi
237
+        # shellcheck disable=SC2181
235
         if [ ! "$?" = "0" ]; then
238
         if [ ! "$?" = "0" ]; then
236
             exit 264824
239
             exit 264824
237
         fi
240
         fi
241
         else
244
         else
242
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
245
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
243
         fi
246
         fi
247
+        # shellcheck disable=SC2181
244
         if [ ! "$?" = "0" ]; then
248
         if [ ! "$?" = "0" ]; then
245
             exit 268492
249
             exit 268492
246
         fi
250
         fi
247
         rm -rf ${temp_restore_dir}
251
         rm -rf ${temp_restore_dir}
248
         rm -rf ${temp_restore_dir}2
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
         chown -hR mediagoblin:www-data /var/lib/mediagoblin
254
         chown -hR mediagoblin:www-data /var/lib/mediagoblin
251
         chmod -R g+wx /var/lib/mediagoblin
255
         chmod -R g+wx /var/lib/mediagoblin
252
     fi
256
     fi
264
 
268
 
265
     function_check remove_onion_service
269
     function_check remove_onion_service
266
     remove_onion_service mediagoblin ${MEDIAGOBLIN_ONION_PORT}
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
     if [ -d /var/lib/mediagoblin ]; then
273
     if [ -d /var/lib/mediagoblin ]; then
270
         rm -rf /var/lib/mediagoblin
274
         rm -rf /var/lib/mediagoblin
271
     fi
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
     fi
278
     fi
275
     remove_completion_param "install_mediagoblin"
279
     remove_completion_param "install_mediagoblin"
276
     remove_completion_param "mediagoblin domain"
280
     remove_completion_param "mediagoblin domain"
277
-    sed -i '/mediagoblin/d' $COMPLETION_FILE
281
+    sed -i '/mediagoblin/d' "$COMPLETION_FILE"
278
 
282
 
279
     remove_nodejs mediagoblin
283
     remove_nodejs mediagoblin
280
 
284
 
282
     userdel -r mediagoblin
286
     userdel -r mediagoblin
283
 
287
 
284
     function_check remove_ddns_domain
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
 function install_mediagoblin {
292
 function install_mediagoblin {
289
-    if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
293
+    if [ ! "$MEDIAGOBLIN_DOMAIN_NAME" ]; then
290
         return
294
         return
291
     fi
295
     fi
292
 
296
 
304
     useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
308
     useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
305
     usermod --append -G mediagoblin mediagoblin
309
     usermod --append -G mediagoblin mediagoblin
306
     mkdir -p /var/lib/mediagoblin
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
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
313
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
310
     chmod -R g+wx /var/lib/mediagoblin
314
     chmod -R g+wx /var/lib/mediagoblin
311
 
315
 
312
     if [ -d /repos/mediagoblin ]; then
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
         git pull
320
         git pull
317
-        chown -R mediagoblin:mediagoblin $MEDIAGOBLIN_BASE_DIR/mediagoblin
321
+        chown -R mediagoblin:mediagoblin "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
318
     else
322
     else
319
         su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
323
         su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
320
     fi
324
     fi
340
             gstreamer1.0-plugins-ugly \
344
             gstreamer1.0-plugins-ugly \
341
             gstreamer1.0-libav \
345
             gstreamer1.0-libav \
342
             python-gst-1.0 python3-gst-1.0
346
             python-gst-1.0 python3-gst-1.0
343
-    cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
347
+    cd "$MEDIAGOBLIN_BASE_DIR/mediagoblin" || exit 76345672472
344
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
348
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
345
 
349
 
346
     # Audio plugin
350
     # Audio plugin
349
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
353
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
350
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/pip install scikits.audiolab" - mediagoblin
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
     else
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
         fi
361
         fi
358
     fi
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
     MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
365
     MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
362
     set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
366
     set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
365
 
369
 
366
     if [[ $ONION_ONLY == "no" ]]; then
370
     if [[ $ONION_ONLY == "no" ]]; then
367
         function_check nginx_http_redirect
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
         function_check nginx_ssl
382
         function_check nginx_ssl
379
-        nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
383
+        nginx_ssl "$MEDIAGOBLIN_DOMAIN_NAME"
380
         function_check nginx_disable_sniffing
384
         function_check nginx_disable_sniffing
381
-        nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
385
+        nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
382
         function_check nginx_limits
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
     else
430
     else
427
-        echo -n '' > /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
431
+        echo -n '' > "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
428
     fi
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
     function_check nginx_disable_sniffing
441
     function_check nginx_disable_sniffing
438
-    nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
442
+    nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
439
     function_check nginx_limits
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
     chmod +x /etc/systemd/system/mediagoblin.service
505
     chmod +x /etc/systemd/system/mediagoblin.service
502
 
506
 
503
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
507
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
504
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
508
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
505
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg makeadmin $MY_USERNAME" - mediagoblin
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
     fi
523
     fi
520
 
524
 
521
     systemctl enable mediagoblin
525
     systemctl enable mediagoblin
529
     fi
533
     fi
530
 
534
 
531
     function_check create_site_certificate
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
     function_check configure_php
538
     function_check configure_php
535
     configure_php
539
     configure_php
536
 
540
 
537
-    nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
541
+    nginx_ensite "$MEDIAGOBLIN_DOMAIN_NAME"
538
 
542
 
539
     systemctl restart php7.0-fpm
543
     systemctl restart php7.0-fpm
540
     systemctl restart nginx
544
     systemctl restart nginx
541
 
545
 
542
     function_check add_ddns_domain
546
     function_check add_ddns_domain
543
-    add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
547
+    add_ddns_domain "$MEDIAGOBLIN_DOMAIN_NAME"
544
 
548
 
545
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
549
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
546
     chmod -R g+wx /var/lib/mediagoblin
550
     chmod -R g+wx /var/lib/mediagoblin

+ 206
- 206
src/freedombone-app-movim 查看文件

58
 function remove_user_movim {
58
 function remove_user_movim {
59
     remove_username="$1"
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
 function add_user_movim {
64
 function add_user_movim {
65
     new_username="$1"
65
     new_username="$1"
66
     new_user_password="$2"
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
     echo '0'
69
     echo '0'
70
 }
70
 }
71
 
71
 
72
 function install_interactive_movim {
72
 function install_interactive_movim {
73
-    if [ ! $ONION_ONLY ]; then
73
+    if [ ! "$ONION_ONLY" ]; then
74
         ONION_ONLY='no'
74
         ONION_ONLY='no'
75
     fi
75
     fi
76
 
76
 
80
         MOVIM_DETAILS_COMPLETE=
80
         MOVIM_DETAILS_COMPLETE=
81
         while [ ! $MOVIM_DETAILS_COMPLETE ]
81
         while [ ! $MOVIM_DETAILS_COMPLETE ]
82
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
84
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
86
                 dialog --backtitle $"Freedombone Configuration" \
85
                 dialog --backtitle $"Freedombone Configuration" \
87
                        --title $"Movim Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
88
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
90
                        $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
89
                        $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
91
-                       2> $data
90
+                       2> "$data"
92
             else
91
             else
93
                 dialog --backtitle $"Freedombone Configuration" \
92
                 dialog --backtitle $"Freedombone Configuration" \
94
                        --title $"Movim Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
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
             fi
97
             fi
99
             sel=$?
98
             sel=$?
100
             case $sel in
99
             case $sel in
101
                 1) exit 1;;
100
                 1) exit 1;;
102
                 255) exit 1;;
101
                 255) exit 1;;
103
             esac
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
                 TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
105
                 TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
107
                 validate_domain_name
106
                 validate_domain_name
108
-                if [[ $TEST_DOMAIN_NAME != $MOVIM_DOMAIN_NAME ]]; then
107
+                if [[ "$TEST_DOMAIN_NAME" != "$MOVIM_DOMAIN_NAME" ]]; then
109
                     MOVIM_DOMAIN_NAME=
108
                     MOVIM_DOMAIN_NAME=
110
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
109
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
111
                 else
110
                 else
112
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$MOVIM_CODE"
113
                         validate_freedns_code "$MOVIM_CODE"
115
-                        if [ ! $VALID_CODE ]; then
114
+                        if [ ! "$VALID_CODE" ]; then
116
                             MOVIM_DOMAIN_NAME=
115
                             MOVIM_DOMAIN_NAME=
117
                         fi
116
                         fi
118
                     fi
117
                     fi
121
             if [ $MOVIM_DOMAIN_NAME ]; then
120
             if [ $MOVIM_DOMAIN_NAME ]; then
122
                 MOVIM_DETAILS_COMPLETE="yes"
121
                 MOVIM_DETAILS_COMPLETE="yes"
123
             fi
122
             fi
123
+            rm -f "$data"
124
         done
124
         done
125
 
125
 
126
         # save the results in the config file
126
         # save the results in the config file
136
 
136
 
137
     read_config_param 'MOVIM_DOMAIN_NAME'
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
 function movim_create_database {
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
     else
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
         fi
148
         fi
149
     fi
149
     fi
150
-    if [ ! $MOVIM_ADMIN_PASSWORD ]; then
150
+    if [ ! "$MOVIM_ADMIN_PASSWORD" ]; then
151
         return
151
         return
152
     fi
152
     fi
153
 
153
 
154
     function_check create_database
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
 function reconfigure_movim {
158
 function reconfigure_movim {
165
         return
165
         return
166
     fi
166
     fi
167
 
167
 
168
-    if grep -q "movim domain" $COMPLETION_FILE; then
168
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
169
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
169
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
170
     fi
170
     fi
171
 
171
 
172
     # update to the next commit
172
     # update to the next commit
173
     function_check set_repo_commit
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
     php composer.phar install
177
     php composer.phar install
178
     php mud.php db --set
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
 function backup_local_movim {
183
 function backup_local_movim {
184
     MOVIM_DOMAIN_NAME='movim'
184
     MOVIM_DOMAIN_NAME='movim'
185
-    if grep -q "movim domain" $COMPLETION_FILE; then
185
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
186
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
186
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
187
     fi
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
         dest_directory=movim
191
         dest_directory=movim
192
         function_check suspend_site
192
         function_check suspend_site
193
-        suspend_site ${MOVIM_DOMAIN_NAME}
193
+        suspend_site "${MOVIM_DOMAIN_NAME}"
194
 
194
 
195
         function_check backup_directory_to_usb
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
         function_check backup_database_to_usb
198
         function_check backup_database_to_usb
199
         backup_database_to_usb movim
199
         backup_database_to_usb movim
204
 }
204
 }
205
 
205
 
206
 function restore_local_movim {
206
 function restore_local_movim {
207
-    if ! grep -q "movim domain" $COMPLETION_FILE; then
207
+    if ! grep -q "movim domain" "$COMPLETION_FILE"; then
208
         return
208
         return
209
     fi
209
     fi
210
     MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
210
     MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
211
-    if [ $MOVIM_DOMAIN_NAME ]; then
211
+    if [ "$MOVIM_DOMAIN_NAME" ]; then
212
         echo $"Restoring movim"
212
         echo $"Restoring movim"
213
         temp_restore_dir=/root/tempmovim
213
         temp_restore_dir=/root/tempmovim
214
         movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
214
         movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
215
         # stop the daemons
215
         # stop the daemons
216
-        cd $movim_dir
216
+        cd "$movim_dir" || exit 7856724252
217
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
217
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
218
 
218
 
219
         function_check movim_create_database
219
         function_check movim_create_database
220
         movim_create_database
220
         movim_create_database
221
 
221
 
222
-        restore_database movim ${MOVIM_DOMAIN_NAME}
222
+        restore_database movim "${MOVIM_DOMAIN_NAME}"
223
         if [ -d $temp_restore_dir ]; then
223
         if [ -d $temp_restore_dir ]; then
224
             rm -rf $temp_restore_dir
224
             rm -rf $temp_restore_dir
225
         fi
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
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
229
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
230
         MARIADB_PASSWORD=
230
         MARIADB_PASSWORD=
231
 
231
 
234
 }
234
 }
235
 
235
 
236
 function backup_remote_movim {
236
 function backup_remote_movim {
237
-    if grep -q "movim domain" $COMPLETION_FILE; then
237
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
238
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
238
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
239
         temp_backup_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
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
             function_check suspend_site
241
             function_check suspend_site
242
-            suspend_site ${MOVIM_DOMAIN_NAME}
242
+            suspend_site "${MOVIM_DOMAIN_NAME}"
243
 
243
 
244
             function_check backup_database_to_friend
244
             function_check backup_database_to_friend
245
             backup_database_to_friend movim
245
             backup_database_to_friend movim
246
 
246
 
247
             function_check backup_directory_to_friend
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
             function_check restart_site
250
             function_check restart_site
251
             restart_site
251
             restart_site
256
 }
256
 }
257
 
257
 
258
 function restore_remote_movim {
258
 function restore_remote_movim {
259
-    if grep -q "movim domain" $COMPLETION_FILE; then
259
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
260
         echo $"Restoring movim"
260
         echo $"Restoring movim"
261
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
261
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
262
 
262
 
263
         # stop the daemons
263
         # stop the daemons
264
-        cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
264
+        cd "/var/www/${MOVIM_DOMAIN_NAME}/htdocs" || exit 524792846827
265
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
265
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
266
 
266
 
267
         function_check movim_create_database
267
         function_check movim_create_database
268
         movim_create_database
268
         movim_create_database
269
 
269
 
270
         function_check restore_database_from_friend
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
         if [ -d /root/tempmovim ]; then
272
         if [ -d /root/tempmovim ]; then
273
             rm -rf /root/tempmovim
273
             rm -rf /root/tempmovim
274
         fi
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
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
278
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
279
         MARIADB_PASSWORD=
279
         MARIADB_PASSWORD=
280
 
280
 
298
 
298
 
299
     read_config_param "MY_USERNAME"
299
     read_config_param "MY_USERNAME"
300
     echo "Removing $MOVIM_DOMAIN_NAME"
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
     fi
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
     fi
309
     fi
310
     function_check drop_database
310
     function_check drop_database
311
     drop_database movim
311
     drop_database movim
316
     fi
316
     fi
317
     remove_app movim
317
     remove_app movim
318
     remove_completion_param install_movim
318
     remove_completion_param install_movim
319
-    sed -i '/movim/d' $COMPLETION_FILE
319
+    sed -i '/movim/d' "$COMPLETION_FILE"
320
     remove_backup_database_local movim
320
     remove_backup_database_local movim
321
 
321
 
322
     function_check remove_ddns_domain
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
 function install_movim {
326
 function install_movim {
327
-    if [ ! $MOVIM_DOMAIN_NAME ]; then
327
+    if [ ! "$MOVIM_DOMAIN_NAME" ]; then
328
         echo $'No domain name was given for movim'
328
         echo $'No domain name was given for movim'
329
         exit 72572
329
         exit 72572
330
     fi
330
     fi
333
         return
333
         return
334
     fi
334
     fi
335
 
335
 
336
-    movim_hourly_script movim $MOVIM_DOMAIN_NAME
336
+    movim_hourly_script movim "$MOVIM_DOMAIN_NAME"
337
 
337
 
338
     function_check install_mariadb
338
     function_check install_mariadb
339
     install_mariadb
339
     install_mariadb
347
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
347
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
348
     apt-get -yq install php-memcached php-intl exiftool php-imagick libfcgi0ldbl
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
     fi
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
         if [ -d /repos/movim ]; then
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
             git pull
359
             git pull
360
         else
360
         else
361
             function_check git_clone
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
         fi
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
             echo $'Unable to clone movim repo'
366
             echo $'Unable to clone movim repo'
367
             exit 76285
367
             exit 76285
368
         fi
368
         fi
369
     fi
369
     fi
370
 
370
 
371
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
371
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 7345247242
372
     git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
372
     git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
373
     set_completion_param "movim commit" "$MOVIM_COMMIT"
373
     set_completion_param "movim commit" "$MOVIM_COMMIT"
374
 
374
 
375
     # default login
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
         echo $'Unable to find Config.php'
377
         echo $'Unable to find Config.php'
378
         exit 72352
378
         exit 72352
379
     fi
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
     # Fix typo
383
     # Fix typo
384
     sed -i 's|weksocket|websocket|g' app/widgets/AdminTest/admintest.js
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
     install_composer
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
     cp db.example.inc.php db.inc.php
390
     cp db.example.inc.php db.inc.php
391
     sed -i "s|'username'.*|'username'    => 'root',|g" db.inc.php
391
     sed -i "s|'username'.*|'username'    => 'root',|g" db.inc.php
392
     sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
392
     sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
393
     sed -i "s|'database'.*|'database'    => 'movim'|g" db.inc.php
393
     sed -i "s|'database'.*|'database'    => 'movim'|g" db.inc.php
394
     php mud.php db --set
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
     function_check movim_create_database
399
     function_check movim_create_database
400
     movim_create_database
400
     movim_create_database
401
 
401
 
402
     function_check add_ddns_domain
402
     function_check add_ddns_domain
403
-    add_ddns_domain $MOVIM_DOMAIN_NAME
403
+    add_ddns_domain "$MOVIM_DOMAIN_NAME"
404
 
404
 
405
     MOVIM_ONION_HOSTNAME=$(add_onion_service movim 80 ${MOVIM_ONION_PORT})
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
     if [[ $ONION_ONLY == 'no' ]]; then
415
     if [[ $ONION_ONLY == 'no' ]]; then
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
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
     else
417
     else
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
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
     fi
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
     systemctl enable movim
428
     systemctl enable movim
429
     systemctl daemon-reload
429
     systemctl daemon-reload
430
 
430
 
431
     movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
431
     movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
432
     if [[ $ONION_ONLY == "no" ]]; then
432
     if [[ $ONION_ONLY == "no" ]]; then
433
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl
444
         function_check nginx_ssl
445
-        nginx_ssl $MOVIM_DOMAIN_NAME
445
+        nginx_ssl "$MOVIM_DOMAIN_NAME"
446
 
446
 
447
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
499
     else
500
-        echo -n '' > $movim_nginx_site
500
+        echo -n '' > "$movim_nginx_site"
501
     fi
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
     function_check nginx_compress
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check configure_php
560
     function_check configure_php
561
     configure_php
561
     configure_php
562
 
562
 
563
     function_check create_site_certificate
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
     # Ensure that the database gets backed up locally, if remote
566
     # Ensure that the database gets backed up locally, if remote
567
     # backups are not being used
567
     # backups are not being used
572
     backup_database_local movim
572
     backup_database_local movim
573
 
573
 
574
     function_check nginx_ensite
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
     set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
579
     set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
580
 
580
 

+ 37
- 36
src/freedombone-app-mumble 查看文件

86
         usermod -a -G ssl-cert mumble-server
86
         usermod -a -G ssl-cert mumble-server
87
     fi
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
         if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
90
         if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
91
             sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
91
             sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
92
             sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
92
             sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
117
 }
117
 }
118
 
118
 
119
 function restore_local_mumble {
119
 function restore_local_mumble {
120
-    if [ -d $USB_MOUNT/backup/mumble ]; then
120
+    if [ -d "$USB_MOUNT/backup/mumble" ]; then
121
         echo $"Restoring mumble settings"
121
         echo $"Restoring mumble settings"
122
         temp_restore_dir=/root/tempmumble
122
         temp_restore_dir=/root/tempmumble
123
         function_check restore_directory_from_usb
123
         function_check restore_directory_from_usb
124
         restore_directory_from_usb $temp_restore_dir voip
124
         restore_directory_from_usb $temp_restore_dir voip
125
         restore_directory_from_usb $temp_restore_dir mumble
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
         else
128
         else
129
             cp -f $temp_restore_dir/mumble-server.ini /etc/
129
             cp -f $temp_restore_dir/mumble-server.ini /etc/
130
         fi
130
         fi
131
+        # shellcheck disable=SC2181
131
         if [ ! "$?" = "0" ]; then
132
         if [ ! "$?" = "0" ]; then
132
             rm -rf $temp_restore_dir
133
             rm -rf $temp_restore_dir
133
             function_check set_user_permissions
134
             function_check set_user_permissions
136
             backup_unmount_drive
137
             backup_unmount_drive
137
             exit 3679
138
             exit 3679
138
         fi
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
         else
142
         else
142
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
143
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
143
         fi
144
         fi
145
+        # shellcheck disable=SC2181
144
         if [ ! "$?" = "0" ]; then
146
         if [ ! "$?" = "0" ]; then
145
             rm -rf $temp_restore_dir
147
             rm -rf $temp_restore_dir
146
             function_check set_user_permissions
148
             function_check set_user_permissions
171
 }
173
 }
172
 
174
 
173
 function restore_remote_mumble {
175
 function restore_remote_mumble {
174
-    if [ -d $SERVER_DIRECTORY/backup/mumble ]; then
176
+    if [ -d "$SERVER_DIRECTORY/backup/mumble" ]; then
175
         echo $"Restoring Mumble settings"
177
         echo $"Restoring Mumble settings"
176
         temp_restore_dir=/root/tempmumble
178
         temp_restore_dir=/root/tempmumble
177
         function_check restore_directory_from_friend
179
         function_check restore_directory_from_friend
178
         restore_directory_from_friend $temp_restore_dir mumble
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
         else
183
         else
182
             cp -f $temp_restore_dir/mumble-server.ini /etc/
184
             cp -f $temp_restore_dir/mumble-server.ini /etc/
183
         fi
185
         fi
186
+        # shellcheck disable=SC2181
184
         if [ ! "$?" = "0" ]; then
187
         if [ ! "$?" = "0" ]; then
185
             rm -rf $temp_restore_dir
188
             rm -rf $temp_restore_dir
186
             exit 7823
189
             exit 7823
187
         fi
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
         else
193
         else
195
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
194
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
196
         fi
195
         fi
196
+        # shellcheck disable=SC2181
197
         if [ ! "$?" = "0" ]; then
197
         if [ ! "$?" = "0" ]; then
198
             rm -rf $temp_restore_dir
198
             rm -rf $temp_restore_dir
199
             exit 276
199
             exit 276
221
     fi
221
     fi
222
     function_check remove_onion_service
222
     function_check remove_onion_service
223
     remove_onion_service mumble ${MUMBLE_PORT}
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
 function configure_firewall_for_mumble {
227
 function configure_firewall_for_mumble {
238
 function install_mumble {
238
 function install_mumble {
239
     apt-get -yq install mumble-server
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
     else
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
             fi
248
             fi
249
         fi
249
         fi
250
     fi
250
     fi
251
 
251
 
252
     if [[ ${ONION_ONLY} == 'no' ]]; then
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
         fi
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
             fi
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
             fi
262
             fi
263
             echo $'Obtaining certificate for the main domain'
263
             echo $'Obtaining certificate for the main domain'
264
             function_check create_site_certificate
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
                 echo $'Incorrect certificate generated'
269
                 echo $'Incorrect certificate generated'
270
                 exit 78352
270
                 exit 78352
271
             fi
271
             fi
276
 
276
 
277
 
277
 
278
     # Make an ssl cert for the server
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
         if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
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
             function_check check_certificates
282
             function_check check_certificates
283
             check_certificates mumble
283
             check_certificates mumble
284
         fi
284
         fi
318
         echo 'allowping=False' >> /etc/mumble-server.ini
318
         echo 'allowping=False' >> /etc/mumble-server.ini
319
     fi
319
     fi
320
     sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
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
         sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
322
         sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
323
         sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
323
         sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
324
     else
324
     else
335
     sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
335
     sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
336
     sed -i "s|port=.*|port=${MUMBLE_PORT}|g" /etc/mumble-server.ini
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
     # turn off logs by default
341
     # turn off logs by default
341
     sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
342
     sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini

+ 229
- 242
src/freedombone-app-nextcloud 查看文件

60
 function remove_user_nextcloud {
60
 function remove_user_nextcloud {
61
     remove_username="$1"
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
 function add_user_nextcloud {
66
 function add_user_nextcloud {
67
     new_username="$1"
67
     new_username="$1"
68
     new_user_password="$2"
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
     echo '0'
71
     echo '0'
72
 }
72
 }
73
 
73
 
76
 
76
 
77
     export OC_PASS="$2"
77
     export OC_PASS="$2"
78
     su -s /bin/sh www-data -c "php occ user:resetpassword --password-from-env $curr_username"
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
     export OC_PASS=""
80
     export OC_PASS=""
81
 }
81
 }
82
 
82
 
83
 function install_interactive_nextcloud {
83
 function install_interactive_nextcloud {
84
-    if [ ! $ONION_ONLY ]; then
84
+    if [ ! "$ONION_ONLY" ]; then
85
         ONION_ONLY='no'
85
         ONION_ONLY='no'
86
     fi
86
     fi
87
 
87
 
91
         NEXTCLOUD_DETAILS_COMPLETE=
91
         NEXTCLOUD_DETAILS_COMPLETE=
92
         while [ ! $NEXTCLOUD_DETAILS_COMPLETE ]
92
         while [ ! $NEXTCLOUD_DETAILS_COMPLETE ]
93
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
95
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
97
                 dialog --backtitle $"Freedombone Configuration" \
96
                 dialog --backtitle $"Freedombone Configuration" \
98
                        --title $"NextCloud Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
99
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
101
                        $"Code:" 2 1 "$(grep 'NEXTCLOUD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
100
                        $"Code:" 2 1 "$(grep 'NEXTCLOUD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
102
-                       2> $data
101
+                       2> "$data"
103
             else
102
             else
104
                 dialog --backtitle $"Freedombone Configuration" \
103
                 dialog --backtitle $"Freedombone Configuration" \
105
                        --title $"NextCloud Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
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
             fi
108
             fi
110
             sel=$?
109
             sel=$?
111
             case $sel in
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
             esac
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
                 TEST_DOMAIN_NAME=$NEXTCLOUD_DOMAIN_NAME
118
                 TEST_DOMAIN_NAME=$NEXTCLOUD_DOMAIN_NAME
121
                 validate_domain_name
119
                 validate_domain_name
122
-                if [[ $TEST_DOMAIN_NAME != $NEXTCLOUD_DOMAIN_NAME ]]; then
120
+                if [[ "$TEST_DOMAIN_NAME" != "$NEXTCLOUD_DOMAIN_NAME" ]]; then
123
                     NEXTCLOUD_DOMAIN_NAME=
121
                     NEXTCLOUD_DOMAIN_NAME=
124
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
122
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
125
                 else
123
                 else
126
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$NEXTCLOUD_CODE"
126
                         validate_freedns_code "$NEXTCLOUD_CODE"
129
-                        if [ ! $VALID_CODE ]; then
127
+                        if [ ! "$VALID_CODE" ]; then
130
                             NEXTCLOUD_DOMAIN_NAME=
128
                             NEXTCLOUD_DOMAIN_NAME=
131
                         fi
129
                         fi
132
                     fi
130
                     fi
135
             if [ $NEXTCLOUD_DOMAIN_NAME ]; then
133
             if [ $NEXTCLOUD_DOMAIN_NAME ]; then
136
                 NEXTCLOUD_DETAILS_COMPLETE="yes"
134
                 NEXTCLOUD_DETAILS_COMPLETE="yes"
137
             fi
135
             fi
136
+            rm -f "$data"
138
         done
137
         done
139
 
138
 
140
         # remove any invalid characters
139
         # remove any invalid characters
141
         if [ ${#NEXTCLOUD_TITLE} -gt 0 ]; then
140
         if [ ${#NEXTCLOUD_TITLE} -gt 0 ]; then
142
-            new_title=$(echo "$NEXTCLOUD_TITLE" | sed "s|'||g")
141
+            new_title=${"$NEXTCLOUD_TITLE"//\'//}
143
             NEXTCLOUD_TITLE="$new_title"
142
             NEXTCLOUD_TITLE="$new_title"
144
         fi
143
         fi
145
 
144
 
156
 
155
 
157
     read_config_param ${NEXTCLOUD_DOMAIN_NAME}
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
 function nextcloud_create_database {
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
     else
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
         fi
167
         fi
169
     fi
168
     fi
170
-    if [ ! $NEXTCLOUD_ADMIN_PASSWORD ]; then
169
+    if [ ! "$NEXTCLOUD_ADMIN_PASSWORD" ]; then
171
         return
170
         return
172
     fi
171
     fi
173
 
172
 
174
     function_check create_database
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
 function reconfigure_nextcloud {
177
 function reconfigure_nextcloud {
186
 function upgrade_nextcloud_base {
185
 function upgrade_nextcloud_base {
187
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
186
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
188
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/data
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
     sudo -u www-data ./occ maintenance:repair
189
     sudo -u www-data ./occ maintenance:repair
191
     sudo -u www-data ./occ files:cleanup
190
     sudo -u www-data ./occ files:cleanup
192
     sudo -u www-data ./occ files:scan --all
191
     sudo -u www-data ./occ files:scan --all
200
         return
199
         return
201
     fi
200
     fi
202
 
201
 
203
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
202
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
204
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
203
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
205
     fi
204
     fi
206
 
205
 
207
     # update to the next commit
206
     # update to the next commit
208
     function_check set_repo_commit
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
     upgrade_nextcloud_base
210
     upgrade_nextcloud_base
212
     sudo -u www-data ./occ upgrade
211
     sudo -u www-data ./occ upgrade
215
 
214
 
216
 function backup_local_nextcloud {
215
 function backup_local_nextcloud {
217
     NEXTCLOUD_DOMAIN_NAME='nextcloud'
216
     NEXTCLOUD_DOMAIN_NAME='nextcloud'
218
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
217
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
219
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
218
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
220
     fi
219
     fi
221
 
220
 
222
     source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
221
     source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
223
-    if [ -d $source_directory ]; then
222
+    if [ -d "$source_directory" ]; then
224
         function_check suspend_site
223
         function_check suspend_site
225
-        suspend_site ${NEXTCLOUD_DOMAIN_NAME}
224
+        suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
226
 
225
 
227
         dest_directory=nextcloudfiles
226
         dest_directory=nextcloudfiles
228
         function_check backup_directory_to_usb
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
         source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
230
         source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
232
         dest_directory=nextcloudconfig
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
         function_check backup_database_to_usb
234
         function_check backup_database_to_usb
236
         backup_database_to_usb nextcloud
235
         backup_database_to_usb nextcloud
241
 }
240
 }
242
 
241
 
243
 function restore_local_nextcloud {
242
 function restore_local_nextcloud {
244
-    if ! grep -q "nextcloud domain" $COMPLETION_FILE; then
243
+    if ! grep -q "nextcloud domain" "$COMPLETION_FILE"; then
245
         return
244
         return
246
     fi
245
     fi
247
     NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
246
     NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
248
-    if [ $NEXTCLOUD_DOMAIN_NAME ]; then
247
+    if [ "$NEXTCLOUD_DOMAIN_NAME" ]; then
249
 
248
 
250
         temp_restore_dir=/root/tempnextcloud
249
         temp_restore_dir=/root/tempnextcloud
251
         function_check nextcloud_create_database
250
         function_check nextcloud_create_database
252
         nextcloud_create_database
251
         nextcloud_create_database
253
-        restore_database nextcloud ${NEXTCLOUD_DOMAIN_NAME}
252
+        restore_database nextcloud "${NEXTCLOUD_DOMAIN_NAME}"
254
 
253
 
255
         temp_restore_dir=/root/tempnextcloudfiles
254
         temp_restore_dir=/root/tempnextcloudfiles
256
         restore_directory_from_usb $temp_restore_dir nextcloudfiles
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
         else
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
         fi
261
         fi
263
-
262
+        # shellcheck disable=SC2181
264
         if [ ! "$?" = "0" ]; then
263
         if [ ! "$?" = "0" ]; then
265
             set_user_permissions
264
             set_user_permissions
266
             backup_unmount_drive
265
             backup_unmount_drive
271
         temp_restore_dir=/root/tempnextcloudconfig
270
         temp_restore_dir=/root/tempnextcloudconfig
272
         restore_directory_from_usb $temp_restore_dir nextcloudconfig
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
         else
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
         fi
277
         fi
279
 
278
 
279
+        # shellcheck disable=SC2181
280
         if [ ! "$?" = "0" ]; then
280
         if [ ! "$?" = "0" ]; then
281
             set_user_permissions
281
             set_user_permissions
282
             backup_unmount_drive
282
             backup_unmount_drive
284
         fi
284
         fi
285
         rm -rf ${temp_restore_dir}
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
         sudo -u www-data ./occ maintenance:repair
290
         sudo -u www-data ./occ maintenance:repair
291
         sudo -u www-data ./occ files:cleanup
291
         sudo -u www-data ./occ files:cleanup
292
         sudo -u www-data ./occ files:scan --all
292
         sudo -u www-data ./occ files:scan --all
294
 }
294
 }
295
 
295
 
296
 function backup_remote_nextcloud {
296
 function backup_remote_nextcloud {
297
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
297
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
298
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
298
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
299
         temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
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
             function_check suspend_site
301
             function_check suspend_site
302
-            suspend_site ${NEXTCLOUD_DOMAIN_NAME}
302
+            suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
303
 
303
 
304
             function_check backup_database_to_friend
304
             function_check backup_database_to_friend
305
             backup_database_to_friend nextcloud
305
             backup_database_to_friend nextcloud
306
 
306
 
307
             function_check backup_directory_to_friend
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
             temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
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
             function_check restart_site
313
             function_check restart_site
314
             restart_site
314
             restart_site
319
 }
319
 }
320
 
320
 
321
 function restore_remote_nextcloud {
321
 function restore_remote_nextcloud {
322
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
322
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
323
         echo $"Restoring nextcloud"
323
         echo $"Restoring nextcloud"
324
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
324
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
325
 
325
 
327
         nextcloud_create_database
327
         nextcloud_create_database
328
 
328
 
329
         function_check restore_database_from_friend
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
         if [ -d /root/tempnextcloud ]; then
331
         if [ -d /root/tempnextcloud ]; then
332
             rm -rf /root/tempnextcloud
332
             rm -rf /root/tempnextcloud
333
         fi
333
         fi
335
         temp_restore_dir=/root/tempnextcloudfiles
335
         temp_restore_dir=/root/tempnextcloudfiles
336
         restore_directory_from_friend $temp_restore_dir nextcloudfiles
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
         else
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
         fi
342
         fi
343
-
343
+        # shellcheck disable=SC2181
344
         if [ ! "$?" = "0" ]; then
344
         if [ ! "$?" = "0" ]; then
345
             exit 768254
345
             exit 768254
346
         fi
346
         fi
349
         temp_restore_dir=/root/tempnextcloudconfig
349
         temp_restore_dir=/root/tempnextcloudconfig
350
         restore_directory_from_friend $temp_restore_dir nextcloudconfig
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
         else
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
         fi
356
         fi
357
 
357
 
358
+        # shellcheck disable=SC2181
358
         if [ ! "$?" = "0" ]; then
359
         if [ ! "$?" = "0" ]; then
359
             exit 573427
360
             exit 573427
360
         fi
361
         fi
361
         rm -rf ${temp_restore_dir}
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
         sudo -u www-data ./occ maintenance:repair
367
         sudo -u www-data ./occ maintenance:repair
367
         sudo -u www-data ./occ files:cleanup
368
         sudo -u www-data ./occ files:cleanup
368
         sudo -u www-data ./occ files:scan --all
369
         sudo -u www-data ./occ files:scan --all
381
     read_config_param "NEXTCLOUD_DOMAIN_NAME"
382
     read_config_param "NEXTCLOUD_DOMAIN_NAME"
382
     read_config_param "MY_USERNAME"
383
     read_config_param "MY_USERNAME"
383
     echo "Removing $NEXTCLOUD_DOMAIN_NAME"
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
     fi
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
     fi
392
     fi
392
     function_check drop_database
393
     function_check drop_database
393
     drop_database nextcloud
394
     drop_database nextcloud
395
     remove_onion_service nextcloud ${NEXTCLOUD_ONION_PORT}
396
     remove_onion_service nextcloud ${NEXTCLOUD_ONION_PORT}
396
     remove_app nextcloud
397
     remove_app nextcloud
397
     remove_completion_param install_nextcloud
398
     remove_completion_param install_nextcloud
398
-    sed -i '/nextcloud/d' $COMPLETION_FILE
399
+    sed -i '/nextcloud/d' "$COMPLETION_FILE"
399
     remove_backup_database_local nextcloud
400
     remove_backup_database_local nextcloud
400
 
401
 
401
     function_check remove_ddns_domain
402
     function_check remove_ddns_domain
402
-    remove_ddns_domain $NEXTCLOUD_DOMAIN_NAME
403
+    remove_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
403
     systemctl restart nginx
404
     systemctl restart nginx
404
     systemctl restart php7.0-fpm
405
     systemctl restart php7.0-fpm
405
 }
406
 }
406
 
407
 
407
 function install_nextcloud_main {
408
 function install_nextcloud_main {
408
-    if [ ! $NEXTCLOUD_DOMAIN_NAME ]; then
409
+    if [ ! "$NEXTCLOUD_DOMAIN_NAME" ]; then
409
         echo $'No domain name was given for nextcloud'
410
         echo $'No domain name was given for nextcloud'
410
         exit 7359
411
         exit 7359
411
     fi
412
     fi
434
     fi
435
     fi
435
     sed -i 's|;env[PATH]|env[PATH]|g' /etc/php/7.0/fpm/pool.d/www.conf
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
     fi
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
         if [ -d /repos/nextcloud ]; then
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
             git pull
447
             git pull
447
         else
448
         else
448
             function_check git_clone
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
         fi
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
             echo $'Unable to clone nextcloud repo'
454
             echo $'Unable to clone nextcloud repo'
454
             exit 87525
455
             exit 87525
455
         fi
456
         fi
456
     fi
457
     fi
457
 
458
 
458
-    cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
459
+    cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 3468346834
459
     git submodule update --init
460
     git submodule update --init
460
     git checkout $NEXTCLOUD_COMMIT -b $NEXTCLOUD_COMMIT
461
     git checkout $NEXTCLOUD_COMMIT -b $NEXTCLOUD_COMMIT
461
     set_completion_param "nextcloud commit" "$NEXTCLOUD_COMMIT"
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
     function_check nextcloud_create_database
467
     function_check nextcloud_create_database
467
     nextcloud_create_database
468
     nextcloud_create_database
474
     fi
475
     fi
475
 
476
 
476
     function_check add_ddns_domain
477
     function_check add_ddns_domain
477
-    add_ddns_domain $NEXTCLOUD_DOMAIN_NAME
478
+    add_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
478
 
479
 
479
     nextcloud_nginx_site=/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
480
     nextcloud_nginx_site=/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
480
     if [[ $ONION_ONLY == "no" ]]; then
481
     if [[ $ONION_ONLY == "no" ]]; then
481
         function_check nginx_http_redirect
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
         function_check nginx_ssl
490
         function_check nginx_ssl
490
-        nginx_ssl $NEXTCLOUD_DOMAIN_NAME mobile
491
+        nginx_ssl "$NEXTCLOUD_DOMAIN_NAME" mobile
491
 
492
 
492
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
550
     else
550
-        echo -n '' > $nextcloud_nginx_site
551
+        echo -n '' > "$nextcloud_nginx_site"
551
     fi
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     # NextCloud doesn't like content-security-policy at all
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
     function_check configure_php
618
     function_check configure_php
618
     configure_php
619
     configure_php
619
 
620
 
620
     function_check create_site_certificate
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
             echo $'Certificate not generated for nextcloud'
626
             echo $'Certificate not generated for nextcloud'
626
             exit 725762
627
             exit 725762
627
         fi
628
         fi
636
     backup_database_local nextcloud
637
     backup_database_local nextcloud
637
 
638
 
638
     function_check nginx_ensite
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
     NEXTCLOUD_ONION_HOSTNAME=$(add_onion_service nextcloud 80 ${NEXTCLOUD_ONION_PORT})
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
     systemctl restart php7.0-fpm
644
     systemctl restart php7.0-fpm
657
     systemctl restart nginx
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
     if [ -d config ]; then
652
     if [ -d config ]; then
665
         chown -R www-data:www-data config
653
         chown -R www-data:www-data config
666
     fi
654
     fi
669
     fi
657
     fi
670
 
658
 
671
     chmod +x occ
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
     if [ ! -d data ]; then
661
     if [ ! -d data ]; then
674
         echo $'Nextcloud data directory was not found. This probably means that the installation failed.'
662
         echo $'Nextcloud data directory was not found. This probably means that the installation failed.'
675
         echo ''
663
         echo ''
683
     sudo -u www-data ./occ status
671
     sudo -u www-data ./occ status
684
     sudo -u www-data ./occ app:list
672
     sudo -u www-data ./occ app:list
685
     sudo -u www-data ./occ app:enable encryption
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
         echo $'Encryption not enabled'
675
         echo $'Encryption not enabled'
689
         exit 73527
676
         exit 73527
690
     fi
677
     fi
691
     sudo -u www-data ./occ encryption:status
678
     sudo -u www-data ./occ encryption:status
692
     sudo -u www-data ./occ config:system:set appstoreenabled --value=false
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
     chmod 0644 .htaccess
682
     chmod 0644 .htaccess
696
     chmod 0750 data
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
     sudo -u www-data ./occ files:cleanup
687
     sudo -u www-data ./occ files:cleanup
701
     sudo -u www-data ./occ files:scan --all
688
     sudo -u www-data ./occ files:scan --all
702
     sudo -u www-data ./occ maintenance:repair
689
     sudo -u www-data ./occ maintenance:repair
705
     systemctl restart mariadb
692
     systemctl restart mariadb
706
 
693
 
707
     # move the data directory
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
     set_completion_param "nextcloud domain" "$NEXTCLOUD_DOMAIN_NAME"
698
     set_completion_param "nextcloud domain" "$NEXTCLOUD_DOMAIN_NAME"
712
 
699
 
714
 }
701
 }
715
 
702
 
716
 function install_nextcloud {
703
 function install_nextcloud {
717
-    if [ ! $ONION_ONLY ]; then
704
+    if [ ! "$ONION_ONLY" ]; then
718
         ONION_ONLY='no'
705
         ONION_ONLY='no'
719
     fi
706
     fi
720
 
707
 

+ 331
- 334
src/freedombone-app-peertube 查看文件

55
                     MY_EMAIL_ADDRESS)
55
                     MY_EMAIL_ADDRESS)
56
 
56
 
57
 function peertube_create_database {
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
     else
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
         fi
63
         fi
64
     fi
64
     fi
65
-    if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
65
+    if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
66
         return
66
         return
67
     fi
67
     fi
68
 
68
 
82
 }
82
 }
83
 
83
 
84
 function remove_user_peertube {
84
 function remove_user_peertube {
85
-    remove_username="$1"
85
+    echo -n ''
86
+#    remove_username="$1"
86
 }
87
 }
87
 
88
 
88
 function add_user_peertube {
89
 function add_user_peertube {
91
         return
92
         return
92
     fi
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
     echo '0'
98
     echo '0'
98
 }
99
 }
99
 
100
 
100
 function install_interactive_peertube {
101
 function install_interactive_peertube {
101
-    if [ ! $ONION_ONLY ]; then
102
+    if [ ! "$ONION_ONLY" ]; then
102
         ONION_ONLY='no'
103
         ONION_ONLY='no'
103
     fi
104
     fi
104
 
105
 
113
 }
114
 }
114
 
115
 
115
 function peertube_set_admin_email {
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
     dialog --title $"Set PeerTube administrator email address" \
119
     dialog --title $"Set PeerTube administrator email address" \
120
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
122
     sel=$?
123
     case $sel in
123
     case $sel in
124
-        0)  peertube_email=$(<$data)
124
+        0)  peertube_email=$(<"$data")
125
             if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
125
             if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
126
                 if [ ${#peertube_email} -gt 8 ]; then
126
                 if [ ${#peertube_email} -gt 8 ]; then
127
                     sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
127
                     sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
132
             fi
132
             fi
133
             ;;
133
             ;;
134
     esac
134
     esac
135
-    rm $data
135
+    rm -f "$data"
136
 }
136
 }
137
 
137
 
138
 function peertube_disable_signups {
138
 function peertube_disable_signups {
139
     dialog --title $"Disable PeerTube signups" \
139
     dialog --title $"Disable PeerTube signups" \
140
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
142
     sel=$?
143
     case $sel in
143
     case $sel in
144
         0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
144
         0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
152
 function configure_interactive_peertube {
152
 function configure_interactive_peertube {
153
     while true
153
     while true
154
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
156
         dialog --backtitle $"Freedombone Control Panel" \
158
                --title $"PeerTube" \
157
                --title $"PeerTube" \
159
                --radiolist $"Choose an operation:" 10 70 4 \
158
                --radiolist $"Choose an operation:" 10 70 4 \
160
                1 $"Set administrator email address" off \
159
                1 $"Set administrator email address" off \
161
                2 $"Disable or enable signups" off \
160
                2 $"Disable or enable signups" off \
162
-               3 $"Exit" on 2> $data
161
+               3 $"Exit" on 2> "$data"
163
         sel=$?
162
         sel=$?
164
         case $sel in
163
         case $sel in
165
             1) break;;
164
             1) break;;
166
             255) break;;
165
             255) break;;
167
         esac
166
         esac
168
-        case $(cat $data) in
167
+        case $(cat "$data") in
169
             1) peertube_set_admin_email;;
168
             1) peertube_set_admin_email;;
170
             2) peertube_disable_signups;;
169
             2) peertube_disable_signups;;
171
-            3) break;;
170
+            3) rm -f "$data"
171
+               break;;
172
         esac
172
         esac
173
+        rm -f "$data"
173
     done
174
     done
174
 }
175
 }
175
 
176
 
176
 function change_password_peertube {
177
 function change_password_peertube {
177
-    PEERTUBE_USERNAME="$1"
178
+#    PEERTUBE_USERNAME="$1"
178
     PEERTUBE_PASSWORD="$2"
179
     PEERTUBE_PASSWORD="$2"
179
     if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
180
     if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
180
         echo $'Peertube password is too short'
181
         echo $'Peertube password is too short'
181
         return
182
         return
182
     fi
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
 function reconfigure_peertube {
187
 function reconfigure_peertube {
195
 
196
 
196
     read_config_param PEERTUBE_DOMAIN_NAME
197
     read_config_param PEERTUBE_DOMAIN_NAME
197
     systemctl stop peertube
198
     systemctl stop peertube
198
-    cd $PEERTUBE_DIR
199
+    cd "$PEERTUBE_DIR" || exit 7824552627
199
 
200
 
200
     function_check set_repo_commit
201
     function_check set_repo_commit
201
     set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
202
     set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
207
 
208
 
208
 function backup_local_peertube {
209
 function backup_local_peertube {
209
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
212
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
212
     fi
213
     fi
213
 
214
 
219
 
220
 
220
     peertube_path=$PEERTUBE_DIR/videos
221
     peertube_path=$PEERTUBE_DIR/videos
221
     if [ -d $peertube_path ]; then
222
     if [ -d $peertube_path ]; then
222
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
223
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
223
         systemctl stop peertube
224
         systemctl stop peertube
224
         backup_directory_to_usb $peertube_path peertubevideos
225
         backup_directory_to_usb $peertube_path peertubevideos
225
         systemctl start peertube
226
         systemctl start peertube
229
 
230
 
230
 function restore_local_peertube {
231
 function restore_local_peertube {
231
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
234
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
234
     fi
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
         systemctl stop peertube
238
         systemctl stop peertube
238
 
239
 
239
         USE_POSTGRESQL=1
240
         USE_POSTGRESQL=1
259
 
260
 
260
 function backup_remote_peertube {
261
 function backup_remote_peertube {
261
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
264
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
264
     fi
265
     fi
265
 
266
 
272
     temp_backup_dir=$PEERTUBE_DIR/videos
273
     temp_backup_dir=$PEERTUBE_DIR/videos
273
     if [ -d $temp_backup_dir ]; then
274
     if [ -d $temp_backup_dir ]; then
274
         systemctl stop peertube
275
         systemctl stop peertube
275
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
276
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
276
         backup_directory_to_friend $temp_backup_dir peertubevideos
277
         backup_directory_to_friend $temp_backup_dir peertubevideos
277
         restart_site
278
         restart_site
278
         systemctl start peertube
279
         systemctl start peertube
284
 
285
 
285
 function restore_remote_peertube {
286
 function restore_remote_peertube {
286
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
289
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
289
     fi
290
     fi
290
-    suspend_site ${PEERTUBE_DOMAIN_NAME}
291
+    suspend_site "${PEERTUBE_DOMAIN_NAME}"
291
 
292
 
292
     systemctl stop peertube
293
     systemctl stop peertube
293
 
294
 
295
+    # shellcheck disable=SC2034
294
     USE_POSTGRESQL=1
296
     USE_POSTGRESQL=1
295
     function_check restore_database_from_friend
297
     function_check restore_database_from_friend
296
     restore_database_from_friend peertube
298
     restore_database_from_friend peertube
326
     remove_nodejs peertube
328
     remove_nodejs peertube
327
 
329
 
328
     read_config_param "PEERTUBE_DOMAIN_NAME"
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
     fi
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
     fi
338
     fi
337
     remove_config_param PEERTUBE_DOMAIN_NAME
339
     remove_config_param PEERTUBE_DOMAIN_NAME
338
     remove_config_param PEERTUBE_CODE
340
     remove_config_param PEERTUBE_CODE
339
     function_check remove_onion_service
341
     function_check remove_onion_service
340
     remove_onion_service peertube ${PEERTUBE_ONION_PORT}
342
     remove_onion_service peertube ${PEERTUBE_ONION_PORT}
341
     remove_completion_param "install_peertube"
343
     remove_completion_param "install_peertube"
342
-    sed -i '/peertube/d' $COMPLETION_FILE
344
+    sed -i '/peertube/d' "$COMPLETION_FILE"
343
 
345
 
344
     function_check drop_database_postgresql
346
     function_check drop_database_postgresql
345
     drop_database_postgresql peertube peertube
347
     drop_database_postgresql peertube peertube
352
     fi
354
     fi
353
 
355
 
354
     function_check remove_ddns_domain
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
 function peertube_setup_web {
360
 function peertube_setup_web {
359
     peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
361
     peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
360
 
362
 
361
     if [[ $ONION_ONLY == "no" ]]; then
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
         function_check nginx_ssl
376
         function_check nginx_ssl
375
-        nginx_ssl $PEERTUBE_DOMAIN_NAME mobile
377
+        nginx_ssl "$PEERTUBE_DOMAIN_NAME" mobile
376
 
378
 
377
         function_check nginx_disable_sniffing
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
     else
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
     # CSP currently causes an error
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
     function_check create_site_certificate
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
     function_check nginx_ensite
484
     function_check nginx_ensite
483
-    nginx_ensite $PEERTUBE_DOMAIN_NAME
485
+    nginx_ensite "$PEERTUBE_DOMAIN_NAME"
484
 }
486
 }
485
 
487
 
486
 function mesh_peertube_setup_web {
488
 function mesh_peertube_setup_web {
489
+    # shellcheck disable=SC2154
487
     peertube_nginx_file=$rootdir/etc/nginx/sites-available/peertube
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
 function peertube_create_config {
542
 function peertube_create_config {
541
 
544
 
542
     peertube_config_file=$peertube_prefix$PEERTUBE_DIR/config/production.yaml
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
         else
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
         fi
561
         fi
559
     else
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
     else
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
 function mesh_install_peertube {
620
 function mesh_install_peertube {
618
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
621
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
619
         return
622
         return
620
     fi
623
     fi
621
-    if [[ $ARCHITECTURE != 'x86_64' && $ARCHITECTURE != 'amd64' ]]; then
624
+    if [[ "$ARCHITECTURE" != 'x86_64' && "$ARCHITECTURE" != 'amd64' ]]; then
622
         return
625
         return
623
     fi
626
     fi
624
 
627
 
627
     function_check install_postgresql
630
     function_check install_postgresql
628
     install_postgresql
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
     fi
635
     fi
633
 
636
 
634
-    git clone $PEERTUBE_REPO $rootdir$PEERTUBE_DIR
637
+    git clone "$PEERTUBE_REPO" "$rootdir$PEERTUBE_DIR"
635
 
638
 
636
     chroot "$rootdir" groupadd peertube
639
     chroot "$rootdir" groupadd peertube
637
     chroot "$rootdir" useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
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
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
643
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
641
 
644
 
642
-
643
     get_npm_arch
645
     get_npm_arch
644
 
646
 
645
-    cat <<EOF > $rootdir/usr/bin/install_peertube
647
+    cat <<EOF > "$rootdir/usr/bin/install_peertube"
646
 #!/bin/bash
648
 #!/bin/bash
647
 cd $PEERTUBE_DIR
649
 cd $PEERTUBE_DIR
648
 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
650
 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
683
     exit 5293593
685
     exit 5293593
684
 fi
686
 fi
685
 EOF
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
         echo $'PeerTube install failed'
690
         echo $'PeerTube install failed'
690
         exit 735638
691
         exit 735638
691
     fi
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
     chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
716
     chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
716
 
717
 
730
         ONION_ONLY='no'
731
         ONION_ONLY='no'
731
     fi
732
     fi
732
 
733
 
733
-    if [ ! $PEERTUBE_DOMAIN_NAME ]; then
734
+    if [ ! "$PEERTUBE_DOMAIN_NAME" ]; then
734
         echo $'The peertube domain name was not specified'
735
         echo $'The peertube domain name was not specified'
735
         exit 783523
736
         exit 783523
736
     fi
737
     fi
740
     function_check install_postgresql
741
     function_check install_postgresql
741
     install_postgresql
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
     fi
746
     fi
746
 
747
 
747
     if [ -d $PEERTUBE_DIR ]; then
748
     if [ -d $PEERTUBE_DIR ]; then
759
     if [ -d /repos/peertube ]; then
760
     if [ -d /repos/peertube ]; then
760
         mkdir -p $PEERTUBE_DIR
761
         mkdir -p $PEERTUBE_DIR
761
         cp -r -p /repos/peertube/. $PEERTUBE_DIR
762
         cp -r -p /repos/peertube/. $PEERTUBE_DIR
762
-        cd $PEERTUBE_DIR
763
+        cd "$PEERTUBE_DIR" || exit 642874682
763
         git pull
764
         git pull
764
     else
765
     else
765
         function_check git_clone
766
         function_check git_clone
766
         git_clone $PEERTUBE_REPO $PEERTUBE_DIR
767
         git_clone $PEERTUBE_REPO $PEERTUBE_DIR
767
     fi
768
     fi
768
 
769
 
769
-    cd $PEERTUBE_DIR
770
+    cd "$PEERTUBE_DIR" || exit 27492742
770
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
771
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
771
     set_completion_param "peertube commit" "$PEERTUBE_COMMIT"
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
         echo $'Failed to install yarn'
775
         echo $'Failed to install yarn'
776
         exit 79353234
776
         exit 79353234
777
     fi
777
     fi
778
     yarn add -D webpack --network-concurrency 1
778
     yarn add -D webpack --network-concurrency 1
779
-    yarn install
780
-    if [ ! "$?" = "0" ]; then
779
+    if ! yarn install; then
781
         echo $'Failed to run yarn install'
780
         echo $'Failed to run yarn install'
782
         exit 63754235
781
         exit 63754235
783
     fi
782
     fi
784
-    npm install
785
-    if [ ! "$?" = "0" ]; then
783
+    if ! npm install; then
786
         echo $'Failed to install peertube'
784
         echo $'Failed to install peertube'
787
         exit 7835243
785
         exit 7835243
788
     fi
786
     fi
789
-    npm run build
790
-    if [ ! "$?" = "0" ]; then
787
+    if ! npm run build; then
791
         echo $'Failed to build peertube'
788
         echo $'Failed to build peertube'
792
         exit 5293593
789
         exit 5293593
793
     fi
790
     fi
794
 
791
 
795
     PEERTUBE_ONION_HOSTNAME=$(add_onion_service peertube 80 ${PEERTUBE_ONION_PORT})
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
     peertube_create_config
814
     peertube_create_config
818
 
815
 
820
 
817
 
821
     peertube_setup_web
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
     function_check add_ddns_domain
822
     function_check add_ddns_domain
826
-    add_ddns_domain $PEERTUBE_DOMAIN_NAME
823
+    add_ddns_domain "$PEERTUBE_DOMAIN_NAME"
827
 
824
 
828
     systemctl enable peertube
825
     systemctl enable peertube
829
     systemctl daemon-reload
826
     systemctl daemon-reload

+ 282
- 272
src/freedombone-app-pelican 查看文件

50
                    PELICAN_BLOG_CODE)
50
                    PELICAN_BLOG_CODE)
51
 
51
 
52
 function pelican_remove_bad_blog_links {
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
 function logging_on_pelican {
61
 function logging_on_pelican {
73
     fi
73
     fi
74
     function_check nginx_http_redirect
74
     function_check nginx_http_redirect
75
     nginx_http_redirect $PELICAN_DOMAIN_NAME
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
     function_check nginx_ssl
85
     function_check nginx_ssl
86
-    nginx_ssl $PELICAN_DOMAIN_NAME
86
+    nginx_ssl "$PELICAN_DOMAIN_NAME"
87
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check create_site_certificate
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
 function install_pelican_website_onion {
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
 function pelican_editor_config {
156
 function pelican_editor_config {
157
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican ]; then
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
     fi
174
     fi
175
 }
175
 }
176
 
176
 
179
     echo ''
179
     echo ''
180
     echo $'Regenerating blog...'
180
     echo $'Regenerating blog...'
181
 
181
 
182
-    cd $PELICAN_BLOG_INSTALL_DIR
182
+    cd "$PELICAN_BLOG_INSTALL_DIR" || exit 463856348
183
     make html
183
     make html
184
     cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
184
     cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
185
     chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
185
     chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
189
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
189
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
190
 
190
 
191
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry ]; then
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
     fi
205
     fi
206
 
206
 
207
     if [ -f /usr/bin/emacs ]; then
207
     if [ -f /usr/bin/emacs ]; then
222
 
222
 
223
     # move to the content directory
223
     # move to the content directory
224
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
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
     # increment the index
227
     # increment the index
228
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
228
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
238
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
238
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
239
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
239
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
240
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
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
         return
242
         return
243
     fi
243
     fi
244
 
244
 
245
     if [ -f /usr/bin/emacs ]; then
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
     else
247
     else
248
-        editor $LAST_BLOG_ENTRY
248
+        editor "$LAST_BLOG_ENTRY"
249
     fi
249
     fi
250
 
250
 
251
     pelican_regenerate_blog
251
     pelican_regenerate_blog
258
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
258
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
259
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
259
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
260
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
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
         return
262
         return
263
     fi
263
     fi
264
 
264
 
265
     dialog --title $"Delete the previous blog entry" \
265
     dialog --title $"Delete the previous blog entry" \
266
            --backtitle $"Freedombone Mesh" \
266
            --backtitle $"Freedombone Mesh" \
267
            --defaultno \
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
     sel=$?
269
     sel=$?
270
     case $sel in
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
                CURRENT_INDEX=$PREVIOUS_INDEX
273
                CURRENT_INDEX=$PREVIOUS_INDEX
274
                echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
274
                echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
275
            else
275
            else
297
     for a in "${THEMES[@]}"
297
     for a in "${THEMES[@]}"
298
     do
298
     do
299
         is_selected='off'
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
                 is_selected='on'
302
                 is_selected='on'
303
             fi
303
             fi
304
         else
304
         else
308
         fi
308
         fi
309
 
309
 
310
         themelist="$themelist $n $a $is_selected"
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
     done
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
     dialog --backtitle $"Freedombone Mesh" \
316
     dialog --backtitle $"Freedombone Mesh" \
318
            --title $"Select Blog Theme" \
317
            --title $"Select Blog Theme" \
319
            --radiolist $'Choose:' \
318
            --radiolist $'Choose:' \
320
-           80 40 20 $themelist 2> $data
319
+           80 40 20 "$themelist" 2> "$data"
321
     sel=$?
320
     sel=$?
322
     case $sel in
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
     esac
326
     esac
326
-    CHOSEN_THEME_INDEX=$(cat $data)
327
+    CHOSEN_THEME_INDEX=$(cat "$data")
328
+    rm -f "$data"
327
     echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
329
     echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
328
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
330
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
329
 
331
 
330
     CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
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
     pelican_remove_bad_blog_links
335
     pelican_remove_bad_blog_links
334
 
336
 
335
     if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
337
     if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
341
 }
343
 }
342
 
344
 
343
 function configure_interactive_pelican {
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
     dialog --backtitle $"Freedombone Configuration" \
347
     dialog --backtitle $"Freedombone Configuration" \
347
            --title $"Pelican Blogging" \
348
            --title $"Pelican Blogging" \
348
            --radiolist $"Choose an operation:" 18 50 11 \
349
            --radiolist $"Choose an operation:" 18 50 11 \
350
            2 $"Edit the previous blog entry" off \
351
            2 $"Edit the previous blog entry" off \
351
            3 $"Delete the previous blog entry" off \
352
            3 $"Delete the previous blog entry" off \
352
            4 $"Change theme" off \
353
            4 $"Change theme" off \
353
-           5 $"Exit" off 2> $data
354
+           5 $"Exit" off 2> "$data"
354
     sel=$?
355
     sel=$?
355
     case $sel in
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
     esac
361
     esac
359
-    case $(cat $data) in
362
+    case $(cat "$data") in
360
         1) pelican_new_blog;;
363
         1) pelican_new_blog;;
361
         2) pelican_edit_blog;;
364
         2) pelican_edit_blog;;
362
         3) pelican_delete_blog;;
365
         3) pelican_delete_blog;;
363
         4) pelican_change_theme;;
366
         4) pelican_change_theme;;
364
-        5) break;;
365
     esac
367
     esac
368
+    rm -f "$data"
366
 }
369
 }
367
 
370
 
368
 function install_interactive_pelican {
371
 function install_interactive_pelican {
369
-    if [ ! $ONION_ONLY ]; then
372
+    if [ ! "$ONION_ONLY" ]; then
370
         ONION_ONLY='no'
373
         ONION_ONLY='no'
371
     fi
374
     fi
372
 
375
 
376
         PELICAN_DETAILS_COMPLETE=
379
         PELICAN_DETAILS_COMPLETE=
377
         while [ ! $PELICAN_DETAILS_COMPLETE ]
380
         while [ ! $PELICAN_DETAILS_COMPLETE ]
378
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
383
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
382
                 dialog --backtitle $"Freedombone Configuration" \
384
                 dialog --backtitle $"Freedombone Configuration" \
383
                        --title $"Pelican Blog Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
387
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
386
                        $"Code:" 2 1 "$(grep 'PELICAN_BLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
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
             else
390
             else
389
                 dialog --backtitle $"Freedombone Configuration" \
391
                 dialog --backtitle $"Freedombone Configuration" \
390
                        --title $"Pelican Blog Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
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
             fi
396
             fi
395
             sel=$?
397
             sel=$?
396
             case $sel in
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
             esac
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
                 if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
406
                 if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
403
                     PELICAN_DOMAIN_NAME=""
407
                     PELICAN_DOMAIN_NAME=""
404
                 fi
408
                 fi
405
                 TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
409
                 TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
406
                 validate_domain_name
410
                 validate_domain_name
407
-                if [[ $TEST_DOMAIN_NAME != $PELICAN_DOMAIN_NAME ]]; then
411
+                if [[ "$TEST_DOMAIN_NAME" != "$PELICAN_DOMAIN_NAME" ]]; then
408
                     PELICAN_DOMAIN_NAME=
412
                     PELICAN_DOMAIN_NAME=
409
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
413
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
410
                 else
414
                 else
411
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$PELICAN_BLOG_CODE"
417
                         validate_freedns_code "$PELICAN_BLOG_CODE"
414
-                        if [ ! $VALID_CODE ]; then
418
+                        if [ ! "$VALID_CODE" ]; then
415
                             PELICAN_DOMAIN_NAME=
419
                             PELICAN_DOMAIN_NAME=
416
                         fi
420
                         fi
417
                     fi
421
                     fi
420
             if [ $PELICAN_DOMAIN_NAME ]; then
424
             if [ $PELICAN_DOMAIN_NAME ]; then
421
                 PELICAN_DETAILS_COMPLETE="yes"
425
                 PELICAN_DETAILS_COMPLETE="yes"
422
             fi
426
             fi
427
+            rm -f "$data"
423
         done
428
         done
424
 
429
 
425
         # save the results in the config file
430
         # save the results in the config file
454
 
459
 
455
 function restore_local_pelican {
460
 function restore_local_pelican {
456
     if [ -d /etc/blog ]; then
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
             temp_restore_dir=/root/temppelican
463
             temp_restore_dir=/root/temppelican
459
             function_check restore_directory_from_usb
464
             function_check restore_directory_from_usb
460
             restore_directory_from_usb $temp_restore_dir pelican
465
             restore_directory_from_usb $temp_restore_dir pelican
463
             else
468
             else
464
                 cp -r $temp_restore_dir/* /etc/blog/
469
                 cp -r $temp_restore_dir/* /etc/blog/
465
             fi
470
             fi
471
+            # shellcheck disable=SC2181
466
             if [ ! "$?" = "0" ]; then
472
             if [ ! "$?" = "0" ]; then
467
                 rm -rf $temp_restore_dir
473
                 rm -rf $temp_restore_dir
468
                 function_check set_user_permissions
474
                 function_check set_user_permissions
475
         fi
481
         fi
476
     fi
482
     fi
477
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
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
             temp_restore_dir=/root/temppelican-site
485
             temp_restore_dir=/root/temppelican-site
480
             function_check restore_directory_from_usb
486
             function_check restore_directory_from_usb
481
             restore_directory_from_usb $temp_restore_dir pelican-site
487
             restore_directory_from_usb $temp_restore_dir pelican-site
484
             else
490
             else
485
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
491
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
486
             fi
492
             fi
493
+            # shellcheck disable=SC2181
487
             if [ ! "$?" = "0" ]; then
494
             if [ ! "$?" = "0" ]; then
488
                 rm -rf $temp_restore_dir
495
                 rm -rf $temp_restore_dir
489
                 function_check set_user_permissions
496
                 function_check set_user_permissions
508
 
515
 
509
 function restore_remote_pelican {
516
 function restore_remote_pelican {
510
     if [ -d /etc/blog ]; then
517
     if [ -d /etc/blog ]; then
511
-        if [ -d $SERVER_DIRECTORY/backup/pelican ]; then
518
+        if [ -d "$SERVER_DIRECTORY/backup/pelican" ]; then
512
             temp_restore_dir=/root/temppelican
519
             temp_restore_dir=/root/temppelican
513
             function_check restore_directory_from_friend
520
             function_check restore_directory_from_friend
514
             restore_directory_from_friend $temp_restore_dir pelican
521
             restore_directory_from_friend $temp_restore_dir pelican
517
             else
524
             else
518
                 cp -r $temp_restore_dir/* /etc/blog/
525
                 cp -r $temp_restore_dir/* /etc/blog/
519
             fi
526
             fi
527
+            # shellcheck disable=SC2181
520
             if [ ! "$?" = "0" ]; then
528
             if [ ! "$?" = "0" ]; then
521
                 exit 782352
529
                 exit 782352
522
             fi
530
             fi
524
         fi
532
         fi
525
     fi
533
     fi
526
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
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
             temp_restore_dir=/root/temppelican-site
536
             temp_restore_dir=/root/temppelican-site
529
             function_check restore_directory_from_friend
537
             function_check restore_directory_from_friend
530
             restore_directory_from_friend $temp_restore_dir pelican-site
538
             restore_directory_from_friend $temp_restore_dir pelican-site
533
             else
541
             else
534
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
542
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
535
             fi
543
             fi
544
+            # shellcheck disable=SC2181
536
             if [ ! "$?" = "0" ]; then
545
             if [ ! "$?" = "0" ]; then
537
                 exit 76382562
546
                 exit 76382562
538
             fi
547
             fi
561
 }
570
 }
562
 
571
 
563
 function create_pelican_conf {
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
 function create_pelican_makefile {
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
 function create_pelican_publish_conf {
660
 function create_pelican_publish_conf {
652
     STATIC_BLOG_FILE=$1
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
 function pelican_themes {
681
 function pelican_themes {
747
 }
756
 }
748
 
757
 
749
 function mesh_install_pelican {
758
 function mesh_install_pelican {
750
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
759
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" && "$VARIANT" != "usb" ]]; then
751
         return
760
         return
752
     fi
761
     fi
753
 
762
 
763
+    # shellcheck disable=SC2154
754
     chroot "$rootdir" apt-get -yq install python-pip
764
     chroot "$rootdir" apt-get -yq install python-pip
755
     chroot "$rootdir" pip install ipython
765
     chroot "$rootdir" pip install ipython
756
     chroot "$rootdir" pip install Markdown
766
     chroot "$rootdir" pip install Markdown
760
     PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
770
     PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
761
     PELICAN_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
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
     fi
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
     fi
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
     fi
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
     pelican_themes
791
     pelican_themes
782
 
792
 
783
     #git clone --recursive $PELICAN_PLUGINS_REPO $rootdir$PELICAN_BLOG_INSTALL_DIR/plugins
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
 function install_pelican {
799
 function install_pelican {
790
-    if [ $INSTALLING_MESH ]; then
800
+    if [ "$INSTALLING_MESH" ]; then
791
         mesh_install_pelican
801
         mesh_install_pelican
792
         return
802
         return
793
     fi
803
     fi
800
 
810
 
801
     PELICAN_BLOG_PATH=/var/www/$PELICAN_DOMAIN_NAME/htdocs
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
     fi
815
     fi
806
 
816
 
807
     if [ ! -d $PELICAN_BLOG_PATH ]; then
817
     if [ ! -d $PELICAN_BLOG_PATH ]; then
808
         mkdir -p $PELICAN_BLOG_PATH
818
         mkdir -p $PELICAN_BLOG_PATH
809
     fi
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
     fi
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
     pelican_themes
831
     pelican_themes
822
 
832
 
823
     #git clone --recursive $PELICAN_PLUGINS_REPO $PELICAN_BLOG_INSTALL_DIR/plugins
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
     chown -R www-data:www-data $PELICAN_BLOG_PATH
836
     chown -R www-data:www-data $PELICAN_BLOG_PATH
827
 
837
 
828
     pelican_editor_config
838
     pelican_editor_config
834
     install_pelican_website_onion
844
     install_pelican_website_onion
835
 
845
 
836
     pelican_regenerate_blog
846
     pelican_regenerate_blog
837
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR/output ]; then
847
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/output" ]; then
838
         echo $'Failed to generate pelican blog'
848
         echo $'Failed to generate pelican blog'
839
         exit 521892
849
         exit 521892
840
     fi
850
     fi

+ 54
- 48
src/freedombone-app-pihole 查看文件

66
     if [ ! -d /etc/.pihole ]; then
66
     if [ ! -d /etc/.pihole ]; then
67
         mkdir /etc/.pihole
67
         mkdir /etc/.pihole
68
     fi
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
     if [ ! -f $PIHOLE_CUSTOM_ADLIST ]; then
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
     fi
73
     fi
74
-    cp $INSTALL_DIR/pihole/advanced/Scripts/* /opt/$piholeBasename
74
+    cp "$INSTALL_DIR/pihole/advanced/Scripts/*" /opt/$piholeBasename
75
     if [ -f /etc/dnsmasq.d/01-pihole.conf ]; then
75
     if [ -f /etc/dnsmasq.d/01-pihole.conf ]; then
76
         rm /etc/dnsmasq.d/01-pihole.conf
76
         rm /etc/dnsmasq.d/01-pihole.conf
77
     fi
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
     chmod +x /opt/pihole/*.sh
80
     chmod +x /opt/pihole/*.sh
81
 }
81
 }
82
 
82
 
95
         return
95
         return
96
     fi
96
     fi
97
 
97
 
98
-    if [ ! -f $HOME/${PROJECT_NAME}-wifi.cfg ]; then
98
+    if [ ! -f "$HOME/${PROJECT_NAME}-wifi.cfg" ]; then
99
         PIHOLE_IFACE=eth0
99
         PIHOLE_IFACE=eth0
100
     else
100
     else
101
         read_config_param WIFI_INTERFACE
101
         read_config_param WIFI_INTERFACE
114
     echo "piholeDNS1=${PIHOLE_DNS1}" >> ${setupVars}
114
     echo "piholeDNS1=${PIHOLE_DNS1}" >> ${setupVars}
115
     echo "piholeDNS2=${PIHOLE_DNS1}" >> ${setupVars}
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
     pihole -g
125
     pihole -g
126
     systemctl restart dnsmasq
126
     systemctl restart dnsmasq
132
 }
132
 }
133
 
133
 
134
 function pihole_change_upstream_dns {
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
     dialog --backtitle $"Ad Blocker Upstream DNS" \
136
     dialog --backtitle $"Ad Blocker Upstream DNS" \
138
            --radiolist $"Pick a domain name service (DNS):" 28 50 19 \
137
            --radiolist $"Pick a domain name service (DNS):" 28 50 19 \
139
            1 $"Digital Courage" on \
138
            1 $"Digital Courage" on \
154
            16 $"DNS.Watch" off \
153
            16 $"DNS.Watch" off \
155
            17 $"uncensoreddns.org" off \
154
            17 $"uncensoreddns.org" off \
156
            18 $"Lorraine Data Network" off \
155
            18 $"Lorraine Data Network" off \
157
-           19 $"Google" off 2> $data
156
+           19 $"Google" off 2> "$data"
158
     sel=$?
157
     sel=$?
159
     case $sel in
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
     esac
163
     esac
163
-    case $(cat $data) in
164
+    case $(cat "$data") in
164
         1) PIHOLE_DNS1='85.214.73.63'
165
         1) PIHOLE_DNS1='85.214.73.63'
165
            PIHOLE_DNS2='213.73.91.35'
166
            PIHOLE_DNS2='213.73.91.35'
166
            ;;
167
            ;;
218
         19) PIHOLE_DNS1='8.8.8.8'
219
         19) PIHOLE_DNS1='8.8.8.8'
219
             PIHOLE_DNS2='4.4.4.4'
220
             PIHOLE_DNS2='4.4.4.4'
220
             dialog --title $"WARNING" \
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
     esac
226
     esac
227
+    rm -f "$data"
225
     write_config_param "PIHOLE_DNS1" "$PIHOLE_DNS1"
228
     write_config_param "PIHOLE_DNS1" "$PIHOLE_DNS1"
226
     write_config_param "PIHOLE_DNS2" "$PIHOLE_DNS2"
229
     write_config_param "PIHOLE_DNS2" "$PIHOLE_DNS2"
227
 }
230
 }
252
 function configure_interactive_pihole {
255
 function configure_interactive_pihole {
253
     while true
256
     while true
254
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
259
         dialog --backtitle $"Freedombone Control Panel" \
258
                --title $"Ad Blocker" \
260
                --title $"Ad Blocker" \
259
                --radiolist $"Choose an operation:" 16 70 7 \
261
                --radiolist $"Choose an operation:" 16 70 7 \
263
                4 $"Change upstream DNS servers" off \
265
                4 $"Change upstream DNS servers" off \
264
                5 $"Pause blocker" off \
266
                5 $"Pause blocker" off \
265
                6 $"Resume blocker" off \
267
                6 $"Resume blocker" off \
266
-               7 $"Exit" on 2> $data
268
+               7 $"Exit" on 2> "$data"
267
         sel=$?
269
         sel=$?
268
         case $sel in
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
         esac
275
         esac
272
-        case $(cat $data) in
276
+        case $(cat "$data") in
273
             1) editor $PIHOLE_CUSTOM_ADLIST
277
             1) editor $PIHOLE_CUSTOM_ADLIST
274
                update_pihole_interactive
278
                update_pihole_interactive
275
                ;;
279
                ;;
286
                ;;
290
                ;;
287
             6) pihole_resume
291
             6) pihole_resume
288
                ;;
292
                ;;
289
-            7) break;;
293
+            7) rm -f "$data"
294
+               break;;
290
         esac
295
         esac
296
+        rm -f "$data"
291
     done
297
     done
292
 }
298
 }
293
 
299
 
306
     fi
312
     fi
307
 
313
 
308
     function_check set_repo_commit
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
     pihole_copy_files
317
     pihole_copy_files
312
     pihole_update
318
     pihole_update
367
         rm /etc/cron.d/pihole
373
         rm /etc/cron.d/pihole
368
     fi
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
     fi
378
     fi
373
 
379
 
374
     firewall_remove 53
380
     firewall_remove 53
391
 
397
 
392
     systemctl enable dnsmasq
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
     fi
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
         if [ -d /repos/pihole ]; then
407
         if [ -d /repos/pihole ]; then
402
             mkdir pihole
408
             mkdir pihole
403
             cp -r -p /repos/pihole/. pihole
409
             cp -r -p /repos/pihole/. pihole
404
-            cd pihole
410
+            cd pihole || exit 24572424684
405
             git pull
411
             git pull
406
         else
412
         else
407
             git_clone $PIHOLE_REPO pihole
413
             git_clone $PIHOLE_REPO pihole
408
         fi
414
         fi
409
 
415
 
410
-        if [ ! -d $INSTALL_DIR/pihole ]; then
416
+        if [ ! -d "$INSTALL_DIR/pihole" ]; then
411
             exit 523925
417
             exit 523925
412
         fi
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
         set_completion_param "pihole commit" "$PIHOLE_COMMIT"
421
         set_completion_param "pihole commit" "$PIHOLE_COMMIT"
416
     fi
422
     fi
417
 
423
 
420
     fi
426
     fi
421
 
427
 
422
     # blank file which takes the place of ads
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
         exit 26738
435
         exit 26738
430
     fi
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
     chmod 755 /usr/local/bin/gravity.sh
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
         exit 52935
441
         exit 52935
436
     fi
442
     fi
437
-    cp $INSTALL_DIR/pihole/pihole /usr/local/bin/pihole
443
+    cp "$INSTALL_DIR/pihole/pihole" /usr/local/bin/pihole
438
     chmod 755 /usr/local/bin/pihole
444
     chmod 755 /usr/local/bin/pihole
439
 
445
 
440
     if [ ! -d $piholeDir ]; then
446
     if [ ! -d $piholeDir ]; then

+ 331
- 333
src/freedombone-app-pleroma
文件差異過大導致無法顯示
查看文件


+ 278
- 275
src/freedombone-app-postactiv
文件差異過大導致無法顯示
查看文件


+ 161
- 157
src/freedombone-app-privatebin 查看文件

56
     find "${pbpath}/" -type d -print0 | xargs -0 chmod 0550
56
     find "${pbpath}/" -type d -print0 | xargs -0 chmod 0550
57
 
57
 
58
     chown -R ${rootuser}:${htgroup} "${pbpath}/"
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
 function logging_on_privatebin {
62
 function logging_on_privatebin {
68
 }
68
 }
69
 
69
 
70
 function remove_user_privatebin {
70
 function remove_user_privatebin {
71
-    remove_username="$1"
71
+    echo -n ''
72
+#    remove_username="$1"
72
 }
73
 }
73
 
74
 
74
 function add_user_privatebin {
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
     echo '0'
79
     echo '0'
79
 }
80
 }
80
 
81
 
81
 function install_interactive_privatebin {
82
 function install_interactive_privatebin {
82
-    if [ ! $ONION_ONLY ]; then
83
+    if [ ! "$ONION_ONLY" ]; then
83
         ONION_ONLY='no'
84
         ONION_ONLY='no'
84
     fi
85
     fi
85
 
86
 
86
-    if [[ $ONION_ONLY != "no" ]]; then
87
+    if [[ "$ONION_ONLY" != "no" ]]; then
87
         PRIVATEBIN_DOMAIN_NAME='privatebin.local'
88
         PRIVATEBIN_DOMAIN_NAME='privatebin.local'
88
     else
89
     else
89
         PRIVATEBIN_DETAILS_COMPLETE=
90
         PRIVATEBIN_DETAILS_COMPLETE=
90
         while [ ! $PRIVATEBIN_DETAILS_COMPLETE ]
91
         while [ ! $PRIVATEBIN_DETAILS_COMPLETE ]
91
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
94
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
95
                 dialog --backtitle $"Freedombone Configuration" \
95
                 dialog --backtitle $"Freedombone Configuration" \
96
                        --title $"PrivateBin Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
98
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
99
                        $"Code:" 2 1 "$(grep 'PRIVATEBIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
99
                        $"Code:" 2 1 "$(grep 'PRIVATEBIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
100
-                       2> $data
100
+                       2> "$data"
101
             else
101
             else
102
                 dialog --backtitle $"Freedombone Configuration" \
102
                 dialog --backtitle $"Freedombone Configuration" \
103
                        --title $"PrivateBin Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
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
             fi
107
             fi
108
             sel=$?
108
             sel=$?
109
             case $sel in
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
             esac
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
                     PRIVATEBIN_DOMAIN_NAME=""
118
                     PRIVATEBIN_DOMAIN_NAME=""
117
                 fi
119
                 fi
118
                 TEST_DOMAIN_NAME=$PRIVATEBIN_DOMAIN_NAME
120
                 TEST_DOMAIN_NAME=$PRIVATEBIN_DOMAIN_NAME
119
                 validate_domain_name
121
                 validate_domain_name
120
-                if [[ $TEST_DOMAIN_NAME != $PRIVATEBIN_DOMAIN_NAME ]]; then
122
+                if [[ "$TEST_DOMAIN_NAME" != "$PRIVATEBIN_DOMAIN_NAME" ]]; then
121
                     PRIVATEBIN_DOMAIN_NAME=
123
                     PRIVATEBIN_DOMAIN_NAME=
122
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
124
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
123
                 else
125
                 else
124
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$PRIVATEBIN_CODE"
128
                         validate_freedns_code "$PRIVATEBIN_CODE"
127
-                        if [ ! $VALID_CODE ]; then
129
+                        if [ ! "$VALID_CODE" ]; then
128
                             PRIVATEBIN_DOMAIN_NAME=
130
                             PRIVATEBIN_DOMAIN_NAME=
129
                         fi
131
                         fi
130
                     fi
132
                     fi
133
             if [ $PRIVATEBIN_DOMAIN_NAME ]; then
135
             if [ $PRIVATEBIN_DOMAIN_NAME ]; then
134
                 PRIVATEBIN_DETAILS_COMPLETE="yes"
136
                 PRIVATEBIN_DETAILS_COMPLETE="yes"
135
             fi
137
             fi
138
+            rm -f "$data"
136
         done
139
         done
137
 
140
 
138
         write_config_param "PRIVATEBIN_CODE" "$PRIVATEBIN_CODE"
141
         write_config_param "PRIVATEBIN_CODE" "$PRIVATEBIN_CODE"
142
 }
145
 }
143
 
146
 
144
 function change_password_privatebin {
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
 function reconfigure_privatebin {
153
 function reconfigure_privatebin {
156
         return
160
         return
157
     fi
161
     fi
158
 
162
 
159
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
163
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
160
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
164
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
161
     fi
165
     fi
162
 
166
 
163
     # update to the next commit
167
     # update to the next commit
164
     function_check set_repo_commit
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
     secure_privatebin
171
     secure_privatebin
168
 }
172
 }
170
 
174
 
171
 function backup_local_privatebin {
175
 function backup_local_privatebin {
172
     PRIVATEBIN_DOMAIN_NAME='privatebin'
176
     PRIVATEBIN_DOMAIN_NAME='privatebin'
173
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
177
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
174
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
178
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
175
     fi
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
     function_check suspend_site
183
     function_check suspend_site
180
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
184
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
181
 
185
 
182
     function_check backup_directory_to_usb
186
     function_check backup_directory_to_usb
183
     dest_directory=privatebin
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
     function_check restart_site
190
     function_check restart_site
187
     restart_site
191
     restart_site
188
 }
192
 }
189
 
193
 
190
 function restore_local_privatebin {
194
 function restore_local_privatebin {
191
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
195
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
192
         return
196
         return
193
     fi
197
     fi
194
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
198
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
195
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
199
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
196
         echo $"Restoring privatebin"
200
         echo $"Restoring privatebin"
197
         temp_restore_dir=/root/tempprivatebin
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
         function_check restore_directory_from_usb
204
         function_check restore_directory_from_usb
201
         restore_directory_from_usb $temp_restore_dir privatebin
205
         restore_directory_from_usb $temp_restore_dir privatebin
202
         if [ -d $temp_restore_dir ]; then
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
             else
209
             else
206
-                cp -rp $temp_restore_dir/* $privatebin_dir/
210
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
207
             fi
211
             fi
208
             secure_privatebin
212
             secure_privatebin
209
             rm -rf $temp_restore_dir
213
             rm -rf $temp_restore_dir
215
 
219
 
216
 function backup_remote_privatebin {
220
 function backup_remote_privatebin {
217
     PRIVATEBIN_DOMAIN_NAME='privatebin'
221
     PRIVATEBIN_DOMAIN_NAME='privatebin'
218
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
222
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
219
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
223
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
220
     fi
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
     function_check suspend_site
228
     function_check suspend_site
225
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
229
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
226
 
230
 
227
     function_check backup_directory_to_friend
231
     function_check backup_directory_to_friend
228
     dest_directory=privatebin
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
     function_check restart_site
235
     function_check restart_site
232
     restart_site
236
     restart_site
233
 }
237
 }
234
 
238
 
235
 function restore_remote_privatebin {
239
 function restore_remote_privatebin {
236
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
240
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
237
         return
241
         return
238
     fi
242
     fi
239
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
243
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
240
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
244
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
241
         temp_restore_dir=/root/tempprivatebin
245
         temp_restore_dir=/root/tempprivatebin
242
         privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
246
         privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
243
 
247
 
244
         function_check restore_directory_from_friend
248
         function_check restore_directory_from_friend
245
         restore_directory_from_friend $temp_restore_dir privatebin
249
         restore_directory_from_friend $temp_restore_dir privatebin
246
         if [ -d $temp_restore_dir ]; then
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
             else
253
             else
250
-                cp -rp $temp_restore_dir/* $privatebin_dir/
254
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
251
             fi
255
             fi
252
             secure_privatebin
256
             secure_privatebin
253
             rm -rf $temp_restore_dir
257
             rm -rf $temp_restore_dir
262
     read_config_param "PRIVATEBIN_DOMAIN_NAME"
266
     read_config_param "PRIVATEBIN_DOMAIN_NAME"
263
     read_config_param "MY_USERNAME"
267
     read_config_param "MY_USERNAME"
264
     echo "Removing $PRIVATEBIN_DOMAIN_NAME"
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
     fi
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
     fi
277
     fi
274
     function_check remove_onion_service
278
     function_check remove_onion_service
275
     remove_onion_service privatebin ${PRIVATEBIN_ONION_PORT}
279
     remove_onion_service privatebin ${PRIVATEBIN_ONION_PORT}
278
     fi
282
     fi
279
     remove_app privatebin
283
     remove_app privatebin
280
     remove_completion_param install_privatebin
284
     remove_completion_param install_privatebin
281
-    sed -i '/privatebin/d' $COMPLETION_FILE
285
+    sed -i '/privatebin/d' "$COMPLETION_FILE"
282
 
286
 
283
     function_check remove_ddns_domain
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
 function install_privatebin {
291
 function install_privatebin {
288
-    if [ ! $ONION_ONLY ]; then
292
+    if [ ! "$ONION_ONLY" ]; then
289
         ONION_ONLY='no'
293
         ONION_ONLY='no'
290
     fi
294
     fi
291
 
295
 
292
-    if [ ! $PRIVATEBIN_DOMAIN_NAME ]; then
296
+    if [ ! "$PRIVATEBIN_DOMAIN_NAME" ]; then
293
         echo $'No domain name was given for privatebin'
297
         echo $'No domain name was given for privatebin'
294
         exit 7359
298
         exit 7359
295
     fi
299
     fi
298
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
302
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
299
     apt-get -yq install php-libsodium libsodium18 php-mcrypt
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
     fi
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
         if [ -d /repos/privatebin ]; then
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
             git pull
314
             git pull
311
         else
315
         else
312
             function_check git_clone
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
         fi
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
             echo $'Unable to clone privatebin repo'
321
             echo $'Unable to clone privatebin repo'
318
             exit 63763873
322
             exit 63763873
319
         fi
323
         fi
320
     fi
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
     set_completion_param "privatebin commit" "$PRIVATEBIN_COMMIT"
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
     function_check add_ddns_domain
333
     function_check add_ddns_domain
330
-    add_ddns_domain $PRIVATEBIN_DOMAIN_NAME
334
+    add_ddns_domain "$PRIVATEBIN_DOMAIN_NAME"
331
 
335
 
332
     PRIVATEBIN_ONION_HOSTNAME=$(add_onion_service privatebin 80 ${PRIVATEBIN_ONION_PORT})
336
     PRIVATEBIN_ONION_HOSTNAME=$(add_onion_service privatebin 80 ${PRIVATEBIN_ONION_PORT})
333
 
337
 
334
     privatebin_nginx_site=/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
338
     privatebin_nginx_site=/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
335
     if [[ $ONION_ONLY == "no" ]]; then
339
     if [[ $ONION_ONLY == "no" ]]; then
336
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl
351
         function_check nginx_ssl
348
-        nginx_ssl $PRIVATEBIN_DOMAIN_NAME
352
+        nginx_ssl "$PRIVATEBIN_DOMAIN_NAME"
349
 
353
 
350
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
386
     else
383
-        echo -n '' > $privatebin_nginx_site
387
+        echo -n '' > "$privatebin_nginx_site"
384
     fi
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
     function_check nginx_compress
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check configure_php
426
     function_check configure_php
423
     configure_php
427
     configure_php
424
 
428
 
425
     function_check create_site_certificate
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
     function_check nginx_ensite
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
     # Change some defaults
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
     secure_privatebin
453
     secure_privatebin
450
 
454
 

+ 114
- 113
src/freedombone-app-profanity 查看文件

57
 }
57
 }
58
 
58
 
59
 function remove_user_profanity {
59
 function remove_user_profanity {
60
-    remove_username="$1"
60
+    echo -n ''
61
+#    remove_username="$1"
61
 }
62
 }
62
 
63
 
63
 function add_user_profanity {
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
     echo '0'
68
     echo '0'
68
 }
69
 }
82
 
83
 
83
     read_config_param DEFAULT_DOMAIN_NAME
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
     # TODO: this is currently interactive. Really there needs to be a
88
     # TODO: this is currently interactive. Really there needs to be a
88
     # non-interactive password change option for prosodyctl
89
     # non-interactive password change option for prosodyctl
89
     clear
90
     clear
90
     echo ''
91
     echo ''
91
     echo $'Currently Prosody requires password changes to be done interactively'
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
     XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
95
     XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
95
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
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
     fi
99
     fi
99
 }
100
 }
100
 
101
 
110
 
111
 
111
     rm -rf /tmp/*
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
     if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
115
     if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
115
         function_check set_repo_commit
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
         ./bootstrap.sh
119
         ./bootstrap.sh
119
         ./configure
120
         ./configure
120
         make
121
         make
124
 
125
 
125
     rm -rf /tmp/*
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
     if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
129
     if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
129
         function_check set_repo_commit
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
         ./bootstrap.sh
133
         ./bootstrap.sh
133
         ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
134
         ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
134
         make
135
         make
135
         make install
136
         make install
136
     fi
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
     if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
140
     if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
140
         # upgrade omemo plugins for all users
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
         pip uninstall -y profanity-omemo-plugin
145
         pip uninstall -y profanity-omemo-plugin
145
         ./install.sh
146
         ./install.sh
146
         for d in /home/*/ ; do
147
         for d in /home/*/ ; do
147
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
148
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
148
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
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
                 fi
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
             fi
158
             fi
158
         done
159
         done
159
         if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
160
         if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
160
             rm /etc/skel/.local/share/profanity/plugins/omemo.*
161
             rm /etc/skel/.local/share/profanity/plugins/omemo.*
161
         fi
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
     fi
164
     fi
164
 
165
 
165
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
166
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
183
 
184
 
184
 function remove_profanity {
185
 function remove_profanity {
185
     if [ -f /usr/local/bin/profanity ]; then
186
     if [ -f /usr/local/bin/profanity ]; then
186
-        cd $INSTALL_DIR/profanity
187
+        cd "$INSTALL_DIR/profanity" || exit 4628462848
187
         make uninstall
188
         make uninstall
188
 
189
 
189
         remove_completion_param install_profanity
190
         remove_completion_param install_profanity
190
-        sed -i '/profanity/d' $COMPLETION_FILE
191
+        sed -i '/profanity/d' "$COMPLETION_FILE"
191
     fi
192
     fi
192
 }
193
 }
193
 
194
 
197
         return
198
         return
198
     fi
199
     fi
199
     # install profanity from source in order to get OMEMO support
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
     fi
203
     fi
203
 
204
 
204
     apt-get -yq install automake autoconf autoconf-archive libtool build-essential
205
     apt-get -yq install automake autoconf autoconf-archive libtool build-essential
207
 
208
 
208
     # dependency for profanity not available in debian
209
     # dependency for profanity not available in debian
209
     if [ -d /repos/libmesode ]; then
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
         git pull
214
         git pull
214
     else
215
     else
215
-        git_clone $LIBMESODE_REPO $INSTALL_DIR/libmesode
216
+        git_clone "$LIBMESODE_REPO" "$INSTALL_DIR/libmesode"
216
     fi
217
     fi
217
 
218
 
218
-    cd $INSTALL_DIR/libmesode
219
+    cd "$INSTALL_DIR/libmesode" || exit 2468246284
219
     git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
220
     git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
220
     ./bootstrap.sh
221
     ./bootstrap.sh
221
     ./configure
222
     ./configure
225
 
226
 
226
     # build profanity
227
     # build profanity
227
     if [ -d /repos/profanity ]; then
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
         git pull
232
         git pull
232
     else
233
     else
233
-        git_clone $PROFANITY_REPO $INSTALL_DIR/profanity
234
+        git_clone "$PROFANITY_REPO" "$INSTALL_DIR/profanity"
234
     fi
235
     fi
235
 
236
 
236
-    cd $INSTALL_DIR/profanity
237
+    cd "$INSTALL_DIR/profanity" || exit 54287452858
237
     git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
238
     git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
238
     ./bootstrap.sh
239
     ./bootstrap.sh
239
     ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
240
     ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
249
     apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev
250
     apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev
250
 
251
 
251
     if [ -d /repos/profanity-omemo ]; then
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
         git pull
256
         git pull
256
     else
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
     fi
259
     fi
259
 
260
 
260
-    cd $INSTALL_DIR/profanity-omemo-plugin
261
+    cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 6428468248
261
     git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT
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
         echo $'prof_omemo_plugin.py not found'
264
         echo $'prof_omemo_plugin.py not found'
264
         exit 389225
265
         exit 389225
265
     fi
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
     ./install.sh
268
     ./install.sh
268
 
269
 
269
     mkdir -p /etc/skel/.local/share/profanity/plugins
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
     XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
275
     XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
275
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
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
     fi
279
     fi
279
 
280
 
280
     XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
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
     if [[ $ONION_ONLY == 'no' ]]; then
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
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
304
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
304
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
305
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
305
         fi
306
         fi
306
     fi
307
     fi
307
 
308
 
308
     if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
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
         if [[ $ONION_ONLY == 'no' ]]; then
311
         if [[ $ONION_ONLY == 'no' ]]; then
311
-            echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
312
+            echo 'enabled=false' >> "$XMPP_CLIENT_ACCOUNTS"
312
         else
313
         else
313
-            echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
314
+            echo 'enabled=true' >> "$XMPP_CLIENT_ACCOUNTS"
314
         fi
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
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
333
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
333
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
334
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
334
         fi
335
         fi
335
     fi
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
     fi
340
     fi
340
-    echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
341
+    echo '[connection]' > "/home/$MY_USERNAME/.config/profanity/profrc"
341
     if [[ $ONION_ONLY == 'no' ]]; then
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
     else
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
     fi
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
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
364
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
364
     APP_INSTALLED=1
365
     APP_INSTALLED=1

+ 157
- 153
src/freedombone-app-radicale 查看文件

61
 function remove_user_radicale {
61
 function remove_user_radicale {
62
     remove_username="$1"
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
     if grep -q "${remove_username}:" ${RADICALE_USERS}; then
66
     if grep -q "${remove_username}:" ${RADICALE_USERS}; then
67
         sed -i "/${remove_username}:/d" ${RADICALE_USERS}
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
         fi
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
         fi
73
         fi
74
         systemctl restart radicale
74
         systemctl restart radicale
75
     fi
75
     fi
79
     new_username="$1"
79
     new_username="$1"
80
     new_user_password="$2"
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
     if [ ! -f ${RADICALE_USERS} ]; then
84
     if [ ! -f ${RADICALE_USERS} ]; then
85
         touch ${RADICALE_USERS}
85
         touch ${RADICALE_USERS}
88
     if ! grep -q "$new_username:" ${RADICALE_USERS}; then
88
     if ! grep -q "$new_username:" ${RADICALE_USERS}; then
89
         htpasswd -bd ${RADICALE_USERS} "$new_username" "$new_user_password"
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
         chown -R www-data:www-data /var/www/radicale
99
         chown -R www-data:www-data /var/www/radicale
100
         chmod -R 755 /var/www/radicale/*
100
         chmod -R 755 /var/www/radicale/*
107
     existing_username="$1"
107
     existing_username="$1"
108
     new_user_password="$2"
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
     if grep -q "${existing_username}:" ${RADICALE_USERS}; then
112
     if grep -q "${existing_username}:" ${RADICALE_USERS}; then
113
         sed -i "/${existing_username}:/d" ${RADICALE_USERS}
113
         sed -i "/${existing_username}:/d" ${RADICALE_USERS}
127
     rm -rf /var/log/radicale/*
127
     rm -rf /var/log/radicale/*
128
 
128
 
129
     # create an admin password
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
     else
132
     else
133
-        RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
133
+        RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
134
     fi
134
     fi
135
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
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
     touch /var/log/radicale/radicale.log
139
     touch /var/log/radicale/radicale.log
140
     chown -R www-data:www-data /var/log/radicale
140
     chown -R www-data:www-data /var/log/radicale
145
         return
145
         return
146
     fi
146
     fi
147
 
147
 
148
-    if ! grep -q "radicale version:" $COMPLETION_FILE; then
148
+    if ! grep -q "radicale version:" "$COMPLETION_FILE"; then
149
         return
149
         return
150
     fi
150
     fi
151
 
151
 
155
     fi
155
     fi
156
 
156
 
157
     # get the source
157
     # get the source
158
-    cd /var/www/radicale
158
+    cd /var/www/radicale || exit 62784628468
159
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
159
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
160
 
160
 
161
     # check the hash
161
     # check the hash
170
         exit 73529
170
         exit 73529
171
     fi
171
     fi
172
     rm Radicale-${RADICALE_VERSION}.tar.gz
172
     rm Radicale-${RADICALE_VERSION}.tar.gz
173
-    cd Radicale-${RADICALE_VERSION}
173
+    cd "Radicale-${RADICALE_VERSION}" || exit 264824684
174
 
174
 
175
     # move the old command
175
     # move the old command
176
     mv /usr/local/bin/radicale /usr/local/bin/radicale_previous
176
     mv /usr/local/bin/radicale /usr/local/bin/radicale_previous
186
     fi
186
     fi
187
 
187
 
188
     # remove the old source
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
     chown -R www-data:www-data /var/www/radicale
192
     chown -R www-data:www-data /var/www/radicale
193
     systemctl restart radicale
193
     systemctl restart radicale
194
     systemctl restart nginx
194
     systemctl restart nginx
219
         else
219
         else
220
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
220
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
221
         fi
221
         fi
222
+        # shellcheck disable=SC2181
222
         if [ ! "$?" = "0" ]; then
223
         if [ ! "$?" = "0" ]; then
223
             function_check backup_unmount_drive
224
             function_check backup_unmount_drive
224
             backup_unmount_drive
225
             backup_unmount_drive
233
         else
234
         else
234
             cp -r $temp_restore_dir/* /var/www/radicale/*
235
             cp -r $temp_restore_dir/* /var/www/radicale/*
235
         fi
236
         fi
237
+        # shellcheck disable=SC2181
236
         if [ ! "$?" = "0" ]; then
238
         if [ ! "$?" = "0" ]; then
237
             function_check backup_unmount_drive
239
             function_check backup_unmount_drive
238
             backup_unmount_drive
240
             backup_unmount_drive
264
         else
266
         else
265
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
267
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
266
         fi
268
         fi
269
+        # shellcheck disable=SC2181
267
         if [ ! "$?" = "0" ]; then
270
         if [ ! "$?" = "0" ]; then
268
             exit 236746
271
             exit 236746
269
         fi
272
         fi
276
         else
279
         else
277
             cp -r $temp_restore_dir/* /var/www/radicale
280
             cp -r $temp_restore_dir/* /var/www/radicale
278
         fi
281
         fi
282
+        # shellcheck disable=SC2181
279
         if [ ! "$?" = "0" ]; then
283
         if [ ! "$?" = "0" ]; then
280
             exit 3674284
284
             exit 3674284
281
         fi
285
         fi
332
     fi
336
     fi
333
 
337
 
334
     remove_completion_param install_radicale
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
     systemctl restart nginx
341
     systemctl restart nginx
338
 }
342
 }
339
 
343
 
340
 function install_radicale {
344
 function install_radicale {
341
     if [[ $ONION_ONLY == 'no' ]]; then
345
     if [[ $ONION_ONLY == 'no' ]]; then
342
         # obtain a cert for the default domain
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
             echo $'Obtaining certificate for the main domain'
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
         fi
350
         fi
347
     fi
351
     fi
348
 
352
 
368
     fi
372
     fi
369
 
373
 
370
     # get the source
374
     # get the source
371
-    cd /var/www/radicale
375
+    cd /var/www/radicale || exit 462874628
372
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
376
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
373
 
377
 
374
     # check the hash
378
     # check the hash
383
         exit 623252
387
         exit 623252
384
     fi
388
     fi
385
     rm Radicale-${RADICALE_VERSION}.tar.gz
389
     rm Radicale-${RADICALE_VERSION}.tar.gz
386
-    cd Radicale-${RADICALE_VERSION}
390
+    cd "Radicale-${RADICALE_VERSION}" || exit 872462842
387
     python setup.py install
391
     python setup.py install
388
     if [ ! -f /usr/local/bin/radicale ]; then
392
     if [ ! -f /usr/local/bin/radicale ]; then
389
         echo $'Radicale did not install'
393
         echo $'Radicale did not install'
398
     fi
402
     fi
399
 
403
 
400
     # create the configuration
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
     # create an admin password
427
     # create an admin password
424
     if [ ${#RADICALE_PASSWORD} -lt 8 ]; then
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
         else
431
         else
428
-            RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
432
+            RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
429
         fi
433
         fi
430
     fi
434
     fi
431
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
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
     addresses_str=$"Addresses"
452
     addresses_str=$"Addresses"
449
     echo "{\"tag\": \"VADDRESSBOOK\", \"D:displayname\": \"${addresses_str}\"}" > /var/www/radicale/collections/addresses.props
453
     echo "{\"tag\": \"VADDRESSBOOK\", \"D:displayname\": \"${addresses_str}\"}" > /var/www/radicale/collections/addresses.props
461
     systemctl enable radicale
465
     systemctl enable radicale
462
     systemctl start radicale
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
         # create a new site config
469
         # create a new site config
466
         RADICALE_ONION_HOSTNAME=$(add_onion_service radicale 80 ${RADICALE_ONION_PORT})
470
         RADICALE_ONION_HOSTNAME=$(add_onion_service radicale 80 ${RADICALE_ONION_PORT})
467
 
471
 
468
         if [[ $ONION_ONLY == 'no' ]]; then
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
             function_check nginx_ssl
477
             function_check nginx_ssl
474
-            nginx_ssl ${DEFAULT_DOMAIN_NAME} mobile
478
+            nginx_ssl "${DEFAULT_DOMAIN_NAME}" mobile
475
             function_check nginx_disable_sniffing
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
         else
514
         else
511
-            echo -n '' > /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
515
+            echo -n '' > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
512
         fi
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
         set_completion_param "radicale onion domain" "${RADICALE_ONION_HOSTNAME}"
551
         set_completion_param "radicale onion domain" "${RADICALE_ONION_HOSTNAME}"
548
     else
552
     else
549
         # alter the existing site config
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
         fi
557
         fi
554
     fi
558
     fi
555
 
559
 
556
     # create a certificate
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
         fi
565
         fi
562
     fi
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
         sed -i "s|radicale.crt|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
569
         sed -i "s|radicale.crt|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
566
         sed -i "s|radicale.pem|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
570
         sed -i "s|radicale.pem|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
567
     fi
571
     fi
572
 
576
 
573
     systemctl restart nginx
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
     # keep track of the version so we can check for upgrades
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
     else
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
     fi
586
     fi
583
 
587
 
584
     APP_INSTALLED=1
588
     APP_INSTALLED=1

+ 89
- 87
src/freedombone-app-riot 查看文件

76
         RIOT_DETAILS_COMPLETE=
76
         RIOT_DETAILS_COMPLETE=
77
         while [ ! $RIOT_DETAILS_COMPLETE ]
77
         while [ ! $RIOT_DETAILS_COMPLETE ]
78
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
80
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
82
                 dialog --backtitle $"Freedombone Configuration" \
81
                 dialog --backtitle $"Freedombone Configuration" \
83
                        --title $"Riot Web user interface for Matrix" \
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
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
84
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
86
                        $"Code:" 2 1 "$(grep 'RIOT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
85
                        $"Code:" 2 1 "$(grep 'RIOT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
87
-                       2> $data
86
+                       2> "$data"
88
             else
87
             else
89
                 dialog --backtitle $"Freedombone Configuration" \
88
                 dialog --backtitle $"Freedombone Configuration" \
90
                        --title $"Riot Web user interface for Matrix" \
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
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
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
             fi
93
             fi
95
             sel=$?
94
             sel=$?
96
             case $sel in
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
             esac
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
                 TEST_DOMAIN_NAME=$RIOT_DOMAIN_NAME
103
                 TEST_DOMAIN_NAME=$RIOT_DOMAIN_NAME
103
                 validate_domain_name
104
                 validate_domain_name
104
-                if [[ $TEST_DOMAIN_NAME != $RIOT_DOMAIN_NAME ]]; then
105
+                if [[ "$TEST_DOMAIN_NAME" != "$RIOT_DOMAIN_NAME" ]]; then
105
                     RIOT_DOMAIN_NAME=
106
                     RIOT_DOMAIN_NAME=
106
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
107
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
107
                 else
108
                 else
108
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$RIOT_CODE"
111
                         validate_freedns_code "$RIOT_CODE"
111
-                        if [ ! $VALID_CODE ]; then
112
+                        if [ ! "$VALID_CODE" ]; then
112
                             RIOT_DOMAIN_NAME=
113
                             RIOT_DOMAIN_NAME=
113
                         fi
114
                         fi
114
                     fi
115
                     fi
117
             if [ $RIOT_DOMAIN_NAME ]; then
118
             if [ $RIOT_DOMAIN_NAME ]; then
118
                 RIOT_DETAILS_COMPLETE="yes"
119
                 RIOT_DETAILS_COMPLETE="yes"
119
             fi
120
             fi
121
+            rm -f "$data"
120
         done
122
         done
121
 
123
 
122
         # save the results in the config file
124
         # save the results in the config file
132
 
134
 
133
 function riot_download {
135
 function riot_download {
134
     # download
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
     fi
139
     fi
138
-    if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
140
+    if [ ! -f "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz" ]; then
139
         echo $'Unable to download Riot Web from releases'
141
         echo $'Unable to download Riot Web from releases'
140
         exit 62836
142
         exit 62836
141
     fi
143
     fi
142
-    cd $INSTALL_DIR
144
+    cd "$INSTALL_DIR" || exit 2468724628
143
 
145
 
144
     # check the hash
146
     # check the hash
145
     curr_hash=$(sha256sum ${RIOT_FILENAME}.tar.gz | awk -F ' ' '{print $1}')
147
     curr_hash=$(sha256sum ${RIOT_FILENAME}.tar.gz | awk -F ' ' '{print $1}')
149
     fi
151
     fi
150
 
152
 
151
     tar -xzvf ${RIOT_FILENAME}.tar.gz
153
     tar -xzvf ${RIOT_FILENAME}.tar.gz
152
-    if [ ! -d $INSTALL_DIR/${RIOT_FILENAME} ]; then
154
+    if [ ! -d "$INSTALL_DIR/${RIOT_FILENAME}" ]; then
153
         echo $'Unable to extract Riot Web tarball'
155
         echo $'Unable to extract Riot Web tarball'
154
         exit 542826
156
         exit 542826
155
     fi
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
 function upgrade_riot {
163
 function upgrade_riot {
162
-    if ! grep -q 'riot version:' $COMPLETION_FILE; then
164
+    if ! grep -q 'riot version:' "$COMPLETION_FILE"; then
163
         return
165
         return
164
     fi
166
     fi
165
 
167
 
171
     fi
173
     fi
172
 
174
 
173
     riot_download
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
     riot_remove_bad_links
177
     riot_remove_bad_links
176
 
178
 
177
     systemctl restart nginx
179
     systemctl restart nginx
207
     fi
209
     fi
208
 
210
 
209
     remove_completion_param install_riot
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
 function install_riot {
215
 function install_riot {
216
     fi
218
     fi
217
 
219
 
218
     # check that matrix has been installed
220
     # check that matrix has been installed
219
-    if [ ! $MATRIX_DOMAIN_NAME ]; then
221
+    if [ ! "$MATRIX_DOMAIN_NAME" ]; then
220
         exit 687292
222
         exit 687292
221
     fi
223
     fi
222
     if [[ "$MATRIX_DOMAIN_NAME" != *'.'* ]]; then
224
     if [[ "$MATRIX_DOMAIN_NAME" != *'.'* ]]; then
235
         mkdir -p /var/www/$RIOT_DOMAIN_NAME/htdocs
237
         mkdir -p /var/www/$RIOT_DOMAIN_NAME/htdocs
236
     fi
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
     fi
242
     fi
241
 
243
 
242
     riot_download
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
         riot_config_file="config.${RIOT_DOMAIN_NAME}.json"
249
         riot_config_file="config.${RIOT_DOMAIN_NAME}.json"
248
         cp config.sample.json $riot_config_file
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
     else
255
     else
254
         riot_config_file="config.${MATRIX_ONION_DOMAIN_NAME}.json"
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
     fi
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
     RIOT_ONION_HOSTNAME=$(add_onion_service riot 80 ${RIOT_ONION_PORT})
267
     RIOT_ONION_HOSTNAME=$(add_onion_service riot 80 ${RIOT_ONION_PORT})
266
 
268
 
268
     if [[ $ONION_ONLY == "no" ]]; then
270
     if [[ $ONION_ONLY == "no" ]]; then
269
         function_check nginx_http_redirect
271
         function_check nginx_http_redirect
270
         nginx_http_redirect $RIOT_DOMAIN_NAME
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
         function_check nginx_ssl
279
         function_check nginx_ssl
278
         nginx_ssl $RIOT_DOMAIN_NAME
280
         nginx_ssl $RIOT_DOMAIN_NAME
279
 
281
 
280
         function_check nginx_disable_sniffing
282
         function_check nginx_disable_sniffing
281
         nginx_disable_sniffing $RIOT_DOMAIN_NAME
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
         function_check nginx_limits
297
         function_check nginx_limits
296
         nginx_limits $RIOT_DOMAIN_NAME '15m'
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
     else
302
     else
301
         echo -n '' > $riot_nginx_site
303
         echo -n '' > $riot_nginx_site
302
     fi
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
     function_check nginx_disable_sniffing
309
     function_check nginx_disable_sniffing
308
     nginx_disable_sniffing $RIOT_DOMAIN_NAME
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
     function_check nginx_limits
322
     function_check nginx_limits
321
     nginx_limits $RIOT_DOMAIN_NAME '15m'
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
     function_check create_site_certificate
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
     fi
335
     fi
334
 
336
 
335
     function_check nginx_ensite
337
     function_check nginx_ensite
344
     systemctl restart nginx
346
     systemctl restart nginx
345
 
347
 
346
     set_completion_param "riot domain" "$RIOT_DOMAIN_NAME"
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
     else
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
     fi
353
     fi
352
     APP_INSTALLED=1
354
     APP_INSTALLED=1
353
 }
355
 }

+ 196
- 192
src/freedombone-app-rss 查看文件

62
 }
62
 }
63
 
63
 
64
 function remove_user_rss {
64
 function remove_user_rss {
65
-    remove_username="$1"
65
+    echo -n ''
66
+#    remove_username="$1"
66
 }
67
 }
67
 
68
 
68
 function add_user_rss {
69
 function add_user_rss {
69
-    new_username="$1"
70
-    new_user_password="$2"
70
+#    new_username="$1"
71
+#    new_user_password="$2"
71
     echo '0'
72
     echo '0'
72
 }
73
 }
73
 
74
 
77
 }
78
 }
78
 
79
 
79
 function change_password_rss {
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
     #${PROJECT_NAME}-pass -u "$curr_username" -a rss -p "$new_user_password"
85
     #${PROJECT_NAME}-pass -u "$curr_username" -a rss -p "$new_user_password"
84
 }
86
 }
85
 
87
 
86
 function rss_create_database {
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
     else
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
         fi
94
         fi
93
     fi
95
     fi
94
-    if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
96
+    if [ ! "$RSS_READER_ADMIN_PASSWORD" ]; then
95
         return
97
         return
96
     fi
98
     fi
97
 
99
 
98
     function_check create_database
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
 function reconfigure_rss {
104
 function reconfigure_rss {
131
         # remove any previous install
133
         # remove any previous install
132
         if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
134
         if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
133
             if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
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
                 rm -rf $RSS_READER_PATH/g2ttree-mobile
138
                 rm -rf $RSS_READER_PATH/g2ttree-mobile
137
             fi
139
             fi
138
         fi
140
         fi
184
                 fi
186
                 fi
185
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
187
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
186
             fi
188
             fi
189
+            # shellcheck disable=SC2181
187
             if [ ! "$?" = "0" ]; then
190
             if [ ! "$?" = "0" ]; then
188
                 function_check set_user_permissions
191
                 function_check set_user_permissions
189
                 set_user_permissions
192
                 set_user_permissions
207
     function_check rss_modifications
210
     function_check rss_modifications
208
     rss_modifications
211
     rss_modifications
209
 
212
 
210
-    if [ -d $USB_MOUNT/backup/ttrss ]; then
213
+    if [ -d "$USB_MOUNT/backup/ttrss" ]; then
211
         chown -R www-data:www-data /etc/share/tt-rss
214
         chown -R www-data:www-data /etc/share/tt-rss
212
         if [ -d $temp_restore_dir ]; then
215
         if [ -d $temp_restore_dir ]; then
213
             rm -rf $temp_restore_dir
216
             rm -rf $temp_restore_dir
214
         fi
217
         fi
215
     fi
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
     sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
221
     sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
219
     MARIADB_PASSWORD=
222
     MARIADB_PASSWORD=
220
 }
223
 }
245
 
248
 
246
 function restore_remote_rss {
249
 function restore_remote_rss {
247
     temp_restore_dir=/root/tempttrss
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
         echo $"Restoring ttrss"
252
         echo $"Restoring ttrss"
250
         function_check get_mariadb_password
253
         function_check get_mariadb_password
251
         get_mariadb_password
254
         get_mariadb_password
263
                 fi
266
                 fi
264
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
267
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
265
             fi
268
             fi
269
+            # shellcheck disable=SC2181
266
             if [ ! "$?" = "0" ]; then
270
             if [ ! "$?" = "0" ]; then
267
                 exit 6391
271
                 exit 6391
268
             fi
272
             fi
280
         function_check rss_modifications
284
         function_check rss_modifications
281
         rss_modifications
285
         rss_modifications
282
 
286
 
283
-        if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
287
+        if [ -d "$SERVER_DIRECTORY/backup/ttrss" ]; then
284
             chown -R www-data:www-data /etc/share/tt-rss
288
             chown -R www-data:www-data /etc/share/tt-rss
285
         fi
289
         fi
286
         if [ -d /root/tempttrss ]; then
290
         if [ -d /root/tempttrss ]; then
287
             rm -rf /root/tempttrss
291
             rm -rf /root/tempttrss
288
         fi
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
         sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
295
         sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
292
         MARIADB_PASSWORD=
296
         MARIADB_PASSWORD=
293
 
297
 
313
     function_check drop_database
317
     function_check drop_database
314
     drop_database ttrss
318
     drop_database ttrss
315
     remove_completion_param install_rss
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
     remove_backup_database_local ttrss
323
     remove_backup_database_local ttrss
320
 }
324
 }
321
 
325
 
329
 
333
 
330
     # ensure that socks5 proxy is used
334
     # ensure that socks5 proxy is used
331
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/plugins/af_unburn/init.php; then
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
         rss_modified=1
337
         rss_modified=1
334
     fi
338
     fi
335
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/include/functions.php; then
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
         rss_modified=1
341
         rss_modified=1
338
     fi
342
     fi
339
     if [ $rss_modified ]; then
343
     if [ $rss_modified ]; then
340
-        cd $RSS_READER_PATH
344
+        cd $RSS_READER_PATH || exit 564286428
341
         git commit -a -m"Modify for Tor proxying"
345
         git commit -a -m"Modify for Tor proxying"
342
     fi
346
     fi
343
     chown -R www-data:www-data $RSS_READER_PATH
347
     chown -R www-data:www-data $RSS_READER_PATH
358
     if [ ! -d /etc/share ]; then
362
     if [ ! -d /etc/share ]; then
359
         mkdir /etc/share
363
         mkdir /etc/share
360
     fi
364
     fi
361
-    cd /etc/share
365
+    cd /etc/share || exit 46284628
362
 
366
 
363
     if [ -d /repos/rss ]; then
367
     if [ -d /repos/rss ]; then
364
         mkdir tt-rss
368
         mkdir tt-rss
365
         cp -r -p /repos/rss/. tt-rss
369
         cp -r -p /repos/rss/. tt-rss
366
-        cd tt-rss
370
+        cd tt-rss || exit 462846822
367
         git pull
371
         git pull
368
     else
372
     else
369
         function_check git_clone
373
         function_check git_clone
374
         echo $'Could not clone RSS reader repo'
378
         echo $'Could not clone RSS reader repo'
375
         exit 52925
379
         exit 52925
376
     fi
380
     fi
377
-    cd $RSS_READER_PATH
381
+    cd $RSS_READER_PATH || exit 42479825792593
378
     git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
382
     git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
379
     set_completion_param "rss reader commit" "$RSS_READER_COMMIT"
383
     set_completion_param "rss reader commit" "$RSS_READER_COMMIT"
380
 
384
 
397
     USE_V2_ONION_ADDRESS=1
401
     USE_V2_ONION_ADDRESS=1
398
     RSS_MOBILE_READER_ONION_HOSTNAME=$(add_onion_service mobilerss 80 ${RSS_MOBILE_READER_ONION_PORT})
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
     if [ ! -f $RSS_READER_PATH/config.php ]; then
505
     if [ ! -f $RSS_READER_PATH/config.php ]; then
502
         # generate a config file
506
         # generate a config file
503
         RSS_FEED_CRYPT_KEY="$(create_password 24)"
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
     fi
549
     fi
546
 
550
 
547
     # initialize the database
551
     # initialize the database
569
     systemctl restart nginx
573
     systemctl restart nginx
570
 
574
 
571
     # daemon to update feeds
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
     systemctl enable ttrss
587
     systemctl enable ttrss
584
     systemctl daemon-reload
588
     systemctl daemon-reload
585
     systemctl start ttrss
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
     install_completed rss_main
593
     install_completed rss_main
590
 }
594
 }
591
 
595
 
592
 function install_rss_gnusocial {
596
 function install_rss_gnusocial {
593
-    if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
597
+    if [ ! "$GNUSOCIAL_DOMAIN_NAME" ]; then
594
         return
598
         return
595
     fi
599
     fi
596
 
600
 
608
         return
612
         return
609
     fi
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
     fi
617
     fi
614
 
618
 
615
-    cd $INSTALL_DIR
619
+    cd "$INSTALL_DIR" || exit 7246284
616
     function_check git_clone
620
     function_check git_clone
617
     git_clone $RSS_READER_GNUSOCIAL_REPO ttrss-gnusocial
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
         echo $'Could not clone repo for RSS reader gnusocial plugin'
623
         echo $'Could not clone repo for RSS reader gnusocial plugin'
620
         exit 52838
624
         exit 52838
621
     fi
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
     git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
628
     git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
625
     set_completion_param "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT"
629
     set_completion_param "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT"
626
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
630
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
642
     # remove any previous install
646
     # remove any previous install
643
     if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
647
     if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
644
         if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
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
             rm -rf $RSS_READER_PATH/g2ttree-mobile
651
             rm -rf $RSS_READER_PATH/g2ttree-mobile
648
         fi
652
         fi
649
     fi
653
     fi
652
         return
656
         return
653
     fi
657
     fi
654
 
658
 
655
-    cd /etc/share
659
+    cd /etc/share || exit 7498264462
656
 
660
 
657
     if [ -d /repos/rss-mobile ]; then
661
     if [ -d /repos/rss-mobile ]; then
658
         mkdir ttrss-mobile
662
         mkdir ttrss-mobile
659
         cp -r -p /repos/rss-mobile/. ttrss-mobile
663
         cp -r -p /repos/rss-mobile/. ttrss-mobile
660
-        cd ttrss-mobile
664
+        cd ttrss-mobile || exit 462846284682
661
         git pull
665
         git pull
662
     else
666
     else
663
         function_check git_clone
667
         function_check git_clone
668
         echo $'Could not clone RSS mobile reader repo'
672
         echo $'Could not clone RSS mobile reader repo'
669
         exit 24816
673
         exit 24816
670
     fi
674
     fi
671
-    cd $RSS_MOBILE_READER_PATH
675
+    cd "$RSS_MOBILE_READER_PATH" || exit 462846246824
672
     git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
676
     git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
673
     set_completion_param "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT"
677
     set_completion_param "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT"
674
 
678
 

+ 173
- 168
src/freedombone-app-scuttlebot 查看文件

61
     invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
61
     invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
62
 
62
 
63
     clear
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
     read -n1 -r -p $"Press any key to continue..." key
66
     read -n1 -r -p $"Press any key to continue..." key
66
 }
67
 }
67
 
68
 
68
 function configure_interactive_scuttlebot {
69
 function configure_interactive_scuttlebot {
69
     while true
70
     while true
70
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
73
         dialog --backtitle $"Freedombone Control Panel" \
74
                --title $"Scuttlebot" \
74
                --title $"Scuttlebot" \
75
                --radiolist $"Choose an operation:" 10 50 2 \
75
                --radiolist $"Choose an operation:" 10 50 2 \
76
                1 $"Create an invite" off \
76
                1 $"Create an invite" off \
77
-               2 $"Exit" on 2> $data
77
+               2 $"Exit" on 2> "$data"
78
         sel=$?
78
         sel=$?
79
         case $sel in
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
         esac
84
         esac
83
-        case $(cat $data) in
85
+        case $(cat "$data") in
84
             1) scuttlebot_create_invite;;
86
             1) scuttlebot_create_invite;;
85
-            2) break;;
87
+            2) rm -f "$data"
88
+               break;;
86
         esac
89
         esac
90
+        rm -f "$data"
87
     done
91
     done
88
 }
92
 }
89
 
93
 
90
 function remove_user_scuttlebot {
94
 function remove_user_scuttlebot {
91
-    remove_username="$1"
95
+    echo -n ''
96
+#    remove_username="$1"
92
 }
97
 }
93
 
98
 
94
 function add_user_scuttlebot {
99
 function add_user_scuttlebot {
95
-    new_username="$1"
96
-    new_user_password="$2"
100
+#    new_username="$1"
101
+#    new_user_password="$2"
97
     echo '0'
102
     echo '0'
98
 }
103
 }
99
 
104
 
109
 }
114
 }
110
 
115
 
111
 function change_password_scuttlebot {
116
 function change_password_scuttlebot {
112
-    new_username="$1"
113
-    new_user_password="$2"
117
+#    new_username="$1"
118
+#    new_user_password="$2"
114
     echo '0'
119
     echo '0'
115
 }
120
 }
116
 
121
 
123
 }
128
 }
124
 
129
 
125
 function upgrade_scuttlebot {
130
 function upgrade_scuttlebot {
126
-    if ! grep -q 'scuttlebot version:' $COMPLETION_FILE; then
131
+    if ! grep -q 'scuttlebot version:' $"COMPLETION_FILE"; then
127
         return
132
         return
128
     fi
133
     fi
129
 
134
 
134
         return
139
         return
135
     fi
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
         return
143
         return
140
     fi
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
 function backup_local_scuttlebot {
148
 function backup_local_scuttlebot {
218
     fi
222
     fi
219
 
223
 
220
     remove_completion_param install_scuttlebot
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
 function git_ssb_script {
228
 function git_ssb_script {
225
     if [[ "$1" == "mesh" ]]; then
229
     if [[ "$1" == "mesh" ]]; then
230
+        # shellcheck disable=SC2154
226
         git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
231
         git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
227
         git_ssb_daemon_filename=$rootdir/etc/systemd/system/git_ssb.service
232
         git_ssb_daemon_filename=$rootdir/etc/systemd/system/git_ssb.service
228
     else
233
     else
229
         git_ssb_script_name=/usr/bin/git-ssb-create
234
         git_ssb_script_name=/usr/bin/git-ssb-create
230
         git_ssb_daemon_filename=/etc/systemd/system/git_ssb.service
235
         git_ssb_daemon_filename=/etc/systemd/system/git_ssb.service
231
     fi
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
     chmod +x $git_ssb_script_name
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
 function scuttlebot_git_setup {
269
 function scuttlebot_git_setup {
265
     if [[ "$1" == "mesh" ]]; then
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
         fi
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
             echo $'Could not find foundation.css'
275
             echo $'Could not find foundation.css'
271
             exit 347687245
276
             exit 347687245
272
         fi
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
         git_ssb_nginx_site=$rootdir/etc/nginx/sites-available/git_ssb
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
     else
291
     else
287
         if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
292
         if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
288
             exit 7357225
293
             exit 7357225
300
         git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
305
         git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
301
         function_check nginx_http_redirect
306
         function_check nginx_http_redirect
302
         nginx_http_redirect $SCUTTLEBOT_DOMAIN_NAME "index index.html"
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
         function_check nginx_compress
313
         function_check nginx_compress
309
         nginx_compress $SCUTTLEBOT_DOMAIN_NAME
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
         function_check nginx_ssl
317
         function_check nginx_ssl
313
         nginx_ssl $SCUTTLEBOT_DOMAIN_NAME
318
         nginx_ssl $SCUTTLEBOT_DOMAIN_NAME
314
 
319
 
316
         nginx_disable_sniffing $SCUTTLEBOT_DOMAIN_NAME
321
         nginx_disable_sniffing $SCUTTLEBOT_DOMAIN_NAME
317
     fi
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
     fi
363
     fi
359
     if [[ "$1" != "mesh" ]]; then
364
     if [[ "$1" != "mesh" ]]; then
360
         nginx_ensite git_ssb
365
         nginx_ensite git_ssb
364
 function mesh_install_dat {
369
 function mesh_install_dat {
365
     get_npm_arch
370
     get_npm_arch
366
 
371
 
367
-    cat <<EOF > $rootdir/usr/bin/install_dat
372
+    cat <<EOF > "$rootdir/usr/bin/install_dat"
368
 #!/bin/bash
373
 #!/bin/bash
369
 npm install --arch=$NPM_ARCH -g dat
374
 npm install --arch=$NPM_ARCH -g dat
370
 npm install --arch=$NPM_ARCH -g @garbados/dat-boi
375
 npm install --arch=$NPM_ARCH -g @garbados/dat-boi
371
 npm install --arch=$NPM_ARCH -g add-to-systemd
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
 EOF
378
 EOF
374
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
379
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
375
     chroot "$rootdir" /usr/bin/install_dat
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
 function install_dat {
384
 function install_dat {
380
     npm install -g dat
385
     npm install -g dat
381
     npm install -g @garbados/dat-boi
386
     npm install -g @garbados/dat-boi
382
     npm install -g add-to-systemd
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
 function mesh_install_scuttlebot {
391
 function mesh_install_scuttlebot {
390
 
395
 
391
     get_npm_arch
396
     get_npm_arch
392
 
397
 
393
-    cat <<EOF > $rootdir/usr/bin/install_scuttlebot
398
+    cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
394
 #!/bin/bash
399
 #!/bin/bash
395
 npm install --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}
400
 npm install --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}
396
 npm install --arch=$NPM_ARCH -g git-ssb
401
 npm install --arch=$NPM_ARCH -g git-ssb
398
 EOF
403
 EOF
399
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
404
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
400
     chroot "$rootdir" /usr/bin/install_scuttlebot
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
         echo $'Scuttlebot was not installed'
409
         echo $'Scuttlebot was not installed'
405
         exit 528253
410
         exit 528253
406
     fi
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
     fi
415
     fi
411
 
416
 
412
     # an unprivileged user to run as
417
     # an unprivileged user to run as
413
     chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
418
     chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
414
 
419
 
415
     # daemon
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
     scuttlebot_git_setup mesh
438
     scuttlebot_git_setup mesh
434
     git_ssb_script mesh
439
     git_ssb_script mesh
455
     useradd -d /etc/scuttlebot/ scuttlebot
460
     useradd -d /etc/scuttlebot/ scuttlebot
456
 
461
 
457
     # daemon
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
     chown -R scuttlebot:scuttlebot /etc/scuttlebot
480
     chown -R scuttlebot:scuttlebot /etc/scuttlebot
476
 
481
 
489
         exit 73528
494
         exit 73528
490
     fi
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
     chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
515
     chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
511
     systemctl restart scuttlebot.service
516
     systemctl restart scuttlebot.service
512
 
517
 
527
 
532
 
528
     systemctl restart nginx
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
     else
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
     fi
539
     fi
535
 
540
 
536
     APP_INSTALLED=1
541
     APP_INSTALLED=1

+ 607
- 611
src/freedombone-app-searx
文件差異過大導致無法顯示
查看文件