Bob Mottram 7 лет назад
Родитель
Сommit
8112c240ae
54 измененных файлов: 4962 добавлений и 4956 удалений
  1. 335
    325
      src/freedombone-app-xmpp
  2. 157
    156
      src/freedombone-app-zeronet
  3. 8
    8
      src/freedombone-archive-mail
  4. 61
    60
      src/freedombone-backup-local
  5. 93
    91
      src/freedombone-backup-remote
  6. 560
    620
      src/freedombone-base-email
  7. 28
    28
      src/freedombone-base-tripwire
  8. 52
    51
      src/freedombone-client
  9. 50
    54
      src/freedombone-clientcert
  10. 169
    134
      src/freedombone-config
  11. 408
    437
      src/freedombone-controlpanel
  12. 207
    220
      src/freedombone-controlpanel-user
  13. 13
    14
      src/freedombone-dhparam
  14. 8
    8
      src/freedombone-encrypt-mail
  15. 5
    8
      src/freedombone-format
  16. 8
    7
      src/freedombone-freedns
  17. 20
    20
      src/freedombone-ignore
  18. 75
    74
      src/freedombone-image
  19. 683
    679
      src/freedombone-image-customise
  20. 19
    25
      src/freedombone-image-hardware-setup
  21. 52
    52
      src/freedombone-image-make
  22. 648
    645
      src/freedombone-image-mesh
  23. 2
    2
      src/freedombone-image-vmdebootstrap
  24. 38
    40
      src/freedombone-keydrive
  25. 16
    16
      src/freedombone-logging
  26. 74
    73
      src/freedombone-mesh-batman
  27. 48
    47
      src/freedombone-mesh-blog
  28. 5
    4
      src/freedombone-mesh-connect
  29. 106
    106
      src/freedombone-mesh-install
  30. 2
    2
      src/freedombone-mesh-invite
  31. 3
    3
      src/freedombone-mesh-reset
  32. 35
    35
      src/freedombone-mesh-routing
  33. 7
    6
      src/freedombone-mesh-visit-site
  34. 43
    44
      src/freedombone-pass
  35. 18
    18
      src/freedombone-pin-cert
  36. 8
    8
      src/freedombone-powerline
  37. 29
    28
      src/freedombone-recoverkey
  38. 32
    32
      src/freedombone-remote
  39. 3
    4
      src/freedombone-renew-cert
  40. 15
    15
      src/freedombone-repair-database
  41. 145
    130
      src/freedombone-restore-local
  42. 153
    139
      src/freedombone-restore-remote
  43. 3
    3
      src/freedombone-rmemail
  44. 6
    6
      src/freedombone-rmlist
  45. 25
    25
      src/freedombone-rmuser
  46. 227
    206
      src/freedombone-sec
  47. 44
    46
      src/freedombone-splitkey
  48. 93
    93
      src/freedombone-syncthing
  49. 56
    53
      src/freedombone-template
  50. 27
    16
      src/freedombone-tests
  51. 7
    7
      src/freedombone-unignore
  52. 9
    10
      src/freedombone-upgrade
  53. 5
    5
      src/freedombone-usb-canary
  54. 19
    18
      src/meshavahi

+ 335
- 325
src/freedombone-app-xmpp
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 157
- 156
src/freedombone-app-zeronet Просмотреть файл

@@ -105,7 +105,7 @@ function remove_zeronet_blog {
105 105
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroBlog
106 106
     fi
107 107
     remove_completion_param install_zeronet_blog
108
-    sed -i '/zeronet blog/d' $COMPLETION_FILE
108
+    sed -i '/zeronet blog/d' "$COMPLETION_FILE"
109 109
 }
110 110
 
111 111
 function remove_zeronet_mail {
@@ -113,7 +113,7 @@ function remove_zeronet_mail {
113 113
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroMail
114 114
     fi
115 115
     remove_completion_param install_zeronet_mail
116
-    sed -i '/zeronet mail/d' $COMPLETION_FILE
116
+    sed -i '/zeronet mail/d' "$COMPLETION_FILE"
117 117
 }
118 118
 
119 119
 function remove_zeronet_forum {
@@ -121,7 +121,7 @@ function remove_zeronet_forum {
121 121
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroTalk
122 122
     fi
123 123
     remove_completion_param install_zeronet_forum
124
-    sed -i '/zeronet forum/d' $COMPLETION_FILE
124
+    sed -i '/zeronet forum/d' "$COMPLETION_FILE"
125 125
 }
126 126
 
127 127
 function remove_zeronet {
@@ -133,10 +133,10 @@ function remove_zeronet {
133 133
     firewall_remove ${TRACKER_PORT}
134 134
     firewall_remove 1900 udp
135 135
 
136
-    ${PROJECT_NAME}-mesh-install -f zeronet --remove yes
136
+    "${PROJECT_NAME}-mesh-install" -f zeronet --remove yes
137 137
     remove_completion_param install_zeronet
138 138
     remove_completion_param configure_firewall_for_zeronet
139
-    sed -i '/zeronet/d' $COMPLETION_FILE
139
+    sed -i '/zeronet/d' "$COMPLETION_FILE"
140 140
 }
141 141
 
142 142
 function configure_firewall_for_zeronet {
@@ -161,14 +161,14 @@ function install_zeronet_blog {
161 161
 
162 162
     ZERONET_DEFAULT_BLOG_TITLE="${MY_USERNAME}'s Blog"
163 163
 
164
-    cd $MESH_INSTALL_DIR/zeronet
164
+    cd "$MESH_INSTALL_DIR/zeronet" || exit 246284728
165 165
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/blog.txt
166 166
     if [ ! -f $MESH_INSTALL_DIR/zeronet/blog.txt ]; then
167 167
         echo $'Unable to create blog'
168 168
         exit 479
169 169
     fi
170
-    blog_address=$(cat blog.txt | grep "Site address" | awk -F ':' '{print $2}')
171
-    blog_private_key=$(cat blog.txt | grep "Site private key" | awk -F ':' '{print $2}')
170
+    blog_address=$(grep "Site address" blog.txt | awk -F ':' '{print $2}')
171
+    blog_private_key=$(grep "Site private key" blog.txt | awk -F ':' '{print $2}')
172 172
     ZERONET_BLOG_ADDRESS=${blog_address//[[:blank:]]/}
173 173
     ZERONET_BLOG_PRIVATE_KEY=${blog_private_key//[[:blank:]]/}
174 174
 
@@ -197,24 +197,24 @@ function install_zeronet_blog {
197 197
         echo $'ZeroBlog repo could not be cloned'
198 198
         exit 6739
199 199
     fi
200
-    cd $MESH_INSTALL_DIR/zeronet/ZeroBlog
200
+    cd "$MESH_INSTALL_DIR/zeronet/ZeroBlog" || exit 47298462874
201 201
     git checkout $ZERONET_BLOG_COMMIT -b $ZERONET_BLOG_COMMIT
202 202
     set_completion_param "zeroNet blog commit" "$ZERONET_BLOG_COMMIT"
203 203
 
204 204
     echo $"ZeroNet Blog address:     $ZERONET_BLOG_ADDRESS"
205 205
     echo $"ZeroNet Blog private key: $ZERONET_BLOG_PRIVATE_KEY"
206
-    cp -r $MESH_INSTALL_DIR/zeronet/ZeroBlog/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS
206
+    cp -r "$MESH_INSTALL_DIR/zeronet/ZeroBlog/*" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS"
207 207
 
208
-    if [ ! -d $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data ]; then
209
-        mkdir $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data
208
+    if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data" ]; then
209
+        mkdir "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data"
210 210
     fi
211
-    cp $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data-default/data.json $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data
212
-    sed -i "s/MyZeroBlog/$ZERONET_DEFAULT_BLOG_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json
213
-    sed -i "s/My ZeroBlog./$ZERONET_DEFAULT_BLOG_TAGLINE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json
214
-    sed -i "s/ZeroBlog Demo/$ZERONET_DEFAULT_BLOG_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html
215
-    sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_BLOG_TAGLINE</h3>|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html
216
-    sed -i "s/Blogging platform Demo/Blogging platform/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/content.json
217
-    python zeronet.py siteSign $ZERONET_BLOG_ADDRESS $ZERONET_BLOG_PRIVATE_KEY
211
+    cp "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data-default/data.json" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data"
212
+    sed -i "s/MyZeroBlog/$ZERONET_DEFAULT_BLOG_TITLE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json"
213
+    sed -i "s/My ZeroBlog./$ZERONET_DEFAULT_BLOG_TAGLINE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/data/data.json"
214
+    sed -i "s/ZeroBlog Demo/$ZERONET_DEFAULT_BLOG_TITLE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html"
215
+    sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_BLOG_TAGLINE</h3>|g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/index.html"
216
+    sed -i "s/Blogging platform Demo/Blogging platform/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_BLOG_ADDRESS/content.json"
217
+    python zeronet.py siteSign "$ZERONET_BLOG_ADDRESS" "$ZERONET_BLOG_PRIVATE_KEY"
218 218
 
219 219
     # Add an avahi service
220 220
     function_check create_avahi_service
@@ -223,11 +223,11 @@ function install_zeronet_blog {
223 223
 
224 224
     chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
225 225
 
226
-    if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then
227
-        mkdir -p /home/$MY_USERNAME/.config/zeronet
228
-        chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
226
+    if [ ! -d "/home/$MY_USERNAME/.config/zeronet" ]; then
227
+        mkdir -p "/home/$MY_USERNAME/.config/zeronet"
228
+        chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.config"
229 229
     fi
230
-    echo "${ZERONET_URL}/${ZERONET_BLOG_ADDRESS}" > /home/$MY_USERNAME/.config/zeronet/myblog
230
+    echo "${ZERONET_URL}/${ZERONET_BLOG_ADDRESS}" > "/home/$MY_USERNAME/.config/zeronet/myblog"
231 231
 
232 232
     install_completed zeronet_blog
233 233
 }
@@ -244,14 +244,14 @@ function install_zeronet_mail {
244 244
 
245 245
     ZERONET_DEFAULT_MAIL_TITLE="${MY_USERNAME}'s Mail"
246 246
 
247
-    cd $MESH_INSTALL_DIR/zeronet
247
+    cd "$MESH_INSTALL_DIR/zeronet" || exit 4628462862
248 248
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/mail.txt
249 249
     if [ ! -f $MESH_INSTALL_DIR/zeronet/mail.txt ]; then
250 250
         echo $'Unable to create mail'
251 251
         exit 479
252 252
     fi
253
-    mail_address=$(cat mail.txt | grep "Site address" | awk -F ':' '{print $2}')
254
-    mail_private_key=$(cat mail.txt | grep "Site private key" | awk -F ':' '{print $2}')
253
+    mail_address=$(grep "Site address" mail.txt | awk -F ':' '{print $2}')
254
+    mail_private_key=$(grep "Site private key" mail.txt | awk -F ':' '{print $2}')
255 255
     ZERONET_MAIL_ADDRESS=${mail_address//[[:blank:]]/}
256 256
     ZERONET_MAIL_PRIVATE_KEY=${mail_private_key//[[:blank:]]/}
257 257
 
@@ -280,24 +280,24 @@ function install_zeronet_mail {
280 280
         echo $'ZeroMail repo could not be cloned'
281 281
         exit 6739
282 282
     fi
283
-    cd $MESH_INSTALL_DIR/zeronet/ZeroMail
283
+    cd "$MESH_INSTALL_DIR/zeronet/ZeroMail" || exit 246284682
284 284
     git checkout $ZERONET_MAIL_COMMIT -b $ZERONET_MAIL_COMMIT
285 285
     set_completion_param "zeroNet mail commit" "$ZERONET_MAIL_COMMIT"
286 286
 
287 287
     echo $"ZeroNet Mail address:     $ZERONET_MAIL_ADDRESS"
288 288
     echo $"ZeroNet Mail private key: $ZERONET_MAIL_PRIVATE_KEY"
289
-    cp -r $MESH_INSTALL_DIR/zeronet/ZeroMail/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS
289
+    cp -r "$MESH_INSTALL_DIR/zeronet/ZeroMail/*" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS"
290 290
 
291
-    if [ ! -d $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data ]; then
292
-        mkdir $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data
291
+    if [ ! -d "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data" ]; then
292
+        mkdir "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data"
293 293
     fi
294
-    cp $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data-default/data.json $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data
295
-    sed -i "s/MyZeroMail/$ZERONET_DEFAULT_MAIL_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json
296
-    sed -i "s/My ZeroMail./$ZERONET_DEFAULT_MAIL_TAGLINE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json
297
-    sed -i "s/ZeroMail Demo/$ZERONET_DEFAULT_MAIL_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html
298
-    sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_MAIL_TAGLINE</h3>|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html
299
-    sed -i "s/Mailging platform Demo/Mailging platform/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/content.json
300
-    python zeronet.py siteSign $ZERONET_MAIL_ADDRESS $ZERONET_MAIL_PRIVATE_KEY
294
+    cp "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data-default/data.json" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data"
295
+    sed -i "s/MyZeroMail/$ZERONET_DEFAULT_MAIL_TITLE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json"
296
+    sed -i "s/My ZeroMail./$ZERONET_DEFAULT_MAIL_TAGLINE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/data/data.json"
297
+    sed -i "s/ZeroMail Demo/$ZERONET_DEFAULT_MAIL_TITLE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html"
298
+    sed -i "s|<h3 class=\"description\">.*|<h3 class=\"description\">$ZERONET_DEFAULT_MAIL_TAGLINE</h3>|g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/index.html"
299
+    sed -i "s/Mailging platform Demo/Mailging platform/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_MAIL_ADDRESS/content.json"
300
+    python zeronet.py siteSign "$ZERONET_MAIL_ADDRESS" "$ZERONET_MAIL_PRIVATE_KEY"
301 301
 
302 302
     # Add an avahi service
303 303
     function_check create_avahi_service
@@ -306,11 +306,11 @@ function install_zeronet_mail {
306 306
 
307 307
     chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
308 308
 
309
-    if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then
310
-        mkdir -p /home/$MY_USERNAME/.config/zeronet
311
-        chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
309
+    if [ ! -d "/home/$MY_USERNAME/.config/zeronet" ]; then
310
+        mkdir -p "/home/$MY_USERNAME/.config/zeronet"
311
+        chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.config"
312 312
     fi
313
-    echo "${ZERONET_URL}/${ZERONET_MAIL_ADDRESS}" > /home/$MY_USERNAME/.config/zeronet/mymail
313
+    echo "${ZERONET_URL}/${ZERONET_MAIL_ADDRESS}" > "/home/$MY_USERNAME/.config/zeronet/mymail"
314 314
 
315 315
     install_completed zeronet_mail
316 316
 }
@@ -327,14 +327,14 @@ function install_zeronet_forum {
327 327
 
328 328
     ZERONET_DEFAULT_FORUM_TITLE=$"${MY_USERNAME}'s Forum"
329 329
 
330
-    cd $MESH_INSTALL_DIR/zeronet
330
+    cd "$MESH_INSTALL_DIR/zeronet" || exit 472984624628
331 331
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/forum.txt
332 332
     if [ ! -f $MESH_INSTALL_DIR/zeronet/forum.txt ]; then
333 333
         echo $'Unable to create forum'
334 334
         exit 479
335 335
     fi
336
-    forum_address=$(cat forum.txt | grep "Site address" | awk -F ':' '{print $2}')
337
-    forum_private_key=$(cat forum.txt | grep "Site private key" | awk -F ':' '{print $2}')
336
+    forum_address=$(grep "Site address" forum.txt | awk -F ':' '{print $2}')
337
+    forum_private_key=$(grep "Site private key" forum.txt | awk -F ':' '{print $2}')
338 338
     ZERONET_FORUM_ADDRESS=${forum_address//[[:blank:]]/}
339 339
     ZERONET_FORUM_PRIVATE_KEY=${forum_private_key//[[:blank:]]/}
340 340
 
@@ -368,13 +368,13 @@ function install_zeronet_forum {
368 368
 
369 369
     echo $"Forum address:     $ZERONET_FORUM_ADDRESS"
370 370
     echo $"Forum private key: $ZERONET_FORUM_PRIVATE_KEY"
371
-    cp -r $MESH_INSTALL_DIR/zeronet/ZeroTalk/* $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS
372
-    sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
373
-    sed -i "s/ZeroTalk/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
374
-    sed -i "s|Demo for dynamic, decentralized content publishing.|$ZERONET_DEFAULT_FORUM_TAGLINE|g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html
375
-    sed -i 's/Messaging Board Demo/Messaging Board/g' $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json
376
-    sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" $MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json
377
-    python zeronet.py siteSign $ZERONET_FORUM_ADDRESS $ZERONET_FORUM_PRIVATE_KEY --inner_path data/users/content.json
371
+    cp -r "$MESH_INSTALL_DIR/zeronet/ZeroTalk/*" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS"
372
+    sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html"
373
+    sed -i "s/ZeroTalk/$ZERONET_DEFAULT_FORUM_TITLE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html"
374
+    sed -i "s|Demo for dynamic, decentralized content publishing.|$ZERONET_DEFAULT_FORUM_TAGLINE|g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/index.html"
375
+    sed -i 's/Messaging Board Demo/Messaging Board/g' "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json"
376
+    sed -i "s/ZeroBoard/$ZERONET_DEFAULT_FORUM_TITLE/g" "$MESH_INSTALL_DIR/zeronet/data/$ZERONET_FORUM_ADDRESS/content.json"
377
+    python zeronet.py siteSign "$ZERONET_FORUM_ADDRESS" "$ZERONET_FORUM_PRIVATE_KEY" --inner_path data/users/content.json
378 378
 
379 379
     # Add an avahi service
380 380
     function_check create_avahi_service
@@ -383,11 +383,11 @@ function install_zeronet_forum {
383 383
 
384 384
     chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
385 385
 
386
-    if [ ! -d /home/$MY_USERNAME/.config/zeronet ]; then
387
-        mkdir -p /home/$MY_USERNAME/.config/zeronet
388
-        chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
386
+    if [ ! -d "/home/$MY_USERNAME/.config/zeronet" ]; then
387
+        mkdir -p "/home/$MY_USERNAME/.config/zeronet"
388
+        chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.config"
389 389
     fi
390
-    echo "${ZERONET_URL}/${ZERONET_FORUM_ADDRESS}" > /home/$MY_USERNAME/.config/zeronet/myforum
390
+    echo "${ZERONET_URL}/${ZERONET_FORUM_ADDRESS}" > "/home/$MY_USERNAME/.config/zeronet/myforum"
391 391
 
392 392
     install_completed zeronet_forum
393 393
 }
@@ -397,7 +397,7 @@ function install_zeronet_main {
397 397
         return
398 398
     fi
399 399
 
400
-    ${PROJECT_NAME}-mesh-install -f zeronet
400
+    "${PROJECT_NAME}-mesh-install" -f zeronet
401 401
     systemctl daemon-reload
402 402
     systemctl start tracker.service
403 403
     systemctl start zeronet.service
@@ -408,117 +408,118 @@ function install_zeronet_main {
408 408
 }
409 409
 
410 410
 function mesh_zeronet {
411
-    ZERONET_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}')
411
+    ZERONET_REPO_MAIN=$(grep "ZERONET_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F '"' '{print $2}')
412 412
     if [ ${#ZERONET_REPO_MAIN} -gt 4 ]; then
413 413
         ZERONET_REPO=$ZERONET_REPO_MAIN
414 414
     fi
415
-    if [ ! $ZERONET_REPO ]; then
415
+    if [ ! "$ZERONET_REPO" ]; then
416 416
         echo $'No ZeroNet repo was specified'
417 417
         exit 723539
418 418
     fi
419 419
 
420
-    ZERONET_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
420
+    ZERONET_COMMIT_MAIN=$(grep "ZERONET_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
421 421
     if [ ${#ZERONET_COMMIT_MAIN} -gt 4 ]; then
422 422
         ZERONET_COMMIT=$ZERONET_COMMIT_MAIN
423 423
     fi
424
-    if [ ! $ZERONET_COMMIT ]; then
424
+    if [ ! "$ZERONET_COMMIT" ]; then
425 425
         echo $'No ZeroNet commit was specified'
426 426
         exit 490439
427 427
     fi
428 428
 
429
-    MESH_INSTALL_DIR_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "MESH_INSTALL_DIR=" | head -n 1 | awk -F "'" '{print $2}')
429
+    MESH_INSTALL_DIR_MAIN=$(grep "MESH_INSTALL_DIR=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
430 430
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
431 431
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
432 432
     fi
433
-    if [ ! $MESH_INSTALL_DIR ]; then
433
+    if [ ! "$MESH_INSTALL_DIR" ]; then
434 434
         echo $'No mesh install dir was specified'
435 435
         exit 432052
436 436
     fi
437 437
 
438
+    # shellcheck disable=SC2154
438 439
     chroot "$rootdir" apt-get -yq install python python-msgpack python-gevent
439 440
     chroot "$rootdir" apt-get -yq install python-pip bittornado
440 441
     chroot "$rootdir" pip install msgpack-python --upgrade
441 442
 
442
-    chroot "$rootdir" useradd -d $MESH_INSTALL_DIR/zeronet/ -s /bin/false zeronet
443
+    chroot "$rootdir" useradd -d "$MESH_INSTALL_DIR/zeronet/" -s /bin/false zeronet
443 444
 
444 445
     if [ -d /repos/zeronet ]; then
445
-        mkdir $rootdir$MESH_INSTALL_DIR/zeronet
446
-        cp -r -p /repos/zeronet/. $rootdir$MESH_INSTALL_DIR/zeronet
447
-        cd $rootdir$MESH_INSTALL_DIR/zeronet
446
+        mkdir "$rootdir$MESH_INSTALL_DIR/zeronet"
447
+        cp -r -p /repos/zeronet/. "$rootdir$MESH_INSTALL_DIR/zeronet"
448
+        cd "$rootdir$MESH_INSTALL_DIR/zeronet" || exit 2648246284
448 449
         git pull
449 450
     else
450
-        git clone $ZERONET_REPO $rootdir$MESH_INSTALL_DIR/zeronet
451
+        git clone "$ZERONET_REPO" "$rootdir$MESH_INSTALL_DIR/zeronet"
451 452
     fi
452 453
 
453
-    if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet ]; then
454
+    if [ ! -d "$rootdir$MESH_INSTALL_DIR/zeronet" ]; then
454 455
         echo 'WARNING: Unable to clone zeronet'
455 456
         return
456 457
     fi
457
-    cd $rootdir$MESH_INSTALL_DIR/zeronet
458
-    git checkout $ZERONET_COMMIT -b $ZERONET_COMMIT
459
-    if ! grep -q "ZeroNet commit" $COMPLETION_FILE; then
460
-        echo "ZeroNet commit:$ZERONET_COMMIT" >> $rootdir$COMPLETION_FILE
458
+    cd "$rootdir$MESH_INSTALL_DIR/zeronet" || exit 2468276484682
459
+    git checkout "$ZERONET_COMMIT" -b "$ZERONET_COMMIT"
460
+    if ! grep -q "ZeroNet commit" "$COMPLETION_FILE"; then
461
+        echo "ZeroNet commit:$ZERONET_COMMIT" >> "$rootdir$COMPLETION_FILE"
461 462
     else
462
-        sed -i "s/ZeroNet commit.*/ZeroNet commit:$ZERONET_COMMIT/g" $COMPLETION_FILE
463
+        sed -i "s/ZeroNet commit.*/ZeroNet commit:$ZERONET_COMMIT/g" "$COMPLETION_FILE"
463 464
     fi
464
-    chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
465
+    chroot "$rootdir" chown -R zeronet:zeronet "$MESH_INSTALL_DIR/zeronet"
465 466
 
466 467
     # Hack to ensure that the file access port is opened
467 468
     # This is because zeronet normally relies on an internet site
468 469
     # to do this, but on a purely local mesh the internet isn't available
469
-    sed -i 's|fileserver_port = 0|fileserver_port = config.fileserver_port\n            sys.modules["main"].file_server.port_opened = True|g' $rootdir$MESH_INSTALL_DIR/zeronet/src/Site/Site.py
470
+    sed -i 's|fileserver_port = 0|fileserver_port = config.fileserver_port\n            sys.modules["main"].file_server.port_opened = True|g' "$rootdir$MESH_INSTALL_DIR/zeronet/src/Site/Site.py"
470 471
 
471 472
     ZERONET_DAEMON=$rootdir/etc/systemd/system/zeronet.service
472
-    echo '[Unit]' > $ZERONET_DAEMON
473
-    echo 'Description=Zeronet Server' >> $ZERONET_DAEMON
474
-    echo 'After=syslog.target' >> $ZERONET_DAEMON
475
-    echo 'After=network.target' >> $ZERONET_DAEMON
476
-    echo '[Service]' >> $ZERONET_DAEMON
477
-    echo 'Type=simple' >> $ZERONET_DAEMON
478
-    echo 'User=zeronet' >> $ZERONET_DAEMON
479
-    echo 'Group=zeronet' >> $ZERONET_DAEMON
480
-    echo "WorkingDirectory=$MESH_INSTALL_DIR/zeronet" >> $ZERONET_DAEMON
481
-    echo "ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file $MESH_INSTALL_DIR/zeronet/bootstrap" >> $ZERONET_DAEMON
482
-    echo '' >> $ZERONET_DAEMON
483
-    echo 'TimeoutSec=300' >> $ZERONET_DAEMON
484
-    echo '' >> $ZERONET_DAEMON
485
-    echo '[Install]' >> $ZERONET_DAEMON
486
-    echo 'WantedBy=multi-user.target' >> $ZERONET_DAEMON
473
+    { echo '[Unit]';
474
+      echo 'Description=Zeronet Server';
475
+      echo 'After=syslog.target';
476
+      echo 'After=network.target';
477
+      echo '[Service]';
478
+      echo 'Type=simple';
479
+      echo 'User=zeronet';
480
+      echo 'Group=zeronet';
481
+      echo "WorkingDirectory=$MESH_INSTALL_DIR/zeronet";
482
+      echo "ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file $MESH_INSTALL_DIR/zeronet/bootstrap";
483
+      echo '';
484
+      echo 'TimeoutSec=300';
485
+      echo '';
486
+      echo '[Install]';
487
+      echo 'WantedBy=multi-user.target'; } > "$ZERONET_DAEMON"
487 488
 
488 489
     TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
489
-    echo '[Unit]' > $TRACKER_DAEMON
490
-    echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON
491
-    echo 'After=syslog.target' >> $TRACKER_DAEMON
492
-    echo 'After=network.target' >> $TRACKER_DAEMON
493
-    echo '[Service]' >> $TRACKER_DAEMON
494
-    echo 'Type=simple' >> $TRACKER_DAEMON
495
-    echo 'User=tracker' >> $TRACKER_DAEMON
496
-    echo 'Group=tracker' >> $TRACKER_DAEMON
497
-    echo "WorkingDirectory=$MESH_INSTALL_DIR/tracker" >> $TRACKER_DAEMON
498
-    echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile $MESH_INSTALL_DIR/tracker/dstate --logfile $MESH_INSTALL_DIR/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $TRACKER_DAEMON
499
-    echo '' >> $TRACKER_DAEMON
500
-    echo 'TimeoutSec=300' >> $TRACKER_DAEMON
501
-    echo '' >> $TRACKER_DAEMON
502
-    echo '[Install]' >> $TRACKER_DAEMON
503
-    echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON
504
-
505
-    chroot "$rootdir" useradd -d $MESH_INSTALL_DIR/tracker/ -s /bin/false tracker
506
-    if [ ! -d $rootdir$MESH_INSTALL_DIR/tracker ]; then
507
-        mkdir $rootdir$MESH_INSTALL_DIR/tracker
508
-    fi
509
-    chroot "$rootdir" chown -R tracker:tracker $MESH_INSTALL_DIR/tracker
490
+    { echo '[Unit]';
491
+      echo 'Description=Torrent Tracker';
492
+      echo 'After=syslog.target';
493
+      echo 'After=network.target';
494
+      echo '[Service]';
495
+      echo 'Type=simple';
496
+      echo 'User=tracker';
497
+      echo 'Group=tracker';
498
+      echo "WorkingDirectory=$MESH_INSTALL_DIR/tracker";
499
+      echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile $MESH_INSTALL_DIR/tracker/dstate --logfile $MESH_INSTALL_DIR/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0";
500
+      echo '';
501
+      echo 'TimeoutSec=300';
502
+      echo '';
503
+      echo '[Install]';
504
+      echo 'WantedBy=multi-user.target'; } > "$TRACKER_DAEMON"
505
+
506
+    chroot "$rootdir" useradd -d "$MESH_INSTALL_DIR/tracker/" -s /bin/false tracker
507
+    if [ ! -d "$rootdir$MESH_INSTALL_DIR/tracker" ]; then
508
+        mkdir "$rootdir$MESH_INSTALL_DIR/tracker"
509
+    fi
510
+    chroot "$rootdir" chown -R tracker:tracker "$MESH_INSTALL_DIR/tracker"
510 511
 
511 512
     # publish regularly
512 513
     MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
513
-    echo '#!/bin/bash' > $MESH_SYNC_COMMAND
514
-    echo '/usr/local/bin/toxavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
515
-    echo '/usr/local/bin/meshavahi 2> /dev/null' >> $MESH_SYNC_COMMAND
516
-    chmod +x $MESH_SYNC_COMMAND
514
+    { echo '#!/bin/bash';
515
+      echo '/usr/local/bin/toxavahi 2> /dev/null';
516
+      echo '/usr/local/bin/meshavahi 2> /dev/null'; } > "$MESH_SYNC_COMMAND"
517
+    chmod +x "$MESH_SYNC_COMMAND"
517 518
 
518
-    if ! grep -q "mesh-sync" ${rootdir}/etc/crontab; then
519
-        echo "*/1            * *   *   *   root /usr/bin/mesh-sync 2> /dev/null" >> ${rootdir}/etc/crontab
520
-        echo "*/1            * *   *   *   root ( sleep 20 ; /usr/bin/mesh-sync 2> /dev/null )" >> ${rootdir}/etc/crontab
521
-        echo "*/1            * *   *   *   root ( sleep 40 ; /usr/bin/mesh-sync 2> /dev/null )" >> ${rootdir}/etc/crontab
519
+    if ! grep -q "mesh-sync" "${rootdir}/etc/crontab"; then
520
+        { echo "*/1            * *   *   *   root /usr/bin/mesh-sync 2> /dev/null";
521
+          echo "*/1            * *   *   *   root ( sleep 20 ; /usr/bin/mesh-sync 2> /dev/null )";
522
+          echo "*/1            * *   *   *   root ( sleep 40 ; /usr/bin/mesh-sync 2> /dev/null )"; } >> "${rootdir}/etc/crontab"
522 523
     fi
523 524
 
524 525
     chroot "$rootdir" systemctl enable tracker.service
@@ -526,95 +527,95 @@ function mesh_zeronet {
526 527
 }
527 528
 
528 529
 function mesh_zeronet_blog {
529
-    ZERONET_BLOG_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_BLOG_REPO=" | head -n 1 | awk -F '"' '{print $2}')
530
-    ZERONET_BLOG_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_BLOG_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
531
-    MESH_INSTALL_DIR_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "MESH_INSTALL_DIR=" | head -n 1 | awk -F "'" '{print $2}')
530
+    ZERONET_BLOG_REPO=$(grep "ZERONET_BLOG_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F '"' '{print $2}')
531
+    ZERONET_BLOG_COMMIT=$(grep "ZERONET_BLOG_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
532
+    MESH_INSTALL_DIR_MAIN=$(grep "MESH_INSTALL_DIR=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
532 533
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
533 534
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
534 535
     fi
535
-    if [ ! $MESH_INSTALL_DIR ]; then
536
+    if [ ! "$MESH_INSTALL_DIR" ]; then
536 537
         echo $'No mesh install dir was specified'
537 538
         exit 432052
538 539
     fi
539 540
 
540
-    git clone $ZERONET_BLOG_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog
541
-    if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog ]; then
541
+    git clone "$ZERONET_BLOG_REPO" "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog"
542
+    if [ ! -d "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog" ]; then
542 543
         echo $'ZeroBlog repo could not be cloned'
543 544
         exit 6739
544 545
     fi
545
-    cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog
546
-    git checkout $ZERONET_BLOG_COMMIT -b $ZERONET_BLOG_COMMIT
547
-    chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
546
+    cd "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroBlog" || exit 247824628
547
+    git checkout "$ZERONET_BLOG_COMMIT" -b "$ZERONET_BLOG_COMMIT"
548
+    chroot "$rootdir" chown -R zeronet:zeronet "$MESH_INSTALL_DIR/zeronet"
548 549
 }
549 550
 
550 551
 function mesh_zeronet_mail {
551
-    ZERONET_MAIL_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_MAIL_REPO=" | head -n 1 | awk -F '"' '{print $2}')
552
-    ZERONET_MAIL_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_MAIL_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
553
-    MESH_INSTALL_DIR_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "MESH_INSTALL_DIR=" | head -n 1 | awk -F "'" '{print $2}')
552
+    ZERONET_MAIL_REPO=$(grep "ZERONET_MAIL_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F '"' '{print $2}')
553
+    ZERONET_MAIL_COMMIT=$(grep "ZERONET_MAIL_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
554
+    MESH_INSTALL_DIR_MAIN=$(grep "MESH_INSTALL_DIR=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
554 555
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
555 556
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
556 557
     fi
557
-    if [ ! $MESH_INSTALL_DIR ]; then
558
+    if [ ! "$MESH_INSTALL_DIR" ]; then
558 559
         echo $'No mesh install dir was specified'
559 560
         exit 432052
560 561
     fi
561 562
 
562
-    git clone $ZERONET_MAIL_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail
563
-    if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail ]; then
563
+    git clone "$ZERONET_MAIL_REPO" "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail"
564
+    if [ ! -d "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail" ]; then
564 565
         echo $'ZeroMail repo could not be cloned'
565 566
         exit 78493
566 567
     fi
567
-    cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail
568
-    git checkout $ZERONET_MAIL_COMMIT -b $ZERONET_MAIL_COMMIT
569
-    chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
568
+    cd "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroMail" || exit 2467824628
569
+    git checkout "$ZERONET_MAIL_COMMIT" -b "$ZERONET_MAIL_COMMIT"
570
+    chroot "$rootdir" chown -R zeronet:zeronet "$MESH_INSTALL_DIR/zeronet"
570 571
 }
571 572
 
572 573
 function mesh_zeronet_forum {
573
-    ZERONET_FORUM_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_FORUM_REPO=" | head -n 1 | awk -F '"' '{print $2}')
574
-    ZERONET_FORUM_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_FORUM_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
575
-    MESH_INSTALL_DIR_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "MESH_INSTALL_DIR=" | head -n 1 | awk -F "'" '{print $2}')
574
+    ZERONET_FORUM_REPO=$(grep "ZERONET_FORUM_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F '"' '{print $2}')
575
+    ZERONET_FORUM_COMMIT=$(grep "ZERONET_FORUM_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
576
+    MESH_INSTALL_DIR_MAIN=$(grep "MESH_INSTALL_DIR=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
576 577
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
577 578
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
578 579
     fi
579
-    if [ ! $MESH_INSTALL_DIR ]; then
580
+    if [ ! "$MESH_INSTALL_DIR" ]; then
580 581
         echo $'No mesh install dir was specified'
581 582
         exit 432052
582 583
     fi
583 584
 
584
-    git clone $ZERONET_FORUM_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk
585
-    if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk ]; then
585
+    git clone "$ZERONET_FORUM_REPO" "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk"
586
+    if [ ! -d "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk" ]; then
586 587
         echo $'ZeroTalk repo could not be cloned'
587 588
         exit 78252
588 589
     fi
589
-    cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk
590
-    git checkout $ZERONET_FORUM_COMMIT -b $ZERONET_FORUM_COMMIT
591
-    chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
590
+    cd "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroTalk" || exit 246824628
591
+    git checkout "$ZERONET_FORUM_COMMIT" -b "$ZERONET_FORUM_COMMIT"
592
+    chroot "$rootdir" chown -R zeronet:zeronet "$MESH_INSTALL_DIR/zeronet"
592 593
 }
593 594
 
594 595
 function mesh_zeronet_id {
595
-    ZERONET_ID_REPO=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_ID_REPO=" | head -n 1 | awk -F '"' '{print $2}')
596
-    ZERONET_ID_COMMIT=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_ID_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
597
-    MESH_INSTALL_DIR_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "MESH_INSTALL_DIR=" | head -n 1 | awk -F "'" '{print $2}')
596
+    ZERONET_ID_REPO=$(grep "ZERONET_ID_REPO=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F '"' '{print $2}')
597
+    ZERONET_ID_COMMIT=$(grep "ZERONET_ID_COMMIT=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
598
+    MESH_INSTALL_DIR_MAIN=$(grep "MESH_INSTALL_DIR=" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet" | head -n 1 | awk -F "'" '{print $2}')
598 599
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
599 600
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
600 601
     fi
601
-    if [ ! $MESH_INSTALL_DIR ]; then
602
+    if [ ! "$MESH_INSTALL_DIR" ]; then
602 603
         echo $'No mesh install dir was specified'
603 604
         exit 432052
604 605
     fi
605 606
 
606
-    git clone $ZERONET_ID_REPO $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID
607
-    if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID ]; then
607
+    git clone "$ZERONET_ID_REPO" "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroID"
608
+    if [ ! -d "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroID" ]; then
608 609
         echo $'ZeroID repo could not be cloned'
609 610
         exit 37936
610 611
     fi
611
-    cd $rootdir$MESH_INSTALL_DIR/zeronet/ZeroID
612
-    git checkout $ZERONET_ID_COMMIT -b $ZERONET_ID_COMMIT
613
-    chroot "$rootdir" chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
612
+    cd "$rootdir$MESH_INSTALL_DIR/zeronet/ZeroID" || exit 8723563244
613
+    git checkout "$ZERONET_ID_COMMIT" -b "$ZERONET_ID_COMMIT"
614
+    chroot "$rootdir" chown -R zeronet:zeronet "$MESH_INSTALL_DIR/zeronet"
614 615
 }
615 616
 
616 617
 function install_zeronet {
617
-    if [ $INSTALLING_MESH ]; then
618
+    if [ "$INSTALLING_MESH" ]; then
618 619
         mesh_zeronet
619 620
         mesh_zeronet_blog
620 621
         mesh_zeronet_mail

+ 8
- 8
src/freedombone-archive-mail Просмотреть файл

@@ -33,34 +33,34 @@ PROJECT_NAME='freedombone'
33 33
 export TEXTDOMAIN=${PROJECT_NAME}-archive-mail
34 34
 export TEXTDOMAINDIR="/usr/share/locale"
35 35
 
36
-source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-validation
36
+source "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-validation"
37 37
 
38 38
 for d in /home/*/ ; do
39 39
     USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
40 40
     if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
41 41
         # for every user who has a mail directory
42
-        if [ -d /home/$USERNAME/Maildir ]; then
42
+        if [ -d "/home/$USERNAME/Maildir" ]; then
43 43
             MUTTRC=/home/$USERNAME/.muttrc
44 44
             # update archives
45 45
             python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""
46 46
             # ensure the user has permissions on the archives
47 47
             for archive_dir in /home/$USERNAME/Maildir/archive-* ; do
48
-                chown -R $USERNAME:$USERNAME $archive_dir
48
+                chown -R "$USERNAME":"$USERNAME" "$archive_dir"
49 49
             done
50 50
             # add the archive to .muttrc if needed
51
-            if [ -f $MUTTRC ]; then
52
-                MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
51
+            if [ -f "$MUTTRC" ]; then
52
+                MUTT_MAILBOXES=$(grep "mailboxes =" "$MUTTRC")
53 53
                 YR=$(date +"%Y")
54 54
                 PREV_YR=$((YR - 1))
55 55
                 BACKUP_DIRECTORY=archive-$YR
56 56
                 PREV_BACKUP_DIRECTORY=archive-$PREV_YR
57 57
                 if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
58 58
                     if [[ $MUTT_MAILBOXES == *$PREV_BACKUP_DIRECTORY* ]]; then
59
-                        sed -i "s|$PREV_BACKUP_DIRECTORY|$PREV_BACKUP_DIRECTORY =$BACKUP_DIRECTORY|g" $MUTTRC
59
+                        sed -i "s|$PREV_BACKUP_DIRECTORY|$PREV_BACKUP_DIRECTORY =$BACKUP_DIRECTORY|g" "$MUTTRC"
60 60
                     else
61
-                        sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC
61
+                        sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" "$MUTTRC"
62 62
                     fi
63
-                    chown $USERNAME:$USERNAME $MUTTRC
63
+                    chown "$USERNAME":"$USERNAME" "$MUTTRC"
64 64
                 fi
65 65
             fi
66 66
         fi

+ 61
- 60
src/freedombone-backup-local Просмотреть файл

@@ -59,13 +59,13 @@ function please_wait {
59 59
 
60 60
 please_wait
61 61
 
62
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
62
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
63 63
 
64 64
 # include utils which allow function_check and drive mount
65
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
65
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
66 66
 for f in $UTILS_FILES
67 67
 do
68
-  source $f
68
+    source "$f"
69 69
 done
70 70
 
71 71
 clear
@@ -82,7 +82,7 @@ ADMIN_NAME=
82 82
 # Sites are suspended so that verification should work
83 83
 SUSPENDED_SITE=
84 84
 
85
-DATABASE_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
85
+DATABASE_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
86 86
 
87 87
 function make_backup_directory {
88 88
     # make a backup directory on the drive
@@ -100,7 +100,7 @@ function make_backup_directory {
100 100
 function check_storage_space_remaining {
101 101
     # Check space remaining on the usb drive
102 102
     used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}')
103
-    if [ $used_percent -gt 95 ]; then
103
+    if [ "$used_percent" -gt 95 ]; then
104 104
         echo $"Less than 5% of space remaining on backup drive"
105 105
         umount $USB_MOUNT
106 106
         rm -rf $USB_MOUNT
@@ -114,105 +114,105 @@ function backup_users {
114 114
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
115 115
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
116 116
             # Backup any gpg keys
117
-            if [ -d /home/$USERNAME/.gnupg ]; then
117
+            if [ -d "/home/$USERNAME/.gnupg" ]; then
118 118
                 echo $"Backing up gpg keys for $USERNAME"
119
-                backup_directory_to_usb /home/$USERNAME/.gnupg gnupg/$USERNAME
119
+                backup_directory_to_usb "/home/$USERNAME/.gnupg" "gnupg/$USERNAME"
120 120
             fi
121 121
 
122 122
             # Backup any personal settings
123
-            if [ -d /home/$USERNAME/personal ]; then
123
+            if [ -d "/home/$USERNAME/personal" ]; then
124 124
                 echo $"Backing up personal settings for $USERNAME"
125
-                backup_directory_to_usb /home/$USERNAME/personal personal/$USERNAME
125
+                backup_directory_to_usb "/home/$USERNAME/personal" "personal/$USERNAME"
126 126
             fi
127 127
 
128 128
             # Backup ssh keys
129
-            if [ -d /home/$USERNAME/.ssh ]; then
129
+            if [ -d "/home/$USERNAME/.ssh" ]; then
130 130
                 echo $"Backing up ssh keys for $USERNAME"
131
-                backup_directory_to_usb /home/$USERNAME/.ssh ssh/$USERNAME
131
+                backup_directory_to_usb "/home/$USERNAME/.ssh" "ssh/$USERNAME"
132 132
             fi
133 133
 
134 134
             # Backup fin database if it exists
135
-            if [ -d /home/$USERNAME/.fin ]; then
135
+            if [ -d "/home/$USERNAME/.fin" ]; then
136 136
                 echo $"Backing up fin files for $USERNAME"
137
-                backup_directory_to_usb /home/$USERNAME/.fin fin/$USERNAME
137
+                backup_directory_to_usb "/home/$USERNAME/.fin" "fin/$USERNAME"
138 138
             fi
139 139
 
140 140
             # Backup emacs
141
-            if [ -d /home/$USERNAME/.emacs.d ]; then
141
+            if [ -d "/home/$USERNAME/.emacs.d" ]; then
142 142
                 echo $"Backing up Emacs config for $USERNAME"
143
-                if [ -f /home/$USERNAME/.emacs ]; then
144
-                    cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
143
+                if [ -f "/home/$USERNAME/.emacs" ]; then
144
+                    cp "/home/$USERNAME/.emacs" "/home/$USERNAME/.emacs.d/dotemacs"
145 145
                 fi
146
-                backup_directory_to_usb /home/$USERNAME/.emacs.d config/$USERNAME
146
+                backup_directory_to_usb "/home/$USERNAME/.emacs.d" "config/$USERNAME"
147 147
             fi
148 148
 
149 149
             # Backup user configs
150
-            if [ -d /home/$USERNAME/.config ]; then
150
+            if [ -d "/home/$USERNAME/.config" ]; then
151 151
                 echo $"Backing up config files for $USERNAME"
152
-                backup_directory_to_usb /home/$USERNAME/.config config/$USERNAME
152
+                backup_directory_to_usb "/home/$USERNAME/.config" "config/$USERNAME"
153 153
             fi
154 154
 
155 155
             # Backup monkeysphere
156
-            if [ -d /home/$USERNAME/.monkeysphere ]; then
156
+            if [ -d "/home/$USERNAME/.monkeysphere" ]; then
157 157
                 echo $"Backing up monkeysphere files for $USERNAME"
158
-                backup_directory_to_usb /home/$USERNAME/.monkeysphere monkeysphere/$USERNAME
158
+                backup_directory_to_usb "/home/$USERNAME/.monkeysphere" "monkeysphere/$USERNAME"
159 159
             fi
160 160
 
161 161
             # Backup user local
162
-            if [ -d /home/$USERNAME/.local ]; then
162
+            if [ -d "/home/$USERNAME/.local" ]; then
163 163
                 echo $"Backing up local files for $USERNAME"
164
-                backup_directory_to_usb /home/$USERNAME/.local local/$USERNAME
164
+                backup_directory_to_usb "/home/$USERNAME/.local" "local/$USERNAME"
165 165
             fi
166 166
 
167 167
             # Backup mutt
168
-            if [ -f /home/$USERNAME/.muttrc ]; then
168
+            if [ -f "/home/$USERNAME/.muttrc" ]; then
169 169
                 echo $"Backing up Mutt settings for $USERNAME"
170
-                if [ ! -d /home/$USERNAME/tempbackup ]; then
171
-                    mkdir -p /home/$USERNAME/tempbackup
170
+                if [ ! -d "/home/$USERNAME/tempbackup" ]; then
171
+                    mkdir -p "/home/$USERNAME/tempbackup"
172 172
                 fi
173
-                cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
173
+                cp "/home/$USERNAME/.muttrc" "/home/$USERNAME/tempbackup"
174 174
                 if [ -f /etc/Muttrc ]; then
175
-                    cp /etc/Muttrc /home/$USERNAME/tempbackup
175
+                    cp /etc/Muttrc "/home/$USERNAME/tempbackup"
176 176
                 fi
177
-                backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
177
+                backup_directory_to_usb "/home/$USERNAME/tempbackup" "mutt/$USERNAME"
178 178
             fi
179
-            if [ -d /home/$USERNAME/.mutt ]; then
179
+            if [ -d "/home/$USERNAME/.mutt" ]; then
180 180
                 echo $"Backing up Mutt configurations for $USERNAME"
181
-                backup_directory_to_usb /home/$USERNAME/.mutt mutt/${USERNAME}configs
181
+                backup_directory_to_usb "/home/$USERNAME/.mutt" "mutt/${USERNAME}configs"
182 182
             fi
183 183
 
184 184
             # Backup email
185
-            if [ -d /home/$USERNAME/Maildir ]; then
185
+            if [ -d "/home/$USERNAME/Maildir" ]; then
186 186
                 echo $"Stopping mail server"
187 187
                 systemctl stop exim4
188 188
                 echo $"Creating an email archive for $USERNAME"
189
-                if [ ! -d /root/tempbackupemail/$USERNAME ]; then
190
-                    mkdir -p /root/tempbackupemail/$USERNAME
189
+                if [ ! -d "/root/tempbackupemail/$USERNAME" ]; then
190
+                    mkdir -p "/root/tempbackupemail/$USERNAME"
191 191
                 fi
192
-                tar -czvf /root/tempbackupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
192
+                tar -czvf "/root/tempbackupemail/$USERNAME/maildir.tar.gz" "/home/$USERNAME/Maildir"
193 193
                 echo $"Restarting mail server"
194 194
                 systemctl start exim4
195 195
                 echo $"Backing up emails for $USERNAME"
196
-                backup_directory_to_usb /root/tempbackupemail/$USERNAME mail/$USERNAME
196
+                backup_directory_to_usb "/root/tempbackupemail/$USERNAME" "mail/$USERNAME"
197 197
             fi
198 198
 
199 199
             # Backup spamassassin
200
-            if [ -d /home/$USERNAME/.spamassassin ]; then
200
+            if [ -d "/home/$USERNAME/.spamassassin" ]; then
201 201
                 echo $"Backing up spamassassin settings for $USERNAME"
202
-                backup_directory_to_usb /home/$USERNAME/.spamassassin spamassassin/$USERNAME
202
+                backup_directory_to_usb "/home/$USERNAME/.spamassassin" "spamassassin/$USERNAME"
203 203
             fi
204 204
 
205 205
             # Backup procmail
206
-            if [ -f /home/$USERNAME/.procmailrc ]; then
206
+            if [ -f "/home/$USERNAME/.procmailrc" ]; then
207 207
                 echo $"Backing up procmail settings for $USERNAME"
208
-                if [ ! -d /home/$USERNAME/tempbackup ]; then
209
-                    mkdir -p /home/$USERNAME/tempbackup
208
+                if [ ! -d "/home/$USERNAME/tempbackup" ]; then
209
+                    mkdir -p "/home/$USERNAME/tempbackup"
210 210
                 fi
211
-                cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
212
-                backup_directory_to_usb /home/$USERNAME/tempbackup procmail/$USERNAME
211
+                cp "/home/$USERNAME/.procmailrc" "/home/$USERNAME/tempbackup"
212
+                backup_directory_to_usb "/home/$USERNAME/tempbackup" "procmail/$USERNAME"
213 213
             fi
214 214
 
215
-            gpg_agent_enable $USERNAME
215
+            gpg_agent_enable "$USERNAME"
216 216
         fi
217 217
     done
218 218
 }
@@ -231,11 +231,11 @@ function backup_directories {
231 231
     for dr in "${backup_dirs[@]}"
232 232
     do
233 233
         # if this directory exists then back it up to the given destination
234
-        source_directory=$(echo $dr | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
235
-        if [ -d $source_directory ]; then
236
-            dest_directory=$(echo $dr | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
234
+        source_directory=$(echo "$dr" | awk -F ',' '{print $1}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
235
+        if [ -d "$source_directory" ]; then
236
+            dest_directory=$(echo "$dr" | awk -F ',' '{print $2}'  | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
237 237
             echo $"Backing up $source_directory to $dest_directory"
238
-            backup_directory_to_usb $source_directory $dest_directory
238
+            backup_directory_to_usb "$source_directory" "$dest_directory"
239 239
         fi
240 240
 
241 241
         restart_site
@@ -243,8 +243,8 @@ function backup_directories {
243 243
 }
244 244
 
245 245
 function remove_backup_directory {
246
-    if [ $1 ]; then
247
-        if [[ $1 == "remove" ]]; then
246
+    if [ "$1" ]; then
247
+        if [[ "$1" == "remove" ]]; then
248 248
             if [ -d $USB_MOUNT/backup ]; then
249 249
                 rm -rf $USB_MOUNT/backup
250 250
                 echo $'Existing backup directory removed'
@@ -274,7 +274,7 @@ function backup_blocklist {
274 274
     if [ ! -d $temp_backup_dir ]; then
275 275
         mkdir -p $temp_backup_dir
276 276
     fi
277
-    if [ -f $NODEJS_INSTALLED_APPS_FILE ]; then
277
+    if [ -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
278 278
         cp -f /root/${PROJECT_NAME}-firewall-domains.cfg $temp_backup_dir
279 279
     fi
280 280
     backup_directory_to_usb $temp_backup_dir blocklist
@@ -287,8 +287,8 @@ function backup_configfiles {
287 287
     if [ ! -d $temp_backup_dir ]; then
288 288
         mkdir -p $temp_backup_dir
289 289
     fi
290
-    if [ -f $NODEJS_INSTALLED_APPS_FILE ]; then
291
-        cp -f $NODEJS_INSTALLED_APPS_FILE $temp_backup_dir
290
+    if [ -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
291
+        cp -f "$NODEJS_INSTALLED_APPS_FILE" $temp_backup_dir
292 292
     fi
293 293
     if [ -f /root/.nostore ]; then
294 294
         cp -f /root/.nostore $temp_backup_dir
@@ -297,13 +297,13 @@ function backup_configfiles {
297 297
             rm $temp_backup_dir/.nostore
298 298
         fi
299 299
     fi
300
-    cp -f $CONFIGURATION_FILE $temp_backup_dir
301
-    cp -f $COMPLETION_FILE $temp_backup_dir
300
+    cp -f "$CONFIGURATION_FILE" $temp_backup_dir
301
+    cp -f "$COMPLETION_FILE" $temp_backup_dir
302 302
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
303 303
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
304 304
     fi
305
-    if [ -f $MONGODB_APPS_FILE ]; then
306
-        cp -f $MONGODB_APPS_FILE $temp_backup_dir
305
+    if [ -f "$MONGODB_APPS_FILE" ]; then
306
+        cp -f "$MONGODB_APPS_FILE" $temp_backup_dir
307 307
     fi
308 308
     # nginx password hashes
309 309
     if [ -f /etc/nginx/.htpasswd ]; then
@@ -355,7 +355,8 @@ function backup_postgresql {
355 355
     if [ ! -d $temp_backup_dir ]; then
356 356
         mkdir $temp_backup_dir
357 357
     fi
358
-    sudo -u postgres pg_dumpall --roles-only > $temp_backup_dir/postgresql.sql
358
+    # shellcheck disable=SC2024
359
+    sudo -u postgres pg_dumpall --roles-only > "$temp_backup_dir/postgresql.sql"
359 360
     if [ ! -s $temp_backup_dir/postgresql.sql ]; then
360 361
         echo $"Unable to backup postgresql settings"
361 362
         rm -rf $temp_backup_dir
@@ -375,8 +376,8 @@ if [[ $1 == "remove" ]]; then
375 376
 fi
376 377
 
377 378
 gpg_agent_setup root
378
-backup_mount_drive $1 $2
379
-remove_backup_directory $remove_option
379
+backup_mount_drive "$1" "$2"
380
+remove_backup_directory "$remove_option"
380 381
 make_backup_directory
381 382
 check_storage_space_remaining
382 383
 backup_users

+ 93
- 91
src/freedombone-backup-remote Просмотреть файл

@@ -43,20 +43,20 @@ if [ -f /usr/bin/${PROJECT_NAME} ]; then
43 43
     PROJECT_INSTALL_DIR=/usr/bin
44 44
 fi
45 45
 
46
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
46
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
47 47
 
48 48
 # utilities needed for backup commands
49
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
49
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
50 50
 for f in $UTILS_FILES
51 51
 do
52
-  source $f
52
+    source "$f"
53 53
 done
54 54
 
55 55
 # Temporary location for data to be backed up to other servers
56 56
 SERVER_DIRECTORY=/root/remotebackup
57 57
 
58 58
 # get the version of Go being used
59
-GO_VERSION=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go | grep 'GO_VERSION=' | head -n 1 | awk -F '=' '{print $2}')
59
+GO_VERSION=$(grep 'GO_VERSION=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-go" | head -n 1 | awk -F '=' '{print $2}')
60 60
 
61 61
 ADMIN_USERNAME=$(get_completion_param "Admin user")
62 62
 ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
@@ -66,7 +66,7 @@ if [ ! -f /etc/ssl/private/backup.key ]; then
66 66
     ${PROJECT_NAME}-addcert -h backup --dhkey 2048
67 67
 fi
68 68
 
69
-if [ ! -f /home/${ADMIN_USERNAME}/backup.list ]; then
69
+if [ ! -f "/home/${ADMIN_USERNAME}/backup.list" ]; then
70 70
     exit 1
71 71
 fi
72 72
 
@@ -92,16 +92,16 @@ function suspend_site {
92 92
         return
93 93
     fi
94 94
     SUSPENDED_SITE="$1"
95
-    nginx_dissite $SUSPENDED_SITE
95
+    nginx_dissite "$SUSPENDED_SITE"
96 96
     systemctl reload nginx
97 97
 }
98 98
 
99 99
 function restart_site {
100 100
     # restarts a given website
101
-    if [ ! $SUSPENDED_SITE ]; then
101
+    if [ ! "$SUSPENDED_SITE" ]; then
102 102
         return
103 103
     fi
104
-    nginx_ensite $SUSPENDED_SITE
104
+    nginx_ensite "$SUSPENDED_SITE"
105 105
     systemctl reload nginx
106 106
     SUSPENDED_SITE=
107 107
 }
@@ -115,7 +115,7 @@ function backup_blocklist {
115 115
     if [ ! -d $temp_backup_dir ]; then
116 116
         mkdir -p $temp_backup_dir
117 117
     fi
118
-    if [ -f $NODEJS_INSTALLED_APPS_FILE ]; then
118
+    if [ -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
119 119
         cp -f /root/${PROJECT_NAME}-firewall-domains.cfg $temp_backup_dir
120 120
     fi
121 121
     backup_directory_to_friend $temp_backup_dir blocklist
@@ -128,8 +128,8 @@ function backup_configfiles {
128 128
     if [ ! -d $temp_backup_dir ]; then
129 129
         mkdir -p $temp_backup_dir
130 130
     fi
131
-    if [ -f $NODEJS_INSTALLED_APPS_FILE ]; then
132
-        cp -f $NODEJS_INSTALLED_APPS_FILE $temp_backup_dir
131
+    if [ -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
132
+        cp -f "$NODEJS_INSTALLED_APPS_FILE" $temp_backup_dir
133 133
     fi
134 134
     if [ -f /root/.nostore ]; then
135 135
         cp -f /root/.nostore $temp_backup_dir
@@ -138,13 +138,13 @@ function backup_configfiles {
138 138
             rm $temp_backup_dir/.nostore
139 139
         fi
140 140
     fi
141
-    cp -f $CONFIGURATION_FILE $temp_backup_dir
142
-    cp -f $COMPLETION_FILE $temp_backup_dir
141
+    cp -f "$CONFIGURATION_FILE" $temp_backup_dir
142
+    cp -f "$COMPLETION_FILE" $temp_backup_dir
143 143
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
144 144
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
145 145
     fi
146
-    if [ -f $MONGODB_APPS_FILE ]; then
147
-        cp -f $MONGODB_APPS_FILE $temp_backup_dir
146
+    if [ -f "$MONGODB_APPS_FILE" ]; then
147
+        cp -f "$MONGODB_APPS_FILE" $temp_backup_dir
148 148
     fi
149 149
     # nginx password hashes
150 150
     if [ -f /etc/nginx/.htpasswd ]; then
@@ -158,114 +158,114 @@ function backup_users {
158 158
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
159 159
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
160 160
             # personal settings
161
-            if [ -d /home/$USERNAME/personal ]; then
161
+            if [ -d "/home/$USERNAME/personal" ]; then
162 162
                 echo $"Backing up personal settings for $USERNAME"
163
-                backup_directory_to_friend /home/$USERNAME/personal personal/$USERNAME
163
+                backup_directory_to_friend "/home/$USERNAME/personal" "personal/$USERNAME"
164 164
             fi
165 165
 
166 166
             # gpg keys
167
-            if [ -d /home/$USERNAME/.gnupg ]; then
167
+            if [ -d "/home/$USERNAME/.gnupg" ]; then
168 168
                 echo $"Backing up gpg keys for $USERNAME"
169
-                backup_directory_to_friend /home/$USERNAME/.gnupg gnupg/$USERNAME
169
+                backup_directory_to_friend "/home/$USERNAME/.gnupg" "gnupg/$USERNAME"
170 170
             fi
171 171
 
172 172
             # ssh keys
173
-            if [ -d /home/$USERNAME/.ssh ]; then
173
+            if [ -d "/home/$USERNAME/.ssh" ]; then
174 174
                 echo $"Backing up ssh keys for $USERNAME"
175
-                backup_directory_to_friend /home/$USERNAME/.ssh ssh/$USERNAME
175
+                backup_directory_to_friend "/home/$USERNAME/.ssh" "ssh/$USERNAME"
176 176
             fi
177 177
 
178 178
             # syncthing files
179
-            if [ -d /home/$USERNAME/Sync ]; then
179
+            if [ -d "/home/$USERNAME/Sync" ]; then
180 180
                 echo $"Backing up syncthing files for $USERNAME"
181
-                backup_directory_to_friend /home/$USERNAME/Sync syncthing/$USERNAME
181
+                backup_directory_to_friend "/home/$USERNAME/Sync" "syncthing/$USERNAME"
182 182
                 # ensure that device IDs will be backed up as part of user config settings
183
-                if [ ! -d /home/$USERNAME/.config/syncthing ]; then
184
-                    mkdir -p /home/$USERNAME/.config/syncthing
185
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
183
+                if [ ! -d "/home/$USERNAME/.config/syncthing" ]; then
184
+                    mkdir -p "/home/$USERNAME/.config/syncthing"
185
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
186 186
                 fi
187
-                if [ -f /home/$USERNAME/.syncthing-server-id ]; then
188
-                    cp /home/$USERNAME/.syncthing-server-id /home/$USERNAME/.config/syncthing
189
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
187
+                if [ -f "/home/$USERNAME/.syncthing-server-id" ]; then
188
+                    cp "/home/$USERNAME/.syncthing-server-id" "/home/$USERNAME/.config/syncthing"
189
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
190 190
                 fi
191
-                if [ -f /home/$USERNAME/.syncthingids ]; then
192
-                    cp /home/$USERNAME/.syncthingids /home/$USERNAME/.config/syncthing
193
-                    chown -R $USERNAME:$USERNAME /home/$USERNAME/.config
191
+                if [ -f "/home/$USERNAME/.syncthingids" ]; then
192
+                    cp "/home/$USERNAME/.syncthingids" "/home/$USERNAME/.config/syncthing"
193
+                    chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.config"
194 194
                 fi
195 195
             fi
196 196
 
197 197
             # config files
198
-            if [ -d /home/$USERNAME/.config ]; then
198
+            if [ -d "/home/$USERNAME/.config" ]; then
199 199
                 echo $"Backing up config files for $USERNAME"
200
-                backup_directory_to_friend /home/$USERNAME/.config config/$USERNAME
200
+                backup_directory_to_friend "/home/$USERNAME/.config" "config/$USERNAME"
201 201
             fi
202 202
 
203 203
             # monkeysphere files
204
-            if [ -d /home/$USERNAME/.monkeysphere ]; then
204
+            if [ -d "/home/$USERNAME/.monkeysphere" ]; then
205 205
                 echo $"Backing up monkeysphere files for $USERNAME"
206
-                backup_directory_to_friend /home/$USERNAME/.monkeysphere monkeysphere/$USERNAME
206
+                backup_directory_to_friend "/home/$USERNAME/.monkeysphere" "monkeysphere/$USERNAME"
207 207
             fi
208 208
 
209 209
             # fin files
210
-            if [ -d /home/$USERNAME/.fin ]; then
210
+            if [ -d "/home/$USERNAME/.fin" ]; then
211 211
                 echo $"Backing up fin files for $USERNAME"
212
-                backup_directory_to_friend /home/$USERNAME/.fin fin/$USERNAME
212
+                backup_directory_to_friend "/home/$USERNAME/.fin" "fin/$USERNAME"
213 213
             fi
214 214
 
215 215
             # local files
216
-            if [ -d /home/$USERNAME/.local ]; then
216
+            if [ -d "/home/$USERNAME/.local" ]; then
217 217
                 echo $"Backing up local files for $USERNAME"
218
-                backup_directory_to_friend /home/$USERNAME/.local local/$USERNAME
218
+                backup_directory_to_friend "/home/$USERNAME/.local" "local/$USERNAME"
219 219
             fi
220 220
 
221 221
             # mutt settings
222
-            if [ -f /home/$USERNAME/.muttrc ]; then
222
+            if [ -f "/home/$USERNAME/.muttrc" ]; then
223 223
                 echo $"Backing up Mutt settings for $USERNAME"
224
-                if [ ! -d /home/$USERNAME/tempbackup ]; then
225
-                    mkdir -p /home/$USERNAME/tempbackup
224
+                if [ ! -d "/home/$USERNAME/tempbackup" ]; then
225
+                    mkdir -p "/home/$USERNAME/tempbackup"
226 226
                 fi
227
-                cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
227
+                cp "/home/$USERNAME/.muttrc" "/home/$USERNAME/tempbackup"
228 228
                 if [ -f /etc/Muttrc ]; then
229
-                    cp /etc/Muttrc /home/$USERNAME/tempbackup
229
+                    cp /etc/Muttrc "/home/$USERNAME/tempbackup"
230 230
                 fi
231
-                backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME
231
+                backup_directory_to_friend "/home/$USERNAME/tempbackup" "mutt/$USERNAME"
232 232
             fi
233
-            if [ -d /home/$USERNAME/.mutt ]; then
233
+            if [ -d "/home/$USERNAME/.mutt" ]; then
234 234
                 echo $"Backing up Mutt configurations for $USERNAME"
235
-                backup_directory_to_friend /home/$USERNAME/.mutt mutt/${USERNAME}configs
235
+                backup_directory_to_friend "/home/$USERNAME/.mutt" "mutt/${USERNAME}configs"
236 236
             fi
237 237
 
238 238
             # procmail settings
239
-            if [ -f /home/$USERNAME/.procmailrc ]; then
239
+            if [ -f "/home/$USERNAME/.procmailrc" ]; then
240 240
                 echo $"Backing up procmail settings for $USERNAME"
241
-                if [ ! -d /home/$USERNAME/tempbackup ]; then
242
-                    mkdir -p /home/$USERNAME/tempbackup
241
+                if [ ! -d "/home/$USERNAME/tempbackup" ]; then
242
+                    mkdir -p "/home/$USERNAME/tempbackup"
243 243
                 fi
244
-                cp /home/$USERNAME/.procmailrc /home/$USERNAME/tempbackup
245
-                backup_directory_to_friend /home/$USERNAME/tempbackup procmail/$USERNAME
244
+                cp "/home/$USERNAME/.procmailrc" "/home/$USERNAME/tempbackup"
245
+                backup_directory_to_friend "/home/$USERNAME/tempbackup" "procmail/$USERNAME"
246 246
             fi
247 247
 
248 248
             # spamassassin settings
249
-            if [ -d /home/$USERNAME/.spamassassin ]; then
249
+            if [ -d "/home/$USERNAME/.spamassassin" ]; then
250 250
                 echo $"Backing up spamassassin settings for $USERNAME"
251
-                backup_directory_to_friend /home/$USERNAME/.spamassassin spamassassin/$USERNAME
251
+                backup_directory_to_friend "/home/$USERNAME/.spamassassin" "spamassassin/$USERNAME"
252 252
             fi
253 253
 
254 254
             # email
255
-            if [ -d /home/$USERNAME/Maildir ]; then
255
+            if [ -d "/home/$USERNAME/Maildir" ]; then
256 256
                 echo $"Stopping mail server"
257 257
                 systemctl stop exim4
258 258
                 echo $"Creating an email archive"
259
-                if [ ! -d /root/backupemail/$USERNAME ]; then
260
-                    mkdir -p /root/backupemail/$USERNAME
259
+                if [ ! -d "/root/backupemail/$USERNAME" ]; then
260
+                    mkdir -p "/root/backupemail/$USERNAME"
261 261
                 fi
262
-                tar -czvf /root/backupemail/$USERNAME/maildir.tar.gz /home/$USERNAME/Maildir
262
+                tar -czvf "/root/backupemail/$USERNAME/maildir.tar.gz" "/home/$USERNAME/Maildir"
263 263
                 echo $"Restarting mail server"
264 264
                 systemctl start exim4
265 265
                 echo $"Backing up emails for $USERNAME"
266
-                backup_directory_to_friend /root/backupemail/$USERNAME mail/$USERNAME
266
+                backup_directory_to_friend "/root/backupemail/$USERNAME" "mail/$USERNAME"
267 267
             fi
268
-            gpg_agent_enable $USERNAME
268
+            gpg_agent_enable "$USERNAME"
269 269
         fi
270 270
     done
271 271
 }
@@ -313,13 +313,13 @@ function backup_web_server {
313 313
 }
314 314
 
315 315
 function backup_admin_readme {
316
-    if [ -f /home/$ADMIN_USERNAME/README ]; then
316
+    if [ -f "/home/$ADMIN_USERNAME/README" ]; then
317 317
         echo $"Backing up README"
318
-        if [ ! -d /home/$ADMIN_USERNAME/tempbackup ]; then
319
-            mkdir -p /home/$ADMIN_USERNAME/tempbackup
318
+        if [ ! -d "/home/$ADMIN_USERNAME/tempbackup" ]; then
319
+            mkdir -p "/home/$ADMIN_USERNAME/tempbackup"
320 320
         fi
321
-        cp -f /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/tempbackup
322
-        backup_directory_to_friend /home/$ADMIN_USERNAME/tempbackup readme
321
+        cp -f "/home/$ADMIN_USERNAME/README" "/home/$ADMIN_USERNAME/tempbackup"
322
+        backup_directory_to_friend "/home/$ADMIN_USERNAME/tempbackup" readme
323 323
     fi
324 324
 }
325 325
 
@@ -330,12 +330,12 @@ function backup_mariadb {
330 330
             mkdir $temp_backup_dir
331 331
         fi
332 332
         keep_database_running
333
-        mysqldump --password=$DATABASE_PASSWORD mysql user > $temp_backup_dir/mysql.sql
333
+        mysqldump --password="$DATABASE_PASSWORD" mysql user > "$temp_backup_dir/mysql.sql"
334 334
         if [ ! -s $temp_backup_dir/mysql.sql ]; then
335 335
             echo $"Unable to backup MariaDB settings"
336 336
             rm -rf $temp_backup_dir
337 337
             # Send a warning email
338
-            echo $"Unable to export database settings" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
338
+            echo $"Unable to export database settings" | mail -s "${PROJECT_NAME} backup to friends" "$ADMIN_EMAIL_ADDRESS"
339 339
             exit 653
340 340
         fi
341 341
         echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
@@ -353,12 +353,13 @@ function backup_postgresql {
353 353
     if [ ! -d $temp_backup_dir ]; then
354 354
         mkdir $temp_backup_dir
355 355
     fi
356
-    sudo -u postgres pg_dumpall --roles-only > $temp_backup_dir/postgresql.sql
356
+    # shellcheck disable=SC2024
357
+    sudo -u postgres pg_dumpall --roles-only > "$temp_backup_dir/postgresql.sql"
357 358
     if [ ! -s $temp_backup_dir/postgresql.sql ]; then
358 359
         echo $"Unable to backup postgresql settings"
359 360
         rm -rf $temp_backup_dir
360
-        umount $USB_MOUNT
361
-        rm -rf $USB_MOUNT
361
+        umount "$USB_MOUNT"
362
+        rm -rf "$USB_MOUNT"
362 363
         exit 684365
363 364
     fi
364 365
     echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
@@ -375,10 +376,10 @@ function get_key_share {
375 376
     # Get a share index based on the supplied domain name
376 377
     # This ensures that the same share is always given to the same domain
377 378
     sharenumstr=$(md5sum <<< "$REMOTE_DOMAIN")
378
-    share_index=$(echo $((0x${sharenumstr%% *} % ${no_of_shares})) | tr -d -)
379
+    share_index=$(echo $((0x${sharenumstr%% *} % no_of_shares)) | tr -d -)
379 380
 
380 381
     # get the filename
381
-    share_files=(/home/$USERNAME/.gnupg_fragments/keyshare.asc.*)
382
+    share_files=("/home/$USERNAME/.gnupg_fragments/keyshare.asc.*")
382 383
     share_filename=${share_files[share_index]}
383 384
 
384 385
     echo "$share_filename"
@@ -391,35 +392,37 @@ function disperse_key_shares {
391 392
     REMOTE_PASSWORD=$4
392 393
     REMOTE_SERVER=$5
393 394
 
394
-    if [ -d /home/$USERNAME/.gnupg_fragments ]; then
395
-        if [ $REMOTE_DOMAIN ]; then
396
-            cd /home/$USERNAME/.gnupg_fragments
395
+    if [ -d "/home/$USERNAME/.gnupg_fragments" ]; then
396
+        if [ "$REMOTE_DOMAIN" ]; then
397
+            cd "/home/$USERNAME/.gnupg_fragments" || exit 34687246462
398
+            # shellcheck disable=SC2012
397 399
             no_of_shares=$(ls -afq keyshare.asc.* | wc -l)
398 400
             if (( no_of_shares > 1 )); then
399
-                share_filename=$(get_key_share $no_of_shares "$USERNAME" "$REMOTE_DOMAIN")
401
+                share_filename=$(get_key_share "$no_of_shares" "$USERNAME" "$REMOTE_DOMAIN")
400 402
 
401 403
                 # create a temp directory containing the share
402 404
                 temp_key_share_dir=/home/$USERNAME/tempkey
403 405
                 temp_key_share_fragments=$temp_key_share_dir/.gnupg_fragments_${USERNAME}
404
-                mkdir -p $temp_key_share_fragments
405
-                cp $share_filename $temp_key_share_fragments/
406
+                mkdir -p "$temp_key_share_fragments"
407
+                cp "$share_filename" "$temp_key_share_fragments/"
406 408
 
407 409
                 # copy the fragments directory to the remote server
408 410
                 /usr/bin/sshpass -p "$REMOTE_PASSWORD" \
409
-                                 scp -r -P $REMOTE_SSH_PORT $temp_key_share_fragments $REMOTE_SERVER
411
+                                 scp -r -P "$REMOTE_SSH_PORT" "$temp_key_share_fragments" "$REMOTE_SERVER"
412
+                # shellcheck disable=SC2181
410 413
                 if [ ! "$?" = "0" ]; then
411 414
                     # Send a warning email
412 415
                     echo "Key share to $REMOTE_SERVER failed" | \
413
-                        mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS
416
+                        mail -s "${PROJECT_NAME} social key management" "$MY_EMAIL_ADDRESS"
414 417
                 else
415 418
                     # Send a confirmation email
416 419
                     echo "Key ${share_filename} shared to $REMOTE_SERVER" | \
417
-                        mail -s "${PROJECT_NAME} social key management" $MY_EMAIL_ADDRESS
420
+                        mail -s "${PROJECT_NAME} social key management" "$MY_EMAIL_ADDRESS"
418 421
                 fi
419 422
 
420 423
                 # remove the temp file/directory
421
-                shred -zu $temp_key_share_fragments/*
422
-                rm -rf $temp_key_share_dir
424
+                shred -zu "$temp_key_share_fragments/*"
425
+                rm -rf "$temp_key_share_dir"
423 426
             fi
424 427
         fi
425 428
     fi
@@ -449,13 +452,13 @@ if [[ $TEST_MODE == "no" ]]; then
449 452
 fi
450 453
 
451 454
 # For each remote server
452
-while read remote_server
455
+while read -r remote_server
453 456
 do
454 457
     # Get the server and its password
455 458
     # Format is:
456 459
     #   username@domain <port number> /home/username <ssh password>
457 460
     REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}')
458
-    if [ $REMOTE_SERVER ]; then
461
+    if [ "$REMOTE_SERVER" ]; then
459 462
         REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}')
460 463
         REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
461 464
         REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
@@ -469,23 +472,22 @@ do
469 472
         for d in /home/*/ ; do
470 473
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
471 474
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
472
-                disperse_key_shares $USERNAME $REMOTE_DOMAIN $REMOTE_SSH_PORT "$REMOTE_PASSWORD" $REMOTE_SERVER
475
+                disperse_key_shares "$USERNAME" "$REMOTE_DOMAIN" "$REMOTE_SSH_PORT" "$REMOTE_PASSWORD" "$REMOTE_SERVER"
473 476
             fi
474 477
         done
475 478
 
476 479
         if [[ $TEST_MODE == "yes" ]]; then
477 480
             echo "rsync -ratlzv --rsh=\"/usr/bin/sshpass -p '$REMOTE_PASSWORD' ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no\" $SERVER_DIRECTORY/backup $REMOTE_SERVER"
478 481
         fi
479
-        rsync -ratlzv --rsh="/usr/bin/sshpass -p \"$REMOTE_PASSWORD\" ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $SERVER_DIRECTORY/backup $REMOTE_SERVER
480
-        if [ ! "$?" = "0" ]; then
482
+        if ! rsync -ratlzv --rsh="/usr/bin/sshpass -p \"$REMOTE_PASSWORD\" ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" "$SERVER_DIRECTORY/backup" "$REMOTE_SERVER"; then
481 483
             echo "$NOW Backup to $REMOTE_SERVER failed" >> /var/log/remotebackups.log
482 484
             # Send a warning email
483
-            echo "Backup to $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} backup to friends" $ADMIN_EMAIL_ADDRESS
485
+            echo "Backup to $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} backup to friends" "$ADMIN_EMAIL_ADDRESS"
484 486
         else
485 487
             echo "$NOW Backed up to $REMOTE_SERVER" >> /var/log/remotebackups.log
486 488
         fi
487 489
     fi
488 490
 
489
-done < /home/${ADMIN_USERNAME}/backup.list
491
+done < "/home/${ADMIN_USERNAME}/backup.list"
490 492
 
491 493
 exit 0

+ 560
- 620
src/freedombone-base-email
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 28
- 28
src/freedombone-base-tripwire Просмотреть файл

@@ -37,7 +37,7 @@ function backup_remote_tripwire {
37 37
 }
38 38
 
39 39
 function remove_tripwire {
40
-    if ! grep -Fxq "tripwire" $COMPLETION_FILE; then
40
+    if ! grep -Fxq "tripwire" "$COMPLETION_FILE"; then
41 41
         return
42 42
     fi
43 43
     apt-get -yq remove --purge tripwire
@@ -45,7 +45,7 @@ function remove_tripwire {
45 45
         rm -rf /etc/tripwire
46 46
     fi
47 47
     rm /usr/bin/reset-tripwire
48
-    sed -i '/tripwire/d' $COMPLETION_FILE
48
+    sed -i '/tripwire/d' "$COMPLETION_FILE"
49 49
 }
50 50
 
51 51
 function install_tripwire {
@@ -60,35 +60,35 @@ function install_tripwire {
60 60
 
61 61
     apt-get -yq install tripwire qrencode
62 62
     apt-get -yq autoremove
63
-    cd /etc/tripwire
64
-
65
-    echo 'ROOT          =/usr/sbin' > /etc/tripwire/twcfg.txt
66
-    echo 'POLFILE       =/etc/tripwire/tw.pol' >> /etc/tripwire/twcfg.txt
67
-    echo 'DBFILE        =/var/lib/tripwire/$(HOSTNAME).twd' >> /etc/tripwire/twcfg.txt
68
-    echo 'REPORTFILE    =/var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr' >> /etc/tripwire/twcfg.txt
69
-    echo 'SITEKEYFILE   =/etc/tripwire/$(HOSTNAME)-site.key' >> /etc/tripwire/twcfg.txt
70
-    echo 'LOCALKEYFILE  =/etc/tripwire/$(HOSTNAME)-local.key' >> /etc/tripwire/twcfg.txt
71
-    echo 'EDITOR        =/usr/bin/editor' >> /etc/tripwire/twcfg.txt
72
-    echo 'LATEPROMPTING =false' >> /etc/tripwire/twcfg.txt
73
-    echo 'LOOSEDIRECTORYCHECKING =false' >> /etc/tripwire/twcfg.txt
74
-    echo 'MAILNOVIOLATIONS =false' >> /etc/tripwire/twcfg.txt
75
-    echo 'EMAILREPORTLEVEL =3' >> /etc/tripwire/twcfg.txt
76
-    echo 'REPORTLEVEL   =3' >> /etc/tripwire/twcfg.txt
77
-    echo 'SYSLOGREPORTING =false' >> /etc/tripwire/twcfg.txt
78
-    echo 'MAILMETHOD    =SENDMAIL' >> /etc/tripwire/twcfg.txt
79
-    echo 'MAILPROGRAM   =/usr/lib/sendmail -oi -t' >> /etc/tripwire/twcfg.txt
80
-    echo 'SMTPHOST      =localhost' >> /etc/tripwire/twcfg.txt
81
-    echo 'SMTPPORT      =25' >> /etc/tripwire/twcfg.txt
82
-    echo 'TEMPDIRECTORY =/tmp' >> /etc/tripwire/twcfg.txt
83
-    echo 'MAILFROMADDRESS =tripwire@$(HOSTNAME)' >> /etc/tripwire/twcfg.txt
63
+    cd /etc/tripwire || exit 246852845
64
+
65
+    { echo 'ROOT          =/usr/sbin';
66
+      echo 'POLFILE       =/etc/tripwire/tw.pol';
67
+      echo "DBFILE        =/var/lib/tripwire/\$(HOSTNAME).twd";
68
+      echo "REPORTFILE    =/var/lib/tripwire/report/\$(HOSTNAME)-\$(DATE).twr";
69
+      echo "SITEKEYFILE   =/etc/tripwire/\$(HOSTNAME)-site.key";
70
+      echo "LOCALKEYFILE  =/etc/tripwire/\$(HOSTNAME)-local.key";
71
+      echo 'EDITOR        =/usr/bin/editor';
72
+      echo 'LATEPROMPTING =false';
73
+      echo 'LOOSEDIRECTORYCHECKING =false';
74
+      echo 'MAILNOVIOLATIONS =false';
75
+      echo 'EMAILREPORTLEVEL =3';
76
+      echo 'REPORTLEVEL   =3';
77
+      echo 'SYSLOGREPORTING =false';
78
+      echo 'MAILMETHOD    =SENDMAIL';
79
+      echo 'MAILPROGRAM   =/usr/lib/sendmail -oi -t';
80
+      echo 'SMTPHOST      =localhost';
81
+      echo 'SMTPPORT      =25';
82
+      echo 'TEMPDIRECTORY =/tmp';
83
+      echo "MAILFROMADDRESS =tripwire@\$(HOSTNAME)"; } > /etc/tripwire/twcfg.txt
84 84
 
85 85
     echo '
86 86
 
87
-       ' | twadmin --generate-keys -L /etc/tripwire/${HOSTNAME}-local.key -S /etc/tripwire/${HOSTNAME}-site.key
87
+       ' | twadmin --generate-keys -L "/etc/tripwire/${HOSTNAME}-local.key" -S "/etc/tripwire/${HOSTNAME}-site.key"
88 88
 
89 89
     echo '
90 90
 
91
-       ' | twadmin --create-cfgfile -S /etc/tripwire/${HOSTNAME}-site.key /etc/tripwire/twcfg.txt
91
+       ' | twadmin --create-cfgfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twcfg.txt
92 92
 
93 93
     # make a script for easy resetting of the tripwire
94 94
     echo '#!/bin/sh' > /usr/bin/reset-tripwire
@@ -137,14 +137,14 @@ function install_tripwire {
137 137
     sed -i '/\/usr\/local\/bin/d' /etc/tripwire/twpol.txt
138 138
 
139 139
     # Avoid logging the changed database
140
-    sed -i 's|$(TWETC)/tw.pol.*||g' /etc/tripwire/twpol.txt
140
+    sed -i "s|\$(TWETC)/tw.pol.*||g" /etc/tripwire/twpol.txt
141 141
     # site key name
142
-    sed -i 's|$(TWETC)/site.key|$(TWETC)/$(HOSTNAME)-site.key|g' /etc/tripwire/twpol.txt
142
+    sed -i "s|$(TWETC)/site.key|\$(TWETC)/\$(HOSTNAME)-site.key|g" /etc/tripwire/twpol.txt
143 143
 
144 144
     # create the policy
145 145
     echo '
146 146
 
147
-       ' | twadmin --create-polfile -S /etc/tripwire/${HOSTNAME}-site.key /etc/tripwire/twpol.txt
147
+       ' | twadmin --create-polfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twpol.txt
148 148
 
149 149
     mark_completed "${FUNCNAME[0]}"
150 150
 }

+ 52
- 51
src/freedombone-client Просмотреть файл

@@ -55,11 +55,11 @@ if [ ! -f $MAIN_PROJECT_FILE ]; then
55 55
 fi
56 56
 
57 57
 # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
58
-UTILS_SSH=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-ssh
59
-SSH_CIPHERS=$(cat $UTILS_SSH | grep 'SSH_CIPHERS=' | head -n 1 | awk -F '"' '{print $2}')
60
-SSH_MACS=$(cat $UTILS_SSH | grep 'SSH_MACS=' | head -n 1 | awk -F '"' '{print $2}')
61
-SSH_KEX=$(cat $UTILS_SSH | grep 'SSH_KEX=' | head -n 1 | awk -F '"' '{print $2}')
62
-SSH_HOST_KEY_ALGORITHMS=$(cat $UTILS_SSH | grep 'SSH_HOST_KEY_ALGORITHMS=' | head -n 1 | awk -F '"' '{print $2}')
58
+UTILS_SSH="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-ssh"
59
+SSH_CIPHERS=$(grep 'SSH_CIPHERS=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
60
+SSH_MACS=$(grep 'SSH_MACS=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
61
+SSH_KEX=$(grep 'SSH_KEX=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
62
+SSH_HOST_KEY_ALGORITHMS=$(grep 'SSH_HOST_KEY_ALGORITHMS=' "$UTILS_SSH" | head -n 1 | awk -F '"' '{print $2}')
63 63
 
64 64
 # refresh gpg keys every few hours
65 65
 REFRESH_GPG_KEYS_HOURS=2
@@ -74,7 +74,7 @@ function global_rate_limit {
74 74
     fi
75 75
 
76 76
     sudo cp $SYSCTL_FILE ~/sysctl.conf
77
-    sudo chown $CURR_USER:$CURR_GROUP ~/sysctl.conf
77
+    sudo chown "$CURR_USER":"$CURR_GROUP" ~/sysctl.conf
78 78
     if ! grep -q "tcp_challenge_ack_limit" ~/sysctl.conf; then
79 79
         echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> ~/sysctl.conf
80 80
     else
@@ -94,7 +94,7 @@ function refresh_gpg_keys {
94 94
         fi
95 95
     fi
96 96
     sudo cp /etc/crontab ~/temp_crontab
97
-    sudo chown $CURR_USER:$CURR_GROUP ~/temp_crontab
97
+    sudo chown "$CURR_USER":"$CURR_GROUP" ~/temp_crontab
98 98
     if ! grep -q 'gpg --refresh-keys' ~/temp_crontab; then
99 99
         echo "0            */$REFRESH_GPG_KEYS_HOURS *   *   *   $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
100 100
         sudo cp ~/temp_crontab /etc/crontab
@@ -105,8 +105,9 @@ function refresh_gpg_keys {
105 105
 
106 106
 # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
107 107
 function ssh_remove_small_moduli {
108
-    sudo awk '$5 > 2000' /etc/ssh/moduli > /home/$CURR_USER/moduli
109
-    sudo mv /home/$CURR_USER/moduli /etc/ssh/moduli
108
+    # shellcheck disable=SC2024
109
+    sudo awk '$5 > 2000' /etc/ssh/moduli > "/home/$CURR_USER/moduli"
110
+    sudo mv "/home/$CURR_USER/moduli" /etc/ssh/moduli
110 111
 }
111 112
 
112 113
 function configure_ssh_client {
@@ -124,7 +125,7 @@ function configure_ssh_client {
124 125
     sudo sed -i "s/HostKeyAlgorithms.*/HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
125 126
     if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
126 127
         sudo cp /etc/ssh/ssh_config ~/ssh_config
127
-        sudo chown $CURR_USER:$CURR_GROUP ~/ssh_config
128
+        sudo chown "$CURR_USER":"$CURR_GROUP" ~/ssh_config
128 129
         echo "   HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
129 130
         sudo mv ~/ssh_config /etc/ssh/ssh_config
130 131
         sudo chown root:root /etc/ssh/ssh_config
@@ -134,7 +135,7 @@ function configure_ssh_client {
134 135
     sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
135 136
     if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
136 137
         sudo cp /etc/ssh/ssh_config ~/ssh_config
137
-        sudo chown $CURR_USER:$CURR_GROUP ~/ssh_config
138
+        sudo chown "$CURR_USER":"$CURR_GROUP" ~/ssh_config
138 139
         echo "   Ciphers $SSH_CIPHERS" >> ~/ssh_config
139 140
         sudo mv ~/ssh_config /etc/ssh/ssh_config
140 141
         sudo chown root:root /etc/ssh/ssh_config
@@ -142,17 +143,17 @@ function configure_ssh_client {
142 143
     sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
143 144
     if ! grep -q "MACs " /etc/ssh/ssh_config; then
144 145
         sudo cp /etc/ssh/ssh_config ~/ssh_config
145
-        sudo chown $CURR_USER:$CURR_GROUP ~/ssh_config
146
+        sudo chown "$CURR_USER":"$CURR_GROUP" ~/ssh_config
146 147
         echo "   MACs $SSH_MACS" >> ~/ssh_config
147 148
         sudo mv ~/ssh_config /etc/ssh/ssh_config
148 149
         sudo chown root:root /etc/ssh/ssh_config
149 150
     fi
150 151
 
151 152
     # Create ssh keys
152
-    if [ ! -f /home/$CURR_USER/.ssh/id_ed25519 ]; then
153
+    if [ ! -f "/home/$CURR_USER/.ssh/id_ed25519" ]; then
153 154
         ssh-keygen -t ed25519 -o -a 100
154 155
     fi
155
-    if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
156
+    if [ ! -f "/home/$CURR_USER/.ssh/id_rsa" ]; then
156 157
         ssh-keygen -t rsa -b 2048 -o -a 100
157 158
     fi
158 159
 
@@ -170,20 +171,20 @@ function configure_ssh_client {
170 171
     fi
171 172
     if ! grep -q "# ${PROJECT_NAME} settings" ~/.ssh/config; then
172 173
         if ! grep -q 'ProxyCommand' ~/.ssh/config; then
173
-            echo "# ${PROJECT_NAME} settings start" >> ~/.ssh/config
174
-            echo 'Host *.onion' >> ~/.ssh/config
175
-            echo '  ServerAliveInterval 60' >> ~/.ssh/config
176
-            echo '  ServerAliveCountMax 3' >> ~/.ssh/config
174
+            { echo "# ${PROJECT_NAME} settings start";
175
+              echo 'Host *.onion';
176
+              echo '  ServerAliveInterval 60';
177
+              echo '  ServerAliveCountMax 3'; } >> ~/.ssh/config
177 178
 
178
-            if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
179
+            if [[ "$ENABLE_MONKEYSPHERE" == $'yes' || "$ENABLE_MONKEYSPHERE" == $'y' ]]; then
179 180
                 echo "  ProxyCommand sh -c 'monkeysphere ssh-proxycommand --no-connect %h %p ; $proxycmd'" >> ~/.ssh/config
180 181
             else
181 182
                 echo "  ProxyCommand $proxycmd" >> ~/.ssh/config
182 183
             fi
183
-            echo 'Host *' >> ~/.ssh/config
184
-            echo '  ServerAliveInterval 60' >> ~/.ssh/config
185
-            echo '  ServerAliveCountMax 3' >> ~/.ssh/config
186
-            if [[ $ENABLE_MONKEYSPHERE == $'yes' || $ENABLE_MONKEYSPHERE == $'y' ]]; then
184
+            { echo 'Host *';
185
+              echo '  ServerAliveInterval 60';
186
+              echo '  ServerAliveCountMax 3'; } >> ~/.ssh/config
187
+            if [[ "$ENABLE_MONKEYSPHERE" == $'yes' || "$ENABLE_MONKEYSPHERE" == $'y' ]]; then
187 188
                 echo '  ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
188 189
             fi
189 190
             echo "# ${PROJECT_NAME} settings end" >> ~/.ssh/config
@@ -194,8 +195,8 @@ function configure_ssh_client {
194 195
     echo $'Go to the Administrator Control Panel, select "Manage Users", '
195 196
     echo $'"Change user ssh public key" then "yes" and paste the following:'
196 197
     echo ''
197
-    echo $(cat /home/$CURR_USER/.ssh/id_rsa.pub)
198
-    echo $(cat /home/$CURR_USER/.ssh/id_ed25519.pub)
198
+    cat "/home/$CURR_USER/.ssh/id_rsa.pub"
199
+    cat "/home/$CURR_USER/.ssh/id_ed25519.pub"
199 200
     echo ''
200 201
     echo $'Then go to "Security Settings", select "Allow ssh login with passwords"'
201 202
     echo $'and set it to "no".'
@@ -222,37 +223,37 @@ function setup_client_app_irc {
222 223
     else
223 224
         sudo pacman -S --noconfirm hexchat tor
224 225
     fi
225
-    if [ ! -d /home/$CURR_USER/.config/hexchat ]; then
226
-        mkdir -p /home/$CURR_USER/.config/hexchat
226
+    if [ ! -d "/home/$CURR_USER/.config/hexchat" ]; then
227
+        mkdir -p "/home/$CURR_USER/.config/hexchat"
227 228
     fi
228
-    echo 'net_proxy_host = 127.0.0.1' > /home/$CURR_USER/.config/hexchat/hexchat.conf
229
-    echo 'net_proxy_port = 9050' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
230
-    echo 'net_proxy_type = 3' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
231
-    echo 'net_proxy_use = 0' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
229
+    { echo 'net_proxy_host = 127.0.0.1';
230
+      echo 'net_proxy_port = 9050';
231
+      echo 'net_proxy_type = 3';
232
+      echo 'net_proxy_use = 0';
232 233
 
233
-    echo 'net_proxy_auth = 1' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
234
-    echo 'net_proxy_pass = HexChat' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
235
-    echo 'net_proxy_user = HexChat' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
234
+      echo 'net_proxy_auth = 1';
235
+      echo 'net_proxy_pass = HexChat';
236
+      echo 'net_proxy_user = HexChat';
236 237
 
237
-    echo 'dcc_auto_chat = 0' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
238
-    echo 'dcc_auto_resume = 0' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
239
-    echo 'dcc_auto_send = 0' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
240
-    echo 'irc_hide_version = 1' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
241
-    echo 'identd = 0' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
238
+      echo 'dcc_auto_chat = 0';
239
+      echo 'dcc_auto_resume = 0';
240
+      echo 'dcc_auto_send = 0';
241
+      echo 'irc_hide_version = 1';
242
+      echo 'identd = 0';
242 243
 
243
-    echo 'away_reason =' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
244
-    echo 'irc_part_reason =' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
245
-    echo 'irc_quit_reason =' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
244
+      echo 'away_reason =';
245
+      echo 'irc_part_reason =';
246
+      echo 'irc_quit_reason =';
246 247
 
247
-    echo "irc_real_name = ${USER}" >> /home/$CURR_USER/.config/hexchat/hexchat.conf
248
-    echo "irc_user_name = ${USER}" >> /home/$CURR_USER/.config/hexchat/hexchat.conf
249
-    echo "irc_nick1 = ${USER}" >> /home/$CURR_USER/.config/hexchat/hexchat.conf
250
-    echo "irc_nick2 = ${USER}_" >> /home/$CURR_USER/.config/hexchat/hexchat.conf
251
-    echo "irc_nick3 = ${USER}__" >> /home/$CURR_USER/.config/hexchat/hexchat.conf
248
+      echo "irc_real_name = ${USER}";
249
+      echo "irc_user_name = ${USER}";
250
+      echo "irc_nick1 = ${USER}";
251
+      echo "irc_nick2 = ${USER}_";
252
+      echo "irc_nick3 = ${USER}__";
252 253
 
253
-    echo 'completion_suffix = :' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
254
+      echo 'completion_suffix = :';
254 255
 
255
-    echo 'gui_slist_skip = 1' >> /home/$CURR_USER/.config/hexchat/hexchat.conf
256
+      echo 'gui_slist_skip = 1'; } > "/home/$CURR_USER/.config/hexchat/hexchat.conf"
256 257
 
257 258
     echo $'hexchat configured'
258 259
 }
@@ -272,8 +273,8 @@ function setup_client_app {
272 273
 
273 274
 function remove_known_hosts_entries {
274 275
     # remove any previous freedombone entries from known hosts
275
-    if [ -f /home/$CURR_USER/.ssh/known_hosts ]; then
276
-        sed -i "/${PROJECT_NAME}.local/d" /home/$CURR_USER/.ssh/known_hosts
276
+    if [ -f "/home/$CURR_USER/.ssh/known_hosts" ]; then
277
+        sed -i "/${PROJECT_NAME}.local/d" "/home/$CURR_USER/.ssh/known_hosts"
277 278
     fi
278 279
 }
279 280
 

+ 50
- 54
src/freedombone-clientcert Просмотреть файл

@@ -59,34 +59,34 @@ function show_help {
59 59
 
60 60
 while [ $# -gt 1 ]
61 61
 do
62
-key="$1"
63
-
64
-case $key in
65
-    --help)
66
-    show_help
67
-    ;;
68
-    -u|--username)
62
+    key="$1"
63
+
64
+    case $key in
65
+        --help)
66
+            show_help
67
+            ;;
68
+        -u|--username)
69
+            shift
70
+            USERNAME="$1"
71
+            ;;
72
+        *)
73
+            # unknown option
74
+            ;;
75
+    esac
69 76
     shift
70
-    USERNAME="$1"
71
-    ;;
72
-    *)
73
-    # unknown option
74
-    ;;
75
-esac
76
-shift
77 77
 done
78 78
 
79
-if [ ! $USERNAME ]; then
79
+if [ ! "$USERNAME" ]; then
80 80
     echo $'No username specified'
81 81
     exit 5748
82 82
 fi
83 83
 
84
-if [ ! -d /home/$USERNAME ]; then
84
+if [ ! -d "/home/$USERNAME" ]; then
85 85
     echo $"User $USERNAME not found"
86 86
     exit 76239
87 87
 fi
88 88
 
89
-if [ -d /home/$USERNAME/emailcert ]; then
89
+if [ -d "/home/$USERNAME/emailcert" ]; then
90 90
     echo $'Client certs were already for created'
91 91
     exit 2953
92 92
 fi
@@ -97,75 +97,71 @@ fi
97 97
 
98 98
 # Add a user password
99 99
 if ! grep -q "$USERNAME:{plain}" /etc/dovecot/passwd-file; then
100
-  echo "$USERNAME:{plain}::::::nopassword" >> /etc/dovecot/passwd-file
100
+    echo "$USERNAME:{plain}::::::nopassword" >> /etc/dovecot/passwd-file
101 101
 fi
102 102
 
103 103
 chmod 600 /etc/dovecot/passwd-file
104 104
 
105 105
 # create a user cert
106
-${PROJECT_NAME}-addcert -h $USERNAME --nodh ""
106
+"${PROJECT_NAME}-addcert" -h "$USERNAME" --nodh ""
107 107
 
108
-if [ ! -f /etc/ssl/private/$USERNAME.key ]; then
108
+if [ ! -f "/etc/ssl/private/$USERNAME.key" ]; then
109 109
     echo $'User certificates were not created'
110
-    rm -rf /home/$USERNAME/emailcert
110
+    rm -rf "/home/$USERNAME/emailcert"
111 111
     exit 74835
112 112
 fi
113 113
 
114 114
 # create a certificate request
115 115
 openssl req -new -sha256 -subj \
116 116
         "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$USERNAME" \
117
-        -key /etc/ssl/private/$USERNAME.key \
118
-        -out /etc/ssl/requests/$USERNAME.csr
117
+        -key "/etc/ssl/private/$USERNAME.key" \
118
+        -out "/etc/ssl/requests/$USERNAME.csr"
119 119
 
120
-if [ ! -f /etc/ssl/requests/$USERNAME.csr ]; then
120
+if [ ! -f "/etc/ssl/requests/$USERNAME.csr" ]; then
121 121
     echo $'Certificate request was not created'
122
-    rm -rf /home/$USERNAME/emailcert
122
+    rm -rf "/home/$USERNAME/emailcert"
123 123
     exit 83520
124 124
 fi
125 125
 
126 126
 # sign the certificate request
127
-cd /etc/ssl
127
+cd /etc/ssl || exit 742742542
128 128
 openssl ca -config /etc/ssl/dovecot-ca.cnf \
129
-        -in /etc/ssl/requests/$USERNAME.csr \
130
-        -out /etc/ssl/certs/$USERNAME.cer
129
+        -in "/etc/ssl/requests/$USERNAME.csr" \
130
+        -out "/etc/ssl/certs/$USERNAME.cer"
131 131
 
132
-if [ ! -f /etc/ssl/certs/$USERNAME.cer ]; then
132
+if [ ! -f "/etc/ssl/certs/$USERNAME.cer" ]; then
133 133
     echo $'Authentication certificate was not created'
134
-    rm -rf /home/$USERNAME/emailcert
134
+    rm -rf "/home/$USERNAME/emailcert"
135 135
     exit 343569
136 136
 fi
137 137
 
138 138
 # move the cert to the user's home
139
-mkdir /home/$USERNAME/emailcert
140
-mv /etc/ssl/certs/$USERNAME.cer /home/$USERNAME/emailcert
141
-cp /etc/ssl/certs/dovecot.crt /home/$USERNAME/emailcert
142
-cp /etc/ssl/certs/ca-$HOSTNAME.crt /home/$USERNAME/emailcert
143
-mv /etc/ssl/private/$USERNAME.key /home/$USERNAME/emailcert
144
-mv /etc/ssl/certs/$USERNAME.crt /home/$USERNAME/emailcert
145
-openssl pkcs12 -export -in /home/$USERNAME/emailcert/$USERNAME.cer \
146
-        -out /home/$USERNAME/emailcert/$USERNAME.p12 \
147
-        -inkey /home/$USERNAME/emailcert/$USERNAME.key \
148
-        -certfile /home/$USERNAME/emailcert/ca-$HOSTNAME.crt \
139
+mkdir "/home/$USERNAME/emailcert"
140
+mv "/etc/ssl/certs/$USERNAME.cer" "/home/$USERNAME/emailcert"
141
+cp "/etc/ssl/certs/dovecot.crt" "/home/$USERNAME/emailcert"
142
+cp "/etc/ssl/certs/ca-$HOSTNAME.crt" "/home/$USERNAME/emailcert"
143
+mv "/etc/ssl/private/$USERNAME.key" "/home/$USERNAME/emailcert"
144
+mv "/etc/ssl/certs/$USERNAME.crt" "/home/$USERNAME/emailcert"
145
+openssl pkcs12 -export -in "/home/$USERNAME/emailcert/$USERNAME.cer" \
146
+        -out "/home/$USERNAME/emailcert/$USERNAME.p12" \
147
+        -inkey "/home/$USERNAME/emailcert/$USERNAME.key" \
148
+        -certfile "/home/$USERNAME/emailcert/ca-$HOSTNAME.crt" \
149 149
         -password pass:""
150 150
 
151 151
 # make an install script
152
-echo '#!/bin/bash' > /home/$USERNAME/emailcert/install.sh
153
-echo "sudo mv ca-$HOSTNAME.crt /etc/ssl/certs" >> \
154
-     /home/$USERNAME/emailcert/install.sh
155
-echo "sudo mv $USERNAME.crt /etc/ssl/certs" >> \
156
-     /home/$USERNAME/emailcert/install.sh
157
-echo "sudo mv dovecot.crt /etc/ssl/certs" >> \
158
-     /home/$USERNAME/emailcert/install.sh
159
-echo "sudo mv $USERNAME.key /etc/ssl/private" >> \
160
-     /home/$USERNAME/emailcert/install.sh
161
-echo 'exit 0' >> /home/$USERNAME/emailcert/install.sh
152
+{ echo '#!/bin/bash';
153
+  echo "sudo mv ca-$HOSTNAME.crt /etc/ssl/certs";
154
+  echo "sudo mv $USERNAME.crt /etc/ssl/certs";
155
+  echo "sudo mv dovecot.crt /etc/ssl/certs";
156
+  echo "sudo mv $USERNAME.key /etc/ssl/private";
157
+  echo 'exit 0'; } > "/home/$USERNAME/emailcert/install.sh"
162 158
 
163 159
 # set permissions for the user
164
-chmod -R 755 /home/$USERNAME/emailcert
165
-chown -R $USERNAME:$USERNAME /home/$USERNAME/emailcert
166
-chmod +x /home/$USERNAME/emailcert/install.sh
160
+chmod -R 755 "/home/$USERNAME/emailcert"
161
+chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/emailcert"
162
+chmod +x "/home/$USERNAME/emailcert/install.sh"
167 163
 
168
-shred -zu /etc/ssl/requests/$USERNAME.csr
164
+shred -zu "/etc/ssl/requests/$USERNAME.csr"
169 165
 
170 166
 echo $'Email authentication certificate created. You can obtain it on the client with:'
171 167
 echo ''

+ 169
- 134
src/freedombone-config Просмотреть файл

@@ -43,7 +43,7 @@ export TEXTDOMAINDIR="/usr/share/locale"
43 43
 FREEDOMBONE_WEBSITE="https://freedombone.net or http://4fvfozz6g3zmvf76.onion"
44 44
 
45 45
 # Minimum number of characters in a password
46
-MINIMUM_PASSWORD_LENGTH=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords | grep 'MINIMUM_PASSWORD_LENGTH=' | head -n 1 | awk -F '=' '{print $2}')
46
+MINIMUM_PASSWORD_LENGTH=$(grep 'MINIMUM_PASSWORD_LENGTH=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords" | head -n 1 | awk -F '=' '{print $2}')
47 47
 
48 48
 # file containing new password
49 49
 IMAGE_PASSWORD_FILE=/root/login.txt
@@ -118,18 +118,18 @@ function please_wait {
118 118
         echo -n ''
119 119
 }
120 120
 
121
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
121
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
122 122
 
123
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
123
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
124 124
 for f in $UTILS_FILES
125 125
 do
126
-    source $f
126
+    source "$f"
127 127
 done
128 128
 
129
-APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
129
+APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
130 130
 for f in $APP_FILES
131 131
 do
132
-    source $f
132
+    source "$f"
133 133
 done
134 134
 
135 135
 function show_help {
@@ -157,23 +157,25 @@ function choose_email_address {
157 157
         while [ ${#MY_EMAIL_ADDRESS} -lt 5 ]
158 158
         do
159 159
             EMAIL_ADDRESS=$(grep 'MY_EMAIL_ADDRESS' temp.cfg | awk -F '=' '{print $2}')
160
-            if [ ! $EMAIL_ADDRESS ]; then
160
+            if [ ! "$EMAIL_ADDRESS" ]; then
161 161
                 EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
162 162
             fi
163 163
             if [ ${#MY_EMAIL_ADDRESS} -lt 5 ]; then
164 164
                 EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
165 165
             fi
166 166
 
167
-            data=$(tempfile 2>/dev/null)
168
-            trap "rm -f $data" 0 1 2 5 15
167
+            data=$(mktemp 2>/dev/null)
169 168
             dialog --backtitle $"Freedombone Configuration" \
170
-                   --inputbox $"Your email address" 10 30 "$EMAIL_ADDRESS" 2> $data
169
+                   --inputbox $"Your email address" 10 30 "$EMAIL_ADDRESS" 2> "$data"
171 170
             sel=$?
172 171
             case $sel in
173
-                0) MY_EMAIL_ADDRESS=$(cat $data);;
174
-                1) exit 1;;
175
-                255) exit 1;;
172
+                0) MY_EMAIL_ADDRESS=$(cat "$data");;
173
+                1) rm -f "$data"
174
+                   exit 1;;
175
+                255) rm -f "$data"
176
+                     exit 1;;
176 177
             esac
178
+            rm -f "$data"
177 179
         done
178 180
     fi
179 181
     save_configuration_values
@@ -183,23 +185,24 @@ function choose_social_instance_domain_name {
183 185
     DEFAULT_DOMAIN_DETAILS_COMPLETE=
184 186
     while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
185 187
     do
186
-        data=$(tempfile 2>/dev/null)
187
-        trap "rm -f $data" 0 1 2 5 15
188
+        data=$(mktemp 2>/dev/null)
188 189
         if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
189 190
             dialog --backtitle $"Freedombone Configuration" \
190 191
                    --title $"Instance domain" \
191
-                   --form $"\nEnter your instance domain name and its FreeDNS code:" 11 55 3 \
192
+                   --form $"\\nEnter your instance domain name and its FreeDNS code:" 11 55 3 \
192 193
                    $"Domain:" 1 1 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 24 33 40 \
193 194
                    $"Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 24 33 255 \
194
-                   2> $data
195
+                   2> "$data"
195 196
             sel=$?
196 197
             case $sel in
197
-                1) exit 1;;
198
-                255) exit 1;;
198
+                1) rm -f "$data"
199
+                   exit 1;;
200
+                255) rm -f "$data"
201
+                     exit 1;;
199 202
             esac
200
-            DEFAULT_DOMAIN_NAME=$(cat $data | sed -n 1p)
201
-            DEFAULT_DOMAIN_CODE=$(cat $data | sed -n 2p)
202
-            if [ $DEFAULT_DOMAIN_NAME ]; then
203
+            DEFAULT_DOMAIN_NAME=$(sed -n 1p < "$data")
204
+            DEFAULT_DOMAIN_CODE=$(sed -n 2p < "$data")
205
+            if [ "$DEFAULT_DOMAIN_NAME" ]; then
203 206
                 validate_freedns_code "$DEFAULT_DOMAIN_CODE"
204 207
                 if [ ! $VALID_CODE ]; then
205 208
                     DEFAULT_DOMAIN_NAME=
@@ -208,24 +211,27 @@ function choose_social_instance_domain_name {
208 211
         else
209 212
             dialog --backtitle $"Freedombone Configuration" \
210 213
                    --inputbox $"Enter your instance domain name:" 10 45 \
211
-                   "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data
214
+                   "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
212 215
             sel=$?
213 216
             case $sel in
214
-                0) DEFAULT_DOMAIN_NAME=$(cat $data);;
215
-                1) exit 1;;
216
-                255) exit 1;;
217
+                0) DEFAULT_DOMAIN_NAME=$(cat "$data");;
218
+                1) rm -f "$data"
219
+                   exit 1;;
220
+                255) rm -f "$data"
221
+                     exit 1;;
217 222
             esac
218 223
         fi
219
-        if [ $DEFAULT_DOMAIN_NAME ]; then
224
+        if [ "$DEFAULT_DOMAIN_NAME" ]; then
220 225
             TEST_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME
221 226
             validate_domain_name
222
-            if [[ $TEST_DOMAIN_NAME != $DEFAULT_DOMAIN_NAME ]]; then
227
+            if [[ "$TEST_DOMAIN_NAME" != "$DEFAULT_DOMAIN_NAME" ]]; then
223 228
                 DEFAULT_DOMAIN_NAME=
224 229
                 dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
225 230
             else
226 231
                 DEFAULT_DOMAIN_DETAILS_COMPLETE="yes"
227 232
             fi
228 233
         fi
234
+        rm -f "$data"
229 235
     done
230 236
     save_configuration_values
231 237
 }
@@ -242,8 +248,7 @@ function choose_default_domain_name {
242 248
         DEFAULT_DOMAIN_DETAILS_COMPLETE=
243 249
         while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
244 250
         do
245
-            data=$(tempfile 2>/dev/null)
246
-            trap "rm -f $data" 0 1 2 5 15
251
+            data=$(mktemp 2>/dev/null)
247 252
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
248 253
                 dialog --backtitle $"Freedombone Configuration" \
249 254
                        --title $"Your main domain name" \
@@ -252,23 +257,26 @@ function choose_default_domain_name {
252 257
                        $"Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 24 33 255 \
253 258
                        $"mail subdomain Code:" 3 1 "$(grep 'EMAIL_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 3 24 33 255 \
254 259
                        $"XMPP subdomain Code:" 4 1 "$(grep 'XMPP_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 24 33 255 \
255
-                       2> $data
260
+                       2> "$data"
256 261
                 sel=$?
257 262
                 case $sel in
258
-                    1) exit 1;;
259
-                    255) exit 1;;
263
+                    1) rm -f "$data"
264
+                       exit 1;;
265
+                    255) rm -f "$data"
266
+                         exit 1;;
260 267
                 esac
261
-                DEFAULT_DOMAIN_NAME=$(cat $data | sed -n 1p)
262
-                DEFAULT_DOMAIN_CODE=$(cat $data | sed -n 2p)
263
-                EMAIL_DOMAIN_CODE=$(cat $data | sed -n 3p)
264
-                XMPP_DOMAIN_CODE=$(cat $data | sed -n 4p)
265
-                if [ $DEFAULT_DOMAIN_NAME ]; then
268
+                DEFAULT_DOMAIN_NAME=$(sed -n 1p < "$data")
269
+                DEFAULT_DOMAIN_CODE=$(sed -n 2p < "$data")
270
+                EMAIL_DOMAIN_CODE=$(sed -n 3p < "$data")
271
+                XMPP_DOMAIN_CODE=$(sed -n 4p < "$data")
272
+                rm -f "$data"
273
+                if [ "$DEFAULT_DOMAIN_NAME" ]; then
266 274
                     validate_freedns_code "$DEFAULT_DOMAIN_CODE"
267 275
                     if [ ! $VALID_CODE ]; then
268 276
                         DEFAULT_DOMAIN_NAME=
269 277
                     fi
270 278
                 fi
271
-                if [ $EMAIL_DOMAIN_CODE ]; then
279
+                if [ "$EMAIL_DOMAIN_CODE" ]; then
272 280
                     validate_freedns_code "$EMAIL_DOMAIN_CODE"
273 281
                     if [ ! $VALID_CODE ]; then
274 282
                         DEFAULT_DOMAIN_NAME=
@@ -277,7 +285,7 @@ function choose_default_domain_name {
277 285
                         write_config_param "EMAIL_DOMAIN_CODE" "$EMAIL_DOMAIN_CODE"
278 286
                     fi
279 287
                 fi
280
-                if [ $XMPP_DOMAIN_CODE ]; then
288
+                if [ "$XMPP_DOMAIN_CODE" ]; then
281 289
                     validate_freedns_code "$XMPP_DOMAIN_CODE"
282 290
                     if [ ! $VALID_CODE ]; then
283 291
                         DEFAULT_DOMAIN_NAME=
@@ -289,18 +297,20 @@ function choose_default_domain_name {
289 297
             else
290 298
                 dialog --backtitle $"Freedombone Configuration" \
291 299
                        --inputbox $"Which domain name should your email/XMPP/IRC/Mumble be associated with?" 10 45 \
292
-                       "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data
300
+                       "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
293 301
                 sel=$?
294 302
                 case $sel in
295
-                    0) DEFAULT_DOMAIN_NAME=$(cat $data);;
296
-                    1) exit 1;;
297
-                    255) exit 1;;
303
+                    0) DEFAULT_DOMAIN_NAME=$(cat "$data");;
304
+                    1) rm -f "$data"
305
+                       exit 1;;
306
+                    255) rm -f "$data"
307
+                         exit 1;;
298 308
                 esac
299 309
             fi
300
-            if [ $DEFAULT_DOMAIN_NAME ]; then
310
+            if [ "$DEFAULT_DOMAIN_NAME" ]; then
301 311
                 TEST_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME
302 312
                 validate_domain_name
303
-                if [[ $TEST_DOMAIN_NAME != $DEFAULT_DOMAIN_NAME ]]; then
313
+                if [[ "$TEST_DOMAIN_NAME" != "$DEFAULT_DOMAIN_NAME" ]]; then
304 314
                     DEFAULT_DOMAIN_NAME=
305 315
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
306 316
                 else
@@ -313,8 +323,7 @@ function choose_default_domain_name {
313 323
 }
314 324
 
315 325
 function dynamic_dns_setup {
316
-    data=$(tempfile 2>/dev/null)
317
-    trap "rm -f $data" 0 1 2 5 15
326
+    data=$(mktemp 2>/dev/null)
318 327
     dialog --backtitle $"Freedombone Configuration" \
319 328
            --radiolist $"Choose Dynamic DNS provider:" 40 40 40 \
320 329
            1 dyn.com off \
@@ -349,13 +358,15 @@ function dynamic_dns_setup {
349 358
            30 strato.com off \
350 359
            31 freemyip.com off \
351 360
            32 cloudxns.net off \
352
-           33 none off 2> $data
361
+           33 none off 2> "$data"
353 362
     sel=$?
354 363
     case $sel in
355
-        1) exit 1;;
356
-        255) exit 1;;
364
+        1) rm -f "$data"
365
+           exit 1;;
366
+        255) rm -f "$data"
367
+             exit 1;;
357 368
     esac
358
-    case $(cat $data) in
369
+    case $(cat "$data") in
359 370
         1) DDNS_PROVIDER="default@www.dyn.com";;
360 371
         2) DDNS_PROVIDER="default@freedns.afraid.org";;
361 372
         3) DDNS_PROVIDER="default@www.zoneedit.com";;
@@ -389,8 +400,10 @@ function dynamic_dns_setup {
389 400
         31) DDNS_PROVIDER="default@freemyip.com";;
390 401
         32) DDNS_PROVIDER="default@www.cloudxns.net";;
391 402
         33) DDNS_PROVIDER="none";;
392
-        255) exit 1;;
403
+        255) rm -f "$data"
404
+             exit 1;;
393 405
     esac
406
+    rm -f "$data"
394 407
     save_configuration_values
395 408
 
396 409
     valid_ddns_username=
@@ -403,50 +416,55 @@ function dynamic_dns_setup {
403 416
     else
404 417
         while [ ! $valid_ddns_username ]
405 418
         do
406
-            data=$(tempfile 2>/dev/null)
407
-            trap "rm -f $data" 0 1 2 5 15
419
+            data=$(mktemp 2>/dev/null)
408 420
             dialog --backtitle $"Freedombone Configuration" \
409
-                   --inputbox $"Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data
421
+                   --inputbox $"Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
410 422
             sel=$?
411 423
             case $sel in
412
-                0)  possible_username=$(cat $data)
424
+                0)  possible_username=$(cat "$data")
413 425
                     if [ "$possible_username" ]; then
414 426
                         if [ ${#possible_username} -gt 1 ]; then
415
-                            valid_ddns_username=$(cat $data)
416
-                            DDNS_USERNAME=$valid_ddns_username
427
+                            valid_ddns_username=$(cat "$data")
428
+                            DDNS_USERNAME="$valid_ddns_username"
429
+                            rm -f "$data"
417 430
                             break;
418 431
                         fi
419 432
                     fi
420 433
                     ;;
421
-                1) exit 1;;
422
-                255) exit 1;;
434
+                1) rm -f "$data"
435
+                   exit 1;;
436
+                255) rm -f "$data"
437
+                     exit 1;;
423 438
             esac
439
+            rm -f "$data"
424 440
         done
425 441
         save_configuration_values
426 442
 
427 443
         while [ ! $valid_ddns_password ]
428 444
         do
429
-            data=$(tempfile 2>/dev/null)
430
-            trap "rm -f $data" 0 1 2 5 15
445
+            data=$(mktemp 2>/dev/null)
431 446
             dialog --backtitle $"Freedombone Configuration" \
432 447
                    --clear \
433 448
                    --insecure \
434
-                   --passwordbox $"Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> $data
449
+                   --passwordbox $"Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
435 450
             sel=$?
436 451
             case $sel in
437
-                0)  possible_password=$(cat $data)
452
+                0)  possible_password=$(cat "$data")
438 453
                     if [ "$possible_password" ]; then
439 454
                         if [ ${#possible_password} -gt 1 ]; then
440
-                            valid_ddns_password=$(cat $data)
455
+                            valid_ddns_password=$(cat "$data")
441 456
                             DDNS_PASSWORD=$valid_ddns_password
442 457
                             break;
443 458
                         fi
444 459
                     fi
445 460
                     ;;
446
-                1) exit 1;;
447
-                255) exit 1;;
461
+                1) rm -f "$data"
462
+                   exit 1;;
463
+                255) rm -f "$data"
464
+                     exit 1;;
448 465
             esac
449
-            if [ ${#DDNS_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
466
+            rm -f "$data"
467
+            if [ ${#DDNS_PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
450 468
                 dialog --title $"Password quality check" --msgbox $"The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters. You may need to change your password on the dynamic DNS provider's web site." 10 40
451 469
                 DDNS_PASSWORD=""
452 470
             fi
@@ -458,10 +476,10 @@ function dynamic_dns_setup {
458 476
 function choose_dynamic_dns {
459 477
     DDNS_PROVIDER="none"
460 478
 
461
-    if [[ $SYSTEM_TYPE != "mesh"* && $ONION_ONLY == "no" ]]; then
479
+    if [[ "$SYSTEM_TYPE" != "mesh"* && "$ONION_ONLY" == "no" ]]; then
462 480
         dialog --title $"Dynamic DNS" \
463 481
                --backtitle $"Freedombone Configuration" \
464
-               --yesno $"\nConfigure a dynamic DNS service?\n\nIf it is already handled by your internet router then select 'no'." 10 50
482
+               --yesno $"\\nConfigure a dynamic DNS service?\\n\\nIf it is already handled by your internet router then select 'no'." 10 50
465 483
         sel=$?
466 484
         case $sel in
467 485
             0) dynamic_dns_setup;;
@@ -472,9 +490,8 @@ function choose_dynamic_dns {
472 490
 }
473 491
 
474 492
 function choose_debian_repo {
475
-    if [[ $MINIMAL_INSTALL == "no" ]]; then
476
-        data=$(tempfile 2>/dev/null)
477
-        trap "rm -f $data" 0 1 2 5 15
493
+    if [[ "$MINIMAL_INSTALL" == "no" ]]; then
494
+        data=$(mktemp 2>/dev/null)
478 495
         dialog --backtitle $"Freedombone Configuration" \
479 496
                --radiolist $"Where to download Debian packages from:" 25 45 49 \
480 497
                1 $"Australia" off \
@@ -525,13 +542,15 @@ function choose_debian_repo {
525 542
                46 $"Turkey" off \
526 543
                47 $"Ukraine" off \
527 544
                48 $"United Kingdom" off \
528
-               49 $"United States" on 2> $data
545
+               49 $"United States" on 2> "$data"
529 546
         sel=$?
530 547
         case $sel in
531
-            1) exit 1;;
532
-            255) exit 1;;
548
+            1) rm -f "$data"
549
+               exit 1;;
550
+            255) rm -f "$data"
551
+                 exit 1;;
533 552
         esac
534
-        case $(cat $data) in
553
+        case $(cat "$data") in
535 554
             1) DEBIAN_REPO='ftp.au.debian.org';;
536 555
             2) DEBIAN_REPO='ftp.at.debian.org';;
537 556
             3) DEBIAN_REPO='ftp.by.debian.org';;
@@ -581,8 +600,10 @@ function choose_debian_repo {
581 600
             47) DEBIAN_REPO='ftp.ua.debian.org';;
582 601
             48) DEBIAN_REPO='ftp.uk.debian.org';;
583 602
             49) DEBIAN_REPO='ftp.us.debian.org';;
584
-            255) exit 1;;
603
+            255) rm -f "$data"
604
+                 exit 1;;
585 605
         esac
606
+        rm -f "$data"
586 607
         save_configuration_values
587 608
     else
588 609
         DEBIAN_REPO='ftp.de.debian.org'
@@ -591,28 +612,31 @@ function choose_debian_repo {
591 612
 
592 613
 function choose_rng {
593 614
     if [[ $MINIMAL_INSTALL == "no" ]]; then
594
-        data=$(tempfile 2>/dev/null)
595
-        trap "rm -f $data" 0 1 2 5 15
596
-        if [[ $INSTALLING_ON_BBB != "yes" ]]; then
615
+        data=$(mktemp 2>/dev/null)
616
+        if [[ "$INSTALLING_ON_BBB" != "yes" ]]; then
597 617
             dialog --backtitle $"Freedombone Configuration" \
598 618
                    --radiolist $"Type of Random Number Generator:" 10 40 2 \
599 619
                    1 Haveged on \
600
-                   2 OneRNG off 2> $data
620
+                   2 OneRNG off 2> "$data"
601 621
             sel=$?
602 622
             case $sel in
603
-                1) exit 1;;
604
-                255) exit 1;;
623
+                1) rm -f "$data"
624
+                   exit 1;;
625
+                255) rm -f "$data"
626
+                     exit 1;;
605 627
             esac
606
-            case $(cat $data) in
628
+            case $(cat "$data") in
607 629
                 2) HWRNG_TYPE="onerng"
608 630
                    dialog --title $"OneRNG Device" \
609 631
                           --msgbox $"Please ensure that the OneRNG device is disconnected. You can reconnect it later during the installation" 8 60
610 632
                    ;;
611
-                255) exit 1;;
633
+                255) rm -f "$data"
634
+                     exit 1;;
612 635
             esac
613 636
         else
614 637
             HWRNG_TYPE="beaglebone"
615 638
         fi
639
+        rm -f "$data"
616 640
         save_configuration_values
617 641
     fi
618 642
 }
@@ -621,9 +645,7 @@ function choose_social_key_management {
621 645
     if [[ $MINIMAL_INSTALL == "no" ]]; then
622 646
         interactive_gpg
623 647
 
624
-        data=$(tempfile 2>/dev/null)
625
-        trap "rm -f $data" 0 1 2 5 15
626
-        SOCIAL_KEY_STR=$"\nDo you wish to enable social key management, otherwise known as \"the unforgettable key\"?\n\nThis means that fragments of your GPG key will be included with any remote backups so that if you later lose your key then it can be reconstructed from your friends servers. If you select \"no\" then you can still do social key management, but offline using physical USB thumb drives, which is more secure but less convenient."
648
+        SOCIAL_KEY_STR=$"\\nDo you wish to enable social key management, otherwise known as \"the unforgettable key\"?\\n\\nThis means that fragments of your GPG key will be included with any remote backups so that if you later lose your key then it can be reconstructed from your friends servers. If you select \"no\" then you can still do social key management, but offline using physical USB thumb drives, which is more secure but less convenient."
627 649
         if [[ $(grep "ENABLE_SOCIAL_KEY_MANAGEMENT" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then
628 650
             dialog --title $"Social Key Management" \
629 651
                    --backtitle $"Freedombone Configuration" \
@@ -659,36 +681,36 @@ function choose_username {
659 681
             if [ ! $SELECTED_USERNAME ]; then
660 682
                 SELECTED_USERNAME=$(grep 'MY_USERNAME' temp.cfg | awk -F '=' '{print $2}')
661 683
             fi
662
-            data=$(tempfile 2>/dev/null)
663
-            trap "rm -f $data" 0 1 2 5 15
684
+            data=$(mktemp 2>/dev/null)
664 685
             dialog --backtitle $"Freedombone Configuration" \
665 686
                    --title $"Username" \
666
-                   --inputbox $"Set your username for the system\n\nYour username should not contain any spaces" 12 60 "$SELECTED_USERNAME" 2> $data
687
+                   --inputbox $"Set your username for the system\\n\\nYour username should not contain any spaces" 12 60 "$SELECTED_USERNAME" 2> "$data"
667 688
             sel=$?
668 689
             case $sel in
669
-                0) possible_username=$(cat $data)
690
+                0) possible_username=$(cat "$data")
670 691
                    SELECTED_USERNAME=
671
-                   if [[ $possible_username != *' '* && $possible_username != *'/'* && $possible_username != *'\'* && $possible_username != *'*'* ]]; then
672
-                       if [ $possible_username ]; then
692
+                   if [[ "$possible_username" != *' '* && "$possible_username" != *'/'* && "$possible_username" != *'*'* ]]; then
693
+                       if [ "$possible_username" ]; then
673 694
                            if [ ${#possible_username} -gt 1 ]; then
674
-                               if [[ $possible_username != $GENERIC_IMAGE_USERNAME ]]; then
675
-                                   MY_USERNAME=$(cat $data)
695
+                               if [[ "$possible_username" != "$GENERIC_IMAGE_USERNAME" ]]; then
696
+                                   MY_USERNAME=$(cat "$data")
676 697
                                    please_wait
677 698
                                    echo ''
678 699
                                    echo $'Creating user account'
679 700
                                    chmod 600 /etc/shadow
680 701
                                    chmod 600 /etc/gshadow
681
-                                   useradd -m -s /bin/bash $MY_USERNAME
702
+                                   useradd -m -s /bin/bash "$MY_USERNAME"
682 703
                                    chmod 0000 /etc/shadow
683 704
                                    chmod 0000 /etc/gshadow
684
-                                   if [ -d /home/$MY_USERNAME ]; then
685
-                                       echo "${MY_USERNAME}:$(printf `cat $IMAGE_PASSWORD_FILE`)" | chpasswd
705
+                                   if [ -d "/home/$MY_USERNAME" ]; then
706
+                                       echo "${MY_USERNAME}:$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")" | chpasswd
686 707
                                        # Add the user as a sudoer - they will be the new admin user
687 708
                                        if ! grep -q "$MY_USERNAME  ALL=(ALL) ALL" /etc/sudoers; then
688 709
                                            echo "$MY_USERNAME  ALL=(ALL) ALL" >> /etc/sudoers
689 710
                                            # remove the generic image admin user from sudoers
690 711
                                            sed -i "s|${GENERIC_IMAGE_USERNAME}.*||g" /etc/sudoers
691 712
                                        fi
713
+                                       rm -f "$data"
692 714
                                        break
693 715
                                    fi
694 716
                                fi
@@ -696,13 +718,16 @@ function choose_username {
696 718
                        fi
697 719
                    fi
698 720
                    ;;
699
-                1) exit 1;;
700
-                255) exit 1;;
721
+                1) rm -f "$data"
722
+                   exit 1;;
723
+                255) rm -f "$data"
724
+                     exit 1;;
701 725
             esac
726
+            rm -f "$data"
702 727
         done
703 728
     else
704 729
         no_of_users=$(find /home/* -maxdepth 0 -type d | wc -l)
705
-        if [ $no_of_users -eq 1 ]; then
730
+        if [ "$no_of_users" -eq 1 ]; then
706 731
             # only a single user on the system
707 732
             MY_USERNAME=$(ls /home)
708 733
         else
@@ -741,13 +766,12 @@ function choose_full_name {
741 766
     valid_name=
742 767
     while [ ! $valid_name ]
743 768
     do
744
-        data=$(tempfile 2>/dev/null)
745
-        trap "rm -f $data" 0 1 2 5 15
769
+        data=$(mktemp 2>/dev/null)
746 770
         dialog --backtitle $"Freedombone Configuration" \
747
-               --inputbox $"Your full name (or nick)" 10 50 "$(grep 'MY_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> $data
771
+               --inputbox $"Your full name (or nick)" 10 50 "$(grep 'MY_NAME' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
748 772
         sel=$?
749 773
         case $sel in
750
-            0)  possible_name=$(cat $data)
774
+            0)  possible_name=$(cat "$data")
751 775
                 if [ "$possible_name" ]; then
752 776
                     if [ ${#possible_name} -gt 1 ]; then
753 777
                         valid_name="$possible_name"
@@ -756,9 +780,12 @@ function choose_full_name {
756 780
                     fi
757 781
                 fi
758 782
                 ;;
759
-            1) exit 1;;
760
-            255) exit 1;;
783
+            1) rm -f "$data"
784
+               exit 1;;
785
+            255) rm -f "$data"
786
+                 exit 1;;
761 787
         esac
788
+        rm -f "$data"
762 789
     done
763 790
     save_configuration_values
764 791
     please_wait
@@ -778,16 +805,17 @@ function choose_system_variant {
778 805
             varstate='on'
779 806
         fi
780 807
         varslist="$varslist $n $a $varstate"
781
-        n=$[n+1]
808
+        n=$((n+1))
782 809
     done
783 810
 
784 811
     variant_choice=$(dialog --stdout --backtitle $"Freedombone Configuration" \
785 812
                             --title $"Type of Installation" \
786 813
                             --radiolist $'Choose:' \
787
-                            27 40 20 $varslist)
814
+                            27 40 20 "$varslist")
788 815
 
816
+    # shellcheck disable=SC2181
789 817
     if [ $? -eq 0 ]; then
790
-        variant_choice=$[variant_choice-1]
818
+        variant_choice=$((variant_choice-1))
791 819
         SYSTEM_TYPE=${available_variants_list[$variant_choice]}
792 820
         save_configuration_values
793 821
     fi
@@ -796,7 +824,7 @@ function choose_system_variant {
796 824
 function validate_freedns_code {
797 825
     freedns_code="$1"
798 826
 
799
-    FREEDNS_MESSAGE=$"Please enter the FreeDNS code for this domain.\n\nThe code can be found by going to https://freedns.afraid.org, selecting 'Dynamic DNS' and then opening 'Wget example'. The code will consist of letters and numbers and be between the ? and = characters."
827
+    FREEDNS_MESSAGE=$"Please enter the FreeDNS code for this domain.\\n\\nThe code can be found by going to https://freedns.afraid.org, selecting 'Dynamic DNS' and then opening 'Wget example'. The code will consist of letters and numbers and be between the ? and = characters."
800 828
 
801 829
     if [[ "$freedns_code" == *"."* || "$freedns_code" == "http"* || "$freedns_code" == *"wget "* || "$freedns_code" == *" "* ]]; then
802 830
         dialog --title $"Invalid FreeDNS Code" --msgbox "$FREEDNS_MESSAGE" 10 70
@@ -855,8 +883,7 @@ do
855 883
 done
856 884
 
857 885
 function interactive_select_language {
858
-    data=$(tempfile 2>/dev/null)
859
-    trap "rm -f $data" 0 1 2 5 15
886
+    data=$(mktemp 2>/dev/null)
860 887
     dialog --backtitle $"Freedombone Configuration" \
861 888
            --radiolist $"Select your language:" 26 40 24 \
862 889
            1 $"Afrikaans" off \
@@ -926,13 +953,15 @@ function interactive_select_language {
926 953
            65 $"Thai" off \
927 954
            66 $"Turkish" off \
928 955
            67 $"Ukrainian" off \
929
-           68 $"Vietnamese" off 2> $data
956
+           68 $"Vietnamese" off 2> "$data"
930 957
     sel=$?
931 958
     case $sel in
932
-        1) exit 1;;
933
-        255) exit 1;;
959
+        1) rm -f "$data"
960
+           exit 1;;
961
+        255) rm -f "$data"
962
+             exit 1;;
934 963
     esac
935
-    case $(cat $data) in
964
+    case $(cat "$data") in
936 965
         1) DEFAULT_LANGUAGE='af_ZA.UTF-8';;
937 966
         2) DEFAULT_LANGUAGE='sq_AL.UTF-8';;
938 967
         3) DEFAULT_LANGUAGE='ar_SA.UTF-8';;
@@ -1002,6 +1031,7 @@ function interactive_select_language {
1002 1031
         67) DEFAULT_LANGUAGE='uk_UA.UTF-8';;
1003 1032
         68) DEFAULT_LANGUAGE='vi_VN.UTF-8';;
1004 1033
     esac
1034
+    rm -f "$data"
1005 1035
     save_configuration_values
1006 1036
 
1007 1037
     please_wait
@@ -1021,22 +1051,26 @@ function interactive_select_language {
1021 1051
 function select_user {
1022 1052
     SELECTED_USERNAME=
1023 1053
 
1024
-    users_array=($(ls /home))
1054
+    homedirs=$(ls /home)
1055
+    # shellcheck disable=SC2206
1056
+    users_array=($homedirs)
1025 1057
 
1026 1058
     delete=(git)
1027
-    for del in ${delete[@]}
1059
+    for del in "${delete[@]}"
1028 1060
     do
1061
+        # shellcheck disable=SC2206
1029 1062
         users_array=(${users_array[@]/$del})
1030 1063
     done
1031 1064
 
1032 1065
     i=0
1033 1066
     W=()
1034 1067
     name=()
1068
+    # shellcheck disable=SC2068
1035 1069
     for u in ${users_array[@]}
1036 1070
     do
1037 1071
         if [[ $(is_valid_user "$u") == "1" ]]; then
1038 1072
             i=$((i+1))
1039
-            W+=($i "$u")
1073
+            W+=("$i" "$u")
1040 1074
             name+=("$u")
1041 1075
         fi
1042 1076
     done
@@ -1046,6 +1080,7 @@ function select_user {
1046 1080
     else
1047 1081
         user_index=$(dialog --backtitle $"Freedombone Configuration" --title $"Select User" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
1048 1082
 
1083
+        # shellcheck disable=SC2181
1049 1084
         if [ $? -eq 0 ]; then
1050 1085
             SELECTED_USERNAME="${name[$((user_index-1))]}"
1051 1086
         fi
@@ -1055,19 +1090,19 @@ function select_user {
1055 1090
 function interactive_config {
1056 1091
     # create a temporary copy of the configuration file
1057 1092
     # which can be used to pre-populate selections
1058
-    if [ -f $CONFIGURATION_FILE ]; then
1059
-        cp $CONFIGURATION_FILE temp.cfg
1093
+    if [ -f "$CONFIGURATION_FILE" ]; then
1094
+        cp "$CONFIGURATION_FILE" temp.cfg
1060 1095
     fi
1061 1096
 
1062 1097
     interactive_select_language
1063 1098
 
1064
-    if [ $SOCIALINSTANCE ]; then
1065
-        INITIAL_MESSAGE=$"Welcome to your Freedombone $SOCIALINSTANCE instance.\n\nEnsure that you have your domain and dynamic DNS settings ready.\n\nFor more information please visit ${FREEDOMBONE_WEBSITE}/socialinstance.html."
1099
+    if [ "$SOCIALINSTANCE" ]; then
1100
+        INITIAL_MESSAGE=$"Welcome to your Freedombone $SOCIALINSTANCE instance.\\n\\nEnsure that you have your domain and dynamic DNS settings ready.\\n\\nFor more information please visit ${FREEDOMBONE_WEBSITE}/socialinstance.html."
1066 1101
     else
1067
-        if [[ $ONION_ONLY == "no" ]]; then
1068
-            INITIAL_MESSAGE=$"Welcome to the Freedombone interactive installer. Communications freedom is only a short time away.\n\nEnsure that you have your domain and dynamic DNS settings ready.\n\nFor more information please visit $FREEDOMBONE_WEBSITE."
1102
+        if [[ "$ONION_ONLY" == "no" ]]; then
1103
+            INITIAL_MESSAGE=$"Welcome to the Freedombone interactive installer. Communications freedom is only a short time away.\\n\\nEnsure that you have your domain and dynamic DNS settings ready.\\n\\nFor more information please visit $FREEDOMBONE_WEBSITE."
1069 1104
         else
1070
-            INITIAL_MESSAGE=$"Welcome to the Freedombone interactive installer. Communications freedom is only a short time away.\n\nWeb sites created will only be viewable within a Tor browser.\n\nFor more information please visit $FREEDOMBONE_WEBSITE."
1105
+            INITIAL_MESSAGE=$"Welcome to the Freedombone interactive installer. Communications freedom is only a short time away.\\n\\nWeb sites created will only be viewable within a Tor browser.\\n\\nFor more information please visit $FREEDOMBONE_WEBSITE."
1071 1106
         fi
1072 1107
     fi
1073 1108
 
@@ -1079,7 +1114,7 @@ function interactive_config {
1079 1114
     choose_social_key_management
1080 1115
     choose_rng
1081 1116
     choose_debian_repo
1082
-    ${PROJECT_NAME}-wifi --networksinteractive $WIFI_NETWORKS_FILE
1117
+    "${PROJECT_NAME}-wifi" --networksinteractive "$WIFI_NETWORKS_FILE"
1083 1118
     choose_dynamic_dns
1084 1119
     choose_default_domain_name
1085 1120
     choose_email_address
@@ -1109,7 +1144,7 @@ function interactive_config {
1109 1144
     fi
1110 1145
 
1111 1146
     # This file indicates that the configuration happened successfully
1112
-    touch $HOME/.${PROJECT_NAME}-interactive
1147
+    touch "$HOME/.${PROJECT_NAME}-interactive"
1113 1148
 }
1114 1149
 
1115 1150
 function show_result {
@@ -1120,11 +1155,11 @@ function show_result {
1120 1155
     echo ''
1121 1156
     echo $'Contents:'
1122 1157
     echo ''
1123
-    cat $CONFIGURATION_FILE
1158
+    cat "$CONFIGURATION_FILE"
1124 1159
     echo ''
1125 1160
 }
1126 1161
 
1127
-if [ ! $CONFIGURATION_FILE ]; then
1162
+if [ ! "$CONFIGURATION_FILE" ]; then
1128 1163
     CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
1129 1164
 fi
1130 1165
 

+ 408
- 437
src/freedombone-controlpanel
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 207
- 220
src/freedombone-controlpanel-user
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 13
- 14
src/freedombone-dhparam Просмотреть файл

@@ -141,38 +141,37 @@ function calc_dh {
141 141
     if [[ $FAST == 'yes' ]]; then
142 142
         DHGROUP=$(( ( RANDOM % 4 )  + 14 ))
143 143
         if [[ ${DHGROUP} == 14 ]]; then
144
-            echo "$BETTERCRYPTO_GROUP14" > ${1}
144
+            echo "$BETTERCRYPTO_GROUP14" > "${1}"
145 145
         else
146 146
             if [[ ${DHGROUP} == 15 ]]; then
147
-                echo "$BETTERCRYPTO_GROUP15" > ${1}
147
+                echo "$BETTERCRYPTO_GROUP15" > "${1}"
148 148
             else
149 149
                 if [[ ${DHGROUP} == 16 ]]; then
150
-                    echo "$BETTERCRYPTO_GROUP16" > ${1}
150
+                    echo "$BETTERCRYPTO_GROUP16" > "${1}"
151 151
                 else
152 152
                     if [[ ${DHGROUP} == 17 ]]; then
153
-                        echo "$BETTERCRYPTO_GROUP17" > ${1}
153
+                        echo "$BETTERCRYPTO_GROUP17" > "${1}"
154 154
                     else
155
-                        echo "$BETTERCRYPTO_GROUP18" > ${1}
155
+                        echo "$BETTERCRYPTO_GROUP18" > "${1}"
156 156
                     fi
157 157
                 fi
158 158
             fi
159 159
         fi
160 160
     else
161
-        openssl dhparam -check -text $KEYLENGTH -out ${1}
162
-        if [ ! "$?" = "0" ]; then
161
+        if ! openssl dhparam -check -text $KEYLENGTH -out "${1}"; then
163 162
             exit 3674
164 163
         fi
165 164
     fi
166
-    chmod 640 ${1}
165
+    chmod 640 "${1}"
167 166
 }
168 167
 
169 168
 function regenerate_dh_keys {
170 169
     for file in /etc/ssl/mycerts/*
171 170
     do
172 171
         if [[ -f $file ]]; then
173
-            filename=/etc/ssl/certs/$(echo $file | awk -F '/etc/ssl/mycerts/' '{print $2}' | awk -F '.crt' '{print $1}').dhparam
174
-            if [ -f $filename ]; then
175
-                calc_dh $filename
172
+            filename=/etc/ssl/certs/$(echo "$file" | awk -F '/etc/ssl/mycerts/' '{print $2}' | awk -F '.crt' '{print $1}').dhparam
173
+            if [ -f "$filename" ]; then
174
+                calc_dh "$filename"
176 175
                 echo $"Recalculated DH params for $filename"
177 176
             fi
178 177
         fi
@@ -202,7 +201,7 @@ do
202 201
         -o|--output)
203 202
             shift
204 203
             FAST='yes'
205
-            calc_dh ${1}
204
+            calc_dh "${1}"
206 205
             exit 0
207 206
             ;;
208 207
         --fast)
@@ -223,7 +222,7 @@ if [[ $RECALCULATE == "yes" || $RECALCULATE == "y" ]]; then
223 222
     exit 0
224 223
 fi
225 224
 
226
-if [ ! $HOSTNAME ]; then
225
+if [ ! "$HOSTNAME" ]; then
227 226
     echo $'No hostname specified'
228 227
     exit 5728
229 228
 fi
@@ -237,7 +236,7 @@ if [ ! -d /etc/ssl/mycerts ]; then
237 236
     mkdir -p /etc/ssl/mycerts
238 237
 fi
239 238
 
240
-calc_dh /etc/ssl/certs/$HOSTNAME.dhparam
239
+calc_dh "/etc/ssl/certs/$HOSTNAME.dhparam"
241 240
 
242 241
 systemctl reload nginx
243 242
 exit 0

+ 8
- 8
src/freedombone-encrypt-mail Просмотреть файл

@@ -31,17 +31,17 @@
31 31
 USERNAME=$1
32 32
 
33 33
 PROJECT_NAME='freedombone'
34
-COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
34
+COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
35 35
 
36
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
36
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
37 37
 for f in $UTILS_FILES
38 38
 do
39
-  source $f
39
+  source "$f"
40 40
 done
41 41
 
42 42
 ADMIN_USER=$(get_completion_param "Admin user")
43 43
 
44
-if [ ! $USERNAME ]; then
44
+if [ ! "$USERNAME" ]; then
45 45
     USERNAME=$ADMIN_USER
46 46
 fi
47 47
 
@@ -49,23 +49,23 @@ MAIL_DIR=/home/$USERNAME/Maildir
49 49
 EMAIL_ADDRESS=$USERNAME@$HOSTNAME
50 50
 
51 51
 # Does this key exist?
52
-gpg --list-keys "$EMAIL_ADDRESS" > /dev/null 2>&1
53
-if [ $? -gt 0 ]; then
52
+if ! gpg --list-keys "$EMAIL_ADDRESS" > /dev/null 2>&1; then
54 53
     echo $"A GPG key for $EMAIL_ADDRESS could not be found!"
55 54
     exit 0
56 55
 fi
57 56
 
58 57
 # Find all files in the Maildir specified.
59 58
 echo $"Calling find"
60
-find "$MAIL_DIR" -type f -regex '.*/\(cur\|new\)/.*' $4|while read line; do
59
+find "$MAIL_DIR" -type f -regex '.*/\(cur\|new\)/.*' "$4"|while read -r line; do
61 60
     gpgit.pl --encrypt-mode prefer-inline "$EMAIL_ADDRESS"  "/tmp/msg_$USERNAME"
62 61
 
63 62
     # Check to see if there are differences between the existing
64 63
     # Maildir file and what was created by gpgit.pl
65 64
     diff -qa "$line" "/tmp/msg_$USERNAME" > /dev/null 2>&1;
65
+    # shellcheck disable=SC2181
66 66
     if [ $? -gt 0 ]; then
67 67
         # Preserve timestamps, set ownership.
68
-        chown $USERNAME:$USERNAME "/tmp/msg_$USERNAME"
68
+        chown "$USERNAME":"$USERNAME" "/tmp/msg_$USERNAME"
69 69
         chmod 600   "/tmp/msg_$USERNAME"
70 70
         touch   "/tmp/msg_$USERNAME" --reference="$line"
71 71
 

+ 5
- 8
src/freedombone-format Просмотреть файл

@@ -33,7 +33,7 @@ PROJECT_NAME='freedombone'
33 33
 export TEXTDOMAIN=${PROJECT_NAME}-format
34 34
 export TEXTDOMAINDIR="/usr/share/locale"
35 35
 
36
-if [ ! $1 ]; then
36
+if [ ! "$1" ]; then
37 37
    echo $'Specify a drive, such as sdb, sdc, etc'
38 38
    exit 1
39 39
 fi
@@ -62,21 +62,18 @@ p
62 62
 a
63 63
 1
64 64
 w
65
-" | fdisk /dev/${USB_DRIVE_SHORT};mkfs.ext4 -L "$LABEL" /dev/${USB_DRIVE_SHORT}1
65
+" | fdisk "/dev/${USB_DRIVE_SHORT}";mkfs.ext4 -L "$LABEL" "/dev/${USB_DRIVE_SHORT}1"
66 66
 
67 67
 echo $"Formatting $USB_DRIVE as LUKS"
68
-cryptsetup -y -v luksFormat ${USB_DRIVE}
69
-if [ ! "$?" = "0" ]; then
68
+if ! cryptsetup -y -v luksFormat "${USB_DRIVE}"; then
70 69
     echo $"Failed to format $USB_DRIVE as LUKS"
71 70
     exit 36823
72 71
 fi
73
-cryptsetup luksOpen ${USB_DRIVE} encrypted_usb
74
-if [ ! "$?" = "0" ]; then
72
+if ! cryptsetup luksOpen "${USB_DRIVE}" encrypted_usb; then
75 73
     echo $"Failed to open LUKS formatted drive $USB_DRIVE"
76 74
     exit 37232
77 75
 fi
78
-mkfs.ext4 /dev/mapper/encrypted_usb -L "$LABEL"
79
-if [ ! "$?" = "0" ]; then
76
+if ! mkfs.ext4 /dev/mapper/encrypted_usb -L "$LABEL"; then
80 77
     cryptsetup luksClose encrypted_usb
81 78
     echo $'Format of drive $USB_DRIVE failed'
82 79
     exit 73218

+ 8
- 7
src/freedombone-freedns Просмотреть файл

@@ -41,7 +41,7 @@ if [[ "$1" == "--verbose" || "$1" == "-v" ]]; then
41 41
     VERBOSE=1
42 42
 fi
43 43
 
44
-if [ ! -f $CONFIGURATION_FILE ]; then
44
+if [ ! -f "$CONFIGURATION_FILE" ]; then
45 45
     exit 0
46 46
 fi
47 47
 
@@ -52,28 +52,29 @@ function item_in_array {
52 52
 }
53 53
 
54 54
 detected_codes=()
55
-codelines=$(grep "_CODE=" $CONFIGURATION_FILE | uniq)
55
+codelines=$(grep "_CODE=" "$CONFIGURATION_FILE" | uniq)
56 56
 while read -r line; do
57 57
     code=$(echo "$line" | awk -F '=' '{print $2}')
58
-    item_in_array "$code" "${detected_codes[@]}"
59
-    if [[ $? != 0 ]]; then
58
+    if ! item_in_array "$code" "${detected_codes[@]}"; then
60 59
         detected_codes+=("$code")
61 60
     fi
62 61
 done <<< "$codelines"
63 62
 
64
-if [ ! -d $HOME/.freedns-update ]; then
65
-    mkdir $HOME/.freedns-update
63
+if [ ! -d "$HOME/.freedns-update" ]; then
64
+    mkdir "$HOME/.freedns-update"
66 65
 fi
67
-cd $HOME/.freedns-update
66
+cd "$HOME/.freedns-update" || exit 2467824684
68 67
 for code in "${detected_codes[@]}"
69 68
 do
70 69
     if [ $VERBOSE ]; then
71 70
         echo $"command: $FREEDNS_WGET${code}="
71
+        # shellcheck disable=SC1066,SC1067
72 72
         $FREEDNS_WGET${code}=
73 73
     else
74 74
         if [ -f /tmp/freedns ]; then
75 75
             rm /tmp/freedns
76 76
         fi
77
+        # shellcheck disable=SC1066,SC1067,SC1007
77 78
         $FREEDNS_WGET${code}= >> /tmp/freedns 2>&1
78 79
     fi
79 80
 done

+ 20
- 20
src/freedombone-ignore Просмотреть файл

@@ -79,37 +79,37 @@ if ! [[ $MYUSERNAME && $EMAIL_ADDRESS ]]; then
79 79
     fi
80 80
 fi
81 81
 
82
-MUTTRC=/home/$MYUSERNAME/.muttrc
83
-PM=/home/$MYUSERNAME/.procmailrc
82
+MUTTRC="/home/$MYUSERNAME/.muttrc"
83
+PM="/home/$MYUSERNAME/.procmailrc"
84 84
 
85 85
 # Ignore if subject line contains text
86 86
 if [ "$SUBJECT_TEXT" ]; then
87
-    if ! grep -q "Ignore rule for $SUBJECT_TEXT" $PM; then
88
-        echo "# Ignore rule for $SUBJECT_TEXT" >> $PM
89
-        echo ":0" >> $PM
90
-        echo "  * ^Subject:.*$SUBJECT_TEXT" >> $PM
91
-        echo "/dev/null" >> $PM
92
-        echo "# End of ignore rule" >> $PM
93
-        chown $MYUSERNAME:$MYUSERNAME $PM
87
+    if ! grep -q "Ignore rule for $SUBJECT_TEXT" "$PM"; then
88
+        { echo "# Ignore rule for $SUBJECT_TEXT";
89
+          echo ":0";
90
+          echo "  * ^Subject:.*$SUBJECT_TEXT";
91
+          echo "/dev/null";
92
+          echo "# End of ignore rule"; } >> "$PM"
93
+        chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
94 94
     fi
95 95
 fi
96 96
 
97 97
 # ignore an email address
98
-if [ $EMAIL_ADDRESS ]; then
99
-    if ! grep -q "Ignore rule for $EMAIL_ADDRESS" $PM; then
100
-        echo "# Ignore rule for $EMAIL_ADDRESS" >> $PM
101
-        echo ":0" >> $PM
102
-        echo "  * ^From:.*$EMAIL_ADDRESS" >> $PM
103
-        echo "/dev/null" >> $PM
104
-        echo "# End of ignore rule" >> $PM
105
-        chown $MYUSERNAME:$MYUSERNAME $PM
98
+if [ "$EMAIL_ADDRESS" ]; then
99
+    if ! grep -q "Ignore rule for $EMAIL_ADDRESS" "$PM"; then
100
+        { echo "# Ignore rule for $EMAIL_ADDRESS";
101
+        echo ":0";
102
+        echo "  * ^From:.*$EMAIL_ADDRESS";
103
+        echo "/dev/null";
104
+        echo "# End of ignore rule"; } >> "$PM"
105
+        chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
106 106
     fi
107 107
 fi
108 108
 
109 109
 PROCMAILLOG=/home/$MYUSERNAME/log
110
-if [ ! -d $PROCMAILLOG ]; then
111
-    mkdir $PROCMAILLOG
112
-    chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
110
+if [ ! -d "$PROCMAILLOG" ]; then
111
+    mkdir "$PROCMAILLOG"
112
+    chown -R "$MYUSERNAME":"$MYUSERNAME" "$PROCMAILLOG"
113 113
 fi
114 114
 
115 115
 exit 0

+ 75
- 74
src/freedombone-image Просмотреть файл

@@ -42,14 +42,14 @@ if [ -f /usr/bin/${PROJECT_NAME} ]; then
42 42
     PROJECT_INSTALL_DIR=/usr/bin
43 43
 fi
44 44
 
45
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
45
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
46 46
 
47 47
 #get the project repo
48 48
 PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}"
49
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
49
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
50 50
 for f in $UTILS_FILES
51 51
 do
52
-    source $f
52
+    source "$f"
53 53
 done
54 54
 read_config_param PROJECT_REPO
55 55
 
@@ -96,7 +96,7 @@ CONFIG_FILENAME=
96 96
 DEFAULT_DOMAIN_NAME="${LOCAL_NAME}.local"
97 97
 
98 98
 # Minimum number of characters in a password
99
-MINIMUM_PASSWORD_LENGTH=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords | grep 'MINIMUM_PASSWORD_LENGTH=' | head -n 1 | awk -F '=' '{print $2}')
99
+MINIMUM_PASSWORD_LENGTH=$(grep 'MINIMUM_PASSWORD_LENGTH=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords" | head -n 1 | awk -F '=' '{print $2}')
100 100
 
101 101
 # Optional ssh public key to allow
102 102
 SSH_PUBKEY="no"
@@ -175,38 +175,36 @@ function image_setup {
175 175
             sudo pacman -S --noconfirm qemu-static binfmt-qemu-static uboot-tools qemu parted
176 176
             sudo pacman -S --noconfirm dpkg-devtools bin86 arch-install-scripts qemu-arch-extra
177 177
             sudo pacman -S --noconfirm syncthing
178
-            mkdir $USERHOME/develop
179
-            if [ -d $USERHOME/develop/python-cliapp ]; then
180
-                sudo rm -rf $USERHOME/develop/python-cliapp
178
+            mkdir "$USERHOME/develop"
179
+            if [ -d "$USERHOME/develop/python-cliapp" ]; then
180
+                sudo rm -rf "$USERHOME/develop/python-cliapp"
181 181
             fi
182
-            git_clone $CLIAPP_REPO $USERHOME/develop/python-cliapp
183
-            if [ ! "$?" = "0" ]; then
182
+            if ! git_clone "$CLIAPP_REPO" "$USERHOME/develop/python-cliapp"; then
184 183
                 echo $"Failed to clone python-cliapp"
185 184
                 return
186 185
             fi
187
-            if [ ! -d $USERHOME/develop/python-cliapp ]; then
186
+            if [ ! -d "$USERHOME/develop/python-cliapp" ]; then
188 187
                 echo $"Couldn't clone python-cliapp"
189 188
                 return
190 189
             fi
191 190
             sudo pacman -S --noconfirm python2-coverage python2-pytest-cov python2-sphinx
192 191
             sudo pacman -S --noconfirm autopep8 python2-pylint python2-yaml python2-xdg python2-pip
193
-            cd $USERHOME/develop/python-cliapp
192
+            cd "$USERHOME/develop/python-cliapp" || exit 7824526242
194 193
             git checkout $CLIAPP_COMMIT -b $CLIAPP_COMMIT
195 194
             sudo python2 setup.py install
196 195
             sudo pip2 install distro-info logging
197
-            if [ -d $USERHOME/develop/mbr ]; then
198
-                sudo rm -rf $USERHOME/develop/mbr
196
+            if [ -d "$USERHOME/develop/mbr" ]; then
197
+                sudo rm -rf "$USERHOME/develop/mbr"
199 198
             fi
200
-            git_clone $MBR_REPO $USERHOME/develop/mbr
201
-            if [ ! "$?" = "0" ]; then
199
+            if ! git_clone $MBR_REPO "$USERHOME/develop/mbr"; then
202 200
                 echo $"Failed to clone mbr"
203 201
                 return
204 202
             fi
205
-            if [ ! -d $USERHOME/develop/mbr ]; then
203
+            if [ ! -d "$USERHOME/develop/mbr" ]; then
206 204
                 echo $"Couldn't clone mbr"
207 205
                 return
208 206
             fi
209
-            cd $USERHOME/develop/mbr
207
+            cd "$USERHOME/develop/mbr" || exit 2468724524
210 208
             git checkout $MBR_COMMIT -b $MBR_COMMIT
211 209
             makepkg --force --noconfirm
212 210
             if [ ! -f mbr-${MBR_VERSION}.tar.gz ]; then
@@ -214,11 +212,11 @@ function image_setup {
214 212
                 return
215 213
             fi
216 214
             tar -xzvf mbr-${MBR_VERSION}.tar.gz
217
-            if [ ! -d $USERHOME/develop/mbr/mbr-${MBR_VERSION} ]; then
215
+            if [ ! -d "$USERHOME/develop/mbr/mbr-${MBR_VERSION}" ]; then
218 216
                 echo $"mbr tarball could not be extracted"
219 217
                 return
220 218
             fi
221
-            cd $USERHOME/develop/mbr/mbr-${MBR_VERSION}
219
+            cd "$USERHOME/develop/mbr/mbr-${MBR_VERSION}" || exit 13584584
222 220
             cp ../*.patch .
223 221
             patch -p0 < *.patch
224 222
             ./configure
@@ -229,35 +227,34 @@ function image_setup {
229 227
                 return
230 228
             fi
231 229
             sudo cp /usr/local/sbin/install-mbr /sbin
232
-            if [ -d $USERHOME/develop/multipath-tools ]; then
233
-                sudo rm -rf $USERHOME/develop/multipath-tools
230
+            if [ -d "$USERHOME/develop/multipath-tools" ]; then
231
+                sudo rm -rf "$USERHOME/develop/multipath-tools"
234 232
             fi
235
-            git_clone $MULTIPATH_TOOLS_REPO $USERHOME/develop/multipath-tools
236
-            if [ ! "$?" = "0" ]; then
233
+            if ! git_clone "$MULTIPATH_TOOLS_REPO" "$USERHOME/develop/multipath-tools"; then
237 234
                 echo $"Failed to clone multipath-tools"
238 235
                 return
239 236
             fi
240
-            if [ ! -d $USERHOME/develop/multipath-tools ]; then
237
+            if [ ! -d "$USERHOME/develop/multipath-tools" ]; then
241 238
                 echo $"Couldn't clone multipath-tools"
242 239
                 return
243 240
             fi
244 241
             sudo pacman -S --noconfirm device-mapper libaio liburcu fakeroot
245
-            cd $USERHOME/develop/multipath-tools
242
+            cd "$USERHOME/develop/multipath-tools" || exit 27462454
246 243
             makepkg --force --noconfirm
247 244
             makepkg -i --force --noconfirm
248
-            sudo wget https://raw.githubusercontent.com/bashrc/freedombone/master/image_build/debootstrap/scripts/${DEBIAN_VERSION} -O /usr/share/debootstrap/scripts/debscript
249
-            sudo cp -f /usr/share/debootstrap/scripts/debscript /usr/share/debootstrap/scripts/${DEBIAN_VERSION}
250
-            if [ ! -f /usr/share/debootstrap/scripts/${DEBIAN_VERSION} ]; then
245
+            sudo wget "https://raw.githubusercontent.com/bashrc/freedombone/master/image_build/debootstrap/scripts/${DEBIAN_VERSION}" -O /usr/share/debootstrap/scripts/debscript
246
+            sudo cp -f "/usr/share/debootstrap/scripts/debscript /usr/share/debootstrap/scripts/${DEBIAN_VERSION}"
247
+            if [ ! -f "/usr/share/debootstrap/scripts/${DEBIAN_VERSION}" ]; then
251 248
                 echo $"No debian debootstrap script was found for $DEBIAN_VERSION"
252 249
                 return
253 250
             fi
254
-            debian_script_hash=$(sha256sum /usr/share/debootstrap/scripts/${DEBIAN_VERSION} | awk -F ' ' '{print $1}')
251
+            debian_script_hash=$(sha256sum "/usr/share/debootstrap/scripts/${DEBIAN_VERSION}" | awk -F ' ' '{print $1}')
255 252
             expected_debian_script_hash='620fa84c7ef64d10349aed38fa9cc2e7f00a6fcd1bc425f33ca2b57cc946fd0c'
256 253
             if [[ "$debian_script_hash" != "$expected_debian_script_hash" ]]; then
257 254
                 echo $"Invalid hash for debootstrap ${DEBIAN_VERSION} script"
258 255
                 return
259 256
             fi
260
-            sudo chmod +x /usr/share/debootstrap/scripts/${DEBIAN_VERSION}
257
+            sudo chmod +x "/usr/share/debootstrap/scripts/${DEBIAN_VERSION}"
261 258
             ;;
262 259
         *)
263 260
             echo $'Unkown operating system'
@@ -271,26 +268,26 @@ function image_setup {
271 268
 function mesh_router_setup_script {
272 269
     # create a setup script for a mesh router
273 270
     mesh_script_filename=$1
274
-    echo "MY_USERNAME=${USERNAME}" > $mesh_script_filename
275
-    echo "DEFAULT_DOMAIN_NAME=${USERNAME}" >> $mesh_script_filename
276
-    echo 'SYSTEM_TYPE=mesh' >> $mesh_script_filename
277
-    echo 'INSTALLING_ON_BBB=no' >> $mesh_script_filename
278
-    echo 'USB_DRIVE=/dev/sda1' >> $mesh_script_filename
279
-    echo 'DDNS_PROVIDER=' >> $mesh_script_filename
280
-    echo 'DDNS_USERNAME=' >> $mesh_script_filename
281
-    echo 'DDNS_PASSWORD=' >> $mesh_script_filename
282
-    echo 'DEFAULT_LANGUAGE=en_GB.UTF-8' >> $mesh_script_filename
283
-    echo 'MY_EMAIL_ADDRESS=' >> $mesh_script_filename
284
-    echo 'ENABLE_BATMAN=yes' >> $mesh_script_filename
285
-    echo 'DEBIAN_REPO=' >> $mesh_script_filename
286
-    echo 'NAMESERVER1=' >> $mesh_script_filename
287
-    echo 'NAMESERVER2=' >> $mesh_script_filename
288
-    echo 'NAMESERVER3=' >> $mesh_script_filename
289
-    echo 'NAMESERVER4=' >> $mesh_script_filename
290
-    echo 'NAMESERVER5=' >> $mesh_script_filename
291
-    echo 'NAMESERVER6=' >> $mesh_script_filename
292
-    echo 'BATMAN_CELLID=any' >> $mesh_script_filename
293
-    echo 'WIFI_CHANNEL=9' >> $mesh_script_filename
271
+    { echo "MY_USERNAME=${USERNAME}";
272
+      echo "DEFAULT_DOMAIN_NAME=${USERNAME}";
273
+      echo 'SYSTEM_TYPE=mesh';
274
+      echo 'INSTALLING_ON_BBB=no';
275
+      echo 'USB_DRIVE=/dev/sda1';
276
+      echo 'DDNS_PROVIDER=';
277
+      echo 'DDNS_USERNAME=';
278
+      echo 'DDNS_PASSWORD=';
279
+      echo 'DEFAULT_LANGUAGE=en_GB.UTF-8';
280
+      echo 'MY_EMAIL_ADDRESS=';
281
+      echo 'ENABLE_BATMAN=yes';
282
+      echo 'DEBIAN_REPO=';
283
+      echo 'NAMESERVER1=';
284
+      echo 'NAMESERVER2=';
285
+      echo 'NAMESERVER3=';
286
+      echo 'NAMESERVER4=';
287
+      echo 'NAMESERVER5=';
288
+      echo 'NAMESERVER6=';
289
+      echo 'BATMAN_CELLID=any';
290
+      echo 'WIFI_CHANNEL=9'; } > "$mesh_script_filename"
294 291
 }
295 292
 
296 293
 while [ $# -gt 1 ]
@@ -304,11 +301,11 @@ do
304 301
         -c|--config)
305 302
             shift
306 303
             CONFIG_FILENAME="$1"
307
-            if [ ! -f $CONFIG_FILENAME ]; then
304
+            if [ ! -f "$CONFIG_FILENAME" ]; then
308 305
                 echo $"Config file $CONFIG_FILENAME not found"
309 306
                 exit 3
310 307
             fi
311
-            DEFAULT_DOMAIN_NAME=$(cat $CONFIG_FILENAME | grep 'DEFAULT_DOMAIN_NAME' | awk -F '=' '{print $2}')
308
+            DEFAULT_DOMAIN_NAME=$(grep 'DEFAULT_DOMAIN_NAME' "$CONFIG_FILENAME" | awk -F '=' '{print $2}')
312 309
             ;;
313 310
         -t|--target|--board)
314 311
             shift
@@ -321,7 +318,7 @@ do
321 318
         -p|--password)
322 319
             shift
323 320
             PASSWORD="$1"
324
-            if [ ${#PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
321
+            if [ ${#PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
325 322
                 echo $"Your password chould contain at least ${MINIMUM_PASSWORD_LENGTH} characters"
326 323
                 exit 3628
327 324
             fi
@@ -415,7 +412,7 @@ do
415 412
             shift
416 413
             MIRROR="$1"
417 414
             ;;
418
-        --debianonly|--basic|--minimal)
415
+        --debianonly|--basic)
419 416
             shift
420 417
             DEBIAN_INSTALL_ONLY="$1"
421 418
             ;;
@@ -467,9 +464,9 @@ done
467 464
 
468 465
 if [[ $INTERACTIVE == "yes" || $INTERACTIVE == "y" || $INTERACTIVE == "Yes" ]]; then
469 466
     ${PROJECT_NAME}-config --minimal "$MINIMAL_INSTALL"
470
-    if [ -f $HOME/${PROJECT_NAME}.cfg ]; then
467
+    if [ -f "$HOME/${PROJECT_NAME}.cfg" ]; then
471 468
         CONFIG_FILENAME=$HOME/${PROJECT_NAME}.cfg
472
-        DEFAULT_DOMAIN_NAME=$(cat $CONFIG_FILENAME | grep 'DEFAULT_DOMAIN_NAME' | awk -F '=' '{print $2}')
469
+        DEFAULT_DOMAIN_NAME=$(grep 'DEFAULT_DOMAIN_NAME' "$CONFIG_FILENAME" | awk -F '=' '{print $2}')
473 470
     fi
474 471
 fi
475 472
 
@@ -480,34 +477,36 @@ fi
480 477
 
481 478
 if [ ! $PASSWORD ]; then
482 479
     # generate a random password
483
-    PASSWORD=$(openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c ${MINIMUM_PASSWORD_LENGTH})
480
+    PASSWORD=$(openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c "${MINIMUM_PASSWORD_LENGTH}")
484 481
 fi
485 482
 
486 483
 # Move any existing images into a build subdirectory
487 484
 image_types=( xz img sig vdi qcow2 )
488 485
 for im in "${image_types[@]}"
489 486
 do
487
+    # shellcheck disable=SC2012,SC2086
490 488
     no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
491 489
     if (( no_of_files > 0 )); then
492
-        if [ ! -d ${CURR_DIR}/build ]; then
493
-            mkdir ${CURR_DIR}/build
490
+        if [ ! -d "${CURR_DIR}/build" ]; then
491
+            mkdir "${CURR_DIR}/build"
494 492
         fi
495
-        mv -f ${CURR_DIR}/${PROJECT_NAME}*.${im} ${CURR_DIR}/build
493
+        mv -f "${CURR_DIR}/${PROJECT_NAME}*.${im}" "${CURR_DIR}/build"
496 494
     fi
497 495
 done
498 496
 
499 497
 # Delete anything which didn't move
500 498
 for im in "${image_types[@]}"
501 499
 do
500
+    # shellcheck disable=SC2012,SC2086
502 501
     no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
503 502
     if (( no_of_files > 0 )); then
504
-        rm -f ${CURR_DIR}/${PROJECT_NAME}*.${im}
503
+        rm -f "${CURR_DIR}/${PROJECT_NAME}*.${im}"
505 504
     fi
506 505
 done
507 506
 
508 507
 # Remove any existing login credentials file
509
-if [ -f ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt ]; then
510
-    rm ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt
508
+if [ -f "${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt" ]; then
509
+    rm "${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt"
511 510
 fi
512 511
 
513 512
 if [ -d $TEMPBUILD_DIR ]; then
@@ -522,8 +521,8 @@ fi
522 521
 
523 522
 cp -r /etc/${PROJECT_NAME}/* $TEMPBUILD_DIR
524 523
 rm -rf $TEMPBUILD_DIR/vendor
525
-chown -R $CURR_USER:$CURR_USER $TEMPBUILD_DIR
526
-cd $TEMPBUILD_DIR
524
+chown -R "$CURR_USER":"$CURR_USER" $TEMPBUILD_DIR
525
+cd $TEMPBUILD_DIR || exit 24729847
527 526
 
528 527
 if [[ $MINIMAL_INSTALL == "yes" ]]; then
529 528
     IMAGE_NAME=$'min'
@@ -565,8 +564,8 @@ if [[ "$SOCIALINSTANCE" == "gnusocial" || "$SOCIALINSTANCE" == "postactiv" ]]; t
565 564
     IMAGE_NAME="${IMAGE_NAME}-${SOCIALINSTANCE}"
566 565
 fi
567 566
 
568
-cd $TEMPBUILD_DIR
569
-make $IMAGE_TYPE \
567
+cd $TEMPBUILD_DIR || exit 724245267
568
+make "$IMAGE_TYPE" \
570 569
      MYUSERNAME="$USERNAME" \
571 570
      MYPASSWORD="$PASSWORD" \
572 571
      ROUTER_IP_ADDRESS="$ROUTER_IP_ADDRESS" \
@@ -603,6 +602,7 @@ make $IMAGE_TYPE \
603 602
      SOCIALINSTANCE="$SOCIALINSTANCE" \
604 603
      LOCAL_NAME="$LOCAL_NAME"
605 604
 
605
+# shellcheck disable=SC2181
606 606
 if [ ! "$?" = "0" ]; then
607 607
     echo $'Build failed'
608 608
     rm -rf $TEMPBUILD_DIR
@@ -615,7 +615,7 @@ if [[ $IMAGE_TYPE == "qemu"* ]]; then
615 615
 fi
616 616
 
617 617
 shopt -s nullglob
618
-imgfiles=(build/${PROJECT_NAME}*.${EXPECTED_EXTENSION})
618
+imgfiles=("build/${PROJECT_NAME}*.${EXPECTED_EXTENSION}")
619 619
 if [ ${#imgfiles[@]} -eq 0 ]; then
620 620
     echo $'Image was not created'
621 621
     rm -rf $TEMPBUILD_DIR
@@ -625,17 +625,18 @@ fi
625 625
 # Move images from temporary directory to the current directory
626 626
 for im in "${image_types[@]}"
627 627
 do
628
+    # shellcheck disable=SC2012,SC2086
628 629
     no_of_files=$(ls -afq build/${PROJECT_NAME}*.${im} | wc -l)
629 630
     if (( no_of_files > 0 )); then
630
-        mv build/${PROJECT_NAME}*.${im} ${CURR_DIR}/
631
-        sudo chown ${CURR_USER}:${CURR_USER} ${CURR_DIR}/*.${im}
631
+        mv "build/${PROJECT_NAME}*.${im}" "${CURR_DIR}/"
632
+        sudo chown "${CURR_USER}":"${CURR_USER}" "${CURR_DIR}/*.${im}"
632 633
     fi
633 634
 done
634 635
 
635 636
 # Remove the temporary directory
636 637
 rm -rf ${TEMPBUILD_DIR}
637 638
 
638
-cd ${CURR_DIR}
639
+cd "${CURR_DIR}" || exit 2842845284
639 640
 
640 641
 clear
641 642
 if [[ $VARIANT != 'meshclient' && $VARIANT != 'meshusb' && $VARIANT != 'mesh' ]]; then
@@ -676,13 +677,13 @@ ls -lh ${PROJECT_NAME}*.img ${PROJECT_NAME}*.sig ${PROJECT_NAME}*.xz ${PROJECT_N
676 677
 
677 678
 # Remove the mesh script after use
678 679
 if [[ $VARIANT == "mesh"* ]]; then
679
-    rm -f $CONFIG_FILENAME
680
+    rm -f "$CONFIG_FILENAME"
680 681
 fi
681 682
 
682 683
 # record the default login credentials for later use
683 684
 echo $"Username: $USERNAME
684
-Password: $PASSWORD" > ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt
685
-chmod 600 ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt
685
+Password: $PASSWORD" > "${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt"
686
+chmod 600 "${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt"
686 687
 
687 688
 if [[ $IMAGE_TYPE != "qemu"* ]]; then
688 689
     echo ''

+ 683
- 679
src/freedombone-image-customise
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 19
- 25
src/freedombone-image-hardware-setup Просмотреть файл

@@ -34,12 +34,11 @@ export TEXTDOMAINDIR="/usr/share/locale"
34 34
 enable_serial_console() {
35 35
     # By default, spawn a console on the serial port
36 36
     device="$1"
37
-    echo $"Adding a getty on the serial port"
37
+    echo "Adding a getty on the serial port"
38 38
     echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
39 39
 }
40 40
 
41 41
 beaglebone_setup_boot() {
42
-    bbb_version=$1
43 42
 
44 43
     # Setup uEnv.txt
45 44
     if grep -q btrfs /etc/fstab ; then
@@ -47,12 +46,9 @@ beaglebone_setup_boot() {
47 46
     else
48 47
         fstype=ext4
49 48
     fi
50
-    if [ ! $bbb_version ]; then
51
-        kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
52
-    else
53
-        kernelVersion=$(ls /usr/lib/*/am335x-boneblack-${1}.dtb | head -1 | cut -d/ -f4)
54
-    fi
55
-    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
49
+    # shellcheck disable=SC2012
50
+    kernelVersion=$(ls "/usr/lib/*/am335x-boneblack.dtb" | head -1 | cut -d/ -f4)
51
+    version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
56 52
     initRd=initrd.img-$version
57 53
     vmlinuz=vmlinuz-$version
58 54
 
@@ -103,7 +99,6 @@ beaglebone_flash() {
103 99
 }
104 100
 
105 101
 beaglebone_repack_kernel() {
106
-    bbb_version=$1
107 102
     # process installed kernel to create uImage, uInitrd, dtb
108 103
     # using flash-kernel would be a good approach, except it fails in the
109 104
     # cross build environment due to too many environment checks...
@@ -119,12 +114,10 @@ beaglebone_repack_kernel() {
119 114
     echo "info: repacking beaglebone kernel and initrd"
120 115
 
121 116
     bbb_dtb='am335x-boneblack'
122
-    if [ $bbb_version ]; then
123
-        bbb_dtb="am335x-boneblack-${bbb_version}"
124
-    fi
125 117
 
126
-    kernelVersion=$(ls /usr/lib/*/${bbb_dtb}.dtb | head -1 | cut -d/ -f4)
127
-    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
118
+    # shellcheck disable=SC2012
119
+    kernelVersion=$(ls "/usr/lib/*/${bbb_dtb}.dtb" | head -1 | cut -d/ -f4)
120
+    version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
128 121
     initRd=initrd.img-$version
129 122
     vmlinuz=vmlinuz-$version
130 123
 
@@ -143,23 +136,23 @@ beaglebone_repack_kernel() {
143 136
 
144 137
     mkdir /tmp/initrd-repack
145 138
 
146
-    (cd /tmp/initrd-repack ; \
147
-     zcat /boot/$initRd | cpio -i ; \
139
+    (cd /tmp/initrd-repack || exit 2468246 ; \
140
+     zcat "/boot/$initRd" | cpio -i ; \
148 141
      rm -f conf/param.conf ; \
149 142
      find . | cpio --quiet -o -H newc | \
150
-         gzip -9 > /boot/$initRd )
143
+         gzip -9 > "/boot/$initRd" )
151 144
 
152 145
     rm -rf /tmp/initrd-repack
153 146
 
154
-    (cd /boot ; \
155
-     cp ${bbb_dtb_file} dtb ; \
156
-     cat $vmlinuz dtb >> temp-kernel ; \
147
+    (cd /boot || exit 246824684 ; \
148
+     cp "${bbb_dtb_file}" dtb ; \
149
+     cat "$vmlinuz" dtb >> temp-kernel ; \
157 150
      mkimage -A arm -O linux -T kernel -n "Debian kernel ${version}" \
158 151
              -C none -a 0x82000000 -e 0x82000000 -d temp-kernel uImage ; \
159 152
      rm -f temp-kernel ; \
160 153
      mkimage -A arm -O linux -T ramdisk -C gzip -a 0x88080000 -e 0x88080000 \
161 154
              -n "Debian ramdisk ${version}" \
162
-             -d $initRd uInitrd )
155
+             -d "$initRd" uInitrd )
163 156
 }
164 157
 
165 158
 a20_setup_boot() {
@@ -171,8 +164,9 @@ a20_setup_boot() {
171 164
     else
172 165
         fstype=ext4
173 166
     fi
174
-    kernelVersion=$(ls /usr/lib/*/$dtb | head -1 | cut -d/ -f4)
175
-    version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
167
+    # shellcheck disable=SC2012
168
+    kernelVersion=$(ls "/usr/lib/*/$dtb" | head -1 | cut -d/ -f4)
169
+    version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
176 170
     initRd=initrd.img-$version
177 171
     vmlinuz=vmlinuz-$version
178 172
 
@@ -213,7 +207,7 @@ EOF
213 207
 
214 208
     # Copy all DTBs
215 209
     mkdir -p /boot/dtbs
216
-    cp /usr/lib/$kernelVersion/* /boot/dtbs
210
+    cp "/usr/lib/$kernelVersion/*" /boot/dtbs
217 211
 
218 212
     # extra boot modules
219 213
     echo "rtc_sunxi" >> /etc/initramfs-tools/modules
@@ -224,7 +218,7 @@ setup_flash_kernel() {
224 218
     if [ ! -d /etc/flash-kernel ] ; then
225 219
        mkdir /etc/flash-kernel
226 220
     fi
227
-    echo -n "$1" > /etc/flash-kernel/machine
221
+    echo "$1" > /etc/flash-kernel/machine
228 222
 
229 223
     command_line=""
230 224
     if [ -n "$2" ] ; then

+ 52
- 52
src/freedombone-image-make Просмотреть файл

@@ -35,11 +35,11 @@ export TEXTDOMAIN=${PROJECT_NAME}-image-make
35 35
 export TEXTDOMAINDIR="/usr/share/locale"
36 36
 
37 37
 PROJECT_INSTALL_DIR=/usr/local/bin
38
-if [ -f /usr/bin/${PROJECT_NAME} ]; then
38
+if [ -f "/usr/bin/${PROJECT_NAME}" ]; then
39 39
     PROJECT_INSTALL_DIR=/usr/bin
40 40
 fi
41 41
 
42
-source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-setup
42
+source "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-setup"
43 43
 
44 44
 #set -x # Enable debugging
45 45
 
@@ -103,7 +103,7 @@ a20_pkgs="linux-image-armmp-lpae u-boot-tools u-boot u-boot-sunxi"
103 103
 # Packages needed for self-hosted development
104 104
 dev_pkgs="build-essential devscripts make man-db emacs org-mode git mercurial"
105 105
 
106
-echo Building $MACHINE $PROJECT_NAME for $ARCHITECTURE.
106
+echo Building "$MACHINE" "$PROJECT_NAME" for "$ARCHITECTURE".
107 107
 
108 108
 case "$MACHINE" in
109 109
     beaglebone)
@@ -164,7 +164,7 @@ for p in $base_pkgs $extra_pkgs; do
164 164
 done
165 165
 
166 166
 # Make sure file is owned by current user, not root
167
-touch $(dirname $IMAGE)/${PROJECT_NAME}.log
167
+touch "$(dirname "$IMAGE")/${PROJECT_NAME}.log"
168 168
 
169 169
 if [ -x vendor/vmdebootstrap/vmdebootstrap ] ; then
170 170
     VMDEBOOTSTRAP=vendor/vmdebootstrap/vmdebootstrap
@@ -173,15 +173,15 @@ else
173 173
 fi
174 174
 
175 175
 PROJECT_INSTALL_DIR=/usr/local/bin
176
-if [ -f /usr/bin/${PROJECT_NAME} ]; then
176
+if [ -f "/usr/bin/${PROJECT_NAME}" ]; then
177 177
     PROJECT_INSTALL_DIR=/usr/bin
178 178
 fi
179 179
 
180 180
 echo $'Making customised customisation script'
181
-TEMP_CUSTOMISE=/etc/${PROJECT_NAME}/image-customise
182
-TEMP_CUSTOMISE2=/tmp/${PROJECT_NAME}-image-customise2
183
-TEMP_CUSTOMISE3=/tmp/${PROJECT_NAME}-image-customise3
184
-TEMP_CUSTOMISE4=/tmp/${PROJECT_NAME}-image-customise4
181
+TEMP_CUSTOMISE="/etc/${PROJECT_NAME}/image-customise"
182
+TEMP_CUSTOMISE2="/tmp/${PROJECT_NAME}-image-customise2"
183
+TEMP_CUSTOMISE3="/tmp/${PROJECT_NAME}-image-customise3"
184
+TEMP_CUSTOMISE4="/tmp/${PROJECT_NAME}-image-customise4"
185 185
 
186 186
 # cat all the things together
187 187
 combine_all_scripts $TEMP_CUSTOMISE2
@@ -191,43 +191,43 @@ if [ ! -f $TEMP_CUSTOMISE2 ]; then
191 191
 fi
192 192
 
193 193
 echo $'Changing values within customised customisation script'
194
-cp $PROJECT_INSTALL_DIR/${PROJECT_NAME}-image-customise $TEMP_CUSTOMISE3
195
-if [ $MYUSERNAME ]; then
196
-    sed -i "s|MY_USERNAME=.*|MY_USERNAME=${MYUSERNAME}|g" $TEMP_CUSTOMISE3
194
+cp "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-image-customise" "$TEMP_CUSTOMISE3"
195
+if [ "$MYUSERNAME" ]; then
196
+    sed -i "s|MY_USERNAME=.*|MY_USERNAME=${MYUSERNAME}|g" "$TEMP_CUSTOMISE3"
197 197
 fi
198
-if [ $MYPASSWORD ]; then
199
-    sed -i "s|MY_PASSWORD=.*|MY_PASSWORD=${MYPASSWORD}|g" $TEMP_CUSTOMISE3
198
+if [ "$MYPASSWORD" ]; then
199
+    sed -i "s|MY_PASSWORD=.*|MY_PASSWORD=${MYPASSWORD}|g" "$TEMP_CUSTOMISE3"
200 200
 fi
201
-sed -i "s|ROUTER_IP_ADDRESS=.*|ROUTER_IP_ADDRESS=${ROUTER_IP_ADDRESS}|g" $TEMP_CUSTOMISE3
202
-sed -i "s|BOX_IP_ADDRESS=.*|BOX_IP_ADDRESS=${BOX_IP_ADDRESS}|g" $TEMP_CUSTOMISE3
203
-sed -i "s|NAMESERVER1=.*|NAMESERVER1=${NAMESERVER1}|g" $TEMP_CUSTOMISE3
204
-sed -i "s|NAMESERVER2=.*|NAMESERVER2=${NAMESERVER2}|g" $TEMP_CUSTOMISE3
205
-sed -i "s|NAMESERVER3=.*|NAMESERVER3=${NAMESERVER3}|g" $TEMP_CUSTOMISE3
206
-sed -i "s|NAMESERVER4=.*|NAMESERVER4=${NAMESERVER4}|g" $TEMP_CUSTOMISE3
207
-sed -i "s|NAMESERVER5=.*|NAMESERVER5=${NAMESERVER5}|g" $TEMP_CUSTOMISE3
208
-sed -i "s|NAMESERVER6=.*|NAMESERVER6=${NAMESERVER6}|g" $TEMP_CUSTOMISE3
209
-sed -i "s|PROJECT_NAME=.*|PROJECT_NAME=${PROJECT_NAME}|g" $TEMP_CUSTOMISE3
210
-sed -i "s|CONFIG_FILENAME=.*|CONFIG_FILENAME=${CONFIG_FILENAME}|g" $TEMP_CUSTOMISE3
211
-sed -i "s|SSH_PUBKEY=.*|SSH_PUBKEY=${SSH_PUBKEY}|g" $TEMP_CUSTOMISE3
212
-sed -i "s|GENERIC_IMAGE=.*|GENERIC_IMAGE=${GENERIC_IMAGE}|g" $TEMP_CUSTOMISE3
213
-sed -i "s|MINIMAL_INSTALL=.*|MINIMAL_INSTALL=\"${MINIMAL_INSTALL}\"|g" $TEMP_CUSTOMISE3
214
-sed -i "s|SSH_PORT=.*|SSH_PORT=\"${SSH_PORT}\"|g" $TEMP_CUSTOMISE3
215
-sed -i "s|ONION_ONLY=.*|ONION_ONLY=\"${ONION_ONLY}\"|g" $TEMP_CUSTOMISE3
216
-sed -i "s|PROJECT_REPO=.*|PROJECT_REPO=\"${PROJECT_REPO}\"|g" $TEMP_CUSTOMISE3
217
-sed -i "s|DEBIAN_INSTALL_ONLY=.*|DEBIAN_INSTALL_ONLY=\"${DEBIAN_INSTALL_ONLY}\"|g" $TEMP_CUSTOMISE3
218
-sed -i "s|WIFI_INTERFACE=.*|WIFI_INTERFACE=\"${WIFI_INTERFACE}\"|g" $TEMP_CUSTOMISE3
219
-sed -i "s|WIFI_SSID=.*|WIFI_SSID=\"${WIFI_SSID}\"|g" $TEMP_CUSTOMISE3
220
-sed -i "s|WIFI_TYPE=.*|WIFI_TYPE=\"${WIFI_TYPE}\"|g" $TEMP_CUSTOMISE3
221
-sed -i "s|WIFI_PASSPHRASE=.*|WIFI_PASSPHRASE=\"${WIFI_PASSPHRASE}\"|g" $TEMP_CUSTOMISE3
222
-sed -i "s|WIFI_HOTSPOT=.*|WIFI_HOTSPOT=\"${WIFI_HOTSPOT}\"|g" $TEMP_CUSTOMISE3
223
-sed -i "s|WIFI_NETWORKS_FILE=.*|WIFI_NETWORKS_FILE=\"${WIFI_NETWORKS_FILE}\"|g" $TEMP_CUSTOMISE3
224
-sed -i "s|VARIANT=.*|VARIANT=\"${VARIANT}\"|g" $TEMP_CUSTOMISE3
225
-sed -i "s|MINIMUM_PASSWORD_LENGTH=.*|MINIMUM_PASSWORD_LENGTH=\"${MINIMUM_PASSWORD_LENGTH}\"|g" $TEMP_CUSTOMISE3
226
-sed -i "s|INSECURE=.*|INSECURE=\"${INSECURE}\"|g" $TEMP_CUSTOMISE3
227
-sed -i "s|AMNESIC=.*|AMNESIC=\"${AMNESIC}\"|g" $TEMP_CUSTOMISE3
228
-sed -i "s|SOCIALINSTANCE=.*|SOCIALINSTANCE=\"${SOCIALINSTANCE}\"|g" $TEMP_CUSTOMISE3
229
-sed -i "s|LOCAL_NAME=.*|LOCAL_NAME=\"${LOCAL_NAME}\"|g" $TEMP_CUSTOMISE3
230
-sed -i 's|#!/bin/bash||g' $TEMP_CUSTOMISE3
201
+sed -i "s|ROUTER_IP_ADDRESS=.*|ROUTER_IP_ADDRESS=${ROUTER_IP_ADDRESS}|g" "$TEMP_CUSTOMISE3"
202
+sed -i "s|BOX_IP_ADDRESS=.*|BOX_IP_ADDRESS=${BOX_IP_ADDRESS}|g" "$TEMP_CUSTOMISE3"
203
+sed -i "s|NAMESERVER1=.*|NAMESERVER1=${NAMESERVER1}|g" "$TEMP_CUSTOMISE3"
204
+sed -i "s|NAMESERVER2=.*|NAMESERVER2=${NAMESERVER2}|g" "$TEMP_CUSTOMISE3"
205
+sed -i "s|NAMESERVER3=.*|NAMESERVER3=${NAMESERVER3}|g" "$TEMP_CUSTOMISE3"
206
+sed -i "s|NAMESERVER4=.*|NAMESERVER4=${NAMESERVER4}|g" "$TEMP_CUSTOMISE3"
207
+sed -i "s|NAMESERVER5=.*|NAMESERVER5=${NAMESERVER5}|g" "$TEMP_CUSTOMISE3"
208
+sed -i "s|NAMESERVER6=.*|NAMESERVER6=${NAMESERVER6}|g" "$TEMP_CUSTOMISE3"
209
+sed -i "s|PROJECT_NAME=.*|PROJECT_NAME=${PROJECT_NAME}|g" "$TEMP_CUSTOMISE3"
210
+sed -i "s|CONFIG_FILENAME=.*|CONFIG_FILENAME=${CONFIG_FILENAME}|g" "$TEMP_CUSTOMISE3"
211
+sed -i "s|SSH_PUBKEY=.*|SSH_PUBKEY=${SSH_PUBKEY}|g" "$TEMP_CUSTOMISE3"
212
+sed -i "s|GENERIC_IMAGE=.*|GENERIC_IMAGE=${GENERIC_IMAGE}|g" "$TEMP_CUSTOMISE3"
213
+sed -i "s|MINIMAL_INSTALL=.*|MINIMAL_INSTALL=\"${MINIMAL_INSTALL}\"|g" "$TEMP_CUSTOMISE3"
214
+sed -i "s|SSH_PORT=.*|SSH_PORT=\"${SSH_PORT}\"|g" "$TEMP_CUSTOMISE3"
215
+sed -i "s|ONION_ONLY=.*|ONION_ONLY=\"${ONION_ONLY}\"|g" "$TEMP_CUSTOMISE3"
216
+sed -i "s|PROJECT_REPO=.*|PROJECT_REPO=\"${PROJECT_REPO}\"|g" "$TEMP_CUSTOMISE3"
217
+sed -i "s|DEBIAN_INSTALL_ONLY=.*|DEBIAN_INSTALL_ONLY=\"${DEBIAN_INSTALL_ONLY}\"|g" "$TEMP_CUSTOMISE3"
218
+sed -i "s|WIFI_INTERFACE=.*|WIFI_INTERFACE=\"${WIFI_INTERFACE}\"|g" "$TEMP_CUSTOMISE3"
219
+sed -i "s|WIFI_SSID=.*|WIFI_SSID=\"${WIFI_SSID}\"|g" "$TEMP_CUSTOMISE3"
220
+sed -i "s|WIFI_TYPE=.*|WIFI_TYPE=\"${WIFI_TYPE}\"|g" "$TEMP_CUSTOMISE3"
221
+sed -i "s|WIFI_PASSPHRASE=.*|WIFI_PASSPHRASE=\"${WIFI_PASSPHRASE}\"|g" "$TEMP_CUSTOMISE3"
222
+sed -i "s|WIFI_HOTSPOT=.*|WIFI_HOTSPOT=\"${WIFI_HOTSPOT}\"|g" "$TEMP_CUSTOMISE3"
223
+sed -i "s|WIFI_NETWORKS_FILE=.*|WIFI_NETWORKS_FILE=\"${WIFI_NETWORKS_FILE}\"|g" "$TEMP_CUSTOMISE3"
224
+sed -i "s|VARIANT=.*|VARIANT=\"${VARIANT}\"|g" "$TEMP_CUSTOMISE3"
225
+sed -i "s|MINIMUM_PASSWORD_LENGTH=.*|MINIMUM_PASSWORD_LENGTH=\"${MINIMUM_PASSWORD_LENGTH}\"|g" "$TEMP_CUSTOMISE3"
226
+sed -i "s|INSECURE=.*|INSECURE=\"${INSECURE}\"|g" "$TEMP_CUSTOMISE3"
227
+sed -i "s|AMNESIC=.*|AMNESIC=\"${AMNESIC}\"|g" "$TEMP_CUSTOMISE3"
228
+sed -i "s|SOCIALINSTANCE=.*|SOCIALINSTANCE=\"${SOCIALINSTANCE}\"|g" "$TEMP_CUSTOMISE3"
229
+sed -i "s|LOCAL_NAME=.*|LOCAL_NAME=\"${LOCAL_NAME}\"|g" "$TEMP_CUSTOMISE3"
230
+sed -i 's|#!/bin/bash||g' "$TEMP_CUSTOMISE3"
231 231
 
232 232
 cat $TEMP_CUSTOMISE2 $TEMP_CUSTOMISE3 > $TEMP_CUSTOMISE4
233 233
 if [ -f $TEMP_CUSTOMISE ]; then
@@ -256,19 +256,19 @@ sudo -H \
256 256
      SOURCE="$SOURCE" \
257 257
      CUSTOM_SETUP="$CUSTOM_SETUP" \
258 258
      $VMDEBOOTSTRAP \
259
-     --log $(dirname $IMAGE)/${PROJECT_NAME}.log \
259
+     --log "$(dirname "$IMAGE")/${PROJECT_NAME}.log" \
260 260
      --log-level debug \
261
-     --size $IMAGE_SIZE \
262
-     --image $IMAGE.img \
261
+     --size "$IMAGE_SIZE" \
262
+     --image "$IMAGE.img" \
263 263
      --hostname ${PROJECT_NAME} \
264 264
      --verbose \
265
-     --mirror $BUILD_MIRROR \
265
+     --mirror "$BUILD_MIRROR" \
266 266
      --customize "$TEMP_CUSTOMISE" \
267 267
      --lock-root-password \
268
-     --arch $ARCHITECTURE \
269
-     --distribution $SUITE \
270
-     $extra_opts \
271
-     $pkgopts
268
+     --arch "$ARCHITECTURE" \
269
+     --distribution "$SUITE" \
270
+     "$extra_opts" \
271
+     "$pkgopts"
272 272
 
273 273
 echo $'Removing customised customisation script'
274 274
 sudo shred -zu $TEMP_CUSTOMISE

+ 648
- 645
src/freedombone-image-mesh
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 2
- 2
src/freedombone-image-vmdebootstrap Просмотреть файл

@@ -36,7 +36,7 @@ VMDEBOOTSTRAP_BRANCH='bashrc/freedombone'
36 36
 
37 37
 mkdir -p vendor
38 38
 if [ -d vendor/vmdebootstrap ] ; then
39
-    (cd vendor/vmdebootstrap; git checkout .; git pull)
39
+    (cd vendor/vmdebootstrap || exit 246824624; git checkout .; git pull)
40 40
 else
41 41
     git clone $VMDEBOOTSTRAP_REPO vendor/vmdebootstrap
42 42
 fi
@@ -103,5 +103,5 @@ EOF
103 103
     sudo mv /tmp/ubuntu.csv /usr/share/distro-info/
104 104
 fi
105 105
 
106
-cd vendor/vmdebootstrap
106
+cd vendor/vmdebootstrap || exit 2648726446
107 107
 git checkout $VMDEBOOTSTRAP_BRANCH

+ 38
- 40
src/freedombone-keydrive Просмотреть файл

@@ -87,17 +87,17 @@ do
87 87
     shift
88 88
 done
89 89
 
90
-if [ ! $MY_USERNAME ]; then
90
+if [ ! "$MY_USERNAME" ]; then
91 91
     echo $'No username given'
92 92
     exit 69350
93 93
 fi
94 94
 
95
-if [ ! -d /home/$MY_USERNAME ]; then
95
+if [ ! -d "/home/$MY_USERNAME" ]; then
96 96
     echo $"Home directory for $MY_USERNAME not found. This user may not exist on the system"
97 97
     exit 72378
98 98
 fi
99 99
 
100
-if [ ! -b $USB_DRIVE ]; then
100
+if [ ! -b "$USB_DRIVE" ]; then
101 101
     echo $'Please attach a USB drive'
102 102
     exit 65743
103 103
 fi
@@ -113,18 +113,15 @@ cryptsetup luksClose encrypted_usb
113 113
 
114 114
 # optionally format the drive
115 115
 if [[ $FORMAT == "yes" ]]; then
116
-    ${PROJECT_NAME}-format ${USB_DRIVE::-1}
117
-    if [ ! "$?" = "0" ]; then
116
+    if ! "${PROJECT_NAME}-format" "${USB_DRIVE::-1}"; then
118 117
         exit 36823
119 118
     fi
120 119
 fi
121 120
 
122
-cryptsetup luksOpen $USB_DRIVE encrypted_usb
123
-if [ "$?" = "0" ]; then
121
+if cryptsetup luksOpen "$USB_DRIVE" encrypted_usb; then
124 122
     USB_DRIVE=/dev/mapper/encrypted_usb
125 123
 fi
126
-mount $USB_DRIVE $USB_MOUNT
127
-if [ ! "$?" = "0" ]; then
124
+if ! mount $USB_DRIVE $USB_MOUNT; then
128 125
     echo $"There was a problem mounting the USB drive to $USB_MOUNT"
129 126
     rm -rf $USB_MOUNT
130 127
     exit 78543
@@ -132,7 +129,7 @@ fi
132 129
 
133 130
 # optionally create a master drive which contains the full GPG keyring
134 131
 if [[ $MASTER_DRIVE == "yes" || $MASTER_DRIVE == "y" || $MASTER_DRIVE == "1" ]]; then
135
-    if [ ! -d /home/$MY_USERNAME/.gnupg ]; then
132
+    if [ ! -d "/home/$MY_USERNAME/.gnupg" ]; then
136 133
         echo $"No .gnupg directory was found for $MY_USERNAME"
137 134
         umount -f $USB_MOUNT
138 135
         rm -rf $USB_MOUNT
@@ -149,7 +146,7 @@ if [[ $MASTER_DRIVE == "yes" || $MASTER_DRIVE == "y" || $MASTER_DRIVE == "1" ]];
149 146
     GPG_BACKUP_ID=$(su -m root -c "gpg --list-keys \"(backup key)\" | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
150 147
 
151 148
     gpgerrstr=$'error'
152
-    gpgkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export $GPG_ID)
149
+    gpgkey=$(gpg --homedir="/home/$MY_USERNAME/.gnupg" --armor --export "$GPG_ID")
153 150
     if [[ "$gpgkey" == *"$gpgerrstr"* ]]; then
154 151
         echo $'Problem exporting public gpg key'
155 152
         echo "$gpgkey"
@@ -157,7 +154,7 @@ if [[ $MASTER_DRIVE == "yes" || $MASTER_DRIVE == "y" || $MASTER_DRIVE == "1" ]];
157 154
     fi
158 155
     echo ''
159 156
     echo $'Enter your gpg private key passphrase:'
160
-    gpgprivkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export-secret-key $GPG_ID)
157
+    gpgprivkey=$(gpg --homedir="/home/$MY_USERNAME/.gnupg" --armor --export-secret-key "$GPG_ID")
161 158
     if [[ "$gpgprivkey" == *"$gpgerrstr"* ]]; then
162 159
         echo $'Problem exporting private gpg key'
163 160
         echo "$gpgprivkey"
@@ -168,13 +165,13 @@ if [[ $MASTER_DRIVE == "yes" || $MASTER_DRIVE == "y" || $MASTER_DRIVE == "1" ]];
168 165
     # Dummy password to get around not being able to create a key without passphrase
169 166
     BACKUP_DUMMY_PASSWORD='backup'
170 167
 
171
-    backupgpgkey=$(gpg --homedir=/home/$MY_USERNAME/.gnupg --armor --export $GPG_BACKUP_ID)
168
+    backupgpgkey=$(gpg --homedir="/home/$MY_USERNAME/.gnupg" --armor --export "$GPG_BACKUP_ID")
172 169
     if [[ "$backupgpgkey" == *"$gpgerrstr"* ]]; then
173 170
         echo $'Problem exporting public gpg backup key'
174 171
         echo "$backupgpgkey"
175 172
         exit 735282
176 173
     fi
177
-    backupgpgprivkey=$(echo "$BACKUP_DUMMY_PASSWORD" | gpg --batch --passphrase-fd 0 --homedir=/home/$MY_USERNAME/.gnupg --armor --export-secret-key $GPG_BACKUP_ID)
174
+    backupgpgprivkey=$(echo "$BACKUP_DUMMY_PASSWORD" | gpg --batch --passphrase-fd 0 --homedir="/home/$MY_USERNAME/.gnupg" --armor --export-secret-key "$GPG_BACKUP_ID")
178 175
     if [[ "$backupgpgprivkey" == *"$gpgerrstr"* ]]; then
179 176
         echo $'Problem exporting private gpg backup key'
180 177
         echo "$backupgpgprivkey"
@@ -187,7 +184,7 @@ if [[ $MASTER_DRIVE == "yes" || $MASTER_DRIVE == "y" || $MASTER_DRIVE == "1" ]];
187 184
     echo "$backupgpgkey" > $USB_MOUNT/.backupgpgkey
188 185
     echo "$backupgpgprivkey" >> $USB_MOUNT/.backupgpgkey
189 186
 
190
-    cp -rf /home/$MY_USERNAME/.gnupg $USB_MOUNT
187
+    cp -rf "/home/$MY_USERNAME/.gnupg" $USB_MOUNT
191 188
 
192 189
     if [ -d /etc/letsencrypt ]; then
193 190
         cp -rf /etc/letsencrypt $USB_MOUNT
@@ -220,25 +217,25 @@ fi
220 217
 FRAGMENTS_DIR=$FRAGMENTS_DIR/$MY_USERNAME
221 218
 
222 219
 # make a directory to contain the fragments
223
-if [ ! -d $FRAGMENTS_DIR ]; then
224
-    mkdir -p $FRAGMENTS_DIR
220
+if [ ! -d "$FRAGMENTS_DIR" ]; then
221
+    mkdir -p "$FRAGMENTS_DIR"
225 222
     echo $"Made directory $FRAGMENTS_DIR"
226 223
 fi
227
-if [ ! -d $FRAGMENTS_DIR ]; then
224
+if [ ! -d "$FRAGMENTS_DIR" ]; then
228 225
     echo $"There was a problem making the directory $FRAGMENTS_DIR"
229 226
     umount -f $USB_MOUNT
230 227
     rm -rf $USB_MOUNT
231 228
     exit 6843
232 229
 fi
233 230
 
234
-cd $FRAGMENTS_DIR
235
-no_of_usb_shares=$(ls -afq keyshare.asc.* | wc -l)
236
-if [ ! "$?" = "0" ]; then
231
+cd "$FRAGMENTS_DIR" || exit 13389478368
232
+# shellcheck disable=SC2012
233
+if ! no_of_usb_shares=$(ls -afq keyshare.asc.* | wc -l); then
237 234
     no_of_usb_shares=0
238 235
 fi
239 236
 if (( no_of_usb_shares > 0 )); then
240 237
     echo $"A key fragment already exists on the drive for the user $MY_USERNAME"
241
-    cd ~/
238
+    cd ~/ || exit 34678264583
242 239
     umount -f $USB_MOUNT
243 240
     rm -rf $USB_MOUNT
244 241
     exit 58945
@@ -247,43 +244,44 @@ fi
247 244
 # copy a random fragment to the drive
248 245
 LOCAL_FRAGMENTS_DIR=/home/$MY_USERNAME/.gnupg_fragments
249 246
 
250
-if [ ! -d $LOCAL_FRAGMENTS_DIR ]; then
251
-    ${PROJECT_NAME}-splitkey -u $MY_USERNAME -n $KEY_FRAGMENTS
247
+if [ ! -d "$LOCAL_FRAGMENTS_DIR" ]; then
248
+    "${PROJECT_NAME}-splitkey" -u "$MY_USERNAME" -n "$KEY_FRAGMENTS"
252 249
 fi
253 250
 
254
-cd $LOCAL_FRAGMENTS_DIR
255
-no_of_local_shares=$(ls -afq keyshare.asc.* | wc -l)
256
-if [ ! "$?" = "0" ]; then
251
+cd "$LOCAL_FRAGMENTS_DIR" || exit 7822452644
252
+# shellcheck disable=SC2012
253
+if ! no_of_local_shares=$(ls -afq keyshare.asc.* | wc -l); then
257 254
     no_of_local_shares=0
258 255
 fi
259 256
 if (( no_of_local_shares < 3 )); then
260
-    ${PROJECT_NAME}-splitkey -u $MY_USERNAME -n $KEY_FRAGMENTS
261
-    cd $LOCAL_FRAGMENTS_DIR
262
-    no_of_local_shares=$(ls -afq keyshare.asc.* | wc -l)
263
-    if [ ! "$?" = "0" ]; then
257
+    "${PROJECT_NAME}-splitkey" -u "$MY_USERNAME" -n "$KEY_FRAGMENTS"
258
+    cd "$LOCAL_FRAGMENTS_DIR" || exit 724524242
259
+    # shellcheck disable=SC2012
260
+    if ! no_of_local_shares=$(ls -afq keyshare.asc.* | wc -l); then
264 261
         no_of_local_shares=0
265 262
     fi
266 263
 fi
267 264
 
268 265
 if (( no_of_local_shares < 3 )); then
269 266
     echo $"Not enough key fragments available ${no_of_local_shares}"
270
-    cd ~/
267
+    cd ~/ || exit 7245267457
271 268
     umount -f $USB_MOUNT
272 269
     rm -rf $USB_MOUNT
273 270
     exit 63386
274 271
 fi
275 272
 
276
-share_files=($LOCAL_FRAGMENTS_DIR/keyshare.asc.*)
273
+share_files=("$LOCAL_FRAGMENTS_DIR/keyshare.asc.*")
277 274
 SHARE_FILENAME=${share_files[RANDOM % ${#share_files[@]}]}
278 275
 
279
-cp -f $SHARE_FILENAME $FRAGMENTS_DIR
280
-cd $FRAGMENTS_DIR
276
+cp -f "$SHARE_FILENAME" "$FRAGMENTS_DIR"
277
+cd "$FRAGMENTS_DIR" || exit 2543244726
278
+# shellcheck disable=SC2012
281 279
 no_of_usb_shares=$(ls -afq keyshare.asc.* | wc -l)
282 280
 echo $"Number of fragments on the drive: ${no_of_usb_shares}"
283 281
 if (( no_of_usb_shares > 1 )); then
284 282
     echo $"Too many key fragments exist in $FRAGMENTS_DIR"
285
-    ls $FRAGMENTS_DIR
286
-    cd ~/
283
+    ls "$FRAGMENTS_DIR"
284
+    cd ~/ || 357836582645
287 285
     umount -f $USB_MOUNT
288 286
     rm -rf $USB_MOUNT
289 287
     exit 54292
@@ -291,14 +289,14 @@ fi
291 289
 if (( no_of_usb_shares <= 0 )); then
292 290
     echo $"There was a problem copying the key fragment to $USB_DRIVE"
293 291
     echo $"Files found: ${no_of_usb_shares}"
294
-    ls $FRAGMENTS_DIR
295
-    cd ~/
292
+    ls "$FRAGMENTS_DIR"
293
+    cd ~/ || exit 743452452
296 294
     umount -f $USB_MOUNT
297 295
     rm -rf $USB_MOUNT
298 296
     exit 54292
299 297
 fi
300 298
 
301
-cd ~/
299
+cd ~/ || exit 245672457
302 300
 umount -f $USB_MOUNT
303 301
 rm -rf $USB_MOUNT
304 302
 echo $"Key fragment copied to $USB_DRIVE. You may now remove the drive."

+ 16
- 16
src/freedombone-logging Просмотреть файл

@@ -42,28 +42,28 @@ REMOVE_FILES_COMMAND='rm -rf'
42 42
 
43 43
 source /usr/local/bin/${PROJECT_NAME}-vars
44 44
 
45
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
45
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
46 46
 for f in $UTILS_FILES
47 47
 do
48
-    source $f
48
+    source "$f"
49 49
 done
50 50
 
51
-APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
51
+APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
52 52
 for f in $APP_FILES
53 53
 do
54
-    source $f
54
+    source "$f"
55 55
 done
56 56
 
57 57
 APPS_AVAILABLE=()
58 58
 
59 59
 function logging_get_app_names {
60
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
60
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
61 61
 
62 62
     for filename in $FILES
63 63
     do
64 64
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
65
-        if grep -q "logging_on_" ${filename}; then
66
-            if grep -q "logging_off_" ${filename}; then
65
+        if grep -q "logging_on_" "${filename}"; then
66
+            if grep -q "logging_off_" "${filename}"; then
67 67
                 APPS_AVAILABLE+=("${app_name}")
68 68
             fi
69 69
         fi
@@ -76,7 +76,7 @@ function turn_logging_on {
76 76
     for a in "${APPS_AVAILABLE[@]}"
77 77
     do
78 78
         echo $"Turning on logging for ${a}"
79
-        logging_on_${a}
79
+        "logging_on_${a}"
80 80
     done
81 81
 }
82 82
 
@@ -86,7 +86,7 @@ function turn_logging_off {
86 86
     for a in "${APPS_AVAILABLE[@]}"
87 87
     do
88 88
         echo $"Turning off logging for ${a}"
89
-        logging_off_${a}
89
+        "logging_off_${a}"
90 90
     done
91 91
 }
92 92
 
@@ -162,14 +162,14 @@ if [[ "$1" == "on" || "$1" == "On" || "$1" == "ON" ]]; then
162 162
         fi
163 163
         for filename in /etc/nginx/sites-available/* ; do
164 164
             filename_domain=$(echo "$filename" | awk -F '/' '{print $5}')
165
-            sed -i "s|access_log.*|access_log /var/log/nginx/$filename_domain.access.log;|g" $filename
166
-            sed -i "s|error_log.*|error_log /var/log/nginx/$filename_domain.err.log $WEBSERVER_LOG_LEVEL;|g" $filename
165
+            sed -i "s|access_log.*|access_log /var/log/nginx/$filename_domain.access.log;|g" "$filename"
166
+            sed -i "s|error_log.*|error_log /var/log/nginx/$filename_domain.err.log $WEBSERVER_LOG_LEVEL;|g" "$filename"
167 167
         done
168 168
         sed -i 's|access_log.*|access_log /var/log/nginx/access.log;|g' /etc/nginx/nginx.conf
169 169
         sed -i 's|error_log.*|error_log /var/log/nginx/error.log;|g' /etc/nginx/nginx.conf
170 170
     fi
171 171
     if [ -f /etc/init.d/spamassassin ]; then
172
-        sed -i 's|DOPTIONS="-s null -d --pidfile=$PIDFILE"|DOPTIONS="-d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
172
+        sed -i "s|DOPTIONS=\"-s null -d --pidfile=\$PIDFILE\"|DOPTIONS=\"-d --pidfile=\$PIDFILE\"|g" /etc/init.d/spamassassin
173 173
     fi
174 174
     if [ -d /etc/exim4 ]; then
175 175
         if [ ! -d /var/log/exim4 ]; then
@@ -211,16 +211,16 @@ else
211 211
     fi
212 212
     if [ -d /etc/nginx ]; then
213 213
         for filename in /etc/nginx/sites-available/* ; do
214
-            sed -i 's|access_log.*|access_log /dev/null;|g' $filename
215
-            sed -i 's|warn_log.*|warn_log /dev/null;|g' $filename
216
-            sed -i 's|error_log.*|error_log /dev/null;|g' $filename
214
+            sed -i 's|access_log.*|access_log /dev/null;|g' "$filename"
215
+            sed -i 's|warn_log.*|warn_log /dev/null;|g' "$filename"
216
+            sed -i 's|error_log.*|error_log /dev/null;|g' "$filename"
217 217
         done
218 218
         sed -i 's|access_log.*|access_log /dev/null;|g' /etc/nginx/nginx.conf
219 219
         sed -i 's|error_log.*|error_log /dev/null;|g' /etc/nginx/nginx.conf
220 220
         $REMOVE_FILES_COMMAND /var/log/nginx/*
221 221
     fi
222 222
     if [ -f /etc/init.d/spamassassin ]; then
223
-        sed -i 's|DOPTIONS="-d --pidfile=$PIDFILE"|DOPTIONS="-s null -d --pidfile=$PIDFILE"|g' /etc/init.d/spamassassin
223
+        sed -i "s|DOPTIONS=\"-d --pidfile=\$PIDFILE\"|DOPTIONS=\"-s null -d --pidfile=\$PIDFILE\"|g" /etc/init.d/spamassassin
224 224
     fi
225 225
     if [ -d /etc/exim4 ]; then
226 226
         sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs

+ 74
- 73
src/freedombone-mesh-batman Просмотреть файл

@@ -29,7 +29,7 @@
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31 31
 PROJECT_NAME='freedombone'
32
-COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
32
+COMPLETION_FILE="/root/${PROJECT_NAME}-completed.txt"
33 33
 
34 34
 # hotspot passphrase must be 5 characters or longer
35 35
 HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
@@ -40,28 +40,29 @@ source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
40 40
 mesh_protocol_init
41 41
 update_wifi_adaptors
42 42
 
43
-if [ ! $IFACE ]; then
43
+if [ ! "$IFACE" ]; then
44 44
     echo $'No wlan adaptor'
45 45
     exit 0
46 46
 fi
47 47
 
48 48
 if [ -e /etc/default/batctl ]; then
49
+    # shellcheck disable=SC1091
49 50
     . /etc/default/batctl
50 51
 fi
51 52
 
52 53
 function status {
53 54
     batctl o
54 55
 
55
-    if grep -q "bmx6" $MESH_CURRENT_PROTOCOL; then
56
+    if grep -q "bmx6" "$MESH_CURRENT_PROTOCOL"; then
56 57
         bmx6 -c show=originators
57 58
     fi
58
-    if grep -q "bmx7" $MESH_CURRENT_PROTOCOL; then
59
+    if grep -q "bmx7" "$MESH_CURRENT_PROTOCOL"; then
59 60
         bmx7 -c show=originators
60 61
     fi
61 62
 }
62 63
 
63 64
 function stop {
64
-    if [ ! -f $MESH_CURRENT_PROTOCOL ]; then
65
+    if [ ! -f "$MESH_CURRENT_PROTOCOL" ]; then
65 66
         return
66 67
     fi
67 68
 
@@ -82,31 +83,31 @@ function stop {
82 83
     systemctl disable dnsmasq
83 84
 
84 85
     if [ "$EIFACE" ]; then
85
-        brctl delif $BRIDGE bat0
86
-        ifconfig $BRIDGE down || true
87
-        ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
86
+        brctl delif "$BRIDGE" bat0
87
+        ifconfig "$BRIDGE" down || true
88
+        ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
88 89
         if [[ "$ethernet_connected" != "0" ]]; then
89 90
             systemctl stop hostapd
90
-            brctl delif $BRIDGE $EIFACE
91
-            ifconfig $EIFACE down -promisc
91
+            brctl delif "$BRIDGE" "$EIFACE"
92
+            ifconfig "$EIFACE" down -promisc
92 93
         fi
93
-        brctl delbr $BRIDGE
94
+        brctl delbr "$BRIDGE"
94 95
     fi
95 96
 
96 97
     ifconfig bat0 down -promisc
97 98
 
98
-    batctl if del $IFACE
99
-    ifconfig $IFACE mtu 1500
100
-    ifconfig $IFACE down
101
-    iwconfig $IFACE mode managed
99
+    batctl if del "$IFACE"
100
+    ifconfig "$IFACE" mtu 1500
101
+    ifconfig "$IFACE" down
102
+    iwconfig "$IFACE" mode managed
102 103
 
103
-    if [ $IFACE_SECONDARY ]; then
104
+    if [ "$IFACE_SECONDARY" ]; then
104 105
         systemctl stop hostapd
105 106
         systemctl disable hostapd
106
-        batctl if del $IFACE_SECONDARY
107
-        ifconfig $IFACE_SECONDARY mtu 1500
108
-        ifconfig $IFACE_SECONDARY down
109
-        iwconfig $IFACE_SECONDARY mode managed
107
+        batctl if del "$IFACE_SECONDARY"
108
+        ifconfig "$IFACE_SECONDARY" mtu 1500
109
+        ifconfig "$IFACE_SECONDARY" down
110
+        iwconfig "$IFACE_SECONDARY" mode managed
110 111
     fi
111 112
 
112 113
     rmmod batman-adv
@@ -115,53 +116,53 @@ function stop {
115 116
 
116 117
     systemctl restart network-manager
117 118
 
118
-    if [ -f $MESH_CURRENT_PROTOCOL ]; then
119
-        rm $MESH_CURRENT_PROTOCOL
119
+    if [ -f "$MESH_CURRENT_PROTOCOL" ]; then
120
+        rm "$MESH_CURRENT_PROTOCOL"
120 121
     fi
121 122
 }
122 123
 
123 124
 function verify {
124 125
     tempfile="$(mktemp)"
125
-    batctl o > $tempfile
126
-    if grep -q "disabled" $tempfile; then
126
+    batctl o > "$tempfile"
127
+    if grep -q "disabled" "$tempfile"; then
127 128
         echo $'B.A.T.M.A.N. not enabled'
128
-        rm $tempfile
129
+        rm "$tempfile"
129 130
         stop
130 131
         exit 726835
131 132
     fi
132 133
     echo $'B.A.T.M.A.N. is running'
133
-    rm $tempfile
134
+    rm "$tempfile"
134 135
 }
135 136
 
136 137
 function add_wifi_interface {
137 138
     ifname=$1
138 139
     ifssid=$WIFI_SSID
139
-    if [ $2 ]; then
140
+    if [ "$2" ]; then
140 141
         ifssid=$2
141 142
     fi
142 143
     ifmode=ad-hoc
143
-    if [ $3 ]; then
144
+    if [ "$3" ]; then
144 145
         ifmode=$3
145 146
     fi
146 147
     ifchannel=$CHANNEL
147
-    if [ $4 ]; then
148
+    if [ "$4" ]; then
148 149
         ifchannel=$4
149 150
     fi
150 151
 
151
-    ifconfig $ifname down
152
-    ifconfig $ifname mtu 1532
152
+    ifconfig "$ifname" down
153
+    ifconfig "$ifname" mtu 1532
153 154
     peermac=$(assign_peer_address)
154
-    if [ ! $peermac ]; then
155
+    if [ ! "$peermac" ]; then
155 156
         echo $"Unable to obtain MAC address for $peermac on $ifname"
156 157
         return
157 158
     fi
158
-    ifconfig $ifname hw ether $peermac
159
+    ifconfig "$ifname" hw ether "$peermac"
159 160
     echo $"$ifname assigned MAC address $peermac"
160
-    iwconfig $ifname enc off
161
-    iwconfig $ifname mode $ifmode essid $ifssid channel $ifchannel
161
+    iwconfig "$ifname" enc off
162
+    iwconfig "$ifname" mode "$ifmode" essid "$ifssid" channel "$ifchannel"
162 163
 
163
-    batctl if add $ifname
164
-    ifconfig $ifname up
164
+    batctl if add "$ifname"
165
+    ifconfig "$ifname" up
165 166
 }
166 167
 
167 168
 function start {
@@ -188,11 +189,11 @@ function start {
188 189
     global_rate_limit
189 190
 
190 191
     # Might have to re-enable wifi
191
-    rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
192
+    rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true
192 193
 
193 194
     secondary_wifi_available=
194
-    if [ $IFACE_SECONDARY ]; then
195
-        if [[ $IFACE != $IFACE_SECONDARY ]]; then
195
+    if [ "$IFACE_SECONDARY" ]; then
196
+        if [[ "$IFACE" != "$IFACE_SECONDARY" ]]; then
196 197
             if [ -d /etc/hostapd ]; then
197 198
                 if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
198 199
                     secondary_wifi_available=1
@@ -215,23 +216,23 @@ function start {
215 216
     sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE}|g" /etc/systemd/system/babel.service
216 217
     systemctl daemon-reload
217 218
 
218
-    add_wifi_interface $IFACE $WIFI_SSID ad-hoc $CHANNEL
219
+    add_wifi_interface "$IFACE" "$WIFI_SSID" ad-hoc "$CHANNEL"
219 220
 
220 221
     # NOTE: Don't connect the secondary wifi device. hostapd will handle that by itself
221 222
 
222 223
     ifconfig bat0 up promisc
223 224
 
224
-    brctl addbr $BRIDGE
225
-    brctl addif $BRIDGE bat0
225
+    brctl addbr "$BRIDGE"
226
+    brctl addif "$BRIDGE" bat0
226 227
     ifconfig bat0 0.0.0.0
227 228
     ethernet_connected='0'
228 229
     if [ "$EIFACE" ] ; then
229
-        ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
230
+        ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
230 231
         if [[ "$ethernet_connected" != "0" ]]; then
231 232
             echo $'Trying ethernet bridge to the internet'
232
-            brctl addif $BRIDGE $EIFACE
233
-            ifconfig $EIFACE 0.0.0.0
234
-            ifconfig $EIFACE up promisc
233
+            brctl addif "$BRIDGE" "$EIFACE"
234
+            ifconfig "$EIFACE" 0.0.0.0
235
+            ifconfig "$EIFACE" up promisc
235 236
             echo $'End of ethernet bridge'
236 237
 
237 238
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
@@ -243,8 +244,8 @@ function start {
243 244
             echo $"$EIFACE is not connected"
244 245
         fi
245 246
     fi
246
-    ifconfig $BRIDGE up
247
-    dhclient $BRIDGE
247
+    ifconfig "$BRIDGE" up
248
+    dhclient "$BRIDGE"
248 249
 
249 250
     enable_mesh_seconary_wifi
250 251
 
@@ -257,34 +258,34 @@ function start {
257 258
 
258 259
     systemctl restart nginx
259 260
 
260
-    if [ ! -f $MESH_DEFAULT_PROTOCOL ]; then
261
-        echo 'bmx6' > $MESH_DEFAULT_PROTOCOL
261
+    if [ ! -f "$MESH_DEFAULT_PROTOCOL" ]; then
262
+        echo 'bmx6' > "$MESH_DEFAULT_PROTOCOL"
262 263
     fi
263 264
 
264
-    if grep -q "bmx6" $MESH_DEFAULT_PROTOCOL; then
265
+    if grep -q "bmx6" "$MESH_DEFAULT_PROTOCOL"; then
265 266
         systemctl enable bmx6
266 267
         systemctl restart bmx6
267 268
         sed -i 's|<type>.*|<type>_bmx6._tcp</type>|g' /etc/avahi/services/routing.service
268 269
     fi
269 270
 
270
-    if grep -q "bmx7" $MESH_DEFAULT_PROTOCOL; then
271
+    if grep -q "bmx7" "$MESH_DEFAULT_PROTOCOL"; then
271 272
         systemctl enable bmx7
272 273
         systemctl restart bmx7
273 274
         sed -i 's|<type>.*|<type>_bmx7._tcp</type>|g' /etc/avahi/services/routing.service
274 275
     fi
275 276
 
276
-    if grep -q "olsr" $MESH_DEFAULT_PROTOCOL; then
277
-        IFACE=$(cat /etc/systemd/system/olsr2.service | grep ExecStart | awk -F ' ' '{print $2}')
278
-        mesh_generate_ipv6_address $IFACE
277
+    if grep -q "olsr" "$MESH_DEFAULT_PROTOCOL"; then
278
+        IFACE=$(grep ExecStart "/etc/systemd/system/olsr2.service" | awk -F ' ' '{print $2}')
279
+        mesh_generate_ipv6_address "$IFACE"
279 280
 
280 281
         systemctl enable olsr2
281 282
         systemctl restart olsr2
282 283
         sed -i 's|<type>.*|<type>_olsr2._tcp</type>|g' /etc/avahi/services/routing.service
283 284
     fi
284 285
 
285
-    if grep -q "babel" $MESH_DEFAULT_PROTOCOL; then
286
-        IFACE=$(cat /etc/systemd/system/babel.service | grep ExecStart | awk -F ' ' '{print $2}')
287
-        mesh_generate_ipv6_address $IFACE
286
+    if grep -q "babel" "$MESH_DEFAULT_PROTOCOL"; then
287
+        IFACE=$(grep ExecStart /etc/systemd/system/babel.service | awk -F ' ' '{print $2}')
288
+        mesh_generate_ipv6_address "$IFACE"
288 289
 
289 290
         systemctl enable babel
290 291
         systemctl restart babel
@@ -295,7 +296,7 @@ function start {
295 296
 
296 297
     verify
297 298
 
298
-    echo "$(cat $MESH_DEFAULT_PROTOCOL)" > $MESH_CURRENT_PROTOCOL
299
+    cat "$MESH_DEFAULT_PROTOCOL" > "$MESH_CURRENT_PROTOCOL"
299 300
 }
300 301
 
301 302
 function monitor {
@@ -329,21 +330,21 @@ function monitor {
329 330
     echo ''
330 331
 
331 332
     # Might have to re-enable wifi
332
-    rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
333
+    rfkill unblock "$(rfkill list|awk -F: "/phy/ {print $1}")" || true
333 334
 
334
-    ifconfig $IFACE down
335
-    ifconfig $IFACE mtu 1532
336
-    ifconfig $IFACE hw ether $(assign_peer_address)
337
-    iwconfig $IFACE enc off
338
-    iwconfig $IFACE mode monitor channel $CHANNEL
335
+    ifconfig "$IFACE" down
336
+    ifconfig "$IFACE" mtu 1532
337
+    ifconfig "$IFACE" hw ether "$(assign_peer_address)"
338
+    iwconfig "$IFACE" enc off
339
+    iwconfig "$IFACE" mode monitor channel "$CHANNEL"
339 340
     sleep 1
340
-    iwconfig $IFACE ap $CELLID
341
+    iwconfig "$IFACE" ap "$CELLID"
341 342
 
342 343
     modprobe batman-adv
343
-    batctl if add $IFACE
344
-    ifconfig $IFACE up
344
+    batctl if add "$IFACE"
345
+    ifconfig "$IFACE" up
345 346
 
346
-    horst -i $IFACE
347
+    horst -i "$IFACE"
347 348
 
348 349
     clear
349 350
     echo ''
@@ -354,7 +355,7 @@ function monitor {
354 355
 }
355 356
 
356 357
 if ! grep -q "$IFACE" /proc/net/dev; then
357
-    echo 'Interface $IFACE was not found'
358
+    echo "Interface \$IFACE was not found"
358 359
     stop
359 360
     exit 1
360 361
 fi
@@ -377,7 +378,7 @@ case "$1" in
377 378
         start
378 379
         ;;
379 380
     ping)
380
-        batctl ping $2
381
+        batctl ping "$2"
381 382
         ;;
382 383
     data)
383 384
         watch -n1 "batctl s | grep mgmt | grep bytes"
@@ -387,7 +388,7 @@ case "$1" in
387 388
         ;;
388 389
     *)
389 390
         echo "error: invalid parameter $1"
390
-        echo 'usage: $0 {start|stop|restart|status|ping|ls|list}'
391
+        echo "usage: \$0 {start|stop|restart|status|ping|ls|list}"
391 392
         exit 2
392 393
         ;;
393 394
 esac

+ 48
- 47
src/freedombone-mesh-blog Просмотреть файл

@@ -42,17 +42,17 @@ BLOG_EDITOR='pluma'
42 42
 DEFAULT_BLOG_TITLE=$"Freedombone Blog"
43 43
 
44 44
 function remove_bad_blog_links {
45
-    find ./ -type f -name *.css -exec sed -i -e '/googleapi/d' {} \;
46
-    find ./ -type f -name *.scss -exec sed -i -e '/googleapi/d' {} \;
47
-    find ./ -type f -name *.html -exec sed -i -e '/googleapi/d' {} \;
48
-    find ./ -type f -name *.css -exec sed -i -e '/bootstrapcdn/d' {} \;
49
-    find ./ -type f -name *.scss -exec sed -i -e '/bootstrapcdn/d' {} \;
50
-    find ./ -type f -name *.html -exec sed -i -e '/bootstrapcdn/d' {} \;
45
+    find ./ -type f -name "*.css" -exec sed -i -e '/googleapi/d' {} \;
46
+    find ./ -type f -name "*.scss" -exec sed -i -e '/googleapi/d' {} \;
47
+    find ./ -type f -name "*.html" -exec sed -i -e '/googleapi/d' {} \;
48
+    find ./ -type f -name "*.css" -exec sed -i -e '/bootstrapcdn/d' {} \;
49
+    find ./ -type f -name "*.scss" -exec sed -i -e '/bootstrapcdn/d' {} \;
50
+    find ./ -type f -name "*.html" -exec sed -i -e '/bootstrapcdn/d' {} \;
51 51
 }
52 52
 
53 53
 function ipfs_publish {
54 54
     DIR_TO_CHECK=/home/$USER/Public
55
-    if [ ! -d $DIR_TO_CHECK ]; then
55
+    if [ ! -d "$DIR_TO_CHECK" ]; then
56 56
         return
57 57
     fi
58 58
 
@@ -60,13 +60,13 @@ function ipfs_publish {
60 60
     echo $'Publishing to IPFS. This may take some time...'
61 61
 
62 62
     OLD_STAT_FILE=/home/$USER/.old_stat.txt
63
-    NEW_STAT=$(stat -t $DIR_TO_CHECK)
64
-    echo $($IPFS_COMMAND add -rq /home/$USER/Public | tail -n 1) > $IPFS_PUBLIC
65
-    echo "$NEW_STAT" > $OLD_STAT_FILE
63
+    NEW_STAT=$(stat -t "$DIR_TO_CHECK")
64
+    $IPFS_COMMAND add -rq "/home/$USER/Public" | tail -n 1 > "$IPFS_PUBLIC"
65
+    echo "$NEW_STAT" > "$OLD_STAT_FILE"
66 66
 
67
-    if [ -f $IPFS_PUBLIC ]; then
68
-        IPFS_PUBLIC_ID=$(cat $IPFS_PUBLIC)
69
-        $IPFS_COMMAND name publish /ipfs/$IPFS_PUBLIC_ID
67
+    if [ -f "$IPFS_PUBLIC" ]; then
68
+        IPFS_PUBLIC_ID=$(cat "$IPFS_PUBLIC")
69
+        $IPFS_COMMAND name publish "/ipfs/$IPFS_PUBLIC_ID"
70 70
     fi
71 71
 }
72 72
 
@@ -75,7 +75,7 @@ function regenerate_blog {
75 75
     echo ''
76 76
     echo $'Regenerating blog...'
77 77
 
78
-    cd $BLOG_PATH
78
+    cd $BLOG_PATH || exit 246872648
79 79
     if grep -q "SITENAME=u'${DEFAULT_BLOG_TITLE}'" $BLOG_PATH/pelicanconf.py; then
80 80
         TOX_NICK=$(toxid --showuser)
81 81
         BLOG_TITLE=$"${TOX_NICK}'s Blog"
@@ -83,7 +83,7 @@ function regenerate_blog {
83 83
     fi
84 84
     make html
85 85
 
86
-    cd $BLOG_PATH
86
+    cd $BLOG_PATH || exit 23682468
87 87
     remove_bad_blog_links
88 88
 
89 89
     ipfs_publish
@@ -97,19 +97,19 @@ function view_blog {
97 97
 function new_blog {
98 98
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
99 99
 
100
-    echo $'Title: Blog Post Title' > ~/.new-blog-entry
101
-    echo $"Date: ${DATESTR}" >> ~/.new-blog-entry
102
-    echo $"Author: $(toxid --showuser)" >> ~/.new-blog-entry
103
-    echo $'Category: default' >> ~/.new-blog-entry
104
-    echo $'Tags: blog, tag' >> ~/.new-blog-entry
105
-    echo  '' >> ~/.new-blog-entry
106
-    echo $'Add your text here' >> ~/.new-blog-entry
107
-    echo  '' >> ~/.new-blog-entry
108
-    echo -n $'To include an image copy it into the ~/CreateBlog/content/images directory, ' >> ~/.new-blog-entry
109
-    echo $'then link to it with:' >> ~/.new-blog-entry
110
-    echo  '' >> ~/.new-blog-entry
111
-    echo $'![My image]({filename}images/myimage.jpg)' >> ~/.new-blog-entry
112
-    echo  '' >> ~/.new-blog-entry
100
+    { echo $'Title: Blog Post Title';
101
+      echo $"Date: ${DATESTR}";
102
+      echo $"Author: $(toxid --showuser)";
103
+      echo $'Category: default';
104
+      echo $'Tags: blog, tag';
105
+      echo  '';
106
+      echo $'Add your text here';
107
+      echo  '';
108
+      echo -n $'To include an image copy it into the ~/CreateBlog/content/images directory, ';
109
+      echo $'then link to it with:';
110
+      echo  '';
111
+      echo $'![My image]({filename}images/myimage.jpg)';
112
+      echo  ''; } > ~/.new-blog-entry
113 113
 
114 114
     $BLOG_EDITOR ~/.new-blog-entry
115 115
 
@@ -119,26 +119,26 @@ function new_blog {
119 119
     if grep -q $"Blog Post Title" ~/.new-blog-entry; then
120 120
         return
121 121
     fi
122
-    if [ ! -f $CURRENT_BLOG_INDEX ]; then
123
-        echo '0' > $CURRENT_BLOG_INDEX
122
+    if [ ! -f "$CURRENT_BLOG_INDEX" ]; then
123
+        echo '0' > "$CURRENT_BLOG_INDEX"
124 124
     fi
125 125
 
126 126
     # move to the content directory
127
-    CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
128
-    mv ~/.new-blog-entry $BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md
127
+    CURRENT_INDEX=$(cat "$CURRENT_BLOG_INDEX")
128
+    mv ~/.new-blog-entry "$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md"
129 129
 
130 130
     # increment the index
131 131
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
132
-    echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX
132
+    echo "$CURRENT_INDEX" > "$CURRENT_BLOG_INDEX"
133 133
 
134 134
     regenerate_blog
135 135
 }
136 136
 
137 137
 function edit_blog {
138
-    if [ ! -f $CURRENT_BLOG_INDEX ]; then
138
+    if [ ! -f "$CURRENT_BLOG_INDEX" ]; then
139 139
         return
140 140
     fi
141
-    CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
141
+    CURRENT_INDEX=$(cat "$CURRENT_BLOG_INDEX")
142 142
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
143 143
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
144 144
     if [ ! -f $LAST_BLOG_ENTRY ]; then
@@ -149,23 +149,23 @@ function edit_blog {
149 149
 }
150 150
 
151 151
 function delete_blog {
152
-    if [ ! -f $CURRENT_BLOG_INDEX ]; then
152
+    if [ ! -f "$CURRENT_BLOG_INDEX" ]; then
153 153
         return
154 154
     fi
155
-    CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
155
+    CURRENT_INDEX=$(cat "$CURRENT_BLOG_INDEX")
156 156
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
157 157
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
158 158
     if [ ! -f $LAST_BLOG_ENTRY ]; then
159 159
         return
160 160
     fi
161 161
 
162
-    if ! zenity --question --title=$'Delete the previous blog entry' --text=$"\nAre you sure that you wish to delete the previous blog entry?" --ok-label=No --cancel-label=Yes --width=300; then
162
+    if ! zenity --question --title=$'Delete the previous blog entry' --text=$"\\nAre you sure that you wish to delete the previous blog entry?" --ok-label=No --cancel-label=Yes --width=300; then
163 163
         rm $LAST_BLOG_ENTRY
164
-        if [ $CURRENT_INDEX -gt 0 ]; then
164
+        if [ "$CURRENT_INDEX" -gt 0 ]; then
165 165
             CURRENT_INDEX=$PREVIOUS_INDEX
166
-            echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX
166
+            echo "$CURRENT_INDEX" > "$CURRENT_BLOG_INDEX"
167 167
         else
168
-            rm -f $CURRENT_BLOG_INDEX
168
+            rm -f "$CURRENT_BLOG_INDEX"
169 169
         fi
170 170
         regenerate_blog
171 171
     fi
@@ -180,8 +180,8 @@ function change_theme {
180 180
 
181 181
     n=1
182 182
     curr_theme_index=
183
-    if [ -f /home/$USER/.blog-theme-index ]; then
184
-        curr_theme_index=$(cat /home/$USER/.blog-theme-index)
183
+    if [ -f "/home/$USER/.blog-theme-index" ]; then
184
+        curr_theme_index=$(cat "/home/$USER/.blog-theme-index")
185 185
     fi
186 186
     if [ -f /tmp/.blog-themes ]; then
187 187
         rm /tmp/.blog-themes
@@ -189,10 +189,11 @@ function change_theme {
189 189
     for a in "${THEMES[@]}"
190 190
     do
191 191
         echo "$n $a" >> /tmp/.blog-themes
192
-        n=$[n+1]
192
+        n=$((n+1))
193 193
     done
194 194
 
195 195
     CHOSEN_THEME_INDEX=$(
196
+    # shellcheck disable=SC2002
196 197
     cat /tmp/.blog-themes | \
197 198
         awk -F ' ' '{
198 199
         for(i=1;i<=NF;i++){
@@ -204,15 +205,15 @@ function change_theme {
204 205
            --column=$'Index' --column=$'Theme' \
205 206
            --print-column=1 --hide-column=1 --width=300 --height=400)
206 207
     rm /tmp/.blog-themes
207
-    if [ ! $CHOSEN_THEME_INDEX ]; then
208
+    if [ ! "$CHOSEN_THEME_INDEX" ]; then
208 209
         exit 1
209 210
     fi
210 211
 
211
-    echo "$CHOSEN_THEME_INDEX" > /home/$USER/.blog-theme-index
212
+    echo "$CHOSEN_THEME_INDEX" > "/home/$USER/.blog-theme-index"
212 213
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
213 214
 
214 215
     CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
215
-    cd cd $BLOG_PATH/themes/$CHOSEN_THEME
216
+    cd "$BLOG_PATH/themes/$CHOSEN_THEME" || exit 346746824
216 217
     remove_bad_blog_links
217 218
     if grep -q "THEME=" $BLOG_PATH/pelicanconf.py; then
218 219
         sed -i "s|THEME=.*|THEME='themes/${CHOSEN_THEME}'|g" $BLOG_PATH/pelicanconf.py

+ 5
- 4
src/freedombone-mesh-connect Просмотреть файл

@@ -54,7 +54,8 @@ function vpn_generate_keys {
54 54
     fi
55 55
     cp /etc/openvpn/dh2048.pem /etc/openvpn/easy-rsa/keys/dh2048.pem
56 56
 
57
-    cd /etc/openvpn/easy-rsa
57
+    cd /etc/openvpn/easy-rsa || exit 246872464
58
+    # shellcheck disable=SC1091
58 59
     . ./vars
59 60
     ./clean-all
60 61
     vpn_openssl_version='1.0.0'
@@ -147,12 +148,12 @@ function mesh_setup_vpn {
147 148
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/stunnel*
148 149
 
149 150
     # create an archive of the vpn client files
150
-    cd /home/$MY_USERNAME
151
+    cd /home/$MY_USERNAME || exit 346825628354
151 152
     tar -czvf vpn.tar.gz stunnel* client.ovpn
152 153
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/vpn.tar.gz
153 154
 
154 155
     if [ -f vpn.tar.gz ]; then
155
-        zenity --info --title $"Generate VPN client keys" --text $"\nNew VPN client keys have been generated in the /home/fbone directory.\n\nYou can find it by selecting \"Places\" then \"Home Directory\" on the top menu bar. Transmit the vpn.tar.gz file to whoever is running the other mesh network so that they can connect to yours.\n\nThey should uncompress vpn.tar.gz to their /home/fbone directory, forward port $VPN_MESH_TLS_PORT then connect using your IP address or domain name." --width 600
156
+        zenity --info --title $"Generate VPN client keys" --text $"\\nNew VPN client keys have been generated in the /home/fbone directory.\\n\\nYou can find it by selecting \"Places\" then \"Home Directory\" on the top menu bar. Transmit the vpn.tar.gz file to whoever is running the other mesh network so that they can connect to yours.\\n\\nThey should uncompress vpn.tar.gz to their /home/fbone directory, forward port $VPN_MESH_TLS_PORT then connect using your IP address or domain name." --width 600
156 157
     fi
157 158
 }
158 159
 
@@ -190,7 +191,7 @@ function connect_to_mesh {
190 191
                     sed -i "s|route .*|route $ip_or_domain 255.255.255.255 net_gateway|g" ~/client.ovpn
191 192
 
192 193
                     clear
193
-                    cd ~/
194
+                    cd ~/ || exit 234628422874
194 195
                     sudo stunnel stunnel-client.conf
195 196
                     sudo openvpn client.ovpn
196 197
                 fi

+ 106
- 106
src/freedombone-mesh-install Просмотреть файл

@@ -108,26 +108,26 @@ function mesh_avahi {
108 108
     fi
109 109
 
110 110
     # Add a mesh routing protocol service
111
-    echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > $rootdir/etc/avahi/services/routing.service
112
-    echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> $rootdir/etc/avahi/services/routing.service
113
-    echo '<service-group>' >> $rootdir/etc/avahi/services/routing.service
114
-    echo '  <name replace-wildcards="yes">%h routing</name>' >> $rootdir/etc/avahi/services/routing.service
115
-    echo '  <service>' >> $rootdir/etc/avahi/services/routing.service
116
-    echo '    <type>_bmx6._tcp</type>' >> $rootdir/etc/avahi/services/routing.service
117
-    echo '  </service>' >> $rootdir/etc/avahi/services/routing.service
118
-    echo '</service-group>' >> $rootdir/etc/avahi/services/routing.service
111
+    { echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->';
112
+      echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">';
113
+      echo '<service-group>';
114
+      echo '  <name replace-wildcards="yes">%h routing</name>';
115
+      echo '  <service>';
116
+      echo '    <type>_bmx6._tcp</type>';
117
+      echo '  </service>';
118
+      echo '</service-group>'; } > "$rootdir/etc/avahi/services/routing.service"
119 119
 
120 120
     # keep the daemon running
121 121
     WATCHDOG_SCRIPT_NAME="keepon"
122
-    echo '' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
123
-    echo '# keep avahi daemon running' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
124
-    echo 'AVAHI_RUNNING=$(pgrep avahi-daemon > /dev/null && echo Running)' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
125
-    echo 'if [ ! $AVAHI_RUNNING ]; then' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
126
-    echo '  systemctl start avahi-daemon' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
127
-    echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
128
-    echo '  echo " Avahi daemon restarted" >> $LOGFILE' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
129
-    echo 'fi' >> $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
130
-    chmod +x $rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME
122
+    { echo '';
123
+    echo '# keep avahi daemon running';
124
+    echo "AVAHI_RUNNING=\$(pgrep avahi-daemon > /dev/null && echo Running)";
125
+    echo "if [ ! \$AVAHI_RUNNING ]; then";
126
+    echo '  systemctl start avahi-daemon';
127
+    echo "  echo -n \$CURRENT_DATE >> \$LOGFILE";
128
+    echo "  echo \" Avahi daemon restarted\" >> \$LOGFILE";
129
+    echo 'fi'; } >> "$rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME"
130
+    chmod +x "$rootdir/usr/bin/$WATCHDOG_SCRIPT_NAME"
131 131
 }
132 132
 
133 133
 function install_batman_remove {
@@ -154,23 +154,23 @@ function install_batman {
154 154
     fi
155 155
 
156 156
     BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
157
-    echo '[Unit]' > $BATMAN_DAEMON
158
-    echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
159
-    echo 'After=network.target' >> $BATMAN_DAEMON
160
-    echo '' >> $BATMAN_DAEMON
161
-    echo '[Service]' >> $BATMAN_DAEMON
162
-    echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
163
-    echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
164
-    echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
165
-    echo 'Restart=on-failure' >> $BATMAN_DAEMON
166
-    echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
167
-    echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
168
-    echo '' >> $BATMAN_DAEMON
169
-    echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
170
-    echo 'TimeoutSec=300' >> $BATMAN_DAEMON
171
-    echo '' >> $BATMAN_DAEMON
172
-    echo '[Install]' >> $BATMAN_DAEMON
173
-    echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
157
+    { echo '[Unit]';
158
+      echo 'Description=B.A.T.M.A.N. Advanced';
159
+      echo 'After=network.target';
160
+      echo '';
161
+      echo '[Service]';
162
+      echo 'RemainAfterExit=yes';
163
+      echo "ExecStart=/var/lib/batman start";
164
+      echo "ExecStop=/var/lib/batman stop";
165
+      echo 'Restart=on-failure';
166
+      echo 'SuccessExitStatus=3 4';
167
+      echo 'RestartForceExitStatus=3 4';
168
+      echo '';
169
+      echo '# Allow time for the server to start/stop';
170
+      echo 'TimeoutSec=300';
171
+      echo '';
172
+      echo '[Install]';
173
+      echo 'WantedBy=multi-user.target'; } > "$BATMAN_DAEMON"
174 174
     $CHROOT_PREFIX systemctl enable batman
175 175
 }
176 176
 
@@ -178,79 +178,79 @@ function mesh_firewall {
178 178
     FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
179 179
     MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
180 180
 
181
-    echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT
182
-    echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
183
-    echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT
184
-    echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT
185
-    echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT
186
-    echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT
187
-    echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT
188
-    echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT
189
-    echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT
190
-    echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
191
-    echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT
192
-    echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
193
-    echo 'ip6tables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
194
-    echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
195
-    echo 'ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
196
-    echo '' >> $MESH_FIREWALL_SCRIPT
197
-    echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT
198
-    echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
199
-    echo 'ip6tables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT
200
-    echo '' >> $MESH_FIREWALL_SCRIPT
201
-    echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT
202
-    echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
203
-    echo 'ip6tables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT
204
-    echo '' >> $MESH_FIREWALL_SCRIPT
205
-    echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT
206
-    echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
207
-    echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT
208
-    echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
209
-    echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
210
-    echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
211
-    echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT
212
-    echo '' >> $MESH_FIREWALL_SCRIPT
213
-    echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT
214
-    echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
215
-    echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT
216
-    echo '' >> $MESH_FIREWALL_SCRIPT
217
-    echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
218
-    echo "ip6tables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
219
-
220
-    echo "iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
221
-    echo "ip6tables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
222
-    echo "iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
223
-    echo "ip6tables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
224
-    echo "iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
225
-    echo "ip6tables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
226
-    echo "iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
227
-    echo "ip6tables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
228
-    echo "iptables -A INPUT -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
229
-    echo "ip6tables -A INPUT -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT
230
-
231
-    echo '# OLSR2/MANET' >> $MESH_FIREWALL_SCRIPT
232
-    echo 'iptables -A INPUT -p udp --dport 269 -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
233
-    echo 'ip6tables -A INPUT -p udp --dport 269 -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
234
-    echo 'iptables -A INPUT -p tcp --dport 138 -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
235
-    echo 'ip6tables -A INPUT -p tcp --dport 138 -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
236
-
237
-    echo '# Babel' >> $MESH_FIREWALL_SCRIPT
238
-    echo 'iptables -A INPUT -p udp --dport 6696 -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
239
-    echo 'ip6tables -A INPUT -p udp --dport 6696 -j ACCEPT' >> $MESH_FIREWALL_SCRIPT
181
+    { echo '#!/bin/bash';
182
+      echo 'iptables -P INPUT ACCEPT';
183
+      echo 'ip6tables -P INPUT ACCEPT';
184
+      echo 'iptables -F';
185
+      echo 'ip6tables -F';
186
+      echo 'iptables -t nat -F';
187
+      echo 'ip6tables -t nat -F';
188
+      echo 'iptables -X';
189
+      echo 'ip6tables -X';
190
+      echo 'iptables -P INPUT DROP';
191
+      echo 'ip6tables -P INPUT DROP';
192
+      echo 'iptables -A INPUT -i lo -j ACCEPT';
193
+      echo 'ip6tables -A INPUT -i lo -j ACCEPT';
194
+      echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT';
195
+      echo 'ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT';
196
+      echo '';
197
+      echo '# Make sure incoming tcp connections are SYN packets';
198
+      echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP';
199
+      echo 'ip6tables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP';
200
+      echo '';
201
+      echo '# Drop packets with incoming fragments';
202
+      echo 'iptables -A INPUT -f -j DROP';
203
+      echo 'ip6tables -A INPUT -f -j DROP';
204
+      echo '';
205
+      echo '# Drop bogons';
206
+      echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP';
207
+      echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP';
208
+      echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP';
209
+      echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP';
210
+      echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP';
211
+      echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP';
212
+      echo '';
213
+      echo '# Incoming malformed NULL packets:';
214
+      echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP';
215
+      echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP';
216
+      echo '';
217
+      echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT";
218
+      echo "ip6tables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT";
219
+
220
+      echo "iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT";
221
+      echo "ip6tables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT";
222
+      echo "iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT";
223
+      echo "ip6tables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT";
224
+      echo "iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT";
225
+      echo "ip6tables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT";
226
+      echo "iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT";
227
+      echo "ip6tables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT";
228
+      echo "iptables -A INPUT -p udp --dport 1900 -j ACCEPT";
229
+      echo "ip6tables -A INPUT -p udp --dport 1900 -j ACCEPT";
230
+
231
+      echo '# OLSR2/MANET';
232
+      echo 'iptables -A INPUT -p udp --dport 269 -j ACCEPT';
233
+      echo 'ip6tables -A INPUT -p udp --dport 269 -j ACCEPT';
234
+      echo 'iptables -A INPUT -p tcp --dport 138 -j ACCEPT';
235
+      echo 'ip6tables -A INPUT -p tcp --dport 138 -j ACCEPT';
236
+
237
+      echo '# Babel';
238
+      echo 'iptables -A INPUT -p udp --dport 6696 -j ACCEPT';
239
+      echo 'ip6tables -A INPUT -p udp --dport 6696 -j ACCEPT'; } > "$MESH_FIREWALL_SCRIPT"
240 240
     chmod +x $MESH_FIREWALL_SCRIPT
241 241
 
242
-    echo '[Unit]' > $FIREWALL_FILENAME
243
-    echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME
244
-    echo '' >> $FIREWALL_FILENAME
245
-    echo '[Service]' >> $FIREWALL_FILENAME
246
-    echo 'Type=oneshot' >> $FIREWALL_FILENAME
247
-    echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME
248
-    echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME
249
-    echo '' >> $FIREWALL_FILENAME
250
-    echo 'TimeoutSec=30' >> $FIREWALL_FILENAME
251
-    echo '' >> $FIREWALL_FILENAME
252
-    echo '[Install]' >> $FIREWALL_FILENAME
253
-    echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME
242
+    { echo '[Unit]';
243
+      echo 'Description=Mesh Firewall';
244
+      echo '';
245
+      echo '[Service]';
246
+      echo 'Type=oneshot';
247
+      echo 'ExecStart=/usr/bin/mesh-firewall';
248
+      echo 'RemainAfterExit=no';
249
+      echo '';
250
+      echo 'TimeoutSec=30';
251
+      echo '';
252
+      echo '[Install]';
253
+      echo 'WantedBy=multi-user.target'; } > $FIREWALL_FILENAME
254 254
     chmod +x $FIREWALL_FILENAME
255 255
     $CHROOT_PREFIX systemctl enable meshfirewall
256 256
 }
@@ -290,7 +290,7 @@ do
290 290
         -r|--rootdir)
291 291
             shift
292 292
             rootdir="$1"
293
-            CHROOT_PREFIX='chroot "${rootdir}"'
293
+            CHROOT_PREFIX="chroot \"\${rootdir}\""
294 294
             ;;
295 295
         -w|--wifi|--interface)
296 296
             shift

+ 2
- 2
src/freedombone-mesh-invite Просмотреть файл

@@ -35,13 +35,13 @@ invite=$(sudo -- bash -c 'su -c "sbot invite.create 1" - scuttlebot' | awk -F '"
35 35
 
36 36
 if [ ${#invite} -lt 10 ]; then
37 37
    dialog --title $"Create Invite" \
38
-          --msgbox $"\nThe invite could not be created" 7 70
38
+          --msgbox $"\\nThe invite could not be created" 7 70
39 39
    exit 1
40 40
 fi
41 41
 
42 42
 echo "$invite" | xclip -selection c
43 43
 
44 44
 dialog --title $"Create Invite" \
45
-       --msgbox $"\nThe invite has been copied to the clipboard.\n\nYou can paste it with CTRL+v" 9 70
45
+       --msgbox $"\\nThe invite has been copied to the clipboard.\\n\\nYou can paste it with CTRL+v" 9 70
46 46
 
47 47
 exit 0

+ 3
- 3
src/freedombone-mesh-reset Просмотреть файл

@@ -43,12 +43,12 @@ if ! zenity --question --title=$'New Identity' --text=$"Do you want to reset you
43 43
     sudo pkill midori
44 44
     sudo pkill patchwork
45 45
     sudo rm -f $MESH_INSTALL_COMPLETED
46
-    sudo ${PROJECT_NAME}-image-mesh $USER new
46
+    sudo "${PROJECT_NAME}-image-mesh" "$USER" new
47 47
 
48 48
     sudo batman start
49 49
 
50
-    if [ -f $HOME/mesh-desktop.sh ]; then
51
-        $HOME/mesh-desktop.sh
50
+    if [ -f "$HOME/mesh-desktop.sh" ]; then
51
+        "$HOME/mesh-desktop.sh"
52 52
     else
53 53
         zenity --info --title=$"New Identity" --text=$"You now have a new identity" --width=200
54 54
     fi

+ 35
- 35
src/freedombone-mesh-routing Просмотреть файл

@@ -31,34 +31,34 @@ PROJECT_NAME='freedombone'
31 31
 export TEXTDOMAIN=${PROJECT_NAME}-mesh-routing
32 32
 export TEXTDOMAINDIR="/usr/share/locale"
33 33
 
34
-source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi
35
-source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh
34
+source "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-wifi"
35
+source "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-mesh"
36 36
 
37 37
 function mesh_stop_daemon {
38 38
     daemon_name=$1
39 39
 
40 40
     clear
41 41
     echo ''
42
-    echo $"Stopping $1..."
43
-    sudo systemctl stop $1
44
-    echo $"Disabling $1..."
45
-    sudo systemctl disable $1
42
+    echo $"Stopping ${daemon_name}..."
43
+    sudo systemctl stop "${daemon_name}"
44
+    echo $"Disabling ${daemon_name}..."
45
+    sudo systemctl disable "${daemon_name}"
46 46
 }
47 47
 
48 48
 clear
49 49
 echo ''
50 50
 echo $'Scanning for BMX6 protocol...'
51
-bmx6_peers=$(avahi-browse -at | grep routing | grep bmx6 | wc -l)
51
+bmx6_peers=$(avahi-browse -at | grep routing | grep -c bmx6)
52 52
 
53 53
 clear
54 54
 echo ''
55 55
 echo $'Scanning for OLSR2 protocol...'
56
-olsr2_peers=$(avahi-browse -at | grep routing | grep olsr2 | wc -l)
56
+olsr2_peers=$(avahi-browse -at | grep routing | grep -c olsr2)
57 57
 
58 58
 clear
59 59
 echo ''
60 60
 echo $'Scanning for Babel protocol...'
61
-babel_peers=$(avahi-browse -at | grep routing | grep babel | wc -l)
61
+babel_peers=$(avahi-browse -at | grep routing | grep -c babel)
62 62
 
63 63
 clear
64 64
 
@@ -71,28 +71,28 @@ case $sel in
71 71
 esac
72 72
 
73 73
 temp_script=$HOME/.change_routing
74
-echo '#!/bin/bash' > $temp_script
75
-echo "echo \"\$1\" > $MESH_DEFAULT_PROTOCOL" >> $temp_script
76
-echo "echo \"\$1\" > $MESH_CURRENT_PROTOCOL" >> $temp_script
77
-echo "sed -i \"s|<type>.*|<type>_\${1}._tcp</type>|g\" /etc/avahi/services/routing.service" >> $temp_script
78
-echo 'systemctl restart avahi-daemon' >> $temp_script
79
-echo "IFACE=\$(cat /etc/systemd/system/\${1}.service | grep ExecStart | awk -F ' ' '{print \$2}')" >> $temp_script
80
-echo 'network=fd66:66:66' >> $temp_script
81
-echo 'search_ipv6=$(ifconfig $1 | grep $network)' >> $temp_script
82
-echo 'if [ $search_ipv6 ]; then' >> $temp_script
83
-echo "    result=\$(ifconfig \$1 | grep \$network | awk -F ' ' '{print \$2}')" >> $temp_script
84
-echo '    ip -6 addr add ${result}/128 dev $1' >> $temp_script
85
-echo 'else' >> $temp_script
86
-echo '    ipv6_array=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )' >> $temp_script
87
-echo '    a=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}' >> $temp_script
88
-echo '    b=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}' >> $temp_script
89
-echo '    c=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}' >> $temp_script
90
-echo '    d=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}' >> $temp_script
91
-echo '    e=${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}${ipv6_array[$RANDOM%16]}' >> $temp_script
92
-echo '    result=$network:$a:$b:$c:$d:$e' >> $temp_script
93
-echo '    ip -6 addr add ${result}/128 dev $1' >> $temp_script
94
-echo 'fi' >> $temp_script
95
-chmod +x $temp_script
74
+{ echo '#!/bin/bash';
75
+  echo "echo \"\$1\" > $MESH_DEFAULT_PROTOCOL";
76
+  echo "echo \"\$1\" > $MESH_CURRENT_PROTOCOL";
77
+  echo "sed -i \"s|<type>.*|<type>_\${1}._tcp</type>|g\" /etc/avahi/services/routing.service";
78
+  echo 'systemctl restart avahi-daemon';
79
+  echo "IFACE=\$(cat /etc/systemd/system/\${1}.service | grep ExecStart | awk -F ' ' '{print \$2}')";
80
+  echo 'network=fd66:66:66';
81
+  echo "search_ipv6=\$(ifconfig \$1 | grep \$network)";
82
+  echo "if [ \$search_ipv6 ]; then";
83
+  echo "    result=\$(ifconfig \$1 | grep \$network | awk -F ' ' '{print \$2}')";
84
+  echo "    ip -6 addr add \${result}/128 dev \$1";
85
+  echo 'else';
86
+  echo '    ipv6_array=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )';
87
+  echo "    a=\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}";
88
+  echo "    b=\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}";
89
+  echo "    c=\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}";
90
+  echo "    d=\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}";
91
+  echo "    e=\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}\${ipv6_array[\$RANDOM%16]}";
92
+  echo "    result=\$network:\$a:\$b:\$c:\$d:\$e";
93
+  echo "    ip -6 addr add \${result}/128 dev \$1";
94
+  echo 'fi'; } > "$temp_script"
95
+chmod +x "$temp_script"
96 96
 
97 97
 clear
98 98
 echo ''
@@ -100,7 +100,7 @@ echo $'Authentication to change mesh protocol'
100 100
 echo ''
101 101
 
102 102
 case $data in
103
-    1)  sudo $temp_script 'bmx6'
103
+    1)  sudo "$temp_script" 'bmx6'
104 104
         mesh_stop_daemon 'bmx7'
105 105
         mesh_stop_daemon 'olsr2'
106 106
         mesh_stop_daemon 'babel'
@@ -111,7 +111,7 @@ case $data in
111 111
         echo $'Starting BMX6...'
112 112
         sudo systemctl start bmx6
113 113
         ;;
114
-    2)  sudo $temp_script 'olsr2'
114
+    2)  sudo "$temp_script" 'olsr2'
115 115
         mesh_stop_daemon 'bmx6'
116 116
         mesh_stop_daemon 'bmx7'
117 117
         mesh_stop_daemon 'babel'
@@ -122,7 +122,7 @@ case $data in
122 122
         echo $'Starting OLSR2...'
123 123
         sudo systemctl start olsr2
124 124
         ;;
125
-    3)  sudo $temp_script 'babel'
125
+    3)  sudo "$temp_script" 'babel'
126 126
         mesh_stop_daemon 'bmx6'
127 127
         mesh_stop_daemon 'bmx7'
128 128
         mesh_stop_daemon 'olsr2'
@@ -135,6 +135,6 @@ case $data in
135 135
         ;;
136 136
 esac
137 137
 
138
-rm $temp_script
138
+rm "$temp_script"
139 139
 
140 140
 exit 0

+ 7
- 6
src/freedombone-mesh-visit-site Просмотреть файл

@@ -51,7 +51,7 @@ fi
51 51
 
52 52
 USERS_FILE_LINES=$(wc -l $USERS_FILE | awk -F ' ' '{print $1}')
53 53
 
54
-if [ $USERS_FILE_LINES -gt 200 ]; then
54
+if [ "$USERS_FILE_LINES" -gt 200 ]; then
55 55
     # If there are more than a Dunbar number of peers then ask for the peer name or ID
56 56
     data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
57 57
     sel=$?
@@ -62,7 +62,7 @@ if [ $USERS_FILE_LINES -gt 200 ]; then
62 62
         if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
63 63
                     TOX_ID="$TOX_USERNAME_OR_ID"
64 64
         else
65
-                    TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME_OR_ID" | head -n 1 | sed "s|$TOX_USERNAME_OR_ID ||g" | sed -e 's/^[[:space:]]*//')
65
+                    TOX_ID=$(grep "$TOX_USERNAME_OR_ID" "$USERS_FILE" | head -n 1 | sed "s|$TOX_USERNAME_OR_ID ||g" | sed -e 's/^[[:space:]]*//')
66 66
         fi
67 67
 
68 68
         if [ ${#TOX_ID} -gt 5 ]; then
@@ -70,7 +70,7 @@ if [ $USERS_FILE_LINES -gt 200 ]; then
70 70
             zenity --info --title $"Visit a site" --text $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" --width 500
71 71
             exit 3
72 72
                     fi
73
-                    IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
73
+                    IPFS_FULL_URL=${IPFS_URL}/$(grep "$TOX_ID" "$IPFS_USERS_FILE" | head -n 1 | awk -F ':' '{print $2}')
74 74
                     pkill $BROWSER
75 75
                     setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
76 76
 
@@ -85,7 +85,8 @@ if [ $USERS_FILE_LINES -gt 200 ]; then
85 85
 else
86 86
     # If there are a relatively small number of users then choose from a list
87 87
     TOX_ID=$(
88
-    cat $USERS_FILE | \
88
+    # shellcheck disable=SC2002
89
+    cat "$USERS_FILE" | \
89 90
         awk -F ' ' '{
90 91
         for(i=1;i<=NF;i++){
91 92
             print $i;
@@ -95,10 +96,10 @@ else
95 96
            --title='Visit the site of another user' \
96 97
            --column='Username' --column='Tox ID' \
97 98
            --print-column=2 --hide-column=2 --width=300 --height=400)
98
-    if [ ! $TOX_ID ]; then
99
+    if [ ! "$TOX_ID" ]; then
99 100
         exit 0
100 101
     fi
101
-    IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
102
+    IPFS_FULL_URL=${IPFS_URL}/$(grep "$TOX_ID" "$IPFS_USERS_FILE" | head -n 1 | awk -F ':' '{print $2}')
102 103
     pkill $BROWSER
103 104
     setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
104 105
 

+ 43
- 44
src/freedombone-pass Просмотреть файл

@@ -60,7 +60,7 @@ function get_backup_key_id {
60 60
     MY_BACKUP_KEY_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
61 61
     if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then
62 62
         echo $"Error: gpg backup key was not found"
63
-        return 58213
63
+        exit 58213
64 64
     fi
65 65
 }
66 66
 
@@ -99,7 +99,7 @@ function pad_string {
99 99
     pass_string="$1"
100 100
     str_length=${#pass_string}
101 101
     total_padding=$((128 - str_length))
102
-    leading_padding=$((1 + RANDOM % $total_padding))
102
+    leading_padding=$((1 + RANDOM % total_padding))
103 103
     trailing_padding=$((total_padding - leading_padding))
104 104
     leading=$(printf "%-${leading_padding}s")
105 105
     trailing=$(printf "%-${trailing_padding}s")
@@ -118,8 +118,7 @@ function run_tests {
118 118
         echo $'Incorrect padded length'
119 119
         exit 78352
120 120
     fi
121
-    ${PROJECT_NAME}-pass -u root -a tests -p "$pass"
122
-    if [ ! "$?" = "0" ]; then
121
+    if ! "${PROJECT_NAME}-pass" -u root -a tests -p "$pass"; then
123 122
         echo $'Unable to encrypt password'
124 123
         exit 72725
125 124
     fi
@@ -142,8 +141,8 @@ function clear_passwords {
142 141
     for d in /root/.passwords/*/ ; do
143 142
         USERNAME=$(echo "$d" | awk -F '/' '{print $4}')
144 143
         if [[ "$USERNAME" != 'root' ]]; then
145
-            shred -zu /root/.passwords/$USERNAME/*
146
-            rm -rf /root/.passwords/$USERNAME
144
+            shred -zu "/root/.passwords/$USERNAME/*"
145
+            rm -rf "/root/.passwords/$USERNAME"
147 146
         fi
148 147
     done
149 148
     if [ ! -f $NO_PASSWORD_STORE_FILE ]; then
@@ -156,34 +155,34 @@ function clear_passwords {
156 155
 function export_to_keepass {
157 156
     filename="$1"
158 157
 
159
-    echo '<database>' > $filename
160
-    echo '  <group>' >> $filename
161
-    echo "    <title>${PROJECT_NAME}</title>" >> $filename
162
-    echo '    <icon>48</icon>' >> $filename
158
+    { echo '<database>';
159
+      echo '  <group>';
160
+      echo "    <title>${PROJECT_NAME}</title>";
161
+      echo '    <icon>48</icon>'; } > "$filename"
163 162
 
164 163
     for d in /root/.passwords/*/ ; do
165 164
         USERNAME=$(echo "$d" | awk -F '/' '{print $4}')
166
-        echo '    <group>' >> $filename
167
-        echo "      <title>$USERNAME</title>" >> $filename
168
-        echo '      <icon>0</icon>' >> $filename
165
+        { echo '    <group>';
166
+          echo "      <title>$USERNAME</title>";
167
+          echo '      <icon>0</icon>'; } >> "$filename"
169 168
         for a in /root/.passwords/$USERNAME/* ; do
170
-            APP_NAME=$(basename $a)
171
-            app_password=$(${PROJECT_NAME}-pass -u $USERNAME -a $APP_NAME)
172
-            echo '      <entry>' >> $filename
173
-            echo "        <title>$APP_NAME</title>" >> $filename
174
-            echo "        <username>$USERNAME</username>" >> $filename
175
-            echo "        <password>$app_password</password>" >> $filename
176
-            echo '        <url/>' >> $filename
177
-            echo '        <comment/>' >> $filename
178
-            echo '        <icon>0</icon>' >> $filename
179
-            echo '        <expire>Never</expire>' >> $filename
180
-            echo '      </entry>' >> $filename
169
+            APP_NAME=$(basename "$a")
170
+            app_password=$("${PROJECT_NAME}-pass" -u "$USERNAME" -a "$APP_NAME")
171
+            { echo '      <entry>';
172
+              echo "        <title>$APP_NAME</title>";
173
+              echo "        <username>$USERNAME</username>";
174
+              echo "        <password>$app_password</password>";
175
+              echo '        <url/>';
176
+              echo '        <comment/>';
177
+              echo '        <icon>0</icon>';
178
+              echo '        <expire>Never</expire>';
179
+              echo '      </entry>'; } >> "$filename"
181 180
         done
182
-        echo '    </group>' >> $filename
181
+        echo '    </group>' >> "$filename"
183 182
     done
184 183
 
185
-    echo '  </group>' >> $filename
186
-    echo '</database>' >> $filename
184
+    echo '  </group>' >> "$filename"
185
+    echo '</database>' >> "$filename"
187 186
 
188 187
     echo $"Exported $filename"
189 188
 }
@@ -245,9 +244,9 @@ do
245 244
     shift
246 245
 done
247 246
 
248
-if [ ${REMOVE_USERNAME} ]; then
249
-    if [ -d ~/.passwords/${REMOVE_USERNAME} ]; then
250
-        rm -rf ~/.passwords/${REMOVE_USERNAME}
247
+if [ "${REMOVE_USERNAME}" ]; then
248
+    if [ -d "${HOME}/.passwords/${REMOVE_USERNAME}" ]; then
249
+        rm -rf "${HOME}/.passwords/${REMOVE_USERNAME}"
251 250
     fi
252 251
     exit 0
253 252
 fi
@@ -271,43 +270,43 @@ if [ $TESTS ]; then
271 270
     exit 0
272 271
 fi
273 272
 
274
-if [ $EXPORT_FILENAME ]; then
275
-    export_to_keepass $EXPORT_FILENAME
273
+if [ "$EXPORT_FILENAME" ]; then
274
+    export_to_keepass "$EXPORT_FILENAME"
276 275
     exit 0
277 276
 fi
278 277
 
279
-if [ ! $CURR_USERNAME ]; then
278
+if [ ! "$CURR_USERNAME" ]; then
280 279
     echo $'Error: No username given'
281 280
     exit 1
282 281
 fi
283 282
 
284
-if [ ! -d /home/$CURR_USERNAME ]; then
283
+if [ ! -d "/home/$CURR_USERNAME" ]; then
285 284
     if [[ "$CURR_USERNAME" != "root" ]]; then
286 285
         echo $"Error: User $CURR_USERNAME does not exist"
287 286
         exit 2
288 287
     fi
289 288
 fi
290 289
 
291
-if [ ${REMOVE_APP} ]; then
292
-    if [ -d ~/.passwords/${CURR_USERNAME}/${REMOVE_APP} ]; then
293
-        shred -zu ~/.passwords/${CURR_USERNAME}/${REMOVE_APP}
290
+if [ "${REMOVE_APP}" ]; then
291
+    if [ -d "${HOME}/.passwords/${CURR_USERNAME}/${REMOVE_APP}" ]; then
292
+        shred -zu "${HOME}/.passwords/${CURR_USERNAME}/${REMOVE_APP}"
294 293
     fi
295 294
     exit 0
296 295
 fi
297 296
 
298
-if [ ! $CURR_APP ]; then
297
+if [ ! "$CURR_APP" ]; then
299 298
     echo $'Error: No app name given'
300 299
     exit 3
301 300
 fi
302 301
 
303 302
 if [ ${#CURR_PASSWORD} -eq 0 ]; then
304 303
     # retrieve password
305
-    if [ ! -f ~/.passwords/$CURR_USERNAME/$CURR_APP ]; then
304
+    if [ ! -f "${HOME}/.passwords/$CURR_USERNAME/$CURR_APP" ]; then
306 305
         MASTER_PASSWORD=
307 306
         echo ""
308 307
         exit 4
309 308
     else
310
-        pass=$(gpg --batch -dq --passphrase "$MASTER_PASSWORD" ~/.passwords/$CURR_USERNAME/$CURR_APP)
309
+        pass=$(gpg --batch -dq --passphrase "$MASTER_PASSWORD" "${HOME}/.passwords/$CURR_USERNAME/$CURR_APP")
311 310
         remove_padding "${pass}"
312 311
     fi
313 312
 else
@@ -318,12 +317,12 @@ else
318 317
             exit 0
319 318
         fi
320 319
     fi
321
-    if [ ! -d ~/.passwords/$CURR_USERNAME ]; then
322
-        mkdir -p ~/.passwords/$CURR_USERNAME
320
+    if [ ! -d "${HOME}/.passwords/$CURR_USERNAME" ]; then
321
+        mkdir -p "${HOME}/.passwords/$CURR_USERNAME"
323 322
     fi
324 323
     # padding helps to ensure than nothing can be learned from the length of the cyphertext
325
-    pad_string "${CURR_PASSWORD}" | gpg --batch -ca --cipher-algo AES256 --passphrase "$MASTER_PASSWORD" > ~/.passwords/$CURR_USERNAME/$CURR_APP
326
-    if [ ! -f ~/.passwords/$CURR_USERNAME/$CURR_APP ]; then
324
+    pad_string "${CURR_PASSWORD}" | gpg --batch -ca --cipher-algo AES256 --passphrase "$MASTER_PASSWORD" > "${HOME}/.passwords/$CURR_USERNAME/$CURR_APP"
325
+    if [ ! -f "${HOME}/.passwords/$CURR_USERNAME/$CURR_APP" ]; then
327 326
         MASTER_PASSWORD=
328 327
         exit 5
329 328
     fi

+ 18
- 18
src/freedombone-pin-cert Просмотреть файл

@@ -43,20 +43,20 @@ function pin_all_certs {
43 43
         return
44 44
     fi
45 45
 
46
-    cd $WEBSITES_DIRECTORY
47
-    for file in `dir -d *` ; do
48
-        if grep -q "Public-Key-Pins" $file; then
46
+    cd $WEBSITES_DIRECTORY || exit 2468724684
47
+    for file in $(dir -d "*") ; do
48
+        if grep -q "Public-Key-Pins" "$file"; then
49 49
             DOMAIN_NAME=$file
50 50
             KEY_FILENAME=/etc/ssl/private/${DOMAIN_NAME}.key
51
-            if [ -f $KEY_FILENAME ]; then
51
+            if [ -f "$KEY_FILENAME" ]; then
52 52
                 BACKUP_KEY_FILENAME=/etc/ssl/certs/${DOMAIN_NAME}.pem
53
-                if [ -f $BACKUP_KEY_FILENAME ]; then
54
-                    KEY_HASH=$(openssl rsa -in $KEY_FILENAME -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
55
-                    BACKUP_KEY_HASH=$(openssl rsa -in $BACKUP_KEY_FILENAME -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
53
+                if [ -f "$BACKUP_KEY_FILENAME" ]; then
54
+                    KEY_HASH=$(openssl rsa -in "$KEY_FILENAME" -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
55
+                    BACKUP_KEY_HASH=$(openssl rsa -in "$BACKUP_KEY_FILENAME" -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
56 56
                     if [ ${#BACKUP_KEY_HASH} -gt 5 ]; then
57 57
 
58 58
                         PIN_HEADER="Public-Key-Pins 'pin-sha256=\"${KEY_HASH}\"; pin-sha256=\"${BACKUP_KEY_HASH}\"; max-age=${PIN_MAX_AGE}; includeSubDomains';"
59
-                        sed -i "s|Public-Key-Pins.*|${PIN_HEADER}|g" $file
59
+                        sed -i "s|Public-Key-Pins.*|${PIN_HEADER}|g" "$file"
60 60
                         echo $"Pinned $DOMAIN_NAME with keys $KEY_HASH $BACKUP_KEY_HASH"
61 61
                     fi
62 62
                 fi
@@ -65,7 +65,7 @@ function pin_all_certs {
65 65
     done
66 66
 }
67 67
 
68
-if [[ $1 == "all" ]]; then
68
+if [[ "$1" == "all" ]]; then
69 69
     pin_all_certs
70 70
     systemctl restart nginx
71 71
     exit 0
@@ -77,7 +77,7 @@ KEY_FILENAME=/etc/ssl/private/${DOMAIN_NAME}.key
77 77
 BACKUP_KEY_FILENAME=/etc/ssl/certs/${DOMAIN_NAME}.pem
78 78
 SITE_FILENAME=$WEBSITES_DIRECTORY/${DOMAIN_NAME}
79 79
 
80
-if [ ! ${DOMAIN_NAME} ]; then
80
+if [ ! "${DOMAIN_NAME}" ]; then
81 81
     exit 0
82 82
 fi
83 83
 
@@ -86,8 +86,8 @@ if [ ! -f "$SITE_FILENAME" ]; then
86 86
 fi
87 87
 
88 88
 if [[ $REMOVE == "remove" ]]; then
89
-    if grep -q "Public-Key-Pins" $SITE_FILENAME; then
90
-        sed -i "/Public-Key-Pins/d" $SITE_FILENAME
89
+    if grep -q "Public-Key-Pins" "$SITE_FILENAME"; then
90
+        sed -i "/Public-Key-Pins/d" "$SITE_FILENAME"
91 91
         echo $"Removed pinning for ${DOMAIN_NAME}"
92 92
         systemctl restart nginx
93 93
     fi
@@ -104,8 +104,8 @@ if [ ! -f "$BACKUP_KEY_FILENAME" ]; then
104 104
     exit 2
105 105
 fi
106 106
 
107
-KEY_HASH=$(openssl rsa -in $KEY_FILENAME -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
108
-BACKUP_KEY_HASH=$(openssl rsa -in $BACKUP_KEY_FILENAME -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
107
+KEY_HASH=$(openssl rsa -in "$KEY_FILENAME" -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
108
+BACKUP_KEY_HASH=$(openssl rsa -in "$BACKUP_KEY_FILENAME" -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64)
109 109
 
110 110
 if [ ${#KEY_HASH} -lt 5 ]; then
111 111
     echo 'Pin hash unexpectedly short'
@@ -118,15 +118,15 @@ if [ ${#BACKUP_KEY_HASH} -lt 5 ]; then
118 118
 fi
119 119
 
120 120
 PIN_HEADER="Public-Key-Pins 'pin-sha256=\"${KEY_HASH}\"; pin-sha256=\"${BACKUP_KEY_HASH}\"; max-age=5184000; includeSubDomains';"
121
-if ! grep -q "Public-Key-Pins" $SITE_FILENAME; then
122
-    sed -i "/ssl_ciphers.*/a     add_header ${PIN_HEADER}" $SITE_FILENAME
121
+if ! grep -q "Public-Key-Pins" "$SITE_FILENAME"; then
122
+    sed -i "/ssl_ciphers.*/a     add_header ${PIN_HEADER}" "$SITE_FILENAME"
123 123
 else
124
-    sed -i "s|Public-Key-Pins.*|${PIN_HEADER}|g" $SITE_FILENAME
124
+    sed -i "s|Public-Key-Pins.*|${PIN_HEADER}|g" "$SITE_FILENAME"
125 125
 fi
126 126
 
127 127
 systemctl restart nginx
128 128
 
129
-if ! grep -q "add_header Public-Key-Pins" $SITE_FILENAME; then
129
+if ! grep -q "add_header Public-Key-Pins" "$SITE_FILENAME"; then
130 130
     echo $'Pinning failed'
131 131
 fi
132 132
 

+ 8
- 8
src/freedombone-powerline Просмотреть файл

@@ -56,23 +56,23 @@ __powerline() {
56 56
   readonly WHITE_BRIGHT=15
57 57
 
58 58
   # Font effects
59
-  readonly DIM="\[$(tput dim)\]"
60
-  readonly REVERSE="\[$(tput rev)\]"
61
-  readonly RESET="\[$(tput sgr0)\]"
62
-  readonly BOLD="\[$(tput bold)\]"
59
+  readonly DIM="\\[$(tput dim)\\]"
60
+  readonly REVERSE="\\[$(tput rev)\\]"
61
+  readonly RESET="\\[$(tput sgr0)\\]"
62
+  readonly BOLD="\\[$(tput bold)\\]"
63 63
 
64 64
   # Generate terminal colour codes
65 65
   # $1 is an int (a colour) and $2 must be 'fg' or 'bg'
66 66
   __colour() {
67 67
     case "$2" in
68 68
       'fg'*)
69
-        echo "\[$(tput setaf "$1")\]"
69
+        echo "\\[$(tput setaf "$1")\\]"
70 70
         ;;
71 71
       'bg'*)
72
-        echo "\[$(tput setab "$1")\]"
72
+        echo "\\[$(tput setab "$1")\\]"
73 73
         ;;
74 74
       *)
75
-        echo "\[$(tput setab "$1")\]"
75
+        echo "\\[$(tput setab "$1")\\]"
76 76
         ;;
77 77
     esac
78 78
   }
@@ -288,7 +288,7 @@ __powerline() {
288 288
       if [ ! -z "${text+x}" ]; then
289 289
         text+="@"
290 290
       fi
291
-      text+="\h"
291
+      text+="\\h"
292 292
     fi
293 293
 
294 294
     if [ ! -z ${text+x} ]; then

+ 29
- 28
src/freedombone-recoverkey Просмотреть файл

@@ -36,10 +36,10 @@ export TEXTDOMAINDIR="/usr/share/locale"
36 36
 source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
37 37
 
38 38
 # include utils which allow function_check, go and drive mount
39
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
39
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
40 40
 for f in $UTILS_FILES
41 41
 do
42
-    source $f
42
+    source "$f"
43 43
 done
44 44
 
45 45
 FRIENDS_SERVERS_LIST=
@@ -78,69 +78,71 @@ do
78 78
     shift
79 79
 done
80 80
 
81
-if [ ! $MY_USERNAME ]; then
81
+if [ ! "$MY_USERNAME" ]; then
82 82
     show_help
83 83
 fi
84
-if [ ! -d /home/$MY_USERNAME ]; then
84
+if [ ! -d "/home/$MY_USERNAME" ]; then
85 85
     echo $"User $MY_USERNAME does not exist on the system"
86 86
     exit 7270
87 87
 fi
88 88
 
89
-if [ ! $MY_USERNAME ]; then
89
+if [ ! "$MY_USERNAME" ]; then
90 90
     echo $'No username given'
91 91
     exit 3578
92 92
 fi
93
-if [ ! -d /home/$MY_USERNAME ]; then
93
+if [ ! -d "/home/$MY_USERNAME" ]; then
94 94
     echo $"User $MY_USERNAME does not exist on the system"
95 95
     exit 7270
96 96
 fi
97 97
 
98
-FRAGMENTS_DIR=/home/$MY_USERNAME/.gnupg_fragments
98
+FRAGMENTS_DIR="/home/$MY_USERNAME/.gnupg_fragments"
99 99
 
100 100
 # if no remote backup list was given then assume recover from USB
101
-if [ ! $FRIENDS_SERVERS_LIST ]; then
101
+if [ ! "$FRIENDS_SERVERS_LIST" ]; then
102 102
     interactive_gpg_from_usb
103 103
     exit 0
104 104
 fi
105 105
 
106 106
 # obtain shares/fragments from remote locations
107
-if [ $FRIENDS_SERVERS_LIST ]; then
107
+if [ "$FRIENDS_SERVERS_LIST" ]; then
108 108
     # For each remote server
109
-    while read remote_server
109
+    while read -r remote_server
110 110
     do
111 111
         # Get the server and its password
112 112
         # Format is:
113 113
         #   username@domain:/home/username <port number> <ssh password>
114 114
         REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}')
115
-        if [ $REMOTE_SERVER ]; then
115
+        if [ "$REMOTE_SERVER" ]; then
116 116
             REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
117 117
             REMOTE_PASSWORD=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
118 118
 
119 119
             # create a directory if it doesn't exist
120
-            if [ ! -d /home/$MY_USERNAME/.gnupg_fragments ]; then
121
-                mkdir -p /home/$MY_USERNAME/.gnupg_fragments
120
+            if [ ! -d "/home/$MY_USERNAME/.gnupg_fragments" ]; then
121
+                mkdir -p "/home/$MY_USERNAME/.gnupg_fragments"
122 122
             fi
123 123
 
124 124
             echo -n $"Starting key retrieval from $REMOTE_SERVER..."
125
-            /usr/bin/sshpass -p $REMOTE_PASSWORD \
126
-                             scp -r -P $REMOTE_SSH_PORT $REMOTE_SERVER/.gnupg_fragments/* /home/$MY_USERNAME/.gnupg_fragments
125
+            /usr/bin/sshpass -p "$REMOTE_PASSWORD" \
126
+                             scp -r -P "$REMOTE_SSH_PORT" "$REMOTE_SERVER/.gnupg_fragments/*" "/home/$MY_USERNAME/.gnupg_fragments"
127
+            # shellcheck disable=SC2181
127 128
             if [ ! "$?" = "0" ]; then
128 129
                 echo $'FAILED'
129 130
             else
130 131
                 echo $'Ok'
131 132
             fi
132 133
         fi
133
-    done < $FRIENDS_SERVERS_LIST
134
+    done < "$FRIENDS_SERVERS_LIST"
134 135
 fi
135 136
 
136 137
 # was a directory created?
137
-if [ ! -d $FRAGMENTS_DIR ]; then
138
+if [ ! -d "$FRAGMENTS_DIR" ]; then
138 139
     echo $'No fragments have been recovered, so the key cannot be recovered'
139 140
     exit 7483
140 141
 fi
141 142
 
142 143
 # was anything downloaded?
143
-cd $FRAGMENTS_DIR
144
+cd "$FRAGMENTS_DIR" || exit 24682468
145
+# shellcheck disable=SC2012
144 146
 no_of_shares=$(ls -afq keyshare.asc.* | wc -l)
145 147
 if (( no_of_shares == 0 )); then
146 148
     echo $'No key fragments were retrieved'
@@ -148,14 +150,14 @@ if (( no_of_shares == 0 )); then
148 150
 fi
149 151
 
150 152
 # set permissions on the fragments
151
-chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg_fragments
153
+chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.gnupg_fragments"
152 154
 
153 155
 # decrypt the file
154 156
 KEYS_FILE=$FRAGMENTS_DIR/keyshare.asc
155
-cd $FRAGMENTS_DIR
156
-gfcombine $KEYS_FILE.*
157
+cd "$FRAGMENTS_DIR" || exit 482746874624
158
+gfcombine "$KEYS_FILE.*"
157 159
 
158
-if [ ! -f $KEYS_FILE ]; then
160
+if [ ! -f "$KEYS_FILE" ]; then
159 161
     echo $'Unable to decrypt key. This may mean that not enough fragments are available'
160 162
     exit 6283
161 163
 fi
@@ -163,15 +165,14 @@ fi
163 165
 echo $'Key fragments recombined'
164 166
 
165 167
 # import the gpg key
166
-gpg --homedir=/home/$MY_USERNAME/.gnupg --allow-secret-key-import --import $KEYS_FILE
167
-if [ ! "$?" = "0" ]; then
168
+if ! gpg --homedir="/home/$MY_USERNAME/.gnupg" --allow-secret-key-import --import "$KEYS_FILE"; then
168 169
     echo $'Unable to import gpg key'
169
-    shred -zu $KEYS_FILE
170
+    shred -zu "$KEYS_FILE"
170 171
     exit 3682
171 172
 fi
172
-shred -zu $KEYS_FILE
173
-chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
174
-chmod -R 600 /home/$MY_USERNAME/.gnupg
173
+shred -zu "$KEYS_FILE"
174
+chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.gnupg"
175
+chmod -R 600 "/home/$MY_USERNAME/.gnupg"
175 176
 
176 177
 echo $'GPG key was recovered'
177 178
 

+ 32
- 32
src/freedombone-remote Просмотреть файл

@@ -35,7 +35,7 @@ PROJECT_NAME='freedombone'
35 35
 export TEXTDOMAIN=${PROJECT_NAME}-remote
36 36
 export TEXTDOMAINDIR="/usr/share/locale"
37 37
 
38
-CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
38
+CONFIG_FILE="$HOME/${PROJECT_NAME}.cfg"
39 39
 
40 40
 # User to create the list for
41 41
 MY_USERNAME=$USER
@@ -44,7 +44,7 @@ MY_USERNAME=$USER
44 44
 FRIENDS_SERVERS_LIST=
45 45
 
46 46
 # Minimum password length in characters
47
-MINIMUM_PASSWORD_LENGTH=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords | grep 'MINIMUM_PASSWORD_LENGTH=' | head -n 1 | awk -F '=' '{print $2}')
47
+MINIMUM_PASSWORD_LENGTH=$(grep 'MINIMUM_PASSWORD_LENGTH=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords" | head -n 1 | awk -F '=' '{print $2}')
48 48
 
49 49
 # How many remote locations were specified
50 50
 entering_remote_backups_ctr=0
@@ -117,24 +117,24 @@ do
117 117
 done
118 118
 
119 119
 function interactive_config_remote_backups {
120
-    if [ ! $MY_USERNAME ]; then
120
+    if [ ! "$MY_USERNAME" ]; then
121 121
         echo $'Please specify a username with the -u option'
122 122
         exit 7356
123 123
     fi
124 124
 
125
-    if [ ! /home/$MY_USERNAME ]; then
125
+    if [ ! -d "/home/$MY_USERNAME" ]; then
126 126
         echo $"The user /home/$MY_USERNAME does not exist on the system"
127 127
         exit 3689
128 128
     fi
129 129
 
130
-    if [ ! $FRIENDS_SERVERS_LIST ]; then
130
+    if [ ! "$FRIENDS_SERVERS_LIST" ]; then
131 131
         FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
132 132
     fi
133 133
 
134 134
     # clear any existing list
135
-    if [ -f $FRIENDS_SERVERS_LIST ]; then
136
-        rm -f $FRIENDS_SERVERS_LIST
137
-        touch $FRIENDS_SERVERS_LIST
135
+    if [ -f "$FRIENDS_SERVERS_LIST" ]; then
136
+        rm -f "$FRIENDS_SERVERS_LIST"
137
+        touch "$FRIENDS_SERVERS_LIST"
138 138
     fi
139 139
     # number of entries made
140 140
     entering_remote_backups_ctr=1
@@ -148,57 +148,57 @@ function interactive_config_remote_backups {
148 148
     remote_ssh_reciprocal_password=""
149 149
     while [[ $entering_remote_backups_done == "no" ]]
150 150
     do
151
-        data=$(tempfile 2>/dev/null)
152
-        trap "rm -f $data" 0 1 2 5 15
151
+        data=$(mktemp 2>/dev/null)
153 152
         if [[ $RECIPROCAL == "yes" ]]; then
154 153
             dialog --backtitle "Freedombone Configuration" \
155 154
                    --title "$TITLE ${entering_remote_backups_ctr}" \
156
-                   --form "\nPlease specify the SSH login details for the remote server\n\nThe reciprocal entries are optional, and can be used if you wish to set up a user account on this system for whoever runs the remote server to also use for backups" 20 50 8 \
155
+                   --form "\\nPlease specify the SSH login details for the remote server\\n\\nThe reciprocal entries are optional, and can be used if you wish to set up a user account on this system for whoever runs the remote server to also use for backups" 20 50 8 \
157 156
                    "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
158 157
                    "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
159 158
                    "SSH port:" 3 1 "2222" 3 23 5 4 \
160 159
                    "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
161 160
                    "Reciprocal Username:" 5 1 "$remote_ssh_reciprocal_username" 5 23 20 100 \
162 161
                    "Reciprocal Password:" 6 1 "$remote_ssh_reciprocal_password" 6 23 20 100 \
163
-                   2> $data
162
+                   2> "$data"
164 163
         else
165 164
             dialog --backtitle "Freedombone Configuration" \
166 165
                    --title "$TITLE ${entering_remote_backups_ctr}" \
167
-                   --form "\nPlease specify the SSH login details for the remote server" 15 50 4 \
166
+                   --form "\\nPlease specify the SSH login details for the remote server" 15 50 4 \
168 167
                    "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
169 168
                    "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
170 169
                    "SSH port:" 3 1 "2222" 3 23 5 4 \
171 170
                    "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
172
-                   2> $data
171
+                   2> "$data"
173 172
         fi
174 173
         sel=$?
175 174
         case $sel in
176 175
             1) entering_remote_backups_done="yes";;
177 176
             255) entering_remote_backups_done="yes";;
178 177
         esac
179
-        remote_ssh_username=$(cat $data | sed -n 1p)
180
-        remote_ssh_domain=$(cat $data | sed -n 2p)
181
-        remote_ssh_port=$(cat $data | sed -n 3p)
182
-        remote_ssh_password=$(cat $data | sed -n 4p)
183
-        remote_ssh_reciprocal_username=$(cat $data | sed -n 5p)
184
-        remote_ssh_reciprocal_password=$(cat $data | sed -n 6p)
178
+        remote_ssh_username=$(sed -n 1p < "$data")
179
+        remote_ssh_domain=$(sed -n 2p < "$data")
180
+        remote_ssh_port=$(sed -n 3p < "$data")
181
+        remote_ssh_password=$(sed -n 4p < "$data")
182
+        remote_ssh_reciprocal_username=$(sed -n 5p < "$data")
183
+        remote_ssh_reciprocal_password=$(sed -n 6p < "$data")
184
+        rm -f "$data"
185 185
         if [[ $remote_ssh_username != "" && \
186 186
                     $remote_ssh_domain != "" && \
187 187
                     $remote_ssh_port != "" && \
188 188
                     $remote_ssh_password != "" ]]; then
189 189
 
190
-            if [ ${#remote_ssh_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
190
+            if [ ${#remote_ssh_password} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
191 191
                 dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
192 192
             else
193 193
 
194 194
                 if [[ $RECIPROCAL == "yes" ]]; then
195 195
                     if [[ $remote_ssh_reciprocal_username != "" && \
196 196
                                 $remote_ssh_reciprocal_password != "" ]]; then
197
-                        if [ ${#remote_ssh_reciprocal_password} -lt $MINIMUM_PASSWORD_LENGTH ]; then
197
+                        if [ ${#remote_ssh_reciprocal_password} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
198 198
                             dialog --title "Password quality check" --msgbox "The reciprocal password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
199 199
                         else
200
-                            echo ${remote_ssh_reciprocal_username}:${remote_ssh_reciprocal_password}::::/home/${remote_ssh_reciprocal_username}:bash | newusers
201
-                            echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
200
+                            echo "${remote_ssh_reciprocal_username}:${remote_ssh_reciprocal_password}::::/home/${remote_ssh_reciprocal_username}:bash" | newusers
201
+                            echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> "$FRIENDS_SERVERS_LIST"
202 202
                             remote_ssh_username=""
203 203
                             remote_ssh_domain=""
204 204
                             remote_ssh_port=""
@@ -208,7 +208,7 @@ function interactive_config_remote_backups {
208 208
                             entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
209 209
                         fi
210 210
                     else
211
-                        echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
211
+                        echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> "$FRIENDS_SERVERS_LIST"
212 212
                         remote_ssh_username=""
213 213
                         remote_ssh_domain=""
214 214
                         remote_ssh_port=""
@@ -218,7 +218,7 @@ function interactive_config_remote_backups {
218 218
                         entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
219 219
                     fi
220 220
                 else
221
-                    echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> $FRIENDS_SERVERS_LIST
221
+                    echo "$remote_ssh_username@$remote_ssh_domain $remote_ssh_port /home/$remote_ssh_username $remote_ssh_password" >> "$FRIENDS_SERVERS_LIST"
222 222
                     remote_ssh_username=""
223 223
                     remote_ssh_domain=""
224 224
                     remote_ssh_port=""
@@ -231,18 +231,18 @@ function interactive_config_remote_backups {
231 231
             entering_remote_backups_done="yes"
232 232
         fi
233 233
     done
234
-    if [ -f $FRIENDS_SERVERS_LIST ]; then
235
-        chown $MY_USERNAME:$MY_USERNAME $FRIENDS_SERVERS_LIST
234
+    if [ -f "$FRIENDS_SERVERS_LIST" ]; then
235
+        chown "$MY_USERNAME":"$MY_USERNAME" "$FRIENDS_SERVERS_LIST"
236 236
     fi
237 237
 }
238 238
 
239 239
 function show_result {
240 240
     clear
241
-    if (( $entering_remote_backups_ctr < 2 )); then
241
+    if (( "$entering_remote_backups_ctr" < 2 )); then
242 242
         echo $'No remote backup locations were specified'
243 243
         exit 0
244 244
     fi
245
-    if [ ! -f $FRIENDS_SERVERS_LIST ]; then
245
+    if [ ! -f "$FRIENDS_SERVERS_LIST" ]; then
246 246
         echo $"No remote backups list found: $FRIENDS_SERVERS_LIST"
247 247
         exit 7358
248 248
     fi
@@ -251,11 +251,11 @@ function show_result {
251 251
     echo ''
252 252
     echo $'Contents:'
253 253
     echo ''
254
-    cat $FRIENDS_SERVERS_LIST
254
+    cat "$FRIENDS_SERVERS_LIST"
255 255
     echo ''
256 256
 }
257 257
 
258
-if [ ! $FRIENDS_SERVERS_LIST ]; then
258
+if [ ! "$FRIENDS_SERVERS_LIST" ]; then
259 259
     FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
260 260
 fi
261 261
 

+ 3
- 4
src/freedombone-renew-cert Просмотреть файл

@@ -59,8 +59,7 @@ function renew_letsencrypt {
59 59
         echo $"Renewing Let's Encrypt certificate"
60 60
     fi
61 61
 
62
-    ${PROJECT_NAME}-addcert -e $HOSTNAME -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH
63
-    if [ ! "$?" = "0" ]; then
62
+    if ! ${PROJECT_NAME}-addcert -e $HOSTNAME -s $LETSENCRYPT_SERVER --dhkey $DH_KEYLENGTH; then
64 63
         echo $"Unable to add Let's encrypt certificate"
65 64
         exit 6328
66 65
     fi
@@ -195,7 +194,7 @@ esac
195 194
 shift
196 195
 done
197 196
 
198
-if [ ! $HOSTNAME ]; then
197
+if [ ! "$HOSTNAME" ]; then
199 198
     echo $'No hostname specified'
200 199
     exit 5748
201 200
 fi
@@ -206,7 +205,7 @@ if ! which openssl > /dev/null ;then
206 205
 fi
207 206
 
208 207
 # check that the web site exists
209
-if [ ! -f /etc/nginx/sites-available/$HOSTNAME ]; then
208
+if [ ! -f "/etc/nginx/sites-available/$HOSTNAME" ]; then
210 209
     echo $"/etc/nginx/sites-available/$HOSTNAME does not exist"
211 210
     exit 7598
212 211
 fi

+ 15
- 15
src/freedombone-repair-database Просмотреть файл

@@ -29,16 +29,16 @@
29 29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30 30
 
31 31
 PROJECT_NAME='freedombone'
32
-COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
33
-CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
32
+COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
33
+CONFIG_FILE="$HOME/${PROJECT_NAME}.cfg"
34 34
 
35 35
 export TEXTDOMAIN=${PROJECT_NAME}-repair-databases
36 36
 export TEXTDOMAINDIR="/usr/share/locale"
37 37
 
38 38
 # The database to be repaired
39
-DATABASE=$1
39
+DATABASE="$1"
40 40
 
41
-ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
41
+ADMIN_USERNAME=$(grep "Admin user" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
42 42
 ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
43 43
 
44 44
 # Frequency - daily/weekly
@@ -62,36 +62,36 @@ TEMPFILE=/root/repair-database-$DATABASE
62 62
 
63 63
 umask 0077
64 64
 
65
-if [ $2 ]; then
66
-    BACKUP_TYPE=$2
65
+if [ "$2" ]; then
66
+    BACKUP_TYPE="$2"
67 67
 fi
68 68
 
69 69
 # check the database
70
-mysqlcheck -c -u root --password="$MYSQL_ROOT_PASSWORD" $DATABASE > $TEMPFILE
70
+mysqlcheck -c -u root --password="$MYSQL_ROOT_PASSWORD" "$DATABASE" > "$TEMPFILE"
71 71
 
72 72
 # Attempt to repair the database if it contains errors
73 73
 if grep -q "Error" "$TEMPFILE"; then
74
-    mysqlcheck -u root --password="$MYSQL_ROOT_PASSWORD" --auto-repair $DATABASE
74
+    mysqlcheck -u root --password="$MYSQL_ROOT_PASSWORD" --auto-repair "$DATABASE"
75 75
 else
76 76
     # No errors were found, so exit
77
-    rm -f $TEMPFILE
77
+    rm -f "$TEMPFILE"
78 78
     exit 0
79 79
 fi
80
-rm -f $TEMPFILE
80
+rm -f "$TEMPFILE"
81 81
 
82 82
 # Check the database again
83
-mysqlcheck -c -u root --password="$MYSQL_ROOT_PASSWORD" $DATABASE > $TEMPFILE
83
+mysqlcheck -c -u root --password="$MYSQL_ROOT_PASSWORD" "$DATABASE" > "$TEMPFILE"
84 84
 
85 85
 # If it still contains errors then restore from backup
86 86
 if grep -q "Error" "$TEMPFILE"; then
87
-    mysql -u root --password="$MYSQL_ROOT_PASSWORD" $DATABASE -o < /var/backups/${DATABASE}_${BACKUP_TYPE}.sql
87
+    mysql -u root --password="$MYSQL_ROOT_PASSWORD" "$DATABASE" -o < "/var/backups/${DATABASE}_${BACKUP_TYPE}.sql"
88 88
 
89 89
     # Send a warning email
90
-    echo $"$DATABASE database corruption could not be repaired. Restored from backup." | mail -s $"${PROJECT_NAME} database maintenance" $ADMIN_EMAIL_ADDRESS
91
-    rm -f $TEMPFILE
90
+    echo $"$DATABASE database corruption could not be repaired. Restored from backup." | mail -s $"${PROJECT_NAME} database maintenance" "$ADMIN_EMAIL_ADDRESS"
91
+    rm -f "$TEMPFILE"
92 92
 
93 93
     exit 1
94 94
 fi
95
-rm -f $TEMPFILE
95
+rm -f "$TEMPFILE"
96 96
 
97 97
 exit 0

+ 145
- 130
src/freedombone-restore-local Просмотреть файл

@@ -31,7 +31,7 @@
31 31
 PROJECT_NAME='freedombone'
32 32
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
33 33
 MONGODB_APPS_FILE=$HOME/.mongodbapps
34
-CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
34
+CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
35 35
 BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
36 36
 
37 37
 # whether to restore everything or just a specific application
@@ -67,10 +67,10 @@ please_wait
67 67
 source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
68 68
 
69 69
 # include utils which allow function_check, go and drive mount
70
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
70
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
71 71
 for f in $UTILS_FILES
72 72
 do
73
-    source $f
73
+    source "$f"
74 74
 done
75 75
 
76 76
 clear
@@ -83,7 +83,7 @@ ADMIN_NAME=
83 83
 
84 84
 read_config_param USB_DRIVE
85 85
 
86
-if [ -f $COMPLETION_FILE ]; then
86
+if [ -f "$COMPLETION_FILE" ]; then
87 87
     ADMIN_USERNAME=$(get_completion_param "Admin user")
88 88
 fi
89 89
 
@@ -98,7 +98,7 @@ function check_backup_exists {
98 98
 
99 99
 function check_admin_user {
100 100
     echo $"Checking that admin user exists"
101
-    if [ ! -d /home/$ADMIN_USERNAME ]; then
101
+    if [ ! -d "/home/$ADMIN_USERNAME" ]; then
102 102
         echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username."
103 103
         set_user_permissions
104 104
         backup_unmount_drive
@@ -108,7 +108,7 @@ function check_admin_user {
108 108
 
109 109
 function copy_gpg_keys {
110 110
     echo $"Copying GPG keys from admin user to root"
111
-    cp -r /home/$ADMIN_USERNAME/.gnupg /root
111
+    cp -r "/home/$ADMIN_USERNAME/.gnupg" /root
112 112
     gpg_set_permissions root
113 113
 }
114 114
 
@@ -185,12 +185,11 @@ function restore_configfiles {
185 185
         #    fi
186 186
         #fi
187 187
 
188
-        if [ -f $temp_restore_dir$MONGODB_APPS_FILE ]; then
189
-            cp -f $temp_restore_dir$MONGODB_APPS_FILE $MONGODB_APPS_FILE
190
-            if [ ! "$?" = "0" ]; then
188
+        if [ -f "$temp_restore_dir$MONGODB_APPS_FILE" ]; then
189
+            if ! cp -f "$temp_restore_dir$MONGODB_APPS_FILE" "$MONGODB_APPS_FILE"; then
191 190
                 set_user_permissions
192 191
                 backup_unmount_drive
193
-                rm -rf $temp_restore_dir
192
+                rm -rf "$temp_restore_dir"
194 193
                 exit 859034853
195 194
             fi
196 195
         fi
@@ -210,12 +209,11 @@ function restore_configfiles {
210 209
         #    fi
211 210
         #fi
212 211
 
213
-        if [ -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ]; then
214
-            cp -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
215
-            if [ ! "$?" = "0" ]; then
212
+        if [ -f "${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES}" ]; then
213
+            if ! cp -f "${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES}" "${BACKUP_EXTRA_DIRECTORIES}"; then
216 214
                 set_user_permissions
217 215
                 backup_unmount_drive
218
-                rm -rf $temp_restore_dir
216
+                rm -rf "$temp_restore_dir"
219 217
                 exit 62121
220 218
             fi
221 219
         fi
@@ -274,6 +272,7 @@ function restore_mariadb {
274 272
             else
275 273
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
276 274
             fi
275
+            # shellcheck disable=SC2181
277 276
             if [ ! "$?" = "0" ]; then
278 277
                 echo $"Try again using the password obtained from backup"
279 278
                 db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
@@ -283,6 +282,7 @@ function restore_mariadb {
283 282
                     mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
284 283
                 fi
285 284
             fi
285
+            # shellcheck disable=SC2181
286 286
             if [ ! "$?" = "0" ]; then
287 287
                 echo "$mysqlsuccess"
288 288
                 set_user_permissions
@@ -292,9 +292,9 @@ function restore_mariadb {
292 292
             echo $"Restarting database"
293 293
             systemctl restart mariadb
294 294
             echo $"Ensure MariaDB handles authentication"
295
-            MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
295
+            MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
296 296
             mariadb_fix_authentication
297
-            DATABASE_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
297
+            DATABASE_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
298 298
         fi
299 299
         rm -rf $temp_restore_dir
300 300
     fi
@@ -328,6 +328,7 @@ function restore_postgresql {
328 328
             else
329 329
                 mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
330 330
             fi
331
+            # shellcheck disable=SC2181
331 332
             if [ ! "$?" = "0" ]; then
332 333
                 echo $"Try again using the password obtained from backup"
333 334
                 db_pass=$(${PROJECT_NAME}-pass -u root -a postgresql)
@@ -337,6 +338,7 @@ function restore_postgresql {
337 338
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
338 339
                 fi
339 340
             fi
341
+            # shellcheck disable=SC2181
340 342
             if [ ! "$?" = "0" ]; then
341 343
                 echo "$mysqlsuccess"
342 344
                 set_user_permissions
@@ -346,8 +348,8 @@ function restore_postgresql {
346 348
             echo $"Restarting database"
347 349
             systemctl restart postgresql
348 350
             echo $"Ensure postgresql handles authentication"
349
-            POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
350
-            DATABASE_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
351
+            POSTGRESQL_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a postgresql)
352
+            DATABASE_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a postgresql)
351 353
         fi
352 354
         rm -rf $temp_restore_dir
353 355
     fi
@@ -411,30 +413,30 @@ function restore_mutt_settings {
411 413
             fi
412 414
 
413 415
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
414
-                if [ ! -d /home/$USERNAME ]; then
415
-                    ${PROJECT_NAME}-adduser $USERNAME
416
+                if [ ! -d "/home/$USERNAME" ]; then
417
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
416 418
                 fi
417 419
                 echo $"Restoring Mutt configurations for $USERNAME"
418
-                restore_directory_from_usb /home/$USERNAME/.mutt mutt/${USERNAME}configs
420
+                restore_directory_from_usb "/home/$USERNAME/.mutt" "mutt/${USERNAME}configs"
419 421
                 echo $"Restoring Mutt settings for $USERNAME"
420 422
                 temp_restore_dir=/root/tempmutt
421
-                restore_directory_from_usb $temp_restore_dir mutt/$USERNAME
422
-                if [ -d $temp_restore_dir/home/$USERNAME/tempbackup ]; then
423
-                    if [ -f $temp_restore_dir/home/$USERNAME/tempbackup/.muttrc ]; then
424
-                        cp -f $temp_restore_dir/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc
425
-                        sed -i '/set sidebar_delim/d' /home/$USERNAME/.muttrc
426
-                        sed -i '/set sidebar_sort/d' /home/$USERNAME/.muttrc
423
+                restore_directory_from_usb "$temp_restore_dir" "mutt/$USERNAME"
424
+                if [ -d "$temp_restore_dir/home/$USERNAME/tempbackup" ]; then
425
+                    if [ -f "$temp_restore_dir/home/$USERNAME/tempbackup/.muttrc" ]; then
426
+                        cp -f "$temp_restore_dir/home/$USERNAME/tempbackup/.muttrc" "/home/$USERNAME/.muttrc"
427
+                        sed -i '/set sidebar_delim/d' "/home/$USERNAME/.muttrc"
428
+                        sed -i '/set sidebar_sort/d' "/home/$USERNAME/.muttrc"
427 429
                     fi
428
-                    if [ -f $temp_restore_dir/home/$USERNAME/tempbackup/Muttrc ]; then
429
-                        cp -f $temp_restore_dir/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc
430
+                    if [ -f "$temp_restore_dir/home/$USERNAME/tempbackup/Muttrc" ]; then
431
+                        cp -f "$temp_restore_dir/home/$USERNAME/tempbackup/Muttrc" /etc/Muttrc
430 432
                         sed -i '/set sidebar_delim/d' /etc/Muttrc
431 433
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
432 434
                     fi
433 435
                 else
434 436
                     if [ -f $temp_restore_dir/.muttrc ]; then
435
-                        cp -f $temp_restore_dir/.muttrc /home/$USERNAME/.muttrc
436
-                        sed -i '/set sidebar_delim/d' /home/$USERNAME/.muttrc
437
-                        sed -i '/set sidebar_sort/d' /home/$USERNAME/.muttrc
437
+                        cp -f "$temp_restore_dir/.muttrc" "/home/$USERNAME/.muttrc"
438
+                        sed -i '/set sidebar_delim/d' "/home/$USERNAME/.muttrc"
439
+                        sed -i '/set sidebar_sort/d' "/home/$USERNAME/.muttrc"
438 440
                     fi
439 441
                     if [ -f $temp_restore_dir/Muttrc ]; then
440 442
                         cp -f $temp_restore_dir/Muttrc /etc/Muttrc
@@ -442,6 +444,7 @@ function restore_mutt_settings {
442 444
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
443 445
                     fi
444 446
                 fi
447
+                # shellcheck disable=SC2181
445 448
                 if [ ! "$?" = "0" ]; then
446 449
                     rm -rf $temp_restore_dir
447 450
                     set_user_permissions
@@ -463,20 +466,21 @@ function restore_gpg {
463 466
         for d in $USB_MOUNT/backup/gnupg/*/ ; do
464 467
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
465 468
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
466
-                if [ ! -d /home/$USERNAME ]; then
467
-                    ${PROJECT_NAME}-adduser $USERNAME
469
+                if [ ! -d "/home/$USERNAME" ]; then
470
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
468 471
                 fi
469 472
                 echo $"Restoring gnupg settings for $USERNAME"
470 473
                 temp_restore_dir=/root/tempgnupg
471
-                restore_directory_from_usb $temp_restore_dir gnupg/$USERNAME
472
-                if [ -d $temp_restore_dir/home/$USERNAME/.gnupg ]; then
473
-                    cp -r $temp_restore_dir/home/$USERNAME/.gnupg /home/$USERNAME/
474
+                restore_directory_from_usb $temp_restore_dir "gnupg/$USERNAME"
475
+                if [ -d "$temp_restore_dir/home/$USERNAME/.gnupg" ]; then
476
+                    cp -r "$temp_restore_dir/home/$USERNAME/.gnupg" "/home/$USERNAME/"
474 477
                 else
475
-                    if [ ! -d /home/$USERNAME/.gnupg ]; then
476
-                        mkdir /home/$USERNAME/.gnupg
478
+                    if [ ! -d "/home/$USERNAME/.gnupg" ]; then
479
+                        mkdir "/home/$USERNAME/.gnupg"
477 480
                     fi
478
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.gnupg/
481
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.gnupg/"
479 482
                 fi
483
+                # shellcheck disable=SC2181
480 484
                 if [ ! "$?" = "0" ]; then
481 485
                     rm -rf $temp_restore_dir
482 486
                     set_user_permissions
@@ -484,10 +488,9 @@ function restore_gpg {
484 488
                     exit 276
485 489
                 fi
486 490
                 rm -rf $temp_restore_dir
487
-                gpg_set_permissions $USERNAME
491
+                gpg_set_permissions "$USERNAME"
488 492
                 if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
489
-                    cp -r /home/$USERNAME/.gnupg /root
490
-                    if [ ! "$?" = "0" ]; then
493
+                    if ! cp -r "/home/$USERNAME/.gnupg" /root; then
491 494
                         set_user_permissions
492 495
                         backup_unmount_drive
493 496
                         exit 283
@@ -509,18 +512,19 @@ function restore_procmail {
509 512
         for d in $USB_MOUNT/backup/procmail/*/ ; do
510 513
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
511 514
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
512
-                if [ ! -d /home/$USERNAME ]; then
513
-                    ${PROJECT_NAME}-adduser $USERNAME
515
+                if [ ! -d "/home/$USERNAME" ]; then
516
+                    ${PROJECT_NAME}-adduser "$USERNAME"
514 517
                 fi
515 518
                 echo $"Restoring procmail settings for $USERNAME"
516 519
                 temp_restore_dir=/root/tempprocmail
517
-                restore_directory_from_usb $temp_restore_dir procmail/$USERNAME
520
+                restore_directory_from_usb $temp_restore_dir "procmail/$USERNAME"
518 521
                 if [ -d $temp_restore_dir ]; then
519
-                    if [ -d $temp_restore_dir/home/$USERNAME/tempbackup ]; then
520
-                        cp -f $temp_restore_dir/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
522
+                    if [ -d "$temp_restore_dir/home/$USERNAME/tempbackup" ]; then
523
+                        cp -f "$temp_restore_dir/home/$USERNAME/tempbackup/.procmailrc" "/home/$USERNAME/"
521 524
                     else
522
-                        cp -f $temp_restore_dir/.procmailrc /home/$USERNAME/.procmailrc
525
+                        cp -f "$temp_restore_dir/.procmailrc" "/home/$USERNAME/.procmailrc"
523 526
                     fi
527
+                    # shellcheck disable=SC2181
524 528
                     if [ ! "$?" = "0" ]; then
525 529
                         rm -rf $temp_restore_dir
526 530
                         set_user_permissions
@@ -544,21 +548,22 @@ function restore_spamassassin {
544 548
         for d in $USB_MOUNT/backup/spamassassin/*/ ; do
545 549
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
546 550
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
547
-                if [ -d $USB_MOUNT/backup/spamassassin/$USERNAME ]; then
548
-                    if [ ! -d /home/$USERNAME ]; then
549
-                        ${PROJECT_NAME}-adduser $USERNAME
551
+                if [ -d "$USB_MOUNT/backup/spamassassin/$USERNAME" ]; then
552
+                    if [ ! -d "/home/$USERNAME" ]; then
553
+                        ${PROJECT_NAME}-adduser "$USERNAME"
550 554
                     fi
551 555
                     echo $"Restoring spamassassin settings for $USERNAME"
552 556
                     temp_restore_dir=/root/tempspamassassin
553
-                    restore_directory_from_usb $temp_restore_dir spamassassin/$USERNAME
554
-                    if [ -d $temp_restore_dir/home/$USERNAME ]; then
555
-                        cp -rf $temp_restore_dir/home/$USERNAME/.spamassassin /home/$USERNAME/
557
+                    restore_directory_from_usb $temp_restore_dir "spamassassin/$USERNAME"
558
+                    if [ -d "$temp_restore_dir/home/$USERNAME" ]; then
559
+                        cp -rf "$temp_restore_dir/home/$USERNAME/.spamassassin" "/home/$USERNAME/"
556 560
                     else
557
-                    if [ ! -d /home/$USERNAME/.spamassassin ]; then
558
-                        mkdir /home/$USERNAME/.spamassassin
561
+                    if [ ! -d "/home/$USERNAME/.spamassassin" ]; then
562
+                        mkdir "/home/$USERNAME/.spamassassin"
559 563
                     fi
560
-                        cp -rf $temp_restore_dir/* /home/$USERNAME/.spamassassin/
564
+                        cp -rf "$temp_restore_dir/*" "/home/$USERNAME/.spamassassin/"
561 565
                     fi
566
+                    # shellcheck disable=SC2181
562 567
                     if [ ! "$?" = "0" ]; then
563 568
                         rm -rf $temp_restore_dir
564 569
                         set_user_permissions
@@ -583,19 +588,20 @@ function restore_admin_readme {
583 588
 
584 589
         # Make a backup of the original README file
585 590
         # incase old passwords need to be used
586
-        if [ -f /home/$ADMIN_USERNAME/README ]; then
587
-            if [ ! -f /home/$ADMIN_USERNAME/README_original ]; then
588
-                cp /home/$ADMIN_USERNAME/README /home/$ADMIN_USERNAME/README_original
591
+        if [ -f "/home/$ADMIN_USERNAME/README" ]; then
592
+            if [ ! -f "/home/$ADMIN_USERNAME/README_original" ]; then
593
+                cp "/home/$ADMIN_USERNAME/README" "/home/$ADMIN_USERNAME/README_original"
589 594
             fi
590 595
         fi
591 596
 
592 597
         temp_restore_dir=/root/tempreadme
593 598
         restore_directory_from_usb $temp_restore_dir readme
594
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
595
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
599
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
600
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README" "/home/$ADMIN_USERNAME/"
596 601
         else
597
-            cp -f $temp_restore_dir/README /home/$ADMIN_USERNAME/README
602
+            cp -f "$temp_restore_dir/README" "/home/$ADMIN_USERNAME/README"
598 603
         fi
604
+        # shellcheck disable=SC2181
599 605
         if [ ! "$?" = "0" ]; then
600 606
             rm -rf $temp_restore_dir
601 607
             set_user_permissions
@@ -616,20 +622,21 @@ function restore_user_ssh_keys {
616 622
         for d in $USB_MOUNT/backup/ssh/*/ ; do
617 623
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
618 624
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
619
-                if [ ! -d /home/$USERNAME ]; then
620
-                    ${PROJECT_NAME}-adduser $USERNAME
625
+                if [ ! -d "/home/$USERNAME" ]; then
626
+                    ${PROJECT_NAME}-adduser "$USERNAME"
621 627
                 fi
622 628
                 echo $"Restoring ssh keys for $USERNAME"
623 629
                 temp_restore_dir=/root/tempssh
624
-                restore_directory_from_usb $temp_restore_dir ssh/$USERNAME
625
-                if [ -d $temp_restore_dir/home/$USERNAME/.ssh ]; then
626
-                    cp -r $temp_restore_dir/home/$USERNAME/.ssh /home/$USERNAME/
630
+                restore_directory_from_usb $temp_restore_dir "ssh/$USERNAME"
631
+                if [ -d "$temp_restore_dir/home/$USERNAME/.ssh" ]; then
632
+                    cp -r "$temp_restore_dir/home/$USERNAME/.ssh" "/home/$USERNAME/"
627 633
                 else
628
-                    if [ ! -d /home/$USERNAME/.ssh ]; then
629
-                        mkdir /home/$USERNAME/.ssh
634
+                    if [ ! -d "/home/$USERNAME/.ssh" ]; then
635
+                        mkdir "/home/$USERNAME/.ssh"
630 636
                     fi
631
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.ssh/
637
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.ssh/"
632 638
                 fi
639
+                # shellcheck disable=SC2181
633 640
                 if [ ! "$?" = "0" ]; then
634 641
                     rm -rf $temp_restore_dir
635 642
                     set_user_permissions
@@ -652,20 +659,21 @@ function restore_user_config {
652 659
         for d in $USB_MOUNT/backup/config/*/ ; do
653 660
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
654 661
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
655
-                if [ ! -d /home/$USERNAME ]; then
656
-                    ${PROJECT_NAME}-adduser $USERNAME
662
+                if [ ! -d "/home/$USERNAME" ]; then
663
+                    ${PROJECT_NAME}-adduser "$USERNAME"
657 664
                 fi
658 665
                 echo $"Restoring config files for $USERNAME"
659 666
                 temp_restore_dir=/root/tempconfig
660
-                restore_directory_from_usb $temp_restore_dir config/$USERNAME
661
-                if [ -d $temp_restore_dir/home/$USERNAME/.config ]; then
662
-                    cp -r $temp_restore_dir/home/$USERNAME/.config /home/$USERNAME/
667
+                restore_directory_from_usb $temp_restore_dir "config/$USERNAME"
668
+                if [ -d "$temp_restore_dir/home/$USERNAME/.config" ]; then
669
+                    cp -r "$temp_restore_dir/home/$USERNAME/.config" "/home/$USERNAME/"
663 670
                 else
664
-                    if [ ! -d /home/$USERNAME/.config ]; then
665
-                        mkdir /home/$USERNAME/.config
671
+                    if [ ! -d "/home/$USERNAME/.config" ]; then
672
+                        mkdir "/home/$USERNAME/.config"
666 673
                     fi
667
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.config/
674
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.config/"
668 675
                 fi
676
+                # shellcheck disable=SC2181
669 677
                 if [ ! "$?" = "0" ]; then
670 678
                     rm -rf $temp_restore_dir
671 679
                     set_user_permissions
@@ -688,20 +696,21 @@ function restore_user_monkeysphere {
688 696
         for d in $USB_MOUNT/backup/monkeysphere/*/ ; do
689 697
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
690 698
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
691
-                if [ ! -d /home/$USERNAME ]; then
692
-                    ${PROJECT_NAME}-adduser $USERNAME
699
+                if [ ! -d "/home/$USERNAME" ]; then
700
+                    ${PROJECT_NAME}-adduser "$USERNAME"
693 701
                 fi
694 702
                 echo $"Restoring monkeysphere ids for $USERNAME"
695 703
                 temp_restore_dir=/root/tempmonkeysphere
696
-                restore_directory_from_usb $temp_restore_dir monkeysphere/$USERNAME
697
-                if [ -d $temp_restore_dir/home/$USERNAME/.monkeysphere ]; then
698
-                    cp -r $temp_restore_dir/home/$USERNAME/.monkeysphere /home/$USERNAME/
704
+                restore_directory_from_usb $temp_restore_dir "monkeysphere/$USERNAME"
705
+                if [ -d "$temp_restore_dir/home/$USERNAME/.monkeysphere" ]; then
706
+                    cp -r "$temp_restore_dir/home/$USERNAME/.monkeysphere" "/home/$USERNAME/"
699 707
                 else
700
-                    if [ ! -d /home/$USERNAME/.monkeysphere ]; then
701
-                        mkdir /home/$USERNAME/.monkeysphere
708
+                    if [ ! -d "/home/$USERNAME/.monkeysphere" ]; then
709
+                        mkdir "/home/$USERNAME/.monkeysphere"
702 710
                     fi
703
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.monkeysphere
711
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.monkeysphere"
704 712
                 fi
713
+                # shellcheck disable=SC2181
705 714
                 if [ ! "$?" = "0" ]; then
706 715
                     rm -rf $temp_restore_dir
707 716
                     set_user_permissions
@@ -716,8 +725,8 @@ function restore_user_monkeysphere {
716 725
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
717 726
         read_config_param MY_EMAIL_ADDRESS
718 727
         MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
719
-        fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
720
-        monkeysphere-authentication add-identity-certifier $fpr
728
+        fpr=$(gpg --with-colons --fingerprint "$MY_GPG_PUBLIC_KEY_ID" | grep fpr | head -n 1 | awk -F ':' '{print $10}')
729
+        monkeysphere-authentication add-identity-certifier "$fpr"
721 730
         monkeysphere-authentication update-users
722 731
     fi
723 732
 }
@@ -732,20 +741,21 @@ function restore_user_fin {
732 741
         for d in $USB_MOUNT/backup/fin/*/ ; do
733 742
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
734 743
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
735
-                if [ ! -d /home/$USERNAME ]; then
736
-                    ${PROJECT_NAME}-adduser $USERNAME
744
+                if [ ! -d "/home/$USERNAME" ]; then
745
+                    ${PROJECT_NAME}-adduser "$USERNAME"
737 746
                 fi
738 747
                 echo $"Restoring fin files for $USERNAME"
739 748
                 temp_restore_dir=/root/tempfin
740
-                restore_directory_from_usb $temp_restore_dir fin/$USERNAME
741
-                if [ -d $temp_restore_dir/home/$USERNAME/.fin ]; then
742
-                    cp -r $temp_restore_dir/home/$USERNAME/.fin /home/$USERNAME/
749
+                restore_directory_from_usb $temp_restore_dir "fin/$USERNAME"
750
+                if [ -d "$temp_restore_dir/home/$USERNAME/.fin" ]; then
751
+                    cp -r "$temp_restore_dir/home/$USERNAME/.fin" "/home/$USERNAME/"
743 752
                 else
744
-                    if [ ! -d /home/$USERNAME/.fin ]; then
745
-                        mkdir /home/$USERNAME/.fin
753
+                    if [ ! -d "/home/$USERNAME/.fin" ]; then
754
+                        mkdir "/home/$USERNAME/.fin"
746 755
                     fi
747
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.fin/
756
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.fin/"
748 757
                 fi
758
+                # shellcheck disable=SC2181
749 759
                 if [ ! "$?" = "0" ]; then
750 760
                     rm -rf $temp_restore_dir
751 761
                     set_user_permissions
@@ -768,20 +778,21 @@ function restore_user_local {
768 778
         for d in $USB_MOUNT/backup/local/*/ ; do
769 779
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
770 780
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
771
-                if [ ! -d /home/$USERNAME ]; then
772
-                    ${PROJECT_NAME}-adduser $USERNAME
781
+                if [ ! -d "/home/$USERNAME" ]; then
782
+                    ${PROJECT_NAME}-adduser "$USERNAME"
773 783
                 fi
774 784
                 echo $"Restoring local files for $USERNAME"
775 785
                 temp_restore_dir=/root/templocal
776
-                restore_directory_from_usb $temp_restore_dir local/$USERNAME
777
-                if [ -d $temp_restore_dir/home/$USERNAME/.local ]; then
778
-                    cp -r $temp_restore_dir/home/$USERNAME/.local /home/$USERNAME/
786
+                restore_directory_from_usb $temp_restore_dir "local/$USERNAME"
787
+                if [ -d "$temp_restore_dir/home/$USERNAME/.local" ]; then
788
+                    cp -r "$temp_restore_dir/home/$USERNAME/.local" "/home/$USERNAME/"
779 789
                 else
780
-                    if [ ! -d /home/$USERNAME/.local ]; then
781
-                        mkdir /home/$USERNAME/.local
790
+                    if [ ! -d "/home/$USERNAME/.local" ]; then
791
+                        mkdir "/home/$USERNAME/.local"
782 792
                     fi
783
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.local/
793
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.local/"
784 794
                 fi
795
+                # shellcheck disable=SC2181
785 796
                 if [ ! "$?" = "0" ]; then
786 797
                     rm -rf $temp_restore_dir
787 798
                     set_user_permissions
@@ -809,6 +820,7 @@ function restore_certs {
809 820
         else
810 821
             cp -r /root/tempssl/* /etc/ssl/
811 822
         fi
823
+        # shellcheck disable=SC2181
812 824
         if [ ! "$?" = "0" ]; then
813 825
             set_user_permissions
814 826
             backup_unmount_drive
@@ -853,24 +865,25 @@ function restore_personal_settings {
853 865
         for d in $USB_MOUNT/backup/personal/*/ ; do
854 866
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
855 867
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
856
-                if [ -d $USB_MOUNT/backup/personal/$USERNAME ]; then
857
-                    if [ ! -d /home/$USERNAME ]; then
858
-                        ${PROJECT_NAME}-adduser $USERNAME
868
+                if [ -d "$USB_MOUNT/backup/personal/$USERNAME" ]; then
869
+                    if [ ! -d "/home/$USERNAME" ]; then
870
+                        ${PROJECT_NAME}-adduser "$USERNAME"
859 871
                     fi
860 872
                     echo $"Restoring personal settings for $USERNAME"
861 873
                     temp_restore_dir=/root/temppersonal
862
-                    restore_directory_from_usb $temp_restore_dir personal/$USERNAME
863
-                    if [ -d /home/$USERNAME/personal ]; then
864
-                        rm -rf /home/$USERNAME/personal
874
+                    restore_directory_from_usb $temp_restore_dir "personal/$USERNAME"
875
+                    if [ -d "/home/$USERNAME/personal" ]; then
876
+                        rm -rf "/home/$USERNAME/personal"
865 877
                     fi
866
-                    if [ -d $temp_restore_dir/home/$USERNAME/personal ]; then
867
-                        mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME
878
+                    if [ -d "$temp_restore_dir/home/$USERNAME/personal" ]; then
879
+                        mv "$temp_restore_dir/home/$USERNAME/personal" "/home/$USERNAME"
868 880
                     else
869
-                        if [ ! -d /home/$USERNAME/personal ]; then
870
-                            mkdir /home/$USERNAME/personal
881
+                        if [ ! -d "/home/$USERNAME/personal" ]; then
882
+                            mkdir "/home/$USERNAME/personal"
871 883
                         fi
872
-                        cp -r $temp_restore_dir/* /home/$USERNAME/personal/
884
+                        cp -r $temp_restore_dir/* "/home/$USERNAME/personal/"
873 885
                     fi
886
+                    # shellcheck disable=SC2181
874 887
                     if [ ! "$?" = "0" ]; then
875 888
                         set_user_permissions
876 889
                         backup_unmount_drive
@@ -898,6 +911,7 @@ function restore_mailing_list {
898 911
         else
899 912
             cp -r $temp_restore_dir/* /var/spool/mlmmj/
900 913
         fi
914
+        # shellcheck disable=SC2181
901 915
         if [ ! "$?" = "0" ]; then
902 916
             set_user_permissions
903 917
             backup_unmount_drive
@@ -917,20 +931,21 @@ function restore_email {
917 931
         for d in $USB_MOUNT/backup/mail/*/ ; do
918 932
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
919 933
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
920
-                if [ ! -d /home/$USERNAME ]; then
921
-                    ${PROJECT_NAME}-adduser $USERNAME
934
+                if [ ! -d "/home/$USERNAME" ]; then
935
+                    ${PROJECT_NAME}-adduser "$USERNAME"
922 936
                 fi
923 937
                 echo $"Restoring emails for $USERNAME"
924 938
                 temp_restore_dir=/root/tempmail
925
-                restore_directory_from_usb $temp_restore_dir mail/$USERNAME
926
-                if [ ! -d /home/$USERNAME/Maildir ]; then
927
-                    mkdir /home/$USERNAME/Maildir
939
+                restore_directory_from_usb $temp_restore_dir "mail/$USERNAME"
940
+                if [ ! -d "/home/$USERNAME/Maildir" ]; then
941
+                    mkdir "/home/$USERNAME/Maildir"
928 942
                 fi
929
-                if [ -d $temp_restore_dir/root/tempbackupemail/$USERNAME ]; then
930
-                    tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
943
+                if [ -d "$temp_restore_dir/root/tempbackupemail/$USERNAME" ]; then
944
+                    tar -xzvf "$temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz" -C /
931 945
                 else
932 946
                     tar -xzvf $temp_restore_dir/maildir.tar.gz -C /
933 947
                 fi
948
+                # shellcheck disable=SC2181
934 949
                 if [ ! "$?" = "0" ]; then
935 950
                     set_user_permissions
936 951
                     backup_unmount_drive
@@ -943,16 +958,16 @@ function restore_email {
943 958
 }
944 959
 
945 960
 function get_restore_app {
946
-    if [ ${1} ]; then
947
-        if [ ! -d /home/${1} ]; then
948
-            RESTORE_APP=${1}
961
+    if [ "${1}" ]; then
962
+        if [ ! -d "/home/${1}" ]; then
963
+            RESTORE_APP="${1}"
949 964
             echo $"Restore $RESTORE_APP"
950 965
         fi
951 966
     fi
952 967
 }
953 968
 
954
-get_restore_app ${2}
955
-backup_mount_drive ${1} ${ADMIN_USERNAME} ${2}
969
+get_restore_app "${2}"
970
+backup_mount_drive "${1}" "${ADMIN_USERNAME}" "${2}"
956 971
 check_backup_exists
957 972
 check_admin_user
958 973
 copy_gpg_keys
@@ -979,7 +994,7 @@ restore_certs
979 994
 restore_personal_settings
980 995
 restore_mailing_list
981 996
 restore_email
982
-restore_apps local $RESTORE_APP
997
+restore_apps local "$RESTORE_APP"
983 998
 set_user_permissions
984 999
 update_default_domain
985 1000
 backup_unmount_drive

+ 153
- 139
src/freedombone-restore-remote Просмотреть файл

@@ -37,19 +37,19 @@ BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
37 37
 export TEXTDOMAIN=${PROJECT_NAME}-restore-remote
38 38
 export TEXTDOMAINDIR="/usr/share/locale"
39 39
 
40
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
40
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
41 41
 for f in $UTILS_FILES
42 42
 do
43
-    source $f
43
+    source "$f"
44 44
 done
45 45
 
46
-SERVER_NAME=$1
46
+SERVER_NAME="$1"
47 47
 
48 48
 # whether to restore everything or just a specific application
49 49
 RESTORE_APP='all'
50 50
 
51
-if [ ${2} ]; then
52
-    RESTORE_APP=${2}
51
+if [ "${2}" ]; then
52
+    RESTORE_APP="${2}"
53 53
 fi
54 54
 
55 55
 ADMIN_USERNAME=$(get_completion_param "Admin user")
@@ -60,46 +60,45 @@ SERVER_DIRECTORY=/root/remoterestore
60 60
 
61 61
 BACKUP_LIST=/home/${ADMIN_USERNAME}/backup.list
62 62
 
63
-if [ ! $SERVER_NAME ]; then
63
+if [ ! "$SERVER_NAME" ]; then
64 64
     echo $'restorefromfriend [server]'
65 65
     exit 1
66 66
 fi
67 67
 
68
-if [ ! -f $BACKUP_LIST ]; then
68
+if [ ! -f "$BACKUP_LIST" ]; then
69 69
     echo $"No friends list found at $BACKUP_LIST"
70 70
     exit 2
71 71
 fi
72 72
 
73
-if ! grep -q "$SERVER_NAME" $BACKUP_LIST; then
73
+if ! grep -q "$SERVER_NAME" "$BACKUP_LIST"; then
74 74
     echo $"Server not found within the friends list"
75 75
     exit 3
76 76
 fi
77 77
 
78
-REMOTE_SERVER=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $1}')
79
-REMOTE_SSH_PORT=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $2}')
80
-REMOTE_DIRECTORY=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $3}')
81
-REMOTE_PASSWORD=$(grep -i "$SERVER_NAME" $BACKUP_LIST | awk -F ' ' '{print $4}')
78
+REMOTE_SERVER=$(grep -i "$SERVER_NAME" "$BACKUP_LIST" | awk -F ' ' '{print $1}')
79
+REMOTE_SSH_PORT=$(grep -i "$SERVER_NAME" "$BACKUP_LIST" | awk -F ' ' '{print $2}')
80
+REMOTE_DIRECTORY=$(grep -i "$SERVER_NAME" "$BACKUP_LIST" | awk -F ' ' '{print $3}')
81
+REMOTE_PASSWORD=$(grep -i "$SERVER_NAME" "$BACKUP_LIST" | awk -F ' ' '{print $4}')
82 82
 REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY
83 83
 
84 84
 NOW=$(date +"%Y-%m-%d %H:%M:%S")
85 85
 
86 86
 echo "$NOW Starting restore from $REMOTE_SERVER" >> /var/log/remotebackups.log
87
-rsync -ratlzv --rsh="/usr/bin/sshpass -p $REMOTE_PASSWORD ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" $REMOTE_SERVER/backup $SERVER_DIRECTORY
88
-if [ ! "$?" = "0" ]; then
87
+if ! rsync -ratlzv --rsh="/usr/bin/sshpass -p $REMOTE_PASSWORD ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no" "$REMOTE_SERVER/backup" "$SERVER_DIRECTORY"; then
89 88
     echo "$NOW Restore from $REMOTE_SERVER failed" >> /var/log/remotebackups.log
90 89
     # Send a warning email
91
-    echo "Restore from $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} restore from friend" $ADMIN_EMAIL_ADDRESS
90
+    echo "Restore from $REMOTE_SERVER failed" | mail -s "${PROJECT_NAME} restore from friend" "$ADMIN_EMAIL_ADDRESS"
92 91
     exit 790
93 92
 else
94 93
     echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log
95 94
 fi
96 95
 
97 96
 # MariaDB password
98
-DATABASE_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
97
+DATABASE_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
99 98
 
100 99
 function copy_gpg_keys {
101 100
     echo $"Copying GPG keys from admin user to root"
102
-    cp -r /home/$ADMIN_USERNAME/.gnupg /root
101
+    cp -r "/home/$ADMIN_USERNAME/.gnupg" /root
103 102
     gpg_set_permissions root
104 103
 }
105 104
 
@@ -110,7 +109,7 @@ function restore_blocklist {
110 109
         fi
111 110
     fi
112 111
 
113
-    if [ -d $USB_MOUNT/backup/blocklist ]; then
112
+    if [ -d "$USB_MOUNT/backup/blocklist" ]; then
114 113
         echo $"Restoring blocklist"
115 114
         temp_restore_dir=/root/tempblocklist
116 115
         restore_directory_from_friend $temp_restore_dir blocklist
@@ -173,9 +172,8 @@ function restore_configfiles {
173 172
         #    fi
174 173
         #fi
175 174
 
176
-        if [ -f $temp_restore_dir$MONGODB_APPS_FILE ]; then
177
-            cp -f $temp_restore_dir$MONGODB_APPS_FILE $MONGODB_APPS_FILE
178
-            if [ ! "$?" = "0" ]; then
175
+        if [ -f "$temp_restore_dir$MONGODB_APPS_FILE" ]; then
176
+            if ! cp -f "$temp_restore_dir$MONGODB_APPS_FILE" "$MONGODB_APPS_FILE"; then
179 177
                 unmount_drive
180 178
                 rm -rf $temp_restore_dir
181 179
                 exit 7835335
@@ -196,9 +194,8 @@ function restore_configfiles {
196 194
         #    fi
197 195
         #fi
198 196
 
199
-        if [ -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ]; then
200
-            cp -f ${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES} ${BACKUP_EXTRA_DIRECTORIES}
201
-            if [ ! "$?" = "0" ]; then
197
+        if [ -f "${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES}" ]; then
198
+            if ! cp -f "${temp_restore_dir}${BACKUP_EXTRA_DIRECTORIES}" "${BACKUP_EXTRA_DIRECTORIES}"; then
202 199
                 unmount_drive
203 200
                 rm -rf $temp_restore_dir
204 201
                 exit 62121
@@ -242,6 +239,7 @@ function restore_mariadb {
242 239
             else
243 240
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
244 241
             fi
242
+            # shellcheck disable=SC2181
245 243
             if [ ! "$?" = "0" ]; then
246 244
                 echo $"Try again using the password obtained from backup"
247 245
                 db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
@@ -251,6 +249,7 @@ function restore_mariadb {
251 249
                     mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
252 250
                 fi
253 251
             fi
252
+            # shellcheck disable=SC2181
254 253
             if [ ! "$?" = "0" ]; then
255 254
                 echo "$mysqlsuccess"
256 255
                 exit 962
@@ -258,7 +257,7 @@ function restore_mariadb {
258 257
             echo $"Restarting database"
259 258
             systemctl restart mariadb
260 259
             echo $"Ensure MariaDB handles authentication"
261
-            MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
260
+            MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
262 261
             mariadb_fix_authentication
263 262
         fi
264 263
         rm -rf ${temp_restore_dir}
@@ -293,15 +292,17 @@ function restore_postgresql {
293 292
             else
294 293
                 mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
295 294
             fi
295
+            # shellcheck disable=SC2181
296 296
             if [ ! "$?" = "0" ]; then
297 297
                 echo $"Try again using the password obtained from backup"
298
-                db_pass=$(${PROJECT_NAME}-pass -u root -a postgresql)
298
+                db_pass=$("${PROJECT_NAME}-pass" -u root -a postgresql)
299 299
                 if [ -d ${temp_restore_dir}${temp_restore_dir} ]; then
300 300
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}${temp_restore_dir}/postgresql.sql)
301 301
                 else
302 302
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
303 303
                 fi
304 304
             fi
305
+            # shellcheck disable=SC2181
305 306
             if [ ! "$?" = "0" ]; then
306 307
                 echo "$mysqlsuccess"
307 308
                 exit 962
@@ -309,7 +310,7 @@ function restore_postgresql {
309 310
             echo $"Restarting database"
310 311
             systemctl restart postgresql
311 312
             echo $"Ensure postgresql handles authentication"
312
-            POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
313
+            POSTGRESQL_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a postgresql)
313 314
         fi
314 315
         rm -rf ${temp_restore_dir}
315 316
     fi
@@ -367,31 +368,31 @@ function restore_mutt_settings {
367 368
         fi
368 369
 
369 370
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
370
-            if [ -d $SERVER_DIRECTORY/backup/mutt/$USERNAME ]; then
371
-                if [ ! -d /home/$USERNAME ]; then
372
-                    ${PROJECT_NAME}-adduser $USERNAME
371
+            if [ -d "$SERVER_DIRECTORY/backup/mutt/$USERNAME" ]; then
372
+                if [ ! -d "/home/$USERNAME" ]; then
373
+                    ${PROJECT_NAME}-adduser "$USERNAME"
373 374
                 fi
374 375
                 echo $"Restoring Mutt configurations for $USERNAME"
375
-                restore_directory_from_friend /home/$USERNAME/.mutt mutt/${USERNAME}configs
376
+                restore_directory_from_friend "/home/$USERNAME/.mutt" "mutt/${USERNAME}configs"
376 377
                 echo $"Restoring Mutt settings for $USERNAME"
377 378
                 temp_restore_dir=/root/tempmutt
378
-                restore_directory_from_friend ${temp_restore_dir} mutt/$USERNAME
379
-                if [ -d ${temp_restore_dir}/home/$USERNAME/tempbackup ]; then
380
-                    if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc ]; then
381
-                        cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc /home/$USERNAME/.muttrc
382
-                        sed -i '/set sidebar_delim/d' /home/$USERNAME/.muttrc
383
-                        sed -i '/set sidebar_sort/d' /home/$USERNAME/.muttrc
379
+                restore_directory_from_friend ${temp_restore_dir} "mutt/$USERNAME"
380
+                if [ -d "${temp_restore_dir}/home/$USERNAME/tempbackup" ]; then
381
+                    if [ -f "${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc" ]; then
382
+                        cp -f "${temp_restore_dir}/home/$USERNAME/tempbackup/.muttrc" "/home/$USERNAME/.muttrc"
383
+                        sed -i '/set sidebar_delim/d' "/home/$USERNAME/.muttrc"
384
+                        sed -i '/set sidebar_sort/d' "/home/$USERNAME/.muttrc"
384 385
                     fi
385
-                    if [ -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc ]; then
386
-                        cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc /etc/Muttrc
386
+                    if [ -f "${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc" ]; then
387
+                        cp -f "${temp_restore_dir}/home/$USERNAME/tempbackup/Muttrc" /etc/Muttrc
387 388
                         sed -i '/set sidebar_delim/d' /etc/Muttrc
388 389
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
389 390
                     fi
390 391
                 else
391 392
                     if [ -f ${temp_restore_dir}/.muttrc ]; then
392
-                        cp -f ${temp_restore_dir}/.muttrc /home/$USERNAME/.muttrc
393
-                        sed -i '/set sidebar_delim/d' /home/$USERNAME/.muttrc
394
-                        sed -i '/set sidebar_sort/d' /home/$USERNAME/.muttrc
393
+                        cp -f "${temp_restore_dir}/.muttrc" "/home/$USERNAME/.muttrc"
394
+                        sed -i '/set sidebar_delim/d' "/home/$USERNAME/.muttrc"
395
+                        sed -i '/set sidebar_sort/d' "/home/$USERNAME/.muttrc"
395 396
                     fi
396 397
                     if [ -f ${temp_restore_dir}/Muttrc ]; then
397 398
                         cp -f ${temp_restore_dir}/Muttrc /etc/Muttrc
@@ -399,6 +400,7 @@ function restore_mutt_settings {
399 400
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
400 401
                     fi
401 402
                 fi
403
+                # shellcheck disable=SC2181
402 404
                 if [ ! "$?" = "0" ]; then
403 405
                     rm -rf ${temp_restore_dir}
404 406
                     exit 276
@@ -417,29 +419,29 @@ function restore_gpg {
417 419
     for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
418 420
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
419 421
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
420
-            if [ -d $SERVER_DIRECTORY/backup/gnupg/$USERNAME ]; then
421
-                if [ ! -d /home/$USERNAME ]; then
422
-                    ${PROJECT_NAME}-adduser $USERNAME
422
+            if [ -d "$SERVER_DIRECTORY/backup/gnupg/$USERNAME" ]; then
423
+                if [ ! -d "/home/$USERNAME" ]; then
424
+                    ${PROJECT_NAME}-adduser "$USERNAME"
423 425
                 fi
424 426
                 echo $"Restoring gnupg settings for $USERNAME"
425 427
                 temp_restore_dir=/root/tempgnupg
426
-                restore_directory_from_friend ${temp_restore_dir} gnupg/$USERNAME
427
-                if [ -d ${temp_restore_dir}/home/$USERNAME/.gnupg ]; then
428
-                    cp -r ${temp_restore_dir}/home/$USERNAME/.gnupg /home/$USERNAME/
428
+                restore_directory_from_friend ${temp_restore_dir} "gnupg/$USERNAME"
429
+                if [ -d "${temp_restore_dir}/home/$USERNAME/.gnupg" ]; then
430
+                    cp -r "${temp_restore_dir}/home/$USERNAME/.gnupg" "/home/$USERNAME/"
429 431
                 else
430
-                    if [ ! -d /home/$USERNAME/.gnupg ]; then
431
-                        mkdir /home/$USERNAME/.gnupg
432
+                    if [ ! -d "/home/$USERNAME/.gnupg" ]; then
433
+                        mkdir "/home/$USERNAME/.gnupg"
432 434
                     fi
433
-                    cp -r ${temp_restore_dir}/* /home/$USERNAME/.gnupg/
435
+                    cp -r "${temp_restore_dir}/*" "/home/$USERNAME/.gnupg/"
434 436
                 fi
437
+                # shellcheck disable=SC2181
435 438
                 if [ ! "$?" = "0" ]; then
436 439
                     rm -rf ${temp_restore_dir}
437 440
                     exit 276
438 441
                 fi
439 442
                 rm -rf ${temp_restore_dir}
440 443
                 if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
441
-                    cp -r /home/$USERNAME/.gnupg /root
442
-                    if [ ! "$?" = "0" ]; then
444
+                    if ! cp -r "/home/$USERNAME/.gnupg" /root; then
443 445
                         exit 283
444 446
                     fi
445 447
                     gpg_set_permissions root
@@ -458,18 +460,19 @@ function restore_procmail {
458 460
     for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
459 461
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
460 462
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
461
-            if [ -d $SERVER_DIRECTORY/backup/procmail/$USERNAME ]; then
462
-                if [ ! -d /home/$USERNAME ]; then
463
-                    ${PROJECT_NAME}-adduser $USERNAME
463
+            if [ -d "$SERVER_DIRECTORY/backup/procmail/$USERNAME" ]; then
464
+                if [ ! -d "/home/$USERNAME" ]; then
465
+                    ${PROJECT_NAME}-adduser "$USERNAME"
464 466
                 fi
465 467
                 echo $"Restoring procmail settings for $USERNAME"
466 468
                 temp_restore_dir=/root/tempprocmail
467
-                restore_directory_from_friend ${temp_restore_dir} procmail/$USERNAME
468
-                if [ -d ${temp_restore_dir}/home/$USERNAME/tempbackup ]; then
469
-                    cp -f ${temp_restore_dir}/home/$USERNAME/tempbackup/.procmailrc /home/$USERNAME/
469
+                restore_directory_from_friend ${temp_restore_dir} "procmail/$USERNAME"
470
+                if [ -d "${temp_restore_dir}/home/$USERNAME/tempbackup" ]; then
471
+                    cp -f "${temp_restore_dir}/home/$USERNAME/tempbackup/.procmailrc" "/home/$USERNAME/"
470 472
                 else
471
-                    cp -f ${temp_restore_dir}/.procmailrc /home/$USERNAME/.procmailrc
473
+                    cp -f "${temp_restore_dir}/.procmailrc" "/home/$USERNAME/.procmailrc"
472 474
                 fi
475
+                # shellcheck disable=SC2181
473 476
                 if [ ! "$?" = "0" ]; then
474 477
                     rm -rf ${temp_restore_dir}
475 478
                     exit 276
@@ -489,21 +492,22 @@ function restore_spamassassin {
489 492
     for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
490 493
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
491 494
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
492
-            if [ -d $SERVER_DIRECTORY/backup/spamassassin/$USERNAME ]; then
493
-                if [ ! -d /home/$USERNAME ]; then
494
-                    ${PROJECT_NAME}-adduser $USERNAME
495
+            if [ -d "$SERVER_DIRECTORY/backup/spamassassin/$USERNAME" ]; then
496
+                if [ ! -d "/home/$USERNAME" ]; then
497
+                    ${PROJECT_NAME}-adduser "$USERNAME"
495 498
                 fi
496 499
                 echo $"Restoring spamassassin settings for $USERNAME"
497 500
                 temp_restore_dir=/root/tempspamassassin
498
-                restore_directory_from_friend $temp_restore_dir spamassassin/$USERNAME
499
-                if [ -d $temp_restore_dir/home/$USERNAME ]; then
500
-                    cp -rf $temp_restore_dir/home/$USERNAME/.spamassassin /home/$USERNAME/
501
+                restore_directory_from_friend $temp_restore_dir "spamassassin/$USERNAME"
502
+                if [ -d "$temp_restore_dir/home/$USERNAME" ]; then
503
+                    cp -rf "$temp_restore_dir/home/$USERNAME/.spamassassin" "/home/$USERNAME/"
501 504
                 else
502
-                    if [ ! -d /home/$USERNAME/.spamassassin ]; then
503
-                        mkdir /home/$USERNAME/.spamassassin
505
+                    if [ ! -d "/home/$USERNAME/.spamassassin" ]; then
506
+                        mkdir "/home/$USERNAME/.spamassassin"
504 507
                     fi
505
-                    cp -rf $temp_restore_dir/* /home/$USERNAME/.spamassassin/
508
+                    cp -rf $temp_restore_dir/* "/home/$USERNAME/.spamassassin/"
506 509
                 fi
510
+                # shellcheck disable=SC2181
507 511
                 if [ ! "$?" = "0" ]; then
508 512
                     rm -rf $temp_restore_dir
509 513
                     exit 276
@@ -524,11 +528,12 @@ function restore_admin_readme {
524 528
         echo $"Restoring README"
525 529
         temp_restore_dir=/root/tempreadme
526 530
         restore_directory_from_friend $temp_restore_dir readme
527
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
528
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README /home/$ADMIN_USERNAME/
531
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
532
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/README" "/home/$ADMIN_USERNAME/"
529 533
         else
530
-            cp -f $temp_restore_dir/README /home/$ADMIN_USERNAME/README
534
+            cp -f "$temp_restore_dir/README" "/home/$ADMIN_USERNAME/README"
531 535
         fi
536
+        # shellcheck disable=SC2181
532 537
         if [ ! "$?" = "0" ]; then
533 538
             rm -rf $temp_restore_dir
534 539
             exit 276
@@ -546,21 +551,22 @@ function restore_ssh_keys {
546 551
     for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
547 552
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
548 553
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
549
-            if [ -d $SERVER_DIRECTORY/backup/ssh/$USERNAME ]; then
550
-                if [ ! -d /home/$USERNAME ]; then
551
-                    ${PROJECT_NAME}-adduser $USERNAME
554
+            if [ -d "$SERVER_DIRECTORY/backup/ssh/$USERNAME" ]; then
555
+                if [ ! -d "/home/$USERNAME" ]; then
556
+                    ${PROJECT_NAME}-adduser "$USERNAME"
552 557
                 fi
553 558
                 echo $"Restoring ssh keys for $USERNAME"
554 559
                 temp_restore_dir=/root/tempssh
555
-                restore_directory_from_friend $temp_restore_dir ssh/$USERNAME
556
-                if [ -d $temp_restore_dir/home/$USERNAME/.ssh ]; then
557
-                    cp -r $temp_restore_dir/home/$USERNAME/.ssh /home/$USERNAME/
560
+                restore_directory_from_friend $temp_restore_dir "ssh/$USERNAME"
561
+                if [ -d "$temp_restore_dir/home/$USERNAME/.ssh" ]; then
562
+                    cp -r "$temp_restore_dir/home/$USERNAME/.ssh" "/home/$USERNAME/"
558 563
                 else
559
-                    if [ ! -d /home/$USERNAME/.ssh ]; then
560
-                        mkdir /home/$USERNAME/.ssh
564
+                    if [ ! -d "/home/$USERNAME/.ssh" ]; then
565
+                        mkdir "/home/$USERNAME/.ssh"
561 566
                     fi
562
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.ssh/
567
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.ssh/"
563 568
                 fi
569
+                # shellcheck disable=SC2181
564 570
                 if [ ! "$?" = "0" ]; then
565 571
                     rm -rf $temp_restore_dir
566 572
                     exit 664
@@ -580,21 +586,22 @@ function restore_user_config {
580 586
     for d in $SERVER_DIRECTORY/backup/config/*/ ; do
581 587
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
582 588
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
583
-            if [ -d $SERVER_DIRECTORY/backup/config/$USERNAME ]; then
584
-                if [ ! -d /home/$USERNAME ]; then
585
-                    ${PROJECT_NAME}-adduser $USERNAME
589
+            if [ -d "$SERVER_DIRECTORY/backup/config/$USERNAME" ]; then
590
+                if [ ! -d "/home/$USERNAME" ]; then
591
+                    ${PROJECT_NAME}-adduser "$USERNAME"
586 592
                 fi
587 593
                 echo $"Restoring config files for $USERNAME"
588 594
                 temp_restore_dir=/root/tempconfig
589
-                restore_directory_from_friend $temp_restore_dir config/$USERNAME
590
-                if [ -d $temp_restore_dir/home/$USERNAME ]; then
591
-                    cp -r $temp_restore_dir/home/$USERNAME/.config /home/$USERNAME/
595
+                restore_directory_from_friend $temp_restore_dir "config/$USERNAME"
596
+                if [ -d "$temp_restore_dir/home/$USERNAME" ]; then
597
+                    cp -r "$temp_restore_dir/home/$USERNAME/.config" "/home/$USERNAME/"
592 598
                 else
593
-                    if [ ! -d /home/$USERNAME/.config ]; then
594
-                        mkdir /home/$USERNAME/.config
599
+                    if [ ! -d "/home/$USERNAME/.config" ]; then
600
+                        mkdir "/home/$USERNAME/.config"
595 601
                     fi
596
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.config/
602
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.config/"
597 603
                 fi
604
+                # shellcheck disable=SC2181
598 605
                 if [ ! "$?" = "0" ]; then
599 606
                     rm -rf $temp_restore_dir
600 607
                     exit 664
@@ -614,21 +621,22 @@ function restore_user_monkeysphere {
614 621
     for d in $SERVER_DIRECTORY/backup/monkeysphere/*/ ; do
615 622
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
616 623
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
617
-            if [ -d $SERVER_DIRECTORY/backup/monkeysphere/$USERNAME ]; then
618
-                if [ ! -d /home/$USERNAME ]; then
619
-                    ${PROJECT_NAME}-adduser $USERNAME
624
+            if [ -d "$SERVER_DIRECTORY/backup/monkeysphere/$USERNAME" ]; then
625
+                if [ ! -d "/home/$USERNAME" ]; then
626
+                    ${PROJECT_NAME}-adduser "$USERNAME"
620 627
                 fi
621 628
                 echo $"Restoring monkeysphere ids for $USERNAME"
622 629
                 temp_restore_dir=/root/tempmonkeysphere
623
-                restore_directory_from_friend $temp_restore_dir monkeysphere/$USERNAME
624
-                if [ -d $temp_restore_dir/home/$USERNAME/.monkeysphere ]; then
625
-                    cp -r $temp_restore_dir/home/$USERNAME/.monkeysphere /home/$USERNAME/
630
+                restore_directory_from_friend $temp_restore_dir "monkeysphere/$USERNAME"
631
+                if [ -d "$temp_restore_dir/home/$USERNAME/.monkeysphere" ]; then
632
+                    cp -r "$temp_restore_dir/home/$USERNAME/.monkeysphere" "/home/$USERNAME/"
626 633
                 else
627
-                    if [ ! -d /home/$USERNAME/.monkeysphere ]; then
628
-                        mkdir /home/$USERNAME/.monkeysphere
634
+                    if [ ! -d "/home/$USERNAME/.monkeysphere" ]; then
635
+                        mkdir "/home/$USERNAME/.monkeysphere"
629 636
                     fi
630
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.monkeysphere/
637
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.monkeysphere/"
631 638
                 fi
639
+                # shellcheck disable=SC2181
632 640
                 if [ ! "$?" = "0" ]; then
633 641
                     rm -rf $temp_restore_dir
634 642
                     exit 664
@@ -641,8 +649,8 @@ function restore_user_monkeysphere {
641 649
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
642 650
         read_config_param MY_EMAIL_ADDRESS
643 651
         MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
644
-        fpr=$(gpg --with-colons --fingerprint $MY_GPG_PUBLIC_KEY_ID | grep fpr | head -n 1 | awk -F ':' '{print $10}')
645
-        monkeysphere-authentication add-identity-certifier $fpr
652
+        fpr=$(gpg --with-colons --fingerprint "$MY_GPG_PUBLIC_KEY_ID" | grep fpr | head -n 1 | awk -F ':' '{print $10}')
653
+        monkeysphere-authentication add-identity-certifier "$fpr"
646 654
         monkeysphere-authentication update-users
647 655
     done
648 656
 }
@@ -656,21 +664,22 @@ function restore_user_fin {
656 664
     for d in $SERVER_DIRECTORY/backup/fin/*/ ; do
657 665
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
658 666
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
659
-            if [ -d $SERVER_DIRECTORY/backup/fin/$USERNAME ]; then
660
-                if [ ! -d /home/$USERNAME ]; then
661
-                    ${PROJECT_NAME}-adduser $USERNAME
667
+            if [ -d "$SERVER_DIRECTORY/backup/fin/$USERNAME" ]; then
668
+                if [ ! -d "/home/$USERNAME" ]; then
669
+                    ${PROJECT_NAME}-adduser "$USERNAME"
662 670
                 fi
663 671
                 echo $"Restoring fin files for $USERNAME"
664 672
                 temp_restore_dir=/root/tempfin
665
-                restore_directory_from_friend $temp_restore_dir fin/$USERNAME
666
-                if [ -d $temp_restore_dir/home/$USERNAME/.fin ]; then
667
-                    cp -r $temp_restore_dir/home/$USERNAME/.fin /home/$USERNAME/
673
+                restore_directory_from_friend $temp_restore_dir "fin/$USERNAME"
674
+                if [ -d "$temp_restore_dir/home/$USERNAME/.fin" ]; then
675
+                    cp -r "$temp_restore_dir/home/$USERNAME/.fin" "/home/$USERNAME/"
668 676
                 else
669
-                    if [ ! -d /home/$USERNAME/.fin ]; then
670
-                        mkdir /home/$USERNAME/.fin
677
+                    if [ ! -d "/home/$USERNAME/.fin" ]; then
678
+                        mkdir "/home/$USERNAME/.fin"
671 679
                     fi
672
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.fin/
680
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.fin/"
673 681
                 fi
682
+                # shellcheck disable=SC2181
674 683
                 if [ ! "$?" = "0" ]; then
675 684
                     rm -rf $temp_restore_dir
676 685
                     exit 664
@@ -690,21 +699,22 @@ function restore_user_local {
690 699
     for d in $SERVER_DIRECTORY/backup/local/*/ ; do
691 700
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
692 701
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
693
-            if [ -d $SERVER_DIRECTORY/backup/local/$USERNAME ]; then
694
-                if [ ! -d /home/$USERNAME ]; then
695
-                    ${PROJECT_NAME}-adduser $USERNAME
702
+            if [ -d "$SERVER_DIRECTORY/backup/local/$USERNAME" ]; then
703
+                if [ ! -d "/home/$USERNAME" ]; then
704
+                    ${PROJECT_NAME}-adduser "$USERNAME"
696 705
                 fi
697 706
                 echo $"Restoring local files for $USERNAME"
698 707
                 temp_restore_dir=/root/templocal
699
-                restore_directory_from_friend $temp_restore_dir local/$USERNAME
700
-                if [ -d $temp_restore_dir/home/$USERNAME/.local ]; then
701
-                    cp -r $temp_restore_dir/home/$USERNAME/.local /home/$USERNAME/
708
+                restore_directory_from_friend $temp_restore_dir "local/$USERNAME"
709
+                if [ -d "$temp_restore_dir/home/$USERNAME/.local" ]; then
710
+                    cp -r "$temp_restore_dir/home/$USERNAME/.local" "/home/$USERNAME/"
702 711
                 else
703
-                    if [ ! -d /home/$USERNAME/.local ]; then
704
-                        mkdir /home/$USERNAME/.local
712
+                    if [ ! -d "/home/$USERNAME/.local" ]; then
713
+                        mkdir "/home/$USERNAME/.local"
705 714
                     fi
706
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.local/
715
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.local/"
707 716
                 fi
717
+                # shellcheck disable=SC2181
708 718
                 if [ ! "$?" = "0" ]; then
709 719
                     rm -rf $temp_restore_dir
710 720
                     exit 664
@@ -729,6 +739,7 @@ function restore_certs {
729 739
         else
730 740
             cp -r /root/tempssl/* /etc/ssl/
731 741
         fi
742
+        # shellcheck disable=SC2181
732 743
         if [ ! "$?" = "0" ]; then
733 744
             exit 276
734 745
         fi
@@ -770,24 +781,25 @@ function restore_personal_settings {
770 781
     for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
771 782
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
772 783
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
773
-            if [ -d $SERVER_DIRECTORY/backup/personal/$USERNAME ]; then
774
-                if [ ! -d /home/$USERNAME ]; then
775
-                    ${PROJECT_NAME}-adduser $USERNAME
784
+            if [ -d "$SERVER_DIRECTORY/backup/personal/$USERNAME" ]; then
785
+                if [ ! -d "/home/$USERNAME" ]; then
786
+                    ${PROJECT_NAME}-adduser "$USERNAME"
776 787
                 fi
777 788
                 echo $"Restoring personal settings for $USERNAME"
778 789
                 temp_restore_dir=/root/temppersonal
779
-                restore_directory_from_friend $temp_restore_dir personal/$USERNAME
780
-                if [ -d $temp_restore_dir/home/$USERNAME/personal ]; then
781
-                    if [ -d /home/$USERNAME/personal ]; then
782
-                        rm -rf /home/$USERNAME/personal
790
+                restore_directory_from_friend $temp_restore_dir "personal/$USERNAME"
791
+                if [ -d "$temp_restore_dir/home/$USERNAME/personal" ]; then
792
+                    if [ -d "/home/$USERNAME/personal" ]; then
793
+                        rm -rf "/home/$USERNAME/personal"
783 794
                     fi
784
-                    mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME
795
+                    mv "$temp_restore_dir/home/$USERNAME/personal" "/home/$USERNAME"
785 796
                 else
786
-                    if [ ! -d /home/$USERNAME/personal ]; then
787
-                        mkdir /home/$USERNAME/personal
797
+                    if [ ! -d "/home/$USERNAME/personal" ]; then
798
+                        mkdir "/home/$USERNAME/personal"
788 799
                     fi
789
-                    cp -r $temp_restore_dir/* /home/$USERNAME/personal/
800
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/personal/"
790 801
                 fi
802
+                # shellcheck disable=SC2181
791 803
                 if [ ! "$?" = "0" ]; then
792 804
                     exit 18437643
793 805
                 fi
@@ -812,6 +824,7 @@ function restore_mailing_list {
812 824
         else
813 825
             cp -r $temp_restore_dir/* /var/spool/mlmmj/
814 826
         fi
827
+        # shellcheck disable=SC2181
815 828
         if [ ! "$?" = "0" ]; then
816 829
             exit 526
817 830
         fi
@@ -828,21 +841,22 @@ function restore_email {
828 841
     for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
829 842
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
830 843
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
831
-            if [ -d $SERVER_DIRECTORY/backup/mail/$USERNAME ]; then
832
-                if [ ! -d /home/$USERNAME ]; then
833
-                    ${PROJECT_NAME}-adduser $USERNAME
844
+            if [ -d "$SERVER_DIRECTORY/backup/mail/$USERNAME" ]; then
845
+                if [ ! -d "/home/$USERNAME" ]; then
846
+                    ${PROJECT_NAME}-adduser "$USERNAME"
834 847
                 fi
835 848
                 echo $"Restoring emails for $USERNAME"
836 849
                 temp_restore_dir=/root/tempmail
837
-                restore_directory_from_friend $temp_restore_dir mail/$USERNAME
838
-                if [ ! -d /home/$USERNAME/Maildir ]; then
839
-                    mkdir /home/$USERNAME/Maildir
850
+                restore_directory_from_friend $temp_restore_dir "mail/$USERNAME"
851
+                if [ ! -d "/home/$USERNAME/Maildir" ]; then
852
+                    mkdir "/home/$USERNAME/Maildir"
840 853
                 fi
841
-                if [ -d $temp_restore_dir/root/tempbackupemail/$USERNAME ]; then
842
-                    tar -xzvf $temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz -C /
854
+                if [ -d "$temp_restore_dir/root/tempbackupemail/$USERNAME" ]; then
855
+                    tar -xzvf "$temp_restore_dir/root/tempbackupemail/$USERNAME/maildir.tar.gz" -C /
843 856
                 else
844 857
                     tar -xzvf $temp_restore_dir/maildir.tar.gz -C /
845 858
                 fi
859
+                # shellcheck disable=SC2181
846 860
                 if [ ! "$?" = "0" ]; then
847 861
                     exit 927
848 862
                 fi
@@ -854,7 +868,7 @@ function restore_email {
854 868
 
855 869
 # Social key management
856 870
 # Recover any key fragments and reconstruct the gpg key
857
-${PROJECT_NAME}-recoverkey -u ${ADMIN_USERNAME} -l $BACKUP_LIST
871
+${PROJECT_NAME}-recoverkey -u "${ADMIN_USERNAME}" -l "$BACKUP_LIST"
858 872
 
859 873
 copy_gpg_keys
860 874
 gpg_agent_setup root

+ 3
- 3
src/freedombone-rmemail Просмотреть файл

@@ -70,11 +70,11 @@ if ! [[ $MYUSERNAME && $EMAILADDRESS ]]; then
70 70
     show_help
71 71
 fi
72 72
 
73
-MUTTRC=/home/$MYUSERNAME/.muttrc
73
+MUTTRC="/home/$MYUSERNAME/.muttrc"
74 74
 PM=/home/$MYUSERNAME/.procmailrc
75 75
 
76
-if grep -q "Email rule for $EMAILADDRESS ->" $PM; then
77
-    sed -i "/# Email rule for $EMAILADDRESS ->.*/,/# End of rule/d" $PM
76
+if grep -q "Email rule for $EMAILADDRESS ->" "$PM"; then
77
+    sed -i "/# Email rule for $EMAILADDRESS ->.*/,/# End of rule/d" "$PM"
78 78
 fi
79 79
 
80 80
 exit 0

+ 6
- 6
src/freedombone-rmlist Просмотреть файл

@@ -77,15 +77,15 @@ if ! [[ $MYUSERNAME && $MAILINGLIST ]]; then
77 77
 fi
78 78
 
79 79
 MUTTRC=/home/$MYUSERNAME/.muttrc
80
-MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
80
+MUTT_MAILBOXES=$(grep "mailboxes =" "$MUTTRC")
81 81
 if [[ $MUTT_MAILBOXES == *$MAILINGLIST* ]]; then
82
-    sed -i "s| =$MAILINGLIST||g" $MUTTRC
83
-    chown $MYUSERNAME:$MYUSERNAME $MUTTRC
82
+    sed -i "s| =$MAILINGLIST||g" "$MUTTRC"
83
+    chown "$MYUSERNAME":"$MYUSERNAME" "$MUTTRC"
84 84
 fi
85 85
 
86
-if [ $LIST_ADDRESS ]; then
87
-    if ! grep -q "unsubscribe $LIST_ADDRESS" $MUTTRC; then
88
-        sed -i "s|subscribe $LIST_ADDRESS|unsubscribe $LIST_ADDRESS|g" $MUTTRC
86
+if [ "$LIST_ADDRESS" ]; then
87
+    if ! grep -q "unsubscribe $LIST_ADDRESS" "$MUTTRC"; then
88
+        sed -i "s|subscribe $LIST_ADDRESS|unsubscribe $LIST_ADDRESS|g" "$MUTTRC"
89 89
     fi
90 90
 fi
91 91
 

+ 25
- 25
src/freedombone-rmuser Просмотреть файл

@@ -36,16 +36,16 @@ export TEXTDOMAINDIR="/usr/share/locale"
36 36
 
37 37
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
38 38
 
39
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
39
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
40 40
 for f in $UTILS_FILES
41 41
 do
42
-    source $f
42
+    source "$f"
43 43
 done
44 44
 
45
-APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
45
+APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
46 46
 for f in $APP_FILES
47 47
 do
48
-    source $f
48
+    source "$f"
49 49
 done
50 50
 
51 51
 read_config_param MY_USERNAME
@@ -53,7 +53,7 @@ read_config_param MY_USERNAME
53 53
 REMOVE_USERNAME=$1
54 54
 REMOVE_OPTIONS="$2"
55 55
 
56
-if [ ! $REMOVE_USERNAME ]; then
56
+if [ ! "$REMOVE_USERNAME" ]; then
57 57
     echo $'Please specify a username to remove'
58 58
     exit 1
59 59
 fi
@@ -68,35 +68,35 @@ if [[ $(is_valid_user "$REMOVE_USERNAME") == "0" ]]; then
68 68
     exit 3
69 69
 fi
70 70
 
71
-if [ ! -d /home/$REMOVE_USERNAME ]; then
71
+if [ ! -d "/home/$REMOVE_USERNAME" ]; then
72 72
     echo $"Home directory does not exist for $REMOVE_USERNAME"
73 73
     exit 4
74 74
 fi
75 75
 
76
-if [ ! -f $COMPLETION_FILE ]; then
76
+if [ ! -f "$COMPLETION_FILE" ]; then
77 77
     echo $"$COMPLETION_FILE not found"
78 78
     exit 5
79 79
 fi
80 80
 
81
-if ! grep -q "Admin user" $COMPLETION_FILE; then
81
+if ! grep -q "Admin user" "$COMPLETION_FILE"; then
82 82
     echo $"No admin user specified in $COMPLETION_FILE"
83 83
     exit 6
84 84
 fi
85 85
 
86 86
 ADMIN_USERNAME=$(get_completion_param "Admin user")
87
-if [ ! $ADMIN_USERNAME ]; then
87
+if [ ! "$ADMIN_USERNAME" ]; then
88 88
     echo $"No admin username specified in $COMPLETION_FILE"
89 89
     exit 7
90 90
 fi
91 91
 
92
-if [[ $REMOVE_USERNAME == $ADMIN_USERNAME ]]; then
92
+if [[ "$REMOVE_USERNAME" == "$ADMIN_USERNAME" ]]; then
93 93
     echo $"The administrator user cannot be removed"
94 94
     exit 8
95 95
 fi
96 96
 
97 97
 if [[ "$REMOVE_OPTIONS" != '-f' && "$REMOVE_OPTIONS" != '-y' && "$REMOVE_OPTIONS" != '--force' ]]; then
98 98
     echo $'>>> REMOVE USER <<<'
99
-    read -p $"Do you really wish to remove the user '$REMOVE_USERNAME' (y/n) ?" yn
99
+    read -r -p $"Do you really wish to remove the user '$REMOVE_USERNAME' (y/n) ?" yn
100 100
     if [[ $yn != 'y' && $yn != 'Y' && $yn != 'yes' && $yn != 'Yes' && $yn != 'YES' ]]; then
101 101
         echo $"User $REMOVE_USERNAME was not removed"
102 102
         exit 9
@@ -107,18 +107,18 @@ fi
107 107
 
108 108
 if [ -f /etc/nginx/.htpasswd ]; then
109 109
     if grep -q "${REMOVE_USERNAME}:" /etc/nginx/.htpasswd; then
110
-        htpasswd -D /etc/nginx/.htpasswd $REMOVE_USERNAME
110
+        htpasswd -D /etc/nginx/.htpasswd "$REMOVE_USERNAME"
111 111
     fi
112 112
 fi
113 113
 
114 114
 # remove gpg keys
115
-if [ -d /home/$REMOVE_USERNAME/.gnupg ]; then
116
-    shred -zu /home/$REMOVE_USERNAME/.gnupg/*
115
+if [ -d "/home/$REMOVE_USERNAME/.gnupg" ]; then
116
+    shred -zu "/home/$REMOVE_USERNAME/.gnupg/*"
117 117
 fi
118 118
 
119 119
 # remove ssh keys
120
-if [ -d /home/$REMOVE_USERNAME/.ssh ]; then
121
-    shred -zu /home/$REMOVE_USERNAME/.ssh/*
120
+if [ -d "/home/$REMOVE_USERNAME/.ssh" ]; then
121
+    shred -zu "/home/$REMOVE_USERNAME/.ssh/*"
122 122
 fi
123 123
 
124 124
 echo $'Detecting installed apps...'
@@ -126,25 +126,25 @@ detect_apps
126 126
 get_apps_installed_names
127 127
 for app_name in "${APPS_INSTALLED_NAMES[@]}"
128 128
 do
129
-    if [[ $(function_exists remove_user_${app_name}) == "1" ]]; then
129
+    if [[ $(function_exists "remove_user_${app_name}") == "1" ]]; then
130 130
         echo $"Removing user from ${app_name}"
131
-        app_load_variables ${app_name}
132
-        remove_user_${app_name} "$REMOVE_USERNAME"
133
-        if grep -q "${app_name}_${REMOVE_USERNAME}" $APP_USERS_FILE; then
134
-            sed -i "/${app_name}_${REMOVE_USERNAME}/d" $APP_USERS_FILE
131
+        app_load_variables "${app_name}"
132
+        "remove_user_${app_name}" "$REMOVE_USERNAME"
133
+        if grep -q "${app_name}_${REMOVE_USERNAME}" "$APP_USERS_FILE"; then
134
+            sed -i "/${app_name}_${REMOVE_USERNAME}/d" "$APP_USERS_FILE"
135 135
         fi
136 136
     fi
137 137
 done
138 138
 
139 139
 chmod 600 /etc/shadow
140 140
 chmod 600 /etc/gshadow
141
-userdel -r $REMOVE_USERNAME
142
-groupdel $REMOVE_USERNAME
141
+userdel -r "$REMOVE_USERNAME"
142
+groupdel "$REMOVE_USERNAME"
143 143
 chmod 0000 /etc/shadow
144 144
 chmod 0000 /etc/gshadow
145 145
 
146
-if [ -d /home/$REMOVE_USERNAME ]; then
147
-    rm -rf /home/$REMOVE_USERNAME
146
+if [ -d "/home/$REMOVE_USERNAME" ]; then
147
+    rm -rf "/home/${REMOVE_USERNAME:?}"
148 148
 fi
149 149
 
150 150
 echo $"User $REMOVE_USERNAME was removed"

+ 227
- 206
src/freedombone-sec
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 44
- 46
src/freedombone-splitkey Просмотреть файл

@@ -90,37 +90,37 @@ esac
90 90
 shift
91 91
 done
92 92
 
93
-if [ ! $MY_USERNAME ]; then
93
+if [ ! "$MY_USERNAME" ]; then
94 94
     show_help
95 95
 fi
96
-if [ ! -d /home/$MY_USERNAME ]; then
96
+if [ ! -d "/home/$MY_USERNAME" ]; then
97 97
     echo $"User $MY_USERNAME does not exist on the system"
98 98
     exit 7270
99 99
 fi
100 100
 
101
-if [ ! -d /home/$MY_USERNAME/.gnupg ]; then
101
+if [ ! -d "/home/$MY_USERNAME/.gnupg" ]; then
102 102
     echo $'No gpg key found'
103 103
     exit 5393
104 104
 fi
105 105
 
106
-if [ $PASSWORD_FILE ]; then
107
-    if [ ! -f $PASSWORD_FILE ]; then
106
+if [ "$PASSWORD_FILE" ]; then
107
+    if [ ! -f "$PASSWORD_FILE" ]; then
108 108
         echo $'Password file not found'
109 109
         exit 62952
110 110
     fi
111 111
 fi
112 112
 
113 113
 FRAGMENTS_DIR=/home/$MY_USERNAME/.gnupg_fragments
114
-if [ -d $FRAGMENTS_DIR ]; then
114
+if [ -d "$FRAGMENTS_DIR" ]; then
115 115
     exit 0
116 116
 fi
117 117
 
118 118
 # get the gpg key ID
119
-if [ ! $MY_EMAIL_ADDRESS ]; then
119
+if [ ! "$MY_EMAIL_ADDRESS" ]; then
120 120
     MY_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
121 121
 fi
122 122
 
123
-KEYID=$(su -c "gpg --list-keys $MY_EMAIL_ADDRESS" - $MY_USERNAME | sed -n '2p' | sed 's/^[ \t]*//')
123
+KEYID=$(su -c "gpg --list-keys $MY_EMAIL_ADDRESS" - "$MY_USERNAME" | sed -n '2p' | sed 's/^[ \t]*//')
124 124
 if [ ${#KEYID} -lt 4 ]; then
125 125
     echo $"gpg key for $MY_EMAIL_ADDRESS was not found"
126 126
     exit 3682
@@ -133,72 +133,70 @@ if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then
133 133
 fi
134 134
 
135 135
 # create the key file
136
-mkdir -p $FRAGMENTS_DIR
137
-chown $MY_USERNAME:$MY_USERNAME $FRAGMENTS_DIR
138
-KEYS_FILE=$FRAGMENTS_DIR/keyshare.asc
139
-gpg --output $FRAGMENTS_DIR/pubkey.txt --armor --export $KEYID
140
-if [ ! "$?" = "0" ]; then
136
+mkdir -p "$FRAGMENTS_DIR"
137
+chown "$MY_USERNAME":"$MY_USERNAME" "$FRAGMENTS_DIR"
138
+KEYS_FILE="$FRAGMENTS_DIR/keyshare.asc"
139
+if ! gpg --output "$FRAGMENTS_DIR/pubkey.txt" --armor --export "$KEYID"; then
141 140
     echo $"Unable to extract public key for $KEYID"
142 141
     exit 7835
143 142
 fi
144
-if [ ! $PASSWORD_FILE ]; then
145
-    gpg --output $FRAGMENTS_DIR/privkey.txt \
146
-        --armor --export-secret-key $KEYID
143
+if [ ! "$PASSWORD_FILE" ]; then
144
+    gpg --output "$FRAGMENTS_DIR/privkey.txt" \
145
+        --armor --export-secret-key "$KEYID"
147 146
 else
148
-    echo "$(printf `cat $PASSWORD_FILE`)" | \
147
+    # shellcheck disable=SC2005
148
+    echo "$(printf "%s" "$(cat "$PASSWORD_FILE")")" | \
149 149
         gpg --batch --passphrase-fd 0 \
150
-        --output $FRAGMENTS_DIR/privkey.txt \
151
-        --armor --export-secret-key $KEYID
150
+        --output "$FRAGMENTS_DIR/privkey.txt" \
151
+        --armor --export-secret-key "$KEYID"
152 152
 fi
153
+# shellcheck disable=SC2181
153 154
 if [ ! "$?" = "0" ]; then
154 155
     echo $"Unable to extract private key for $KEYID"
155 156
     exit 7823
156 157
 fi
157
-gpg --output $FRAGMENTS_DIR/backup_pubkey.txt \
158
-    --armor --export $MY_BACKUP_KEY_ID
159
-if [ ! "$?" = "0" ]; then
160
-    shred -zu $FRAGMENTS_DIR/privkey.txt
158
+if ! gpg --output "$FRAGMENTS_DIR/backup_pubkey.txt" \
159
+    --armor --export "$MY_BACKUP_KEY_ID"; then
160
+    shred -zu "$FRAGMENTS_DIR/privkey.txt"
161 161
     echo $"Unable to extract backup public key for $MY_BACKUP_KEY_ID"
162 162
     exit 62928
163 163
 fi
164 164
 echo "$BACKUP_DUMMY_PASSWORD" | \
165
-    gpg --output $FRAGMENTS_DIR/backup_privkey.txt \
165
+if ! gpg --output "$FRAGMENTS_DIR/backup_privkey.txt" \
166 166
         --batch --passphrase-fd 0 \
167
-        --armor --export-secret-key $MY_BACKUP_KEY_ID
168
-if [ ! "$?" = "0" ]; then
169
-    shred -zu $FRAGMENTS_DIR/privkey.txt
167
+        --armor --export-secret-key "$MY_BACKUP_KEY_ID"; then
168
+    shred -zu "$FRAGMENTS_DIR/privkey.txt"
170 169
     echo $"Unable to extract backup private key for $MY_BACKUP_KEY_ID"
171 170
     exit 13783
172 171
 fi
173 172
 
174 173
 # Ensure there aren't any permissions problems when running cat
175
-chmod +r $FRAGMENTS_DIR/privkey.txt
176
-chmod +r $FRAGMENTS_DIR/backup_privkey.txt
177
-
178
-cat $FRAGMENTS_DIR/pubkey.txt \
179
-    $FRAGMENTS_DIR/privkey.txt \
180
-    $FRAGMENTS_DIR/backup_pubkey.txt \
181
-    $FRAGMENTS_DIR/backup_privkey.txt > $KEYS_FILE
182
-shred -zu $FRAGMENTS_DIR/privkey.txt
183
-shred -zu $FRAGMENTS_DIR/pubkey.txt
184
-shred -zu $FRAGMENTS_DIR/backup_privkey.txt
185
-shred -zu $FRAGMENTS_DIR/backup_pubkey.txt
174
+chmod +r "$FRAGMENTS_DIR/privkey.txt"
175
+chmod +r "$FRAGMENTS_DIR/backup_privkey.txt"
176
+
177
+cat "$FRAGMENTS_DIR/pubkey.txt" \
178
+    "$FRAGMENTS_DIR/privkey.txt" \
179
+    "$FRAGMENTS_DIR/backup_pubkey.txt" \
180
+    "$FRAGMENTS_DIR/backup_privkey.txt" > "$KEYS_FILE"
181
+shred -zu "$FRAGMENTS_DIR/privkey.txt"
182
+shred -zu "$FRAGMENTS_DIR/pubkey.txt"
183
+shred -zu "$FRAGMENTS_DIR/backup_privkey.txt"
184
+shred -zu "$FRAGMENTS_DIR/backup_pubkey.txt"
186 185
 
187 186
 KEY_SHARES=$((KEY_FRAGMENTS * 2))
188
-gfsplit -n $KEY_FRAGMENTS -m $KEY_SHARES $KEYS_FILE
189
-if [ ! "$?" = "0" ]; then
187
+if ! gfsplit -n "$KEY_FRAGMENTS" -m "$KEY_SHARES $KEYS_FILE"; then
190 188
     echo $"Unable to split the gpg key"
191
-    rm -rf $FRAGMENTS_DIR
192
-    if [ -f $KEYS_FILE ]; then
193
-        shred -zu $KEYS_FILE
189
+    rm -rf "$FRAGMENTS_DIR"
190
+    if [ -f "$KEYS_FILE" ]; then
191
+        shred -zu "$KEYS_FILE"
194 192
     fi
195 193
     exit 63028
196 194
 fi
197
-shred -zu $KEYS_FILE
195
+shred -zu "$KEYS_FILE"
198 196
 
199 197
 # set permissions
200
-chown -R $MY_USERNAME:$MY_USERNAME $FRAGMENTS_DIR
201
-chmod -R 600 $FRAGMENTS_DIR
198
+chown -R "$MY_USERNAME":"$MY_USERNAME" "$FRAGMENTS_DIR"
199
+chmod -R 600 "$FRAGMENTS_DIR"
202 200
 
203 201
 echo $"$KEY_SHARES key shares created"
204 202
 

+ 93
- 93
src/freedombone-syncthing Просмотреть файл

@@ -36,10 +36,10 @@ PROJECT_NAME='freedombone'
36 36
 export TEXTDOMAIN=$PROJECT_NAME-syncthing
37 37
 export TEXTDOMAINDIR="/usr/share/locale"
38 38
 
39
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
39
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
40 40
 for f in $UTILS_FILES
41 41
 do
42
-  source $f
42
+    source "$f"
43 43
 done
44 44
 
45 45
 # File which keeps track of what has already been installed
@@ -68,13 +68,14 @@ function new_syncthing_id {
68 68
     for i in {1..8}
69 69
     do
70 70
         v=""
71
+        # shellcheck disable=SC2034
71 72
         for j in {1..2}
72 73
         do
73
-            v2=`echo "obase=16;$RANDOM" | bc`
74
+            v2=$(echo "obase=16;$RANDOM" | bc)
74 75
             v=$v$v2
75 76
         done
76 77
         v=$(echo "$v" | cut -c1-7)
77
-        if [[ ${i} < 8 ]]; then
78
+        if [ "${i}" -lt 8 ]; then
78 79
             v=$v"-"
79 80
         fi
80 81
         echo -n "$v"
@@ -83,11 +84,11 @@ function new_syncthing_id {
83 84
 }
84 85
 
85 86
 function create_syncthing_config {
86
-    if grep -q "syncthing ID" $COMPLETION_FILE; then
87
+    if grep -q "syncthing ID" "$COMPLETION_FILE"; then
87 88
         SYNCTHING_ID=$(get_completion_param "syncthing ID")
88 89
     else
89 90
         if [ -f $SYNCTHING_CONFIG_FILE ]; then
90
-            SYNCTHING_ID=$(cat $SYNCTHING_CONFIG_FILE | grep "device id=" | head -n 1 | awk -F '"' '{print $2}')
91
+            SYNCTHING_ID=$(grep "device id=" "$SYNCTHING_CONFIG_FILE" | head -n 1 | awk -F '"' '{print $2}')
91 92
         else
92 93
             SYNCTHING_ID=$(new_syncthing_id)
93 94
         fi
@@ -109,7 +110,7 @@ function create_syncthing_config {
109 110
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
110 111
             echo "    <folder id=\"$USERNAME\" path=\"/home/$USERNAME/Sync/\" ro=\"false\" rescanIntervalS=\"60\" ignorePerms=\"false\" autoNormalize=\"true\">" >> $SYNCTHING_CONFIG_FILE
111 112
             # include any specified device IDs for this user
112
-            if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then
113
+            if [ -f "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE" ]; then
113 114
                 echo "" > $TEMP_IDS_FILE
114 115
                 while read -r line || [[ -n "$line" ]]; do
115 116
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
@@ -121,23 +122,23 @@ function create_syncthing_config {
121 122
                             fi
122 123
                         fi
123 124
                     fi
124
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
125
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
125 126
                 rm $TEMP_IDS_FILE
126 127
             fi
127
-            echo "        <device id=\"$SYNCTHING_ID\"></device>" >> $SYNCTHING_CONFIG_FILE
128
-            echo '        <minDiskFreePct>1</minDiskFreePct>' >> $SYNCTHING_CONFIG_FILE
129
-            echo '        <versioning></versioning>' >> $SYNCTHING_CONFIG_FILE
130
-            echo '        <copiers>0</copiers>' >> $SYNCTHING_CONFIG_FILE
131
-            echo '        <pullers>0</pullers>' >> $SYNCTHING_CONFIG_FILE
132
-            echo '        <hashers>0</hashers>' >> $SYNCTHING_CONFIG_FILE
133
-            echo '        <order>random</order>' >> $SYNCTHING_CONFIG_FILE
134
-            echo '        <ignoreDelete>false</ignoreDelete>' >> $SYNCTHING_CONFIG_FILE
135
-            echo '        <scanProgressIntervalS>0</scanProgressIntervalS>' >> $SYNCTHING_CONFIG_FILE
136
-            echo '        <pullerSleepS>0</pullerSleepS>' >> $SYNCTHING_CONFIG_FILE
137
-            echo '        <pullerPauseS>0</pullerPauseS>' >> $SYNCTHING_CONFIG_FILE
138
-            echo '        <maxConflicts>10</maxConflicts>' >> $SYNCTHING_CONFIG_FILE
139
-            echo '        <disableSparseFiles>false</disableSparseFiles>' >> $SYNCTHING_CONFIG_FILE
140
-            echo '    </folder>' >> $SYNCTHING_CONFIG_FILE
128
+            { echo "        <device id=\"$SYNCTHING_ID\"></device>";
129
+              echo '        <minDiskFreePct>1</minDiskFreePct>';
130
+              echo '        <versioning></versioning>';
131
+              echo '        <copiers>0</copiers>';
132
+              echo '        <pullers>0</pullers>';
133
+              echo '        <hashers>0</hashers>';
134
+              echo '        <order>random</order>';
135
+              echo '        <ignoreDelete>false</ignoreDelete>';
136
+              echo '        <scanProgressIntervalS>0</scanProgressIntervalS>';
137
+              echo '        <pullerSleepS>0</pullerSleepS>';
138
+              echo '        <pullerPauseS>0</pullerPauseS>';
139
+              echo '        <maxConflicts>10</maxConflicts>';
140
+              echo '        <disableSparseFiles>false</disableSparseFiles>';
141
+              echo '    </folder>'; } >> "$SYNCTHING_CONFIG_FILE"
141 142
         fi
142 143
     done
143 144
 
@@ -147,7 +148,7 @@ function create_syncthing_config {
147 148
     for d in /home/*/ ; do
148 149
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
149 150
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
150
-            if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then
151
+            if [ -f "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE" ]; then
151 152
                 while read -r line || [[ -n "$line" ]]; do
152 153
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
153 154
                     if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
@@ -158,96 +159,95 @@ function create_syncthing_config {
158 159
                             fi
159 160
                         fi
160 161
                     fi
161
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
162
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
162 163
             fi
163 164
         fi
164 165
     done
165 166
     rm $TEMP_IDS_FILE
166
-    echo "        <device id=\"$SYNCTHING_ID\"></device>" >> $SYNCTHING_CONFIG_FILE
167
-    echo '        <minDiskFreePct>1</minDiskFreePct>' >> $SYNCTHING_CONFIG_FILE
168
-    echo '        <versioning></versioning>' >> $SYNCTHING_CONFIG_FILE
169
-    echo '        <copiers>0</copiers>' >> $SYNCTHING_CONFIG_FILE
170
-    echo '        <pullers>0</pullers>' >> $SYNCTHING_CONFIG_FILE
171
-    echo '        <hashers>0</hashers>' >> $SYNCTHING_CONFIG_FILE
172
-    echo '        <order>random</order>' >> $SYNCTHING_CONFIG_FILE
173
-    echo '        <ignoreDelete>false</ignoreDelete>' >> $SYNCTHING_CONFIG_FILE
174
-    echo '        <scanProgressIntervalS>0</scanProgressIntervalS>' >> $SYNCTHING_CONFIG_FILE
175
-    echo '        <pullerSleepS>0</pullerSleepS>' >> $SYNCTHING_CONFIG_FILE
176
-    echo '        <pullerPauseS>0</pullerPauseS>' >> $SYNCTHING_CONFIG_FILE
177
-    echo '        <maxConflicts>10</maxConflicts>' >> $SYNCTHING_CONFIG_FILE
178
-    echo '        <disableSparseFiles>false</disableSparseFiles>' >> $SYNCTHING_CONFIG_FILE
179
-    echo '    </folder>' >> $SYNCTHING_CONFIG_FILE
167
+    { echo "        <device id=\"$SYNCTHING_ID\"></device>";
168
+      echo '        <minDiskFreePct>1</minDiskFreePct>';
169
+      echo '        <versioning></versioning>';
170
+      echo '        <copiers>0</copiers>';
171
+      echo '        <pullers>0</pullers>';
172
+      echo '        <hashers>0</hashers>';
173
+      echo '        <order>random</order>';
174
+      echo '        <ignoreDelete>false</ignoreDelete>';
175
+      echo '        <scanProgressIntervalS>0</scanProgressIntervalS>';
176
+      echo '        <pullerSleepS>0</pullerSleepS>';
177
+      echo '        <pullerPauseS>0</pullerPauseS>';
178
+      echo '        <maxConflicts>10</maxConflicts>';
179
+      echo '        <disableSparseFiles>false</disableSparseFiles>';
180
+      echo '    </folder>';
180 181
 
181
-
182
-    echo "    <device id=\"$SYNCTHING_ID\" name=\"${PROJECT_NAME}\" compression=\"metadata\" introducer=\"false\">" >> $SYNCTHING_CONFIG_FILE
183
-    echo '        <address>dynamic</address>' >> $SYNCTHING_CONFIG_FILE
184
-    echo '    </device>' >> $SYNCTHING_CONFIG_FILE
182
+      echo "    <device id=\"$SYNCTHING_ID\" name=\"${PROJECT_NAME}\" compression=\"metadata\" introducer=\"false\">";
183
+      echo '        <address>dynamic</address>';
184
+      echo '    </device>'; } >> "$SYNCTHING_CONFIG_FILE"
185 185
 
186 186
     echo "" > $TEMP_IDS_FILE
187 187
     for d in /home/*/ ; do
188 188
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
189 189
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
190
-            if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then
190
+            if [ -f "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE" ]; then
191 191
                 while read -r line || [[ -n "$line" ]]; do
192 192
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
193 193
                     if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
194 194
                         if [ ${#line2} -gt 10 ]; then
195 195
                             if ! grep -q "$line2" $TEMP_IDS_FILE; then
196
-                                echo "    <device id=\"$line2\" name=\"${USERNAME}\" compression=\"metadata\" introducer=\"false\">" >> $SYNCTHING_CONFIG_FILE
196
+                                echo "    <device id=\"$line2\" name=\"${USERNAME}\" compression=\"metadata\" introducer=\"false\">" >> "$SYNCTHING_CONFIG_FILE"
197 197
                                 echo '        <address>dynamic</address>' >> $SYNCTHING_CONFIG_FILE
198 198
                                 echo '    </device>' >> $SYNCTHING_CONFIG_FILE
199 199
                                 echo "$line2" >> $TEMP_IDS_FILE
200 200
                             fi
201 201
                         fi
202 202
                     fi
203
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
203
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
204 204
             fi
205 205
         fi
206 206
     done
207 207
     rm $TEMP_IDS_FILE
208 208
 
209
-    echo '    <options>' >> $SYNCTHING_CONFIG_FILE
210
-    echo "        <listenAddress>tcp://0.0.0.0:$SYNCTHING_PORT</listenAddress>" >> $SYNCTHING_CONFIG_FILE
211
-    echo '        <globalAnnounceServer>default</globalAnnounceServer>' >> $SYNCTHING_CONFIG_FILE
212
-    echo '        <globalAnnounceEnabled>true</globalAnnounceEnabled>' >> $SYNCTHING_CONFIG_FILE
213
-    echo '        <localAnnounceEnabled>true</localAnnounceEnabled>' >> $SYNCTHING_CONFIG_FILE
214
-    echo '        <localAnnouncePort>21027</localAnnouncePort>' >> $SYNCTHING_CONFIG_FILE
215
-    echo '        <localAnnounceMCAddr>[ff12::8384]:21027</localAnnounceMCAddr>' >> $SYNCTHING_CONFIG_FILE
216
-    echo "        <relayServer>dynamic+$SYNCTHING_RELAY_SERVER</relayServer>" >> $SYNCTHING_CONFIG_FILE
217
-    echo '        <maxSendKbps>0</maxSendKbps>' >> $SYNCTHING_CONFIG_FILE
218
-    echo '        <maxRecvKbps>0</maxRecvKbps>' >> $SYNCTHING_CONFIG_FILE
219
-    echo '        <reconnectionIntervalS>60</reconnectionIntervalS>' >> $SYNCTHING_CONFIG_FILE
220
-    echo '        <relaysEnabled>true</relaysEnabled>' >> $SYNCTHING_CONFIG_FILE
221
-    echo '        <relayReconnectIntervalM>10</relayReconnectIntervalM>' >> $SYNCTHING_CONFIG_FILE
222
-    echo '        <startBrowser>true</startBrowser>' >> $SYNCTHING_CONFIG_FILE
223
-    echo '        <upnpEnabled>true</upnpEnabled>' >> $SYNCTHING_CONFIG_FILE
224
-    echo '        <upnpLeaseMinutes>60</upnpLeaseMinutes>' >> $SYNCTHING_CONFIG_FILE
225
-    echo '        <upnpRenewalMinutes>30</upnpRenewalMinutes>' >> $SYNCTHING_CONFIG_FILE
226
-    echo '        <upnpTimeoutSeconds>10</upnpTimeoutSeconds>' >> $SYNCTHING_CONFIG_FILE
227
-    echo '        <urAccepted>-1</urAccepted>' >> $SYNCTHING_CONFIG_FILE
228
-    echo '        <urUniqueID></urUniqueID>' >> $SYNCTHING_CONFIG_FILE
229
-    echo '        <urURL>https://data.syncthing.net/newdata</urURL>' >> $SYNCTHING_CONFIG_FILE
230
-    echo '        <urPostInsecurely>false</urPostInsecurely>' >> $SYNCTHING_CONFIG_FILE
231
-    echo '        <urInitialDelayS>1800</urInitialDelayS>' >> $SYNCTHING_CONFIG_FILE
232
-    echo '        <restartOnWakeup>true</restartOnWakeup>' >> $SYNCTHING_CONFIG_FILE
233
-    echo '        <autoUpgradeIntervalH>12</autoUpgradeIntervalH>' >> $SYNCTHING_CONFIG_FILE
234
-    echo '        <keepTemporariesH>24</keepTemporariesH>' >> $SYNCTHING_CONFIG_FILE
235
-    echo '        <cacheIgnoredFiles>true</cacheIgnoredFiles>' >> $SYNCTHING_CONFIG_FILE
236
-    echo '        <progressUpdateIntervalS>5</progressUpdateIntervalS>' >> $SYNCTHING_CONFIG_FILE
237
-    echo '        <symlinksEnabled>true</symlinksEnabled>' >> $SYNCTHING_CONFIG_FILE
238
-    echo '        <limitBandwidthInLan>false</limitBandwidthInLan>' >> $SYNCTHING_CONFIG_FILE
239
-    echo '        <minHomeDiskFreePct>1</minHomeDiskFreePct>' >> $SYNCTHING_CONFIG_FILE
240
-    echo "        <releasesURL>$SYNCTHING_RELEASES</releasesURL>" >> $SYNCTHING_CONFIG_FILE
241
-    echo '    </options>' >> $SYNCTHING_CONFIG_FILE
242
-    echo '</configuration>' >> $SYNCTHING_CONFIG_FILE
209
+    { echo '    <options>';
210
+      echo "        <listenAddress>tcp://0.0.0.0:$SYNCTHING_PORT</listenAddress>";
211
+      echo '        <globalAnnounceServer>default</globalAnnounceServer>';
212
+      echo '        <globalAnnounceEnabled>true</globalAnnounceEnabled>';
213
+      echo '        <localAnnounceEnabled>true</localAnnounceEnabled>';
214
+      echo '        <localAnnouncePort>21027</localAnnouncePort>';
215
+      echo '        <localAnnounceMCAddr>[ff12::8384]:21027</localAnnounceMCAddr>';
216
+      echo "        <relayServer>dynamic+$SYNCTHING_RELAY_SERVER</relayServer>";
217
+      echo '        <maxSendKbps>0</maxSendKbps>';
218
+      echo '        <maxRecvKbps>0</maxRecvKbps>';
219
+      echo '        <reconnectionIntervalS>60</reconnectionIntervalS>';
220
+      echo '        <relaysEnabled>true</relaysEnabled>';
221
+      echo '        <relayReconnectIntervalM>10</relayReconnectIntervalM>';
222
+      echo '        <startBrowser>true</startBrowser>';
223
+      echo '        <upnpEnabled>true</upnpEnabled>';
224
+      echo '        <upnpLeaseMinutes>60</upnpLeaseMinutes>';
225
+      echo '        <upnpRenewalMinutes>30</upnpRenewalMinutes>';
226
+      echo '        <upnpTimeoutSeconds>10</upnpTimeoutSeconds>';
227
+      echo '        <urAccepted>-1</urAccepted>';
228
+      echo '        <urUniqueID></urUniqueID>';
229
+      echo '        <urURL>https://data.syncthing.net/newdata</urURL>';
230
+      echo '        <urPostInsecurely>false</urPostInsecurely>';
231
+      echo '        <urInitialDelayS>1800</urInitialDelayS>';
232
+      echo '        <restartOnWakeup>true</restartOnWakeup>';
233
+      echo '        <autoUpgradeIntervalH>12</autoUpgradeIntervalH>';
234
+      echo '        <keepTemporariesH>24</keepTemporariesH>';
235
+      echo '        <cacheIgnoredFiles>true</cacheIgnoredFiles>';
236
+      echo '        <progressUpdateIntervalS>5</progressUpdateIntervalS>';
237
+      echo '        <symlinksEnabled>true</symlinksEnabled>';
238
+      echo '        <limitBandwidthInLan>false</limitBandwidthInLan>';
239
+      echo '        <minHomeDiskFreePct>1</minHomeDiskFreePct>';
240
+      echo "        <releasesURL>$SYNCTHING_RELEASES</releasesURL>";
241
+      echo '    </options>';
242
+      echo '</configuration>'; } >> "$SYNCTHING_CONFIG_FILE"
243 243
 
244 244
     # give each user account a file containing the device id for this server
245 245
     # This allows it to appear within the user control panel
246 246
     for d in /home/*/ ; do
247 247
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
248 248
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
249
-            echo "$SYNCTHING_ID" > /home/$USERNAME/.syncthing-server-id
250
-            chown $USERNAME:$USERNAME /home/$USERNAME/.syncthing-server-id
249
+            echo "$SYNCTHING_ID" > "/home/$USERNAME/.syncthing-server-id"
250
+            chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.syncthing-server-id"
251 251
         fi
252 252
     done
253 253
 }
@@ -266,7 +266,7 @@ function user_devices_changed {
266 266
 
267 267
     for d in /home/*/ ; do
268 268
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
269
-        if [ ! -f /home/$USERNAME/.syncthing-server-id ]; then
269
+        if [ ! -f "/home/$USERNAME/.syncthing-server-id" ]; then
270 270
             CHANGED=1
271 271
             return
272 272
         fi
@@ -275,11 +275,11 @@ function user_devices_changed {
275 275
     for d in /home/*/ ; do
276 276
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
277 277
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
278
-            if [ -f /home/$USERNAME/$SYNCTHING_UPDATE_FILE ]; then
278
+            if [ -f "/home/$USERNAME/$SYNCTHING_UPDATE_FILE" ]; then
279 279
                 CHANGED=1
280 280
             fi
281 281
 
282
-            if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then
282
+            if [ -f "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE" ]; then
283 283
                 while read -r line || [[ -n "$line" ]]; do
284 284
                     if [[ $line != *"#"* && $line != *"*"* && $line != *'/'*  && $line == *"-"* ]]; then
285 285
                         if [ ${#line} -gt 10 ]; then
@@ -288,15 +288,15 @@ function user_devices_changed {
288 288
                             fi
289 289
                         fi
290 290
                     fi
291
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
291
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
292 292
             fi
293 293
 
294 294
             # Permissions on user Sync directories
295
-            if [ -d /home/$USERNAME/Sync ]; then
296
-                chown $USERNAME:$USERNAME /home/$USERNAME /home/$USERNAME/Sync
295
+            if [ -d "/home/$USERNAME/Sync" ]; then
296
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME" "/home/$USERNAME/Sync"
297 297
             fi
298
-            if [ -d /home/$USERNAME/SyncShared ]; then
299
-                chown $USERNAME:$USERNAME /home/$USERNAME /home/$USERNAME/SyncShared
298
+            if [ -d "/home/$USERNAME/SyncShared" ]; then
299
+                chown "$USERNAME":"$USERNAME" "/home/$USERNAME" "/home/$USERNAME/SyncShared"
300 300
             fi
301 301
         fi
302 302
     done
@@ -305,11 +305,11 @@ function user_devices_changed {
305 305
 function syncthing_set_permissions {
306 306
     for d in /home/*/ ; do
307 307
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
308
-        if [ -d /home/$USERNAME/Sync ]; then
309
-            chown $USERNAME:$USERNAME /home/$USERNAME /home/$USERNAME/Sync
308
+        if [ -d "/home/$USERNAME/Sync" ]; then
309
+            chown "$USERNAME":"$USERNAME" "/home/$USERNAME" "/home/$USERNAME/Sync"
310 310
         fi
311
-        if [ -d /home/$USERNAME/SyncShared ]; then
312
-            chown $USERNAME:$USERNAME /home/$USERNAME /home/$USERNAME/SyncShared
311
+        if [ -d "/home/$USERNAME/SyncShared" ]; then
312
+            chown "$USERNAME":"$USERNAME" "/home/$USERNAME" "/home/$USERNAME/SyncShared"
313 313
         fi
314 314
     done
315 315
 }

+ 56
- 53
src/freedombone-template Просмотреть файл

@@ -85,9 +85,9 @@ do
85 85
         -a|--app|--appname)
86 86
             shift
87 87
             app_name="$1"
88
-            app_name_lower=$(echo ${app_name} | tr '[:upper:]' '[:lower:]')
88
+            app_name_lower=$(echo "${app_name}" | tr '[:upper:]' '[:lower:]')
89 89
             app_name=$app_name_lower
90
-            app_name_upper=$(echo ${app_name} | tr '[:lower:]' '[:upper:]')
90
+            app_name_upper=$(echo "${app_name}" | tr '[:lower:]' '[:upper:]')
91 91
             ;;
92 92
         -r|--repo)
93 93
             shift
@@ -226,14 +226,14 @@ fi
226 226
 echo ''
227 227
 echo "${app_name_upper}_DOMAIN_NAME="
228 228
 echo "${app_name_upper}_CODE="
229
-if [ $app_port ]; then
229
+if [ "$app_port" ]; then
230 230
     echo "${app_name_upper}_PORT=$app_port"
231 231
 fi
232 232
 echo "${app_name_upper}_ONION_PORT=$(( ( RANDOM % 1000 )  + 9010 ))"
233 233
 echo "${app_name_upper}_REPO=\"${app_repo}\""
234 234
 echo "${app_name_upper}_COMMIT='${app_repo_commit}'"
235 235
 if [ $app_daemon ]; then
236
-    if [ ! $app_port_internal ]; then
236
+    if [ ! "$app_port_internal" ]; then
237 237
         echo "${app_name_upper}_PORT_INTERNAL=TODO"
238 238
     else
239 239
         echo "${app_name_upper}_PORT_INTERNAL=$app_port_internal"
@@ -255,14 +255,14 @@ echo "    echo -n ''"
255 255
 echo '}'
256 256
 echo ''
257 257
 echo "function remove_user_${app_name} {"
258
-echo '    remove_username="$1"'
258
+echo "    remove_username=\"\$1\""
259 259
 echo ''
260 260
 echo "    \${PROJECT_NAME}-pass -u \$remove_username --rmapp ${app_name}"
261 261
 echo '}'
262 262
 echo ''
263 263
 echo "function add_user_${app_name} {"
264
-echo '    new_username="$1"'
265
-echo '    new_user_password="$2"'
264
+echo "    new_username=\"\$1\""
265
+echo "    new_user_password=\"\$2\""
266 266
 echo ''
267 267
 echo "    \${PROJECT_NAME}-pass -u \$new_username -a ${app_name} -p \"\$new_user_password\""
268 268
 echo "    echo '0'"
@@ -270,11 +270,11 @@ echo '}'
270 270
 echo ''
271 271
 echo "function install_interactive_${app_name} {"
272 272
 if [ ! $app_onion_only ]; then
273
-    echo '    if [ ! $ONION_ONLY ]; then'
273
+    echo "    if [ ! \$ONION_ONLY ]; then"
274 274
     echo "        ONION_ONLY='no'"
275 275
     echo '    fi'
276 276
     echo ''
277
-    echo '    if [[ $ONION_ONLY != "no" ]]; then'
277
+    echo "    if [[ \$ONION_ONLY != \"no\" ]]; then"
278 278
     echo "        ${app_name_upper}_DOMAIN_NAME='${app_name}.local'"
279 279
     echo "        write_config_param \"${app_name_upper}_DOMAIN_NAME\" \"\$${app_name_upper}_DOMAIN_NAME\""
280 280
     echo '    else'
@@ -287,8 +287,8 @@ echo '    APP_INSTALLED=1'
287 287
 echo '}'
288 288
 echo ''
289 289
 echo "function change_password_${app_name} {"
290
-echo '    curr_username="$1"'
291
-echo '    new_user_password="$2"'
290
+echo "    curr_username=\"\$1\""
291
+echo "    new_user_password=\"\$2\""
292 292
 echo ''
293 293
 echo "    read_config_param '${app_name_upper}_DOMAIN_NAME'"
294 294
 echo ''
@@ -298,8 +298,8 @@ echo '}'
298 298
 if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" || "$database_type" == "postgres"* ]]; then
299 299
     echo ''
300 300
     echo "function ${app_name}_create_database {"
301
-    echo '    if [ -f $IMAGE_PASSWORD_FILE ]; then'
302
-    echo "        ${app_name_upper}_ADMIN_PASSWORD=\"\$(printf `cat $IMAGE_PASSWORD_FILE`)\""
301
+    echo "    if [ -f \$IMAGE_PASSWORD_FILE ]; then"
302
+    echo "        ${app_name_upper}_ADMIN_PASSWORD=\"\$(printf \"%d\" \"\$(cat \"$IMAGE_PASSWORD_FILE\")\")\""
303 303
     echo '    else'
304 304
     echo "        if [ ! \$${app_name_upper}_ADMIN_PASSWORD ]; then"
305 305
     echo "            ${app_name_upper}_ADMIN_PASSWORD=\"\$(create_password \${MINIMUM_PASSWORD_LENGTH})\""
@@ -329,26 +329,29 @@ echo ''
329 329
 echo "function configure_interactive_${app_name} {"
330 330
 echo '    while true'
331 331
 echo '    do'
332
-echo '        data=$(tempfile 2>/dev/null)'
333
-echo '        trap "rm -f $data" 0 1 2 5 15'
332
+echo "        data=\$(mktemp 2>/dev/null)"
334 333
 echo "        dialog --backtitle \$\"Freedombone Control Panel\" \\"
335 334
 echo "               --title \$\"${app_name}\" \\"
336 335
 echo "               --radiolist \$\"Choose an operation:\" 16 70 3 \\"
337
-echo '               1 $"Option 1" off \'
338
-echo '               2 $"Option 2" off \'
339
-echo '               3 $"Exit" on 2> $data'
336
+echo "               1 \$\"Option 1\" off \\"
337
+echo "               2 \$\"Option 2\" off \\"
338
+echo "               3 \$\"Exit\" on 2> \"\$data\""
340 339
 echo '        sel=$?'
341
-echo '        case $sel in'
342
-echo '            1) return;;'
343
-echo '            255) return;;'
340
+echo "        case \$sel in"
341
+echo "            1) rm -f \"\$data\""
342
+echo '               return;;'
343
+echo "            255) rm -f \"\$data\""
344
+echo '                 return;;'
344 345
 echo '        esac'
345
-echo '        case $(cat $data) in'
346
+echo "        case \$(cat \"\$data\") in"
346 347
 echo '            1) # call some function for option 1'
347 348
 echo '               ;;'
348 349
 echo '            2) # call some function for option 2'
349 350
 echo '               ;;'
350
-echo '            3) break;;'
351
+echo "            3) rm -f \"\$data\""
352
+echo '               break;;'
351 353
 echo '        esac'
354
+echo "        rm -f \"\$data\""
352 355
 echo '    done'
353 356
 echo '}'
354 357
 echo ''
@@ -363,7 +366,7 @@ echo "        ${app_name_upper}_DOMAIN_NAME=\$(get_completion_param \"${app_name
363 366
 echo '    fi'
364 367
 echo ''
365 368
 echo '    # update to the next commit'
366
-if [ ! $app_dir ]; then
369
+if [ ! "$app_dir" ]; then
367 370
     echo "    set_repo_commit /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs \"${app_name} commit\" \"\$${app_name_upper}_COMMIT\" \$${app_name_upper}_REPO"
368 371
     echo "    chown -R www-data:www-data /var/www/\${${app_name_upper}_DOMAIN_NAME}/htdocs"
369 372
 else
@@ -378,7 +381,7 @@ echo "    if grep -q \"${app_name} domain\" \$COMPLETION_FILE; then"
378 381
 echo "        ${app_name_upper}_DOMAIN_NAME=\$(get_completion_param \"${app_name} domain\")"
379 382
 echo '    fi'
380 383
 echo ''
381
-if [ ! $app_dir ]; then
384
+if [ ! "$app_dir" ]; then
382 385
     echo "    source_directory=/var/www/\${${app_name_upper}_DOMAIN_NAME}/htdocs"
383 386
 else
384 387
     echo "    source_directory=${app_dir}"
@@ -387,7 +390,7 @@ echo ''
387 390
 echo "    suspend_site \${${app_name_upper}_DOMAIN_NAME}"
388 391
 echo ''
389 392
 echo "    dest_directory=${app_name}"
390
-echo '    backup_directory_to_usb $source_directory $dest_directory'
393
+echo "    backup_directory_to_usb \$source_directory \$dest_directory"
391 394
 echo ''
392 395
 if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" ]]; then
393 396
     echo "    backup_database_to_usb ${app_name}"
@@ -408,7 +411,7 @@ echo '    fi'
408 411
 echo "    ${app_name_upper}_DOMAIN_NAME=\$(get_completion_param \"${app_name} domain\")"
409 412
 echo "    if [ \$${app_name_upper}_DOMAIN_NAME ]; then"
410 413
 echo "        temp_restore_dir=/root/temp${app_name}"
411
-if [ ! $app_dir ]; then
414
+if [ ! "$app_dir" ]; then
412 415
     echo "        ${app_name}_dir=/var/www/\${${app_name_upper}_DOMAIN_NAME}/htdocs"
413 416
 else
414 417
     echo "        ${app_name}_dir=${app_dir}"
@@ -418,8 +421,8 @@ if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" ]]; then
418 421
     echo "        ${app_name}_create_database"
419 422
     echo ''
420 423
     echo "        restore_database ${app_name}"
421
-    echo '        if [ -d $temp_restore_dir ]; then'
422
-    echo '            rm -rf $temp_restore_dir'
424
+    echo "        if [ -d \$temp_restore_dir ]; then"
425
+    echo "            rm -rf \$temp_restore_dir"
423 426
     echo '        fi'
424 427
     echo ''
425 428
 fi
@@ -428,13 +431,13 @@ if [[ "$database_type" == "postgres"* ]]; then
428 431
     echo ''
429 432
     echo '        USE_POSTGRESQL=1'
430 433
     echo "        restore_database ${app_name}"
431
-    echo '        if [ -d $temp_restore_dir ]; then'
432
-    echo '            rm -rf $temp_restore_dir'
434
+    echo "        if [ -d \$temp_restore_dir ]; then"
435
+    echo "            rm -rf \$temp_restore_dir"
433 436
     echo '        fi'
434 437
     echo ''
435 438
 fi
436 439
 echo "        restore_directory_from_usb \$temp_restore_dir ${app_name}"
437
-echo '        if [ -d $temp_restore_dir ]; then'
440
+echo "        if [ -d \$temp_restore_dir ]; then"
438 441
 echo "            if [ -d cp \$temp_restore_dir\$${app_name}_dir ]; then"
439 442
 echo "                cp -rp \$temp_restore_dir\$${app_name}_dir/* \$${app_name}_dir/"
440 443
 echo '            else'
@@ -444,7 +447,7 @@ echo '                fi'
444 447
 echo "                cp -rp \$temp_restore_dir/* \$${app_name}_dir/"
445 448
 echo '            fi'
446 449
 echo "            chown -R www-data:www-data \$${app_name}_dir"
447
-echo '            rm -rf $temp_restore_dir'
450
+echo "            rm -rf \$temp_restore_dir"
448 451
 echo '        fi'
449 452
 echo ''
450 453
 echo '    fi'
@@ -456,7 +459,7 @@ echo "    if grep -q \"${app_name} domain\" \$COMPLETION_FILE; then"
456 459
 echo "        ${app_name_upper}_DOMAIN_NAME=\$(get_completion_param \"${app_name} domain\")"
457 460
 echo '    fi'
458 461
 echo ''
459
-if [ ! $app_dir ]; then
462
+if [ ! "$app_dir" ]; then
460 463
     echo "    source_directory=/var/www/\${${app_name_upper}_DOMAIN_NAME}/htdocs"
461 464
 else
462 465
     echo "    source_directory=${app_dir}"
@@ -465,7 +468,7 @@ echo ''
465 468
 echo "    suspend_site \${${app_name_upper}_DOMAIN_NAME}"
466 469
 echo ''
467 470
 echo "    dest_directory=${app_name}"
468
-echo '    backup_directory_to_friend $source_directory $dest_directory'
471
+echo "    backup_directory_to_friend \$source_directory \$dest_directory"
469 472
 echo ''
470 473
 if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" ]]; then
471 474
     echo "    backup_database_to_friend ${app_name}"
@@ -486,7 +489,7 @@ echo '    fi'
486 489
 echo "    ${app_name_upper}_DOMAIN_NAME=\$(get_completion_param \"${app_name} domain\")"
487 490
 echo "    if [ \$${app_name_upper}_DOMAIN_NAME ]; then"
488 491
 echo "        temp_restore_dir=/root/temp${app_name}"
489
-if [ ! $app_dir ]; then
492
+if [ ! "$app_dir" ]; then
490 493
     echo "        ${app_name}_dir=/var/www/\${${app_name_upper}_DOMAIN_NAME}/htdocs"
491 494
 else
492 495
     echo "        ${app_name}_dir=${app_dir}"
@@ -496,8 +499,8 @@ if [[ "$database_type" == "mariadb" || "$database_type" == "mysql" ]]; then
496 499
     echo "        ${app_name}_create_database"
497 500
     echo ''
498 501
     echo "        restore_database_from_friend ${app_name}"
499
-    echo '        if [ -d $temp_restore_dir ]; then'
500
-    echo '            rm -rf $temp_restore_dir'
502
+    echo "        if [ -d \$temp_restore_dir ]; then"
503
+    echo "            rm -rf \$temp_restore_dir"
501 504
     echo '        fi'
502 505
     echo ''
503 506
 fi
@@ -506,13 +509,13 @@ if [[ "$database_type" == "postgres"* ]]; then
506 509
     echo ''
507 510
     echo '        USE_POSTGRESQL=1'
508 511
     echo "        restore_database_from_friend ${app_name}"
509
-    echo '        if [ -d $temp_restore_dir ]; then'
510
-    echo '            rm -rf $temp_restore_dir'
512
+    echo "        if [ -d \$temp_restore_dir ]; then"
513
+    echo "            rm -rf \$temp_restore_dir"
511 514
     echo '        fi'
512 515
     echo ''
513 516
 fi
514 517
 echo "        restore_directory_from_friend \$temp_restore_dir ${app_name}"
515
-echo '        if [ -d $temp_restore_dir ]; then'
518
+echo "        if [ -d \$temp_restore_dir ]; then"
516 519
 echo "            if [ -d cp \$temp_restore_dir\$${app_name}_dir ]; then"
517 520
 echo "                cp -rp \$temp_restore_dir\$${app_name}_dir/* \$${app_name}_dir/"
518 521
 echo '            else'
@@ -522,7 +525,7 @@ echo '                fi'
522 525
 echo "                cp -rp \$temp_restore_dir/* \$${app_name}_dir/"
523 526
 echo '            fi'
524 527
 echo "            chown -R www-data:www-data \$${app_name}_dir"
525
-echo '            rm -rf $temp_restore_dir'
528
+echo "            rm -rf \$temp_restore_dir"
526 529
 echo '        fi'
527 530
 echo ''
528 531
 echo '    fi'
@@ -564,7 +567,7 @@ echo '    fi'
564 567
 echo "    remove_app ${app_name}"
565 568
 echo "    remove_completion_param install_${app_name}"
566 569
 echo "    sed -i '/${app_name}/d' \$COMPLETION_FILE"
567
-if [ $app_port ]; then
570
+if [ "$app_port" ]; then
568 571
     echo ''
569 572
     echo "    firewall_remove ${app_port} tcp"
570 573
 fi
@@ -597,7 +600,7 @@ echo '    fi'
597 600
 echo "    if [ ! -d /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs ]; then"
598 601
 echo "        if [ -d /repos/${app_name} ]; then"
599 602
 echo "            mkdir /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs"
600
-if [ ! $app_dir ]; then
603
+if [ ! "$app_dir" ]; then
601 604
     echo "            cp -r -p /repos/${app_name}/. /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs"
602 605
     echo "            cd /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs"
603 606
 else
@@ -606,14 +609,14 @@ else
606 609
 fi
607 610
 echo '            git pull'
608 611
 echo '        else'
609
-if [ ! $app_dir ]; then
612
+if [ ! "$app_dir" ]; then
610 613
     echo "            git_clone \$${app_name_upper}_REPO /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs"
611 614
 else
612 615
     echo "            git_clone \$${app_name_upper}_REPO ${app_dir}"
613 616
 fi
614 617
 echo '        fi'
615 618
 echo ''
616
-if [ ! $app_dir ]; then
619
+if [ ! "$app_dir" ]; then
617 620
     echo "        if [ ! -d /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs ]; then"
618 621
 else
619 622
     echo "        if [ ! -d ${app_dir} ]; then"
@@ -623,7 +626,7 @@ echo '            exit 87525'
623 626
 echo '        fi'
624 627
 echo '    fi'
625 628
 echo ''
626
-if [ ! $app_dir ]; then
629
+if [ ! "$app_dir" ]; then
627 630
     echo "    cd /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs"
628 631
 else
629 632
     echo "    cd ${app_dir}"
@@ -646,7 +649,7 @@ echo ''
646 649
 echo "    ${app_name}_nginx_site=/etc/nginx/sites-available/\$${app_name_upper}_DOMAIN_NAME"
647 650
 
648 651
 if [ $app_onion_only ]; then
649
-    echo '    if [[ $ONION_ONLY == "no" ]]; then'
652
+    echo "    if [[ \"\$ONION_ONLY\" == \"no\" ]]; then"
650 653
     if [[ "$app_php" == 'yes' ]]; then
651 654
         echo "        nginx_http_redirect \$${app_name_upper}_DOMAIN_NAME \"index index.php\""
652 655
     else
@@ -675,7 +678,7 @@ if [ $app_onion_only ]; then
675 678
     echo "        echo '' >> \$${app_name}_nginx_site"
676 679
     if [[ "$app_php" == 'yes' ]]; then
677 680
         echo "        echo '  index index.php;' >> \$${app_name}_nginx_site"
678
-        echo "        echo '  location ~ \.php {' >> \$${app_name}_nginx_site"
681
+        echo "        echo '  location ~ \\.php {' >> \$${app_name}_nginx_site"
679 682
         echo "        echo '    include snippets/fastcgi-php.conf;' >> \$${app_name}_nginx_site"
680 683
         echo "        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> \$${app_name}_nginx_site"
681 684
         echo "        echo '    fastcgi_read_timeout 30;' >> \$${app_name}_nginx_site"
@@ -717,7 +720,7 @@ echo "    echo \"  root /var/www/\$${app_name_upper}_DOMAIN_NAME/htdocs;\" >> \$
717 720
 echo "    echo '' >> \$${app_name}_nginx_site"
718 721
 if [[ "$app_php" == 'yes' ]]; then
719 722
     echo "    echo '  index index.php;' >> \$${app_name}_nginx_site"
720
-    echo "    echo '  location ~ \.php {' >> \$${app_name}_nginx_site"
723
+    echo "    echo '  location ~ \\.php {' >> \$${app_name}_nginx_site"
721 724
     echo "    echo '    include snippets/fastcgi-php.conf;' >> \$${app_name}_nginx_site"
722 725
     echo "    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> \$${app_name}_nginx_site"
723 726
     echo "    echo '    fastcgi_read_timeout 30;' >> \$${app_name}_nginx_site"
@@ -753,7 +756,7 @@ if [ $app_daemon ]; then
753 756
     echo "    echo 'Type=simple' >> /etc/systemd/system/${app_name}.service"
754 757
     echo "    echo 'User=${app_name}' >> /etc/systemd/system/${app_name}.service"
755 758
     echo "    echo 'Group=${app_name}' >> /etc/systemd/system/${app_name}.service"
756
-    if [ ! $app_dir ]; then
759
+    if [ ! "$app_dir" ]; then
757 760
         echo "    echo 'WorkingDirectory=TODO' >> /etc/systemd/system/${app_name}.service"
758 761
     else
759 762
         echo "    echo 'WorkingDirectory=${app_dir}' >> /etc/systemd/system/${app_name}.service"
@@ -765,7 +768,7 @@ if [ $app_daemon ]; then
765 768
     echo "    echo '[Install]' >> /etc/systemd/system/${app_name}.service"
766 769
     echo "    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/${app_name}.service"
767 770
     echo "    systemctl enable ${app_name}"
768
-    if [ $app_dir ]; then
771
+    if [ "$app_dir" ]; then
769 772
         echo "    chown -R ${app_name}:${app_name} ${app_dir}"
770 773
     fi
771 774
     echo "    systemctl start ${app_name}"
@@ -785,7 +788,7 @@ echo '    systemctl restart nginx'
785 788
 echo ''
786 789
 echo "    \${PROJECT_NAME}-pass -u \$MY_USERNAME -a ${app_name} -p \"\$${app_name_upper}_ADMIN_PASSWORD\""
787 790
 echo "    set_completion_param \"${app_name} domain\" \"\$${app_name_upper}_DOMAIN_NAME\""
788
-if [ $app_port ]; then
791
+if [ "$app_port" ]; then
789 792
     echo ''
790 793
     echo "    firewall_add ${app_name} ${app_port} tcp"
791 794
 fi

+ 27
- 16
src/freedombone-tests Просмотреть файл

@@ -56,8 +56,8 @@ function test_app_function_type {
56 56
     filename=$1
57 57
     fn_type=$2
58 58
     app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
59
-    app_function=$(cat "${filename}" | grep "function ${fn_type}_${app_name} {" | awk -F "${fn_type}_" '{print $2}' | awk -F ' ' '{print $1}')
60
-    if [ ! ${app_function} ]; then
59
+    app_function=$(grep "function ${fn_type}_${app_name} {" "${filename}" | awk -F "${fn_type}_" '{print $2}' | awk -F ' ' '{print $1}')
60
+    if [ ! "${app_function}" ]; then
61 61
         echo $"Application ${app_name} does not contain a function called '${fn_type}_${app_name}'"
62 62
         echo ''
63 63
         echo "See ${filename}"
@@ -69,7 +69,7 @@ function test_app_functions {
69 69
     if [ $RUN_STIG ]; then
70 70
         return
71 71
     fi
72
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
72
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
73 73
 
74 74
     # check that these functions exist
75 75
     interface_functions=( install remove backup_local backup_remote restore_local restore_remote upgrade reconfigure )
@@ -80,7 +80,7 @@ function test_app_functions {
80 80
         # for each expected interface function
81 81
         for f in "${interface_functions[@]}"
82 82
         do
83
-            test_app_function_type ${filename} $f
83
+            test_app_function_type ${filename} "$f"
84 84
         done
85 85
     done
86 86
 }
@@ -91,12 +91,12 @@ function test_unique_onion_ports {
91 91
     fi
92 92
 
93 93
     # test that some services are not assigned the same onion port
94
-    FILES=src/${PROJECT_NAME}-app-*
95
-    ports=$(grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}')
96
-    unique_ports=$(grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}' | uniq)
94
+    FILES="src/${PROJECT_NAME}-app-*"
95
+    ports=$(grep -r "_ONION_PORT=" "$FILES" | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}')
96
+    unique_ports=$(grep -r "_ONION_PORT=" "$FILES" | awk -F ':' '{print $2}' | uniq | awk -F '=' '{print $2}' | uniq)
97 97
     if [[ "$ports" != "$unique_ports" ]]; then
98 98
         echo $'Some onion ports are clashing'
99
-        grep -r "_ONION_PORT=" $FILES | awk -F ':' '{print $2}' | uniq
99
+        grep -r "_ONION_PORT=" "$FILES" | awk -F ':' '{print $2}' | uniq
100 100
         exit 637252
101 101
     fi
102 102
 }
@@ -110,7 +110,7 @@ function stig_log_msg {
110 110
     NORMAL=$(tput sgr0)
111 111
     MSG="$2"
112 112
 
113
-    if [ $ESTATUS -eq 0 ];then
113
+    if [ "$ESTATUS" -eq 0 ];then
114 114
         printf "%s %s"  "$GREEN$BOLD[ PASS ]$NORMAL" "$MSG"
115 115
         echo
116 116
     else
@@ -123,19 +123,20 @@ function stig_spinner {
123 123
 
124 124
     local pid=$1
125 125
     local delay=0.1
126
+    # shellcheck disable=SC2143
126 127
     while [ "$(ps -a | awk '{print $1}' | grep "$pid")" ];
127 128
     do
128 129
         sleep $delay
129 130
     done
130
-    printf " \b"
131
-    wait $1
131
+    printf " \\b"
132
+    wait "$1"
132 133
 }
133 134
 
134 135
 function disallow_package {
135 136
     package_name=$1
136 137
 
137 138
     if service --status-all | grep "+.*${package_name}";then
138
-        apt-get -yq remove --purge ${package_name}
139
+        apt-get -yq remove --purge "${package_name}"
139 140
         apt -yq autoremove
140 141
     fi
141 142
 }
@@ -164,7 +165,7 @@ function test_stig {
164 165
     CATCOLOR=1
165 166
     SETLANG="en"
166 167
 
167
-    source $STIG_TESTS_DIR/output.sh
168
+    source "$STIG_TESTS_DIR/output.sh"
168 169
 
169 170
     ##RHEL-06-000001
170 171
     ##The system must use a separate file system for /tmp.
@@ -249,6 +250,7 @@ function test_stig {
249 250
     ##RHEL-06-000033
250 251
     ##The /etc/shadow file must be owned by root.
251 252
 
253
+    # shellcheck disable=SC2012
252 254
     ls -l /etc/shadow | awk '{print $3}' | grep "^root$" > /dev/null 2>&1 &
253 255
 
254 256
     stig_spinner $!
@@ -258,6 +260,7 @@ function test_stig {
258 260
     ##RHEL-06-000034
259 261
     ##The /etc/shadow file must be group-owned by root.
260 262
 
263
+    # shellcheck disable=SC2012
261 264
     ls -l /etc/shadow | awk '{print $4}' | grep "^root$" > /dev/null 2>&1 &
262 265
 
263 266
     stig_spinner $!
@@ -267,6 +270,7 @@ function test_stig {
267 270
     ##RHEL-06-000035
268 271
     ##The /etc/shadow file must have mode 0000.
269 272
 
273
+    # shellcheck disable=SC2012
270 274
     ls -l /etc/shadow | awk '{print $1}' | grep "^----------$" > /dev/null 2>&1 &
271 275
 
272 276
     stig_spinner $!
@@ -276,6 +280,7 @@ function test_stig {
276 280
     ##RHEL-06-000036
277 281
     ##The /etc/gshadow file must be owned by root.
278 282
 
283
+    # shellcheck disable=SC2012
279 284
     ls -l /etc/gshadow | awk '{print $3}' | grep "^root$" > /dev/null 2>&1 &
280 285
 
281 286
     stig_spinner $!
@@ -285,6 +290,7 @@ function test_stig {
285 290
     ##RHEL-06-000037
286 291
     ##The /etc/gshadow file must be group-owned by root.
287 292
 
293
+    # shellcheck disable=SC2012
288 294
     ls -l /etc/gshadow | awk '{print $4}' | grep "^root$" > /dev/null 2>&1 &
289 295
 
290 296
     stig_spinner $!
@@ -294,6 +300,7 @@ function test_stig {
294 300
     ##RHEL-06-000038
295 301
     ##The /etc/gshadow file must have mode 0000.
296 302
 
303
+    # shellcheck disable=SC2012
297 304
     ls -l /etc/gshadow | awk '{print $1}' | grep "^----------$" > /dev/null 2>&1 &
298 305
 
299 306
     stig_spinner $!
@@ -303,6 +310,7 @@ function test_stig {
303 310
     ##RHEL-06-000039
304 311
     ##The /etc/passwd file must be owned by root.
305 312
 
313
+    # shellcheck disable=SC2012
306 314
     ls -l /etc/passwd | awk '{print $3}' | grep "^root$" > /dev/null 2>&1 &
307 315
 
308 316
     stig_spinner $!
@@ -312,6 +320,7 @@ function test_stig {
312 320
     ##RHEL-06-000040
313 321
     ##The /etc/passwd file must be group-owned by root.
314 322
 
323
+    # shellcheck disable=SC2012
315 324
     ls -l /etc/passwd | awk '{print $4}' | grep "^root$" > /dev/null 2>&1 &
316 325
 
317 326
     stig_spinner $!
@@ -330,6 +339,7 @@ function test_stig {
330 339
     ##RHEL-06-000042
331 340
     ##The /etc/group file must be owned by root.
332 341
 
342
+    # shellcheck disable=SC2012
333 343
     ls -l /etc/group | awk '{print $3}' | grep "^root$" > /dev/null 2>&1 &
334 344
 
335 345
     stig_spinner $!
@@ -339,6 +349,7 @@ function test_stig {
339 349
     ##RHEL-06-000043
340 350
     ##The /etc/group file must be group-owned by root.
341 351
 
352
+    # shellcheck disable=SC2012
342 353
     ls -l /etc/group | awk '{print $4}' | grep "^root$" > /dev/null 2>&1 &
343 354
 
344 355
     stig_spinner $!
@@ -1202,7 +1213,7 @@ function test_stig {
1202 1213
     if [ $SHOW_ALL_TESTS ]; then
1203 1214
         show_passes_fails=1
1204 1215
     else
1205
-        if [ $FAILS -gt 0 ]; then
1216
+        if [ "$FAILS" -gt 0 ]; then
1206 1217
             show_passes_fails=1
1207 1218
         fi
1208 1219
     fi
@@ -1211,7 +1222,7 @@ function test_stig {
1211 1222
         echo ''
1212 1223
         echo $"Passes: $PASSES"
1213 1224
         echo $"Fails:  $FAILS"
1214
-        if [ $FAILS -gt 0 ]; then
1225
+        if [ "$FAILS" -gt 0 ]; then
1215 1226
             exit 792353
1216 1227
         fi
1217 1228
     fi
@@ -1239,7 +1250,7 @@ do
1239 1250
     shift
1240 1251
 done
1241 1252
 
1242
-if [ ! $RUN_STIG ]; then
1253
+if [ ! "$RUN_STIG" ]; then
1243 1254
     echo $'Running tests'
1244 1255
 fi
1245 1256
 

+ 7
- 7
src/freedombone-unignore Просмотреть файл

@@ -79,20 +79,20 @@ if ! [[ $MYUSERNAME && $EMAIL_ADDRESS ]]; then
79 79
     fi
80 80
 fi
81 81
 
82
-MUTTRC=/home/$MYUSERNAME/.muttrc
82
+MUTTRC="/home/$MYUSERNAME/.muttrc"
83 83
 PM=/home/$MYUSERNAME/.procmailrc
84 84
 
85 85
 # unignore if subject line contains text
86
-if [ $SUBJECT_TEXT ]; then
87
-    if grep -q "Ignore rule for $SUBJECT_TEXT" $PM; then
88
-        sed -i "/# Ignore rule for $SUBJECT_TEXT/,/# End of ignore rule/d" $PM
86
+if [ "$SUBJECT_TEXT" ]; then
87
+    if grep -q "Ignore rule for $SUBJECT_TEXT" "$PM"; then
88
+        sed -i "/# Ignore rule for $SUBJECT_TEXT/,/# End of ignore rule/d" "$PM"
89 89
     fi
90 90
 fi
91 91
 
92 92
 # unignore an email address
93
-if [ $EMAIL_ADDRESS ]; then
94
-    if grep -q "Ignore rule for $EMAIL_ADDRESS" $PM; then
95
-        sed -i "/# Ignore rule for $EMAIL_ADDRESS/,/# End of ignore rule/d" $PM
93
+if [ "$EMAIL_ADDRESS" ]; then
94
+    if grep -q "Ignore rule for $EMAIL_ADDRESS" "$PM"; then
95
+        sed -i "/# Ignore rule for $EMAIL_ADDRESS/,/# End of ignore rule/d" "$PM"
96 96
     fi
97 97
 fi
98 98
 

+ 9
- 10
src/freedombone-upgrade Просмотреть файл

@@ -42,10 +42,10 @@ CURRENT_BRANCH=master
42 42
 # clear temporary files
43 43
 rm -rf /tmp/*
44 44
 
45
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
45
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
46 46
 for f in $UTILS_FILES
47 47
 do
48
-    source $f
48
+    source "$f"
49 49
 done
50 50
 
51 51
 read_config_param PROJECT_REPO
@@ -68,14 +68,14 @@ fi
68 68
 
69 69
 #update-ca-certificates
70 70
 
71
-if [ ! -d $PROJECT_DIR ]; then
72
-    git_clone $PROJECT_REPO $PROJECT_DIR
71
+if [ ! -d "$PROJECT_DIR" ]; then
72
+    git_clone "$PROJECT_REPO" "$PROJECT_DIR"
73 73
 fi
74 74
 
75
-if [ -d $PROJECT_DIR ]; then
76
-    if [ -f $CONFIGURATION_FILE ]; then
77
-        cd $PROJECT_DIR
78
-        rm -rf $PROJECT_DIR/locale/*
75
+if [ -d "$PROJECT_DIR" ]; then
76
+    if [ -f "$CONFIGURATION_FILE" ]; then
77
+        cd "$PROJECT_DIR" || exit 246823484
78
+        rm -rf "$PROJECT_DIR/locale/*"
79 79
         if [[ "$CURRENT_BRANCH" == *"master" ]]; then
80 80
             git_pull $PROJECT_REPO
81 81
         else
@@ -88,8 +88,7 @@ if [ -d $PROJECT_DIR ]; then
88 88
             chmod -R +r /usr/share/${PROJECT_NAME}
89 89
         fi
90 90
 
91
-        ${PROJECT_NAME} -c $CONFIGURATION_FILE
92
-        if [ ! "$?" = "0" ]; then
91
+        if ! ${PROJECT_NAME} -c "$CONFIGURATION_FILE"; then
93 92
             exit 453536
94 93
         fi
95 94
 

+ 5
- 5
src/freedombone-usb-canary Просмотреть файл

@@ -30,12 +30,12 @@
30 30
 
31 31
 PROJECT_NAME=freedombone
32 32
 
33
-UPTIME=$(cat /proc/uptime | awk -F '.' '{print $1}')
34
-if [ $UPTIME -gt 120 ]; then
35
-    ADMIN_USER=$(cat /root/${PROJECT_NAME}-completed.txt | grep 'Admin user' | awk -F ':' '{print $2}')
33
+UPTIME=$(awk -F '.' '{print $1}' < "/proc/uptime")
34
+if [ "$UPTIME" -gt 120 ]; then
35
+    ADMIN_USER=$(grep 'Admin user' /root/${PROJECT_NAME}-completed.txt | awk -F ':' '{print $2}')
36 36
     MY_EMAIL_ADDRESS=${ADMIN_USER}@$(cat /etc/hostname)
37
-    echo "USB device connected on ${DEVPATH}" | mail -s "${PROJECT_NAME} USB canary" ${MY_EMAIL_ADDRESS}
37
+    echo "USB device connected on ${DEVPATH}" | mail -s "${PROJECT_NAME} USB canary" "${MY_EMAIL_ADDRESS}"
38 38
     echo "${ACTION}" > /tmp/usb-canary
39 39
     echo "${MY_EMAIL_ADDRESS}" >> /tmp/usb-canary
40
-    echo "$(date)" >> /tmp/usb-canary
40
+    date >> /tmp/usb-canary
41 41
 fi

+ 19
- 18
src/meshavahi Просмотреть файл

@@ -71,17 +71,17 @@ function ipfs_publish {
71 71
     # include some subdirectories
72 72
     for dir in $DIR_TO_CHECK/*/
73 73
     do
74
-        REALLY_NEW_STAT="$NEW_STAT$(stat -t $dir)"
74
+        REALLY_NEW_STAT="$NEW_STAT$(stat -t "$dir")"
75 75
         NEW_STAT="$REALLY_NEW_STAT"
76 76
 
77 77
         for dir2 in "$dir"/*/
78 78
         do
79
-            REALLY_NEW_STAT="$NEW_STAT$(stat -t $dir2)"
79
+            REALLY_NEW_STAT="$NEW_STAT$(stat -t "$dir2")"
80 80
             NEW_STAT="$REALLY_NEW_STAT"
81 81
 
82 82
             for dir3 in "$dir2"/*/
83 83
             do
84
-                REALLY_NEW_STAT="$NEW_STAT$(stat -t $dir3)"
84
+                REALLY_NEW_STAT="$NEW_STAT$(stat -t "$dir3")"
85 85
                 NEW_STAT="$REALLY_NEW_STAT"
86 86
             done
87 87
         done
@@ -101,7 +101,7 @@ function ipfs_publish {
101 101
 
102 102
 function ipfs_bootstrap {
103 103
     # TODO switch to ipv6
104
-    cat $TEMPFILE_BASE | grep "ipfs_id\|hostname =\|address =\|port =\|txt =" > $TEMPFILE
104
+    grep "ipfs_id\\|hostname =\\|address =\\|port =\\|txt =" "$TEMPFILE_BASE" > "$TEMPFILE"
105 105
 
106 106
     state=0
107 107
     address=""
@@ -126,13 +126,13 @@ function ipfs_bootstrap {
126 126
         fi
127 127
         if [ ${state} -eq "2" ]; then
128 128
             if [[ $line == *"address ="* ]]; then
129
-                address=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
129
+                address=$(echo "$line" | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
130 130
                 state=3
131 131
             fi
132 132
         fi
133 133
         if [ ${state} -eq "1" ]; then
134 134
             if [[ $line == *"hostname ="* ]]; then
135
-                peer=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
135
+                peer=$(echo "$line" | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
136 136
                 state=2
137 137
             fi
138 138
         fi
@@ -144,7 +144,7 @@ function ipfs_bootstrap {
144 144
     # Create a list of user sites, in alphabetical order by Tox nick
145 145
     if [ -d /home/$MY_USERNAME/Desktop ]; then
146 146
         if [ -f ${IPFS_USERS_FILE}.new ]; then
147
-            sites_list=$(cat ${IPFS_USERS_FILE}.new | sort -d)
147
+            sites_list=$(sort -d < "${IPFS_USERS_FILE}.new")
148 148
             echo "${sites_list}" > ${IPFS_USERS_FILE}
149 149
             chown $MY_USERNAME:$MY_USERNAME ${IPFS_USERS_FILE}
150 150
             rm ${IPFS_USERS_FILE}.new
@@ -155,7 +155,7 @@ function ipfs_bootstrap {
155 155
 function detect_new_tox_users {
156 156
     CURRENT_USERS_FILE=$1
157 157
 
158
-    if [ ! -f $CURRENT_USERS_FILE ]; then
158
+    if [ ! -f "$CURRENT_USERS_FILE" ]; then
159 159
         return
160 160
     fi
161 161
 
@@ -170,10 +170,11 @@ function detect_new_tox_users {
170 170
             if [[ $line != "Failed*" && $line != "data "* && $line != "Anon "* && $line != "anon "* && $line != "anonymous "* && $line != "Anonymous "* ]]; then
171 171
                 if ! grep -q "$line" $PREV_TOX_USERS_FILE; then
172 172
                     # get the nick of the user
173
-                    toxidstr=$(echo "$line" | awk -F ' ' '{print $(NF)}')
174
-                    toxuser=$(echo "$line" | sed "s| $toxidstr||g")
173
+                    toxidstr=$(awk -F ' ' '{print $(NF)}' < "$line")
174
+                    toxuser=$(sed "s| $toxidstr||g" < "$line")
175 175
 
176 176
                     if [ -r "/home/$MESH_USERNAME/.dbus/Xdbus" ]; then
177
+                        # shellcheck disable=SC1090
177 178
                         . "/home/$MESH_USERNAME/.dbus/Xdbus"
178 179
                     fi
179 180
                     export DISPLAY=:0.0
@@ -186,28 +187,28 @@ function detect_new_tox_users {
186 187
     fi
187 188
 
188 189
     # Store the previous tox users list
189
-    cp -f $CURRENT_USERS_FILE $PREV_TOX_USERS_FILE
190
+    cp -f "$CURRENT_USERS_FILE" "$PREV_TOX_USERS_FILE"
190 191
 }
191 192
 
192 193
 function detect_tox_users {
193 194
     # don't show the first peer field
194
-    lstox | awk -F ' ' '{$1=""; print $0}' | sed -e 's/^[[:space:]]*//' | sort -d > $TEMPFILE
195
+    lstox | awk -F ' ' '{$1=""; print $0}' | sed -e 's/^[[:space:]]*//' | sort -d > "$TEMPFILE"
195 196
 
196
-    detect_new_tox_users $TEMPFILE
197
+    detect_new_tox_users "$TEMPFILE"
197 198
 }
198 199
 
199 200
 function avahi_extract_info {
200 201
     # Create a list of bootstrap nodes
201
-    avahi-browse -atr > $TEMPFILE_BASE
202
-    cat $TEMPFILE_BASE | grep "hostname =\|address =\|port =" > $TEMPFILE
203
-    if [ ! -f $TEMPFILE ]; then
202
+    avahi-browse -atr > "$TEMPFILE_BASE"
203
+    grep "hostname =\\|address =\\|port =" "$TEMPFILE_BASE" > "$TEMPFILE"
204
+    if [ ! -f "$TEMPFILE" ]; then
204 205
         exit 1
205 206
     fi
206 207
 }
207 208
 
208 209
 function avahi_remove_info {
209
-    rm -f $TEMPFILE_BASE
210
-    rm -f $TEMPFILE
210
+    rm -f "$TEMPFILE_BASE"
211
+    rm -f "$TEMPFILE"
211 212
 }
212 213
 
213 214
 if [ ! -d /etc/avahi ]; then