Bob Mottram 7 年之前
父節點
當前提交
7888f7ae63
共有 6 個文件被更改,包括 818 次插入789 次删除
  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 查看文件

66
 
66
 
67
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
67
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
68
     if [ ! -f $SYNCTHING_CONFIG_FILE ]; then
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
     fi
75
     fi
76
 }
76
 }
77
 
77
 
94
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
94
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
95
     dialog --title $"Device ID for ${PROJECT_NAME}" \
95
     dialog --title $"Device ID for ${PROJECT_NAME}" \
96
            --backtitle $"Freedombone User Control Panel" \
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
     clear
98
     clear
99
     echo $'Your Syncthing ID code'
99
     echo $'Your Syncthing ID code'
100
     echo ''
100
     echo ''
101
     echo -n "$SYNCTHING_ID" | qrencode -t UTF8
101
     echo -n "$SYNCTHING_ID" | qrencode -t UTF8
102
     echo ''
102
     echo ''
103
+    # shellcheck disable=SC2034
103
     read -n1 -rsp $"Press any key to continue..." key
104
     read -n1 -rsp $"Press any key to continue..." key
104
 }
105
 }
105
 
106
 
110
 
111
 
111
     syncthing_create_ids_file
112
     syncthing_create_ids_file
112
 
113
 
113
-    data=$(tempfile 2>/dev/null)
114
+    data=$(mktemp 2>/dev/null)
114
     trap "rm -f $data" 0 1 2 5 15
115
     trap "rm -f $data" 0 1 2 5 15
115
     dialog --backtitle $"Freedombone User Control Panel" \
116
     dialog --backtitle $"Freedombone User Control Panel" \
116
            --title $"Add a Syncthing device ID" \
117
            --title $"Add a Syncthing device ID" \
117
            --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \
118
            --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \
118
            $"Device ID:" 1 1 "" 1 26 80 80 \
119
            $"Device ID:" 1 1 "" 1 26 80 80 \
119
            $"Description (optional):" 2 1 "" 2 26 80 80 \
120
            $"Description (optional):" 2 1 "" 2 26 80 80 \
120
-           2> $data
121
+           2> "$data"
121
     sel=$?
122
     sel=$?
122
     case $sel in
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
     esac
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
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
133
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
130
         return
134
         return
164
 
168
 
165
     syncthing_create_ids_file
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
     dialog --backtitle $"Freedombone User Control Panel" \
172
     dialog --backtitle $"Freedombone User Control Panel" \
170
            --title $"Remove a Syncthing device ID" \
173
            --title $"Remove a Syncthing device ID" \
171
            --form $"Paste the device ID which is to be removed below" 8 80 1 \
174
            --form $"Paste the device ID which is to be removed below" 8 80 1 \
172
            $"Device ID:" 1 1 "" 1 14 80 80 \
175
            $"Device ID:" 1 1 "" 1 14 80 80 \
173
-           2> $data
176
+           2> "$data"
174
     sel=$?
177
     sel=$?
175
     case $sel in
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
     esac
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
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
187
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
182
         return
188
         return
212
 
218
 
213
     while true
219
     while true
214
     do
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
         dialog --backtitle $"Freedombone User Control Panel" \
222
         dialog --backtitle $"Freedombone User Control Panel" \
218
                --title $"File Synchronization" \
223
                --title $"File Synchronization" \
219
                --radiolist $"Choose an operation:" 12 70 6 \
224
                --radiolist $"Choose an operation:" 12 70 6 \
221
                2 $"Add an ID for another machine or device" off \
226
                2 $"Add an ID for another machine or device" off \
222
                3 $"Remove an ID for another machine or device" off \
227
                3 $"Remove an ID for another machine or device" off \
223
                4 $"Manually edit device IDs" off \
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
         sel=$?
230
         sel=$?
226
         case $sel in
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
         esac
236
         esac
230
-        case $(cat $data) in
237
+        case $(cat "$data") in
231
             1) syncthing_show_id;;
238
             1) syncthing_show_id;;
232
             2) syncthing_add_id;;
239
             2) syncthing_add_id;;
233
             3) syncthing_remove_id;;
240
             3) syncthing_remove_id;;
234
             4) syncthing_manual_edit;;
241
             4) syncthing_manual_edit;;
235
-            5) break;;
242
+            5) rm -f "$data"
243
+               break;;
236
         esac
244
         esac
245
+        rm -f "$data"
237
     done
246
     done
238
 }
247
 }
239
 
248
 
260
     for d in /home/*/ ; do
269
     for d in /home/*/ ; do
261
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
270
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
262
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
271
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
263
-            if [ -d /home/$USERNAME/Sync ]; then
272
+            if [ -d "/home/$USERNAME/Sync" ]; then
264
                 echo $"Backing up syncthing files for $USERNAME"
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
                 # ensure that device IDs will be backed up as part of user config settings
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
                 fi
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
                 fi
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
                 fi
287
                 fi
279
             fi
288
             fi
280
         fi
289
         fi
288
     fi
297
     fi
289
 
298
 
290
     temp_restore_dir=/root/tempsyncthing
299
     temp_restore_dir=/root/tempsyncthing
291
-    if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
300
+    if [ -d "$USB_MOUNT/backup/syncthingconfig" ]; then
292
         echo $"Restoring syncthing configuration"
301
         echo $"Restoring syncthing configuration"
293
         function_check restore_directory_from_usb
302
         function_check restore_directory_from_usb
294
         restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
303
         restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
297
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
306
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
298
             mkdir -p $SYNCTHING_CONFIG_PATH
307
             mkdir -p $SYNCTHING_CONFIG_PATH
299
         fi
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
             set_user_permissions
310
             set_user_permissions
304
             backup_unmount_drive
311
             backup_unmount_drive
305
             systemctl start syncthing
312
             systemctl start syncthing
309
         rm -rf ${temp_restore_dir}config
316
         rm -rf ${temp_restore_dir}config
310
     fi
317
     fi
311
 
318
 
312
-    if [ -d $USB_MOUNT/backup/syncthingshared ]; then
319
+    if [ -d "$USB_MOUNT/backup/syncthingshared" ]; then
313
         echo $"Restoring syncthing shared files"
320
         echo $"Restoring syncthing shared files"
314
         restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
321
         restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
315
         #cp -r ${temp_restore_dir}shared/* /
322
         #cp -r ${temp_restore_dir}shared/* /
321
         rm -rf ${temp_restore_dir}shared
328
         rm -rf ${temp_restore_dir}shared
322
     fi
329
     fi
323
 
330
 
324
-    if [ -d $USB_MOUNT/backup/syncthing ]; then
331
+    if [ -d "$USB_MOUNT/backup/syncthing" ]; then
325
         for d in $USB_MOUNT/backup/syncthing/*/ ; do
332
         for d in $USB_MOUNT/backup/syncthing/*/ ; do
326
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
333
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
327
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
337
                 fi
331
                 echo $"Restoring syncthing files for $USERNAME"
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
                 else
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
                     fi
345
                     fi
339
                     if [ -d /root/Sync ]; then
346
                     if [ -d /root/Sync ]; then
340
-                        cp -r /root/Sync/* /home/$USERNAME/Sync/
347
+                        cp -r /root/Sync/* "/home/$USERNAME/Sync/"
341
                         rm -rf /root/Sync
348
                         rm -rf /root/Sync
342
                     else
349
                     else
343
-                        cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
350
+                        cp -r "${temp_restore_dir}/*" "/home/$USERNAME/Sync/"
344
                     fi
351
                     fi
345
                 fi
352
                 fi
353
+                # shellcheck disable=SC2181
346
                 if [ ! "$?" = "0" ]; then
354
                 if [ ! "$?" = "0" ]; then
347
                     rm -rf ${temp_restore_dir}
355
                     rm -rf ${temp_restore_dir}
348
                     set_user_permissions
356
                     set_user_permissions
354
                 rm -rf ${temp_restore_dir}
362
                 rm -rf ${temp_restore_dir}
355
 
363
 
356
                 # restore device IDs from config settings
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
                 fi
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
                 fi
372
                 fi
365
             fi
373
             fi
366
         done
374
         done
389
     for d in /home/*/ ; do
397
     for d in /home/*/ ; do
390
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
398
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
391
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
399
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
392
-            if [ -d /home/$USERNAME/Sync ]; then
400
+            if [ -d "/home/$USERNAME/Sync" ]; then
393
                 echo $"Backing up syncthing files for $USERNAME"
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
                 # ensure that device IDs will be backed up as part of user config settings
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
                 fi
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
                 fi
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
                 fi
415
                 fi
408
             fi
416
             fi
409
         fi
417
         fi
416
         systemctl stop cron
424
         systemctl stop cron
417
     fi
425
     fi
418
 
426
 
419
-    if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
427
+    if [ -d "$SERVER_DIRECTORY/backup/syncthingconfig" ]; then
420
         echo $"Restoring syncthing configuration"
428
         echo $"Restoring syncthing configuration"
421
         temp_restore_dir=/root/tempsyncthingconfig
429
         temp_restore_dir=/root/tempsyncthingconfig
422
         function_check restore_directory_from_friend
430
         function_check restore_directory_from_friend
425
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
433
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
426
             mkdir -p $SYNCTHING_CONFIG_PATH
434
             mkdir -p $SYNCTHING_CONFIG_PATH
427
         fi
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
             systemctl start syncthing
437
             systemctl start syncthing
431
             systemctl start cron
438
             systemctl start cron
432
             exit 6833
439
             exit 6833
434
         rm -rf $temp_restore_dir
441
         rm -rf $temp_restore_dir
435
     fi
442
     fi
436
 
443
 
437
-    if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
444
+    if [ -d "$SERVER_DIRECTORY/backup/syncthingshared" ]; then
438
         echo $"Restoring syncthing shared files"
445
         echo $"Restoring syncthing shared files"
439
         temp_restore_dir=/root/tempsyncthingshared
446
         temp_restore_dir=/root/tempsyncthingshared
440
         function_check restore_directory_from_friend
447
         function_check restore_directory_from_friend
446
         rm -rf ${temp_restore_dir}
453
         rm -rf ${temp_restore_dir}
447
     fi
454
     fi
448
 
455
 
449
-    if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
456
+    if [ -d "$SERVER_DIRECTORY/backup/syncthing" ]; then
450
         for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
457
         for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
451
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
458
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
452
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
462
                 fi
456
                 echo $"Restoring syncthing files for $USERNAME"
463
                 echo $"Restoring syncthing files for $USERNAME"
457
                 temp_restore_dir=/root/tempsyncthing
464
                 temp_restore_dir=/root/tempsyncthing
458
                 function_check restore_directory_from_friend
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
                 else
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
                     fi
472
                     fi
466
                     if [ -d /root/Sync ]; then
473
                     if [ -d /root/Sync ]; then
467
-                        cp -r /root/Sync/* /home/$USERNAME/Sync/
474
+                        cp -r /root/Sync/* "/home/$USERNAME/Sync/"
468
                         rm -rf /root/Sync
475
                         rm -rf /root/Sync
469
                     else
476
                     else
470
-                        cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
477
+                        cp -r "${temp_restore_dir}/*" "/home/$USERNAME/Sync/"
471
                     fi
478
                     fi
472
                 fi
479
                 fi
480
+                # shellcheck disable=SC2181
473
                 if [ ! "$?" = "0" ]; then
481
                 if [ ! "$?" = "0" ]; then
474
                     rm -rf $temp_restore_dir
482
                     rm -rf $temp_restore_dir
475
                     systemctl start syncthing
483
                     systemctl start syncthing
479
                 rm -rf $temp_restore_dir
487
                 rm -rf $temp_restore_dir
480
 
488
 
481
                 # restore device IDs from config settings
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
                 fi
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
                 fi
497
                 fi
490
                 echo $"Restore of syncthing files for $USERNAME complete"
498
                 echo $"Restore of syncthing files for $USERNAME complete"
491
             fi
499
             fi

+ 163
- 156
src/freedombone-app-tahoelafs 查看文件

72
 
72
 
73
     new_username="$1"
73
     new_username="$1"
74
     new_user_password="$2"
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
     if grep -q "${new_username}:" /etc/nginx/.htpasswd-tahoelafs; then
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
     fi
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
     echo '0'
80
     echo '0'
81
 }
81
 }
82
 
82
 
83
 function remove_user_tahoelafs {
83
 function remove_user_tahoelafs {
84
     remove_username="$1"
84
     remove_username="$1"
85
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp tahoelafs
85
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp tahoelafs
86
     if grep -q "${remove_username}:" /etc/nginx/.htpasswd-tahoelafs; then
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
     fi
88
     fi
89
 }
89
 }
90
 
90
 
91
 function change_password_tahoelafs {
91
 function change_password_tahoelafs {
92
     change_username="$1"
92
     change_username="$1"
93
     change_password="$2"
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
     if grep -q "${change_username}:" /etc/nginx/.htpasswd-tahoelafs; then
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
     fi
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
 function add_tahoelafs_storage_node_interactive {
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
     dialog --backtitle $"Freedombone Configuration" \
103
     dialog --backtitle $"Freedombone Configuration" \
105
            --title $"Add Tahoe-LAFS storage node" \
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
            $"Hostname:" 1 1 "" 1 14 53 40 \
106
            $"Hostname:" 1 1 "" 1 14 53 40 \
108
            $"Public Key:" 2 1 "" 2 14 53 255 \
107
            $"Public Key:" 2 1 "" 2 14 53 255 \
109
            $"Nickname:" 3 1 "" 3 14 53 255 \
108
            $"Nickname:" 3 1 "" 3 14 53 255 \
110
            $"FURL:" 4 1 "" 4 14 53 255 \
109
            $"FURL:" 4 1 "" 4 14 53 255 \
111
-           2> $data
110
+           2> "$data"
112
     sel=$?
111
     sel=$?
113
     case $sel in
112
     case $sel in
114
         1) return;;
113
         1) return;;
115
         255) return;;
114
         255) return;;
116
     esac
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
     if [ ${#public_key} -eq 0 ]; then
122
     if [ ${#public_key} -eq 0 ]; then
123
         return
123
         return
142
     read_config_param TAHOELAFS_SHARES_HAPPY
142
     read_config_param TAHOELAFS_SHARES_HAPPY
143
     read_config_param TAHOELAFS_SHARES_TOTAL
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
     dialog --backtitle $"Freedombone Configuration" \
146
     dialog --backtitle $"Freedombone Configuration" \
148
            --title $"Tahoe-LAFS shares" \
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
            $"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
149
            $"Needed:" 1 1 "${TAHOELAFS_SHARES_NEEDED}" 1 14 4 4 \
151
            $"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
150
            $"Happy:" 2 1 "${TAHOELAFS_SHARES_HAPPY}" 2 14 4 4 \
152
            $"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
151
            $"Total:" 3 1 "${TAHOELAFS_SHARES_TOTAL}" 3 14 4 4 \
153
-           2> $data
152
+           2> "$data"
154
     sel=$?
153
     sel=$?
155
     case $sel in
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
     esac
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
     if [ ${#tl_needed} -gt 0 ]; then
165
     if [ ${#tl_needed} -gt 0 ]; then
163
         TAHOELAFS_SHARES_NEEDED=${tl_needed}
166
         TAHOELAFS_SHARES_NEEDED=${tl_needed}
164
     fi
167
     fi
185
 }
188
 }
186
 
189
 
187
 function configure_interactive_tahoelafs {
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
     dialog --backtitle $"Freedombone Configuration" \
192
     dialog --backtitle $"Freedombone Configuration" \
191
            --title $"Tahoe-LAFS" \
193
            --title $"Tahoe-LAFS" \
192
            --radiolist $"The least authority is always the best" 11 50 5 \
194
            --radiolist $"The least authority is always the best" 11 50 5 \
193
            1 "Add a storage node" off \
195
            1 "Add a storage node" off \
194
            2 "Manually edit storage nodes" off \
196
            2 "Manually edit storage nodes" off \
195
            3 "Shares settings" off \
197
            3 "Shares settings" off \
196
-           4 "Back to main menu" on 2> $data
198
+           4 "Back to main menu" on 2> "$data"
197
     sel=$?
199
     sel=$?
198
     case $sel in
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
     esac
205
     esac
202
-    case $(cat $data) in
206
+    case $(cat "$data") in
203
         1) add_tahoelafs_storage_node_interactive;;
207
         1) add_tahoelafs_storage_node_interactive;;
204
         2) edit_tahoelafs_nodes;;
208
         2) edit_tahoelafs_nodes;;
205
         3) edit_tahoelafs_shares;;
209
         3) edit_tahoelafs_shares;;
206
     esac
210
     esac
211
+    rm -f "$data"
207
 }
212
 }
208
 
213
 
209
 function tahoelafs_setup_client_config {
214
 function tahoelafs_setup_client_config {
210
-    config_file=$1
215
+    config_file="$1"
211
     nick="$2"
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
 function tahoelafs_setup_storage_config {
243
 function tahoelafs_setup_storage_config {
239
-    config_file=$1
244
+    config_file="$1"
240
     nick="$2"
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
     chown -R tahoelafs:debian-tor $TAHOE_DIR
276
     chown -R tahoelafs:debian-tor $TAHOE_DIR
272
 }
277
 }
304
     else
309
     else
305
         cp -r $temp_restore_dir/* $TAHOE_DIR/
310
         cp -r $temp_restore_dir/* $TAHOE_DIR/
306
     fi
311
     fi
312
+    # shellcheck disable=SC2181
307
     if [ ! "$?" = "0" ]; then
313
     if [ ! "$?" = "0" ]; then
308
         if [ -d ${TAHOE_DIR}-old ]; then
314
         if [ -d ${TAHOE_DIR}-old ]; then
309
             mv ${TAHOE_DIR}-old $TAHOE_DIR
315
             mv ${TAHOE_DIR}-old $TAHOE_DIR
346
     else
352
     else
347
         cp -r $temp_restore_dir/* $TAHOE_DIR/
353
         cp -r $temp_restore_dir/* $TAHOE_DIR/
348
     fi
354
     fi
355
+    # shellcheck disable=SC2181
349
     if [ ! "$?" = "0" ]; then
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
         fi
359
         fi
353
         exit 623925
360
         exit 623925
354
     fi
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
     fi
364
     fi
358
     rm -rf $temp_restore_dir
365
     rm -rf $temp_restore_dir
359
     chown -R tahoelafs:debian-tor $TAHOE_DIR
366
     chown -R tahoelafs:debian-tor $TAHOE_DIR
398
     remove_completion_param install_tahoelafs
405
     remove_completion_param install_tahoelafs
399
     function_check remove_onion_service
406
     function_check remove_onion_service
400
     remove_onion_service tahoelafs ${TAHOELAFS_ONION_PORT}
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
     sed -i '/HidServAuth /d' /etc/tor/torrc
409
     sed -i '/HidServAuth /d' /etc/tor/torrc
403
 
410
 
404
     groupdel -f tahoelafs
411
     groupdel -f tahoelafs
437
         exit 682362
444
         exit 682362
438
     fi
445
     fi
439
 
446
 
440
-    if [ ! -f ${node_dir}/tahoe.cfg ]; then
447
+    if [ ! -f "${node_dir}/tahoe.cfg" ]; then
441
         su -c "mkdir ${node_dir}" - tahoelafs
448
         su -c "mkdir ${node_dir}" - tahoelafs
442
         su -c "$TAHOE_COMMAND create-node -C ${node_dir} --hostname=fixme" - tahoelafs
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
     fi
451
     fi
445
 
452
 
446
-    if [ ! -f ${client_dir}/tahoe.cfg ]; then
453
+    if [ ! -f "${client_dir}/tahoe.cfg" ]; then
447
         su -c "mkdir ${client_dir}" - tahoelafs
454
         su -c "mkdir ${client_dir}" - tahoelafs
448
         su -c "$TAHOE_COMMAND create-client -C ${client_dir}" - tahoelafs
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
     fi
457
     fi
451
 }
458
 }
452
 
459
 
453
 function create_tahoelafs_introducer {
460
 function create_tahoelafs_introducer {
454
     introducer_dir="$1"
461
     introducer_dir="$1"
455
 
462
 
456
-    if [ -f ${introducer_dir}/tahoe.cfg ]; then
463
+    if [ -f "${introducer_dir}/tahoe.cfg" ]; then
457
         return
464
         return
458
     fi
465
     fi
459
 
466
 
470
         return
477
         return
471
     fi
478
     fi
472
 
479
 
473
-    if [ -f ${node_dir}/tahoe.cfg ]; then
480
+    if [ -f "${node_dir}/tahoe.cfg" ]; then
474
         return
481
         return
475
     fi
482
     fi
476
 
483
 
487
         return
494
         return
488
     fi
495
     fi
489
 
496
 
490
-    if [ -f ${client_dir}/tahoe.cfg ]; then
497
+    if [ -f "${client_dir}/tahoe.cfg" ]; then
491
         return
498
         return
492
     fi
499
     fi
493
 
500
 
494
     su -c "mkdir ${client_dir}" - tahoelafs
501
     su -c "mkdir ${client_dir}" - tahoelafs
495
     su -c "$TAHOE_COMMAND create-client -C ${client_dir} --introducer=\"$furl\" --listen=tor --hide-ip --hostname=127.0.0.1" - tahoelafs
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
 function get_tahoelafs_furl {
508
 function get_tahoelafs_furl {
510
 }
517
 }
511
 
518
 
512
 function get_tahoelafs_storage_hostname {
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
 function get_tahoelafs_public_key {
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
 function add_tahoelafs_server {
527
 function add_tahoelafs_server {
549
         fi
556
         fi
550
         echo '# storage' >> ${tahoelafs_storage_file}
557
         echo '# storage' >> ${tahoelafs_storage_file}
551
     fi
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
     chown tahoelafs:debian-tor ${tahoelafs_storage_file}
563
     chown tahoelafs:debian-tor ${tahoelafs_storage_file}
557
 
564
 
558
     if ! grep -q "HidServAuth ${storage_hostname}" /etc/tor/torrc; then
565
     if ! grep -q "HidServAuth ${storage_hostname}" /etc/tor/torrc; then
566
     TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
573
     TAHOELAFS_DAEMON_FILE=/etc/systemd/system/tahoelafs-${daemon_name}.service
567
     echo "Creating daemon: $TAHOELAFS_DAEMON_FILE"
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
     systemctl daemon-reload
595
     systemctl daemon-reload
589
-    systemctl start tahoelafs-${daemon_name}
596
+    systemctl start "tahoelafs-${daemon_name}"
590
 }
597
 }
591
 
598
 
592
 function create_tahoelafs_web {
599
 function create_tahoelafs_web {
596
     TAHOELAFS_LOGIN_TEXT=$'Tahoe-LAFS login'
603
     TAHOELAFS_LOGIN_TEXT=$'Tahoe-LAFS login'
597
 
604
 
598
     tahoelafs_nginx_site=/etc/nginx/sites-available/tahoelafs
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
     function_check nginx_disable_sniffing
610
     function_check nginx_disable_sniffing
604
     nginx_disable_sniffing tahoelafs
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
     function_check nginx_limits
623
     function_check nginx_limits
617
     nginx_limits tahoelafs '15m'
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
     if [ ! -f /etc/nginx/.htpasswd-tahoelafs ]; then
637
     if [ ! -f /etc/nginx/.htpasswd-tahoelafs ]; then
631
         touch /etc/nginx/.htpasswd-tahoelafs
638
         touch /etc/nginx/.htpasswd-tahoelafs
632
     fi
639
     fi
633
     if grep -q "${MY_USERNAME}:" /etc/nginx/.htpasswd-tahoelafs; then
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
     fi
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
     function_check nginx_ensite
645
     function_check nginx_ensite
639
     nginx_ensite tahoelafs
646
     nginx_ensite tahoelafs
641
 }
648
 }
642
 
649
 
643
 function install_tahoelafs {
650
 function install_tahoelafs {
644
-    if [ $INSTALLING_MESH ]; then
651
+    if [ "$INSTALLING_MESH" ]; then
645
         return
652
         return
646
     fi
653
     fi
647
 
654
 
692
     # create an onion address for client node
699
     # create an onion address for client node
693
     TAHOELAFS_ONION_HOSTNAME=$(add_onion_service tahoelafs 80 ${TAHOELAFS_ONION_PORT})
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
     # start the storage node
704
     # start the storage node
698
     su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs
705
     su -c "/usr/bin/python2 /usr/bin/tahoe start $TAHOE_DIR/storage" - tahoelafs

+ 197
- 201
src/freedombone-app-tox 查看文件

74
 function remove_user_tox {
74
 function remove_user_tox {
75
     remove_username="$1"
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
         fi
81
         fi
82
-        shred -zu /home/$remove_username/.config/tox/*
82
+        shred -zu "/home/$remove_username/.config/tox/*"
83
     fi
83
     fi
84
 }
84
 }
85
 
85
 
87
     new_username="$1"
87
     new_username="$1"
88
 
88
 
89
     # Note: password isn't used
89
     # Note: password isn't used
90
-    new_user_password="$2"
90
+    #new_user_password="$2"
91
 
91
 
92
     USER_TOX_FILE=/home/${new_username}/.config/tox/data.tox
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
     fi
98
     fi
99
 }
99
 }
100
 
100
 
101
 function run_client_tox {
101
 function run_client_tox {
102
     # create a tox user
102
     # create a tox user
103
     USER_TOX_FILE=/home/${USER}/.config/tox/data.tox
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
     fi
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
 function install_interactive_tox {
113
 function install_interactive_tox {
121
     fi
121
     fi
122
     bootstrap_id=$(cat $TOX_BOOTSTRAP_ID_FILE)
122
     bootstrap_id=$(cat $TOX_BOOTSTRAP_ID_FILE)
123
     dialog --title $"Tox Bootstrap Node ID" \
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
 function mesh_tox_qtox {
127
 function mesh_tox_qtox {
128
-    if [ ! ${rootdir}$INSTALL_DIR ]; then
128
+    # shellcheck disable=SC2154
129
+    if [ ! "${rootdir}$INSTALL_DIR" ]; then
129
         INSTALL_DIR=${rootdir}/root/build
130
         INSTALL_DIR=${rootdir}/root/build
130
     fi
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
     fi
135
     fi
135
 
136
 
136
     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
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
     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
     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
     if [ -d /repos/qtox ]; then
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
         git pull
156
         git pull
156
     else
157
     else
157
-        git clone $QTOX_REPO ${rootdir}$INSTALL_DIR/qtox
158
+        git clone "$QTOX_REPO" "${rootdir}$INSTALL_DIR/qtox"
158
     fi
159
     fi
159
 
160
 
160
-    if [ ! -d ${rootdir}$INSTALL_DIR/qtox ]; then
161
+    if [ ! -d "${rootdir}$INSTALL_DIR/qtox" ]; then
161
         exit 72428
162
         exit 72428
162
     fi
163
     fi
163
-    cd ${rootdir}${INSTALL_DIR}/qtox
164
+    cd "${rootdir}${INSTALL_DIR}/qtox" || exit 235745728
164
     git checkout $QTOX_COMMIT -b $QTOX_COMMIT
165
     git checkout $QTOX_COMMIT -b $QTOX_COMMIT
165
-    chroot ${rootdir} /bin/bash -x <<EOF
166
+    chroot "${rootdir}" /bin/bash -x <<EOF
166
 cd ${INSTALL_DIR}/qtox
167
 cd ${INSTALL_DIR}/qtox
167
 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
168
 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig"
168
 cmake .
169
 cmake .
169
 make
170
 make
170
 make install
171
 make install
171
 EOF
172
 EOF
172
-    if [ ! -f ${rootdir}/usr/local/bin/qtox ]; then
173
+    if [ ! -f "${rootdir}/usr/local/bin/qtox" ]; then
173
         exit 75784
174
         exit 75784
174
     fi
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
 function reconfigure_tox {
179
 function reconfigure_tox {
181
 
182
 
182
 function upgrade_tox {
183
 function upgrade_tox {
183
     function_check set_repo_commit
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
         sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
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
         autoreconf -i
189
         autoreconf -i
189
         ./configure --enable-daemon
190
         ./configure --enable-daemon
194
     fi
195
     fi
195
 
196
 
196
     function_check set_repo_commit
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
         make
201
         make
201
         make install
202
         make install
202
     fi
203
     fi
221
 }
222
 }
222
 
223
 
223
 function restore_local_tox {
224
 function restore_local_tox {
224
-    if [ -d $USB_MOUNT/backup/tox ]; then
225
+    if [ -d "$USB_MOUNT/backup/tox" ]; then
225
         echo $"Restoring Tox node settings"
226
         echo $"Restoring Tox node settings"
226
         function_check restore_directory_from_usb
227
         function_check restore_directory_from_usb
227
         #restore_directory_from_usb / tox
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
             function_check set_user_permissions
230
             function_check set_user_permissions
231
             set_user_permissions
231
             set_user_permissions
232
             function_check backup_unmount_drive
232
             function_check backup_unmount_drive
234
             exit 6393
234
             exit 6393
235
         fi
235
         fi
236
         cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
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
             systemctl status tox-bootstrapd.service
238
             systemctl status tox-bootstrapd.service
240
             function_check set_user_permissions
239
             function_check set_user_permissions
241
             set_user_permissions
240
             set_user_permissions
259
 }
258
 }
260
 
259
 
261
 function restore_remote_tox {
260
 function restore_remote_tox {
262
-    if [ -d $SERVER_DIRECTORY/backup/tox ]; then
261
+    if [ -d "$SERVER_DIRECTORY/backup/tox" ]; then
263
         echo $"Restoring Tox node settings"
262
         echo $"Restoring Tox node settings"
264
         function_check restore_directory_from_friend
263
         function_check restore_directory_from_friend
265
         #restore_directory_from_friend / tox
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
             exit 93653
266
             exit 93653
269
         fi
267
         fi
270
         cp /var/lib/tox-bootstrapd/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
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
             systemctl status tox-bootstrapd.service
270
             systemctl status tox-bootstrapd.service
274
             exit 59369
271
             exit 59369
275
         fi
272
         fi
283
     function_check remove_onion_service
280
     function_check remove_onion_service
284
     remove_onion_service tox ${TOX_PORT}
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
         echo $'Failed to remove tox node'
284
         echo $'Failed to remove tox node'
289
         exit 763836
285
         exit 763836
290
     fi
286
     fi
293
 }
289
 }
294
 
290
 
295
 function remove_tox_avahi {
291
 function remove_tox_avahi {
296
-    cd $INSTALL_DIR/toxid
292
+    cd "$INSTALL_DIR/toxid" || exit 82456275
297
     make uninstall
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
 function remove_tox_client {
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
         echo $'Could not remove Tox client'
300
         echo $'Could not remove Tox client'
306
         exit 737253
301
         exit 737253
307
     fi
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
 function remove_tox {
308
 function remove_tox {
317
 }
312
 }
318
 
313
 
319
 function configure_firewall_for_tox {
314
 function configure_firewall_for_tox {
320
-    if [ ! $INSTALLING_MESH ]; then
315
+    if [ ! "$INSTALLING_MESH" ]; then
321
         if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
316
         if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
322
             return
317
             return
323
         fi
318
         fi
331
         return
326
         return
332
     fi
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
     if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
330
     if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
336
         TOX_PORT=$TOX_PORT_MAIN
331
         TOX_PORT=$TOX_PORT_MAIN
337
     fi
332
     fi
338
-    if [ ! $TOX_PORT ]; then
333
+    if [ ! "$TOX_PORT" ]; then
339
         echo $'No Tox port was specified'
334
         echo $'No Tox port was specified'
340
         exit 32856
335
         exit 32856
341
     fi
336
     fi
342
 
337
 
343
-    firewall_add Tox ${TOX_PORT}
338
+    firewall_add Tox "${TOX_PORT}"
344
     mark_completed "${FUNCNAME[0]}"
339
     mark_completed "${FUNCNAME[0]}"
345
 }
340
 }
346
 
341
 
355
     fi
350
     fi
356
 
351
 
357
     # install a command to obtain the Tox ID
352
     # install a command to obtain the Tox ID
358
-    cd $INSTALL_DIR
353
+    cd "$INSTALL_DIR" || exit 131497953
359
 
354
 
360
     if [ -d /repos/toxid ]; then
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
         git pull
359
         git pull
365
     else
360
     else
366
         function_check git_clone
361
         function_check git_clone
367
-        git_clone $TOXID_REPO $INSTALL_DIR/toxid
362
+        git_clone "$TOXID_REPO" "$INSTALL_DIR/toxid"
368
     fi
363
     fi
369
 
364
 
370
-    if [ ! -d $INSTALL_DIR/toxid ]; then
365
+    if [ ! -d "$INSTALL_DIR/toxid" ]; then
371
         exit 63921
366
         exit 63921
372
     fi
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
         exit 58432
370
         exit 58432
377
     fi
371
     fi
378
     make install
372
     make install
399
     mesh_tox_node
393
     mesh_tox_node
400
 
394
 
401
     # onion address for bootstrapping
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
     systemctl restart tox-bootstrapd.service
398
     systemctl restart tox-bootstrapd.service
405
 
399
 
406
     sleep 3
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
     if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
403
     if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
410
         echo $'Could not obtain the tox node public key'
404
         echo $'Could not obtain the tox node public key'
411
         exit 6529
405
         exit 6529
435
 
429
 
436
 function mesh_tox_node {
430
 function mesh_tox_node {
437
     # obtain commits from the main file
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
     if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
433
     if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then
440
         TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
434
         TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN
441
     fi
435
     fi
442
-    if [ ! $TOXCORE_COMMIT ]; then
436
+    if [ ! "$TOXCORE_COMMIT" ]; then
443
         echo $'No Tox commit was specified'
437
         echo $'No Tox commit was specified'
444
         exit 76325
438
         exit 76325
445
     fi
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
     if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
442
     if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then
449
         TOXID_REPO=$TOXID_REPO_MAIN
443
         TOXID_REPO=$TOXID_REPO_MAIN
450
     fi
444
     fi
451
-    if [ ! $TOXID_REPO ]; then
445
+    if [ ! "$TOXID_REPO" ]; then
452
         echo $'No ToxID repo was specified'
446
         echo $'No ToxID repo was specified'
453
         exit 78252
447
         exit 78252
454
     fi
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
     if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
451
     if [ ${#TOX_PORT_MAIN} -gt 2 ]; then
458
         TOX_PORT=$TOX_PORT_MAIN
452
         TOX_PORT=$TOX_PORT_MAIN
459
     fi
453
     fi
460
-    if [ ! $TOX_PORT ]; then
454
+    if [ ! "$TOX_PORT" ]; then
461
         echo $'No Tox port was specified'
455
         echo $'No Tox port was specified'
462
         exit 32856
456
         exit 32856
463
     fi
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
     if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
460
     if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then
467
         TOXCORE_REPO=$TOXCORE_REPO_MAIN
461
         TOXCORE_REPO=$TOXCORE_REPO_MAIN
468
     fi
462
     fi
469
-    if [ ! $TOXCORE_REPO ]; then
463
+    if [ ! "$TOXCORE_REPO" ]; then
470
         echo $'No Tox repo was specified'
464
         echo $'No Tox repo was specified'
471
         exit 16865
465
         exit 16865
472
     fi
466
     fi
473
 
467
 
474
-    if [ ! $TOXCORE_COMMIT ]; then
468
+    if [ ! "$TOXCORE_COMMIT" ]; then
475
         echo $'No Tox commit was specified'
469
         echo $'No Tox commit was specified'
476
         exit 76325
470
         exit 76325
477
     fi
471
     fi
478
 
472
 
479
-    if [ ! $TOXCORE_REPO ]; then
473
+    if [ ! "$TOXCORE_REPO" ]; then
480
         echo $'No Tox repo was specified'
474
         echo $'No Tox repo was specified'
481
         exit 16865
475
         exit 16865
482
     fi
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
     else
484
     else
491
         apt-get -yq install build-essential libtool autotools-dev
485
         apt-get -yq install build-essential libtool autotools-dev
492
         apt-get -yq install automake checkinstall check git yasm
486
         apt-get -yq install automake checkinstall check git yasm
495
         apt-get -yq install libopus-dev libvpx-dev
489
         apt-get -yq install libopus-dev libvpx-dev
496
     fi
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
     fi
494
     fi
501
-    if [ ! -d ${rootdir}${INSTALL_DIR}/toxcore ]; then
495
+    if [ ! -d "${rootdir}${INSTALL_DIR}/toxcore" ]; then
502
         if [ -d /repos/toxcore ]; then
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
             git pull
500
             git pull
507
         else
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
             fi
504
             fi
512
         fi
505
         fi
513
     fi
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
 cd ${INSTALL_DIR}/toxcore
512
 cd ${INSTALL_DIR}/toxcore
520
 autoreconf -i
513
 autoreconf -i
521
 ./configure --enable-daemon
514
 ./configure --enable-daemon
532
 EOF
525
 EOF
533
     fi
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
     else
533
     else
541
         systemctl enable tox-bootstrapd.service
534
         systemctl enable tox-bootstrapd.service
542
     fi
535
     fi
543
 
536
 
544
     SECONDS=0
537
     SECONDS=0
545
-    if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then
538
+    if [ ! -f "$rootdir/usr/local/bin/tox-bootstrapd" ]; then
546
         duration=$SECONDS
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
         echo $'Unable to make toxcore'
541
         echo $'Unable to make toxcore'
549
         exit 73835
542
         exit 73835
550
     fi
543
     fi
551
     duration=$SECONDS
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
     else
550
     else
558
         chmod 600 /etc/shadow
551
         chmod 600 /etc/shadow
559
         chmod 600 /etc/gshadow
552
         chmod 600 /etc/gshadow
564
     fi
557
     fi
565
 
558
 
566
     # remove Maildir
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
     fi
562
     fi
570
 
563
 
571
     # create configuration file
564
     # create configuration file
572
     TOX_BOOTSTRAP_CONFIG=$rootdir/etc/tox-bootstrapd.conf
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
     if [ $TOX_NODES ]; then
577
     if [ $TOX_NODES ]; then
585
-        echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG
578
+        echo 'bootstrap_nodes = (' >> "$TOX_BOOTSTRAP_CONFIG"
586
         toxcount=0
579
         toxcount=0
587
         while [ "x${TOX_NODES[toxcount]}" != "x" ]
580
         while [ "x${TOX_NODES[toxcount]}" != "x" ]
588
         do
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
             if [[ $toxval_ipv6 != 'NONE' ]]; then
590
             if [[ $toxval_ipv6 != 'NONE' ]]; then
596
-                echo "  address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG
591
+                echo "  address = \"$toxval_ipv6\"" >> "$TOX_BOOTSTRAP_CONFIG"
597
             else
592
             else
598
-                echo "  address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG
593
+                echo "  address = \"$toxval_ipv4\"" >> "$TOX_BOOTSTRAP_CONFIG"
599
             fi
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
             if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
598
             if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
604
-                echo "}," >> $TOX_BOOTSTRAP_CONFIG
599
+                echo "}," >> "$TOX_BOOTSTRAP_CONFIG"
605
             else
600
             else
606
-                echo "}" >> $TOX_BOOTSTRAP_CONFIG
601
+                echo "}" >> "$TOX_BOOTSTRAP_CONFIG"
607
             fi
602
             fi
608
         done
603
         done
609
-        echo ')' >> $TOX_BOOTSTRAP_CONFIG
604
+        echo ')' >> "$TOX_BOOTSTRAP_CONFIG"
610
     fi
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
     fi
609
     fi
615
 }
610
 }
616
 
611
 
617
 function mesh_tox_avahi {
612
 function mesh_tox_avahi {
618
-    if [ ! -d $rootdir/etc/avahi ]; then
613
+    if [ ! -d "$rootdir/etc/avahi" ]; then
619
         echo $'tox_avahi: avahi is not installed'
614
         echo $'tox_avahi: avahi is not installed'
620
         exit 87359
615
         exit 87359
621
     fi
616
     fi
622
 
617
 
623
-    if [ ! $TOXID_REPO ]; then
618
+    if [ ! "$TOXID_REPO" ]; then
624
         echo $'No ToxID repo was specified'
619
         echo $'No ToxID repo was specified'
625
         exit 78252
620
         exit 78252
626
     fi
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
     fi
625
     fi
631
 
626
 
632
     if [ -d /repos/toxid ]; then
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
         git pull
631
         git pull
637
     else
632
     else
638
-        git clone ${TOXID_REPO} ${rootdir}${INSTALL_DIR}/toxid
633
+        git clone "${TOXID_REPO}" "${rootdir}${INSTALL_DIR}/toxid"
639
     fi
634
     fi
640
 
635
 
641
-    if [ ! -d ${rootdir}${INSTALL_DIR}/toxid ]; then
636
+    if [ ! -d "${rootdir}${INSTALL_DIR}/toxid" ]; then
642
         echo $'Unable to clone toxid repo'
637
         echo $'Unable to clone toxid repo'
643
         exit 768352
638
         exit 768352
644
     fi
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
 cd ${INSTALL_DIR}/toxid
643
 cd ${INSTALL_DIR}/toxid
649
 make
644
 make
650
 make install
645
 make install
657
 EOF
652
 EOF
658
     fi
653
     fi
659
 
654
 
660
-    if [ ! -f $rootdir/usr/local/bin/toxid ]; then
655
+    if [ ! -f "$rootdir/usr/local/bin/toxid" ]; then
661
         echo $'toxid not found'
656
         echo $'toxid not found'
662
         exit 74370
657
         exit 74370
663
     fi
658
     fi
664
-    if [ ! -f $rootdir/usr/local/bin/toxavahi ]; then
659
+    if [ ! -f "$rootdir/usr/local/bin/toxavahi" ]; then
665
         exit 3621729
660
         exit 3621729
666
     fi
661
     fi
667
 
662
 
668
     MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
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
     fi
673
     fi
678
 }
674
 }
679
 
675
 
680
 function mesh_tox_client {
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
     # obtain commits from the main file
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
     if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
682
     if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then
687
         TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
683
         TOXIC_COMMIT=$TOXIC_COMMIT_MAIN
688
     fi
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
     if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
687
     if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then
692
         TOXIC_REPO=$TOXIC_REPO_MAIN
688
         TOXIC_REPO=$TOXIC_REPO_MAIN
693
     fi
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
     else
695
     else
700
         apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
696
         apt-get -yq install libncursesw5-dev libconfig-dev libqrencode-dev
701
         apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
697
         apt-get -yq install libcurl4-openssl-dev libvpx-dev libopenal-dev
704
 
700
 
705
     TEMP_SCRIPT_NAME=fbtmp728353.sh
701
     TEMP_SCRIPT_NAME=fbtmp728353.sh
706
     TEMP_SCRIPT=/tmp/$TEMP_SCRIPT_NAME
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
     chmod +x $TEMP_SCRIPT
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
     SECONDS=0
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
     else
729
     else
734
         /root/$TEMP_SCRIPT_NAME
730
         /root/$TEMP_SCRIPT_NAME
735
     fi
731
     fi
732
+    # shellcheck disable=SC2181
736
     if [ ! "$?" = "0" ]; then
733
     if [ ! "$?" = "0" ]; then
737
         cat -n /root/fbtmp728353.sh
734
         cat -n /root/fbtmp728353.sh
738
         duration=$SECONDS
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
         echo $'Unable to make tox client'
737
         echo $'Unable to make tox client'
741
         rm $TEMP_SCRIPT
738
         rm $TEMP_SCRIPT
742
         exit 74872
739
         exit 74872
743
     fi
740
     fi
744
     rm $TEMP_SCRIPT
741
     rm $TEMP_SCRIPT
745
-    if [ ! -f $rootdir$TOXIC_FILE ]; then
742
+    if [ ! -f "$rootdir$TOXIC_FILE" ]; then
746
         echo $"Tox client was not installed to $TOXIC_FILE"
743
         echo $"Tox client was not installed to $TOXIC_FILE"
747
         exit 63278
744
         exit 63278
748
     fi
745
     fi
749
     duration=$SECONDS
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
 function enable_tox_repo {
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
 #!/bin/bash
754
 #!/bin/bash
759
 wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_9.0/Release.key -O- > /root/tox.key
755
 wget -q http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_9.0/Release.key -O- > /root/tox.key
760
 apt-key add /root/tox.key
756
 apt-key add /root/tox.key
769
 function install_tox {
765
 function install_tox {
770
     configure_firewall_for_tox
766
     configure_firewall_for_tox
771
 
767
 
772
-    if [ $INSTALLING_MESH ]; then
768
+    if [ "$INSTALLING_MESH" ]; then
773
         mesh_tox_node
769
         mesh_tox_node
774
         mesh_tox_avahi
770
         mesh_tox_avahi
775
         mesh_tox_client
771
         mesh_tox_client
776
     else
772
     else
777
         avoid_tor_restart=
773
         avoid_tor_restart=
778
-        if [ -f $IMAGE_PASSWORD_FILE ]; then
774
+        if [ -f "$IMAGE_PASSWORD_FILE" ]; then
779
             if [[ $ONION_ONLY != 'no' ]]; then
775
             if [[ $ONION_ONLY != 'no' ]]; then
780
                 avoid_tor_restart=1
776
                 avoid_tor_restart=1
781
             fi
777
             fi
782
         fi
778
         fi
783
 
779
 
784
         if [ $avoid_tor_restart ]; then
780
         if [ $avoid_tor_restart ]; then
785
-            ${PROJECT_NAME}-logging on --onion
781
+            "${PROJECT_NAME}-logging" on --onion
786
         else
782
         else
787
-            ${PROJECT_NAME}-logging on
783
+            "${PROJECT_NAME}-logging" on
788
         fi
784
         fi
789
 
785
 
790
         install_tox_node
786
         install_tox_node
791
 
787
 
792
         if [ $avoid_tor_restart ]; then
788
         if [ $avoid_tor_restart ]; then
793
-            ${PROJECT_NAME}-logging off --onion
789
+            "${PROJECT_NAME}-logging" off --onion
794
         else
790
         else
795
-            ${PROJECT_NAME}-logging off
791
+            "${PROJECT_NAME}-logging" off
796
         fi
792
         fi
797
 
793
 
798
         tox_avahi
794
         tox_avahi

+ 81
- 73
src/freedombone-app-turtl 查看文件

68
 }
68
 }
69
 
69
 
70
 function change_password_turtl {
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
 function remove_user_turtl {
76
 function remove_user_turtl {
76
-    remove_username="$1"
77
+    echo -n ''
78
+#    remove_username="$1"
77
 }
79
 }
78
 
80
 
79
 function add_user_turtl {
81
 function add_user_turtl {
80
-    new_username="$1"
81
-    new_user_password="$2"
82
+#    new_username="$1"
83
+#    new_user_password="$2"
82
     echo '0'
84
     echo '0'
83
 }
85
 }
84
 
86
 
85
 function install_interactive_turtl {
87
 function install_interactive_turtl {
86
-    if [ ! $ONION_ONLY ]; then
88
+    if [ ! "$ONION_ONLY" ]; then
87
         ONION_ONLY='no'
89
         ONION_ONLY='no'
88
     fi
90
     fi
89
 
91
 
128
     dialog --title $"Allow new turtl signups" \
130
     dialog --title $"Allow new turtl signups" \
129
            --backtitle $"Freedombone Control Panel" \
131
            --backtitle $"Freedombone Control Panel" \
130
            --defaultno \
132
            --defaultno \
131
-           --yesno $"\nAllow registration of new users?" 10 60
133
+           --yesno $"\\nAllow registration of new users?" 10 60
132
     sel=$?
134
     sel=$?
133
     case $sel in
135
     case $sel in
134
         0)
136
         0)
146
 }
148
 }
147
 
149
 
148
 function configure_interactive_turtl_storage {
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
     dialog --title $"Change storage limit" \
152
     dialog --title $"Change storage limit" \
152
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
155
     sel=$?
155
     case $sel in
156
     case $sel in
156
         0)
157
         0)
157
-            STORAGE=$(<$data)
158
+            STORAGE=$(<"$data")
158
             if [ ${#STORAGE} -gt 0 ]; then
159
             if [ ${#STORAGE} -gt 0 ]; then
159
                 TURTL_STORAGE_LIMIT_MB=$STORAGE
160
                 TURTL_STORAGE_LIMIT_MB=$STORAGE
160
                 sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* ${TURTL_STORAGE_LIMIT_MB})|g" $TURTL_BASE_DIR/api/config/config.lisp
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
             fi
165
             fi
165
             ;;
166
             ;;
166
     esac
167
     esac
168
+    rm -f "$data"
167
 }
169
 }
168
 
170
 
169
 function configure_interactive_turtl {
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
     dialog --backtitle $"Freedombone Control Panel" \
173
     dialog --backtitle $"Freedombone Control Panel" \
173
            --title $"turtl app settings" \
174
            --title $"turtl app settings" \
174
            --radiolist $"Choose an operation:" 12 70 3 \
175
            --radiolist $"Choose an operation:" 12 70 3 \
175
            1 $"Enable/disable new user registrations" off \
176
            1 $"Enable/disable new user registrations" off \
176
            2 $"Change storage limit" off \
177
            2 $"Change storage limit" off \
177
-           3 $"Exit" on 2> $data
178
+           3 $"Exit" on 2> "$data"
178
     sel=$?
179
     sel=$?
179
     case $sel in
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
     esac
185
     esac
183
-    case $(cat $data) in
186
+    case $(cat "$data") in
184
         1) configure_interactive_turtl_signups;;
187
         1) configure_interactive_turtl_signups;;
185
         2) configure_interactive_turtl_storage;;
188
         2) configure_interactive_turtl_storage;;
186
-        3) return;;
189
+        3) rm -f "$data"
190
+           return;;
187
     esac
191
     esac
192
+    rm -f "$data"
188
 }
193
 }
189
 
194
 
190
 function reconfigure_turtl {
195
 function reconfigure_turtl {
255
         else
260
         else
256
             cp -r ${temp_restore_dir}/* /etc/turtl/
261
             cp -r ${temp_restore_dir}/* /etc/turtl/
257
         fi
262
         fi
258
-
263
+        # shellcheck disable=SC2181
259
         if [ ! "$?" = "0" ]; then
264
         if [ ! "$?" = "0" ]; then
260
             set_user_permissions
265
             set_user_permissions
261
             backup_unmount_drive
266
             backup_unmount_drive
273
             cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
278
             cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
274
         fi
279
         fi
275
 
280
 
281
+        # shellcheck disable=SC2181
276
         if [ ! "$?" = "0" ]; then
282
         if [ ! "$?" = "0" ]; then
277
             set_user_permissions
283
             set_user_permissions
278
             backup_unmount_drive
284
             backup_unmount_drive
318
             cp -r ${temp_restore_dir}/* /etc/turtl/
324
             cp -r ${temp_restore_dir}/* /etc/turtl/
319
         fi
325
         fi
320
 
326
 
327
+        # shellcheck disable=SC2181
321
         if [ ! "$?" = "0" ]; then
328
         if [ ! "$?" = "0" ]; then
322
             if [ -d /etc/turtl_previous ]; then
329
             if [ -d /etc/turtl_previous ]; then
323
                 mv /etc/turtl_previous $TURTL_BASE_DIR
330
                 mv /etc/turtl_previous $TURTL_BASE_DIR
338
             cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
345
             cp -r ${temp_restore_dir}/* /var/lib/rethinkdb/
339
         fi
346
         fi
340
 
347
 
348
+        # shellcheck disable=SC2181
341
         if [ ! "$?" = "0" ]; then
349
         if [ ! "$?" = "0" ]; then
342
             set_user_permissions
350
             set_user_permissions
343
             exit 26783
351
             exit 26783
358
     remove_rethinkdb
366
     remove_rethinkdb
359
     remove_app turtl
367
     remove_app turtl
360
     remove_completion_param install_turtl
368
     remove_completion_param install_turtl
361
-    sed -i '/turtl/d' $COMPLETION_FILE
369
+    sed -i '/turtl/d' "$COMPLETION_FILE"
362
     nginx_dissite $TURTL_DOMAIN_NAME
370
     nginx_dissite $TURTL_DOMAIN_NAME
363
     if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
371
     if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
364
         rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
372
         rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
444
         exit 6238234
452
         exit 6238234
445
     fi
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
     if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
468
     if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
461
         echo "ExecStart=$TURTL_BASE_DIR/ccl/lx86cl64 -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
469
         echo "ExecStart=$TURTL_BASE_DIR/ccl/lx86cl64 -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
466
             echo "ExecStart=$TURTL_BASE_DIR/ccl/armcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
474
             echo "ExecStart=$TURTL_BASE_DIR/ccl/armcl -l $TURTL_BASE_DIR/quicklisp/setup.lisp -l launch.lisp" >> /etc/systemd/system/turtl.service
467
         fi
475
         fi
468
     fi
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
     chmod +x /etc/systemd/system/turtl.service
480
     chmod +x /etc/systemd/system/turtl.service
473
 
481
 
474
     chown -R turtl:turtl $TURTL_BASE_DIR
482
     chown -R turtl:turtl $TURTL_BASE_DIR
484
     if [ ! -d $TURTL_BASE_DIR ]; then
492
     if [ ! -d $TURTL_BASE_DIR ]; then
485
         mkdir -p $TURTL_BASE_DIR
493
         mkdir -p $TURTL_BASE_DIR
486
     fi
494
     fi
487
-    cd $TURTL_BASE_DIR
495
+    cd "$TURTL_BASE_DIR" || exit 745726542
488
     mkdir cd $TURTL_BASE_DIR/data
496
     mkdir cd $TURTL_BASE_DIR/data
489
     check_architecture=$(uname -a)
497
     check_architecture=$(uname -a)
490
 
498
 
600
     chown -R rethinkdb:rethinkdb /var/lib/rethinkdb
608
     chown -R rethinkdb:rethinkdb /var/lib/rethinkdb
601
 
609
 
602
     # install turtl API
610
     # install turtl API
603
-    cd $TURTL_BASE_DIR/
611
+    cd "$TURTL_BASE_DIR/" || exit 6428462
604
 
612
 
605
     if [ -d /repos/turtl ]; then
613
     if [ -d /repos/turtl ]; then
606
         mkdir $TURTL_BASE_DIR/api
614
         mkdir $TURTL_BASE_DIR/api
607
         cp -r -p /repos/turtl/. $TURTL_BASE_DIR/api
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
         git pull
617
         git pull
610
     else
618
     else
611
         git clone $TURTL_REPO $TURTL_BASE_DIR/api
619
         git clone $TURTL_REPO $TURTL_BASE_DIR/api
612
     fi
620
     fi
613
 
621
 
614
-    cd $TURTL_BASE_DIR/api
622
+    cd "$TURTL_BASE_DIR/api" || exit 35814614
615
     git checkout $TURTL_COMMIT -b $TURTL_COMMIT
623
     git checkout $TURTL_COMMIT -b $TURTL_COMMIT
616
     set_completion_param "turtl commit" "$TURTL_COMMIT"
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
     git clone git://github.com/orthecreedence/cl-hash-util
626
     git clone git://github.com/orthecreedence/cl-hash-util
619
     if [[ "$check_architecture" != *"arm"* ]]; then
627
     if [[ "$check_architecture" != *"arm"* ]]; then
620
         if [[ "$check_architecture" == *"64"* ]]; then
628
         if [[ "$check_architecture" == *"64"* ]]; then
657
     if [[ $ONION_ONLY == "no" ]]; then
665
     if [[ $ONION_ONLY == "no" ]]; then
658
         function_check nginx_http_redirect
666
         function_check nginx_http_redirect
659
         nginx_http_redirect $TURTL_DOMAIN_NAME
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
         function_check nginx_ssl
674
         function_check nginx_ssl
667
         nginx_ssl $TURTL_DOMAIN_NAME
675
         nginx_ssl $TURTL_DOMAIN_NAME
668
 
676
 
669
         function_check nginx_disable_sniffing
677
         function_check nginx_disable_sniffing
670
         nginx_disable_sniffing $TURTL_DOMAIN_NAME
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
         function_check nginx_limits
687
         function_check nginx_limits
680
         nginx_limits $TURTL_DOMAIN_NAME '15m'
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
     else
694
     else
687
         echo -n '' > $turtl_nginx_site
695
         echo -n '' > $turtl_nginx_site
688
     fi
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
     function_check nginx_disable_sniffing
701
     function_check nginx_disable_sniffing
694
     nginx_disable_sniffing $TURTL_DOMAIN_NAME
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
     function_check nginx_limits
709
     function_check nginx_limits
702
     nginx_limits $TURTL_DOMAIN_NAME '15m'
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
     function_check add_ddns_domain
717
     function_check add_ddns_domain
710
     add_ddns_domain $TURTL_DOMAIN_NAME
718
     add_ddns_domain $TURTL_DOMAIN_NAME

+ 62
- 60
src/freedombone-app-vim 查看文件

62
             echo $"Backing up Vim config for $USERNAME"
62
             echo $"Backing up Vim config for $USERNAME"
63
 
63
 
64
             # create a temporary directory
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
             fi
67
             fi
68
 
68
 
69
             # copy config files into the directory
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
             fi
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
             fi
77
             fi
78
 
78
 
79
             # backup the directory
79
             # backup the directory
80
             function_check backup_directory_to_usb
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
             # remove temporary directory
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
             fi
86
             fi
87
         fi
87
         fi
88
     done
88
     done
90
 
90
 
91
 function restore_local_vim {
91
 function restore_local_vim {
92
     temp_restore_dir=/root/tempvim
92
     temp_restore_dir=/root/tempvim
93
-    if [ -d $USB_MOUNT/backup/vim ]; then
93
+    if [ -d "$USB_MOUNT/backup/vim" ]; then
94
         for d in $USB_MOUNT/backup/vim/*/ ; do
94
         for d in $USB_MOUNT/backup/vim/*/ ; do
95
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
95
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
96
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
99
                 fi
100
                 echo $"Restoring Vim config for $USERNAME"
100
                 echo $"Restoring Vim config for $USERNAME"
101
                 function_check restore_directory_from_usb
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
                 else
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
                     fi
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
                 fi
110
                 fi
111
+                # shellcheck disable=SC2181
111
                 if [ ! "$?" = "0" ]; then
112
                 if [ ! "$?" = "0" ]; then
112
                     rm -rf $temp_restore_dir
113
                     rm -rf $temp_restore_dir
113
                     function_check set_user_permissions
114
                     function_check set_user_permissions
116
                     backup_unmount_drive
117
                     backup_unmount_drive
117
                     exit 664
118
                     exit 664
118
                 fi
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
                 fi
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
                 fi
126
                 fi
126
-                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
127
+                rm -rf "/home/${USERNAME:?}/$VIM_TEMP_DIR"
127
                 rm -rf $temp_restore_dir
128
                 rm -rf $temp_restore_dir
128
             fi
129
             fi
129
         done
130
         done
137
             echo $"Backing up Vim config for $USERNAME"
138
             echo $"Backing up Vim config for $USERNAME"
138
 
139
 
139
             # create a temporary directory
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
             fi
143
             fi
143
 
144
 
144
             # copy config files into the directory
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
             fi
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
             fi
153
             fi
153
 
154
 
154
             # backup the directory
155
             # backup the directory
155
             function_check backup_directory_to_friend
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
             # remove temporary directory
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
             fi
162
             fi
162
         fi
163
         fi
163
     done
164
     done
165
 
166
 
166
 function restore_remote_vim {
167
 function restore_remote_vim {
167
     temp_restore_dir=/root/tempvim
168
     temp_restore_dir=/root/tempvim
168
-    if [ -d $USB_MOUNT/backup/vim ]; then
169
+    if [ -d "$USB_MOUNT/backup/vim" ]; then
169
         for d in $USB_MOUNT/backup/vim/*/ ; do
170
         for d in $USB_MOUNT/backup/vim/*/ ; do
170
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
171
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
171
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
175
                 fi
175
                 echo $"Restoring Vim config for $USERNAME"
176
                 echo $"Restoring Vim config for $USERNAME"
176
                 function_check restore_directory_from_friend
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
                 else
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
                     fi
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
                 fi
186
                 fi
187
+                # shellcheck disable=SC2181
186
                 if [ ! "$?" = "0" ]; then
188
                 if [ ! "$?" = "0" ]; then
187
                     rm -rf $temp_restore_dir
189
                     rm -rf $temp_restore_dir
188
                     function_check set_user_permissions
190
                     function_check set_user_permissions
191
                     backup_unmount_drive
193
                     backup_unmount_drive
192
                     exit 664
194
                     exit 664
193
                 fi
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
                 fi
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
                 fi
202
                 fi
201
-                rm -rf /home/$USERNAME/$VIM_TEMP_DIR
203
+                rm -rf "/home/${USERNAME:?}/$VIM_TEMP_DIR"
202
                 rm -rf $temp_restore_dir
204
                 rm -rf $temp_restore_dir
203
             fi
205
             fi
204
         done
206
         done
210
     # This may change with Debian Stretch
212
     # This may change with Debian Stretch
211
     # apt-get -yq remove --purge vim
213
     # apt-get -yq remove --purge vim
212
     update-alternatives --set editor /usr/bin/nano
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
     # remove Vim as the mutt email editor
217
     # remove Vim as the mutt email editor
216
     if [ -f /etc/Muttrc ]; then
218
     if [ -f /etc/Muttrc ]; then
220
         for d in /home/*/ ; do
222
         for d in /home/*/ ; do
221
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
223
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
222
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                     fi
228
                     fi
227
                 fi
229
                 fi
228
             fi
230
             fi
244
         for d in /home/*/ ; do
246
         for d in /home/*/ ; do
245
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
247
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
246
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                     else
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
                     fi
254
                     fi
253
                 fi
255
                 fi
254
             fi
256
             fi

+ 218
- 210
src/freedombone-app-vpn 查看文件

82
     VPN_DETAILS_COMPLETE=
82
     VPN_DETAILS_COMPLETE=
83
     while [ ! $VPN_DETAILS_COMPLETE ]
83
     while [ ! $VPN_DETAILS_COMPLETE ]
84
     do
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
         currtlsport=$(grep 'VPN_TLS_PORT' temp.cfg | awk -F '=' '{print $2}')
86
         currtlsport=$(grep 'VPN_TLS_PORT' temp.cfg | awk -F '=' '{print $2}')
88
-        if [ $currtlsport ]; then
87
+        if [ "$currtlsport" ]; then
89
             VPN_TLS_PORT=$currtlsport
88
             VPN_TLS_PORT=$currtlsport
90
         fi
89
         fi
91
         dialog --backtitle $"Freedombone Configuration" \
90
         dialog --backtitle $"Freedombone Configuration" \
92
                --title $"VPN Configuration" \
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
                $"TLS port:" 1 1 "$VPN_TLS_PORT" 1 12 5 5 \
93
                $"TLS port:" 1 1 "$VPN_TLS_PORT" 1 12 5 5 \
95
-               2> $data
94
+               2> "$data"
96
         sel=$?
95
         sel=$?
97
         case $sel in
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
         esac
101
         esac
101
-        tlsport=$(cat $data | sed -n 1p)
102
+        tlsport=$(sed -n 1p < "$data")
102
         if [ ${#tlsport} -gt 1 ]; then
103
         if [ ${#tlsport} -gt 1 ]; then
103
             if [[ "$tlsport" != *' '* && "$tlsport" != *'.'* ]]; then
104
             if [[ "$tlsport" != *' '* && "$tlsport" != *'.'* ]]; then
104
                 VPN_TLS_PORT="$tlsport"
105
                 VPN_TLS_PORT="$tlsport"
106
                 write_config_param "VPN_TLS_PORT" "$VPN_TLS_PORT"
107
                 write_config_param "VPN_TLS_PORT" "$VPN_TLS_PORT"
107
             fi
108
             fi
108
         fi
109
         fi
110
+        rm -f "$data"
109
     done
111
     done
110
     clear
112
     clear
111
     APP_INSTALLED=1
113
     APP_INSTALLED=1
112
 }
114
 }
113
 
115
 
114
 function vpn_change_tls_port {
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
         EXISTING_VPN_TLS_PORT=443
118
         EXISTING_VPN_TLS_PORT=443
117
     else
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
     fi
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
     dialog --title $"VPN Configuration" \
124
     dialog --title $"VPN Configuration" \
124
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
127
     sel=$?
127
     case $sel in
128
     case $sel in
128
         0)
129
         0)
129
-            tlsport=$(<$data)
130
+            tlsport=$(<"$data")
130
             if [ ${#tlsport} -gt 0 ]; then
131
             if [ ${#tlsport} -gt 0 ]; then
131
                 if [[ "$tlsport" != "$EXISTING_VPN_TLS_PORT" ]]; then
132
                 if [[ "$tlsport" != "$EXISTING_VPN_TLS_PORT" ]]; then
132
                     clear
133
                     clear
137
 
138
 
138
                     for d in /home/*/ ; do
139
                     for d in /home/*/ ; do
139
                         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
                         fi
144
                         fi
144
                     done
145
                     done
145
 
146
 
146
-                    if [ $VPN_TLS_PORT -eq 443 ]; then
147
+                    if [ "$VPN_TLS_PORT" -eq 443 ]; then
147
                         if [[ "$PREVIOUS_VPN_TLS_PORT" != "443" ]]; then
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
                         fi
150
                         fi
150
                         systemctl stop nginx
151
                         systemctl stop nginx
151
                         systemctl disable nginx
152
                         systemctl disable nginx
152
                     else
153
                     else
153
                         if [[ "$PREVIOUS_VPN_TLS_PORT" != "$VPN_TLS_PORT" ]]; then
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
                         fi
157
                         fi
157
                         systemctl enable nginx
158
                         systemctl enable nginx
158
                         systemctl restart nginx
159
                         systemctl restart nginx
160
 
161
 
161
                     systemctl restart stunnel
162
                     systemctl restart stunnel
162
 
163
 
163
-                    if [ $VPN_TLS_PORT -eq 443 ]; then
164
+                    if [ "$VPN_TLS_PORT" -eq 443 ]; then
164
                         dialog --title $"VPN Configuration" \
165
                         dialog --title $"VPN Configuration" \
165
                                --msgbox $"TLS port changed to ${VPN_TLS_PORT}. Forward this port from your internet router." 10 60
166
                                --msgbox $"TLS port changed to ${VPN_TLS_PORT}. Forward this port from your internet router." 10 60
166
                     else
167
                     else
171
             fi
172
             fi
172
             ;;
173
             ;;
173
     esac
174
     esac
175
+    rm -f "$data"
174
 }
176
 }
175
 
177
 
176
 function vpn_regenerate_client_keys {
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
     dialog --title $"Regenerate VPN keys for a user" \
180
     dialog --title $"Regenerate VPN keys for a user" \
180
            --backtitle $"Freedombone Control Panel" \
181
            --backtitle $"Freedombone Control Panel" \
181
-           --inputbox $'username' 10 50 2>$data
182
+           --inputbox $'username' 10 50 2>"$data"
182
     sel=$?
183
     sel=$?
183
     case $sel in
184
     case $sel in
184
         0)
185
         0)
185
-            USERNAME=$(<$data)
186
+            USERNAME=$(<"$data")
186
             if [ ${#USERNAME} -gt 0 ]; then
187
             if [ ${#USERNAME} -gt 0 ]; then
187
-                if [ -d /home/$USERNAME ]; then
188
+                if [ -d "/home/$USERNAME" ]; then
188
                     clear
189
                     clear
189
-                    create_user_vpn_key $USERNAME
190
+                    create_user_vpn_key "$USERNAME"
190
                     dialog --title $"Regenerate VPN keys for a user" \
191
                     dialog --title $"Regenerate VPN keys for a user" \
191
                            --msgbox $"VPN keys were regenerated for $USERNAME" 6 60
192
                            --msgbox $"VPN keys were regenerated for $USERNAME" 6 60
192
                 fi
193
                 fi
193
             fi
194
             fi
194
             ;;
195
             ;;
195
     esac
196
     esac
197
+    rm -f "$data"
196
 }
198
 }
197
 
199
 
198
 function configure_interactive_vpn {
200
 function configure_interactive_vpn {
199
     read_config_param VPN_TLS_PORT
201
     read_config_param VPN_TLS_PORT
200
     while true
202
     while true
201
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
205
         dialog --backtitle $"Freedombone Control Panel" \
205
                --title $"VPN Configuration" \
206
                --title $"VPN Configuration" \
206
                --radiolist $"Choose an operation:" 13 70 3 \
207
                --radiolist $"Choose an operation:" 13 70 3 \
207
                1 $"Change TLS port (currently $VPN_TLS_PORT)" off \
208
                1 $"Change TLS port (currently $VPN_TLS_PORT)" off \
208
                2 $"Regenerate keys for a user" off \
209
                2 $"Regenerate keys for a user" off \
209
-               3 $"Exit" on 2> $data
210
+               3 $"Exit" on 2> "$data"
210
         sel=$?
211
         sel=$?
211
         case $sel in
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
         esac
217
         esac
215
-        case $(cat $data) in
218
+        case $(cat "$data") in
216
             1) vpn_change_tls_port;;
219
             1) vpn_change_tls_port;;
217
             2) vpn_regenerate_client_keys;;
220
             2) vpn_regenerate_client_keys;;
218
-            3) break;;
221
+            3) rm -f "$data"
222
+               break;;
219
         esac
223
         esac
224
+        rm -f "$data"
220
     done
225
     done
221
 }
226
 }
222
 
227
 
231
 function backup_local_vpn {
236
 function backup_local_vpn {
232
     for d in /home/*/ ; do
237
     for d in /home/*/ ; do
233
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
         fi
241
         fi
237
     done
242
     done
238
 
243
 
252
 
257
 
253
         for d in /home/*/ ; do
258
         for d in /home/*/ ; do
254
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
             fi
263
             fi
259
         done
264
         done
260
     fi
265
     fi
265
         rm -rf ${temp_restore_dir}
270
         rm -rf ${temp_restore_dir}
266
         for d in /home/*/ ; do
271
         for d in /home/*/ ; do
267
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
             fi
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
             fi
280
             fi
276
         done
281
         done
277
     fi
282
     fi
280
 function backup_remote_vpn {
285
 function backup_remote_vpn {
281
     for d in /home/*/ ; do
286
     for d in /home/*/ ; do
282
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
         fi
290
         fi
286
     done
291
     done
287
 
292
 
301
 
306
 
302
         for d in /home/*/ ; do
307
         for d in /home/*/ ; do
303
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
             fi
312
             fi
308
         done
313
         done
309
     fi
314
     fi
314
         rm -rf ${temp_restore_dir}
319
         rm -rf ${temp_restore_dir}
315
         for d in /home/*/ ; do
320
         for d in /home/*/ ; do
316
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
             fi
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
             fi
329
             fi
325
         done
330
         done
326
     fi
331
     fi
332
     rm /etc/systemd/system/stunnel.service
337
     rm /etc/systemd/system/stunnel.service
333
 
338
 
334
     systemctl stop openvpn
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
     else
342
     else
338
         systemctl enable nginx
343
         systemctl enable nginx
339
         systemctl restart nginx
344
         systemctl restart nginx
354
     # remove any client keys
359
     # remove any client keys
355
     for d in /home/*/ ; do
360
     for d in /home/*/ ; do
356
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
         fi
364
         fi
360
-        rm /home/$USERNAME/stunnel*
365
+        rm "/home/$USERNAME/stunnel*"
361
     done
366
     done
362
     userdel -f vpn
367
     userdel -f vpn
363
     groupdel -f vpn
368
     groupdel -f vpn
370
 function create_user_vpn_key {
375
 function create_user_vpn_key {
371
     username=$1
376
     username=$1
372
 
377
 
373
-    if [ ! -d /home/$username ]; then
378
+    if [ ! -d "/home/$username" ]; then
374
         return
379
         return
375
     fi
380
     fi
376
 
381
 
377
     echo $"Creating VPN key for $username"
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
     fi
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
     fi
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
     fi
394
     fi
390
 
395
 
391
     sed -i 's| --interact||g' build-key
396
     sed -i 's| --interact||g' build-key
392
     ./build-key "$username"
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
         echo $'VPN user cert not generated'
400
         echo $'VPN user cert not generated'
396
         exit 783528
401
         exit 783528
397
     fi
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
     if [ ${#user_cert} -lt 10 ]; then
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
         echo $'User cert generation failed'
406
         echo $'User cert generation failed'
402
         exit 634659
407
         exit 634659
403
     fi
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
         echo $'VPN user key not generated'
410
         echo $'VPN user key not generated'
406
         exit 682523
411
         exit 682523
407
     fi
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
     if [ ${#user_key} -lt 10 ]; then
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
         echo $'User key generation failed'
416
         echo $'User key generation failed'
412
         exit 285838
417
         exit 285838
413
     fi
418
     fi
414
 
419
 
415
     user_vpn_cert_file=/home/$username/$OPENVPN_KEY_FILENAME
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
     # keep a backup
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
     #rm /etc/openvpn/easy-rsa/keys/$username.crt
458
     #rm /etc/openvpn/easy-rsa/keys/$username.crt
453
     #rm /etc/openvpn/easy-rsa/keys/$username.csr
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
     echo $"VPN key created at $user_vpn_cert_file"
462
     echo $"VPN key created at $user_vpn_cert_file"
457
 }
463
 }
458
 
464
 
459
 function add_user_vpn {
465
 function add_user_vpn {
460
     new_username="$1"
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
     if [ -f /etc/stunnel/stunnel.pem ]; then
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
     fi
473
     fi
468
     if [ -f /etc/stunnel/stunnel.p12 ]; then
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
     fi
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
 function remove_user_vpn {
482
 function remove_user_vpn {
516
     fi
522
     fi
517
     chmod 640 /etc/stunnel/stunnel.p12
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
 function install_stunnel {
530
 function install_stunnel {
525
     prefix=
531
     prefix=
526
     prefixchroot=
532
     prefixchroot=
527
-    if [ $rootdir ]; then
533
+    # shellcheck disable=SC2154
534
+    if [ "$rootdir" ]; then
528
         prefix=$rootdir
535
         prefix=$rootdir
529
         prefixchroot="chroot $rootdir"
536
         prefixchroot="chroot $rootdir"
530
         VPN_TLS_PORT=$VPN_MESH_TLS_PORT
537
         VPN_TLS_PORT=$VPN_MESH_TLS_PORT
532
 
539
 
533
     $prefixchroot apt-get -yq install stunnel4
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
         generate_stunnel_keys
544
         generate_stunnel_keys
538
     fi
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
         if [ $VPN_TLS_PORT -eq 443 ]; then
589
         if [ $VPN_TLS_PORT -eq 443 ]; then
583
             systemctl stop nginx
590
             systemctl stop nginx
584
             systemctl disable nginx
591
             systemctl disable nginx
591
         systemctl daemon-reload
598
         systemctl daemon-reload
592
         systemctl start stunnel
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
     fi
603
     fi
597
 }
604
 }
598
 
605
 
599
 function vpn_generate_keys {
606
 function vpn_generate_keys {
600
     # generate host keys
607
     # generate host keys
601
     if [ ! -f /etc/openvpn/dh2048.pem ]; then
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
     fi
610
     fi
604
     if [ ! -f /etc/openvpn/dh2048.pem ]; then
611
     if [ ! -f /etc/openvpn/dh2048.pem ]; then
605
         echo $'vpn dhparams were not generated'
612
         echo $'vpn dhparams were not generated'
607
     fi
614
     fi
608
     cp /etc/openvpn/dh2048.pem /etc/openvpn/easy-rsa/keys/dh2048.pem
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
     . ./vars
619
     . ./vars
612
     ./clean-all
620
     ./clean-all
613
     vpn_openssl_version='1.0.0'
621
     vpn_openssl_version='1.0.0'
651
     fi
659
     fi
652
     cp /etc/openvpn/easy-rsa/keys/{$OPENVPN_SERVER_NAME.crt,$OPENVPN_SERVER_NAME.key,ca.crt} /etc/openvpn
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
 function install_vpn {
665
 function install_vpn {
658
     prefix=
666
     prefix=
659
     prefixchroot=
667
     prefixchroot=
660
-    if [ $rootdir ]; then
668
+    if [ "$rootdir" ]; then
661
         prefix=$rootdir
669
         prefix=$rootdir
662
         prefixchroot="chroot $rootdir"
670
         prefixchroot="chroot $rootdir"
663
         VPN_TLS_PORT=$VPN_MESH_TLS_PORT
671
         VPN_TLS_PORT=$VPN_MESH_TLS_PORT
668
     $prefixchroot useradd -r -s /bin/false -g vpn vpn
676
     $prefixchroot useradd -r -s /bin/false -g vpn vpn
669
 
677
 
670
     # server configuration
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
         echo 1 > /proc/sys/net/ipv4/ip_forward
702
         echo 1 > /proc/sys/net/ipv4/ip_forward
695
     fi
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
     fi
711
     fi
704
 
712
 
705
     # keys configuration
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
         vpn_generate_keys
723
         vpn_generate_keys
716
         firewall_enable_vpn
724
         firewall_enable_vpn
717
 
725
 
724
 
732
 
725
     install_stunnel
733
     install_stunnel
726
 
734
 
727
-    if [ ! $prefix ]; then
735
+    if [ ! "$prefix" ]; then
728
         systemctl restart openvpn
736
         systemctl restart openvpn
729
     fi
737
     fi
730
 
738