Bob Mottram vor 7 Jahren
Ursprung
Commit
7888f7ae63
6 geänderte Dateien mit 818 neuen und 789 gelöschten Zeilen
  1. 97
    89
      src/freedombone-app-syncthing
  2. 163
    156
      src/freedombone-app-tahoelafs
  3. 197
    201
      src/freedombone-app-tox
  4. 81
    73
      src/freedombone-app-turtl
  5. 62
    60
      src/freedombone-app-vim
  6. 218
    210
      src/freedombone-app-vpn

+ 97
- 89
src/freedombone-app-syncthing Datei anzeigen

@@ -66,12 +66,12 @@ function syncthing_create_ids_file {
66 66
 
67 67
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
68 68
     if [ ! -f $SYNCTHING_CONFIG_FILE ]; then
69
-        echo $'# Your syncthing configuration file' > $SYNCTHING_CONFIG_FILE
70
-        echo '#' >> $SYNCTHING_CONFIG_FILE
71
-        echo $"# The ${PROJECT_NAME} syncthing ID is: $SYNCTHING_ID" >> $SYNCTHING_CONFIG_FILE
72
-        echo '#' >> $SYNCTHING_CONFIG_FILE
73
-        echo '# Paste the IDs of your devices below' >> $SYNCTHING_CONFIG_FILE
74
-        echo '#' >> $SYNCTHING_CONFIG_FILE
69
+        { echo $'# Your syncthing configuration file';
70
+          echo '#';
71
+          echo $"# The ${PROJECT_NAME} syncthing ID is: $SYNCTHING_ID";
72
+          echo '#';
73
+          echo '# Paste the IDs of your devices below';
74
+          echo '#'; } > $SYNCTHING_CONFIG_FILE
75 75
     fi
76 76
 }
77 77
 
@@ -94,12 +94,13 @@ function syncthing_show_id {
94 94
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
95 95
     dialog --title $"Device ID for ${PROJECT_NAME}" \
96 96
            --backtitle $"Freedombone User Control Panel" \
97
-           --msgbox $"In a desktop terminal press shift and select the ID below,\nthen right click and copy.\n\nWithin Connectbot select Menu/Copy and then highlight the ID below\n\n$SYNCTHING_ID\n\nAlternatively press Enter to display a QR code which can be scanned." 13 78
97
+           --msgbox $"In a desktop terminal press shift and select the ID below,\\nthen right click and copy.\\n\\nWithin Connectbot select Menu/Copy and then highlight the ID below\\n\\n$SYNCTHING_ID\\n\\nAlternatively press Enter to display a QR code which can be scanned." 13 78
98 98
     clear
99 99
     echo $'Your Syncthing ID code'
100 100
     echo ''
101 101
     echo -n "$SYNCTHING_ID" | qrencode -t UTF8
102 102
     echo ''
103
+    # shellcheck disable=SC2034
103 104
     read -n1 -rsp $"Press any key to continue..." key
104 105
 }
105 106
 
@@ -110,21 +111,24 @@ function syncthing_add_id {
110 111
 
111 112
     syncthing_create_ids_file
112 113
 
113
-    data=$(tempfile 2>/dev/null)
114
+    data=$(mktemp 2>/dev/null)
114 115
     trap "rm -f $data" 0 1 2 5 15
115 116
     dialog --backtitle $"Freedombone User Control Panel" \
116 117
            --title $"Add a Syncthing device ID" \
117 118
            --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \
118 119
            $"Device ID:" 1 1 "" 1 26 80 80 \
119 120
            $"Description (optional):" 2 1 "" 2 26 80 80 \
120
-           2> $data
121
+           2> "$data"
121 122
     sel=$?
122 123
     case $sel in
123
-        1) return;;
124
-        255) return;;
124
+        1) rm -f "$data"
125
+           return;;
126
+        255) rm -f "$data"
127
+             return;;
125 128
     esac
126
-    SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p)
127
-    SYNCTHING_DESCRIPTION=$(cat $data | sed -n 2p)
129
+    SYNCTHING_DEVICE_ID=$(sed -n 1p < "$data")
130
+    SYNCTHING_DESCRIPTION=$(sed -n 2p < "$data")
131
+    rm -f "$data"
128 132
 
129 133
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
130 134
         return
@@ -164,19 +168,21 @@ function syncthing_remove_id {
164 168
 
165 169
     syncthing_create_ids_file
166 170
 
167
-    data=$(tempfile 2>/dev/null)
168
-    trap "rm -f $data" 0 1 2 5 15
171
+    data=$(mktemp 2>/dev/null)
169 172
     dialog --backtitle $"Freedombone User Control Panel" \
170 173
            --title $"Remove a Syncthing device ID" \
171 174
            --form $"Paste the device ID which is to be removed below" 8 80 1 \
172 175
            $"Device ID:" 1 1 "" 1 14 80 80 \
173
-           2> $data
176
+           2> "$data"
174 177
     sel=$?
175 178
     case $sel in
176
-        1) return;;
177
-        255) return;;
179
+        1) rm -f "$data"
180
+           return;;
181
+        255) rm -f "$data"
182
+             return;;
178 183
     esac
179
-    SYNCTHING_DEVICE_ID=$(cat $data | sed -n 1p)
184
+    SYNCTHING_DEVICE_ID=$(sed -n 1p < "$data")
185
+    rm -f "$data"
180 186
 
181 187
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
182 188
         return
@@ -212,8 +218,7 @@ function run_client_syncthing {
212 218
 
213 219
     while true
214 220
     do
215
-        data=$(tempfile 2>/dev/null)
216
-        trap "rm -f $data" 0 1 2 5 15
221
+        data=$(mktemp 2>/dev/null)
217 222
         dialog --backtitle $"Freedombone User Control Panel" \
218 223
                --title $"File Synchronization" \
219 224
                --radiolist $"Choose an operation:" 12 70 6 \
@@ -221,19 +226,23 @@ function run_client_syncthing {
221 226
                2 $"Add an ID for another machine or device" off \
222 227
                3 $"Remove an ID for another machine or device" off \
223 228
                4 $"Manually edit device IDs" off \
224
-               5 $"Back to main menu" on 2> $data
229
+               5 $"Back to main menu" on 2> "$data"
225 230
         sel=$?
226 231
         case $sel in
227
-            1) break;;
228
-            255) break;;
232
+            1) rm -f "$data"
233
+               break;;
234
+            255) rm -f "$data"
235
+                 break;;
229 236
         esac
230
-        case $(cat $data) in
237
+        case $(cat "$data") in
231 238
             1) syncthing_show_id;;
232 239
             2) syncthing_add_id;;
233 240
             3) syncthing_remove_id;;
234 241
             4) syncthing_manual_edit;;
235
-            5) break;;
242
+            5) rm -f "$data"
243
+               break;;
236 244
         esac
245
+        rm -f "$data"
237 246
     done
238 247
 }
239 248
 
@@ -260,21 +269,21 @@ function backup_local_syncthing {
260 269
     for d in /home/*/ ; do
261 270
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
262 271
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
263
-            if [ -d /home/$USERNAME/Sync ]; then
272
+            if [ -d "/home/$USERNAME/Sync" ]; then
264 273
                 echo $"Backing up syncthing files for $USERNAME"
265
-                backup_directory_to_usb /home/$USERNAME/Sync syncthing/$USERNAME
274
+                backup_directory_to_usb "/home/$USERNAME/Sync" "syncthing/$USERNAME"
266 275
                 # ensure that device IDs will be backed up as part of user config settings
267
-                if [ ! -d /home/$USERNAME/.config/syncthing ]; then
268
-                    mkdir -p /home/$USERNAME/.config/syncthing
269
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
276
+                if [ ! -d "/home/$USERNAME/.config/syncthing" ]; then
277
+                    mkdir -p "/home/$USERNAME/.config/syncthing"
278
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
270 279
                 fi
271
-                if [ -f /home/$USERNAME/.syncthing-server-id ]; then
272
-                    cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
273
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
280
+                if [ -f "/home/$USERNAME/.syncthing-server-id" ]; then
281
+                    cp "/home/$USERNAME/.syncthing-server-id" "/home/$USERNAME/.config/syncthing"
282
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
274 283
                 fi
275
-                if [ -f /home/$USERNAME/.syncthingids ]; then
276
-                    cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
277
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
284
+                if [ -f "/home/$USERNAME/.syncthingids" ]; then
285
+                    cp "/home/$USERNAME/.syncthingids" "/home/$USERNAME/.config/syncthing"
286
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
278 287
                 fi
279 288
             fi
280 289
         fi
@@ -288,7 +297,7 @@ function restore_local_syncthing {
288 297
     fi
289 298
 
290 299
     temp_restore_dir=/root/tempsyncthing
291
-    if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
300
+    if [ -d "$USB_MOUNT/backup/syncthingconfig" ]; then
292 301
         echo $"Restoring syncthing configuration"
293 302
         function_check restore_directory_from_usb
294 303
         restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
@@ -297,9 +306,7 @@ function restore_local_syncthing {
297 306
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
298 307
             mkdir -p $SYNCTHING_CONFIG_PATH
299 308
         fi
300
-        cp -r ${temp_restore_dir}config/* $SYNCTHING_CONFIG_PATH/
301
-
302
-        if [ ! "$?" = "0" ]; then
309
+        if ! cp -r ${temp_restore_dir}config/* $SYNCTHING_CONFIG_PATH/; then
303 310
             set_user_permissions
304 311
             backup_unmount_drive
305 312
             systemctl start syncthing
@@ -309,7 +316,7 @@ function restore_local_syncthing {
309 316
         rm -rf ${temp_restore_dir}config
310 317
     fi
311 318
 
312
-    if [ -d $USB_MOUNT/backup/syncthingshared ]; then
319
+    if [ -d "$USB_MOUNT/backup/syncthingshared" ]; then
313 320
         echo $"Restoring syncthing shared files"
314 321
         restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
315 322
         #cp -r ${temp_restore_dir}shared/* /
@@ -321,28 +328,29 @@ function restore_local_syncthing {
321 328
         rm -rf ${temp_restore_dir}shared
322 329
     fi
323 330
 
324
-    if [ -d $USB_MOUNT/backup/syncthing ]; then
331
+    if [ -d "$USB_MOUNT/backup/syncthing" ]; then
325 332
         for d in $USB_MOUNT/backup/syncthing/*/ ; do
326 333
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
327 334
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
328
-                if [ ! -d /home/$USERNAME ]; then
329
-                    ${PROJECT_NAME}-adduser $USERNAME
335
+                if [ ! -d "/home/$USERNAME" ]; then
336
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
330 337
                 fi
331 338
                 echo $"Restoring syncthing files for $USERNAME"
332
-                restore_directory_from_usb ${temp_restore_dir} syncthing/$USERNAME
333
-                if [ -d ${temp_restore_dir}/home/$USERNAME/Sync ]; then
334
-                    cp -r ${temp_restore_dir}/home/$USERNAME/Sync /home/$USERNAME/
339
+                restore_directory_from_usb "${temp_restore_dir}" "syncthing/$USERNAME"
340
+                if [ -d "${temp_restore_dir}/home/$USERNAME/Sync" ]; then
341
+                    cp -r "${temp_restore_dir}/home/$USERNAME/Sync" "/home/$USERNAME/"
335 342
                 else
336
-                    if [ ! -d /home/$USERNAME/Sync ]; then
337
-                        mkdir /home/$USERNAME/Sync
343
+                    if [ ! -d "/home/$USERNAME/Sync" ]; then
344
+                        mkdir "/home/$USERNAME/Sync"
338 345
                     fi
339 346
                     if [ -d /root/Sync ]; then
340
-                        cp -r /root/Sync/* /home/$USERNAME/Sync/
347
+                        cp -r /root/Sync/* "/home/$USERNAME/Sync/"
341 348
                         rm -rf /root/Sync
342 349
                     else
343
-                        cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
350
+                        cp -r "${temp_restore_dir}/*" "/home/$USERNAME/Sync/"
344 351
                     fi
345 352
                 fi
353
+                # shellcheck disable=SC2181
346 354
                 if [ ! "$?" = "0" ]; then
347 355
                     rm -rf ${temp_restore_dir}
348 356
                     set_user_permissions
@@ -354,13 +362,13 @@ function restore_local_syncthing {
354 362
                 rm -rf ${temp_restore_dir}
355 363
 
356 364
                 # restore device IDs from config settings
357
-                if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
358
-                    cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
359
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
365
+                if [ -f "/home/$USERNAME/.config/syncthing/.syncthing-server-id" ]; then
366
+                    cp "/home/$USERNAME/.config/syncthing/.syncthing-server-id" "/home/$USERNAME/.syncthing-server-id"
367
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.syncthing-server-id"
360 368
                 fi
361
-                if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
362
-                    cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
363
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
369
+                if [ -f "/home/$USERNAME/.config/syncthing/.syncthingids" ]; then
370
+                    cp "/home/$USERNAME/.config/syncthing/.syncthingids" "/home/$USERNAME/.syncthingids"
371
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.syncthingids"
364 372
                 fi
365 373
             fi
366 374
         done
@@ -389,21 +397,21 @@ function backup_remote_syncthing {
389 397
     for d in /home/*/ ; do
390 398
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
391 399
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
392
-            if [ -d /home/$USERNAME/Sync ]; then
400
+            if [ -d "/home/$USERNAME/Sync" ]; then
393 401
                 echo $"Backing up syncthing files for $USERNAME"
394
-                backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME
402
+                backup_directory_to_friend "/home/$USERNAME/Sync" "syncthing/$USERNAME"
395 403
                 # ensure that device IDs will be backed up as part of user config settings
396
-                if [ ! -d /home/$USERNAME/.config/syncthing ]; then
397
-                    mkdir -p /home/$USERNAME/.config/syncthing
398
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
404
+                if [ ! -d "/home/$USERNAME/.config/syncthing" ]; then
405
+                    mkdir -p "/home/$USERNAME/.config/syncthing"
406
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
399 407
                 fi
400
-                if [ -f /home/$USERNAME/.syncthing-server-id ]; then
401
-                    cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
402
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
408
+                if [ -f "/home/$USERNAME/.syncthing-server-id" ]; then
409
+                    cp "/home/$USERNAME/.syncthing-server-id" "/home/$USERNAME/.config/syncthing"
410
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
403 411
                 fi
404
-                if [ -f /home/$USERNAME/.syncthingids ]; then
405
-                    cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
406
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
412
+                if [ -f "/home/$USERNAME/.syncthingids" ]; then
413
+                    cp "/home/$USERNAME/.syncthingids" "/home/$USERNAME/.config/syncthing"
414
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
407 415
                 fi
408 416
             fi
409 417
         fi
@@ -416,7 +424,7 @@ function restore_remote_syncthing {
416 424
         systemctl stop cron
417 425
     fi
418 426
 
419
-    if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
427
+    if [ -d "$SERVER_DIRECTORY/backup/syncthingconfig" ]; then
420 428
         echo $"Restoring syncthing configuration"
421 429
         temp_restore_dir=/root/tempsyncthingconfig
422 430
         function_check restore_directory_from_friend
@@ -425,8 +433,7 @@ function restore_remote_syncthing {
425 433
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
426 434
             mkdir -p $SYNCTHING_CONFIG_PATH
427 435
         fi
428
-        cp -r ${temp_restore_dir}/* $SYNCTHING_CONFIG_PATH/
429
-        if [ ! "$?" = "0" ]; then
436
+        if ! cp -r ${temp_restore_dir}/* $SYNCTHING_CONFIG_PATH/; then
430 437
             systemctl start syncthing
431 438
             systemctl start cron
432 439
             exit 6833
@@ -434,7 +441,7 @@ function restore_remote_syncthing {
434 441
         rm -rf $temp_restore_dir
435 442
     fi
436 443
 
437
-    if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
444
+    if [ -d "$SERVER_DIRECTORY/backup/syncthingshared" ]; then
438 445
         echo $"Restoring syncthing shared files"
439 446
         temp_restore_dir=/root/tempsyncthingshared
440 447
         function_check restore_directory_from_friend
@@ -446,30 +453,31 @@ function restore_remote_syncthing {
446 453
         rm -rf ${temp_restore_dir}
447 454
     fi
448 455
 
449
-    if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
456
+    if [ -d "$SERVER_DIRECTORY/backup/syncthing" ]; then
450 457
         for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
451 458
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
452 459
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
453
-                if [ ! -d /home/$USERNAME ]; then
454
-                    ${PROJECT_NAME}-adduser $USERNAME
460
+                if [ ! -d "/home/$USERNAME" ]; then
461
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
455 462
                 fi
456 463
                 echo $"Restoring syncthing files for $USERNAME"
457 464
                 temp_restore_dir=/root/tempsyncthing
458 465
                 function_check restore_directory_from_friend
459
-                restore_directory_from_friend $temp_restore_dir syncthing/$USERNAME
460
-                if [ -d $temp_restore_dir/home/$USERNAME/Sync ]; then
461
-                    cp -r $temp_restore_dir/home/$USERNAME/Sync /home/$USERNAME/
466
+                restore_directory_from_friend "$temp_restore_dir" "syncthing/$USERNAME"
467
+                if [ -d "$temp_restore_dir/home/$USERNAME/Sync" ]; then
468
+                    cp -r "$temp_restore_dir/home/$USERNAME/Sync" "/home/$USERNAME/"
462 469
                 else
463
-                    if [ ! -d /home/$USERNAME/Sync ]; then
464
-                        mkdir /home/$USERNAME/Sync
470
+                    if [ ! -d "/home/$USERNAME/Sync" ]; then
471
+                        mkdir "/home/$USERNAME/Sync"
465 472
                     fi
466 473
                     if [ -d /root/Sync ]; then
467
-                        cp -r /root/Sync/* /home/$USERNAME/Sync/
474
+                        cp -r /root/Sync/* "/home/$USERNAME/Sync/"
468 475
                         rm -rf /root/Sync
469 476
                     else
470
-                        cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
477
+                        cp -r "${temp_restore_dir}/*" "/home/$USERNAME/Sync/"
471 478
                     fi
472 479
                 fi
480
+                # shellcheck disable=SC2181
473 481
                 if [ ! "$?" = "0" ]; then
474 482
                     rm -rf $temp_restore_dir
475 483
                     systemctl start syncthing
@@ -479,13 +487,13 @@ function restore_remote_syncthing {
479 487
                 rm -rf $temp_restore_dir
480 488
 
481 489
                 # restore device IDs from config settings
482
-                if [ -f /home/$USERNAME/.config/syncthing/.syncthing-server-id ]; then
483
-                    cp /home/$USERNAME/.config/syncthing/.syncthing-server-id /home/$USERNAME/.syncthing-server-id
484
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
490
+                if [ -f "/home/$USERNAME/.config/syncthing/.syncthing-server-id" ]; then
491
+                    cp "/home/$USERNAME/.config/syncthing/.syncthing-server-id" "/home/$USERNAME/.syncthing-server-id"
492
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.syncthing-server-id"
485 493
                 fi
486
-                if [ -f /home/$USERNAME/.config/syncthing/.syncthingids ]; then
487
-                    cp /home/$USERNAME/.config/syncthing/.syncthingids /home/$USERNAME/.syncthingids
488
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.syncthingids
494
+                if [ -f "/home/$USERNAME/.config/syncthing/.syncthingids" ]; then
495
+                    cp "/home/$USERNAME/.config/syncthing/.syncthingids" "/home/$USERNAME/.syncthingids"
496
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.syncthingids"
489 497
                 fi
490 498
                 echo $"Restore of syncthing files for $USERNAME complete"
491 499
             fi

+ 163
- 156
src/freedombone-app-tahoelafs Datei anzeigen

@@ -72,52 +72,52 @@ function add_user_tahoelafs {
72 72
 
73 73
     new_username="$1"
74 74
     new_user_password="$2"
75
-    ${PROJECT_NAME}-pass -u $new_username -a tahoelafs -p "$new_user_password"
75
+    "${PROJECT_NAME}-pass" -u "$new_username" -a tahoelafs -p "$new_user_password"
76 76
     if grep -q "${new_username}:" /etc/nginx/.htpasswd-tahoelafs; then
77
-        sed -i '/${new_username}:/d' /etc/nginx/.htpasswd-tahoelafs
77
+        sed -i "'/${new_username}:/d" /etc/nginx/.htpasswd-tahoelafs
78 78
     fi
79
-    echo "${new_user_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${new_username}
79
+    echo "${new_user_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs "${new_username}"
80 80
     echo '0'
81 81
 }
82 82
 
83 83
 function remove_user_tahoelafs {
84 84
     remove_username="$1"
85
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp tahoelafs
85
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp tahoelafs
86 86
     if grep -q "${remove_username}:" /etc/nginx/.htpasswd-tahoelafs; then
87
-        sed -i '/${remove_username}:/d' /etc/nginx/.htpasswd-tahoelafs
87
+        sed -i "/${remove_username}:/d" /etc/nginx/.htpasswd-tahoelafs
88 88
     fi
89 89
 }
90 90
 
91 91
 function change_password_tahoelafs {
92 92
     change_username="$1"
93 93
     change_password="$2"
94
-    ${PROJECT_NAME}-pass -u $change_username -a tahoelafs -p "$change_password"
94
+    "${PROJECT_NAME}-pass" -u "$change_username" -a tahoelafs -p "$change_password"
95 95
     if grep -q "${change_username}:" /etc/nginx/.htpasswd-tahoelafs; then
96
-        sed -i '/tahoe-${change_username}:/d' /etc/nginx/.htpasswd-tahoelafs
96
+        sed -i "/tahoe-${change_username}:/d" /etc/nginx/.htpasswd-tahoelafs
97 97
     fi
98
-    echo "${change_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${change_username}
98
+    echo "${change_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs "${change_username}"
99 99
 }
100 100
 
101 101
 function add_tahoelafs_storage_node_interactive {
102
-    data=$(tempfile 2>/dev/null)
103
-    trap "rm -f $data" 0 1 2 5 15
102
+    data=$(mktemp 2>/dev/null)
104 103
     dialog --backtitle $"Freedombone Configuration" \
105 104
            --title $"Add Tahoe-LAFS storage node" \
106
-           --form $"\nEnter the storage node details which can be found on the About screen of another server" 13 75 5 \
105
+           --form $"\\nEnter the storage node details which can be found on the About screen of another server" 13 75 5 \
107 106
            $"Hostname:" 1 1 "" 1 14 53 40 \
108 107
            $"Public Key:" 2 1 "" 2 14 53 255 \
109 108
            $"Nickname:" 3 1 "" 3 14 53 255 \
110 109
            $"FURL:" 4 1 "" 4 14 53 255 \
111
-           2> $data
110
+           2> "$data"
112 111
     sel=$?
113 112
     case $sel in
114 113
         1) return;;
115 114
         255) return;;
116 115
     esac
117
-    storage_hostname=$(cat $data | sed -n 1p)
118
-    public_key="$(cat $data | sed -n 2p)"
119
-    nick=$(cat $data | sed -n 3p)
120
-    furl=$(cat $data | sed -n 4p)
116
+    storage_hostname=$(sed -n 1p < "$data")
117
+    public_key=$(sed -n 2p < "$data")
118
+    nick=$(sed -n 3p < "$data")
119
+    furl=$(sed -n 4p < "$data")
120
+    rm -f "$data"
121 121
 
122 122
     if [ ${#public_key} -eq 0 ]; then
123 123
         return
@@ -142,23 +142,26 @@ function edit_tahoelafs_shares {
142 142
     read_config_param TAHOELAFS_SHARES_HAPPY
143 143
     read_config_param TAHOELAFS_SHARES_TOTAL
144 144
 
145
-    data=$(tempfile 2>/dev/null)
146
-    trap "rm -f $data" 0 1 2 5 15
145
+    data=$(mktemp 2>/dev/null)
147 146
     dialog --backtitle $"Freedombone Configuration" \
148 147
            --title $"Tahoe-LAFS shares" \
149
-           --form $"\nEnter the storage node details which can be found on the About screen of another server" 13 40 3 \
148
+           --form $"\\nEnter the storage node details which can be found on the About screen of another server" 13 40 3 \
150 149
            $"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
151 150
            $"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
152 151
            $"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
153
-           2> $data
152
+           2> "$data"
154 153
     sel=$?
155 154
     case $sel in
156
-        1) return;;
157
-        255) return;;
155
+        1) rm -f "$data"
156
+           return;;
157
+        255) rm -f "$data"
158
+             return;;
158 159
     esac
159
-    tl_needed="$(cat $data | sed -n 1p)"
160
-    tl_happy="$(cat $data | sed -n 2p)"
161
-    tl_total="$(cat $data | sed -n 3p)"
160
+    tl_needed=$(sed -n 1p < "$data")
161
+    tl_happy=$(sed -n 2p < "$data")
162
+    tl_total=$(sed -n 3p < "$data")
163
+    rm -f "$data"
164
+
162 165
     if [ ${#tl_needed} -gt 0 ]; then
163 166
         TAHOELAFS_SHARES_NEEDED=${tl_needed}
164 167
     fi
@@ -185,88 +188,90 @@ function edit_tahoelafs_shares {
185 188
 }
186 189
 
187 190
 function configure_interactive_tahoelafs {
188
-    data=$(tempfile 2>/dev/null)
189
-    trap "rm -f $data" 0 1 2 5 15
191
+    data=$(mktemp 2>/dev/null)
190 192
     dialog --backtitle $"Freedombone Configuration" \
191 193
            --title $"Tahoe-LAFS" \
192 194
            --radiolist $"The least authority is always the best" 11 50 5 \
193 195
            1 "Add a storage node" off \
194 196
            2 "Manually edit storage nodes" off \
195 197
            3 "Shares settings" off \
196
-           4 "Back to main menu" on 2> $data
198
+           4 "Back to main menu" on 2> "$data"
197 199
     sel=$?
198 200
     case $sel in
199
-        1) exit 1;;
200
-        255) exit 1;;
201
+        1) rm -f "$data"
202
+           exit 1;;
203
+        255) rm -f "$data"
204
+             exit 1;;
201 205
     esac
202
-    case $(cat $data) in
206
+    case $(cat "$data") in
203 207
         1) add_tahoelafs_storage_node_interactive;;
204 208
         2) edit_tahoelafs_nodes;;
205 209
         3) edit_tahoelafs_shares;;
206 210
     esac
211
+    rm -f "$data"
207 212
 }
208 213
 
209 214
 function tahoelafs_setup_client_config {
210
-    config_file=$1
215
+    config_file="$1"
211 216
     nick="$2"
212 217
 
213
-    echo '[node]' > $config_file
214
-    echo "nickname = $nick" >> $config_file
215
-    echo 'reveal-IP-address = false' >> $config_file
216
-    echo "web.port = tcp:${TAHOELAFS_PORT}:interface=127.0.0.1" >> $config_file
217
-    echo 'web.static = public_html' >> $config_file
218
-    echo 'tub.port = disabled' >> $config_file
219
-    echo 'tub.location = disabled' >> $config_file
220
-    echo '' >> $config_file
221
-    echo '[client]' >> $config_file
222
-    echo 'introducer.furl =' >> $config_file
223
-    echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
224
-    echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
225
-    echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
226
-    echo '' >> $config_file
227
-    echo '[storage]' >> $config_file
228
-    echo 'enabled = false' >> $config_file
229
-    echo 'reserved_space = 3G' >> $config_file
230
-    echo '' >> $config_file
231
-    echo '[helper]' >> $config_file
232
-    echo 'enabled = false' >> $config_file
233
-    echo '' >> $config_file
234
-    echo '[connections]' >> $config_file
235
-    echo 'tcp = tor' >> $config_file
218
+    { echo '[node]';
219
+      echo "nickname = $nick";
220
+      echo 'reveal-IP-address = false';
221
+      echo "web.port = tcp:${TAHOELAFS_PORT}:interface=127.0.0.1";
222
+      echo 'web.static = public_html';
223
+      echo 'tub.port = disabled';
224
+      echo 'tub.location = disabled';
225
+      echo '';
226
+      echo '[client]';
227
+      echo 'introducer.furl =';
228
+      echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}";
229
+      echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}";
230
+      echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}";
231
+      echo '';
232
+      echo '[storage]';
233
+      echo 'enabled = false';
234
+      echo 'reserved_space = 3G';
235
+      echo '';
236
+      echo '[helper]';
237
+      echo 'enabled = false';
238
+      echo '';
239
+      echo '[connections]';
240
+      echo 'tcp = tor'; } > "$config_file"
236 241
 }
237 242
 
238 243
 function tahoelafs_setup_storage_config {
239
-    config_file=$1
244
+    config_file="$1"
240 245
     nick="$2"
241 246
 
242
-    echo '[node]' > $config_file
243
-    echo "nickname = $nick" >> $config_file
244
-    echo 'reveal-IP-address = false' >> $config_file
245
-    echo 'web.port =' >> $config_file
246
-    echo 'web.static = public_html' >> $config_file
247
-    echo "tub.port = tcp:${TAHOELAFS_STORAGE_ONION_PORT}:interface=127.0.0.1" >> $config_file
248
-    echo "tub.location = tor:${TAHOELAFS_STORAGE_ONION_HOSTNAME}:${TAHOELAFS_STORAGE_PORT}" >> $config_file
249
-    echo '' >> $config_file
250
-    echo '[client]' >> $config_file
251
-    echo 'introducer.furl =' >> $config_file
252
-    echo 'helper.furl =' >> $config_file
253
-    echo '' >> $config_file
254
-    echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}" >> $config_file
255
-    echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}" >> $config_file
256
-    echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}" >> $config_file
257
-    echo '' >> $config_file
258
-    echo '[storage]' >> $config_file
259
-    echo 'enabled = true' >> $config_file
260
-    echo 'reserved_space = 3G' >> $config_file
261
-    echo 'expire.enabled = true' >> $config_file
262
-    echo 'expire.mode = age' >> $config_file
263
-    echo 'expire.override_lease_duration = 3 months' >> $config_file
264
-    echo '' >> $config_file
265
-    echo '[helper]' >> $config_file
266
-    echo 'enabled = false' >> $config_file
267
-    echo '' >> $config_file
268
-    echo '[connections]' >> $config_file
269
-    echo 'tcp = tor' >> $config_file
247
+    { echo '[node]';
248
+      echo "nickname = $nick";
249
+      echo 'reveal-IP-address = false';
250
+      echo 'web.port =';
251
+      echo 'web.static = public_html';
252
+      echo "tub.port = tcp:${TAHOELAFS_STORAGE_ONION_PORT}:interface=127.0.0.1";
253
+      echo "tub.location = tor:${TAHOELAFS_STORAGE_ONION_HOSTNAME}:${TAHOELAFS_STORAGE_PORT}";
254
+      echo '';
255
+      echo '[client]';
256
+      echo 'introducer.furl =';
257
+      echo 'helper.furl =';
258
+      echo '';
259
+      echo "shares.needed = ${TAHOELAFS_SHARES_NEEDED}";
260
+      echo "shares.happy = ${TAHOELAFS_SHARES_HAPPY}";
261
+      echo "shares.total = ${TAHOELAFS_SHARES_TOTAL}";
262
+      echo '';
263
+      echo '[storage]';
264
+      echo 'enabled = true';
265
+      echo 'reserved_space = 3G';
266
+      echo 'expire.enabled = true';
267
+      echo 'expire.mode = age';
268
+      echo 'expire.override_lease_duration = 3 months';
269
+      echo '';
270
+      echo '[helper]';
271
+      echo 'enabled = false';
272
+      echo '';
273
+      echo '[connections]';
274
+      echo 'tcp = tor'; } > "$config_file"
270 275
 
271 276
     chown -R tahoelafs:debian-tor $TAHOE_DIR
272 277
 }
@@ -304,6 +309,7 @@ function restore_local_tahoelafs {
304 309
     else
305 310
         cp -r $temp_restore_dir/* $TAHOE_DIR/
306 311
     fi
312
+    # shellcheck disable=SC2181
307 313
     if [ ! "$?" = "0" ]; then
308 314
         if [ -d ${TAHOE_DIR}-old ]; then
309 315
             mv ${TAHOE_DIR}-old $TAHOE_DIR
@@ -346,14 +352,15 @@ function restore_remote_tahoelafs {
346 352
     else
347 353
         cp -r $temp_restore_dir/* $TAHOE_DIR/
348 354
     fi
355
+    # shellcheck disable=SC2181
349 356
     if [ ! "$?" = "0" ]; then
350
-        if [ -d ${$TAHOE_DIR}-old ]; then
351
-            mv ${TAHOE_DIR}-old $TAHOE_DIR
357
+        if [ -d "${TAHOE_DIR}-old" ]; then
358
+            mv "${TAHOE_DIR}-old" $TAHOE_DIR
352 359
         fi
353 360
         exit 623925
354 361
     fi
355
-    if [ -d ${$TAHOE_DIR}-old ]; then
356
-        rm -rf ${$TAHOE_DIR}-old
362
+    if [ -d "${TAHOE_DIR}-old" ]; then
363
+        rm -rf "${TAHOE_DIR}-old"
357 364
     fi
358 365
     rm -rf $temp_restore_dir
359 366
     chown -R tahoelafs:debian-tor $TAHOE_DIR
@@ -398,7 +405,7 @@ function remove_tahoelafs {
398 405
     remove_completion_param install_tahoelafs
399 406
     function_check remove_onion_service
400 407
     remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT}
401
-    remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} $(get_tahoelafs_nick)
408
+    remove_onion_service storage-tahoelafs ${TAHOELAFS_STORAGE_ONION_PORT} "$(get_tahoelafs_nick)"
402 409
     sed -i '/HidServAuth /d' /etc/tor/torrc
403 410
 
404 411
     groupdel -f tahoelafs
@@ -437,23 +444,23 @@ function create_tahoelafs_stealth_node {
437 444
         exit 682362
438 445
     fi
439 446
 
440
-    if [ ! -f ${node_dir}/tahoe.cfg ]; then
447
+    if [ ! -f "${node_dir}/tahoe.cfg" ]; then
441 448
         su -c "mkdir ${node_dir}" - tahoelafs
442 449
         su -c "$TAHOE_COMMAND create-node -C ${node_dir} --hostname=fixme" - tahoelafs
443
-        tahoelafs_setup_storage_config ${node_dir}/tahoe.cfg ${node_nick}
450
+        tahoelafs_setup_storage_config "${node_dir}/tahoe.cfg" "${node_nick}"
444 451
     fi
445 452
 
446
-    if [ ! -f ${client_dir}/tahoe.cfg ]; then
453
+    if [ ! -f "${client_dir}/tahoe.cfg" ]; then
447 454
         su -c "mkdir ${client_dir}" - tahoelafs
448 455
         su -c "$TAHOE_COMMAND create-client -C ${client_dir}" - tahoelafs
449
-        tahoelafs_setup_client_config ${client_dir}/tahoe.cfg ${client_nick}
456
+        tahoelafs_setup_client_config "${client_dir}/tahoe.cfg" "${client_nick}"
450 457
     fi
451 458
 }
452 459
 
453 460
 function create_tahoelafs_introducer {
454 461
     introducer_dir="$1"
455 462
 
456
-    if [ -f ${introducer_dir}/tahoe.cfg ]; then
463
+    if [ -f "${introducer_dir}/tahoe.cfg" ]; then
457 464
         return
458 465
     fi
459 466
 
@@ -470,7 +477,7 @@ function create_tahoelafs_storage_node {
470 477
         return
471 478
     fi
472 479
 
473
-    if [ -f ${node_dir}/tahoe.cfg ]; then
480
+    if [ -f "${node_dir}/tahoe.cfg" ]; then
474 481
         return
475 482
     fi
476 483
 
@@ -487,15 +494,15 @@ function create_tahoelafs_client {
487 494
         return
488 495
     fi
489 496
 
490
-    if [ -f ${client_dir}/tahoe.cfg ]; then
497
+    if [ -f "${client_dir}/tahoe.cfg" ]; then
491 498
         return
492 499
     fi
493 500
 
494 501
     su -c "mkdir ${client_dir}" - tahoelafs
495 502
     su -c "$TAHOE_COMMAND create-client -C ${client_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
496
-    sed -i 's|reveal-IP-address =.*|reveal-IP-address = False|g' $client_dir/tahoe.cfg
497
-    sed -i 's|tub.port =.*|tub.port = disabled|g' $client_dir/tahoe.cfg
498
-    sed -i 's|tub.location =.*|tub.location = disabled|g' $client_dir/tahoe.cfg
503
+    sed -i 's|reveal-IP-address =.*|reveal-IP-address = False|g' "$client_dir/tahoe.cfg"
504
+    sed -i 's|tub.port =.*|tub.port = disabled|g' "$client_dir/tahoe.cfg"
505
+    sed -i 's|tub.location =.*|tub.location = disabled|g' "$client_dir/tahoe.cfg"
499 506
 }
500 507
 
501 508
 function get_tahoelafs_furl {
@@ -510,11 +517,11 @@ function get_tahoelafs_nick {
510 517
 }
511 518
 
512 519
 function get_tahoelafs_storage_hostname {
513
-    echo "$(cat /var/lib/tor/hidden_service_storage-tahoelafs/hostname)"
520
+    cat /var/lib/tor/hidden_service_storage-tahoelafs/hostname
514 521
 }
515 522
 
516 523
 function get_tahoelafs_public_key {
517
-    echo "$(cat $TAHOE_DIR/storage/node.pubkey | grep 'v0-' | sed 's|pub-||g')"
524
+    grep 'v0-' "$TAHOE_DIR/storage/node.pubkey" | sed 's|pub-||g'
518 525
 }
519 526
 
520 527
 function add_tahoelafs_server {
@@ -549,10 +556,10 @@ function add_tahoelafs_server {
549 556
         fi
550 557
         echo '# storage' >> ${tahoelafs_storage_file}
551 558
     fi
552
-    echo "  ${public_key}:" >> ${tahoelafs_storage_file}
553
-    echo "    ann:" >> ${tahoelafs_storage_file}
554
-    echo "      nickname: ${nick}" >> ${tahoelafs_storage_file}
555
-    echo "      anonymous-storage-FURL: ${furl}" >> ${tahoelafs_storage_file}
559
+    { echo "  ${public_key}:";
560
+      echo "    ann:";
561
+      echo "      nickname: ${nick}";
562
+      echo "      anonymous-storage-FURL: ${furl}"; } >> "${tahoelafs_storage_file}"
556 563
     chown tahoelafs:debian-tor ${tahoelafs_storage_file}
557 564
 
558 565
     if ! grep -q "HidServAuth ${storage_hostname}" /etc/tor/torrc; then
@@ -566,27 +573,27 @@ function create_tahoelafs_daemon {
566 573
     TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
567 574
     echo "Creating daemon: $TAHOELAFS_DAEMON_FILE"
568 575
 
569
-    echo '[Unit]' > $TAHOELAFS_DAEMON_FILE
570
-    echo "Description=Tahoe-LAFS ${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
571
-    echo 'After=syslog.target' >> $TAHOELAFS_DAEMON_FILE
572
-    echo 'After=network.target' >> $TAHOELAFS_DAEMON_FILE
573
-    echo '' >> $TAHOELAFS_DAEMON_FILE
574
-    echo '[Service]' >> $TAHOELAFS_DAEMON_FILE
575
-    echo 'Type=simple' >> $TAHOELAFS_DAEMON_FILE
576
-    echo "User=tahoelafs" >> $TAHOELAFS_DAEMON_FILE
577
-    echo "Group=debian-tor" >> $TAHOELAFS_DAEMON_FILE
578
-    echo "WorkingDirectory=${TAHOE_DIR}" >> $TAHOELAFS_DAEMON_FILE
579
-    echo "ExecStart=/usr/bin/tahoe run ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
580
-    echo "ExecStop=/usr/bin/tahoe stop ${TAHOE_DIR}/${daemon_name}" >> $TAHOELAFS_DAEMON_FILE
581
-    echo 'Restart=on-failure' >> $TAHOELAFS_DAEMON_FILE
582
-    echo 'RestartSec=10' >> $TAHOELAFS_DAEMON_FILE
583
-    echo "Environment=\"USER=tahoelafs\" \"HOME=${TAHOE_DIR}\"" >> $TAHOELAFS_DAEMON_FILE
584
-    echo '' >> $TAHOELAFS_DAEMON_FILE
585
-    echo '[Install]' >> $TAHOELAFS_DAEMON_FILE
586
-    echo 'WantedBy=multi-user.target' >> $TAHOELAFS_DAEMON_FILE
587
-    systemctl enable tahoelafs-${daemon_name}
576
+    { echo '[Unit]';
577
+      echo "Description=Tahoe-LAFS ${daemon_name}";
578
+      echo 'After=syslog.target';
579
+      echo 'After=network.target';
580
+      echo '';
581
+      echo '[Service]';
582
+      echo 'Type=simple';
583
+      echo "User=tahoelafs";
584
+      echo "Group=debian-tor";
585
+      echo "WorkingDirectory=${TAHOE_DIR}";
586
+      echo "ExecStart=/usr/bin/tahoe run ${TAHOE_DIR}/${daemon_name}";
587
+      echo "ExecStop=/usr/bin/tahoe stop ${TAHOE_DIR}/${daemon_name}";
588
+      echo 'Restart=on-failure';
589
+      echo 'RestartSec=10';
590
+      echo "Environment=\"USER=tahoelafs\" \"HOME=${TAHOE_DIR}\"";
591
+      echo '';
592
+      echo '[Install]';
593
+      echo 'WantedBy=multi-user.target'; } > "$TAHOELAFS_DAEMON_FILE"
594
+    systemctl enable "tahoelafs-${daemon_name}"
588 595
     systemctl daemon-reload
589
-    systemctl start tahoelafs-${daemon_name}
596
+    systemctl start "tahoelafs-${daemon_name}"
590 597
 }
591 598
 
592 599
 function create_tahoelafs_web {
@@ -596,44 +603,44 @@ function create_tahoelafs_web {
596 603
     TAHOELAFS_LOGIN_TEXT=$'Tahoe-LAFS login'
597 604
 
598 605
     tahoelafs_nginx_site=/etc/nginx/sites-available/tahoelafs
599
-    echo 'server {' > $tahoelafs_nginx_site
600
-    echo "    listen 127.0.0.1:$TAHOELAFS_ONION_PORT default_server;" >> $tahoelafs_nginx_site
601
-    echo "    server_name $TAHOELAFS_ONION_HOSTNAME;" >> $tahoelafs_nginx_site
602
-    echo '' >> $tahoelafs_nginx_site
606
+    { echo 'server {';
607
+      echo "    listen 127.0.0.1:$TAHOELAFS_ONION_PORT default_server;";
608
+      echo "    server_name $TAHOELAFS_ONION_HOSTNAME;";
609
+      echo ''; } > "$tahoelafs_nginx_site"
603 610
     function_check nginx_disable_sniffing
604 611
     nginx_disable_sniffing tahoelafs
605
-    echo '' >> $tahoelafs_nginx_site
606
-    echo '  # Logs' >> $tahoelafs_nginx_site
607
-    echo '  access_log /dev/null;' >> $tahoelafs_nginx_site
608
-    echo '  error_log /dev/null;' >> $tahoelafs_nginx_site
609
-    echo '' >> $tahoelafs_nginx_site
610
-    echo '  # Root' >> $tahoelafs_nginx_site
611
-    echo "  root /var/www/tahoelafs/htdocs;" >> $tahoelafs_nginx_site
612
-    echo '' >> $tahoelafs_nginx_site
613
-    echo '  location / {' >> $tahoelafs_nginx_site
614
-    echo "    auth_basic \"${TAHOELAFS_LOGIN_TEXT}\";" >> $tahoelafs_nginx_site
615
-    echo '    auth_basic_user_file /etc/nginx/.htpasswd-tahoelafs;' >> $tahoelafs_nginx_site
612
+    { echo '';
613
+      echo '  # Logs';
614
+      echo '  access_log /dev/null;';
615
+      echo '  error_log /dev/null;';
616
+      echo '';
617
+      echo '  # Root';
618
+      echo "  root /var/www/tahoelafs/htdocs;";
619
+      echo '';
620
+      echo '  location / {';
621
+      echo "    auth_basic \"${TAHOELAFS_LOGIN_TEXT}\";";
622
+      echo '    auth_basic_user_file /etc/nginx/.htpasswd-tahoelafs;'; } >> "$tahoelafs_nginx_site"
616 623
     function_check nginx_limits
617 624
     nginx_limits tahoelafs '15m'
618
-    echo '    rewrite /(.*) /$1 break;' >> $tahoelafs_nginx_site
619
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $tahoelafs_nginx_site
620
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $tahoelafs_nginx_site
621
-    echo '    proxy_set_header Host $http_host;' >> $tahoelafs_nginx_site
622
-    echo '    proxy_set_header X-NginX-Proxy true;' >> $tahoelafs_nginx_site
623
-    echo "    proxy_pass http://localhost:${TAHOELAFS_PORT};" >> $tahoelafs_nginx_site
624
-    echo '    proxy_redirect off;' >> $tahoelafs_nginx_site
625
-    echo '  }' >> $tahoelafs_nginx_site
626
-    echo '}' >> $tahoelafs_nginx_site
627
-
628
-    TAHOELAFS_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
629
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a tahoelafs -p "$TAHOELAFS_ADMIN_PASSWORD"
625
+    { echo "    rewrite /(.*) /\$1 break;";
626
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
627
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
628
+      echo "    proxy_set_header Host \$http_host;";
629
+      echo '    proxy_set_header X-NginX-Proxy true;';
630
+      echo "    proxy_pass http://localhost:${TAHOELAFS_PORT};";
631
+      echo '    proxy_redirect off;';
632
+      echo '  }';
633
+      echo '}'; } >> "$tahoelafs_nginx_site"
634
+
635
+    TAHOELAFS_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
636
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a tahoelafs -p "$TAHOELAFS_ADMIN_PASSWORD"
630 637
     if [ ! -f /etc/nginx/.htpasswd-tahoelafs ]; then
631 638
         touch /etc/nginx/.htpasswd-tahoelafs
632 639
     fi
633 640
     if grep -q "${MY_USERNAME}:" /etc/nginx/.htpasswd-tahoelafs; then
634
-        sed -i '/${MY_USERNAME}:/d' /etc/nginx/.htpasswd-tahoelafs
641
+        sed -i "/${MY_USERNAME}:/d" /etc/nginx/.htpasswd-tahoelafs
635 642
     fi
636
-    echo "${TAHOELAFS_ADMIN_PASSWORD}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${MY_USERNAME}
643
+    echo "${TAHOELAFS_ADMIN_PASSWORD}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs "${MY_USERNAME}"
637 644
 
638 645
     function_check nginx_ensite
639 646
     nginx_ensite tahoelafs
@@ -641,7 +648,7 @@ function create_tahoelafs_web {
641 648
 }
642 649
 
643 650
 function install_tahoelafs {
644
-    if [ $INSTALLING_MESH ]; then
651
+    if [ "$INSTALLING_MESH" ]; then
645 652
         return
646 653
     fi
647 654
 
@@ -692,7 +699,7 @@ function install_tahoelafs {
692 699
     # create an onion address for client node
693 700
     TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT})
694 701
 
695
-    create_tahoelafs_stealth_node $TAHOE_DIR/storage $TAHOE_DIR/client ${node_nick} ${client_nick}
702
+    create_tahoelafs_stealth_node "$TAHOE_DIR/storage" "$TAHOE_DIR/client" "${node_nick}" "${client_nick}"
696 703
 
697 704
     # start the storage node
698 705
     su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs

+ 197
- 201
src/freedombone-app-tox Datei anzeigen

@@ -74,12 +74,12 @@ function logging_off_tox {
74 74
 function remove_user_tox {
75 75
     remove_username="$1"
76 76
 
77
-    if [ -d /home/$remove_username/.config/tox ]; then
78
-        if [ -d /home/$remove_username/.config/tox/chatlogs ]; then
79
-            shred -zu /home/$remove_username/.config/tox/chatlogs/*
80
-            rm -rf /home/$remove_username/.config/tox/chatlogs
77
+    if [ -d "/home/$remove_username/.config/tox" ]; then
78
+        if [ -d "/home/$remove_username/.config/tox/chatlogs" ]; then
79
+            shred -zu "/home/$remove_username/.config/tox/chatlogs/*"
80
+            rm -rf "/home/$remove_username/.config/tox/chatlogs"
81 81
         fi
82
-        shred -zu /home/$remove_username/.config/tox/*
82
+        shred -zu "/home/$remove_username/.config/tox/*"
83 83
     fi
84 84
 }
85 85
 
@@ -87,27 +87,27 @@ function add_user_tox {
87 87
     new_username="$1"
88 88
 
89 89
     # Note: password isn't used
90
-    new_user_password="$2"
90
+    #new_user_password="$2"
91 91
 
92 92
     USER_TOX_FILE=/home/${new_username}/.config/tox/data.tox
93
-    if [ ! -f $USER_TOX_FILE ]; then
94
-        mkdir -p /home/${new_username}/.config/tox
95
-        chown -R ${new_username}:${new_username} /home/${new_username}/.config
96
-        su -c "toxid -u ${new_username} -n data" - $new_username
97
-        su -c "toxid --setuser ${new_username}" - $new_username
93
+    if [ ! -f "$USER_TOX_FILE" ]; then
94
+        mkdir -p "/home/${new_username}/.config/tox"
95
+        chown -R "${new_username}":"${new_username}" "/home/${new_username}/.config"
96
+        su -c "toxid -u ${new_username} -n data" - "$new_username"
97
+        su -c "toxid --setuser ${new_username}" - "$new_username"
98 98
     fi
99 99
 }
100 100
 
101 101
 function run_client_tox {
102 102
     # create a tox user
103 103
     USER_TOX_FILE=/home/${USER}/.config/tox/data.tox
104
-    if [ ! -f $USER_TOX_FILE ]; then
105
-        mkdir -p /home/${USER}/.config/tox
106
-        chown -R ${USER}:${USER} /home/${USER}/.config
107
-        toxid -u ${USER} -n data
108
-        toxid --setuser ${USER}
104
+    if [ ! -f "$USER_TOX_FILE" ]; then
105
+        mkdir -p "/home/${USER}/.config/tox"
106
+        chown -R "${USER}":"${USER}" "/home/${USER}/.config"
107
+        toxid -u "${USER}" -n data
108
+        toxid --setuser "${USER}"
109 109
     fi
110
-    toxic -f $USER_TOX_FILE --force-tcp --SOCKS5-proxy 127.0.0.1 9050
110
+    toxic -f "$USER_TOX_FILE" --force-tcp --SOCKS5-proxy 127.0.0.1 9050
111 111
 }
112 112
 
113 113
 function install_interactive_tox {
@@ -121,16 +121,17 @@ function configure_interactive_tox {
121 121
     fi
122 122
     bootstrap_id=$(cat $TOX_BOOTSTRAP_ID_FILE)
123 123
     dialog --title $"Tox Bootstrap Node ID" \
124
-           --msgbox $"\n$bootstrap_id\n\nTo copy this hold down the shift key, select the ID and then right click and copy." 10 70
124
+           --msgbox $"\\n$bootstrap_id\\n\\nTo copy this hold down the shift key, select the ID and then right click and copy." 10 70
125 125
 }
126 126
 
127 127
 function mesh_tox_qtox {
128
-    if [ ! ${rootdir}$INSTALL_DIR ]; then
128
+    # shellcheck disable=SC2154
129
+    if [ ! "${rootdir}$INSTALL_DIR" ]; then
129 130
         INSTALL_DIR=${rootdir}/root/build
130 131
     fi
131 132
 
132
-    if [ ! -d ${rootdir}$INSTALL_DIR ]; then
133
-        mkdir -p ${rootdir}$INSTALL_DIR
133
+    if [ ! -d "${rootdir}$INSTALL_DIR" ]; then
134
+        mkdir -p "${rootdir}$INSTALL_DIR"
134 135
     fi
135 136
 
136 137
     chroot "${rootdir}" apt-get -yq install build-essential libatk1.0-0 libbz2-1.0 libc6 libcairo2 libdbus-1-3 libegl1-mesa libfontconfig1 libfreetype6 libgcc1 libgdk-pixbuf2.0-0 libgl1-mesa-glx libglib2.0-0 libgtk2.0-0 libice6 libicu57 libjpeg62-turbo libmng1 libmtdev1 libopenal1 libopus0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpng16-16 libqrencode3 libsm6 libsodium18 libsqlite3-0 libssl1.1 libstdc++6 libtiff5 libudev1 libvpx4 libwayland-client0 libwayland-cursor0 libwayland-egl1-mesa libwebp6 libx11-6 libx11-xcb1 libxcb-glx0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-render0 libxcb-shape0 libxcb-shm0 libxcb-sync1 libxcb-xfixes0 libxcb-xinerama0 libxcb1 libxext6 libxfixes3 libxi6 libxrender1 libxss1 zlib1g libopus-dev libvpx-dev
@@ -149,30 +150,30 @@ function mesh_tox_qtox {
149 150
     chroot "${rootdir}" apt-get -yq install build-essential cmake ffmpeg libexif-dev libgdk-pixbuf2.0-dev libglib2.0-dev libgtk2.0-dev libopenal-dev libqrencode-dev libqt5opengl5-dev libqt5svg5-dev libsqlcipher-dev libxss-dev pkg-config qrencode qt5-default qt5-qmake qttools5-dev qttools5-dev-tools yasm
150 151
 
151 152
     if [ -d /repos/qtox ]; then
152
-        mkdir ${rootdir}$INSTALL_DIR/qtox
153
-        cp -r -p /repos/qtox/. ${rootdir}$INSTALL_DIR/qtox
154
-        cd ${rootdir}$INSTALL_DIR/qtox
153
+        mkdir "${rootdir}$INSTALL_DIR/qtox"
154
+        cp -r -p /repos/qtox/. "${rootdir}$INSTALL_DIR/qtox"
155
+        cd "${rootdir}$INSTALL_DIR/qtox" || exit 264826826
155 156
         git pull
156 157
     else
157
-        git clone $QTOX_REPO ${rootdir}$INSTALL_DIR/qtox
158
+        git clone "$QTOX_REPO" "${rootdir}$INSTALL_DIR/qtox"
158 159
     fi
159 160
 
160
-    if [ ! -d ${rootdir}$INSTALL_DIR/qtox ]; then
161
+    if [ ! -d "${rootdir}$INSTALL_DIR/qtox" ]; then
161 162
         exit 72428
162 163
     fi
163
-    cd ${rootdir}${INSTALL_DIR}/qtox
164
+    cd "${rootdir}${INSTALL_DIR}/qtox" || exit 235745728
164 165
     git checkout $QTOX_COMMIT -b $QTOX_COMMIT
165
-    chroot ${rootdir} /bin/bash -x <<EOF
166
+    chroot "${rootdir}" /bin/bash -x <<EOF
166 167
 cd ${INSTALL_DIR}/qtox
167 168
 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
168 169
 cmake .
169 170
 make
170 171
 make install
171 172
 EOF
172
-    if [ ! -f ${rootdir}/usr/local/bin/qtox ]; then
173
+    if [ ! -f "${rootdir}/usr/local/bin/qtox" ]; then
173 174
         exit 75784
174 175
     fi
175
-    cp ${rootdir}/usr/local/bin/qtox ${rootdir}/usr/bin/qtox
176
+    cp "${rootdir}/usr/local/bin/qtox" "${rootdir}/usr/bin/qtox"
176 177
 }
177 178
 
178 179
 function reconfigure_tox {
@@ -181,9 +182,9 @@ function reconfigure_tox {
181 182
 
182 183
 function upgrade_tox {
183 184
     function_check set_repo_commit
184
-    set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
185
-    if [[ $(commit_has_changed $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT") == "1" ]]; then
186
-        cd $INSTALL_DIR/toxcore
185
+    set_repo_commit "$INSTALL_DIR/toxcore" "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
186
+    if [[ $(commit_has_changed "$INSTALL_DIR/toxcore" "toxcore commit" "$TOXCORE_COMMIT") == "1" ]]; then
187
+        cd "$INSTALL_DIR/toxcore" || exit 53683563
187 188
         sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
188 189
         autoreconf -i
189 190
         ./configure --enable-daemon
@@ -194,9 +195,9 @@ function upgrade_tox {
194 195
     fi
195 196
 
196 197
     function_check set_repo_commit
197
-    set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
198
-    if [[ $(commit_has_changed $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT") == "1" ]]; then
199
-        cd $INSTALL_DIR/toxic
198
+    set_repo_commit "$INSTALL_DIR/toxic" "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
199
+    if [[ $(commit_has_changed "$INSTALL_DIR/toxic" "Toxic commit" "$TOXIC_COMMIT") == "1" ]]; then
200
+        cd "$INSTALL_DIR/toxic" || exit 4684618
200 201
         make
201 202
         make install
202 203
     fi
@@ -221,12 +222,11 @@ function backup_local_tox {
221 222
 }
222 223
 
223 224
 function restore_local_tox {
224
-    if [ -d $USB_MOUNT/backup/tox ]; then
225
+    if [ -d "$USB_MOUNT/backup/tox" ]; then
225 226
         echo $"Restoring Tox node settings"
226 227
         function_check restore_directory_from_usb
227 228
         #restore_directory_from_usb / tox
228
-        restore_directory_from_usb /var/lib/tox-bootstrapd tox
229
-        if [ ! "$?" = "0" ]; then
229
+        if ! restore_directory_from_usb /var/lib/tox-bootstrapd tox; then
230 230
             function_check set_user_permissions
231 231
             set_user_permissions
232 232
             function_check backup_unmount_drive
@@ -234,8 +234,7 @@ function restore_local_tox {
234 234
             exit 6393
235 235
         fi
236 236
         cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
237
-        systemctl restart tox-bootstrapd.service
238
-        if [ ! "$?" = "0" ]; then
237
+        if ! systemctl restart tox-bootstrapd.service; then
239 238
             systemctl status tox-bootstrapd.service
240 239
             function_check set_user_permissions
241 240
             set_user_permissions
@@ -259,17 +258,15 @@ function backup_remote_tox {
259 258
 }
260 259
 
261 260
 function restore_remote_tox {
262
-    if [ -d $SERVER_DIRECTORY/backup/tox ]; then
261
+    if [ -d "$SERVER_DIRECTORY/backup/tox" ]; then
263 262
         echo $"Restoring Tox node settings"
264 263
         function_check restore_directory_from_friend
265 264
         #restore_directory_from_friend / tox
266
-        restore_directory_from_friend /var/lib/tox-bootstrapd tox
267
-        if [ ! "$?" = "0" ]; then
265
+        if ! restore_directory_from_friend /var/lib/tox-bootstrapd tox; then
268 266
             exit 93653
269 267
         fi
270 268
         cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
271
-        systemctl restart tox-bootstrapd.service
272
-        if [ ! "$?" = "0" ]; then
269
+        if ! systemctl restart tox-bootstrapd.service; then
273 270
             systemctl status tox-bootstrapd.service
274 271
             exit 59369
275 272
         fi
@@ -283,8 +280,7 @@ function remove_tox_node {
283 280
     function_check remove_onion_service
284 281
     remove_onion_service tox ${TOX_PORT}
285 282
 
286
-    ${PROJECT_NAME}-mesh-install -f tox_node --remove yes
287
-    if [ ! "$?" = "0" ]; then
283
+    if ! "${PROJECT_NAME}-mesh-install" -f tox_node --remove yes; then
288 284
         echo $'Failed to remove tox node'
289 285
         exit 763836
290 286
     fi
@@ -293,21 +289,20 @@ function remove_tox_node {
293 289
 }
294 290
 
295 291
 function remove_tox_avahi {
296
-    cd $INSTALL_DIR/toxid
292
+    cd "$INSTALL_DIR/toxid" || exit 82456275
297 293
     make uninstall
298
-    rm -rf $INSTALL_DIR/toxid
299
-    sed -i '/tox_avahi/d' $COMPLETION_FILE
294
+    rm -rf "$INSTALL_DIR/toxid"
295
+    sed -i '/tox_avahi/d' "$COMPLETION_FILE"
300 296
 }
301 297
 
302 298
 function remove_tox_client {
303
-    ${PROJECT_NAME}-mesh-install -f tox_client --remove yes
304
-    if [ ! "$?" = "0" ]; then
299
+    if ! "${PROJECT_NAME}-mesh-install" -f tox_client --remove yes; then
305 300
         echo $'Could not remove Tox client'
306 301
         exit 737253
307 302
     fi
308
-    sed -i '/install_tox_client/d' $COMPLETION_FILE
309
-    sed -i '/Tox /d' $COMPLETION_FILE
310
-    sed -i '/Toxic /d' $COMPLETION_FILE
303
+    sed -i '/install_tox_client/d' "$COMPLETION_FILE"
304
+    sed -i '/Tox /d' "$COMPLETION_FILE"
305
+    sed -i '/Toxic /d' "$COMPLETION_FILE"
311 306
 }
312 307
 
313 308
 function remove_tox {
@@ -317,7 +312,7 @@ function remove_tox {
317 312
 }
318 313
 
319 314
 function configure_firewall_for_tox {
320
-    if [ ! $INSTALLING_MESH ]; then
315
+    if [ ! "$INSTALLING_MESH" ]; then
321 316
         if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
322 317
             return
323 318
         fi
@@ -331,16 +326,16 @@ function configure_firewall_for_tox {
331 326
         return
332 327
     fi
333 328
 
334
-    TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
329
+    TOX_PORT_MAIN=$(grep "TOX_PORT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}')
335 330
     if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
336 331
         TOX_PORT=$TOX_PORT_MAIN
337 332
     fi
338
-    if [ ! $TOX_PORT ]; then
333
+    if [ ! "$TOX_PORT" ]; then
339 334
         echo $'No Tox port was specified'
340 335
         exit 32856
341 336
     fi
342 337
 
343
-    firewall_add Tox ${TOX_PORT}
338
+    firewall_add Tox "${TOX_PORT}"
344 339
     mark_completed "${FUNCNAME[0]}"
345 340
 }
346 341
 
@@ -355,24 +350,23 @@ function tox_avahi {
355 350
     fi
356 351
 
357 352
     # install a command to obtain the Tox ID
358
-    cd $INSTALL_DIR
353
+    cd "$INSTALL_DIR" || exit 131497953
359 354
 
360 355
     if [ -d /repos/toxid ]; then
361
-        mkdir $INSTALL_DIR/toxid
362
-        cp -r -p /repos/toxid/. $INSTALL_DIR/toxid
363
-        cd $INSTALL_DIR/toxid
356
+        mkdir "$INSTALL_DIR/toxid"
357
+        cp -r -p /repos/toxid/. "$INSTALL_DIR/toxid"
358
+        cd "$INSTALL_DIR/toxid" || exit 468276424526
364 359
         git pull
365 360
     else
366 361
         function_check git_clone
367
-        git_clone $TOXID_REPO $INSTALL_DIR/toxid
362
+        git_clone "$TOXID_REPO" "$INSTALL_DIR/toxid"
368 363
     fi
369 364
 
370
-    if [ ! -d $INSTALL_DIR/toxid ]; then
365
+    if [ ! -d "$INSTALL_DIR/toxid" ]; then
371 366
         exit 63921
372 367
     fi
373
-    cd $INSTALL_DIR/toxid
374
-    make
375
-    if [ ! "$?" = "0" ]; then
368
+    cd "$INSTALL_DIR/toxid" || exit 4782462846
369
+    if ! make; then
376 370
         exit 58432
377 371
     fi
378 372
     make install
@@ -399,13 +393,13 @@ function install_tox_node {
399 393
     mesh_tox_node
400 394
 
401 395
     # onion address for bootstrapping
402
-    TOX_ONION_HOSTNAME=$(add_onion_service tox ${TOX_PORT} ${TOX_PORT})
396
+    add_onion_service tox "${TOX_PORT}" "${TOX_PORT}"
403 397
 
404 398
     systemctl restart tox-bootstrapd.service
405 399
 
406 400
     sleep 3
407 401
 
408
-    TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | tail -n 1 | awk -F ' ' '{print $8}')
402
+    TOX_PUBLIC_KEY=$(grep tox /var/log/syslog | grep "Public Key" | tail -n 1 | awk -F ' ' '{print $8}')
409 403
     if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
410 404
         echo $'Could not obtain the tox node public key'
411 405
         exit 6529
@@ -435,58 +429,58 @@ function install_tox_client {
435 429
 
436 430
 function mesh_tox_node {
437 431
     # obtain commits from the main file
438
-    TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
432
+    TOXCORE_COMMIT_MAIN=$(grep "TOXCORE_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F "'" '{print $2}')
439 433
     if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
440 434
         TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
441 435
     fi
442
-    if [ ! $TOXCORE_COMMIT ]; then
436
+    if [ ! "$TOXCORE_COMMIT" ]; then
443 437
         echo $'No Tox commit was specified'
444 438
         exit 76325
445 439
     fi
446 440
 
447
-    TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
441
+    TOXID_REPO_MAIN=$(grep "TOXID_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '"' '{print $2}')
448 442
     if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
449 443
         TOXID_REPO=$TOXID_REPO_MAIN
450 444
     fi
451
-    if [ ! $TOXID_REPO ]; then
445
+    if [ ! "$TOXID_REPO" ]; then
452 446
         echo $'No ToxID repo was specified'
453 447
         exit 78252
454 448
     fi
455 449
 
456
-    TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}')
450
+    TOX_PORT_MAIN=$(grep "TOX_PORT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}')
457 451
     if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
458 452
         TOX_PORT=$TOX_PORT_MAIN
459 453
     fi
460
-    if [ ! $TOX_PORT ]; then
454
+    if [ ! "$TOX_PORT" ]; then
461 455
         echo $'No Tox port was specified'
462 456
         exit 32856
463 457
     fi
464 458
 
465
-    TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
459
+    TOXCORE_REPO_MAIN=$(grep "TOXCORE_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '"' '{print $2}')
466 460
     if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
467 461
         TOXCORE_REPO=$TOXCORE_REPO_MAIN
468 462
     fi
469
-    if [ ! $TOXCORE_REPO ]; then
463
+    if [ ! "$TOXCORE_REPO" ]; then
470 464
         echo $'No Tox repo was specified'
471 465
         exit 16865
472 466
     fi
473 467
 
474
-    if [ ! $TOXCORE_COMMIT ]; then
468
+    if [ ! "$TOXCORE_COMMIT" ]; then
475 469
         echo $'No Tox commit was specified'
476 470
         exit 76325
477 471
     fi
478 472
 
479
-    if [ ! $TOXCORE_REPO ]; then
473
+    if [ ! "$TOXCORE_REPO" ]; then
480 474
         echo $'No Tox repo was specified'
481 475
         exit 16865
482 476
     fi
483 477
 
484
-    if [ $rootdir ]; then
485
-        chroot ${rootdir} apt-get -yq install build-essential libtool autotools-dev
486
-        chroot ${rootdir} apt-get -yq install automake checkinstall check git yasm
487
-        chroot ${rootdir} apt-get -yq install libsodium18 libsodium-dev libcap2-bin
488
-        chroot ${rootdir} apt-get -yq install libconfig9 libconfig-dev autoconf
489
-        chroot ${rootdir} apt-get -yq install libopus-dev libvpx-dev
478
+    if [ "$rootdir" ]; then
479
+        chroot "${rootdir}" apt-get -yq install build-essential libtool autotools-dev
480
+        chroot "${rootdir}" apt-get -yq install automake checkinstall check git yasm
481
+        chroot "${rootdir}" apt-get -yq install libsodium18 libsodium-dev libcap2-bin
482
+        chroot "${rootdir}" apt-get -yq install libconfig9 libconfig-dev autoconf
483
+        chroot "${rootdir}" apt-get -yq install libopus-dev libvpx-dev
490 484
     else
491 485
         apt-get -yq install build-essential libtool autotools-dev
492 486
         apt-get -yq install automake checkinstall check git yasm
@@ -495,27 +489,26 @@ function mesh_tox_node {
495 489
         apt-get -yq install libopus-dev libvpx-dev
496 490
     fi
497 491
 
498
-    if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
499
-        mkdir -p ${rootdir}${INSTALL_DIR}
492
+    if [ ! -d "${rootdir}${INSTALL_DIR}" ]; then
493
+        mkdir -p "${rootdir}${INSTALL_DIR}"
500 494
     fi
501
-    if [ ! -d ${rootdir}${INSTALL_DIR}/toxcore ]; then
495
+    if [ ! -d "${rootdir}${INSTALL_DIR}/toxcore" ]; then
502 496
         if [ -d /repos/toxcore ]; then
503
-            mkdir ${rootdir}${INSTALL_DIR}/toxcore
504
-            cp -r -p /repos/toxcore/. ${rootdir}${INSTALL_DIR}/toxcore
505
-            cd ${rootdir}${INSTALL_DIR}/toxcore
497
+            mkdir "${rootdir}${INSTALL_DIR}/toxcore"
498
+            cp -r -p /repos/toxcore/. "${rootdir}${INSTALL_DIR}/toxcore"
499
+            cd "${rootdir}${INSTALL_DIR}/toxcore" || exit 2468246284
506 500
             git pull
507 501
         else
508
-            git clone ${TOXCORE_REPO} ${rootdir}${INSTALL_DIR}/toxcore
509
-            if [ ! "$?" = "0" ]; then
510
-                exit 429252
502
+            if ! git clone "${TOXCORE_REPO}" "${rootdir}${INSTALL_DIR}/toxcore"; then
503
+                exit 4292521
511 504
             fi
512 505
         fi
513 506
     fi
514
-    cd ${rootdir}$INSTALL_DIR/toxcore
515
-    git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT
507
+    cd "${rootdir}$INSTALL_DIR/toxcore" || exit 46824624
508
+    git checkout "$TOXCORE_COMMIT" -b "$TOXCORE_COMMIT"
516 509
 
517
-    if [ ${rootdir} ]; then
518
-        chroot ${rootdir} /bin/bash -x <<EOF
510
+    if [ "${rootdir}" ]; then
511
+        chroot "${rootdir}" /bin/bash -x <<EOF
519 512
 cd ${INSTALL_DIR}/toxcore
520 513
 autoreconf -i
521 514
 ./configure --enable-daemon
@@ -532,28 +525,28 @@ make install
532 525
 EOF
533 526
     fi
534 527
 
535
-    cp $rootdir/usr/local/lib/libtoxcore* $rootdir/usr/lib/
536
-    cp ${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/
537
-    sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
538
-    if [ ${rootdir} ]; then
539
-        chroot ${rootdir} systemctl enable tox-bootstrapd.service
528
+    cp "$rootdir/usr/local/lib/libtoxcore*" "$rootdir/usr/lib/"
529
+    cp "${rootdir}${INSTALL_DIR}/toxcore/other/bootstrap_daemon/tox-bootstrapd.service" "$rootdir/etc/systemd/system/"
530
+    sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' "$rootdir/etc/systemd/system/tox-bootstrapd.service"
531
+    if [ "${rootdir}" ]; then
532
+        chroot "${rootdir}" systemctl enable tox-bootstrapd.service
540 533
     else
541 534
         systemctl enable tox-bootstrapd.service
542 535
     fi
543 536
 
544 537
     SECONDS=0
545
-    if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
538
+    if [ ! -f "$rootdir/usr/local/bin/tox-bootstrapd" ]; then
546 539
         duration=$SECONDS
547
-        echo $"Toxcore compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
540
+        echo $"Toxcore compile failed at $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
548 541
         echo $'Unable to make toxcore'
549 542
         exit 73835
550 543
     fi
551 544
     duration=$SECONDS
552
-    echo $"Toxcore compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
545
+    echo $"Toxcore compile $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
553 546
 
554
-    if [ ${rootdir} ]; then
555
-        chroot ${rootdir} /usr/sbin/useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
556
-        chroot ${rootdir} /bin/chmod 700 /var/lib/tox-bootstrapd
547
+    if [ "${rootdir}" ]; then
548
+        chroot "${rootdir}" /usr/sbin/useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment $"Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
549
+        chroot "${rootdir}" /bin/chmod 700 /var/lib/tox-bootstrapd
557 550
     else
558 551
         chmod 600 /etc/shadow
559 552
         chmod 600 /etc/gshadow
@@ -564,87 +557,89 @@ EOF
564 557
     fi
565 558
 
566 559
     # remove Maildir
567
-    if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then
568
-        rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir
560
+    if [ -d "$rootdir/var/lib/tox-bootstrapd/Maildir" ]; then
561
+        rm -rf "$rootdir/var/lib/tox-bootstrapd/Maildir"
569 562
     fi
570 563
 
571 564
     # create configuration file
572 565
     TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
573
-    echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG
574
-    echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG
575
-    echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG
576
-    echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG
577
-    echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG
578
-    echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG
579
-    echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG
580
-    echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG
581
-    echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG
582
-    echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG
566
+    { echo "port = $TOX_PORT";
567
+      echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"';
568
+      echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"';
569
+      echo 'enable_ipv6 = true';
570
+      echo 'enable_ipv4_fallback = true';
571
+      echo 'enable_lan_discovery = true';
572
+      echo 'enable_tcp_relay = true';
573
+      echo "tcp_relay_ports = [443, 3389, $TOX_PORT]";
574
+      echo 'enable_motd = true';
575
+      echo 'motd = "tox-bootstrapd"'; } > "$TOX_BOOTSTRAP_CONFIG"
583 576
 
584 577
     if [ $TOX_NODES ]; then
585
-        echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
578
+        echo 'bootstrap_nodes = (' >> "$TOX_BOOTSTRAP_CONFIG"
586 579
         toxcount=0
587 580
         while [ "x${TOX_NODES[toxcount]}" != "x" ]
588 581
         do
589
-            toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
590
-            toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
591
-            toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
592
-            toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
593
-            toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
594
-            echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG
582
+            # shellcheck disable=SC2102
583
+            nodes_str=$(echo $TOX_NODES[toxcount])
584
+            toxval_ipv4=$(awk "$nodes_str" -F ',' '{print $1}')
585
+            toxval_ipv6=$(awk "$nodes_str" -F ',' '{print $2}')
586
+            toxval_port=$(awk "$nodes_str" -F ',' '{print $3}')
587
+            toxval_pubkey=$(awk "$nodes_str" -F ',' '{print $4}')
588
+            toxval_maintainer=$(awk "$nodes_str" -F ',' '{print $5}')
589
+            echo "{ // $toxval_maintainer" >> "$TOX_BOOTSTRAP_CONFIG"
595 590
             if [[ $toxval_ipv6 != 'NONE' ]]; then
596
-                echo "  address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
591
+                echo "  address = \"$toxval_ipv6\"" >> "$TOX_BOOTSTRAP_CONFIG"
597 592
             else
598
-                echo "  address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
593
+                echo "  address = \"$toxval_ipv4\"" >> "$TOX_BOOTSTRAP_CONFIG"
599 594
             fi
600
-            echo "  port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG
601
-            echo "  public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG
602
-            toxcount=$(( $toxcount + 1 ))
595
+            echo "  port = $toxval_port" >> "$TOX_BOOTSTRAP_CONFIG"
596
+            echo "  public_key = \"$toxval_pubkey\"" >> "$TOX_BOOTSTRAP_CONFIG"
597
+            toxcount=$((toxcount + 1))
603 598
             if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
604
-                echo "}," >> $TOX_BOOTSTRAP_CONFIG
599
+                echo "}," >> "$TOX_BOOTSTRAP_CONFIG"
605 600
             else
606
-                echo "}" >> $TOX_BOOTSTRAP_CONFIG
601
+                echo "}" >> "$TOX_BOOTSTRAP_CONFIG"
607 602
             fi
608 603
         done
609
-        echo ')' >> $TOX_BOOTSTRAP_CONFIG
604
+        echo ')' >> "$TOX_BOOTSTRAP_CONFIG"
610 605
     fi
611 606
 
612
-    if [ -f $rootdir/var/lib/tox-bootstrapd/keys ]; then
613
-        chmod 700 $rootdir/var/lib/tox-bootstrapd/keys
607
+    if [ -f "$rootdir/var/lib/tox-bootstrapd/keys" ]; then
608
+        chmod 700 "$rootdir/var/lib/tox-bootstrapd/keys"
614 609
     fi
615 610
 }
616 611
 
617 612
 function mesh_tox_avahi {
618
-    if [ ! -d $rootdir/etc/avahi ]; then
613
+    if [ ! -d "$rootdir/etc/avahi" ]; then
619 614
         echo $'tox_avahi: avahi is not installed'
620 615
         exit 87359
621 616
     fi
622 617
 
623
-    if [ ! $TOXID_REPO ]; then
618
+    if [ ! "$TOXID_REPO" ]; then
624 619
         echo $'No ToxID repo was specified'
625 620
         exit 78252
626 621
     fi
627 622
 
628
-    if [ ! -d ${rootdir}${INSTALL_DIR} ]; then
629
-        mkdir -p ${rootdir}${INSTALL_DIR}
623
+    if [ ! -d "${rootdir}${INSTALL_DIR}" ]; then
624
+        mkdir -p "${rootdir}${INSTALL_DIR}"
630 625
     fi
631 626
 
632 627
     if [ -d /repos/toxid ]; then
633
-        mkdir ${rootdir}${INSTALL_DIR}/toxid
634
-        cp -r -p /repos/toxid/. ${rootdir}${INSTALL_DIR}/toxid
635
-        cd ${rootdir}${INSTALL_DIR}/toxid
628
+        mkdir "${rootdir}${INSTALL_DIR}/toxid"
629
+        cp -r -p /repos/toxid/. "${rootdir}${INSTALL_DIR}/toxid"
630
+        cd "${rootdir}${INSTALL_DIR}/toxid" || exit 2468246
636 631
         git pull
637 632
     else
638
-        git clone ${TOXID_REPO} ${rootdir}${INSTALL_DIR}/toxid
633
+        git clone "${TOXID_REPO}" "${rootdir}${INSTALL_DIR}/toxid"
639 634
     fi
640 635
 
641
-    if [ ! -d ${rootdir}${INSTALL_DIR}/toxid ]; then
636
+    if [ ! -d "${rootdir}${INSTALL_DIR}/toxid" ]; then
642 637
         echo $'Unable to clone toxid repo'
643 638
         exit 768352
644 639
     fi
645 640
 
646
-    if [ ${rootdir} ]; then
647
-        chroot ${rootdir} /bin/bash -x <<EOF
641
+    if [ "${rootdir}" ]; then
642
+        chroot "${rootdir}" /bin/bash -x <<EOF
648 643
 cd ${INSTALL_DIR}/toxid
649 644
 make
650 645
 make install
@@ -657,45 +652,46 @@ make install
657 652
 EOF
658 653
     fi
659 654
 
660
-    if [ ! -f $rootdir/usr/local/bin/toxid ]; then
655
+    if [ ! -f "$rootdir/usr/local/bin/toxid" ]; then
661 656
         echo $'toxid not found'
662 657
         exit 74370
663 658
     fi
664
-    if [ ! -f $rootdir/usr/local/bin/toxavahi ]; then
659
+    if [ ! -f "$rootdir/usr/local/bin/toxavahi" ]; then
665 660
         exit 3621729
666 661
     fi
667 662
 
668 663
     MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
669
-    echo '#!/bin/bash' > $MESH_SYNC_COMMAND
670
-    echo '/usr/local/bin/toxavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
671
-    echo '/usr/local/bin/meshavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
672
-    chmod +x $MESH_SYNC_COMMAND
664
+    { echo '#!/bin/bash';
665
+      echo '/usr/local/bin/toxavahi 2> /dev/null';
666
+      echo '/usr/local/bin/meshavahi 2> /dev/null'; } > "$MESH_SYNC_COMMAND"
667
+    chmod +x "$MESH_SYNC_COMMAND"
673 668
 
674
-    if ! grep -q "mesh-sync" ${rootdir}/etc/crontab; then
675
-        echo "*/1            * *   *   *   root /usr/bin/mesh-sync 2> /dev/null" >> ${rootdir}/etc/crontab
676
-        echo "*/1            * *   *   *   root ( sleep 20 ; /usr/bin/mesh-sync 2> /dev/null )" >> ${rootdir}/etc/cro        echo "*/1            * *   *   *   root ( sleep 40 ; /usr/bin/mesh-sync 2> /dev/null )" >> ${rootdir}/etc/crontab
669
+    if ! grep -q "mesh-sync" "${rootdir}/etc/crontab"; then
670
+        { echo "*/1            * *   *   *   root /usr/bin/mesh-sync 2> /dev/null";
671
+          echo "*/1            * *   *   *   root ( sleep 20 ; /usr/bin/mesh-sync 2> /dev/null )";
672
+          echo "*/1            * *   *   *   root ( sleep 40 ; /usr/bin/mesh-sync 2> /dev/null )"; } >> "${rootdir}/etc/crontab"
677 673
     fi
678 674
 }
679 675
 
680 676
 function mesh_tox_client {
681 677
 
682
-    TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
678
+    TOXIC_FILE=$(grep "TOXIC_FILE=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}')
683 679
 
684 680
     # obtain commits from the main file
685
-    TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
681
+    TOXIC_COMMIT_MAIN=$(grep "TOXIC_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F "'" '{print $2}')
686 682
     if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
687 683
         TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
688 684
     fi
689 685
 
690
-    TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}')
686
+    TOXIC_REPO_MAIN=$(grep "TOXIC_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '"' '{print $2}')
691 687
     if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
692 688
         TOXIC_REPO=$TOXIC_REPO_MAIN
693 689
     fi
694 690
 
695
-    if [ ${rootdir} ]; then
696
-        chroot ${rootdir} apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
697
-        chroot ${rootdir} apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
698
-        chroot ${rootdir} apt-get -yq install libqrencode-dev
691
+    if [ "${rootdir}" ]; then
692
+        chroot "${rootdir}" apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
693
+        chroot "${rootdir}" apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
694
+        chroot "${rootdir}" apt-get -yq install libqrencode-dev
699 695
     else
700 696
         apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
701 697
         apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
@@ -704,57 +700,57 @@ function mesh_tox_client {
704 700
 
705 701
     TEMP_SCRIPT_NAME=fbtmp728353.sh
706 702
     TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
707
-    echo '#!/bin/bash' > $TEMP_SCRIPT
708
-    echo "mkdir -p $INSTALL_DIR" >> $TEMP_SCRIPT
709
-    echo 'if [ -d /repos/toxic ]; then' >> $TEMP_SCRIPT
710
-    echo "    mkdir $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
711
-    echo "    cp -r -p /repos/toxic/. $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
712
-    echo "    cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
713
-    echo '    git pull' >> $TEMP_SCRIPT
714
-    echo 'else' >> $TEMP_SCRIPT
715
-    echo "    git clone $TOXIC_REPO $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
716
-    echo 'fi' >> $TEMP_SCRIPT
717
-    echo "cd $INSTALL_DIR/toxic" >> $TEMP_SCRIPT
718
-    echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT" >> $TEMP_SCRIPT
719
-    echo 'make' >> $TEMP_SCRIPT
720
-    echo 'if [ ! "$?" = "0" ]; then' >> $TEMP_SCRIPT
721
-    echo '    exit 1' >> $TEMP_SCRIPT
722
-    echo 'fi' >> $TEMP_SCRIPT
723
-    echo 'make install' >> $TEMP_SCRIPT
724
-    echo 'exit 0' >> $TEMP_SCRIPT
703
+    { echo '#!/bin/bash';
704
+      echo "mkdir -p $INSTALL_DIR";
705
+      echo 'if [ -d /repos/toxic ]; then';
706
+      echo "    mkdir $INSTALL_DIR/toxic";
707
+      echo "    cp -r -p /repos/toxic/. $INSTALL_DIR/toxic";
708
+      echo "    cd $INSTALL_DIR/toxic";
709
+      echo '    git pull';
710
+      echo 'else';
711
+      echo "    git clone $TOXIC_REPO $INSTALL_DIR/toxic";
712
+      echo 'fi';
713
+      echo "cd $INSTALL_DIR/toxic";
714
+      echo "git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT";
715
+      echo 'make';
716
+      echo 'if [ ! "$?" = "0" ]; then';
717
+      echo '    exit 1';
718
+      echo 'fi';
719
+      echo 'make install';
720
+      echo 'exit 0'; } > "$TEMP_SCRIPT"
725 721
     chmod +x $TEMP_SCRIPT
726
-    cp $TEMP_SCRIPT $rootdir/root/
722
+    cp "$TEMP_SCRIPT" "$rootdir/root/"
727 723
 
728
-    TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
724
+    TOXIC_FILE=$(grep "TOXIC_FILE=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox" | head -n 1 | awk -F '=' '{print $2}')
729 725
 
730 726
     SECONDS=0
731
-    if [ ${rootdir} ]; then
732
-        chroot ${rootdir} /root/$TEMP_SCRIPT_NAME
727
+    if [ "${rootdir}" ]; then
728
+        chroot "${rootdir}" "/root/$TEMP_SCRIPT_NAME"
733 729
     else
734 730
         /root/$TEMP_SCRIPT_NAME
735 731
     fi
732
+    # shellcheck disable=SC2181
736 733
     if [ ! "$?" = "0" ]; then
737 734
         cat -n /root/fbtmp728353.sh
738 735
         duration=$SECONDS
739
-        echo $"Toxic client compile failed at $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
736
+        echo $"Toxic client compile failed at $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
740 737
         echo $'Unable to make tox client'
741 738
         rm $TEMP_SCRIPT
742 739
         exit 74872
743 740
     fi
744 741
     rm $TEMP_SCRIPT
745
-    if [ ! -f $rootdir$TOXIC_FILE ]; then
742
+    if [ ! -f "$rootdir$TOXIC_FILE" ]; then
746 743
         echo $"Tox client was not installed to $TOXIC_FILE"
747 744
         exit 63278
748 745
     fi
749 746
     duration=$SECONDS
750
-    echo $"Toxic client compile $(($duration / 60)) minutes and $(($duration % 60)) seconds elapsed."
747
+    echo $"Toxic client compile $((duration / 60)) minutes and $((duration % 60)) seconds elapsed."
751 748
 }
752 749
 
753 750
 function enable_tox_repo {
754
-    echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_9.0/ /' > $rootdir/etc/apt/sources.list.d/tox.list
755
-
751
+    echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_9.0/ /' > "$rootdir/etc/apt/sources.list.d/tox.list"
756 752
 
757
-    cat >> $rootdir/root/gettoxkey.sh <<EOF
753
+    cat >> "$rootdir/root/gettoxkey.sh" <<EOF
758 754
 #!/bin/bash
759 755
 wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_9.0/Release.key -O- > /root/tox.key
760 756
 apt-key add /root/tox.key
@@ -769,30 +765,30 @@ EOF
769 765
 function install_tox {
770 766
     configure_firewall_for_tox
771 767
 
772
-    if [ $INSTALLING_MESH ]; then
768
+    if [ "$INSTALLING_MESH" ]; then
773 769
         mesh_tox_node
774 770
         mesh_tox_avahi
775 771
         mesh_tox_client
776 772
     else
777 773
         avoid_tor_restart=
778
-        if [ -f $IMAGE_PASSWORD_FILE ]; then
774
+        if [ -f "$IMAGE_PASSWORD_FILE" ]; then
779 775
             if [[ $ONION_ONLY != 'no' ]]; then
780 776
                 avoid_tor_restart=1
781 777
             fi
782 778
         fi
783 779
 
784 780
         if [ $avoid_tor_restart ]; then
785
-            ${PROJECT_NAME}-logging on --onion
781
+            "${PROJECT_NAME}-logging" on --onion
786 782
         else
787
-            ${PROJECT_NAME}-logging on
783
+            "${PROJECT_NAME}-logging" on
788 784
         fi
789 785
 
790 786
         install_tox_node
791 787
 
792 788
         if [ $avoid_tor_restart ]; then
793
-            ${PROJECT_NAME}-logging off --onion
789
+            "${PROJECT_NAME}-logging" off --onion
794 790
         else
795
-            ${PROJECT_NAME}-logging off
791
+            "${PROJECT_NAME}-logging" off
796 792
         fi
797 793
 
798 794
         tox_avahi

+ 81
- 73
src/freedombone-app-turtl Datei anzeigen

@@ -68,22 +68,24 @@ function logging_off_turtl {
68 68
 }
69 69
 
70 70
 function change_password_turtl {
71
-    change_username="$1"
72
-    new_user_password="$2"
71
+    echo -n ''
72
+#    change_username="$1"
73
+#    new_user_password="$2"
73 74
 }
74 75
 
75 76
 function remove_user_turtl {
76
-    remove_username="$1"
77
+    echo -n ''
78
+#    remove_username="$1"
77 79
 }
78 80
 
79 81
 function add_user_turtl {
80
-    new_username="$1"
81
-    new_user_password="$2"
82
+#    new_username="$1"
83
+#    new_user_password="$2"
82 84
     echo '0'
83 85
 }
84 86
 
85 87
 function install_interactive_turtl {
86
-    if [ ! $ONION_ONLY ]; then
88
+    if [ ! "$ONION_ONLY" ]; then
87 89
         ONION_ONLY='no'
88 90
     fi
89 91
 
@@ -128,7 +130,7 @@ function configure_interactive_turtl_signups {
128 130
     dialog --title $"Allow new turtl signups" \
129 131
            --backtitle $"Freedombone Control Panel" \
130 132
            --defaultno \
131
-           --yesno $"\nAllow registration of new users?" 10 60
133
+           --yesno $"\\nAllow registration of new users?" 10 60
132 134
     sel=$?
133 135
     case $sel in
134 136
         0)
@@ -146,15 +148,14 @@ function configure_interactive_turtl_signups {
146 148
 }
147 149
 
148 150
 function configure_interactive_turtl_storage {
149
-    data=$(tempfile 2>/dev/null)
150
-    trap "rm -f $data" 0 1 2 5 15
151
+    data=$(mktemp 2>/dev/null)
151 152
     dialog --title $"Change storage limit" \
152 153
            --backtitle $"Freedombone Control Panel" \
153
-           --inputbox $"Enter a storage limit in megabytes." 8 75 "$TURTL_STORAGE_LIMIT_MB" 2>$data
154
+           --inputbox $"Enter a storage limit in megabytes." 8 75 "$TURTL_STORAGE_LIMIT_MB" 2>"$data"
154 155
     sel=$?
155 156
     case $sel in
156 157
         0)
157
-            STORAGE=$(<$data)
158
+            STORAGE=$(<"$data")
158 159
             if [ ${#STORAGE} -gt 0 ]; then
159 160
                 TURTL_STORAGE_LIMIT_MB=$STORAGE
160 161
                 sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* ${TURTL_STORAGE_LIMIT_MB})|g" $TURTL_BASE_DIR/api/config/config.lisp
@@ -164,27 +165,31 @@ function configure_interactive_turtl_storage {
164 165
             fi
165 166
             ;;
166 167
     esac
168
+    rm -f "$data"
167 169
 }
168 170
 
169 171
 function configure_interactive_turtl {
170
-    data=$(tempfile 2>/dev/null)
171
-    trap "rm -f $data" 0 1 2 5 15
172
+    data=$(mktemp 2>/dev/null)
172 173
     dialog --backtitle $"Freedombone Control Panel" \
173 174
            --title $"turtl app settings" \
174 175
            --radiolist $"Choose an operation:" 12 70 3 \
175 176
            1 $"Enable/disable new user registrations" off \
176 177
            2 $"Change storage limit" off \
177
-           3 $"Exit" on 2> $data
178
+           3 $"Exit" on 2> "$data"
178 179
     sel=$?
179 180
     case $sel in
180
-        1) exit 1;;
181
-        255) exit 1;;
181
+        1) rm -f "$data"
182
+           exit 1;;
183
+        255) rm -f "$data"
184
+             exit 1;;
182 185
     esac
183
-    case $(cat $data) in
186
+    case $(cat "$data") in
184 187
         1) configure_interactive_turtl_signups;;
185 188
         2) configure_interactive_turtl_storage;;
186
-        3) return;;
189
+        3) rm -f "$data"
190
+           return;;
187 191
     esac
192
+    rm -f "$data"
188 193
 }
189 194
 
190 195
 function reconfigure_turtl {
@@ -255,7 +260,7 @@ function restore_local_turtl {
255 260
         else
256 261
             cp -r ${temp_restore_dir}/* /etc/turtl/
257 262
         fi
258
-
263
+        # shellcheck disable=SC2181
259 264
         if [ ! "$?" = "0" ]; then
260 265
             set_user_permissions
261 266
             backup_unmount_drive
@@ -273,6 +278,7 @@ function restore_local_turtl {
273 278
             cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
274 279
         fi
275 280
 
281
+        # shellcheck disable=SC2181
276 282
         if [ ! "$?" = "0" ]; then
277 283
             set_user_permissions
278 284
             backup_unmount_drive
@@ -318,6 +324,7 @@ function restore_remote_turtl {
318 324
             cp -r ${temp_restore_dir}/* /etc/turtl/
319 325
         fi
320 326
 
327
+        # shellcheck disable=SC2181
321 328
         if [ ! "$?" = "0" ]; then
322 329
             if [ -d /etc/turtl_previous ]; then
323 330
                 mv /etc/turtl_previous $TURTL_BASE_DIR
@@ -338,6 +345,7 @@ function restore_remote_turtl {
338 345
             cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
339 346
         fi
340 347
 
348
+        # shellcheck disable=SC2181
341 349
         if [ ! "$?" = "0" ]; then
342 350
             set_user_permissions
343 351
             exit 26783
@@ -358,7 +366,7 @@ function remove_turtl {
358 366
     remove_rethinkdb
359 367
     remove_app turtl
360 368
     remove_completion_param install_turtl
361
-    sed -i '/turtl/d' $COMPLETION_FILE
369
+    sed -i '/turtl/d' "$COMPLETION_FILE"
362 370
     nginx_dissite $TURTL_DOMAIN_NAME
363 371
     if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
364 372
         rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
@@ -444,18 +452,18 @@ __ENDCONFIG__
444 452
         exit 6238234
445 453
     fi
446 454
 
447
-    echo '[Unit]' > /etc/systemd/system/turtl.service
448
-    echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
449
-    echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
450
-    echo 'Requires=network.target' >> /etc/systemd/system/turtl.service
451
-    echo 'Requires=rethinkdb.service' >> /etc/systemd/system/turtl.service
452
-    echo 'After=network.target' >> /etc/systemd/system/turtl.service
453
-    echo 'After=rethinkdb.service' >> /etc/systemd/system/turtl.service
454
-    echo '' >> /etc/systemd/system/turtl.service
455
-    echo '[Service]' >> /etc/systemd/system/turtl.service
456
-    echo 'Type=simple' >> /etc/systemd/system/turtl.service
457
-    echo 'User=turtl' >> /etc/systemd/system/turtl.service
458
-    echo "WorkingDirectory=$TURTL_BASE_DIR/api/" >> /etc/systemd/system/turtl.service
455
+    { echo '[Unit]';
456
+      echo 'Description=Note taking service';
457
+      echo 'Documentation=http://turtl.it';
458
+      echo 'Requires=network.target';
459
+      echo 'Requires=rethinkdb.service';
460
+      echo 'After=network.target';
461
+      echo 'After=rethinkdb.service';
462
+      echo '';
463
+      echo '[Service]';
464
+      echo 'Type=simple';
465
+      echo 'User=turtl';
466
+      echo "WorkingDirectory=$TURTL_BASE_DIR/api/"; } > /etc/systemd/system/turtl.service
459 467
 
460 468
     if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
461 469
         echo "ExecStart=$TURTL_BASE_DIR/ccl/lx86cl64 -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
@@ -466,9 +474,9 @@ __ENDCONFIG__
466 474
             echo "ExecStart=$TURTL_BASE_DIR/ccl/armcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
467 475
         fi
468 476
     fi
469
-    echo '' >> /etc/systemd/system/turtl.service
470
-    echo '[Install]' >> /etc/systemd/system/turtl.service
471
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/turtl.service
477
+    { echo '';
478
+      echo '[Install]';
479
+      echo 'WantedBy=multi-user.target'; } >> /etc/systemd/system/turtl.service
472 480
     chmod +x /etc/systemd/system/turtl.service
473 481
 
474 482
     chown -R turtl:turtl $TURTL_BASE_DIR
@@ -484,7 +492,7 @@ function install_turtl_api {
484 492
     if [ ! -d $TURTL_BASE_DIR ]; then
485 493
         mkdir -p $TURTL_BASE_DIR
486 494
     fi
487
-    cd $TURTL_BASE_DIR
495
+    cd "$TURTL_BASE_DIR" || exit 745726542
488 496
     mkdir cd $TURTL_BASE_DIR/data
489 497
     check_architecture=$(uname -a)
490 498
 
@@ -600,21 +608,21 @@ __ENDCONFIG__
600 608
     chown -R rethinkdb:rethinkdb /var/lib/rethinkdb
601 609
 
602 610
     # install turtl API
603
-    cd $TURTL_BASE_DIR/
611
+    cd "$TURTL_BASE_DIR/" || exit 6428462
604 612
 
605 613
     if [ -d /repos/turtl ]; then
606 614
         mkdir $TURTL_BASE_DIR/api
607 615
         cp -r -p /repos/turtl/. $TURTL_BASE_DIR/api
608
-        cd $TURTL_BASE_DIR/api
616
+        cd "$TURTL_BASE_DIR/api" || exit 57141845
609 617
         git pull
610 618
     else
611 619
         git clone $TURTL_REPO $TURTL_BASE_DIR/api
612 620
     fi
613 621
 
614
-    cd $TURTL_BASE_DIR/api
622
+    cd "$TURTL_BASE_DIR/api" || exit 35814614
615 623
     git checkout $TURTL_COMMIT -b $TURTL_COMMIT
616 624
     set_completion_param "turtl commit" "$TURTL_COMMIT"
617
-    cd $TURTL_BASE_DIR/quicklisp/local-projects
625
+    cd "$TURTL_BASE_DIR/quicklisp/local-projects" || exit 43618941415
618 626
     git clone git://github.com/orthecreedence/cl-hash-util
619 627
     if [[ "$check_architecture" != *"arm"* ]]; then
620 628
         if [[ "$check_architecture" == *"64"* ]]; then
@@ -657,54 +665,54 @@ function install_turtl_nginx {
657 665
     if [[ $ONION_ONLY == "no" ]]; then
658 666
         function_check nginx_http_redirect
659 667
         nginx_http_redirect $TURTL_DOMAIN_NAME
660
-        echo 'server {' >> $turtl_nginx_site
661
-        echo '  listen 443 ssl;' >> $turtl_nginx_site
662
-        echo '  #listen [::]:443 ssl;' >> $turtl_nginx_site
663
-        echo "  server_name ${TURTL_DOMAIN_NAME};" >> $turtl_nginx_site
664
-        echo '' >> $turtl_nginx_site
665
-        echo '  # Security' >> $turtl_nginx_site
668
+        { echo 'server {';
669
+          echo '  listen 443 ssl;';
670
+          echo '  #listen [::]:443 ssl;';
671
+          echo "  server_name ${TURTL_DOMAIN_NAME};";
672
+          echo '';
673
+          echo '  # Security'; } >> "$turtl_nginx_site"
666 674
         function_check nginx_ssl
667 675
         nginx_ssl $TURTL_DOMAIN_NAME
668 676
 
669 677
         function_check nginx_disable_sniffing
670 678
         nginx_disable_sniffing $TURTL_DOMAIN_NAME
671 679
 
672
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $turtl_nginx_site
673
-        echo '' >> $turtl_nginx_site
674
-        echo '  # Logs' >> $turtl_nginx_site
675
-        echo '  access_log /dev/null;' >> $turtl_nginx_site
676
-        echo '  error_log /dev/null;' >> $turtl_nginx_site
677
-        echo '' >> $turtl_nginx_site
678
-        echo '  location / {' >> $turtl_nginx_site
680
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
681
+          echo '';
682
+          echo '  # Logs';
683
+          echo '  access_log /dev/null;';
684
+          echo '  error_log /dev/null;';
685
+          echo '';
686
+          echo '  location / {'; } >> "$turtl_nginx_site"
679 687
         function_check nginx_limits
680 688
         nginx_limits $TURTL_DOMAIN_NAME '15m'
681
-        echo "    proxy_pass        http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
682
-        echo '    proxy_set_header  Host $host;' >> $turtl_nginx_site
683
-        echo '    proxy_buffering   off;' >> $turtl_nginx_site
684
-        echo '  }' >> $turtl_nginx_site
685
-        echo '}' >> $turtl_nginx_site
689
+        { echo "    proxy_pass        http://localhost:${TURTL_PORT}/;";
690
+          echo "    proxy_set_header  Host \$host;";
691
+          echo '    proxy_buffering   off;';
692
+          echo '  }';
693
+          echo '}'; } >> "$turtl_nginx_site"
686 694
     else
687 695
         echo -n '' > $turtl_nginx_site
688 696
     fi
689
-    echo 'server {' >> $turtl_nginx_site
690
-    echo "  listen 127.0.0.1:${TURTL_ONION_PORT};" >> $turtl_nginx_site
691
-    echo "  server_name ${TURTL_ONION_HOSTNAME};" >> $turtl_nginx_site
692
-    echo '' >> $turtl_nginx_site
697
+    { echo 'server {';
698
+      echo "  listen 127.0.0.1:${TURTL_ONION_PORT};";
699
+      echo "  server_name ${TURTL_ONION_HOSTNAME};";
700
+      echo ''; } >> $turtl_nginx_site
693 701
     function_check nginx_disable_sniffing
694 702
     nginx_disable_sniffing $TURTL_DOMAIN_NAME
695
-    echo '' >> $turtl_nginx_site
696
-    echo '  # Logs' >> $turtl_nginx_site
697
-    echo '  access_log /dev/null;' >> $turtl_nginx_site
698
-    echo '  error_log /dev/null;' >> $turtl_nginx_site
699
-    echo '' >> $turtl_nginx_site
700
-    echo '  location / {' >> $turtl_nginx_site
703
+    { echo '';
704
+      echo '  # Logs';
705
+      echo '  access_log /dev/null;';
706
+      echo '  error_log /dev/null;';
707
+      echo '';
708
+      echo '  location / {'; } >> $turtl_nginx_site
701 709
     function_check nginx_limits
702 710
     nginx_limits $TURTL_DOMAIN_NAME '15m'
703
-    echo "    proxy_pass        http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
704
-    echo '    proxy_set_header  Host $host;' >> $turtl_nginx_site
705
-    echo '    proxy_buffering   off;' >> $turtl_nginx_site
706
-    echo '  }' >> $turtl_nginx_site
707
-    echo '}' >> $turtl_nginx_site
711
+    { echo "    proxy_pass        http://localhost:${TURTL_PORT}/;";
712
+      echo "    proxy_set_header  Host \$host;";
713
+      echo '    proxy_buffering   off;';
714
+      echo '  }';
715
+      echo '}'; } >> $turtl_nginx_site
708 716
 
709 717
     function_check add_ddns_domain
710 718
     add_ddns_domain $TURTL_DOMAIN_NAME

+ 62
- 60
src/freedombone-app-vim Datei anzeigen

@@ -62,27 +62,27 @@ function backup_local_vim {
62 62
             echo $"Backing up Vim config for $USERNAME"
63 63
 
64 64
             # create a temporary directory
65
-            if [ ! -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
66
-                mkdir /home/$USERNAME/$VIM_TEMP_DIR
65
+            if [ ! -d "/home/$USERNAME/$VIM_TEMP_DIR" ]; then
66
+                mkdir "/home/$USERNAME/$VIM_TEMP_DIR"
67 67
             fi
68 68
 
69 69
             # copy config files into the directory
70
-            if [ -f /home/$USERNAME/.vimrc ]; then
71
-                cp /home/$USERNAME/.vimrc /home/$USERNAME/$VIM_TEMP_DIR
72
-                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
70
+            if [ -f "/home/$USERNAME/.vimrc" ]; then
71
+                cp "/home/$USERNAME/.vimrc" "/home/$USERNAME/$VIM_TEMP_DIR"
72
+                chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/$VIM_TEMP_DIR"
73 73
             fi
74
-            if [ -f /home/$USERNAME/.viminfo ]; then
75
-                cp /home/$USERNAME/.viminfo /home/$USERNAME/$VIM_TEMP_DIR
76
-                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
74
+            if [ -f "/home/$USERNAME/.viminfo" ]; then
75
+                cp "/home/$USERNAME/.viminfo" "/home/$USERNAME/$VIM_TEMP_DIR"
76
+                chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/$VIM_TEMP_DIR"
77 77
             fi
78 78
 
79 79
             # backup the directory
80 80
             function_check backup_directory_to_usb
81
-            backup_directory_to_usb /home/$USERNAME/$VIM_TEMP_DIR vim/$USERNAME
81
+            backup_directory_to_usb "/home/$USERNAME/$VIM_TEMP_DIR" "vim/$USERNAME"
82 82
 
83 83
             # remove temporary directory
84
-            if [ -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
85
-                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
84
+            if [ -d "/home/$USERNAME/$VIM_TEMP_DIR" ]; then
85
+                rm -rf "/home/${USERNAME:?}/$VIM_TEMP_DIR"
86 86
             fi
87 87
         fi
88 88
     done
@@ -90,24 +90,25 @@ function backup_local_vim {
90 90
 
91 91
 function restore_local_vim {
92 92
     temp_restore_dir=/root/tempvim
93
-    if [ -d $USB_MOUNT/backup/vim ]; then
93
+    if [ -d "$USB_MOUNT/backup/vim" ]; then
94 94
         for d in $USB_MOUNT/backup/vim/*/ ; do
95 95
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
96 96
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
97
-                if [ ! -d /home/$USERNAME ]; then
98
-                    ${PROJECT_NAME}-adduser $USERNAME
97
+                if [ ! -d "/home/$USERNAME" ]; then
98
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
99 99
                 fi
100 100
                 echo $"Restoring Vim config for $USERNAME"
101 101
                 function_check restore_directory_from_usb
102
-                restore_directory_from_usb $temp_restore_dir vim/$USERNAME
103
-                if [ -d $temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR ]; then
104
-                    cp -r $temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR /home/$USERNAME/
102
+                restore_directory_from_usb "$temp_restore_dir" "vim/$USERNAME"
103
+                if [ -d "$temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR" ]; then
104
+                    cp -r "$temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR" "/home/$USERNAME/"
105 105
                 else
106
-                    if [ ! -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
107
-                        mkdir /home/$USERNAME/$VIM_TEMP_DIR
106
+                    if [ ! -d "/home/$USERNAME/$VIM_TEMP_DIR" ]; then
107
+                        mkdir "/home/$USERNAME/$VIM_TEMP_DIR"
108 108
                     fi
109
-                    cp -r $temp_restore_dir/* /home/$USERNAME/$VIM_TEMP_DIR/
109
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/$VIM_TEMP_DIR/"
110 110
                 fi
111
+                # shellcheck disable=SC2181
111 112
                 if [ ! "$?" = "0" ]; then
112 113
                     rm -rf $temp_restore_dir
113 114
                     function_check set_user_permissions
@@ -116,14 +117,14 @@ function restore_local_vim {
116 117
                     backup_unmount_drive
117 118
                     exit 664
118 119
                 fi
119
-                cp /home/$USERNAME/$VIM_TEMP_DIR/* /home/$USERNAME
120
-                if [ -f /home/$USERNAME/.viminfo ]; then
121
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.viminfo
120
+                cp "/home/$USERNAME/$VIM_TEMP_DIR/*" "/home/$USERNAME"
121
+                if [ -f "/home/$USERNAME/.viminfo" ]; then
122
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.viminfo"
122 123
                 fi
123
-                if [ -f /home/$USERNAME/.vimrc ]; then
124
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.vimrc
124
+                if [ -f "/home/$USERNAME/.vimrc" ]; then
125
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.vimrc"
125 126
                 fi
126
-                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
127
+                rm -rf "/home/${USERNAME:?}/$VIM_TEMP_DIR"
127 128
                 rm -rf $temp_restore_dir
128 129
             fi
129 130
         done
@@ -137,27 +138,27 @@ function backup_remote_vim {
137 138
             echo $"Backing up Vim config for $USERNAME"
138 139
 
139 140
             # create a temporary directory
140
-            if [ ! -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
141
-                mkdir /home/$USERNAME/$VIM_TEMP_DIR
141
+            if [ ! -d "/home/$USERNAME/$VIM_TEMP_DIR" ]; then
142
+                mkdir "/home/$USERNAME/$VIM_TEMP_DIR"
142 143
             fi
143 144
 
144 145
             # copy config files into the directory
145
-            if [ -f /home/$USERNAME/.vimrc ]; then
146
-                cp /home/$USERNAME/.vimrc /home/$USERNAME/$VIM_TEMP_DIR
147
-                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
146
+            if [ -f "/home/$USERNAME/.vimrc" ]; then
147
+                cp "/home/$USERNAME/.vimrc" "/home/$USERNAME/$VIM_TEMP_DIR"
148
+                chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/$VIM_TEMP_DIR"
148 149
             fi
149
-            if [ -f /home/$USERNAME/.viminfo ]; then
150
-                cp /home/$USERNAME/.viminfo /home/$USERNAME/$VIM_TEMP_DIR
151
-                chown -R $USERNAME:$USERNAME /home/$USERNAME/$VIM_TEMP_DIR
150
+            if [ -f "/home/$USERNAME/.viminfo" ]; then
151
+                cp "/home/$USERNAME/.viminfo" "/home/$USERNAME/$VIM_TEMP_DIR"
152
+                chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/$VIM_TEMP_DIR"
152 153
             fi
153 154
 
154 155
             # backup the directory
155 156
             function_check backup_directory_to_friend
156
-            backup_directory_to_friend /home/$USERNAME/$VIM_TEMP_DIR vim/$USERNAME
157
+            backup_directory_to_friend "/home/$USERNAME/$VIM_TEMP_DIR" "vim/$USERNAME"
157 158
 
158 159
             # remove temporary directory
159
-            if [ -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
160
-                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
160
+            if [ -d "/home/$USERNAME/$VIM_TEMP_DIR" ]; then
161
+                rm -rf "/home/${USERNAME:?}/$VIM_TEMP_DIR"
161 162
             fi
162 163
         fi
163 164
     done
@@ -165,24 +166,25 @@ function backup_remote_vim {
165 166
 
166 167
 function restore_remote_vim {
167 168
     temp_restore_dir=/root/tempvim
168
-    if [ -d $USB_MOUNT/backup/vim ]; then
169
+    if [ -d "$USB_MOUNT/backup/vim" ]; then
169 170
         for d in $USB_MOUNT/backup/vim/*/ ; do
170 171
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
171 172
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
172
-                if [ ! -d /home/$USERNAME ]; then
173
-                    ${PROJECT_NAME}-adduser $USERNAME
173
+                if [ ! -d "/home/$USERNAME" ]; then
174
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
174 175
                 fi
175 176
                 echo $"Restoring Vim config for $USERNAME"
176 177
                 function_check restore_directory_from_friend
177
-                restore_directory_from_friend $temp_restore_dir vim/$USERNAME
178
-                if [ -d $temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR ]; then
179
-                    cp -r $temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR /home/$USERNAME/
178
+                restore_directory_from_friend "$temp_restore_dir vim/$USERNAME"
179
+                if [ -d "$temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR" ]; then
180
+                    cp -r "$temp_restore_dir/home/$USERNAME/$VIM_TEMP_DIR" "/home/$USERNAME/"
180 181
                 else
181
-                    if [ ! -d /home/$USERNAME/$VIM_TEMP_DIR ]; then
182
-                        mkdir /home/$USERNAME/$VIM_TEMP_DIR
182
+                    if [ ! -d "/home/$USERNAME/$VIM_TEMP_DIR" ]; then
183
+                        mkdir "/home/$USERNAME/$VIM_TEMP_DIR"
183 184
                     fi
184
-                    cp -r $temp_restore_dir/* /home/$USERNAME/$VIM_TEMP_DIR/
185
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/$VIM_TEMP_DIR/"
185 186
                 fi
187
+                # shellcheck disable=SC2181
186 188
                 if [ ! "$?" = "0" ]; then
187 189
                     rm -rf $temp_restore_dir
188 190
                     function_check set_user_permissions
@@ -191,14 +193,14 @@ function restore_remote_vim {
191 193
                     backup_unmount_drive
192 194
                     exit 664
193 195
                 fi
194
-                cp /home/$USERNAME/$VIM_TEMP_DIR/* /home/$USERNAME
195
-                if [ -f /home/$USERNAME/.viminfo ]; then
196
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.viminfo
196
+                cp "/home/$USERNAME/$VIM_TEMP_DIR/*" "/home/$USERNAME"
197
+                if [ -f "/home/$USERNAME/.viminfo" ]; then
198
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.viminfo"
197 199
                 fi
198
-                if [ -f /home/$USERNAME/.vimrc ]; then
199
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.vimrc
200
+                if [ -f "/home/$USERNAME/.vimrc" ]; then
201
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.vimrc"
200 202
                 fi
201
-                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
203
+                rm -rf "/home/${USERNAME:?}/$VIM_TEMP_DIR"
202 204
                 rm -rf $temp_restore_dir
203 205
             fi
204 206
         done
@@ -210,7 +212,7 @@ function remove_vim {
210 212
     # This may change with Debian Stretch
211 213
     # apt-get -yq remove --purge vim
212 214
     update-alternatives --set editor /usr/bin/nano
213
-    sed -i '/install_vim/d' $COMPLETION_FILE
215
+    sed -i '/install_vim/d' "$COMPLETION_FILE"
214 216
 
215 217
     # remove Vim as the mutt email editor
216 218
     if [ -f /etc/Muttrc ]; then
@@ -220,9 +222,9 @@ function remove_vim {
220 222
         for d in /home/*/ ; do
221 223
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
222 224
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
223
-                if [ -f /home/$USERNAME/.muttrc ]; then
224
-                    if grep -q "set editor=" /home/$USERNAME/.muttrc; then
225
-                        sed -i '/set editor=/d' /home/$USERNAME/.muttrc
225
+                if [ -f "/home/$USERNAME/.muttrc" ]; then
226
+                    if grep -q "set editor=" "/home/$USERNAME/.muttrc"; then
227
+                        sed -i '/set editor=/d' "/home/$USERNAME/.muttrc"
226 228
                     fi
227 229
                 fi
228 230
             fi
@@ -244,11 +246,11 @@ function install_vim {
244 246
         for d in /home/*/ ; do
245 247
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
246 248
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
247
-                if [ -f /home/$USERNAME/.muttrc ]; then
248
-                    if ! grep -q "set editor=" /home/$USERNAME/.muttrc; then
249
-                        echo "set editor=\"$VIM_MUTT_EDITOR\"" >> /home/$USERNAME/.muttrc
249
+                if [ -f "/home/$USERNAME/.muttrc" ]; then
250
+                    if ! grep -q "set editor=" "/home/$USERNAME/.muttrc"; then
251
+                        echo "set editor=\"$VIM_MUTT_EDITOR\"" >> "/home/$USERNAME/.muttrc"
250 252
                     else
251
-                        sed -i "s|set editor=.*|set editor=\"$VIM_MUTT_EDITOR\"|g" /home/$USERNAME/.muttrc
253
+                        sed -i "s|set editor=.*|set editor=\"$VIM_MUTT_EDITOR\"|g" "/home/$USERNAME/.muttrc"
252 254
                     fi
253 255
                 fi
254 256
             fi

+ 218
- 210
src/freedombone-app-vpn Datei anzeigen

@@ -82,23 +82,24 @@ function install_interactive_vpn {
82 82
     VPN_DETAILS_COMPLETE=
83 83
     while [ ! $VPN_DETAILS_COMPLETE ]
84 84
     do
85
-        data=$(tempfile 2>/dev/null)
86
-        trap "rm -f $data" 0 1 2 5 15
85
+        data=$(mktemp 2>/dev/null)
87 86
         currtlsport=$(grep 'VPN_TLS_PORT' temp.cfg | awk -F '=' '{print $2}')
88
-        if [ $currtlsport ]; then
87
+        if [ "$currtlsport" ]; then
89 88
             VPN_TLS_PORT=$currtlsport
90 89
         fi
91 90
         dialog --backtitle $"Freedombone Configuration" \
92 91
                --title $"VPN Configuration" \
93
-               --form $"\nPlease enter your VPN details. Changing the port to 443 will help defend against censorship but will prevent other web apps from running." 12 65 1 \
92
+               --form $"\\nPlease enter your VPN details. Changing the port to 443 will help defend against censorship but will prevent other web apps from running." 12 65 1 \
94 93
                $"TLS port:" 1 1 "$VPN_TLS_PORT" 1 12 5 5 \
95
-               2> $data
94
+               2> "$data"
96 95
         sel=$?
97 96
         case $sel in
98
-            1) exit 1;;
99
-            255) exit 1;;
97
+            1) rm -f "$data"
98
+               exit 1;;
99
+            255) rm -f "$data"
100
+                 exit 1;;
100 101
         esac
101
-        tlsport=$(cat $data | sed -n 1p)
102
+        tlsport=$(sed -n 1p < "$data")
102 103
         if [ ${#tlsport} -gt 1 ]; then
103 104
             if [[ "$tlsport" != *' '* && "$tlsport" != *'.'* ]]; then
104 105
                 VPN_TLS_PORT="$tlsport"
@@ -106,27 +107,27 @@ function install_interactive_vpn {
106 107
                 write_config_param "VPN_TLS_PORT" "$VPN_TLS_PORT"
107 108
             fi
108 109
         fi
110
+        rm -f "$data"
109 111
     done
110 112
     clear
111 113
     APP_INSTALLED=1
112 114
 }
113 115
 
114 116
 function vpn_change_tls_port {
115
-    if ! grep -q "VPN-TLS" $FIREWALL_CONFIG; then
117
+    if ! grep -q "VPN-TLS" "$FIREWALL_CONFIG"; then
116 118
         EXISTING_VPN_TLS_PORT=443
117 119
     else
118
-        EXISTING_VPN_TLS_PORT=$(cat $FIREWALL_CONFIG | grep "VPN-TLS" | awk -F '=' '{print $2}')
120
+        EXISTING_VPN_TLS_PORT=$(grep "VPN-TLS" "$FIREWALL_CONFIG" | awk -F '=' '{print $2}')
119 121
     fi
120 122
 
121
-    data=$(tempfile 2>/dev/null)
122
-    trap "rm -f $data" 0 1 2 5 15
123
+    data=$(mktemp 2>/dev/null)
123 124
     dialog --title $"VPN Configuration" \
124 125
            --backtitle $"Freedombone Control Panel" \
125
-           --inputbox $'Change TLS port' 10 50 $EXISTING_VPN_TLS_PORT 2>$data
126
+           --inputbox $'Change TLS port' 10 50 "$EXISTING_VPN_TLS_PORT" 2>"$data"
126 127
     sel=$?
127 128
     case $sel in
128 129
         0)
129
-            tlsport=$(<$data)
130
+            tlsport=$(<"$data")
130 131
             if [ ${#tlsport} -gt 0 ]; then
131 132
                 if [[ "$tlsport" != "$EXISTING_VPN_TLS_PORT" ]]; then
132 133
                     clear
@@ -137,22 +138,22 @@ function vpn_change_tls_port {
137 138
 
138 139
                     for d in /home/*/ ; do
139 140
                         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
140
-                        if [ -f /home/$USERNAME/stunnel-client.conf ]; then
141
-                            cp /etc/stunnel/stunnel-client.conf /home/$USERNAME/stunnel-client.conf
142
-                            chown $USERNAME:$USERNAME /home/$USERNAME/stunnel-client.conf
141
+                        if [ -f "/home/$USERNAME/stunnel-client.conf" ]; then
142
+                            cp "/etc/stunnel/stunnel-client.conf" "/home/$USERNAME/stunnel-client.conf"
143
+                            chown "$USERNAME":"$USERNAME" "/home/$USERNAME/stunnel-client.conf"
143 144
                         fi
144 145
                     done
145 146
 
146
-                    if [ $VPN_TLS_PORT -eq 443 ]; then
147
+                    if [ "$VPN_TLS_PORT" -eq 443 ]; then
147 148
                         if [[ "$PREVIOUS_VPN_TLS_PORT" != "443" ]]; then
148
-                            firewall_remove VPN-TLS ${EXISTING_VPN_TLS_PORT}
149
+                            firewall_remove VPN-TLS "${EXISTING_VPN_TLS_PORT}"
149 150
                         fi
150 151
                         systemctl stop nginx
151 152
                         systemctl disable nginx
152 153
                     else
153 154
                         if [[ "$PREVIOUS_VPN_TLS_PORT" != "$VPN_TLS_PORT" ]]; then
154
-                            firewall_remove VPN-TLS ${EXISTING_VPN_TLS_PORT}
155
-                            firewall_add VPN-TLS ${VPN_TLS_PORT} tcp
155
+                            firewall_remove VPN-TLS "${EXISTING_VPN_TLS_PORT}"
156
+                            firewall_add VPN-TLS "${VPN_TLS_PORT}" tcp
156 157
                         fi
157 158
                         systemctl enable nginx
158 159
                         systemctl restart nginx
@@ -160,7 +161,7 @@ function vpn_change_tls_port {
160 161
 
161 162
                     systemctl restart stunnel
162 163
 
163
-                    if [ $VPN_TLS_PORT -eq 443 ]; then
164
+                    if [ "$VPN_TLS_PORT" -eq 443 ]; then
164 165
                         dialog --title $"VPN Configuration" \
165 166
                                --msgbox $"TLS port changed to ${VPN_TLS_PORT}. Forward this port from your internet router." 10 60
166 167
                     else
@@ -171,52 +172,56 @@ function vpn_change_tls_port {
171 172
             fi
172 173
             ;;
173 174
     esac
175
+    rm -f "$data"
174 176
 }
175 177
 
176 178
 function vpn_regenerate_client_keys {
177
-    data=$(tempfile 2>/dev/null)
178
-    trap "rm -f $data" 0 1 2 5 15
179
+    data=$(mktemp 2>/dev/null)
179 180
     dialog --title $"Regenerate VPN keys for a user" \
180 181
            --backtitle $"Freedombone Control Panel" \
181
-           --inputbox $'username' 10 50 2>$data
182
+           --inputbox $'username' 10 50 2>"$data"
182 183
     sel=$?
183 184
     case $sel in
184 185
         0)
185
-            USERNAME=$(<$data)
186
+            USERNAME=$(<"$data")
186 187
             if [ ${#USERNAME} -gt 0 ]; then
187
-                if [ -d /home/$USERNAME ]; then
188
+                if [ -d "/home/$USERNAME" ]; then
188 189
                     clear
189
-                    create_user_vpn_key $USERNAME
190
+                    create_user_vpn_key "$USERNAME"
190 191
                     dialog --title $"Regenerate VPN keys for a user" \
191 192
                            --msgbox $"VPN keys were regenerated for $USERNAME" 6 60
192 193
                 fi
193 194
             fi
194 195
             ;;
195 196
     esac
197
+    rm -f "$data"
196 198
 }
197 199
 
198 200
 function configure_interactive_vpn {
199 201
     read_config_param VPN_TLS_PORT
200 202
     while true
201 203
     do
202
-        data=$(tempfile 2>/dev/null)
203
-        trap "rm -f $data" 0 1 2 5 15
204
+        data=$(mktemp 2>/dev/null)
204 205
         dialog --backtitle $"Freedombone Control Panel" \
205 206
                --title $"VPN Configuration" \
206 207
                --radiolist $"Choose an operation:" 13 70 3 \
207 208
                1 $"Change TLS port (currently $VPN_TLS_PORT)" off \
208 209
                2 $"Regenerate keys for a user" off \
209
-               3 $"Exit" on 2> $data
210
+               3 $"Exit" on 2> "$data"
210 211
         sel=$?
211 212
         case $sel in
212
-            1) return;;
213
-            255) return;;
213
+            1) rm -f "$data"
214
+               return;;
215
+            255) rm -f "$data"
216
+                 return;;
214 217
         esac
215
-        case $(cat $data) in
218
+        case $(cat "$data") in
216 219
             1) vpn_change_tls_port;;
217 220
             2) vpn_regenerate_client_keys;;
218
-            3) break;;
221
+            3) rm -f "$data"
222
+               break;;
219 223
         esac
224
+        rm -f "$data"
220 225
     done
221 226
 }
222 227
 
@@ -231,8 +236,8 @@ function upgrade_vpn {
231 236
 function backup_local_vpn {
232 237
     for d in /home/*/ ; do
233 238
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
234
-        if [ -f /home/$USERNAME/$OPENVPN_KEY_FILENAME ]; then
235
-            cp /home/$USERNAME/$OPENVPN_KEY_FILENAME /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}
239
+        if [ -f "/home/$USERNAME/$OPENVPN_KEY_FILENAME" ]; then
240
+            cp "/home/$USERNAME/$OPENVPN_KEY_FILENAME" "/etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}"
236 241
         fi
237 242
     done
238 243
 
@@ -252,9 +257,9 @@ function restore_local_vpn {
252 257
 
253 258
         for d in /home/*/ ; do
254 259
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
255
-            if [ -f /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} ]; then
256
-                cp /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} /home/$USERNAME/$OPENVPN_KEY_FILENAME
257
-                chown $USERNAME:$USERNAME /home/$USERNAME/$OPENVPN_KEY_FILENAME
260
+            if [ -f "/etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}" ]; then
261
+                cp "/etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}" "/home/$USERNAME/$OPENVPN_KEY_FILENAME"
262
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME/$OPENVPN_KEY_FILENAME"
258 263
             fi
259 264
         done
260 265
     fi
@@ -265,13 +270,13 @@ function restore_local_vpn {
265 270
         rm -rf ${temp_restore_dir}
266 271
         for d in /home/*/ ; do
267 272
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
268
-            if [ -f /home/$USERNAME/stunnel.pem ]; then
269
-                cp /etc/stunnel/stunnel.pem /home/$USERNAME/stunnel.pem
270
-                chown $USERNAME:$USERNAME /home/$USERNAME/stunnel.pem
273
+            if [ -f "/home/$USERNAME/stunnel.pem" ]; then
274
+                cp /etc/stunnel/stunnel.pem "/home/$USERNAME/stunnel.pem"
275
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME/stunnel.pem"
271 276
             fi
272
-            if [ -f /home/$USERNAME/stunnel.p12 ]; then
273
-                cp /etc/stunnel/stunnel.p12 /home/$USERNAME/stunnel.p12
274
-                chown $USERNAME:$USERNAME /home/$USERNAME/stunnel.p12
277
+            if [ -f "/home/$USERNAME/stunnel.p12" ]; then
278
+                cp /etc/stunnel/stunnel.p12 "/home/$USERNAME/stunnel.p12"
279
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME/stunnel.p12"
275 280
             fi
276 281
         done
277 282
     fi
@@ -280,8 +285,8 @@ function restore_local_vpn {
280 285
 function backup_remote_vpn {
281 286
     for d in /home/*/ ; do
282 287
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
283
-        if [ -f /home/$USERNAME/$OPENVPN_KEY_FILENAME ]; then
284
-            cp /home/$USERNAME/$OPENVPN_KEY_FILENAME /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}
288
+        if [ -f "/home/$USERNAME/$OPENVPN_KEY_FILENAME" ]; then
289
+            cp "/home/$USERNAME/$OPENVPN_KEY_FILENAME" "/etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}"
285 290
         fi
286 291
     done
287 292
 
@@ -301,9 +306,9 @@ function restore_remote_vpn {
301 306
 
302 307
         for d in /home/*/ ; do
303 308
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
304
-            if [ -f /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} ]; then
305
-                cp /etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME} /home/$USERNAME/$OPENVPN_KEY_FILENAME
306
-                chown $USERNAME:$USERNAME /home/$USERNAME/$OPENVPN_KEY_FILENAME
309
+            if [ -f "/etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}" ]; then
310
+                cp "/etc/openvpn/easy-rsa/keys/${USERNAME}_${OPENVPN_KEY_FILENAME}" "/home/$USERNAME/$OPENVPN_KEY_FILENAME"
311
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME/$OPENVPN_KEY_FILENAME"
307 312
             fi
308 313
         done
309 314
     fi
@@ -314,13 +319,13 @@ function restore_remote_vpn {
314 319
         rm -rf ${temp_restore_dir}
315 320
         for d in /home/*/ ; do
316 321
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
317
-            if [ -f /home/$USERNAME/stunnel.pem ]; then
318
-                cp /etc/stunnel/stunnel.pem /home/$USERNAME/stunnel.pem
319
-                chown $USERNAME:$USERNAME /home/$USERNAME/stunnel.pem
322
+            if [ -f "/home/$USERNAME/stunnel.pem" ]; then
323
+                cp /etc/stunnel/stunnel.pem "/home/$USERNAME/stunnel.pem"
324
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME/stunnel.pem"
320 325
             fi
321
-            if [ -f /home/$USERNAME/stunnel.p12 ]; then
322
-                cp /etc/stunnel/stunnel.p12 /home/$USERNAME/stunnel.p12
323
-                chown $USERNAME:$USERNAME /home/$USERNAME/stunnel.p12
326
+            if [ -f "/home/$USERNAME/stunnel.p12" ]; then
327
+                cp /etc/stunnel/stunnel.p12 "/home/$USERNAME/stunnel.p12"
328
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME/stunnel.p12"
324 329
             fi
325 330
         done
326 331
     fi
@@ -332,8 +337,8 @@ function remove_vpn {
332 337
     rm /etc/systemd/system/stunnel.service
333 338
 
334 339
     systemctl stop openvpn
335
-    if [ $VPN_TLS_PORT -ne 443 ]; then
336
-        firewall_remove VPN-TLS $VPN_TLS_PORT
340
+    if [ "$VPN_TLS_PORT" -ne 443 ]; then
341
+        firewall_remove VPN-TLS "$VPN_TLS_PORT"
337 342
     else
338 343
         systemctl enable nginx
339 344
         systemctl restart nginx
@@ -354,10 +359,10 @@ function remove_vpn {
354 359
     # remove any client keys
355 360
     for d in /home/*/ ; do
356 361
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
357
-        if [ -f /home/$USERNAME/$OPENVPN_KEY_FILENAME ]; then
358
-            shred -zu /home/$USERNAME/$OPENVPN_KEY_FILENAME
362
+        if [ -f "/home/$USERNAME/$OPENVPN_KEY_FILENAME" ]; then
363
+            shred -zu "/home/$USERNAME/$OPENVPN_KEY_FILENAME"
359 364
         fi
360
-        rm /home/$USERNAME/stunnel*
365
+        rm "/home/$USERNAME/stunnel*"
361 366
     done
362 367
     userdel -f vpn
363 368
     groupdel -f vpn
@@ -370,107 +375,108 @@ function remove_vpn {
370 375
 function create_user_vpn_key {
371 376
     username=$1
372 377
 
373
-    if [ ! -d /home/$username ]; then
378
+    if [ ! -d "/home/$username" ]; then
374 379
         return
375 380
     fi
376 381
 
377 382
     echo $"Creating VPN key for $username"
378 383
 
379
-    cd /etc/openvpn/easy-rsa
384
+    cd /etc/openvpn/easy-rsa || exit 4728468246
380 385
 
381
-    if [ -f /etc/openvpn/easy-rsa/keys/$username.crt ]; then
382
-        rm /etc/openvpn/easy-rsa/keys/$username.crt
386
+    if [ -f "/etc/openvpn/easy-rsa/keys/$username.crt" ]; then
387
+        rm "/etc/openvpn/easy-rsa/keys/$username.crt"
383 388
     fi
384
-    if [ -f /etc/openvpn/easy-rsa/keys/$username.key ]; then
385
-        rm /etc/openvpn/easy-rsa/keys/$username.key
389
+    if [ -f "/etc/openvpn/easy-rsa/keys/$username.key" ]; then
390
+        rm "/etc/openvpn/easy-rsa/keys/$username.key"
386 391
     fi
387
-    if [ -f /etc/openvpn/easy-rsa/keys/$username.csr ]; then
388
-        rm /etc/openvpn/easy-rsa/keys/$username.csr
392
+    if [ -f "/etc/openvpn/easy-rsa/keys/$username.csr" ]; then
393
+        rm "/etc/openvpn/easy-rsa/keys/$username.csr"
389 394
     fi
390 395
 
391 396
     sed -i 's| --interact||g' build-key
392 397
     ./build-key "$username"
393 398
 
394
-    if [ ! -f /etc/openvpn/easy-rsa/keys/$username.crt ]; then
399
+    if [ ! -f "/etc/openvpn/easy-rsa/keys/$username.crt" ]; then
395 400
         echo $'VPN user cert not generated'
396 401
         exit 783528
397 402
     fi
398
-    user_cert=$(cat /etc/openvpn/easy-rsa/keys/$username.crt)
403
+    user_cert=$(cat "/etc/openvpn/easy-rsa/keys/$username.crt")
399 404
     if [ ${#user_cert} -lt 10 ]; then
400
-        cat /etc/openvpn/easy-rsa/keys/$username.crt
405
+        cat "/etc/openvpn/easy-rsa/keys/$username.crt"
401 406
         echo $'User cert generation failed'
402 407
         exit 634659
403 408
     fi
404
-    if [ ! -f /etc/openvpn/easy-rsa/keys/$username.key ]; then
409
+    if [ ! -f "/etc/openvpn/easy-rsa/keys/$username.key" ]; then
405 410
         echo $'VPN user key not generated'
406 411
         exit 682523
407 412
     fi
408
-    user_key=$(cat /etc/openvpn/easy-rsa/keys/$username.key)
413
+    user_key=$(cat "/etc/openvpn/easy-rsa/keys/$username.key")
409 414
     if [ ${#user_key} -lt 10 ]; then
410
-        cat /etc/openvpn/easy-rsa/keys/$username.key
415
+        cat "/etc/openvpn/easy-rsa/keys/$username.key"
411 416
         echo $'User key generation failed'
412 417
         exit 285838
413 418
     fi
414 419
 
415 420
     user_vpn_cert_file=/home/$username/$OPENVPN_KEY_FILENAME
416 421
 
417
-    echo 'client' > $user_vpn_cert_file
418
-    echo 'dev tun' >> $user_vpn_cert_file
419
-    echo 'proto tcp' >> $user_vpn_cert_file
420
-    echo "remote localhost $STUNNEL_PORT" >> $user_vpn_cert_file
421
-    echo "route $DEFAULT_DOMAIN_NAME 255.255.255.255 net_gateway" >> $user_vpn_cert_file
422
-    echo 'resolv-retry infinite' >> $user_vpn_cert_file
423
-    echo 'nobind' >> $user_vpn_cert_file
424
-    echo 'tun-mtu 1500' >> $user_vpn_cert_file
425
-    echo 'tun-mtu-extra 32' >> $user_vpn_cert_file
426
-    echo 'mssfix 1450' >> $user_vpn_cert_file
427
-    echo 'persist-key' >> $user_vpn_cert_file
428
-    echo 'persist-tun' >> $user_vpn_cert_file
429
-    echo 'auth-nocache' >> $user_vpn_cert_file
430
-    echo 'remote-cert-tls server' >> $user_vpn_cert_file
431
-    echo 'comp-lzo' >> $user_vpn_cert_file
432
-    echo 'verb 3' >> $user_vpn_cert_file
433
-    echo '' >> $user_vpn_cert_file
434
-
435
-    echo '<ca>' >> $user_vpn_cert_file
436
-    cat /etc/openvpn/ca.crt >> $user_vpn_cert_file
437
-    echo '</ca>' >> $user_vpn_cert_file
438
-
439
-    echo '<cert>' >> $user_vpn_cert_file
440
-    cat /etc/openvpn/easy-rsa/keys/$username.crt >> $user_vpn_cert_file
441
-    echo '</cert>' >> $user_vpn_cert_file
442
-
443
-    echo '<key>' >> $user_vpn_cert_file
444
-    cat /etc/openvpn/easy-rsa/keys/$username.key >> $user_vpn_cert_file
445
-    echo '</key>' >> $user_vpn_cert_file
446
-
447
-    chown $username:$username $user_vpn_cert_file
422
+    { echo 'client';
423
+      echo 'dev tun';
424
+      echo 'proto tcp';
425
+      echo "remote localhost $STUNNEL_PORT";
426
+      echo "route $DEFAULT_DOMAIN_NAME 255.255.255.255 net_gateway";
427
+      echo 'resolv-retry infinite';
428
+      echo 'nobind';
429
+      echo 'tun-mtu 1500';
430
+      echo 'tun-mtu-extra 32';
431
+      echo 'mssfix 1450';
432
+      echo 'persist-key';
433
+      echo 'persist-tun';
434
+      echo 'auth-nocache';
435
+      echo 'remote-cert-tls server';
436
+      echo 'comp-lzo';
437
+      echo 'verb 3';
438
+      echo ''; } > "$user_vpn_cert_file"
439
+
440
+    {
441
+        echo '<ca>';
442
+        cat /etc/openvpn/ca.crt;
443
+        echo '</ca>';
444
+
445
+        echo '<cert>';
446
+        cat "/etc/openvpn/easy-rsa/keys/$username.crt;"
447
+        echo '</cert>';
448
+
449
+        echo '<key>';
450
+        cat "/etc/openvpn/easy-rsa/keys/$username.key;"
451
+        echo '</key>'; } >> "$user_vpn_cert_file"
452
+
453
+    chown "$username":"$username" "$user_vpn_cert_file"
448 454
 
449 455
     # keep a backup
450
-    cp $user_vpn_cert_file /etc/openvpn/easy-rsa/keys/$username.ovpn
456
+    cp "$user_vpn_cert_file" "/etc/openvpn/easy-rsa/keys/$username.ovpn"
451 457
 
452 458
     #rm /etc/openvpn/easy-rsa/keys/$username.crt
453 459
     #rm /etc/openvpn/easy-rsa/keys/$username.csr
454
-    shred -zu /etc/openvpn/easy-rsa/keys/$username.key
460
+    shred -zu "/etc/openvpn/easy-rsa/keys/$username.key"
455 461
 
456 462
     echo $"VPN key created at $user_vpn_cert_file"
457 463
 }
458 464
 
459 465
 function add_user_vpn {
460 466
     new_username="$1"
461
-    new_user_password="$2"
467
+#    new_user_password="$2"
462 468
 
463
-    create_user_vpn_key $new_username
469
+    create_user_vpn_key "$new_username"
464 470
     if [ -f /etc/stunnel/stunnel.pem ]; then
465
-        cp /etc/stunnel/stunnel.pem /home/$new_username/stunnel.pem
466
-        chown $new_username:$new_username /home/$new_username/stunnel.pem
471
+        cp /etc/stunnel/stunnel.pem "/home/$new_username/stunnel.pem"
472
+        chown "$new_username":"$new_username" "/home/$new_username/stunnel.pem"
467 473
     fi
468 474
     if [ -f /etc/stunnel/stunnel.p12 ]; then
469
-        cp /etc/stunnel/stunnel.p12 /home/$new_username/stunnel.p12
470
-        chown $new_username:$new_username /home/$new_username/stunnel.p12
475
+        cp /etc/stunnel/stunnel.p12 "/home/$new_username/stunnel.p12"
476
+        chown "$new_username":"$new_username" "/home/$new_username/stunnel.p12"
471 477
     fi
472
-    cp /etc/stunnel/stunnel-client.conf /home/$new_username/stunnel-client.conf
473
-    chown $new_username:$new_username /home/$new_username/stunnel-client.conf
478
+    cp /etc/stunnel/stunnel-client.conf "/home/$new_username/stunnel-client.conf"
479
+    chown "$new_username":"$new_username" "/home/$new_username/stunnel-client.conf"
474 480
 }
475 481
 
476 482
 function remove_user_vpn {
@@ -516,15 +522,16 @@ function generate_stunnel_keys {
516 522
     fi
517 523
     chmod 640 /etc/stunnel/stunnel.p12
518 524
 
519
-    cp /etc/stunnel/stunnel.pem /home/$MY_USERNAME/stunnel.pem
520
-    cp /etc/stunnel/stunnel.p12 /home/$MY_USERNAME/stunnel.p12
521
-    chown $MY_USERNAME:$MY_USERNAME $prefix$userhome/stunnel*
525
+    cp /etc/stunnel/stunnel.pem "/home/$MY_USERNAME/stunnel.pem"
526
+    cp /etc/stunnel/stunnel.p12 "/home/$MY_USERNAME/stunnel.p12"
527
+    chown "$MY_USERNAME":"$MY_USERNAME" "$prefix/home/$MY_USERNAME/stunnel*"
522 528
 }
523 529
 
524 530
 function install_stunnel {
525 531
     prefix=
526 532
     prefixchroot=
527
-    if [ $rootdir ]; then
533
+    # shellcheck disable=SC2154
534
+    if [ "$rootdir" ]; then
528 535
         prefix=$rootdir
529 536
         prefixchroot="chroot $rootdir"
530 537
         VPN_TLS_PORT=$VPN_MESH_TLS_PORT
@@ -532,53 +539,53 @@ function install_stunnel {
532 539
 
533 540
     $prefixchroot apt-get -yq install stunnel4
534 541
 
535
-    if [ ! $prefix ]; then
536
-        cd /etc/stunnel
542
+    if [ ! "$prefix" ]; then
543
+        cd /etc/stunnel || exit 46284624
537 544
         generate_stunnel_keys
538 545
     fi
539 546
 
540
-    echo 'chroot = /var/lib/stunnel4' > $prefix/etc/stunnel/stunnel.conf
541
-    echo 'pid = /stunnel4.pid' >> $prefix/etc/stunnel/stunnel.conf
542
-    echo 'setuid = stunnel4' >> $prefix/etc/stunnel/stunnel.conf
543
-    echo 'setgid = stunnel4' >> $prefix/etc/stunnel/stunnel.conf
544
-    echo 'socket = l:TCP_NODELAY=1' >> $prefix/etc/stunnel/stunnel.conf
545
-    echo 'socket = r:TCP_NODELAY=1' >> $prefix/etc/stunnel/stunnel.conf
546
-    echo 'cert = /etc/stunnel/stunnel.pem' >> $prefix/etc/stunnel/stunnel.conf
547
-    echo '[openvpn]' >> $prefix/etc/stunnel/stunnel.conf
548
-    echo "accept = $VPN_TLS_PORT" >> $prefix/etc/stunnel/stunnel.conf
549
-    echo 'connect = localhost:1194' >> $prefix/etc/stunnel/stunnel.conf
550
-    echo 'cert = /etc/stunnel/stunnel.pem' >> $prefix/etc/stunnel/stunnel.conf
551
-    echo 'protocol = socks' >> $prefix/etc/stunnel/stunnel.conf
552
-
553
-    sed -i 's|ENABLED=.*|ENABLED=1|g' $prefix/etc/default/stunnel4
554
-
555
-    echo '[openvpn]' > $prefix/etc/stunnel/stunnel-client.conf
556
-    echo 'client = yes' >> $prefix/etc/stunnel/stunnel-client.conf
557
-    echo "accept = $STUNNEL_PORT" >> $prefix/etc/stunnel/stunnel-client.conf
558
-    echo "connect = $DEFAULT_DOMAIN_NAME:$VPN_TLS_PORT" >> $prefix/etc/stunnel/stunnel-client.conf
559
-    echo 'cert = stunnel.pem' >> $prefix/etc/stunnel/stunnel-client.conf
560
-    echo 'protocol = socks' >> $prefix/etc/stunnel/stunnel-client.conf
561
-
562
-    echo '[Unit]' > $prefix/etc/systemd/system/stunnel.service
563
-    echo 'Description=SSL tunnel for network daemons' >> $prefix/etc/systemd/system/stunnel.service
564
-    echo 'Documentation=man:stunnel https://www.stunnel.org/docs.html' >> $prefix/etc/systemd/system/stunnel.service
565
-    echo 'DefaultDependencies=no' >> $prefix/etc/systemd/system/stunnel.service
566
-    echo 'After=network.target' >> $prefix/etc/systemd/system/stunnel.service
567
-    echo 'After=syslog.target' >> $prefix/etc/systemd/system/stunnel.service
568
-    echo '' >> $prefix/etc/systemd/system/stunnel.service
569
-    echo '[Install]' >> $prefix/etc/systemd/system/stunnel.service
570
-    echo 'WantedBy=multi-user.target' >> $prefix/etc/systemd/system/stunnel.service
571
-    echo 'Alias=stunnel.target' >> $prefix/etc/systemd/system/stunnel.service
572
-    echo '' >> $prefix/etc/systemd/system/stunnel.service
573
-    echo '[Service]' >> $prefix/etc/systemd/system/stunnel.service
574
-    echo 'Type=forking' >> $prefix/etc/systemd/system/stunnel.service
575
-    echo 'RuntimeDirectory=stunnel' >> $prefix/etc/systemd/system/stunnel.service
576
-    echo 'EnvironmentFile=-/etc/stunnel/stunnel.conf' >> $prefix/etc/systemd/system/stunnel.service
577
-    echo 'ExecStart=/usr/bin/stunnel /etc/stunnel/stunnel.conf' >> $prefix/etc/systemd/system/stunnel.service
578
-    echo 'ExecStop=/usr/bin/killall -9 stunnel' >> $prefix/etc/systemd/system/stunnel.service
579
-    echo 'RemainAfterExit=yes' >> $prefix/etc/systemd/system/stunnel.service
580
-
581
-    if [ ! $prefix ]; then
547
+    { echo 'chroot = /var/lib/stunnel4';
548
+      echo 'pid = /stunnel4.pid';
549
+      echo 'setuid = stunnel4';
550
+      echo 'setgid = stunnel4';
551
+      echo 'socket = l:TCP_NODELAY=1';
552
+      echo 'socket = r:TCP_NODELAY=1';
553
+      echo 'cert = /etc/stunnel/stunnel.pem';
554
+      echo '[openvpn]';
555
+      echo "accept = $VPN_TLS_PORT";
556
+      echo 'connect = localhost:1194';
557
+      echo 'cert = /etc/stunnel/stunnel.pem';
558
+      echo 'protocol = socks'; } > "$prefix/etc/stunnel/stunnel.conf"
559
+
560
+    sed -i 's|ENABLED=.*|ENABLED=1|g' "$prefix/etc/default/stunnel4"
561
+
562
+    { echo '[openvpn]';
563
+      echo 'client = yes';
564
+      echo "accept = $STUNNEL_PORT";
565
+      echo "connect = $DEFAULT_DOMAIN_NAME:$VPN_TLS_PORT";
566
+      echo 'cert = stunnel.pem';
567
+      echo 'protocol = socks'; } > "$prefix/etc/stunnel/stunnel-client.conf"
568
+
569
+    { echo '[Unit]';
570
+      echo 'Description=SSL tunnel for network daemons';
571
+      echo 'Documentation=man:stunnel https://www.stunnel.org/docs.html';
572
+      echo 'DefaultDependencies=no';
573
+      echo 'After=network.target';
574
+      echo 'After=syslog.target';
575
+      echo '';
576
+      echo '[Install]';
577
+      echo 'WantedBy=multi-user.target';
578
+      echo 'Alias=stunnel.target';
579
+      echo '';
580
+      echo '[Service]';
581
+      echo 'Type=forking';
582
+      echo 'RuntimeDirectory=stunnel';
583
+      echo 'EnvironmentFile=-/etc/stunnel/stunnel.conf';
584
+      echo 'ExecStart=/usr/bin/stunnel /etc/stunnel/stunnel.conf';
585
+      echo 'ExecStop=/usr/bin/killall -9 stunnel';
586
+      echo 'RemainAfterExit=yes'; } > "$prefix/etc/systemd/system/stunnel.service"
587
+
588
+    if [ ! "$prefix" ]; then
582 589
         if [ $VPN_TLS_PORT -eq 443 ]; then
583 590
             systemctl stop nginx
584 591
             systemctl disable nginx
@@ -591,15 +598,15 @@ function install_stunnel {
591 598
         systemctl daemon-reload
592 599
         systemctl start stunnel
593 600
 
594
-        cp /etc/stunnel/stunnel-client.conf /home/$MY_USERNAME/stunnel-client.conf
595
-        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/stunnel*
601
+        cp /etc/stunnel/stunnel-client.conf "/home/$MY_USERNAME/stunnel-client.conf"
602
+        chown "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/stunnel*"
596 603
     fi
597 604
 }
598 605
 
599 606
 function vpn_generate_keys {
600 607
     # generate host keys
601 608
     if [ ! -f /etc/openvpn/dh2048.pem ]; then
602
-        ${PROJECT_NAME}-dhparam -o /etc/openvpn/dh2048.pem
609
+        "${PROJECT_NAME}-dhparam" -o /etc/openvpn/dh2048.pem
603 610
     fi
604 611
     if [ ! -f /etc/openvpn/dh2048.pem ]; then
605 612
         echo $'vpn dhparams were not generated'
@@ -607,7 +614,8 @@ function vpn_generate_keys {
607 614
     fi
608 615
     cp /etc/openvpn/dh2048.pem /etc/openvpn/easy-rsa/keys/dh2048.pem
609 616
 
610
-    cd /etc/openvpn/easy-rsa
617
+    cd /etc/openvpn/easy-rsa || exit 5628756256
618
+    # shellcheck disable=SC1091
611 619
     . ./vars
612 620
     ./clean-all
613 621
     vpn_openssl_version='1.0.0'
@@ -651,13 +659,13 @@ function vpn_generate_keys {
651 659
     fi
652 660
     cp /etc/openvpn/easy-rsa/keys/{$OPENVPN_SERVER_NAME.crt,$OPENVPN_SERVER_NAME.key,ca.crt} /etc/openvpn
653 661
 
654
-    create_user_vpn_key ${MY_USERNAME}
662
+    create_user_vpn_key "${MY_USERNAME}"
655 663
 }
656 664
 
657 665
 function install_vpn {
658 666
     prefix=
659 667
     prefixchroot=
660
-    if [ $rootdir ]; then
668
+    if [ "$rootdir" ]; then
661 669
         prefix=$rootdir
662 670
         prefixchroot="chroot $rootdir"
663 671
         VPN_TLS_PORT=$VPN_MESH_TLS_PORT
@@ -668,50 +676,50 @@ function install_vpn {
668 676
     $prefixchroot useradd -r -s /bin/false -g vpn vpn
669 677
 
670 678
     # server configuration
671
-    echo 'port 1194' > $prefix/etc/openvpn/server.conf
672
-    echo 'proto tcp' >> $prefix/etc/openvpn/server.conf
673
-    echo 'dev tun' >> $prefix/etc/openvpn/server.conf
674
-    echo 'tun-mtu 1500' >> $prefix/etc/openvpn/server.conf
675
-    echo 'tun-mtu-extra 32' >> $prefix/etc/openvpn/server.conf
676
-    echo 'mssfix 1450' >> $prefix/etc/openvpn/server.conf
677
-    echo 'ca /etc/openvpn/ca.crt' >> $prefix/etc/openvpn/server.conf
678
-    echo 'cert /etc/openvpn/server.crt' >> $prefix/etc/openvpn/server.conf
679
-    echo 'key /etc/openvpn/server.key' >> $prefix/etc/openvpn/server.conf
680
-    echo 'dh /etc/openvpn/dh2048.pem' >> $prefix/etc/openvpn/server.conf
681
-    echo 'server 10.8.0.0 255.255.255.0' >> $prefix/etc/openvpn/server.conf
682
-    echo 'push "redirect-gateway def1 bypass-dhcp"' >> $prefix/etc/openvpn/server.conf
683
-    echo "push \"dhcp-option DNS 85.214.73.63\"" >> $prefix/etc/openvpn/server.conf
684
-    echo "push \"dhcp-option DNS 213.73.91.35\"" >> $prefix/etc/openvpn/server.conf
685
-    echo 'keepalive 5 30' >> $prefix/etc/openvpn/server.conf
686
-    echo 'comp-lzo' >> $prefix/etc/openvpn/server.conf
687
-    echo 'persist-key' >> $prefix/etc/openvpn/server.conf
688
-    echo 'persist-tun' >> $prefix/etc/openvpn/server.conf
689
-    echo 'status /dev/null' >> $prefix/etc/openvpn/server.conf
690
-    echo 'verb 3' >> $prefix/etc/openvpn/server.conf
691
-    echo '' >> $prefix/etc/openvpn/server.conf
692
-
693
-    if [ ! $prefix ]; then
679
+    { echo 'port 1194';
680
+      echo 'proto tcp';
681
+      echo 'dev tun';
682
+      echo 'tun-mtu 1500';
683
+      echo 'tun-mtu-extra 32';
684
+      echo 'mssfix 1450';
685
+      echo 'ca /etc/openvpn/ca.crt';
686
+      echo 'cert /etc/openvpn/server.crt';
687
+      echo 'key /etc/openvpn/server.key';
688
+      echo 'dh /etc/openvpn/dh2048.pem';
689
+      echo 'server 10.8.0.0 255.255.255.0';
690
+      echo 'push "redirect-gateway def1 bypass-dhcp"';
691
+      echo "push \"dhcp-option DNS 85.214.73.63\"";
692
+      echo "push \"dhcp-option DNS 213.73.91.35\"";
693
+      echo 'keepalive 5 30';
694
+      echo 'comp-lzo';
695
+      echo 'persist-key';
696
+      echo 'persist-tun';
697
+      echo 'status /dev/null';
698
+      echo 'verb 3';
699
+      echo ''; } > "$prefix/etc/openvpn/server.conf"
700
+
701
+    if [ ! "$prefix" ]; then
694 702
         echo 1 > /proc/sys/net/ipv4/ip_forward
695 703
     fi
696
-    sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' $prefix/etc/sysctl.conf
697
-    sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' $prefix/etc/sysctl.conf
698
-    sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' $prefix/etc/sysctl.conf
704
+    sed -i 's|# net.ipv4.ip_forward|net.ipv4.ip_forward|g' "$prefix/etc/sysctl.conf"
705
+    sed -i 's|#net.ipv4.ip_forward|net.ipv4.ip_forward|g' "$prefix/etc/sysctl.conf"
706
+    sed -i 's|net.ipv4.ip_forward.*|net.ipv4.ip_forward=1|g' "$prefix/etc/sysctl.conf"
699 707
 
700
-    cp -r $prefix/usr/share/easy-rsa/ $prefix/etc/openvpn
701
-    if [ ! -d $prefix/etc/openvpn/easy-rsa/keys ]; then
702
-        mkdir $prefix/etc/openvpn/easy-rsa/keys
708
+    cp -r "$prefix/usr/share/easy-rsa/" "$prefix/etc/openvpn"
709
+    if [ ! -d "$prefix/etc/openvpn/easy-rsa/keys" ]; then
710
+        mkdir "$prefix/etc/openvpn/easy-rsa/keys"
703 711
     fi
704 712
 
705 713
     # keys configuration
706
-    sed -i "s|export KEY_COUNTRY.*|export KEY_COUNTRY=\"US\"|g" $prefix/etc/openvpn/easy-rsa/vars
707
-    sed -i "s|export KEY_PROVINCE.*|export KEY_PROVINCE=\"TX\"|g" $prefix/etc/openvpn/easy-rsa/vars
708
-    sed -i "s|export KEY_CITY.*|export KEY_CITY=\"Dallas\"|g" $prefix/etc/openvpn/easy-rsa/vars
709
-    sed -i "s|export KEY_ORG.*|export KEY_ORG=\"$PROJECT_NAME\"|g" $prefix/etc/openvpn/easy-rsa/vars
710
-    sed -i "s|export KEY_EMAIL.*|export KEY_EMAIL=\"$MY_EMAIL_ADDRESS\"|g" $prefix/etc/openvpn/easy-rsa/vars
711
-    sed -i "s|export KEY_OU=.*|export KEY_OU=\"MoonUnit\"|g" $prefix/etc/openvpn/easy-rsa/vars
712
-    sed -i "s|export KEY_NAME.*|export KEY_NAME=\"$OPENVPN_SERVER_NAME\"|g" $prefix/etc/openvpn/easy-rsa/vars
713
-
714
-    if [ ! $prefix ]; then
714
+    sed -i "s|export KEY_COUNTRY.*|export KEY_COUNTRY=\"US\"|g" "$prefix/etc/openvpn/easy-rsa/vars"
715
+    sed -i "s|export KEY_PROVINCE.*|export KEY_PROVINCE=\"TX\"|g" "$prefix/etc/openvpn/easy-rsa/vars"
716
+    sed -i "s|export KEY_CITY.*|export KEY_CITY=\"Dallas\"|g" "$prefix/etc/openvpn/easy-rsa/vars"
717
+    sed -i "s|export KEY_ORG.*|export KEY_ORG=\"$PROJECT_NAME\"|g" "$prefix/etc/openvpn/easy-rsa/vars"
718
+    sed -i "s|export KEY_EMAIL.*|export KEY_EMAIL=\"$MY_EMAIL_ADDRESS\"|g" "$prefix/etc/openvpn/easy-rsa/vars"
719
+    sed -i "s|export KEY_OU=.*|export KEY_OU=\"MoonUnit\"|g" "$prefix/etc/openvpn/easy-rsa/vars"
720
+    sed -i "s|export KEY_NAME.*|export KEY_NAME=\"$OPENVPN_SERVER_NAME\"|g" "$prefix/etc/openvpn/easy-rsa/vars"
721
+
722
+    if [ ! "$prefix" ]; then
715 723
         vpn_generate_keys
716 724
         firewall_enable_vpn
717 725
 
@@ -724,7 +732,7 @@ function install_vpn {
724 732
 
725 733
     install_stunnel
726 734
 
727
-    if [ ! $prefix ]; then
735
+    if [ ! "$prefix" ]; then
728 736
         systemctl restart openvpn
729 737
     fi
730 738