Bob Mottram преди 7 години
родител
ревизия
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
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroBlog
105
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroBlog
106
     fi
106
     fi
107
     remove_completion_param install_zeronet_blog
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
 function remove_zeronet_mail {
111
 function remove_zeronet_mail {
113
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroMail
113
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroMail
114
     fi
114
     fi
115
     remove_completion_param install_zeronet_mail
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
 function remove_zeronet_forum {
119
 function remove_zeronet_forum {
121
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroTalk
121
         rm -rf $MESH_INSTALL_DIR/zeronet/ZeroTalk
122
     fi
122
     fi
123
     remove_completion_param install_zeronet_forum
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
 function remove_zeronet {
127
 function remove_zeronet {
133
     firewall_remove ${TRACKER_PORT}
133
     firewall_remove ${TRACKER_PORT}
134
     firewall_remove 1900 udp
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
     remove_completion_param install_zeronet
137
     remove_completion_param install_zeronet
138
     remove_completion_param configure_firewall_for_zeronet
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
 function configure_firewall_for_zeronet {
142
 function configure_firewall_for_zeronet {
161
 
161
 
162
     ZERONET_DEFAULT_BLOG_TITLE="${MY_USERNAME}'s Blog"
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
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/blog.txt
165
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/blog.txt
166
     if [ ! -f $MESH_INSTALL_DIR/zeronet/blog.txt ]; then
166
     if [ ! -f $MESH_INSTALL_DIR/zeronet/blog.txt ]; then
167
         echo $'Unable to create blog'
167
         echo $'Unable to create blog'
168
         exit 479
168
         exit 479
169
     fi
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
     ZERONET_BLOG_ADDRESS=${blog_address//[[:blank:]]/}
172
     ZERONET_BLOG_ADDRESS=${blog_address//[[:blank:]]/}
173
     ZERONET_BLOG_PRIVATE_KEY=${blog_private_key//[[:blank:]]/}
173
     ZERONET_BLOG_PRIVATE_KEY=${blog_private_key//[[:blank:]]/}
174
 
174
 
197
         echo $'ZeroBlog repo could not be cloned'
197
         echo $'ZeroBlog repo could not be cloned'
198
         exit 6739
198
         exit 6739
199
     fi
199
     fi
200
-    cd $MESH_INSTALL_DIR/zeronet/ZeroBlog
200
+    cd "$MESH_INSTALL_DIR/zeronet/ZeroBlog" || exit 47298462874
201
     git checkout $ZERONET_BLOG_COMMIT -b $ZERONET_BLOG_COMMIT
201
     git checkout $ZERONET_BLOG_COMMIT -b $ZERONET_BLOG_COMMIT
202
     set_completion_param "zeroNet blog commit" "$ZERONET_BLOG_COMMIT"
202
     set_completion_param "zeroNet blog commit" "$ZERONET_BLOG_COMMIT"
203
 
203
 
204
     echo $"ZeroNet Blog address:     $ZERONET_BLOG_ADDRESS"
204
     echo $"ZeroNet Blog address:     $ZERONET_BLOG_ADDRESS"
205
     echo $"ZeroNet Blog private key: $ZERONET_BLOG_PRIVATE_KEY"
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
     fi
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
     # Add an avahi service
219
     # Add an avahi service
220
     function_check create_avahi_service
220
     function_check create_avahi_service
223
 
223
 
224
     chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
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
     fi
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
     install_completed zeronet_blog
232
     install_completed zeronet_blog
233
 }
233
 }
244
 
244
 
245
     ZERONET_DEFAULT_MAIL_TITLE="${MY_USERNAME}'s Mail"
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
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/mail.txt
248
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/mail.txt
249
     if [ ! -f $MESH_INSTALL_DIR/zeronet/mail.txt ]; then
249
     if [ ! -f $MESH_INSTALL_DIR/zeronet/mail.txt ]; then
250
         echo $'Unable to create mail'
250
         echo $'Unable to create mail'
251
         exit 479
251
         exit 479
252
     fi
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
     ZERONET_MAIL_ADDRESS=${mail_address//[[:blank:]]/}
255
     ZERONET_MAIL_ADDRESS=${mail_address//[[:blank:]]/}
256
     ZERONET_MAIL_PRIVATE_KEY=${mail_private_key//[[:blank:]]/}
256
     ZERONET_MAIL_PRIVATE_KEY=${mail_private_key//[[:blank:]]/}
257
 
257
 
280
         echo $'ZeroMail repo could not be cloned'
280
         echo $'ZeroMail repo could not be cloned'
281
         exit 6739
281
         exit 6739
282
     fi
282
     fi
283
-    cd $MESH_INSTALL_DIR/zeronet/ZeroMail
283
+    cd "$MESH_INSTALL_DIR/zeronet/ZeroMail" || exit 246284682
284
     git checkout $ZERONET_MAIL_COMMIT -b $ZERONET_MAIL_COMMIT
284
     git checkout $ZERONET_MAIL_COMMIT -b $ZERONET_MAIL_COMMIT
285
     set_completion_param "zeroNet mail commit" "$ZERONET_MAIL_COMMIT"
285
     set_completion_param "zeroNet mail commit" "$ZERONET_MAIL_COMMIT"
286
 
286
 
287
     echo $"ZeroNet Mail address:     $ZERONET_MAIL_ADDRESS"
287
     echo $"ZeroNet Mail address:     $ZERONET_MAIL_ADDRESS"
288
     echo $"ZeroNet Mail private key: $ZERONET_MAIL_PRIVATE_KEY"
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
     fi
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
     # Add an avahi service
302
     # Add an avahi service
303
     function_check create_avahi_service
303
     function_check create_avahi_service
306
 
306
 
307
     chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
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
     fi
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
     install_completed zeronet_mail
315
     install_completed zeronet_mail
316
 }
316
 }
327
 
327
 
328
     ZERONET_DEFAULT_FORUM_TITLE=$"${MY_USERNAME}'s Forum"
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
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/forum.txt
331
     python zeronet.py --batch siteCreate 2> $MESH_INSTALL_DIR/zeronet/forum.txt
332
     if [ ! -f $MESH_INSTALL_DIR/zeronet/forum.txt ]; then
332
     if [ ! -f $MESH_INSTALL_DIR/zeronet/forum.txt ]; then
333
         echo $'Unable to create forum'
333
         echo $'Unable to create forum'
334
         exit 479
334
         exit 479
335
     fi
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
     ZERONET_FORUM_ADDRESS=${forum_address//[[:blank:]]/}
338
     ZERONET_FORUM_ADDRESS=${forum_address//[[:blank:]]/}
339
     ZERONET_FORUM_PRIVATE_KEY=${forum_private_key//[[:blank:]]/}
339
     ZERONET_FORUM_PRIVATE_KEY=${forum_private_key//[[:blank:]]/}
340
 
340
 
368
 
368
 
369
     echo $"Forum address:     $ZERONET_FORUM_ADDRESS"
369
     echo $"Forum address:     $ZERONET_FORUM_ADDRESS"
370
     echo $"Forum private key: $ZERONET_FORUM_PRIVATE_KEY"
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
     # Add an avahi service
379
     # Add an avahi service
380
     function_check create_avahi_service
380
     function_check create_avahi_service
383
 
383
 
384
     chown -R zeronet:zeronet $MESH_INSTALL_DIR/zeronet
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
     fi
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
     install_completed zeronet_forum
392
     install_completed zeronet_forum
393
 }
393
 }
397
         return
397
         return
398
     fi
398
     fi
399
 
399
 
400
-    ${PROJECT_NAME}-mesh-install -f zeronet
400
+    "${PROJECT_NAME}-mesh-install" -f zeronet
401
     systemctl daemon-reload
401
     systemctl daemon-reload
402
     systemctl start tracker.service
402
     systemctl start tracker.service
403
     systemctl start zeronet.service
403
     systemctl start zeronet.service
408
 }
408
 }
409
 
409
 
410
 function mesh_zeronet {
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
     if [ ${#ZERONET_REPO_MAIN} -gt 4 ]; then
412
     if [ ${#ZERONET_REPO_MAIN} -gt 4 ]; then
413
         ZERONET_REPO=$ZERONET_REPO_MAIN
413
         ZERONET_REPO=$ZERONET_REPO_MAIN
414
     fi
414
     fi
415
-    if [ ! $ZERONET_REPO ]; then
415
+    if [ ! "$ZERONET_REPO" ]; then
416
         echo $'No ZeroNet repo was specified'
416
         echo $'No ZeroNet repo was specified'
417
         exit 723539
417
         exit 723539
418
     fi
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
     if [ ${#ZERONET_COMMIT_MAIN} -gt 4 ]; then
421
     if [ ${#ZERONET_COMMIT_MAIN} -gt 4 ]; then
422
         ZERONET_COMMIT=$ZERONET_COMMIT_MAIN
422
         ZERONET_COMMIT=$ZERONET_COMMIT_MAIN
423
     fi
423
     fi
424
-    if [ ! $ZERONET_COMMIT ]; then
424
+    if [ ! "$ZERONET_COMMIT" ]; then
425
         echo $'No ZeroNet commit was specified'
425
         echo $'No ZeroNet commit was specified'
426
         exit 490439
426
         exit 490439
427
     fi
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
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
430
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
431
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
431
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
432
     fi
432
     fi
433
-    if [ ! $MESH_INSTALL_DIR ]; then
433
+    if [ ! "$MESH_INSTALL_DIR" ]; then
434
         echo $'No mesh install dir was specified'
434
         echo $'No mesh install dir was specified'
435
         exit 432052
435
         exit 432052
436
     fi
436
     fi
437
 
437
 
438
+    # shellcheck disable=SC2154
438
     chroot "$rootdir" apt-get -yq install python python-msgpack python-gevent
439
     chroot "$rootdir" apt-get -yq install python python-msgpack python-gevent
439
     chroot "$rootdir" apt-get -yq install python-pip bittornado
440
     chroot "$rootdir" apt-get -yq install python-pip bittornado
440
     chroot "$rootdir" pip install msgpack-python --upgrade
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
     if [ -d /repos/zeronet ]; then
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
         git pull
449
         git pull
449
     else
450
     else
450
-        git clone $ZERONET_REPO $rootdir$MESH_INSTALL_DIR/zeronet
451
+        git clone "$ZERONET_REPO" "$rootdir$MESH_INSTALL_DIR/zeronet"
451
     fi
452
     fi
452
 
453
 
453
-    if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet ]; then
454
+    if [ ! -d "$rootdir$MESH_INSTALL_DIR/zeronet" ]; then
454
         echo 'WARNING: Unable to clone zeronet'
455
         echo 'WARNING: Unable to clone zeronet'
455
         return
456
         return
456
     fi
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
     else
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
     fi
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
     # Hack to ensure that the file access port is opened
467
     # Hack to ensure that the file access port is opened
467
     # This is because zeronet normally relies on an internet site
468
     # This is because zeronet normally relies on an internet site
468
     # to do this, but on a purely local mesh the internet isn't available
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
     ZERONET_DAEMON=$rootdir/etc/systemd/system/zeronet.service
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
     TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
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
     # publish regularly
512
     # publish regularly
512
     MESH_SYNC_COMMAND=$rootdir/usr/bin/mesh-sync
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
     fi
523
     fi
523
 
524
 
524
     chroot "$rootdir" systemctl enable tracker.service
525
     chroot "$rootdir" systemctl enable tracker.service
526
 }
527
 }
527
 
528
 
528
 function mesh_zeronet_blog {
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
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
533
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
533
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
534
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
534
     fi
535
     fi
535
-    if [ ! $MESH_INSTALL_DIR ]; then
536
+    if [ ! "$MESH_INSTALL_DIR" ]; then
536
         echo $'No mesh install dir was specified'
537
         echo $'No mesh install dir was specified'
537
         exit 432052
538
         exit 432052
538
     fi
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
         echo $'ZeroBlog repo could not be cloned'
543
         echo $'ZeroBlog repo could not be cloned'
543
         exit 6739
544
         exit 6739
544
     fi
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
 function mesh_zeronet_mail {
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
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
555
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
555
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
556
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
556
     fi
557
     fi
557
-    if [ ! $MESH_INSTALL_DIR ]; then
558
+    if [ ! "$MESH_INSTALL_DIR" ]; then
558
         echo $'No mesh install dir was specified'
559
         echo $'No mesh install dir was specified'
559
         exit 432052
560
         exit 432052
560
     fi
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
         echo $'ZeroMail repo could not be cloned'
565
         echo $'ZeroMail repo could not be cloned'
565
         exit 78493
566
         exit 78493
566
     fi
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
 function mesh_zeronet_forum {
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
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
577
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
577
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
578
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
578
     fi
579
     fi
579
-    if [ ! $MESH_INSTALL_DIR ]; then
580
+    if [ ! "$MESH_INSTALL_DIR" ]; then
580
         echo $'No mesh install dir was specified'
581
         echo $'No mesh install dir was specified'
581
         exit 432052
582
         exit 432052
582
     fi
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
         echo $'ZeroTalk repo could not be cloned'
587
         echo $'ZeroTalk repo could not be cloned'
587
         exit 78252
588
         exit 78252
588
     fi
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
 function mesh_zeronet_id {
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
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
599
     if [ ${#MESH_INSTALL_DIR_MAIN} -gt 4 ]; then
599
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
600
         MESH_INSTALL_DIR=$MESH_INSTALL_DIR_MAIN
600
     fi
601
     fi
601
-    if [ ! $MESH_INSTALL_DIR ]; then
602
+    if [ ! "$MESH_INSTALL_DIR" ]; then
602
         echo $'No mesh install dir was specified'
603
         echo $'No mesh install dir was specified'
603
         exit 432052
604
         exit 432052
604
     fi
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
         echo $'ZeroID repo could not be cloned'
609
         echo $'ZeroID repo could not be cloned'
609
         exit 37936
610
         exit 37936
610
     fi
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
 function install_zeronet {
617
 function install_zeronet {
617
-    if [ $INSTALLING_MESH ]; then
618
+    if [ "$INSTALLING_MESH" ]; then
618
         mesh_zeronet
619
         mesh_zeronet
619
         mesh_zeronet_blog
620
         mesh_zeronet_blog
620
         mesh_zeronet_mail
621
         mesh_zeronet_mail

+ 8
- 8
src/freedombone-archive-mail Целия файл

33
 export TEXTDOMAIN=${PROJECT_NAME}-archive-mail
33
 export TEXTDOMAIN=${PROJECT_NAME}-archive-mail
34
 export TEXTDOMAINDIR="/usr/share/locale"
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
 for d in /home/*/ ; do
38
 for d in /home/*/ ; do
39
     USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
39
     USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
40
     if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
40
     if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
41
         # for every user who has a mail directory
41
         # for every user who has a mail directory
42
-        if [ -d /home/$USERNAME/Maildir ]; then
42
+        if [ -d "/home/$USERNAME/Maildir" ]; then
43
             MUTTRC=/home/$USERNAME/.muttrc
43
             MUTTRC=/home/$USERNAME/.muttrc
44
             # update archives
44
             # update archives
45
             python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""
45
             python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""
46
             # ensure the user has permissions on the archives
46
             # ensure the user has permissions on the archives
47
             for archive_dir in /home/$USERNAME/Maildir/archive-* ; do
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
             done
49
             done
50
             # add the archive to .muttrc if needed
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
                 YR=$(date +"%Y")
53
                 YR=$(date +"%Y")
54
                 PREV_YR=$((YR - 1))
54
                 PREV_YR=$((YR - 1))
55
                 BACKUP_DIRECTORY=archive-$YR
55
                 BACKUP_DIRECTORY=archive-$YR
56
                 PREV_BACKUP_DIRECTORY=archive-$PREV_YR
56
                 PREV_BACKUP_DIRECTORY=archive-$PREV_YR
57
                 if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
57
                 if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
58
                     if [[ $MUTT_MAILBOXES == *$PREV_BACKUP_DIRECTORY* ]]; then
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
                     else
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
                     fi
62
                     fi
63
-                    chown $USERNAME:$USERNAME $MUTTRC
63
+                    chown "$USERNAME":"$USERNAME" "$MUTTRC"
64
                 fi
64
                 fi
65
             fi
65
             fi
66
         fi
66
         fi

+ 61
- 60
src/freedombone-backup-local Целия файл

59
 
59
 
60
 please_wait
60
 please_wait
61
 
61
 
62
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
62
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
63
 
63
 
64
 # include utils which allow function_check and drive mount
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
 for f in $UTILS_FILES
66
 for f in $UTILS_FILES
67
 do
67
 do
68
-  source $f
68
+    source "$f"
69
 done
69
 done
70
 
70
 
71
 clear
71
 clear
82
 # Sites are suspended so that verification should work
82
 # Sites are suspended so that verification should work
83
 SUSPENDED_SITE=
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
 function make_backup_directory {
87
 function make_backup_directory {
88
     # make a backup directory on the drive
88
     # make a backup directory on the drive
100
 function check_storage_space_remaining {
100
 function check_storage_space_remaining {
101
     # Check space remaining on the usb drive
101
     # Check space remaining on the usb drive
102
     used_percent=$(df -k $USB_MOUNT | tail -n 1 | awk -F ' ' '{print $5}' | awk -F '%' '{print $1}')
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
         echo $"Less than 5% of space remaining on backup drive"
104
         echo $"Less than 5% of space remaining on backup drive"
105
         umount $USB_MOUNT
105
         umount $USB_MOUNT
106
         rm -rf $USB_MOUNT
106
         rm -rf $USB_MOUNT
114
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
114
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
115
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
115
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
116
             # Backup any gpg keys
116
             # Backup any gpg keys
117
-            if [ -d /home/$USERNAME/.gnupg ]; then
117
+            if [ -d "/home/$USERNAME/.gnupg" ]; then
118
                 echo $"Backing up gpg keys for $USERNAME"
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
             fi
120
             fi
121
 
121
 
122
             # Backup any personal settings
122
             # Backup any personal settings
123
-            if [ -d /home/$USERNAME/personal ]; then
123
+            if [ -d "/home/$USERNAME/personal" ]; then
124
                 echo $"Backing up personal settings for $USERNAME"
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
             fi
126
             fi
127
 
127
 
128
             # Backup ssh keys
128
             # Backup ssh keys
129
-            if [ -d /home/$USERNAME/.ssh ]; then
129
+            if [ -d "/home/$USERNAME/.ssh" ]; then
130
                 echo $"Backing up ssh keys for $USERNAME"
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
             fi
132
             fi
133
 
133
 
134
             # Backup fin database if it exists
134
             # Backup fin database if it exists
135
-            if [ -d /home/$USERNAME/.fin ]; then
135
+            if [ -d "/home/$USERNAME/.fin" ]; then
136
                 echo $"Backing up fin files for $USERNAME"
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
             fi
138
             fi
139
 
139
 
140
             # Backup emacs
140
             # Backup emacs
141
-            if [ -d /home/$USERNAME/.emacs.d ]; then
141
+            if [ -d "/home/$USERNAME/.emacs.d" ]; then
142
                 echo $"Backing up Emacs config for $USERNAME"
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
                 fi
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
             fi
147
             fi
148
 
148
 
149
             # Backup user configs
149
             # Backup user configs
150
-            if [ -d /home/$USERNAME/.config ]; then
150
+            if [ -d "/home/$USERNAME/.config" ]; then
151
                 echo $"Backing up config files for $USERNAME"
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
             fi
153
             fi
154
 
154
 
155
             # Backup monkeysphere
155
             # Backup monkeysphere
156
-            if [ -d /home/$USERNAME/.monkeysphere ]; then
156
+            if [ -d "/home/$USERNAME/.monkeysphere" ]; then
157
                 echo $"Backing up monkeysphere files for $USERNAME"
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
             fi
159
             fi
160
 
160
 
161
             # Backup user local
161
             # Backup user local
162
-            if [ -d /home/$USERNAME/.local ]; then
162
+            if [ -d "/home/$USERNAME/.local" ]; then
163
                 echo $"Backing up local files for $USERNAME"
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
             fi
165
             fi
166
 
166
 
167
             # Backup mutt
167
             # Backup mutt
168
-            if [ -f /home/$USERNAME/.muttrc ]; then
168
+            if [ -f "/home/$USERNAME/.muttrc" ]; then
169
                 echo $"Backing up Mutt settings for $USERNAME"
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
                 fi
172
                 fi
173
-                cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
173
+                cp "/home/$USERNAME/.muttrc" "/home/$USERNAME/tempbackup"
174
                 if [ -f /etc/Muttrc ]; then
174
                 if [ -f /etc/Muttrc ]; then
175
-                    cp /etc/Muttrc /home/$USERNAME/tempbackup
175
+                    cp /etc/Muttrc "/home/$USERNAME/tempbackup"
176
                 fi
176
                 fi
177
-                backup_directory_to_usb /home/$USERNAME/tempbackup mutt/$USERNAME
177
+                backup_directory_to_usb "/home/$USERNAME/tempbackup" "mutt/$USERNAME"
178
             fi
178
             fi
179
-            if [ -d /home/$USERNAME/.mutt ]; then
179
+            if [ -d "/home/$USERNAME/.mutt" ]; then
180
                 echo $"Backing up Mutt configurations for $USERNAME"
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
             fi
182
             fi
183
 
183
 
184
             # Backup email
184
             # Backup email
185
-            if [ -d /home/$USERNAME/Maildir ]; then
185
+            if [ -d "/home/$USERNAME/Maildir" ]; then
186
                 echo $"Stopping mail server"
186
                 echo $"Stopping mail server"
187
                 systemctl stop exim4
187
                 systemctl stop exim4
188
                 echo $"Creating an email archive for $USERNAME"
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
                 fi
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
                 echo $"Restarting mail server"
193
                 echo $"Restarting mail server"
194
                 systemctl start exim4
194
                 systemctl start exim4
195
                 echo $"Backing up emails for $USERNAME"
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
             fi
197
             fi
198
 
198
 
199
             # Backup spamassassin
199
             # Backup spamassassin
200
-            if [ -d /home/$USERNAME/.spamassassin ]; then
200
+            if [ -d "/home/$USERNAME/.spamassassin" ]; then
201
                 echo $"Backing up spamassassin settings for $USERNAME"
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
             fi
203
             fi
204
 
204
 
205
             # Backup procmail
205
             # Backup procmail
206
-            if [ -f /home/$USERNAME/.procmailrc ]; then
206
+            if [ -f "/home/$USERNAME/.procmailrc" ]; then
207
                 echo $"Backing up procmail settings for $USERNAME"
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
                 fi
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
             fi
213
             fi
214
 
214
 
215
-            gpg_agent_enable $USERNAME
215
+            gpg_agent_enable "$USERNAME"
216
         fi
216
         fi
217
     done
217
     done
218
 }
218
 }
231
     for dr in "${backup_dirs[@]}"
231
     for dr in "${backup_dirs[@]}"
232
     do
232
     do
233
         # if this directory exists then back it up to the given destination
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
             echo $"Backing up $source_directory to $dest_directory"
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
         fi
239
         fi
240
 
240
 
241
         restart_site
241
         restart_site
243
 }
243
 }
244
 
244
 
245
 function remove_backup_directory {
245
 function remove_backup_directory {
246
-    if [ $1 ]; then
247
-        if [[ $1 == "remove" ]]; then
246
+    if [ "$1" ]; then
247
+        if [[ "$1" == "remove" ]]; then
248
             if [ -d $USB_MOUNT/backup ]; then
248
             if [ -d $USB_MOUNT/backup ]; then
249
                 rm -rf $USB_MOUNT/backup
249
                 rm -rf $USB_MOUNT/backup
250
                 echo $'Existing backup directory removed'
250
                 echo $'Existing backup directory removed'
274
     if [ ! -d $temp_backup_dir ]; then
274
     if [ ! -d $temp_backup_dir ]; then
275
         mkdir -p $temp_backup_dir
275
         mkdir -p $temp_backup_dir
276
     fi
276
     fi
277
-    if [ -f $NODEJS_INSTALLED_APPS_FILE ]; then
277
+    if [ -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
278
         cp -f /root/${PROJECT_NAME}-firewall-domains.cfg $temp_backup_dir
278
         cp -f /root/${PROJECT_NAME}-firewall-domains.cfg $temp_backup_dir
279
     fi
279
     fi
280
     backup_directory_to_usb $temp_backup_dir blocklist
280
     backup_directory_to_usb $temp_backup_dir blocklist
287
     if [ ! -d $temp_backup_dir ]; then
287
     if [ ! -d $temp_backup_dir ]; then
288
         mkdir -p $temp_backup_dir
288
         mkdir -p $temp_backup_dir
289
     fi
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
     fi
292
     fi
293
     if [ -f /root/.nostore ]; then
293
     if [ -f /root/.nostore ]; then
294
         cp -f /root/.nostore $temp_backup_dir
294
         cp -f /root/.nostore $temp_backup_dir
297
             rm $temp_backup_dir/.nostore
297
             rm $temp_backup_dir/.nostore
298
         fi
298
         fi
299
     fi
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
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
302
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
303
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
303
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
304
     fi
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
     fi
307
     fi
308
     # nginx password hashes
308
     # nginx password hashes
309
     if [ -f /etc/nginx/.htpasswd ]; then
309
     if [ -f /etc/nginx/.htpasswd ]; then
355
     if [ ! -d $temp_backup_dir ]; then
355
     if [ ! -d $temp_backup_dir ]; then
356
         mkdir $temp_backup_dir
356
         mkdir $temp_backup_dir
357
     fi
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
     if [ ! -s $temp_backup_dir/postgresql.sql ]; then
360
     if [ ! -s $temp_backup_dir/postgresql.sql ]; then
360
         echo $"Unable to backup postgresql settings"
361
         echo $"Unable to backup postgresql settings"
361
         rm -rf $temp_backup_dir
362
         rm -rf $temp_backup_dir
375
 fi
376
 fi
376
 
377
 
377
 gpg_agent_setup root
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
 make_backup_directory
381
 make_backup_directory
381
 check_storage_space_remaining
382
 check_storage_space_remaining
382
 backup_users
383
 backup_users

+ 93
- 91
src/freedombone-backup-remote Целия файл

43
     PROJECT_INSTALL_DIR=/usr/bin
43
     PROJECT_INSTALL_DIR=/usr/bin
44
 fi
44
 fi
45
 
45
 
46
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
46
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
47
 
47
 
48
 # utilities needed for backup commands
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
 for f in $UTILS_FILES
50
 for f in $UTILS_FILES
51
 do
51
 do
52
-  source $f
52
+    source "$f"
53
 done
53
 done
54
 
54
 
55
 # Temporary location for data to be backed up to other servers
55
 # Temporary location for data to be backed up to other servers
56
 SERVER_DIRECTORY=/root/remotebackup
56
 SERVER_DIRECTORY=/root/remotebackup
57
 
57
 
58
 # get the version of Go being used
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
 ADMIN_USERNAME=$(get_completion_param "Admin user")
61
 ADMIN_USERNAME=$(get_completion_param "Admin user")
62
 ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
62
 ADMIN_NAME=$(getent passwd $ADMIN_USERNAME | cut -d: -f5 | cut -d, -f1)
66
     ${PROJECT_NAME}-addcert -h backup --dhkey 2048
66
     ${PROJECT_NAME}-addcert -h backup --dhkey 2048
67
 fi
67
 fi
68
 
68
 
69
-if [ ! -f /home/${ADMIN_USERNAME}/backup.list ]; then
69
+if [ ! -f "/home/${ADMIN_USERNAME}/backup.list" ]; then
70
     exit 1
70
     exit 1
71
 fi
71
 fi
72
 
72
 
92
         return
92
         return
93
     fi
93
     fi
94
     SUSPENDED_SITE="$1"
94
     SUSPENDED_SITE="$1"
95
-    nginx_dissite $SUSPENDED_SITE
95
+    nginx_dissite "$SUSPENDED_SITE"
96
     systemctl reload nginx
96
     systemctl reload nginx
97
 }
97
 }
98
 
98
 
99
 function restart_site {
99
 function restart_site {
100
     # restarts a given website
100
     # restarts a given website
101
-    if [ ! $SUSPENDED_SITE ]; then
101
+    if [ ! "$SUSPENDED_SITE" ]; then
102
         return
102
         return
103
     fi
103
     fi
104
-    nginx_ensite $SUSPENDED_SITE
104
+    nginx_ensite "$SUSPENDED_SITE"
105
     systemctl reload nginx
105
     systemctl reload nginx
106
     SUSPENDED_SITE=
106
     SUSPENDED_SITE=
107
 }
107
 }
115
     if [ ! -d $temp_backup_dir ]; then
115
     if [ ! -d $temp_backup_dir ]; then
116
         mkdir -p $temp_backup_dir
116
         mkdir -p $temp_backup_dir
117
     fi
117
     fi
118
-    if [ -f $NODEJS_INSTALLED_APPS_FILE ]; then
118
+    if [ -f "$NODEJS_INSTALLED_APPS_FILE" ]; then
119
         cp -f /root/${PROJECT_NAME}-firewall-domains.cfg $temp_backup_dir
119
         cp -f /root/${PROJECT_NAME}-firewall-domains.cfg $temp_backup_dir
120
     fi
120
     fi
121
     backup_directory_to_friend $temp_backup_dir blocklist
121
     backup_directory_to_friend $temp_backup_dir blocklist
128
     if [ ! -d $temp_backup_dir ]; then
128
     if [ ! -d $temp_backup_dir ]; then
129
         mkdir -p $temp_backup_dir
129
         mkdir -p $temp_backup_dir
130
     fi
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
     fi
133
     fi
134
     if [ -f /root/.nostore ]; then
134
     if [ -f /root/.nostore ]; then
135
         cp -f /root/.nostore $temp_backup_dir
135
         cp -f /root/.nostore $temp_backup_dir
138
             rm $temp_backup_dir/.nostore
138
             rm $temp_backup_dir/.nostore
139
         fi
139
         fi
140
     fi
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
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
143
     if [ -f $BACKUP_EXTRA_DIRECTORIES ]; then
144
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
144
         cp -f $BACKUP_EXTRA_DIRECTORIES $temp_backup_dir
145
     fi
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
     fi
148
     fi
149
     # nginx password hashes
149
     # nginx password hashes
150
     if [ -f /etc/nginx/.htpasswd ]; then
150
     if [ -f /etc/nginx/.htpasswd ]; then
158
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
158
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
159
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
159
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
160
             # personal settings
160
             # personal settings
161
-            if [ -d /home/$USERNAME/personal ]; then
161
+            if [ -d "/home/$USERNAME/personal" ]; then
162
                 echo $"Backing up personal settings for $USERNAME"
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
             fi
164
             fi
165
 
165
 
166
             # gpg keys
166
             # gpg keys
167
-            if [ -d /home/$USERNAME/.gnupg ]; then
167
+            if [ -d "/home/$USERNAME/.gnupg" ]; then
168
                 echo $"Backing up gpg keys for $USERNAME"
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
             fi
170
             fi
171
 
171
 
172
             # ssh keys
172
             # ssh keys
173
-            if [ -d /home/$USERNAME/.ssh ]; then
173
+            if [ -d "/home/$USERNAME/.ssh" ]; then
174
                 echo $"Backing up ssh keys for $USERNAME"
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
             fi
176
             fi
177
 
177
 
178
             # syncthing files
178
             # syncthing files
179
-            if [ -d /home/$USERNAME/Sync ]; then
179
+            if [ -d "/home/$USERNAME/Sync" ]; then
180
                 echo $"Backing up syncthing files for $USERNAME"
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
                 # ensure that device IDs will be backed up as part of user config settings
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
                 fi
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
                 fi
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
                 fi
194
                 fi
195
             fi
195
             fi
196
 
196
 
197
             # config files
197
             # config files
198
-            if [ -d /home/$USERNAME/.config ]; then
198
+            if [ -d "/home/$USERNAME/.config" ]; then
199
                 echo $"Backing up config files for $USERNAME"
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
             fi
201
             fi
202
 
202
 
203
             # monkeysphere files
203
             # monkeysphere files
204
-            if [ -d /home/$USERNAME/.monkeysphere ]; then
204
+            if [ -d "/home/$USERNAME/.monkeysphere" ]; then
205
                 echo $"Backing up monkeysphere files for $USERNAME"
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
             fi
207
             fi
208
 
208
 
209
             # fin files
209
             # fin files
210
-            if [ -d /home/$USERNAME/.fin ]; then
210
+            if [ -d "/home/$USERNAME/.fin" ]; then
211
                 echo $"Backing up fin files for $USERNAME"
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
             fi
213
             fi
214
 
214
 
215
             # local files
215
             # local files
216
-            if [ -d /home/$USERNAME/.local ]; then
216
+            if [ -d "/home/$USERNAME/.local" ]; then
217
                 echo $"Backing up local files for $USERNAME"
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
             fi
219
             fi
220
 
220
 
221
             # mutt settings
221
             # mutt settings
222
-            if [ -f /home/$USERNAME/.muttrc ]; then
222
+            if [ -f "/home/$USERNAME/.muttrc" ]; then
223
                 echo $"Backing up Mutt settings for $USERNAME"
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
                 fi
226
                 fi
227
-                cp /home/$USERNAME/.muttrc /home/$USERNAME/tempbackup
227
+                cp "/home/$USERNAME/.muttrc" "/home/$USERNAME/tempbackup"
228
                 if [ -f /etc/Muttrc ]; then
228
                 if [ -f /etc/Muttrc ]; then
229
-                    cp /etc/Muttrc /home/$USERNAME/tempbackup
229
+                    cp /etc/Muttrc "/home/$USERNAME/tempbackup"
230
                 fi
230
                 fi
231
-                backup_directory_to_friend /home/$USERNAME/tempbackup mutt/$USERNAME
231
+                backup_directory_to_friend "/home/$USERNAME/tempbackup" "mutt/$USERNAME"
232
             fi
232
             fi
233
-            if [ -d /home/$USERNAME/.mutt ]; then
233
+            if [ -d "/home/$USERNAME/.mutt" ]; then
234
                 echo $"Backing up Mutt configurations for $USERNAME"
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
             fi
236
             fi
237
 
237
 
238
             # procmail settings
238
             # procmail settings
239
-            if [ -f /home/$USERNAME/.procmailrc ]; then
239
+            if [ -f "/home/$USERNAME/.procmailrc" ]; then
240
                 echo $"Backing up procmail settings for $USERNAME"
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
                 fi
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
             fi
246
             fi
247
 
247
 
248
             # spamassassin settings
248
             # spamassassin settings
249
-            if [ -d /home/$USERNAME/.spamassassin ]; then
249
+            if [ -d "/home/$USERNAME/.spamassassin" ]; then
250
                 echo $"Backing up spamassassin settings for $USERNAME"
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
             fi
252
             fi
253
 
253
 
254
             # email
254
             # email
255
-            if [ -d /home/$USERNAME/Maildir ]; then
255
+            if [ -d "/home/$USERNAME/Maildir" ]; then
256
                 echo $"Stopping mail server"
256
                 echo $"Stopping mail server"
257
                 systemctl stop exim4
257
                 systemctl stop exim4
258
                 echo $"Creating an email archive"
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
                 fi
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
                 echo $"Restarting mail server"
263
                 echo $"Restarting mail server"
264
                 systemctl start exim4
264
                 systemctl start exim4
265
                 echo $"Backing up emails for $USERNAME"
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
             fi
267
             fi
268
-            gpg_agent_enable $USERNAME
268
+            gpg_agent_enable "$USERNAME"
269
         fi
269
         fi
270
     done
270
     done
271
 }
271
 }
313
 }
313
 }
314
 
314
 
315
 function backup_admin_readme {
315
 function backup_admin_readme {
316
-    if [ -f /home/$ADMIN_USERNAME/README ]; then
316
+    if [ -f "/home/$ADMIN_USERNAME/README" ]; then
317
         echo $"Backing up README"
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
         fi
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
     fi
323
     fi
324
 }
324
 }
325
 
325
 
330
             mkdir $temp_backup_dir
330
             mkdir $temp_backup_dir
331
         fi
331
         fi
332
         keep_database_running
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
         if [ ! -s $temp_backup_dir/mysql.sql ]; then
334
         if [ ! -s $temp_backup_dir/mysql.sql ]; then
335
             echo $"Unable to backup MariaDB settings"
335
             echo $"Unable to backup MariaDB settings"
336
             rm -rf $temp_backup_dir
336
             rm -rf $temp_backup_dir
337
             # Send a warning email
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
             exit 653
339
             exit 653
340
         fi
340
         fi
341
         echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
341
         echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
353
     if [ ! -d $temp_backup_dir ]; then
353
     if [ ! -d $temp_backup_dir ]; then
354
         mkdir $temp_backup_dir
354
         mkdir $temp_backup_dir
355
     fi
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
     if [ ! -s $temp_backup_dir/postgresql.sql ]; then
358
     if [ ! -s $temp_backup_dir/postgresql.sql ]; then
358
         echo $"Unable to backup postgresql settings"
359
         echo $"Unable to backup postgresql settings"
359
         rm -rf $temp_backup_dir
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
         exit 684365
363
         exit 684365
363
     fi
364
     fi
364
     echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
365
     echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
375
     # Get a share index based on the supplied domain name
376
     # Get a share index based on the supplied domain name
376
     # This ensures that the same share is always given to the same domain
377
     # This ensures that the same share is always given to the same domain
377
     sharenumstr=$(md5sum <<< "$REMOTE_DOMAIN")
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
     # get the filename
381
     # get the filename
381
-    share_files=(/home/$USERNAME/.gnupg_fragments/keyshare.asc.*)
382
+    share_files=("/home/$USERNAME/.gnupg_fragments/keyshare.asc.*")
382
     share_filename=${share_files[share_index]}
383
     share_filename=${share_files[share_index]}
383
 
384
 
384
     echo "$share_filename"
385
     echo "$share_filename"
391
     REMOTE_PASSWORD=$4
392
     REMOTE_PASSWORD=$4
392
     REMOTE_SERVER=$5
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
             no_of_shares=$(ls -afq keyshare.asc.* | wc -l)
399
             no_of_shares=$(ls -afq keyshare.asc.* | wc -l)
398
             if (( no_of_shares > 1 )); then
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
                 # create a temp directory containing the share
403
                 # create a temp directory containing the share
402
                 temp_key_share_dir=/home/$USERNAME/tempkey
404
                 temp_key_share_dir=/home/$USERNAME/tempkey
403
                 temp_key_share_fragments=$temp_key_share_dir/.gnupg_fragments_${USERNAME}
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
                 # copy the fragments directory to the remote server
409
                 # copy the fragments directory to the remote server
408
                 /usr/bin/sshpass -p "$REMOTE_PASSWORD" \
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
                 if [ ! "$?" = "0" ]; then
413
                 if [ ! "$?" = "0" ]; then
411
                     # Send a warning email
414
                     # Send a warning email
412
                     echo "Key share to $REMOTE_SERVER failed" | \
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
                 else
417
                 else
415
                     # Send a confirmation email
418
                     # Send a confirmation email
416
                     echo "Key ${share_filename} shared to $REMOTE_SERVER" | \
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
                 fi
421
                 fi
419
 
422
 
420
                 # remove the temp file/directory
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
             fi
426
             fi
424
         fi
427
         fi
425
     fi
428
     fi
449
 fi
452
 fi
450
 
453
 
451
 # For each remote server
454
 # For each remote server
452
-while read remote_server
455
+while read -r remote_server
453
 do
456
 do
454
     # Get the server and its password
457
     # Get the server and its password
455
     # Format is:
458
     # Format is:
456
     #   username@domain <port number> /home/username <ssh password>
459
     #   username@domain <port number> /home/username <ssh password>
457
     REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}')
460
     REMOTE_SERVER=$(echo "${remote_server}" | awk -F ' ' '{print $1}')
458
-    if [ $REMOTE_SERVER ]; then
461
+    if [ "$REMOTE_SERVER" ]; then
459
         REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}')
462
         REMOTE_DOMAIN=$(echo "${remote_server}" | awk -F ' ' '{print $1}' | awk -F '@' '{print $2}')
460
         REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
463
         REMOTE_SSH_PORT=$(echo "${remote_server}" | awk -F ' ' '{print $2}')
461
         REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
464
         REMOTE_DIRECTORY=$(echo "${remote_server}" | awk -F ' ' '{print $3}')
469
         for d in /home/*/ ; do
472
         for d in /home/*/ ; do
470
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
473
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
471
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
             fi
476
             fi
474
         done
477
         done
475
 
478
 
476
         if [[ $TEST_MODE == "yes" ]]; then
479
         if [[ $TEST_MODE == "yes" ]]; then
477
             echo "rsync -ratlzv --rsh=\"/usr/bin/sshpass -p '$REMOTE_PASSWORD' ssh -p $REMOTE_SSH_PORT -o StrictHostKeyChecking=no\" $SERVER_DIRECTORY/backup $REMOTE_SERVER"
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
         fi
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
             echo "$NOW Backup to $REMOTE_SERVER failed" >> /var/log/remotebackups.log
483
             echo "$NOW Backup to $REMOTE_SERVER failed" >> /var/log/remotebackups.log
482
             # Send a warning email
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
         else
486
         else
485
             echo "$NOW Backed up to $REMOTE_SERVER" >> /var/log/remotebackups.log
487
             echo "$NOW Backed up to $REMOTE_SERVER" >> /var/log/remotebackups.log
486
         fi
488
         fi
487
     fi
489
     fi
488
 
490
 
489
-done < /home/${ADMIN_USERNAME}/backup.list
491
+done < "/home/${ADMIN_USERNAME}/backup.list"
490
 
492
 
491
 exit 0
493
 exit 0

+ 560
- 620
src/freedombone-base-email
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 28
- 28
src/freedombone-base-tripwire Целия файл

37
 }
37
 }
38
 
38
 
39
 function remove_tripwire {
39
 function remove_tripwire {
40
-    if ! grep -Fxq "tripwire" $COMPLETION_FILE; then
40
+    if ! grep -Fxq "tripwire" "$COMPLETION_FILE"; then
41
         return
41
         return
42
     fi
42
     fi
43
     apt-get -yq remove --purge tripwire
43
     apt-get -yq remove --purge tripwire
45
         rm -rf /etc/tripwire
45
         rm -rf /etc/tripwire
46
     fi
46
     fi
47
     rm /usr/bin/reset-tripwire
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
 function install_tripwire {
51
 function install_tripwire {
60
 
60
 
61
     apt-get -yq install tripwire qrencode
61
     apt-get -yq install tripwire qrencode
62
     apt-get -yq autoremove
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
     echo '
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
     echo '
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
     # make a script for easy resetting of the tripwire
93
     # make a script for easy resetting of the tripwire
94
     echo '#!/bin/sh' > /usr/bin/reset-tripwire
94
     echo '#!/bin/sh' > /usr/bin/reset-tripwire
137
     sed -i '/\/usr\/local\/bin/d' /etc/tripwire/twpol.txt
137
     sed -i '/\/usr\/local\/bin/d' /etc/tripwire/twpol.txt
138
 
138
 
139
     # Avoid logging the changed database
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
     # site key name
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
     # create the policy
144
     # create the policy
145
     echo '
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
     mark_completed "${FUNCNAME[0]}"
149
     mark_completed "${FUNCNAME[0]}"
150
 }
150
 }

+ 52
- 51
src/freedombone-client Целия файл

55
 fi
55
 fi
56
 
56
 
57
 # ssh (from https://stribika.github.io/2015/01/04/secure-secure-shell.html)
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
 # refresh gpg keys every few hours
64
 # refresh gpg keys every few hours
65
 REFRESH_GPG_KEYS_HOURS=2
65
 REFRESH_GPG_KEYS_HOURS=2
74
     fi
74
     fi
75
 
75
 
76
     sudo cp $SYSCTL_FILE ~/sysctl.conf
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
     if ! grep -q "tcp_challenge_ack_limit" ~/sysctl.conf; then
78
     if ! grep -q "tcp_challenge_ack_limit" ~/sysctl.conf; then
79
         echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> ~/sysctl.conf
79
         echo 'net.ipv4.tcp_challenge_ack_limit = 999999999' >> ~/sysctl.conf
80
     else
80
     else
94
         fi
94
         fi
95
     fi
95
     fi
96
     sudo cp /etc/crontab ~/temp_crontab
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
     if ! grep -q 'gpg --refresh-keys' ~/temp_crontab; then
98
     if ! grep -q 'gpg --refresh-keys' ~/temp_crontab; then
99
         echo "0            */$REFRESH_GPG_KEYS_HOURS *   *   *   $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
99
         echo "0            */$REFRESH_GPG_KEYS_HOURS *   *   *   $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
100
         sudo cp ~/temp_crontab /etc/crontab
100
         sudo cp ~/temp_crontab /etc/crontab
105
 
105
 
106
 # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
106
 # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
107
 function ssh_remove_small_moduli {
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
 function configure_ssh_client {
113
 function configure_ssh_client {
124
     sudo sed -i "s/HostKeyAlgorithms.*/HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
125
     sudo sed -i "s/HostKeyAlgorithms.*/HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS/g" /etc/ssh/ssh_config
125
     if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
126
     if ! grep -q "HostKeyAlgorithms" /etc/ssh/ssh_config; then
126
         sudo cp /etc/ssh/ssh_config ~/ssh_config
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
         echo "   HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
129
         echo "   HostKeyAlgorithms $SSH_HOST_KEY_ALGORITHMS" >> ~/ssh_config
129
         sudo mv ~/ssh_config /etc/ssh/ssh_config
130
         sudo mv ~/ssh_config /etc/ssh/ssh_config
130
         sudo chown root:root /etc/ssh/ssh_config
131
         sudo chown root:root /etc/ssh/ssh_config
134
     sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
135
     sudo sed -i "s/Ciphers.*/Ciphers $SSH_CIPHERS/g" /etc/ssh/ssh_config
135
     if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
136
     if ! grep -q "Ciphers " /etc/ssh/ssh_config; then
136
         sudo cp /etc/ssh/ssh_config ~/ssh_config
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
         echo "   Ciphers $SSH_CIPHERS" >> ~/ssh_config
139
         echo "   Ciphers $SSH_CIPHERS" >> ~/ssh_config
139
         sudo mv ~/ssh_config /etc/ssh/ssh_config
140
         sudo mv ~/ssh_config /etc/ssh/ssh_config
140
         sudo chown root:root /etc/ssh/ssh_config
141
         sudo chown root:root /etc/ssh/ssh_config
142
     sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
143
     sudo sed -i "s/MACs.*/MACs $SSH_MACS/g" /etc/ssh/ssh_config
143
     if ! grep -q "MACs " /etc/ssh/ssh_config; then
144
     if ! grep -q "MACs " /etc/ssh/ssh_config; then
144
         sudo cp /etc/ssh/ssh_config ~/ssh_config
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
         echo "   MACs $SSH_MACS" >> ~/ssh_config
147
         echo "   MACs $SSH_MACS" >> ~/ssh_config
147
         sudo mv ~/ssh_config /etc/ssh/ssh_config
148
         sudo mv ~/ssh_config /etc/ssh/ssh_config
148
         sudo chown root:root /etc/ssh/ssh_config
149
         sudo chown root:root /etc/ssh/ssh_config
149
     fi
150
     fi
150
 
151
 
151
     # Create ssh keys
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
         ssh-keygen -t ed25519 -o -a 100
154
         ssh-keygen -t ed25519 -o -a 100
154
     fi
155
     fi
155
-    if [ ! -f /home/$CURR_USER/.ssh/id_rsa ]; then
156
+    if [ ! -f "/home/$CURR_USER/.ssh/id_rsa" ]; then
156
         ssh-keygen -t rsa -b 2048 -o -a 100
157
         ssh-keygen -t rsa -b 2048 -o -a 100
157
     fi
158
     fi
158
 
159
 
170
     fi
171
     fi
171
     if ! grep -q "# ${PROJECT_NAME} settings" ~/.ssh/config; then
172
     if ! grep -q "# ${PROJECT_NAME} settings" ~/.ssh/config; then
172
         if ! grep -q 'ProxyCommand' ~/.ssh/config; then
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
                 echo "  ProxyCommand sh -c 'monkeysphere ssh-proxycommand --no-connect %h %p ; $proxycmd'" >> ~/.ssh/config
180
                 echo "  ProxyCommand sh -c 'monkeysphere ssh-proxycommand --no-connect %h %p ; $proxycmd'" >> ~/.ssh/config
180
             else
181
             else
181
                 echo "  ProxyCommand $proxycmd" >> ~/.ssh/config
182
                 echo "  ProxyCommand $proxycmd" >> ~/.ssh/config
182
             fi
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
                 echo '  ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
188
                 echo '  ProxyCommand monkeysphere ssh-proxycommand %h %p' >> ~/.ssh/config
188
             fi
189
             fi
189
             echo "# ${PROJECT_NAME} settings end" >> ~/.ssh/config
190
             echo "# ${PROJECT_NAME} settings end" >> ~/.ssh/config
194
     echo $'Go to the Administrator Control Panel, select "Manage Users", '
195
     echo $'Go to the Administrator Control Panel, select "Manage Users", '
195
     echo $'"Change user ssh public key" then "yes" and paste the following:'
196
     echo $'"Change user ssh public key" then "yes" and paste the following:'
196
     echo ''
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
     echo ''
200
     echo ''
200
     echo $'Then go to "Security Settings", select "Allow ssh login with passwords"'
201
     echo $'Then go to "Security Settings", select "Allow ssh login with passwords"'
201
     echo $'and set it to "no".'
202
     echo $'and set it to "no".'
222
     else
223
     else
223
         sudo pacman -S --noconfirm hexchat tor
224
         sudo pacman -S --noconfirm hexchat tor
224
     fi
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
     fi
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
     echo $'hexchat configured'
258
     echo $'hexchat configured'
258
 }
259
 }
272
 
273
 
273
 function remove_known_hosts_entries {
274
 function remove_known_hosts_entries {
274
     # remove any previous freedombone entries from known hosts
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
     fi
278
     fi
278
 }
279
 }
279
 
280
 

+ 50
- 54
src/freedombone-clientcert Целия файл

59
 
59
 
60
 while [ $# -gt 1 ]
60
 while [ $# -gt 1 ]
61
 do
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
     shift
76
     shift
70
-    USERNAME="$1"
71
-    ;;
72
-    *)
73
-    # unknown option
74
-    ;;
75
-esac
76
-shift
77
 done
77
 done
78
 
78
 
79
-if [ ! $USERNAME ]; then
79
+if [ ! "$USERNAME" ]; then
80
     echo $'No username specified'
80
     echo $'No username specified'
81
     exit 5748
81
     exit 5748
82
 fi
82
 fi
83
 
83
 
84
-if [ ! -d /home/$USERNAME ]; then
84
+if [ ! -d "/home/$USERNAME" ]; then
85
     echo $"User $USERNAME not found"
85
     echo $"User $USERNAME not found"
86
     exit 76239
86
     exit 76239
87
 fi
87
 fi
88
 
88
 
89
-if [ -d /home/$USERNAME/emailcert ]; then
89
+if [ -d "/home/$USERNAME/emailcert" ]; then
90
     echo $'Client certs were already for created'
90
     echo $'Client certs were already for created'
91
     exit 2953
91
     exit 2953
92
 fi
92
 fi
97
 
97
 
98
 # Add a user password
98
 # Add a user password
99
 if ! grep -q "$USERNAME:{plain}" /etc/dovecot/passwd-file; then
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
 fi
101
 fi
102
 
102
 
103
 chmod 600 /etc/dovecot/passwd-file
103
 chmod 600 /etc/dovecot/passwd-file
104
 
104
 
105
 # create a user cert
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
     echo $'User certificates were not created'
109
     echo $'User certificates were not created'
110
-    rm -rf /home/$USERNAME/emailcert
110
+    rm -rf "/home/$USERNAME/emailcert"
111
     exit 74835
111
     exit 74835
112
 fi
112
 fi
113
 
113
 
114
 # create a certificate request
114
 # create a certificate request
115
 openssl req -new -sha256 -subj \
115
 openssl req -new -sha256 -subj \
116
         "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$USERNAME" \
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
     echo $'Certificate request was not created'
121
     echo $'Certificate request was not created'
122
-    rm -rf /home/$USERNAME/emailcert
122
+    rm -rf "/home/$USERNAME/emailcert"
123
     exit 83520
123
     exit 83520
124
 fi
124
 fi
125
 
125
 
126
 # sign the certificate request
126
 # sign the certificate request
127
-cd /etc/ssl
127
+cd /etc/ssl || exit 742742542
128
 openssl ca -config /etc/ssl/dovecot-ca.cnf \
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
     echo $'Authentication certificate was not created'
133
     echo $'Authentication certificate was not created'
134
-    rm -rf /home/$USERNAME/emailcert
134
+    rm -rf "/home/$USERNAME/emailcert"
135
     exit 343569
135
     exit 343569
136
 fi
136
 fi
137
 
137
 
138
 # move the cert to the user's home
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
         -password pass:""
149
         -password pass:""
150
 
150
 
151
 # make an install script
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
 # set permissions for the user
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
 echo $'Email authentication certificate created. You can obtain it on the client with:'
166
 echo $'Email authentication certificate created. You can obtain it on the client with:'
171
 echo ''
167
 echo ''

+ 169
- 134
src/freedombone-config Целия файл

43
 FREEDOMBONE_WEBSITE="https://freedombone.net or http://4fvfozz6g3zmvf76.onion"
43
 FREEDOMBONE_WEBSITE="https://freedombone.net or http://4fvfozz6g3zmvf76.onion"
44
 
44
 
45
 # Minimum number of characters in a password
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
 # file containing new password
48
 # file containing new password
49
 IMAGE_PASSWORD_FILE=/root/login.txt
49
 IMAGE_PASSWORD_FILE=/root/login.txt
118
         echo -n ''
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
 for f in $UTILS_FILES
124
 for f in $UTILS_FILES
125
 do
125
 do
126
-    source $f
126
+    source "$f"
127
 done
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
 for f in $APP_FILES
130
 for f in $APP_FILES
131
 do
131
 do
132
-    source $f
132
+    source "$f"
133
 done
133
 done
134
 
134
 
135
 function show_help {
135
 function show_help {
157
         while [ ${#MY_EMAIL_ADDRESS} -lt 5 ]
157
         while [ ${#MY_EMAIL_ADDRESS} -lt 5 ]
158
         do
158
         do
159
             EMAIL_ADDRESS=$(grep 'MY_EMAIL_ADDRESS' temp.cfg | awk -F '=' '{print $2}')
159
             EMAIL_ADDRESS=$(grep 'MY_EMAIL_ADDRESS' temp.cfg | awk -F '=' '{print $2}')
160
-            if [ ! $EMAIL_ADDRESS ]; then
160
+            if [ ! "$EMAIL_ADDRESS" ]; then
161
                 EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
161
                 EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
162
             fi
162
             fi
163
             if [ ${#MY_EMAIL_ADDRESS} -lt 5 ]; then
163
             if [ ${#MY_EMAIL_ADDRESS} -lt 5 ]; then
164
                 EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
164
                 EMAIL_ADDRESS=$MY_USERNAME@$DEFAULT_DOMAIN_NAME
165
             fi
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
             dialog --backtitle $"Freedombone Configuration" \
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
             sel=$?
170
             sel=$?
172
             case $sel in
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
             esac
177
             esac
178
+            rm -f "$data"
177
         done
179
         done
178
     fi
180
     fi
179
     save_configuration_values
181
     save_configuration_values
183
     DEFAULT_DOMAIN_DETAILS_COMPLETE=
185
     DEFAULT_DOMAIN_DETAILS_COMPLETE=
184
     while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
186
     while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
185
     do
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
         if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
189
         if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
189
             dialog --backtitle $"Freedombone Configuration" \
190
             dialog --backtitle $"Freedombone Configuration" \
190
                    --title $"Instance domain" \
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
                    $"Domain:" 1 1 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 24 33 40 \
193
                    $"Domain:" 1 1 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 24 33 40 \
193
                    $"Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 24 33 255 \
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
             sel=$?
196
             sel=$?
196
             case $sel in
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
             esac
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
                 validate_freedns_code "$DEFAULT_DOMAIN_CODE"
206
                 validate_freedns_code "$DEFAULT_DOMAIN_CODE"
204
                 if [ ! $VALID_CODE ]; then
207
                 if [ ! $VALID_CODE ]; then
205
                     DEFAULT_DOMAIN_NAME=
208
                     DEFAULT_DOMAIN_NAME=
208
         else
211
         else
209
             dialog --backtitle $"Freedombone Configuration" \
212
             dialog --backtitle $"Freedombone Configuration" \
210
                    --inputbox $"Enter your instance domain name:" 10 45 \
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
             sel=$?
215
             sel=$?
213
             case $sel in
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
             esac
222
             esac
218
         fi
223
         fi
219
-        if [ $DEFAULT_DOMAIN_NAME ]; then
224
+        if [ "$DEFAULT_DOMAIN_NAME" ]; then
220
             TEST_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME
225
             TEST_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME
221
             validate_domain_name
226
             validate_domain_name
222
-            if [[ $TEST_DOMAIN_NAME != $DEFAULT_DOMAIN_NAME ]]; then
227
+            if [[ "$TEST_DOMAIN_NAME" != "$DEFAULT_DOMAIN_NAME" ]]; then
223
                 DEFAULT_DOMAIN_NAME=
228
                 DEFAULT_DOMAIN_NAME=
224
                 dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
229
                 dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
225
             else
230
             else
226
                 DEFAULT_DOMAIN_DETAILS_COMPLETE="yes"
231
                 DEFAULT_DOMAIN_DETAILS_COMPLETE="yes"
227
             fi
232
             fi
228
         fi
233
         fi
234
+        rm -f "$data"
229
     done
235
     done
230
     save_configuration_values
236
     save_configuration_values
231
 }
237
 }
242
         DEFAULT_DOMAIN_DETAILS_COMPLETE=
248
         DEFAULT_DOMAIN_DETAILS_COMPLETE=
243
         while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
249
         while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
244
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
252
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
248
                 dialog --backtitle $"Freedombone Configuration" \
253
                 dialog --backtitle $"Freedombone Configuration" \
249
                        --title $"Your main domain name" \
254
                        --title $"Your main domain name" \
252
                        $"Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 24 33 255 \
257
                        $"Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 24 33 255 \
253
                        $"mail subdomain Code:" 3 1 "$(grep 'EMAIL_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 3 24 33 255 \
258
                        $"mail subdomain Code:" 3 1 "$(grep 'EMAIL_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 3 24 33 255 \
254
                        $"XMPP subdomain Code:" 4 1 "$(grep 'XMPP_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 24 33 255 \
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
                 sel=$?
261
                 sel=$?
257
                 case $sel in
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
                 esac
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
                     validate_freedns_code "$DEFAULT_DOMAIN_CODE"
274
                     validate_freedns_code "$DEFAULT_DOMAIN_CODE"
267
                     if [ ! $VALID_CODE ]; then
275
                     if [ ! $VALID_CODE ]; then
268
                         DEFAULT_DOMAIN_NAME=
276
                         DEFAULT_DOMAIN_NAME=
269
                     fi
277
                     fi
270
                 fi
278
                 fi
271
-                if [ $EMAIL_DOMAIN_CODE ]; then
279
+                if [ "$EMAIL_DOMAIN_CODE" ]; then
272
                     validate_freedns_code "$EMAIL_DOMAIN_CODE"
280
                     validate_freedns_code "$EMAIL_DOMAIN_CODE"
273
                     if [ ! $VALID_CODE ]; then
281
                     if [ ! $VALID_CODE ]; then
274
                         DEFAULT_DOMAIN_NAME=
282
                         DEFAULT_DOMAIN_NAME=
277
                         write_config_param "EMAIL_DOMAIN_CODE" "$EMAIL_DOMAIN_CODE"
285
                         write_config_param "EMAIL_DOMAIN_CODE" "$EMAIL_DOMAIN_CODE"
278
                     fi
286
                     fi
279
                 fi
287
                 fi
280
-                if [ $XMPP_DOMAIN_CODE ]; then
288
+                if [ "$XMPP_DOMAIN_CODE" ]; then
281
                     validate_freedns_code "$XMPP_DOMAIN_CODE"
289
                     validate_freedns_code "$XMPP_DOMAIN_CODE"
282
                     if [ ! $VALID_CODE ]; then
290
                     if [ ! $VALID_CODE ]; then
283
                         DEFAULT_DOMAIN_NAME=
291
                         DEFAULT_DOMAIN_NAME=
289
             else
297
             else
290
                 dialog --backtitle $"Freedombone Configuration" \
298
                 dialog --backtitle $"Freedombone Configuration" \
291
                        --inputbox $"Which domain name should your email/XMPP/IRC/Mumble be associated with?" 10 45 \
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
                 sel=$?
301
                 sel=$?
294
                 case $sel in
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
                 esac
308
                 esac
299
             fi
309
             fi
300
-            if [ $DEFAULT_DOMAIN_NAME ]; then
310
+            if [ "$DEFAULT_DOMAIN_NAME" ]; then
301
                 TEST_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME
311
                 TEST_DOMAIN_NAME=$DEFAULT_DOMAIN_NAME
302
                 validate_domain_name
312
                 validate_domain_name
303
-                if [[ $TEST_DOMAIN_NAME != $DEFAULT_DOMAIN_NAME ]]; then
313
+                if [[ "$TEST_DOMAIN_NAME" != "$DEFAULT_DOMAIN_NAME" ]]; then
304
                     DEFAULT_DOMAIN_NAME=
314
                     DEFAULT_DOMAIN_NAME=
305
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
315
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
306
                 else
316
                 else
313
 }
323
 }
314
 
324
 
315
 function dynamic_dns_setup {
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
     dialog --backtitle $"Freedombone Configuration" \
327
     dialog --backtitle $"Freedombone Configuration" \
319
            --radiolist $"Choose Dynamic DNS provider:" 40 40 40 \
328
            --radiolist $"Choose Dynamic DNS provider:" 40 40 40 \
320
            1 dyn.com off \
329
            1 dyn.com off \
349
            30 strato.com off \
358
            30 strato.com off \
350
            31 freemyip.com off \
359
            31 freemyip.com off \
351
            32 cloudxns.net off \
360
            32 cloudxns.net off \
352
-           33 none off 2> $data
361
+           33 none off 2> "$data"
353
     sel=$?
362
     sel=$?
354
     case $sel in
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
     esac
368
     esac
358
-    case $(cat $data) in
369
+    case $(cat "$data") in
359
         1) DDNS_PROVIDER="default@www.dyn.com";;
370
         1) DDNS_PROVIDER="default@www.dyn.com";;
360
         2) DDNS_PROVIDER="default@freedns.afraid.org";;
371
         2) DDNS_PROVIDER="default@freedns.afraid.org";;
361
         3) DDNS_PROVIDER="default@www.zoneedit.com";;
372
         3) DDNS_PROVIDER="default@www.zoneedit.com";;
389
         31) DDNS_PROVIDER="default@freemyip.com";;
400
         31) DDNS_PROVIDER="default@freemyip.com";;
390
         32) DDNS_PROVIDER="default@www.cloudxns.net";;
401
         32) DDNS_PROVIDER="default@www.cloudxns.net";;
391
         33) DDNS_PROVIDER="none";;
402
         33) DDNS_PROVIDER="none";;
392
-        255) exit 1;;
403
+        255) rm -f "$data"
404
+             exit 1;;
393
     esac
405
     esac
406
+    rm -f "$data"
394
     save_configuration_values
407
     save_configuration_values
395
 
408
 
396
     valid_ddns_username=
409
     valid_ddns_username=
403
     else
416
     else
404
         while [ ! $valid_ddns_username ]
417
         while [ ! $valid_ddns_username ]
405
         do
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
             dialog --backtitle $"Freedombone Configuration" \
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
             sel=$?
422
             sel=$?
411
             case $sel in
423
             case $sel in
412
-                0)  possible_username=$(cat $data)
424
+                0)  possible_username=$(cat "$data")
413
                     if [ "$possible_username" ]; then
425
                     if [ "$possible_username" ]; then
414
                         if [ ${#possible_username} -gt 1 ]; then
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
                             break;
430
                             break;
418
                         fi
431
                         fi
419
                     fi
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
             esac
438
             esac
439
+            rm -f "$data"
424
         done
440
         done
425
         save_configuration_values
441
         save_configuration_values
426
 
442
 
427
         while [ ! $valid_ddns_password ]
443
         while [ ! $valid_ddns_password ]
428
         do
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
             dialog --backtitle $"Freedombone Configuration" \
446
             dialog --backtitle $"Freedombone Configuration" \
432
                    --clear \
447
                    --clear \
433
                    --insecure \
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
             sel=$?
450
             sel=$?
436
             case $sel in
451
             case $sel in
437
-                0)  possible_password=$(cat $data)
452
+                0)  possible_password=$(cat "$data")
438
                     if [ "$possible_password" ]; then
453
                     if [ "$possible_password" ]; then
439
                         if [ ${#possible_password} -gt 1 ]; then
454
                         if [ ${#possible_password} -gt 1 ]; then
440
-                            valid_ddns_password=$(cat $data)
455
+                            valid_ddns_password=$(cat "$data")
441
                             DDNS_PASSWORD=$valid_ddns_password
456
                             DDNS_PASSWORD=$valid_ddns_password
442
                             break;
457
                             break;
443
                         fi
458
                         fi
444
                     fi
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
             esac
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
                 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
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
                 DDNS_PASSWORD=""
469
                 DDNS_PASSWORD=""
452
             fi
470
             fi
458
 function choose_dynamic_dns {
476
 function choose_dynamic_dns {
459
     DDNS_PROVIDER="none"
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
         dialog --title $"Dynamic DNS" \
480
         dialog --title $"Dynamic DNS" \
463
                --backtitle $"Freedombone Configuration" \
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
         sel=$?
483
         sel=$?
466
         case $sel in
484
         case $sel in
467
             0) dynamic_dns_setup;;
485
             0) dynamic_dns_setup;;
472
 }
490
 }
473
 
491
 
474
 function choose_debian_repo {
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
         dialog --backtitle $"Freedombone Configuration" \
495
         dialog --backtitle $"Freedombone Configuration" \
479
                --radiolist $"Where to download Debian packages from:" 25 45 49 \
496
                --radiolist $"Where to download Debian packages from:" 25 45 49 \
480
                1 $"Australia" off \
497
                1 $"Australia" off \
525
                46 $"Turkey" off \
542
                46 $"Turkey" off \
526
                47 $"Ukraine" off \
543
                47 $"Ukraine" off \
527
                48 $"United Kingdom" off \
544
                48 $"United Kingdom" off \
528
-               49 $"United States" on 2> $data
545
+               49 $"United States" on 2> "$data"
529
         sel=$?
546
         sel=$?
530
         case $sel in
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
         esac
552
         esac
534
-        case $(cat $data) in
553
+        case $(cat "$data") in
535
             1) DEBIAN_REPO='ftp.au.debian.org';;
554
             1) DEBIAN_REPO='ftp.au.debian.org';;
536
             2) DEBIAN_REPO='ftp.at.debian.org';;
555
             2) DEBIAN_REPO='ftp.at.debian.org';;
537
             3) DEBIAN_REPO='ftp.by.debian.org';;
556
             3) DEBIAN_REPO='ftp.by.debian.org';;
581
             47) DEBIAN_REPO='ftp.ua.debian.org';;
600
             47) DEBIAN_REPO='ftp.ua.debian.org';;
582
             48) DEBIAN_REPO='ftp.uk.debian.org';;
601
             48) DEBIAN_REPO='ftp.uk.debian.org';;
583
             49) DEBIAN_REPO='ftp.us.debian.org';;
602
             49) DEBIAN_REPO='ftp.us.debian.org';;
584
-            255) exit 1;;
603
+            255) rm -f "$data"
604
+                 exit 1;;
585
         esac
605
         esac
606
+        rm -f "$data"
586
         save_configuration_values
607
         save_configuration_values
587
     else
608
     else
588
         DEBIAN_REPO='ftp.de.debian.org'
609
         DEBIAN_REPO='ftp.de.debian.org'
591
 
612
 
592
 function choose_rng {
613
 function choose_rng {
593
     if [[ $MINIMAL_INSTALL == "no" ]]; then
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
             dialog --backtitle $"Freedombone Configuration" \
617
             dialog --backtitle $"Freedombone Configuration" \
598
                    --radiolist $"Type of Random Number Generator:" 10 40 2 \
618
                    --radiolist $"Type of Random Number Generator:" 10 40 2 \
599
                    1 Haveged on \
619
                    1 Haveged on \
600
-                   2 OneRNG off 2> $data
620
+                   2 OneRNG off 2> "$data"
601
             sel=$?
621
             sel=$?
602
             case $sel in
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
             esac
627
             esac
606
-            case $(cat $data) in
628
+            case $(cat "$data") in
607
                 2) HWRNG_TYPE="onerng"
629
                 2) HWRNG_TYPE="onerng"
608
                    dialog --title $"OneRNG Device" \
630
                    dialog --title $"OneRNG Device" \
609
                           --msgbox $"Please ensure that the OneRNG device is disconnected. You can reconnect it later during the installation" 8 60
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
             esac
635
             esac
613
         else
636
         else
614
             HWRNG_TYPE="beaglebone"
637
             HWRNG_TYPE="beaglebone"
615
         fi
638
         fi
639
+        rm -f "$data"
616
         save_configuration_values
640
         save_configuration_values
617
     fi
641
     fi
618
 }
642
 }
621
     if [[ $MINIMAL_INSTALL == "no" ]]; then
645
     if [[ $MINIMAL_INSTALL == "no" ]]; then
622
         interactive_gpg
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
         if [[ $(grep "ENABLE_SOCIAL_KEY_MANAGEMENT" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then
649
         if [[ $(grep "ENABLE_SOCIAL_KEY_MANAGEMENT" temp.cfg | awk -F '=' '{print $2}') == "yes" ]]; then
628
             dialog --title $"Social Key Management" \
650
             dialog --title $"Social Key Management" \
629
                    --backtitle $"Freedombone Configuration" \
651
                    --backtitle $"Freedombone Configuration" \
659
             if [ ! $SELECTED_USERNAME ]; then
681
             if [ ! $SELECTED_USERNAME ]; then
660
                 SELECTED_USERNAME=$(grep 'MY_USERNAME' temp.cfg | awk -F '=' '{print $2}')
682
                 SELECTED_USERNAME=$(grep 'MY_USERNAME' temp.cfg | awk -F '=' '{print $2}')
661
             fi
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
             dialog --backtitle $"Freedombone Configuration" \
685
             dialog --backtitle $"Freedombone Configuration" \
665
                    --title $"Username" \
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
             sel=$?
688
             sel=$?
668
             case $sel in
689
             case $sel in
669
-                0) possible_username=$(cat $data)
690
+                0) possible_username=$(cat "$data")
670
                    SELECTED_USERNAME=
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
                            if [ ${#possible_username} -gt 1 ]; then
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
                                    please_wait
697
                                    please_wait
677
                                    echo ''
698
                                    echo ''
678
                                    echo $'Creating user account'
699
                                    echo $'Creating user account'
679
                                    chmod 600 /etc/shadow
700
                                    chmod 600 /etc/shadow
680
                                    chmod 600 /etc/gshadow
701
                                    chmod 600 /etc/gshadow
681
-                                   useradd -m -s /bin/bash $MY_USERNAME
702
+                                   useradd -m -s /bin/bash "$MY_USERNAME"
682
                                    chmod 0000 /etc/shadow
703
                                    chmod 0000 /etc/shadow
683
                                    chmod 0000 /etc/gshadow
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
                                        # Add the user as a sudoer - they will be the new admin user
707
                                        # Add the user as a sudoer - they will be the new admin user
687
                                        if ! grep -q "$MY_USERNAME  ALL=(ALL) ALL" /etc/sudoers; then
708
                                        if ! grep -q "$MY_USERNAME  ALL=(ALL) ALL" /etc/sudoers; then
688
                                            echo "$MY_USERNAME  ALL=(ALL) ALL" >> /etc/sudoers
709
                                            echo "$MY_USERNAME  ALL=(ALL) ALL" >> /etc/sudoers
689
                                            # remove the generic image admin user from sudoers
710
                                            # remove the generic image admin user from sudoers
690
                                            sed -i "s|${GENERIC_IMAGE_USERNAME}.*||g" /etc/sudoers
711
                                            sed -i "s|${GENERIC_IMAGE_USERNAME}.*||g" /etc/sudoers
691
                                        fi
712
                                        fi
713
+                                       rm -f "$data"
692
                                        break
714
                                        break
693
                                    fi
715
                                    fi
694
                                fi
716
                                fi
696
                        fi
718
                        fi
697
                    fi
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
             esac
725
             esac
726
+            rm -f "$data"
702
         done
727
         done
703
     else
728
     else
704
         no_of_users=$(find /home/* -maxdepth 0 -type d | wc -l)
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
             # only a single user on the system
731
             # only a single user on the system
707
             MY_USERNAME=$(ls /home)
732
             MY_USERNAME=$(ls /home)
708
         else
733
         else
741
     valid_name=
766
     valid_name=
742
     while [ ! $valid_name ]
767
     while [ ! $valid_name ]
743
     do
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
         dialog --backtitle $"Freedombone Configuration" \
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
         sel=$?
772
         sel=$?
749
         case $sel in
773
         case $sel in
750
-            0)  possible_name=$(cat $data)
774
+            0)  possible_name=$(cat "$data")
751
                 if [ "$possible_name" ]; then
775
                 if [ "$possible_name" ]; then
752
                     if [ ${#possible_name} -gt 1 ]; then
776
                     if [ ${#possible_name} -gt 1 ]; then
753
                         valid_name="$possible_name"
777
                         valid_name="$possible_name"
756
                     fi
780
                     fi
757
                 fi
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
         esac
787
         esac
788
+        rm -f "$data"
762
     done
789
     done
763
     save_configuration_values
790
     save_configuration_values
764
     please_wait
791
     please_wait
778
             varstate='on'
805
             varstate='on'
779
         fi
806
         fi
780
         varslist="$varslist $n $a $varstate"
807
         varslist="$varslist $n $a $varstate"
781
-        n=$[n+1]
808
+        n=$((n+1))
782
     done
809
     done
783
 
810
 
784
     variant_choice=$(dialog --stdout --backtitle $"Freedombone Configuration" \
811
     variant_choice=$(dialog --stdout --backtitle $"Freedombone Configuration" \
785
                             --title $"Type of Installation" \
812
                             --title $"Type of Installation" \
786
                             --radiolist $'Choose:' \
813
                             --radiolist $'Choose:' \
787
-                            27 40 20 $varslist)
814
+                            27 40 20 "$varslist")
788
 
815
 
816
+    # shellcheck disable=SC2181
789
     if [ $? -eq 0 ]; then
817
     if [ $? -eq 0 ]; then
790
-        variant_choice=$[variant_choice-1]
818
+        variant_choice=$((variant_choice-1))
791
         SYSTEM_TYPE=${available_variants_list[$variant_choice]}
819
         SYSTEM_TYPE=${available_variants_list[$variant_choice]}
792
         save_configuration_values
820
         save_configuration_values
793
     fi
821
     fi
796
 function validate_freedns_code {
824
 function validate_freedns_code {
797
     freedns_code="$1"
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
     if [[ "$freedns_code" == *"."* || "$freedns_code" == "http"* || "$freedns_code" == *"wget "* || "$freedns_code" == *" "* ]]; then
829
     if [[ "$freedns_code" == *"."* || "$freedns_code" == "http"* || "$freedns_code" == *"wget "* || "$freedns_code" == *" "* ]]; then
802
         dialog --title $"Invalid FreeDNS Code" --msgbox "$FREEDNS_MESSAGE" 10 70
830
         dialog --title $"Invalid FreeDNS Code" --msgbox "$FREEDNS_MESSAGE" 10 70
855
 done
883
 done
856
 
884
 
857
 function interactive_select_language {
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
     dialog --backtitle $"Freedombone Configuration" \
887
     dialog --backtitle $"Freedombone Configuration" \
861
            --radiolist $"Select your language:" 26 40 24 \
888
            --radiolist $"Select your language:" 26 40 24 \
862
            1 $"Afrikaans" off \
889
            1 $"Afrikaans" off \
926
            65 $"Thai" off \
953
            65 $"Thai" off \
927
            66 $"Turkish" off \
954
            66 $"Turkish" off \
928
            67 $"Ukrainian" off \
955
            67 $"Ukrainian" off \
929
-           68 $"Vietnamese" off 2> $data
956
+           68 $"Vietnamese" off 2> "$data"
930
     sel=$?
957
     sel=$?
931
     case $sel in
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
     esac
963
     esac
935
-    case $(cat $data) in
964
+    case $(cat "$data") in
936
         1) DEFAULT_LANGUAGE='af_ZA.UTF-8';;
965
         1) DEFAULT_LANGUAGE='af_ZA.UTF-8';;
937
         2) DEFAULT_LANGUAGE='sq_AL.UTF-8';;
966
         2) DEFAULT_LANGUAGE='sq_AL.UTF-8';;
938
         3) DEFAULT_LANGUAGE='ar_SA.UTF-8';;
967
         3) DEFAULT_LANGUAGE='ar_SA.UTF-8';;
1002
         67) DEFAULT_LANGUAGE='uk_UA.UTF-8';;
1031
         67) DEFAULT_LANGUAGE='uk_UA.UTF-8';;
1003
         68) DEFAULT_LANGUAGE='vi_VN.UTF-8';;
1032
         68) DEFAULT_LANGUAGE='vi_VN.UTF-8';;
1004
     esac
1033
     esac
1034
+    rm -f "$data"
1005
     save_configuration_values
1035
     save_configuration_values
1006
 
1036
 
1007
     please_wait
1037
     please_wait
1021
 function select_user {
1051
 function select_user {
1022
     SELECTED_USERNAME=
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
     delete=(git)
1058
     delete=(git)
1027
-    for del in ${delete[@]}
1059
+    for del in "${delete[@]}"
1028
     do
1060
     do
1061
+        # shellcheck disable=SC2206
1029
         users_array=(${users_array[@]/$del})
1062
         users_array=(${users_array[@]/$del})
1030
     done
1063
     done
1031
 
1064
 
1032
     i=0
1065
     i=0
1033
     W=()
1066
     W=()
1034
     name=()
1067
     name=()
1068
+    # shellcheck disable=SC2068
1035
     for u in ${users_array[@]}
1069
     for u in ${users_array[@]}
1036
     do
1070
     do
1037
         if [[ $(is_valid_user "$u") == "1" ]]; then
1071
         if [[ $(is_valid_user "$u") == "1" ]]; then
1038
             i=$((i+1))
1072
             i=$((i+1))
1039
-            W+=($i "$u")
1073
+            W+=("$i" "$u")
1040
             name+=("$u")
1074
             name+=("$u")
1041
         fi
1075
         fi
1042
     done
1076
     done
1046
     else
1080
     else
1047
         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)
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
         if [ $? -eq 0 ]; then
1084
         if [ $? -eq 0 ]; then
1050
             SELECTED_USERNAME="${name[$((user_index-1))]}"
1085
             SELECTED_USERNAME="${name[$((user_index-1))]}"
1051
         fi
1086
         fi
1055
 function interactive_config {
1090
 function interactive_config {
1056
     # create a temporary copy of the configuration file
1091
     # create a temporary copy of the configuration file
1057
     # which can be used to pre-populate selections
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
     fi
1095
     fi
1061
 
1096
 
1062
     interactive_select_language
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
     else
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
         else
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
         fi
1106
         fi
1072
     fi
1107
     fi
1073
 
1108
 
1079
     choose_social_key_management
1114
     choose_social_key_management
1080
     choose_rng
1115
     choose_rng
1081
     choose_debian_repo
1116
     choose_debian_repo
1082
-    ${PROJECT_NAME}-wifi --networksinteractive $WIFI_NETWORKS_FILE
1117
+    "${PROJECT_NAME}-wifi" --networksinteractive "$WIFI_NETWORKS_FILE"
1083
     choose_dynamic_dns
1118
     choose_dynamic_dns
1084
     choose_default_domain_name
1119
     choose_default_domain_name
1085
     choose_email_address
1120
     choose_email_address
1109
     fi
1144
     fi
1110
 
1145
 
1111
     # This file indicates that the configuration happened successfully
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
 function show_result {
1150
 function show_result {
1120
     echo ''
1155
     echo ''
1121
     echo $'Contents:'
1156
     echo $'Contents:'
1122
     echo ''
1157
     echo ''
1123
-    cat $CONFIGURATION_FILE
1158
+    cat "$CONFIGURATION_FILE"
1124
     echo ''
1159
     echo ''
1125
 }
1160
 }
1126
 
1161
 
1127
-if [ ! $CONFIGURATION_FILE ]; then
1162
+if [ ! "$CONFIGURATION_FILE" ]; then
1128
     CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
1163
     CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
1129
 fi
1164
 fi
1130
 
1165
 

+ 408
- 437
src/freedombone-controlpanel
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 207
- 220
src/freedombone-controlpanel-user
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 13
- 14
src/freedombone-dhparam Целия файл

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

+ 8
- 8
src/freedombone-encrypt-mail Целия файл

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

+ 5
- 8
src/freedombone-format Целия файл

33
 export TEXTDOMAIN=${PROJECT_NAME}-format
33
 export TEXTDOMAIN=${PROJECT_NAME}-format
34
 export TEXTDOMAINDIR="/usr/share/locale"
34
 export TEXTDOMAINDIR="/usr/share/locale"
35
 
35
 
36
-if [ ! $1 ]; then
36
+if [ ! "$1" ]; then
37
    echo $'Specify a drive, such as sdb, sdc, etc'
37
    echo $'Specify a drive, such as sdb, sdc, etc'
38
    exit 1
38
    exit 1
39
 fi
39
 fi
62
 a
62
 a
63
 1
63
 1
64
 w
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
 echo $"Formatting $USB_DRIVE as LUKS"
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
     echo $"Failed to format $USB_DRIVE as LUKS"
69
     echo $"Failed to format $USB_DRIVE as LUKS"
71
     exit 36823
70
     exit 36823
72
 fi
71
 fi
73
-cryptsetup luksOpen ${USB_DRIVE} encrypted_usb
74
-if [ ! "$?" = "0" ]; then
72
+if ! cryptsetup luksOpen "${USB_DRIVE}" encrypted_usb; then
75
     echo $"Failed to open LUKS formatted drive $USB_DRIVE"
73
     echo $"Failed to open LUKS formatted drive $USB_DRIVE"
76
     exit 37232
74
     exit 37232
77
 fi
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
     cryptsetup luksClose encrypted_usb
77
     cryptsetup luksClose encrypted_usb
81
     echo $'Format of drive $USB_DRIVE failed'
78
     echo $'Format of drive $USB_DRIVE failed'
82
     exit 73218
79
     exit 73218

+ 8
- 7
src/freedombone-freedns Целия файл

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

+ 20
- 20
src/freedombone-ignore Целия файл

79
     fi
79
     fi
80
 fi
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
 # Ignore if subject line contains text
85
 # Ignore if subject line contains text
86
 if [ "$SUBJECT_TEXT" ]; then
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
     fi
94
     fi
95
 fi
95
 fi
96
 
96
 
97
 # ignore an email address
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
     fi
106
     fi
107
 fi
107
 fi
108
 
108
 
109
 PROCMAILLOG=/home/$MYUSERNAME/log
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
 fi
113
 fi
114
 
114
 
115
 exit 0
115
 exit 0

+ 75
- 74
src/freedombone-image Целия файл

42
     PROJECT_INSTALL_DIR=/usr/bin
42
     PROJECT_INSTALL_DIR=/usr/bin
43
 fi
43
 fi
44
 
44
 
45
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
45
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
46
 
46
 
47
 #get the project repo
47
 #get the project repo
48
 PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}"
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
 for f in $UTILS_FILES
50
 for f in $UTILS_FILES
51
 do
51
 do
52
-    source $f
52
+    source "$f"
53
 done
53
 done
54
 read_config_param PROJECT_REPO
54
 read_config_param PROJECT_REPO
55
 
55
 
96
 DEFAULT_DOMAIN_NAME="${LOCAL_NAME}.local"
96
 DEFAULT_DOMAIN_NAME="${LOCAL_NAME}.local"
97
 
97
 
98
 # Minimum number of characters in a password
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
 # Optional ssh public key to allow
101
 # Optional ssh public key to allow
102
 SSH_PUBKEY="no"
102
 SSH_PUBKEY="no"
175
             sudo pacman -S --noconfirm qemu-static binfmt-qemu-static uboot-tools qemu parted
175
             sudo pacman -S --noconfirm qemu-static binfmt-qemu-static uboot-tools qemu parted
176
             sudo pacman -S --noconfirm dpkg-devtools bin86 arch-install-scripts qemu-arch-extra
176
             sudo pacman -S --noconfirm dpkg-devtools bin86 arch-install-scripts qemu-arch-extra
177
             sudo pacman -S --noconfirm syncthing
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
             fi
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
                 echo $"Failed to clone python-cliapp"
183
                 echo $"Failed to clone python-cliapp"
185
                 return
184
                 return
186
             fi
185
             fi
187
-            if [ ! -d $USERHOME/develop/python-cliapp ]; then
186
+            if [ ! -d "$USERHOME/develop/python-cliapp" ]; then
188
                 echo $"Couldn't clone python-cliapp"
187
                 echo $"Couldn't clone python-cliapp"
189
                 return
188
                 return
190
             fi
189
             fi
191
             sudo pacman -S --noconfirm python2-coverage python2-pytest-cov python2-sphinx
190
             sudo pacman -S --noconfirm python2-coverage python2-pytest-cov python2-sphinx
192
             sudo pacman -S --noconfirm autopep8 python2-pylint python2-yaml python2-xdg python2-pip
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
             git checkout $CLIAPP_COMMIT -b $CLIAPP_COMMIT
193
             git checkout $CLIAPP_COMMIT -b $CLIAPP_COMMIT
195
             sudo python2 setup.py install
194
             sudo python2 setup.py install
196
             sudo pip2 install distro-info logging
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
             fi
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
                 echo $"Failed to clone mbr"
200
                 echo $"Failed to clone mbr"
203
                 return
201
                 return
204
             fi
202
             fi
205
-            if [ ! -d $USERHOME/develop/mbr ]; then
203
+            if [ ! -d "$USERHOME/develop/mbr" ]; then
206
                 echo $"Couldn't clone mbr"
204
                 echo $"Couldn't clone mbr"
207
                 return
205
                 return
208
             fi
206
             fi
209
-            cd $USERHOME/develop/mbr
207
+            cd "$USERHOME/develop/mbr" || exit 2468724524
210
             git checkout $MBR_COMMIT -b $MBR_COMMIT
208
             git checkout $MBR_COMMIT -b $MBR_COMMIT
211
             makepkg --force --noconfirm
209
             makepkg --force --noconfirm
212
             if [ ! -f mbr-${MBR_VERSION}.tar.gz ]; then
210
             if [ ! -f mbr-${MBR_VERSION}.tar.gz ]; then
214
                 return
212
                 return
215
             fi
213
             fi
216
             tar -xzvf mbr-${MBR_VERSION}.tar.gz
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
                 echo $"mbr tarball could not be extracted"
216
                 echo $"mbr tarball could not be extracted"
219
                 return
217
                 return
220
             fi
218
             fi
221
-            cd $USERHOME/develop/mbr/mbr-${MBR_VERSION}
219
+            cd "$USERHOME/develop/mbr/mbr-${MBR_VERSION}" || exit 13584584
222
             cp ../*.patch .
220
             cp ../*.patch .
223
             patch -p0 < *.patch
221
             patch -p0 < *.patch
224
             ./configure
222
             ./configure
229
                 return
227
                 return
230
             fi
228
             fi
231
             sudo cp /usr/local/sbin/install-mbr /sbin
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
             fi
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
                 echo $"Failed to clone multipath-tools"
234
                 echo $"Failed to clone multipath-tools"
238
                 return
235
                 return
239
             fi
236
             fi
240
-            if [ ! -d $USERHOME/develop/multipath-tools ]; then
237
+            if [ ! -d "$USERHOME/develop/multipath-tools" ]; then
241
                 echo $"Couldn't clone multipath-tools"
238
                 echo $"Couldn't clone multipath-tools"
242
                 return
239
                 return
243
             fi
240
             fi
244
             sudo pacman -S --noconfirm device-mapper libaio liburcu fakeroot
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
             makepkg --force --noconfirm
243
             makepkg --force --noconfirm
247
             makepkg -i --force --noconfirm
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
                 echo $"No debian debootstrap script was found for $DEBIAN_VERSION"
248
                 echo $"No debian debootstrap script was found for $DEBIAN_VERSION"
252
                 return
249
                 return
253
             fi
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
             expected_debian_script_hash='620fa84c7ef64d10349aed38fa9cc2e7f00a6fcd1bc425f33ca2b57cc946fd0c'
252
             expected_debian_script_hash='620fa84c7ef64d10349aed38fa9cc2e7f00a6fcd1bc425f33ca2b57cc946fd0c'
256
             if [[ "$debian_script_hash" != "$expected_debian_script_hash" ]]; then
253
             if [[ "$debian_script_hash" != "$expected_debian_script_hash" ]]; then
257
                 echo $"Invalid hash for debootstrap ${DEBIAN_VERSION} script"
254
                 echo $"Invalid hash for debootstrap ${DEBIAN_VERSION} script"
258
                 return
255
                 return
259
             fi
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
             echo $'Unkown operating system'
260
             echo $'Unkown operating system'
271
 function mesh_router_setup_script {
268
 function mesh_router_setup_script {
272
     # create a setup script for a mesh router
269
     # create a setup script for a mesh router
273
     mesh_script_filename=$1
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
 while [ $# -gt 1 ]
293
 while [ $# -gt 1 ]
304
         -c|--config)
301
         -c|--config)
305
             shift
302
             shift
306
             CONFIG_FILENAME="$1"
303
             CONFIG_FILENAME="$1"
307
-            if [ ! -f $CONFIG_FILENAME ]; then
304
+            if [ ! -f "$CONFIG_FILENAME" ]; then
308
                 echo $"Config file $CONFIG_FILENAME not found"
305
                 echo $"Config file $CONFIG_FILENAME not found"
309
                 exit 3
306
                 exit 3
310
             fi
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
         -t|--target|--board)
310
         -t|--target|--board)
314
             shift
311
             shift
321
         -p|--password)
318
         -p|--password)
322
             shift
319
             shift
323
             PASSWORD="$1"
320
             PASSWORD="$1"
324
-            if [ ${#PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
321
+            if [ ${#PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
325
                 echo $"Your password chould contain at least ${MINIMUM_PASSWORD_LENGTH} characters"
322
                 echo $"Your password chould contain at least ${MINIMUM_PASSWORD_LENGTH} characters"
326
                 exit 3628
323
                 exit 3628
327
             fi
324
             fi
415
             shift
412
             shift
416
             MIRROR="$1"
413
             MIRROR="$1"
417
             ;;
414
             ;;
418
-        --debianonly|--basic|--minimal)
415
+        --debianonly|--basic)
419
             shift
416
             shift
420
             DEBIAN_INSTALL_ONLY="$1"
417
             DEBIAN_INSTALL_ONLY="$1"
421
             ;;
418
             ;;
467
 
464
 
468
 if [[ $INTERACTIVE == "yes" || $INTERACTIVE == "y" || $INTERACTIVE == "Yes" ]]; then
465
 if [[ $INTERACTIVE == "yes" || $INTERACTIVE == "y" || $INTERACTIVE == "Yes" ]]; then
469
     ${PROJECT_NAME}-config --minimal "$MINIMAL_INSTALL"
466
     ${PROJECT_NAME}-config --minimal "$MINIMAL_INSTALL"
470
-    if [ -f $HOME/${PROJECT_NAME}.cfg ]; then
467
+    if [ -f "$HOME/${PROJECT_NAME}.cfg" ]; then
471
         CONFIG_FILENAME=$HOME/${PROJECT_NAME}.cfg
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
     fi
470
     fi
474
 fi
471
 fi
475
 
472
 
480
 
477
 
481
 if [ ! $PASSWORD ]; then
478
 if [ ! $PASSWORD ]; then
482
     # generate a random password
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
 fi
481
 fi
485
 
482
 
486
 # Move any existing images into a build subdirectory
483
 # Move any existing images into a build subdirectory
487
 image_types=( xz img sig vdi qcow2 )
484
 image_types=( xz img sig vdi qcow2 )
488
 for im in "${image_types[@]}"
485
 for im in "${image_types[@]}"
489
 do
486
 do
487
+    # shellcheck disable=SC2012,SC2086
490
     no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
488
     no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
491
     if (( no_of_files > 0 )); then
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
         fi
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
     fi
494
     fi
497
 done
495
 done
498
 
496
 
499
 # Delete anything which didn't move
497
 # Delete anything which didn't move
500
 for im in "${image_types[@]}"
498
 for im in "${image_types[@]}"
501
 do
499
 do
500
+    # shellcheck disable=SC2012,SC2086
502
     no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
501
     no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
503
     if (( no_of_files > 0 )); then
502
     if (( no_of_files > 0 )); then
504
-        rm -f ${CURR_DIR}/${PROJECT_NAME}*.${im}
503
+        rm -f "${CURR_DIR}/${PROJECT_NAME}*.${im}"
505
     fi
504
     fi
506
 done
505
 done
507
 
506
 
508
 # Remove any existing login credentials file
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
 fi
510
 fi
512
 
511
 
513
 if [ -d $TEMPBUILD_DIR ]; then
512
 if [ -d $TEMPBUILD_DIR ]; then
522
 
521
 
523
 cp -r /etc/${PROJECT_NAME}/* $TEMPBUILD_DIR
522
 cp -r /etc/${PROJECT_NAME}/* $TEMPBUILD_DIR
524
 rm -rf $TEMPBUILD_DIR/vendor
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
 if [[ $MINIMAL_INSTALL == "yes" ]]; then
527
 if [[ $MINIMAL_INSTALL == "yes" ]]; then
529
     IMAGE_NAME=$'min'
528
     IMAGE_NAME=$'min'
565
     IMAGE_NAME="${IMAGE_NAME}-${SOCIALINSTANCE}"
564
     IMAGE_NAME="${IMAGE_NAME}-${SOCIALINSTANCE}"
566
 fi
565
 fi
567
 
566
 
568
-cd $TEMPBUILD_DIR
569
-make $IMAGE_TYPE \
567
+cd $TEMPBUILD_DIR || exit 724245267
568
+make "$IMAGE_TYPE" \
570
      MYUSERNAME="$USERNAME" \
569
      MYUSERNAME="$USERNAME" \
571
      MYPASSWORD="$PASSWORD" \
570
      MYPASSWORD="$PASSWORD" \
572
      ROUTER_IP_ADDRESS="$ROUTER_IP_ADDRESS" \
571
      ROUTER_IP_ADDRESS="$ROUTER_IP_ADDRESS" \
603
      SOCIALINSTANCE="$SOCIALINSTANCE" \
602
      SOCIALINSTANCE="$SOCIALINSTANCE" \
604
      LOCAL_NAME="$LOCAL_NAME"
603
      LOCAL_NAME="$LOCAL_NAME"
605
 
604
 
605
+# shellcheck disable=SC2181
606
 if [ ! "$?" = "0" ]; then
606
 if [ ! "$?" = "0" ]; then
607
     echo $'Build failed'
607
     echo $'Build failed'
608
     rm -rf $TEMPBUILD_DIR
608
     rm -rf $TEMPBUILD_DIR
615
 fi
615
 fi
616
 
616
 
617
 shopt -s nullglob
617
 shopt -s nullglob
618
-imgfiles=(build/${PROJECT_NAME}*.${EXPECTED_EXTENSION})
618
+imgfiles=("build/${PROJECT_NAME}*.${EXPECTED_EXTENSION}")
619
 if [ ${#imgfiles[@]} -eq 0 ]; then
619
 if [ ${#imgfiles[@]} -eq 0 ]; then
620
     echo $'Image was not created'
620
     echo $'Image was not created'
621
     rm -rf $TEMPBUILD_DIR
621
     rm -rf $TEMPBUILD_DIR
625
 # Move images from temporary directory to the current directory
625
 # Move images from temporary directory to the current directory
626
 for im in "${image_types[@]}"
626
 for im in "${image_types[@]}"
627
 do
627
 do
628
+    # shellcheck disable=SC2012,SC2086
628
     no_of_files=$(ls -afq build/${PROJECT_NAME}*.${im} | wc -l)
629
     no_of_files=$(ls -afq build/${PROJECT_NAME}*.${im} | wc -l)
629
     if (( no_of_files > 0 )); then
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
     fi
633
     fi
633
 done
634
 done
634
 
635
 
635
 # Remove the temporary directory
636
 # Remove the temporary directory
636
 rm -rf ${TEMPBUILD_DIR}
637
 rm -rf ${TEMPBUILD_DIR}
637
 
638
 
638
-cd ${CURR_DIR}
639
+cd "${CURR_DIR}" || exit 2842845284
639
 
640
 
640
 clear
641
 clear
641
 if [[ $VARIANT != 'meshclient' && $VARIANT != 'meshusb' && $VARIANT != 'mesh' ]]; then
642
 if [[ $VARIANT != 'meshclient' && $VARIANT != 'meshusb' && $VARIANT != 'mesh' ]]; then
676
 
677
 
677
 # Remove the mesh script after use
678
 # Remove the mesh script after use
678
 if [[ $VARIANT == "mesh"* ]]; then
679
 if [[ $VARIANT == "mesh"* ]]; then
679
-    rm -f $CONFIG_FILENAME
680
+    rm -f "$CONFIG_FILENAME"
680
 fi
681
 fi
681
 
682
 
682
 # record the default login credentials for later use
683
 # record the default login credentials for later use
683
 echo $"Username: $USERNAME
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
 if [[ $IMAGE_TYPE != "qemu"* ]]; then
688
 if [[ $IMAGE_TYPE != "qemu"* ]]; then
688
     echo ''
689
     echo ''

+ 683
- 679
src/freedombone-image-customise
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 19
- 25
src/freedombone-image-hardware-setup Целия файл

34
 enable_serial_console() {
34
 enable_serial_console() {
35
     # By default, spawn a console on the serial port
35
     # By default, spawn a console on the serial port
36
     device="$1"
36
     device="$1"
37
-    echo $"Adding a getty on the serial port"
37
+    echo "Adding a getty on the serial port"
38
     echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
38
     echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
39
 }
39
 }
40
 
40
 
41
 beaglebone_setup_boot() {
41
 beaglebone_setup_boot() {
42
-    bbb_version=$1
43
 
42
 
44
     # Setup uEnv.txt
43
     # Setup uEnv.txt
45
     if grep -q btrfs /etc/fstab ; then
44
     if grep -q btrfs /etc/fstab ; then
47
     else
46
     else
48
         fstype=ext4
47
         fstype=ext4
49
     fi
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
     initRd=initrd.img-$version
52
     initRd=initrd.img-$version
57
     vmlinuz=vmlinuz-$version
53
     vmlinuz=vmlinuz-$version
58
 
54
 
103
 }
99
 }
104
 
100
 
105
 beaglebone_repack_kernel() {
101
 beaglebone_repack_kernel() {
106
-    bbb_version=$1
107
     # process installed kernel to create uImage, uInitrd, dtb
102
     # process installed kernel to create uImage, uInitrd, dtb
108
     # using flash-kernel would be a good approach, except it fails in the
103
     # using flash-kernel would be a good approach, except it fails in the
109
     # cross build environment due to too many environment checks...
104
     # cross build environment due to too many environment checks...
119
     echo "info: repacking beaglebone kernel and initrd"
114
     echo "info: repacking beaglebone kernel and initrd"
120
 
115
 
121
     bbb_dtb='am335x-boneblack'
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
     initRd=initrd.img-$version
121
     initRd=initrd.img-$version
129
     vmlinuz=vmlinuz-$version
122
     vmlinuz=vmlinuz-$version
130
 
123
 
143
 
136
 
144
     mkdir /tmp/initrd-repack
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
      rm -f conf/param.conf ; \
141
      rm -f conf/param.conf ; \
149
      find . | cpio --quiet -o -H newc | \
142
      find . | cpio --quiet -o -H newc | \
150
-         gzip -9 > /boot/$initRd )
143
+         gzip -9 > "/boot/$initRd" )
151
 
144
 
152
     rm -rf /tmp/initrd-repack
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
      mkimage -A arm -O linux -T kernel -n "Debian kernel ${version}" \
150
      mkimage -A arm -O linux -T kernel -n "Debian kernel ${version}" \
158
              -C none -a 0x82000000 -e 0x82000000 -d temp-kernel uImage ; \
151
              -C none -a 0x82000000 -e 0x82000000 -d temp-kernel uImage ; \
159
      rm -f temp-kernel ; \
152
      rm -f temp-kernel ; \
160
      mkimage -A arm -O linux -T ramdisk -C gzip -a 0x88080000 -e 0x88080000 \
153
      mkimage -A arm -O linux -T ramdisk -C gzip -a 0x88080000 -e 0x88080000 \
161
              -n "Debian ramdisk ${version}" \
154
              -n "Debian ramdisk ${version}" \
162
-             -d $initRd uInitrd )
155
+             -d "$initRd" uInitrd )
163
 }
156
 }
164
 
157
 
165
 a20_setup_boot() {
158
 a20_setup_boot() {
171
     else
164
     else
172
         fstype=ext4
165
         fstype=ext4
173
     fi
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
     initRd=initrd.img-$version
170
     initRd=initrd.img-$version
177
     vmlinuz=vmlinuz-$version
171
     vmlinuz=vmlinuz-$version
178
 
172
 
213
 
207
 
214
     # Copy all DTBs
208
     # Copy all DTBs
215
     mkdir -p /boot/dtbs
209
     mkdir -p /boot/dtbs
216
-    cp /usr/lib/$kernelVersion/* /boot/dtbs
210
+    cp "/usr/lib/$kernelVersion/*" /boot/dtbs
217
 
211
 
218
     # extra boot modules
212
     # extra boot modules
219
     echo "rtc_sunxi" >> /etc/initramfs-tools/modules
213
     echo "rtc_sunxi" >> /etc/initramfs-tools/modules
224
     if [ ! -d /etc/flash-kernel ] ; then
218
     if [ ! -d /etc/flash-kernel ] ; then
225
        mkdir /etc/flash-kernel
219
        mkdir /etc/flash-kernel
226
     fi
220
     fi
227
-    echo -n "$1" > /etc/flash-kernel/machine
221
+    echo "$1" > /etc/flash-kernel/machine
228
 
222
 
229
     command_line=""
223
     command_line=""
230
     if [ -n "$2" ] ; then
224
     if [ -n "$2" ] ; then

+ 52
- 52
src/freedombone-image-make Целия файл

35
 export TEXTDOMAINDIR="/usr/share/locale"
35
 export TEXTDOMAINDIR="/usr/share/locale"
36
 
36
 
37
 PROJECT_INSTALL_DIR=/usr/local/bin
37
 PROJECT_INSTALL_DIR=/usr/local/bin
38
-if [ -f /usr/bin/${PROJECT_NAME} ]; then
38
+if [ -f "/usr/bin/${PROJECT_NAME}" ]; then
39
     PROJECT_INSTALL_DIR=/usr/bin
39
     PROJECT_INSTALL_DIR=/usr/bin
40
 fi
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
 #set -x # Enable debugging
44
 #set -x # Enable debugging
45
 
45
 
103
 # Packages needed for self-hosted development
103
 # Packages needed for self-hosted development
104
 dev_pkgs="build-essential devscripts make man-db emacs org-mode git mercurial"
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
 case "$MACHINE" in
108
 case "$MACHINE" in
109
     beaglebone)
109
     beaglebone)
164
 done
164
 done
165
 
165
 
166
 # Make sure file is owned by current user, not root
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
 if [ -x vendor/vmdebootstrap/vmdebootstrap ] ; then
169
 if [ -x vendor/vmdebootstrap/vmdebootstrap ] ; then
170
     VMDEBOOTSTRAP=vendor/vmdebootstrap/vmdebootstrap
170
     VMDEBOOTSTRAP=vendor/vmdebootstrap/vmdebootstrap
173
 fi
173
 fi
174
 
174
 
175
 PROJECT_INSTALL_DIR=/usr/local/bin
175
 PROJECT_INSTALL_DIR=/usr/local/bin
176
-if [ -f /usr/bin/${PROJECT_NAME} ]; then
176
+if [ -f "/usr/bin/${PROJECT_NAME}" ]; then
177
     PROJECT_INSTALL_DIR=/usr/bin
177
     PROJECT_INSTALL_DIR=/usr/bin
178
 fi
178
 fi
179
 
179
 
180
 echo $'Making customised customisation script'
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
 # cat all the things together
186
 # cat all the things together
187
 combine_all_scripts $TEMP_CUSTOMISE2
187
 combine_all_scripts $TEMP_CUSTOMISE2
191
 fi
191
 fi
192
 
192
 
193
 echo $'Changing values within customised customisation script'
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
 fi
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
 fi
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
 cat $TEMP_CUSTOMISE2 $TEMP_CUSTOMISE3 > $TEMP_CUSTOMISE4
232
 cat $TEMP_CUSTOMISE2 $TEMP_CUSTOMISE3 > $TEMP_CUSTOMISE4
233
 if [ -f $TEMP_CUSTOMISE ]; then
233
 if [ -f $TEMP_CUSTOMISE ]; then
256
      SOURCE="$SOURCE" \
256
      SOURCE="$SOURCE" \
257
      CUSTOM_SETUP="$CUSTOM_SETUP" \
257
      CUSTOM_SETUP="$CUSTOM_SETUP" \
258
      $VMDEBOOTSTRAP \
258
      $VMDEBOOTSTRAP \
259
-     --log $(dirname $IMAGE)/${PROJECT_NAME}.log \
259
+     --log "$(dirname "$IMAGE")/${PROJECT_NAME}.log" \
260
      --log-level debug \
260
      --log-level debug \
261
-     --size $IMAGE_SIZE \
262
-     --image $IMAGE.img \
261
+     --size "$IMAGE_SIZE" \
262
+     --image "$IMAGE.img" \
263
      --hostname ${PROJECT_NAME} \
263
      --hostname ${PROJECT_NAME} \
264
      --verbose \
264
      --verbose \
265
-     --mirror $BUILD_MIRROR \
265
+     --mirror "$BUILD_MIRROR" \
266
      --customize "$TEMP_CUSTOMISE" \
266
      --customize "$TEMP_CUSTOMISE" \
267
      --lock-root-password \
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
 echo $'Removing customised customisation script'
273
 echo $'Removing customised customisation script'
274
 sudo shred -zu $TEMP_CUSTOMISE
274
 sudo shred -zu $TEMP_CUSTOMISE

+ 648
- 645
src/freedombone-image-mesh
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 2
- 2
src/freedombone-image-vmdebootstrap Целия файл

36
 
36
 
37
 mkdir -p vendor
37
 mkdir -p vendor
38
 if [ -d vendor/vmdebootstrap ] ; then
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
 else
40
 else
41
     git clone $VMDEBOOTSTRAP_REPO vendor/vmdebootstrap
41
     git clone $VMDEBOOTSTRAP_REPO vendor/vmdebootstrap
42
 fi
42
 fi
103
     sudo mv /tmp/ubuntu.csv /usr/share/distro-info/
103
     sudo mv /tmp/ubuntu.csv /usr/share/distro-info/
104
 fi
104
 fi
105
 
105
 
106
-cd vendor/vmdebootstrap
106
+cd vendor/vmdebootstrap || exit 2648726446
107
 git checkout $VMDEBOOTSTRAP_BRANCH
107
 git checkout $VMDEBOOTSTRAP_BRANCH

+ 38
- 40
src/freedombone-keydrive Целия файл

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

+ 16
- 16
src/freedombone-logging Целия файл

42
 
42
 
43
 source /usr/local/bin/${PROJECT_NAME}-vars
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
 for f in $UTILS_FILES
46
 for f in $UTILS_FILES
47
 do
47
 do
48
-    source $f
48
+    source "$f"
49
 done
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
 for f in $APP_FILES
52
 for f in $APP_FILES
53
 do
53
 do
54
-    source $f
54
+    source "$f"
55
 done
55
 done
56
 
56
 
57
 APPS_AVAILABLE=()
57
 APPS_AVAILABLE=()
58
 
58
 
59
 function logging_get_app_names {
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
     for filename in $FILES
62
     for filename in $FILES
63
     do
63
     do
64
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
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
                 APPS_AVAILABLE+=("${app_name}")
67
                 APPS_AVAILABLE+=("${app_name}")
68
             fi
68
             fi
69
         fi
69
         fi
76
     for a in "${APPS_AVAILABLE[@]}"
76
     for a in "${APPS_AVAILABLE[@]}"
77
     do
77
     do
78
         echo $"Turning on logging for ${a}"
78
         echo $"Turning on logging for ${a}"
79
-        logging_on_${a}
79
+        "logging_on_${a}"
80
     done
80
     done
81
 }
81
 }
82
 
82
 
86
     for a in "${APPS_AVAILABLE[@]}"
86
     for a in "${APPS_AVAILABLE[@]}"
87
     do
87
     do
88
         echo $"Turning off logging for ${a}"
88
         echo $"Turning off logging for ${a}"
89
-        logging_off_${a}
89
+        "logging_off_${a}"
90
     done
90
     done
91
 }
91
 }
92
 
92
 
162
         fi
162
         fi
163
         for filename in /etc/nginx/sites-available/* ; do
163
         for filename in /etc/nginx/sites-available/* ; do
164
             filename_domain=$(echo "$filename" | awk -F '/' '{print $5}')
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
         done
167
         done
168
         sed -i 's|access_log.*|access_log /var/log/nginx/access.log;|g' /etc/nginx/nginx.conf
168
         sed -i 's|access_log.*|access_log /var/log/nginx/access.log;|g' /etc/nginx/nginx.conf
169
         sed -i 's|error_log.*|error_log /var/log/nginx/error.log;|g' /etc/nginx/nginx.conf
169
         sed -i 's|error_log.*|error_log /var/log/nginx/error.log;|g' /etc/nginx/nginx.conf
170
     fi
170
     fi
171
     if [ -f /etc/init.d/spamassassin ]; then
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
     fi
173
     fi
174
     if [ -d /etc/exim4 ]; then
174
     if [ -d /etc/exim4 ]; then
175
         if [ ! -d /var/log/exim4 ]; then
175
         if [ ! -d /var/log/exim4 ]; then
211
     fi
211
     fi
212
     if [ -d /etc/nginx ]; then
212
     if [ -d /etc/nginx ]; then
213
         for filename in /etc/nginx/sites-available/* ; do
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
         done
217
         done
218
         sed -i 's|access_log.*|access_log /dev/null;|g' /etc/nginx/nginx.conf
218
         sed -i 's|access_log.*|access_log /dev/null;|g' /etc/nginx/nginx.conf
219
         sed -i 's|error_log.*|error_log /dev/null;|g' /etc/nginx/nginx.conf
219
         sed -i 's|error_log.*|error_log /dev/null;|g' /etc/nginx/nginx.conf
220
         $REMOVE_FILES_COMMAND /var/log/nginx/*
220
         $REMOVE_FILES_COMMAND /var/log/nginx/*
221
     fi
221
     fi
222
     if [ -f /etc/init.d/spamassassin ]; then
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
     fi
224
     fi
225
     if [ -d /etc/exim4 ]; then
225
     if [ -d /etc/exim4 ]; then
226
         sed -i 's|MAIN_LOG_SELECTOR = .*|MAIN_LOG_SELECTOR = -all|g' /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs
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
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
 
30
 
31
 PROJECT_NAME='freedombone'
31
 PROJECT_NAME='freedombone'
32
-COMPLETION_FILE=/root/${PROJECT_NAME}-completed.txt
32
+COMPLETION_FILE="/root/${PROJECT_NAME}-completed.txt"
33
 
33
 
34
 # hotspot passphrase must be 5 characters or longer
34
 # hotspot passphrase must be 5 characters or longer
35
 HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
35
 HOTSPOT_PASSPHRASE="${PROJECT_NAME}"
40
 mesh_protocol_init
40
 mesh_protocol_init
41
 update_wifi_adaptors
41
 update_wifi_adaptors
42
 
42
 
43
-if [ ! $IFACE ]; then
43
+if [ ! "$IFACE" ]; then
44
     echo $'No wlan adaptor'
44
     echo $'No wlan adaptor'
45
     exit 0
45
     exit 0
46
 fi
46
 fi
47
 
47
 
48
 if [ -e /etc/default/batctl ]; then
48
 if [ -e /etc/default/batctl ]; then
49
+    # shellcheck disable=SC1091
49
     . /etc/default/batctl
50
     . /etc/default/batctl
50
 fi
51
 fi
51
 
52
 
52
 function status {
53
 function status {
53
     batctl o
54
     batctl o
54
 
55
 
55
-    if grep -q "bmx6" $MESH_CURRENT_PROTOCOL; then
56
+    if grep -q "bmx6" "$MESH_CURRENT_PROTOCOL"; then
56
         bmx6 -c show=originators
57
         bmx6 -c show=originators
57
     fi
58
     fi
58
-    if grep -q "bmx7" $MESH_CURRENT_PROTOCOL; then
59
+    if grep -q "bmx7" "$MESH_CURRENT_PROTOCOL"; then
59
         bmx7 -c show=originators
60
         bmx7 -c show=originators
60
     fi
61
     fi
61
 }
62
 }
62
 
63
 
63
 function stop {
64
 function stop {
64
-    if [ ! -f $MESH_CURRENT_PROTOCOL ]; then
65
+    if [ ! -f "$MESH_CURRENT_PROTOCOL" ]; then
65
         return
66
         return
66
     fi
67
     fi
67
 
68
 
82
     systemctl disable dnsmasq
83
     systemctl disable dnsmasq
83
 
84
 
84
     if [ "$EIFACE" ]; then
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
         if [[ "$ethernet_connected" != "0" ]]; then
89
         if [[ "$ethernet_connected" != "0" ]]; then
89
             systemctl stop hostapd
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
         fi
93
         fi
93
-        brctl delbr $BRIDGE
94
+        brctl delbr "$BRIDGE"
94
     fi
95
     fi
95
 
96
 
96
     ifconfig bat0 down -promisc
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
         systemctl stop hostapd
105
         systemctl stop hostapd
105
         systemctl disable hostapd
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
     fi
111
     fi
111
 
112
 
112
     rmmod batman-adv
113
     rmmod batman-adv
115
 
116
 
116
     systemctl restart network-manager
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
     fi
121
     fi
121
 }
122
 }
122
 
123
 
123
 function verify {
124
 function verify {
124
     tempfile="$(mktemp)"
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
         echo $'B.A.T.M.A.N. not enabled'
128
         echo $'B.A.T.M.A.N. not enabled'
128
-        rm $tempfile
129
+        rm "$tempfile"
129
         stop
130
         stop
130
         exit 726835
131
         exit 726835
131
     fi
132
     fi
132
     echo $'B.A.T.M.A.N. is running'
133
     echo $'B.A.T.M.A.N. is running'
133
-    rm $tempfile
134
+    rm "$tempfile"
134
 }
135
 }
135
 
136
 
136
 function add_wifi_interface {
137
 function add_wifi_interface {
137
     ifname=$1
138
     ifname=$1
138
     ifssid=$WIFI_SSID
139
     ifssid=$WIFI_SSID
139
-    if [ $2 ]; then
140
+    if [ "$2" ]; then
140
         ifssid=$2
141
         ifssid=$2
141
     fi
142
     fi
142
     ifmode=ad-hoc
143
     ifmode=ad-hoc
143
-    if [ $3 ]; then
144
+    if [ "$3" ]; then
144
         ifmode=$3
145
         ifmode=$3
145
     fi
146
     fi
146
     ifchannel=$CHANNEL
147
     ifchannel=$CHANNEL
147
-    if [ $4 ]; then
148
+    if [ "$4" ]; then
148
         ifchannel=$4
149
         ifchannel=$4
149
     fi
150
     fi
150
 
151
 
151
-    ifconfig $ifname down
152
-    ifconfig $ifname mtu 1532
152
+    ifconfig "$ifname" down
153
+    ifconfig "$ifname" mtu 1532
153
     peermac=$(assign_peer_address)
154
     peermac=$(assign_peer_address)
154
-    if [ ! $peermac ]; then
155
+    if [ ! "$peermac" ]; then
155
         echo $"Unable to obtain MAC address for $peermac on $ifname"
156
         echo $"Unable to obtain MAC address for $peermac on $ifname"
156
         return
157
         return
157
     fi
158
     fi
158
-    ifconfig $ifname hw ether $peermac
159
+    ifconfig "$ifname" hw ether "$peermac"
159
     echo $"$ifname assigned MAC address $peermac"
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
 function start {
168
 function start {
188
     global_rate_limit
189
     global_rate_limit
189
 
190
 
190
     # Might have to re-enable wifi
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
     secondary_wifi_available=
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
             if [ -d /etc/hostapd ]; then
197
             if [ -d /etc/hostapd ]; then
197
                 if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
198
                 if [ ${#HOTSPOT_PASSPHRASE} -gt 4 ]; then
198
                     secondary_wifi_available=1
199
                     secondary_wifi_available=1
215
     sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE}|g" /etc/systemd/system/babel.service
216
     sed -i "s|ExecStart=.*|ExecStart=/usr/local/bin/babeld ${IFACE}|g" /etc/systemd/system/babel.service
216
     systemctl daemon-reload
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
     # NOTE: Don't connect the secondary wifi device. hostapd will handle that by itself
221
     # NOTE: Don't connect the secondary wifi device. hostapd will handle that by itself
221
 
222
 
222
     ifconfig bat0 up promisc
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
     ifconfig bat0 0.0.0.0
227
     ifconfig bat0 0.0.0.0
227
     ethernet_connected='0'
228
     ethernet_connected='0'
228
     if [ "$EIFACE" ] ; then
229
     if [ "$EIFACE" ] ; then
229
-        ethernet_connected=$(cat /sys/class/net/$EIFACE/carrier)
230
+        ethernet_connected=$(cat "/sys/class/net/$EIFACE/carrier")
230
         if [[ "$ethernet_connected" != "0" ]]; then
231
         if [[ "$ethernet_connected" != "0" ]]; then
231
             echo $'Trying ethernet bridge to the internet'
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
             echo $'End of ethernet bridge'
236
             echo $'End of ethernet bridge'
236
 
237
 
237
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
238
             sed -i "s|ExecStart=.*|ExecStart=/usr/sbin/bmx6 dev=${IFACE} dev=${EIFACE}|g" /etc/systemd/system/bmx6.service
243
             echo $"$EIFACE is not connected"
244
             echo $"$EIFACE is not connected"
244
         fi
245
         fi
245
     fi
246
     fi
246
-    ifconfig $BRIDGE up
247
-    dhclient $BRIDGE
247
+    ifconfig "$BRIDGE" up
248
+    dhclient "$BRIDGE"
248
 
249
 
249
     enable_mesh_seconary_wifi
250
     enable_mesh_seconary_wifi
250
 
251
 
257
 
258
 
258
     systemctl restart nginx
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
     fi
263
     fi
263
 
264
 
264
-    if grep -q "bmx6" $MESH_DEFAULT_PROTOCOL; then
265
+    if grep -q "bmx6" "$MESH_DEFAULT_PROTOCOL"; then
265
         systemctl enable bmx6
266
         systemctl enable bmx6
266
         systemctl restart bmx6
267
         systemctl restart bmx6
267
         sed -i 's|<type>.*|<type>_bmx6._tcp</type>|g' /etc/avahi/services/routing.service
268
         sed -i 's|<type>.*|<type>_bmx6._tcp</type>|g' /etc/avahi/services/routing.service
268
     fi
269
     fi
269
 
270
 
270
-    if grep -q "bmx7" $MESH_DEFAULT_PROTOCOL; then
271
+    if grep -q "bmx7" "$MESH_DEFAULT_PROTOCOL"; then
271
         systemctl enable bmx7
272
         systemctl enable bmx7
272
         systemctl restart bmx7
273
         systemctl restart bmx7
273
         sed -i 's|<type>.*|<type>_bmx7._tcp</type>|g' /etc/avahi/services/routing.service
274
         sed -i 's|<type>.*|<type>_bmx7._tcp</type>|g' /etc/avahi/services/routing.service
274
     fi
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
         systemctl enable olsr2
281
         systemctl enable olsr2
281
         systemctl restart olsr2
282
         systemctl restart olsr2
282
         sed -i 's|<type>.*|<type>_olsr2._tcp</type>|g' /etc/avahi/services/routing.service
283
         sed -i 's|<type>.*|<type>_olsr2._tcp</type>|g' /etc/avahi/services/routing.service
283
     fi
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
         systemctl enable babel
290
         systemctl enable babel
290
         systemctl restart babel
291
         systemctl restart babel
295
 
296
 
296
     verify
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
 function monitor {
302
 function monitor {
329
     echo ''
330
     echo ''
330
 
331
 
331
     # Might have to re-enable wifi
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
     sleep 1
340
     sleep 1
340
-    iwconfig $IFACE ap $CELLID
341
+    iwconfig "$IFACE" ap "$CELLID"
341
 
342
 
342
     modprobe batman-adv
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
     clear
349
     clear
349
     echo ''
350
     echo ''
354
 }
355
 }
355
 
356
 
356
 if ! grep -q "$IFACE" /proc/net/dev; then
357
 if ! grep -q "$IFACE" /proc/net/dev; then
357
-    echo 'Interface $IFACE was not found'
358
+    echo "Interface \$IFACE was not found"
358
     stop
359
     stop
359
     exit 1
360
     exit 1
360
 fi
361
 fi
377
         start
378
         start
378
         ;;
379
         ;;
379
     ping)
380
     ping)
380
-        batctl ping $2
381
+        batctl ping "$2"
381
         ;;
382
         ;;
382
     data)
383
     data)
383
         watch -n1 "batctl s | grep mgmt | grep bytes"
384
         watch -n1 "batctl s | grep mgmt | grep bytes"
387
         ;;
388
         ;;
388
     *)
389
     *)
389
         echo "error: invalid parameter $1"
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
         exit 2
392
         exit 2
392
         ;;
393
         ;;
393
 esac
394
 esac

+ 48
- 47
src/freedombone-mesh-blog Целия файл

42
 DEFAULT_BLOG_TITLE=$"Freedombone Blog"
42
 DEFAULT_BLOG_TITLE=$"Freedombone Blog"
43
 
43
 
44
 function remove_bad_blog_links {
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
 function ipfs_publish {
53
 function ipfs_publish {
54
     DIR_TO_CHECK=/home/$USER/Public
54
     DIR_TO_CHECK=/home/$USER/Public
55
-    if [ ! -d $DIR_TO_CHECK ]; then
55
+    if [ ! -d "$DIR_TO_CHECK" ]; then
56
         return
56
         return
57
     fi
57
     fi
58
 
58
 
60
     echo $'Publishing to IPFS. This may take some time...'
60
     echo $'Publishing to IPFS. This may take some time...'
61
 
61
 
62
     OLD_STAT_FILE=/home/$USER/.old_stat.txt
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
     fi
70
     fi
71
 }
71
 }
72
 
72
 
75
     echo ''
75
     echo ''
76
     echo $'Regenerating blog...'
76
     echo $'Regenerating blog...'
77
 
77
 
78
-    cd $BLOG_PATH
78
+    cd $BLOG_PATH || exit 246872648
79
     if grep -q "SITENAME=u'${DEFAULT_BLOG_TITLE}'" $BLOG_PATH/pelicanconf.py; then
79
     if grep -q "SITENAME=u'${DEFAULT_BLOG_TITLE}'" $BLOG_PATH/pelicanconf.py; then
80
         TOX_NICK=$(toxid --showuser)
80
         TOX_NICK=$(toxid --showuser)
81
         BLOG_TITLE=$"${TOX_NICK}'s Blog"
81
         BLOG_TITLE=$"${TOX_NICK}'s Blog"
83
     fi
83
     fi
84
     make html
84
     make html
85
 
85
 
86
-    cd $BLOG_PATH
86
+    cd $BLOG_PATH || exit 23682468
87
     remove_bad_blog_links
87
     remove_bad_blog_links
88
 
88
 
89
     ipfs_publish
89
     ipfs_publish
97
 function new_blog {
97
 function new_blog {
98
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
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
     $BLOG_EDITOR ~/.new-blog-entry
114
     $BLOG_EDITOR ~/.new-blog-entry
115
 
115
 
119
     if grep -q $"Blog Post Title" ~/.new-blog-entry; then
119
     if grep -q $"Blog Post Title" ~/.new-blog-entry; then
120
         return
120
         return
121
     fi
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
     fi
124
     fi
125
 
125
 
126
     # move to the content directory
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
     # increment the index
130
     # increment the index
131
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
131
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
132
-    echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX
132
+    echo "$CURRENT_INDEX" > "$CURRENT_BLOG_INDEX"
133
 
133
 
134
     regenerate_blog
134
     regenerate_blog
135
 }
135
 }
136
 
136
 
137
 function edit_blog {
137
 function edit_blog {
138
-    if [ ! -f $CURRENT_BLOG_INDEX ]; then
138
+    if [ ! -f "$CURRENT_BLOG_INDEX" ]; then
139
         return
139
         return
140
     fi
140
     fi
141
-    CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
141
+    CURRENT_INDEX=$(cat "$CURRENT_BLOG_INDEX")
142
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
142
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
143
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
143
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
144
     if [ ! -f $LAST_BLOG_ENTRY ]; then
144
     if [ ! -f $LAST_BLOG_ENTRY ]; then
149
 }
149
 }
150
 
150
 
151
 function delete_blog {
151
 function delete_blog {
152
-    if [ ! -f $CURRENT_BLOG_INDEX ]; then
152
+    if [ ! -f "$CURRENT_BLOG_INDEX" ]; then
153
         return
153
         return
154
     fi
154
     fi
155
-    CURRENT_INDEX=$(cat $CURRENT_BLOG_INDEX)
155
+    CURRENT_INDEX=$(cat "$CURRENT_BLOG_INDEX")
156
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
156
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
157
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
157
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
158
     if [ ! -f $LAST_BLOG_ENTRY ]; then
158
     if [ ! -f $LAST_BLOG_ENTRY ]; then
159
         return
159
         return
160
     fi
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
         rm $LAST_BLOG_ENTRY
163
         rm $LAST_BLOG_ENTRY
164
-        if [ $CURRENT_INDEX -gt 0 ]; then
164
+        if [ "$CURRENT_INDEX" -gt 0 ]; then
165
             CURRENT_INDEX=$PREVIOUS_INDEX
165
             CURRENT_INDEX=$PREVIOUS_INDEX
166
-            echo "$CURRENT_INDEX" > $CURRENT_BLOG_INDEX
166
+            echo "$CURRENT_INDEX" > "$CURRENT_BLOG_INDEX"
167
         else
167
         else
168
-            rm -f $CURRENT_BLOG_INDEX
168
+            rm -f "$CURRENT_BLOG_INDEX"
169
         fi
169
         fi
170
         regenerate_blog
170
         regenerate_blog
171
     fi
171
     fi
180
 
180
 
181
     n=1
181
     n=1
182
     curr_theme_index=
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
     fi
185
     fi
186
     if [ -f /tmp/.blog-themes ]; then
186
     if [ -f /tmp/.blog-themes ]; then
187
         rm /tmp/.blog-themes
187
         rm /tmp/.blog-themes
189
     for a in "${THEMES[@]}"
189
     for a in "${THEMES[@]}"
190
     do
190
     do
191
         echo "$n $a" >> /tmp/.blog-themes
191
         echo "$n $a" >> /tmp/.blog-themes
192
-        n=$[n+1]
192
+        n=$((n+1))
193
     done
193
     done
194
 
194
 
195
     CHOSEN_THEME_INDEX=$(
195
     CHOSEN_THEME_INDEX=$(
196
+    # shellcheck disable=SC2002
196
     cat /tmp/.blog-themes | \
197
     cat /tmp/.blog-themes | \
197
         awk -F ' ' '{
198
         awk -F ' ' '{
198
         for(i=1;i<=NF;i++){
199
         for(i=1;i<=NF;i++){
204
            --column=$'Index' --column=$'Theme' \
205
            --column=$'Index' --column=$'Theme' \
205
            --print-column=1 --hide-column=1 --width=300 --height=400)
206
            --print-column=1 --hide-column=1 --width=300 --height=400)
206
     rm /tmp/.blog-themes
207
     rm /tmp/.blog-themes
207
-    if [ ! $CHOSEN_THEME_INDEX ]; then
208
+    if [ ! "$CHOSEN_THEME_INDEX" ]; then
208
         exit 1
209
         exit 1
209
     fi
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
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
213
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
213
 
214
 
214
     CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
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
     remove_bad_blog_links
217
     remove_bad_blog_links
217
     if grep -q "THEME=" $BLOG_PATH/pelicanconf.py; then
218
     if grep -q "THEME=" $BLOG_PATH/pelicanconf.py; then
218
         sed -i "s|THEME=.*|THEME='themes/${CHOSEN_THEME}'|g" $BLOG_PATH/pelicanconf.py
219
         sed -i "s|THEME=.*|THEME='themes/${CHOSEN_THEME}'|g" $BLOG_PATH/pelicanconf.py

+ 5
- 4
src/freedombone-mesh-connect Целия файл

54
     fi
54
     fi
55
     cp /etc/openvpn/dh2048.pem /etc/openvpn/easy-rsa/keys/dh2048.pem
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
     . ./vars
59
     . ./vars
59
     ./clean-all
60
     ./clean-all
60
     vpn_openssl_version='1.0.0'
61
     vpn_openssl_version='1.0.0'
147
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/stunnel*
148
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/stunnel*
148
 
149
 
149
     # create an archive of the vpn client files
150
     # create an archive of the vpn client files
150
-    cd /home/$MY_USERNAME
151
+    cd /home/$MY_USERNAME || exit 346825628354
151
     tar -czvf vpn.tar.gz stunnel* client.ovpn
152
     tar -czvf vpn.tar.gz stunnel* client.ovpn
152
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/vpn.tar.gz
153
     chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/vpn.tar.gz
153
 
154
 
154
     if [ -f vpn.tar.gz ]; then
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
     fi
157
     fi
157
 }
158
 }
158
 
159
 
190
                     sed -i "s|route .*|route $ip_or_domain 255.255.255.255 net_gateway|g" ~/client.ovpn
191
                     sed -i "s|route .*|route $ip_or_domain 255.255.255.255 net_gateway|g" ~/client.ovpn
191
 
192
 
192
                     clear
193
                     clear
193
-                    cd ~/
194
+                    cd ~/ || exit 234628422874
194
                     sudo stunnel stunnel-client.conf
195
                     sudo stunnel stunnel-client.conf
195
                     sudo openvpn client.ovpn
196
                     sudo openvpn client.ovpn
196
                 fi
197
                 fi

+ 106
- 106
src/freedombone-mesh-install Целия файл

108
     fi
108
     fi
109
 
109
 
110
     # Add a mesh routing protocol service
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
     # keep the daemon running
120
     # keep the daemon running
121
     WATCHDOG_SCRIPT_NAME="keepon"
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
 function install_batman_remove {
133
 function install_batman_remove {
154
     fi
154
     fi
155
 
155
 
156
     BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
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
     $CHROOT_PREFIX systemctl enable batman
174
     $CHROOT_PREFIX systemctl enable batman
175
 }
175
 }
176
 
176
 
178
     FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
178
     FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service
179
     MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall
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
     chmod +x $MESH_FIREWALL_SCRIPT
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
     chmod +x $FIREWALL_FILENAME
254
     chmod +x $FIREWALL_FILENAME
255
     $CHROOT_PREFIX systemctl enable meshfirewall
255
     $CHROOT_PREFIX systemctl enable meshfirewall
256
 }
256
 }
290
         -r|--rootdir)
290
         -r|--rootdir)
291
             shift
291
             shift
292
             rootdir="$1"
292
             rootdir="$1"
293
-            CHROOT_PREFIX='chroot "${rootdir}"'
293
+            CHROOT_PREFIX="chroot \"\${rootdir}\""
294
             ;;
294
             ;;
295
         -w|--wifi|--interface)
295
         -w|--wifi|--interface)
296
             shift
296
             shift

+ 2
- 2
src/freedombone-mesh-invite Целия файл

35
 
35
 
36
 if [ ${#invite} -lt 10 ]; then
36
 if [ ${#invite} -lt 10 ]; then
37
    dialog --title $"Create Invite" \
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
    exit 1
39
    exit 1
40
 fi
40
 fi
41
 
41
 
42
 echo "$invite" | xclip -selection c
42
 echo "$invite" | xclip -selection c
43
 
43
 
44
 dialog --title $"Create Invite" \
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
 exit 0
47
 exit 0

+ 3
- 3
src/freedombone-mesh-reset Целия файл

43
     sudo pkill midori
43
     sudo pkill midori
44
     sudo pkill patchwork
44
     sudo pkill patchwork
45
     sudo rm -f $MESH_INSTALL_COMPLETED
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
     sudo batman start
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
     else
52
     else
53
         zenity --info --title=$"New Identity" --text=$"You now have a new identity" --width=200
53
         zenity --info --title=$"New Identity" --text=$"You now have a new identity" --width=200
54
     fi
54
     fi

+ 35
- 35
src/freedombone-mesh-routing Целия файл

31
 export TEXTDOMAIN=${PROJECT_NAME}-mesh-routing
31
 export TEXTDOMAIN=${PROJECT_NAME}-mesh-routing
32
 export TEXTDOMAINDIR="/usr/share/locale"
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
 function mesh_stop_daemon {
37
 function mesh_stop_daemon {
38
     daemon_name=$1
38
     daemon_name=$1
39
 
39
 
40
     clear
40
     clear
41
     echo ''
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
 clear
48
 clear
49
 echo ''
49
 echo ''
50
 echo $'Scanning for BMX6 protocol...'
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
 clear
53
 clear
54
 echo ''
54
 echo ''
55
 echo $'Scanning for OLSR2 protocol...'
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
 clear
58
 clear
59
 echo ''
59
 echo ''
60
 echo $'Scanning for Babel protocol...'
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
 clear
63
 clear
64
 
64
 
71
 esac
71
 esac
72
 
72
 
73
 temp_script=$HOME/.change_routing
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
 clear
97
 clear
98
 echo ''
98
 echo ''
100
 echo ''
100
 echo ''
101
 
101
 
102
 case $data in
102
 case $data in
103
-    1)  sudo $temp_script 'bmx6'
103
+    1)  sudo "$temp_script" 'bmx6'
104
         mesh_stop_daemon 'bmx7'
104
         mesh_stop_daemon 'bmx7'
105
         mesh_stop_daemon 'olsr2'
105
         mesh_stop_daemon 'olsr2'
106
         mesh_stop_daemon 'babel'
106
         mesh_stop_daemon 'babel'
111
         echo $'Starting BMX6...'
111
         echo $'Starting BMX6...'
112
         sudo systemctl start bmx6
112
         sudo systemctl start bmx6
113
         ;;
113
         ;;
114
-    2)  sudo $temp_script 'olsr2'
114
+    2)  sudo "$temp_script" 'olsr2'
115
         mesh_stop_daemon 'bmx6'
115
         mesh_stop_daemon 'bmx6'
116
         mesh_stop_daemon 'bmx7'
116
         mesh_stop_daemon 'bmx7'
117
         mesh_stop_daemon 'babel'
117
         mesh_stop_daemon 'babel'
122
         echo $'Starting OLSR2...'
122
         echo $'Starting OLSR2...'
123
         sudo systemctl start olsr2
123
         sudo systemctl start olsr2
124
         ;;
124
         ;;
125
-    3)  sudo $temp_script 'babel'
125
+    3)  sudo "$temp_script" 'babel'
126
         mesh_stop_daemon 'bmx6'
126
         mesh_stop_daemon 'bmx6'
127
         mesh_stop_daemon 'bmx7'
127
         mesh_stop_daemon 'bmx7'
128
         mesh_stop_daemon 'olsr2'
128
         mesh_stop_daemon 'olsr2'
135
         ;;
135
         ;;
136
 esac
136
 esac
137
 
137
 
138
-rm $temp_script
138
+rm "$temp_script"
139
 
139
 
140
 exit 0
140
 exit 0

+ 7
- 6
src/freedombone-mesh-visit-site Целия файл

51
 
51
 
52
 USERS_FILE_LINES=$(wc -l $USERS_FILE | awk -F ' ' '{print $1}')
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
     # If there are more than a Dunbar number of peers then ask for the peer name or ID
55
     # If there are more than a Dunbar number of peers then ask for the peer name or ID
56
     data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
56
     data=$(zenity --entry --title="Visit IPFS site" --text="Enter the username or Tox ID for the site you wish to visit")
57
     sel=$?
57
     sel=$?
62
         if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
62
         if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
63
                     TOX_ID="$TOX_USERNAME_OR_ID"
63
                     TOX_ID="$TOX_USERNAME_OR_ID"
64
         else
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
         fi
66
         fi
67
 
67
 
68
         if [ ${#TOX_ID} -gt 5 ]; then
68
         if [ ${#TOX_ID} -gt 5 ]; then
70
             zenity --info --title $"Visit a site" --text $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" --width 500
70
             zenity --info --title $"Visit a site" --text $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" --width 500
71
             exit 3
71
             exit 3
72
                     fi
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
                     pkill $BROWSER
74
                     pkill $BROWSER
75
                     setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
75
                     setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
76
 
76
 
85
 else
85
 else
86
     # If there are a relatively small number of users then choose from a list
86
     # If there are a relatively small number of users then choose from a list
87
     TOX_ID=$(
87
     TOX_ID=$(
88
-    cat $USERS_FILE | \
88
+    # shellcheck disable=SC2002
89
+    cat "$USERS_FILE" | \
89
         awk -F ' ' '{
90
         awk -F ' ' '{
90
         for(i=1;i<=NF;i++){
91
         for(i=1;i<=NF;i++){
91
             print $i;
92
             print $i;
95
            --title='Visit the site of another user' \
96
            --title='Visit the site of another user' \
96
            --column='Username' --column='Tox ID' \
97
            --column='Username' --column='Tox ID' \
97
            --print-column=2 --hide-column=2 --width=300 --height=400)
98
            --print-column=2 --hide-column=2 --width=300 --height=400)
98
-    if [ ! $TOX_ID ]; then
99
+    if [ ! "$TOX_ID" ]; then
99
         exit 0
100
         exit 0
100
     fi
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
     pkill $BROWSER
103
     pkill $BROWSER
103
     setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
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
     MY_BACKUP_KEY_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
60
     MY_BACKUP_KEY_ID=$(gpg --list-keys "(backup key)" | sed -n '2p' | sed 's/^[ \t]*//')
61
     if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then
61
     if [ ${#MY_BACKUP_KEY_ID} -lt 4 ]; then
62
         echo $"Error: gpg backup key was not found"
62
         echo $"Error: gpg backup key was not found"
63
-        return 58213
63
+        exit 58213
64
     fi
64
     fi
65
 }
65
 }
66
 
66
 
99
     pass_string="$1"
99
     pass_string="$1"
100
     str_length=${#pass_string}
100
     str_length=${#pass_string}
101
     total_padding=$((128 - str_length))
101
     total_padding=$((128 - str_length))
102
-    leading_padding=$((1 + RANDOM % $total_padding))
102
+    leading_padding=$((1 + RANDOM % total_padding))
103
     trailing_padding=$((total_padding - leading_padding))
103
     trailing_padding=$((total_padding - leading_padding))
104
     leading=$(printf "%-${leading_padding}s")
104
     leading=$(printf "%-${leading_padding}s")
105
     trailing=$(printf "%-${trailing_padding}s")
105
     trailing=$(printf "%-${trailing_padding}s")
118
         echo $'Incorrect padded length'
118
         echo $'Incorrect padded length'
119
         exit 78352
119
         exit 78352
120
     fi
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
         echo $'Unable to encrypt password'
122
         echo $'Unable to encrypt password'
124
         exit 72725
123
         exit 72725
125
     fi
124
     fi
142
     for d in /root/.passwords/*/ ; do
141
     for d in /root/.passwords/*/ ; do
143
         USERNAME=$(echo "$d" | awk -F '/' '{print $4}')
142
         USERNAME=$(echo "$d" | awk -F '/' '{print $4}')
144
         if [[ "$USERNAME" != 'root' ]]; then
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
         fi
146
         fi
148
     done
147
     done
149
     if [ ! -f $NO_PASSWORD_STORE_FILE ]; then
148
     if [ ! -f $NO_PASSWORD_STORE_FILE ]; then
156
 function export_to_keepass {
155
 function export_to_keepass {
157
     filename="$1"
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
     for d in /root/.passwords/*/ ; do
163
     for d in /root/.passwords/*/ ; do
165
         USERNAME=$(echo "$d" | awk -F '/' '{print $4}')
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
         for a in /root/.passwords/$USERNAME/* ; do
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
         done
180
         done
182
-        echo '    </group>' >> $filename
181
+        echo '    </group>' >> "$filename"
183
     done
182
     done
184
 
183
 
185
-    echo '  </group>' >> $filename
186
-    echo '</database>' >> $filename
184
+    echo '  </group>' >> "$filename"
185
+    echo '</database>' >> "$filename"
187
 
186
 
188
     echo $"Exported $filename"
187
     echo $"Exported $filename"
189
 }
188
 }
245
     shift
244
     shift
246
 done
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
     fi
250
     fi
252
     exit 0
251
     exit 0
253
 fi
252
 fi
271
     exit 0
270
     exit 0
272
 fi
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
     exit 0
275
     exit 0
277
 fi
276
 fi
278
 
277
 
279
-if [ ! $CURR_USERNAME ]; then
278
+if [ ! "$CURR_USERNAME" ]; then
280
     echo $'Error: No username given'
279
     echo $'Error: No username given'
281
     exit 1
280
     exit 1
282
 fi
281
 fi
283
 
282
 
284
-if [ ! -d /home/$CURR_USERNAME ]; then
283
+if [ ! -d "/home/$CURR_USERNAME" ]; then
285
     if [[ "$CURR_USERNAME" != "root" ]]; then
284
     if [[ "$CURR_USERNAME" != "root" ]]; then
286
         echo $"Error: User $CURR_USERNAME does not exist"
285
         echo $"Error: User $CURR_USERNAME does not exist"
287
         exit 2
286
         exit 2
288
     fi
287
     fi
289
 fi
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
     fi
293
     fi
295
     exit 0
294
     exit 0
296
 fi
295
 fi
297
 
296
 
298
-if [ ! $CURR_APP ]; then
297
+if [ ! "$CURR_APP" ]; then
299
     echo $'Error: No app name given'
298
     echo $'Error: No app name given'
300
     exit 3
299
     exit 3
301
 fi
300
 fi
302
 
301
 
303
 if [ ${#CURR_PASSWORD} -eq 0 ]; then
302
 if [ ${#CURR_PASSWORD} -eq 0 ]; then
304
     # retrieve password
303
     # retrieve password
305
-    if [ ! -f ~/.passwords/$CURR_USERNAME/$CURR_APP ]; then
304
+    if [ ! -f "${HOME}/.passwords/$CURR_USERNAME/$CURR_APP" ]; then
306
         MASTER_PASSWORD=
305
         MASTER_PASSWORD=
307
         echo ""
306
         echo ""
308
         exit 4
307
         exit 4
309
     else
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
         remove_padding "${pass}"
310
         remove_padding "${pass}"
312
     fi
311
     fi
313
 else
312
 else
318
             exit 0
317
             exit 0
319
         fi
318
         fi
320
     fi
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
     fi
322
     fi
324
     # padding helps to ensure than nothing can be learned from the length of the cyphertext
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
         MASTER_PASSWORD=
326
         MASTER_PASSWORD=
328
         exit 5
327
         exit 5
329
     fi
328
     fi

+ 18
- 18
src/freedombone-pin-cert Целия файл

43
         return
43
         return
44
     fi
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
             DOMAIN_NAME=$file
49
             DOMAIN_NAME=$file
50
             KEY_FILENAME=/etc/ssl/private/${DOMAIN_NAME}.key
50
             KEY_FILENAME=/etc/ssl/private/${DOMAIN_NAME}.key
51
-            if [ -f $KEY_FILENAME ]; then
51
+            if [ -f "$KEY_FILENAME" ]; then
52
                 BACKUP_KEY_FILENAME=/etc/ssl/certs/${DOMAIN_NAME}.pem
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
                     if [ ${#BACKUP_KEY_HASH} -gt 5 ]; then
56
                     if [ ${#BACKUP_KEY_HASH} -gt 5 ]; then
57
 
57
 
58
                         PIN_HEADER="Public-Key-Pins 'pin-sha256=\"${KEY_HASH}\"; pin-sha256=\"${BACKUP_KEY_HASH}\"; max-age=${PIN_MAX_AGE}; includeSubDomains';"
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
                         echo $"Pinned $DOMAIN_NAME with keys $KEY_HASH $BACKUP_KEY_HASH"
60
                         echo $"Pinned $DOMAIN_NAME with keys $KEY_HASH $BACKUP_KEY_HASH"
61
                     fi
61
                     fi
62
                 fi
62
                 fi
65
     done
65
     done
66
 }
66
 }
67
 
67
 
68
-if [[ $1 == "all" ]]; then
68
+if [[ "$1" == "all" ]]; then
69
     pin_all_certs
69
     pin_all_certs
70
     systemctl restart nginx
70
     systemctl restart nginx
71
     exit 0
71
     exit 0
77
 BACKUP_KEY_FILENAME=/etc/ssl/certs/${DOMAIN_NAME}.pem
77
 BACKUP_KEY_FILENAME=/etc/ssl/certs/${DOMAIN_NAME}.pem
78
 SITE_FILENAME=$WEBSITES_DIRECTORY/${DOMAIN_NAME}
78
 SITE_FILENAME=$WEBSITES_DIRECTORY/${DOMAIN_NAME}
79
 
79
 
80
-if [ ! ${DOMAIN_NAME} ]; then
80
+if [ ! "${DOMAIN_NAME}" ]; then
81
     exit 0
81
     exit 0
82
 fi
82
 fi
83
 
83
 
86
 fi
86
 fi
87
 
87
 
88
 if [[ $REMOVE == "remove" ]]; then
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
         echo $"Removed pinning for ${DOMAIN_NAME}"
91
         echo $"Removed pinning for ${DOMAIN_NAME}"
92
         systemctl restart nginx
92
         systemctl restart nginx
93
     fi
93
     fi
104
     exit 2
104
     exit 2
105
 fi
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
 if [ ${#KEY_HASH} -lt 5 ]; then
110
 if [ ${#KEY_HASH} -lt 5 ]; then
111
     echo 'Pin hash unexpectedly short'
111
     echo 'Pin hash unexpectedly short'
118
 fi
118
 fi
119
 
119
 
120
 PIN_HEADER="Public-Key-Pins 'pin-sha256=\"${KEY_HASH}\"; pin-sha256=\"${BACKUP_KEY_HASH}\"; max-age=5184000; includeSubDomains';"
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
 else
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
 fi
125
 fi
126
 
126
 
127
 systemctl restart nginx
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
     echo $'Pinning failed'
130
     echo $'Pinning failed'
131
 fi
131
 fi
132
 
132
 

+ 8
- 8
src/freedombone-powerline Целия файл

56
   readonly WHITE_BRIGHT=15
56
   readonly WHITE_BRIGHT=15
57
 
57
 
58
   # Font effects
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
   # Generate terminal colour codes
64
   # Generate terminal colour codes
65
   # $1 is an int (a colour) and $2 must be 'fg' or 'bg'
65
   # $1 is an int (a colour) and $2 must be 'fg' or 'bg'
66
   __colour() {
66
   __colour() {
67
     case "$2" in
67
     case "$2" in
68
       'fg'*)
68
       'fg'*)
69
-        echo "\[$(tput setaf "$1")\]"
69
+        echo "\\[$(tput setaf "$1")\\]"
70
         ;;
70
         ;;
71
       'bg'*)
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
     esac
77
     esac
78
   }
78
   }
288
       if [ ! -z "${text+x}" ]; then
288
       if [ ! -z "${text+x}" ]; then
289
         text+="@"
289
         text+="@"
290
       fi
290
       fi
291
-      text+="\h"
291
+      text+="\\h"
292
     fi
292
     fi
293
 
293
 
294
     if [ ! -z ${text+x} ]; then
294
     if [ ! -z ${text+x} ]; then

+ 29
- 28
src/freedombone-recoverkey Целия файл

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

+ 32
- 32
src/freedombone-remote Целия файл

35
 export TEXTDOMAIN=${PROJECT_NAME}-remote
35
 export TEXTDOMAIN=${PROJECT_NAME}-remote
36
 export TEXTDOMAINDIR="/usr/share/locale"
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
 # User to create the list for
40
 # User to create the list for
41
 MY_USERNAME=$USER
41
 MY_USERNAME=$USER
44
 FRIENDS_SERVERS_LIST=
44
 FRIENDS_SERVERS_LIST=
45
 
45
 
46
 # Minimum password length in characters
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
 # How many remote locations were specified
49
 # How many remote locations were specified
50
 entering_remote_backups_ctr=0
50
 entering_remote_backups_ctr=0
117
 done
117
 done
118
 
118
 
119
 function interactive_config_remote_backups {
119
 function interactive_config_remote_backups {
120
-    if [ ! $MY_USERNAME ]; then
120
+    if [ ! "$MY_USERNAME" ]; then
121
         echo $'Please specify a username with the -u option'
121
         echo $'Please specify a username with the -u option'
122
         exit 7356
122
         exit 7356
123
     fi
123
     fi
124
 
124
 
125
-    if [ ! /home/$MY_USERNAME ]; then
125
+    if [ ! -d "/home/$MY_USERNAME" ]; then
126
         echo $"The user /home/$MY_USERNAME does not exist on the system"
126
         echo $"The user /home/$MY_USERNAME does not exist on the system"
127
         exit 3689
127
         exit 3689
128
     fi
128
     fi
129
 
129
 
130
-    if [ ! $FRIENDS_SERVERS_LIST ]; then
130
+    if [ ! "$FRIENDS_SERVERS_LIST" ]; then
131
         FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
131
         FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
132
     fi
132
     fi
133
 
133
 
134
     # clear any existing list
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
     fi
138
     fi
139
     # number of entries made
139
     # number of entries made
140
     entering_remote_backups_ctr=1
140
     entering_remote_backups_ctr=1
148
     remote_ssh_reciprocal_password=""
148
     remote_ssh_reciprocal_password=""
149
     while [[ $entering_remote_backups_done == "no" ]]
149
     while [[ $entering_remote_backups_done == "no" ]]
150
     do
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
         if [[ $RECIPROCAL == "yes" ]]; then
152
         if [[ $RECIPROCAL == "yes" ]]; then
154
             dialog --backtitle "Freedombone Configuration" \
153
             dialog --backtitle "Freedombone Configuration" \
155
                    --title "$TITLE ${entering_remote_backups_ctr}" \
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
                    "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
156
                    "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
158
                    "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
157
                    "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
159
                    "SSH port:" 3 1 "2222" 3 23 5 4 \
158
                    "SSH port:" 3 1 "2222" 3 23 5 4 \
160
                    "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
159
                    "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
161
                    "Reciprocal Username:" 5 1 "$remote_ssh_reciprocal_username" 5 23 20 100 \
160
                    "Reciprocal Username:" 5 1 "$remote_ssh_reciprocal_username" 5 23 20 100 \
162
                    "Reciprocal Password:" 6 1 "$remote_ssh_reciprocal_password" 6 23 20 100 \
161
                    "Reciprocal Password:" 6 1 "$remote_ssh_reciprocal_password" 6 23 20 100 \
163
-                   2> $data
162
+                   2> "$data"
164
         else
163
         else
165
             dialog --backtitle "Freedombone Configuration" \
164
             dialog --backtitle "Freedombone Configuration" \
166
                    --title "$TITLE ${entering_remote_backups_ctr}" \
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
                    "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
167
                    "Username:" 1 1 "$remote_ssh_username" 1 23 16 15 \
169
                    "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
168
                    "Domain:" 2 1 "$remote_ssh_domain" 2 23 16 15 \
170
                    "SSH port:" 3 1 "2222" 3 23 5 4 \
169
                    "SSH port:" 3 1 "2222" 3 23 5 4 \
171
                    "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
170
                    "Password:" 4 1 "$remote_ssh_password" 4 23 20 100 \
172
-                   2> $data
171
+                   2> "$data"
173
         fi
172
         fi
174
         sel=$?
173
         sel=$?
175
         case $sel in
174
         case $sel in
176
             1) entering_remote_backups_done="yes";;
175
             1) entering_remote_backups_done="yes";;
177
             255) entering_remote_backups_done="yes";;
176
             255) entering_remote_backups_done="yes";;
178
         esac
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
         if [[ $remote_ssh_username != "" && \
185
         if [[ $remote_ssh_username != "" && \
186
                     $remote_ssh_domain != "" && \
186
                     $remote_ssh_domain != "" && \
187
                     $remote_ssh_port != "" && \
187
                     $remote_ssh_port != "" && \
188
                     $remote_ssh_password != "" ]]; then
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
                 dialog --title "Password quality check" --msgbox "The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
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
             else
192
             else
193
 
193
 
194
                 if [[ $RECIPROCAL == "yes" ]]; then
194
                 if [[ $RECIPROCAL == "yes" ]]; then
195
                     if [[ $remote_ssh_reciprocal_username != "" && \
195
                     if [[ $remote_ssh_reciprocal_username != "" && \
196
                                 $remote_ssh_reciprocal_password != "" ]]; then
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
                             dialog --title "Password quality check" --msgbox "The reciprocal password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters" 6 40
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
                         else
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
                             remote_ssh_username=""
202
                             remote_ssh_username=""
203
                             remote_ssh_domain=""
203
                             remote_ssh_domain=""
204
                             remote_ssh_port=""
204
                             remote_ssh_port=""
208
                             entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
208
                             entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
209
                         fi
209
                         fi
210
                     else
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
                         remote_ssh_username=""
212
                         remote_ssh_username=""
213
                         remote_ssh_domain=""
213
                         remote_ssh_domain=""
214
                         remote_ssh_port=""
214
                         remote_ssh_port=""
218
                         entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
218
                         entering_remote_backups_ctr=$((entering_remote_backups_ctr + 1))
219
                     fi
219
                     fi
220
                 else
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
                     remote_ssh_username=""
222
                     remote_ssh_username=""
223
                     remote_ssh_domain=""
223
                     remote_ssh_domain=""
224
                     remote_ssh_port=""
224
                     remote_ssh_port=""
231
             entering_remote_backups_done="yes"
231
             entering_remote_backups_done="yes"
232
         fi
232
         fi
233
     done
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
     fi
236
     fi
237
 }
237
 }
238
 
238
 
239
 function show_result {
239
 function show_result {
240
     clear
240
     clear
241
-    if (( $entering_remote_backups_ctr < 2 )); then
241
+    if (( "$entering_remote_backups_ctr" < 2 )); then
242
         echo $'No remote backup locations were specified'
242
         echo $'No remote backup locations were specified'
243
         exit 0
243
         exit 0
244
     fi
244
     fi
245
-    if [ ! -f $FRIENDS_SERVERS_LIST ]; then
245
+    if [ ! -f "$FRIENDS_SERVERS_LIST" ]; then
246
         echo $"No remote backups list found: $FRIENDS_SERVERS_LIST"
246
         echo $"No remote backups list found: $FRIENDS_SERVERS_LIST"
247
         exit 7358
247
         exit 7358
248
     fi
248
     fi
251
     echo ''
251
     echo ''
252
     echo $'Contents:'
252
     echo $'Contents:'
253
     echo ''
253
     echo ''
254
-    cat $FRIENDS_SERVERS_LIST
254
+    cat "$FRIENDS_SERVERS_LIST"
255
     echo ''
255
     echo ''
256
 }
256
 }
257
 
257
 
258
-if [ ! $FRIENDS_SERVERS_LIST ]; then
258
+if [ ! "$FRIENDS_SERVERS_LIST" ]; then
259
     FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
259
     FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
260
 fi
260
 fi
261
 
261
 

+ 3
- 4
src/freedombone-renew-cert Целия файл

59
         echo $"Renewing Let's Encrypt certificate"
59
         echo $"Renewing Let's Encrypt certificate"
60
     fi
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
         echo $"Unable to add Let's encrypt certificate"
63
         echo $"Unable to add Let's encrypt certificate"
65
         exit 6328
64
         exit 6328
66
     fi
65
     fi
195
 shift
194
 shift
196
 done
195
 done
197
 
196
 
198
-if [ ! $HOSTNAME ]; then
197
+if [ ! "$HOSTNAME" ]; then
199
     echo $'No hostname specified'
198
     echo $'No hostname specified'
200
     exit 5748
199
     exit 5748
201
 fi
200
 fi
206
 fi
205
 fi
207
 
206
 
208
 # check that the web site exists
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
     echo $"/etc/nginx/sites-available/$HOSTNAME does not exist"
209
     echo $"/etc/nginx/sites-available/$HOSTNAME does not exist"
211
     exit 7598
210
     exit 7598
212
 fi
211
 fi

+ 15
- 15
src/freedombone-repair-database Целия файл

29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
29
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
 
30
 
31
 PROJECT_NAME='freedombone'
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
 export TEXTDOMAIN=${PROJECT_NAME}-repair-databases
35
 export TEXTDOMAIN=${PROJECT_NAME}-repair-databases
36
 export TEXTDOMAINDIR="/usr/share/locale"
36
 export TEXTDOMAINDIR="/usr/share/locale"
37
 
37
 
38
 # The database to be repaired
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
 ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
42
 ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
43
 
43
 
44
 # Frequency - daily/weekly
44
 # Frequency - daily/weekly
62
 
62
 
63
 umask 0077
63
 umask 0077
64
 
64
 
65
-if [ $2 ]; then
66
-    BACKUP_TYPE=$2
65
+if [ "$2" ]; then
66
+    BACKUP_TYPE="$2"
67
 fi
67
 fi
68
 
68
 
69
 # check the database
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
 # Attempt to repair the database if it contains errors
72
 # Attempt to repair the database if it contains errors
73
 if grep -q "Error" "$TEMPFILE"; then
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
 else
75
 else
76
     # No errors were found, so exit
76
     # No errors were found, so exit
77
-    rm -f $TEMPFILE
77
+    rm -f "$TEMPFILE"
78
     exit 0
78
     exit 0
79
 fi
79
 fi
80
-rm -f $TEMPFILE
80
+rm -f "$TEMPFILE"
81
 
81
 
82
 # Check the database again
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
 # If it still contains errors then restore from backup
85
 # If it still contains errors then restore from backup
86
 if grep -q "Error" "$TEMPFILE"; then
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
     # Send a warning email
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
     exit 1
93
     exit 1
94
 fi
94
 fi
95
-rm -f $TEMPFILE
95
+rm -f "$TEMPFILE"
96
 
96
 
97
 exit 0
97
 exit 0

+ 145
- 130
src/freedombone-restore-local Целия файл

31
 PROJECT_NAME='freedombone'
31
 PROJECT_NAME='freedombone'
32
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
32
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
33
 MONGODB_APPS_FILE=$HOME/.mongodbapps
33
 MONGODB_APPS_FILE=$HOME/.mongodbapps
34
-CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
34
+CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
35
 BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
35
 BACKUP_EXTRA_DIRECTORIES=/root/backup-extra-dirs.csv
36
 
36
 
37
 # whether to restore everything or just a specific application
37
 # whether to restore everything or just a specific application
67
 source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
67
 source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
68
 
68
 
69
 # include utils which allow function_check, go and drive mount
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
 for f in $UTILS_FILES
71
 for f in $UTILS_FILES
72
 do
72
 do
73
-    source $f
73
+    source "$f"
74
 done
74
 done
75
 
75
 
76
 clear
76
 clear
83
 
83
 
84
 read_config_param USB_DRIVE
84
 read_config_param USB_DRIVE
85
 
85
 
86
-if [ -f $COMPLETION_FILE ]; then
86
+if [ -f "$COMPLETION_FILE" ]; then
87
     ADMIN_USERNAME=$(get_completion_param "Admin user")
87
     ADMIN_USERNAME=$(get_completion_param "Admin user")
88
 fi
88
 fi
89
 
89
 
98
 
98
 
99
 function check_admin_user {
99
 function check_admin_user {
100
     echo $"Checking that admin user exists"
100
     echo $"Checking that admin user exists"
101
-    if [ ! -d /home/$ADMIN_USERNAME ]; then
101
+    if [ ! -d "/home/$ADMIN_USERNAME" ]; then
102
         echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username."
102
         echo $"Username $ADMIN_USERNAME not found. Reinstall ${PROJECT_NAME} with this username."
103
         set_user_permissions
103
         set_user_permissions
104
         backup_unmount_drive
104
         backup_unmount_drive
108
 
108
 
109
 function copy_gpg_keys {
109
 function copy_gpg_keys {
110
     echo $"Copying GPG keys from admin user to root"
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
     gpg_set_permissions root
112
     gpg_set_permissions root
113
 }
113
 }
114
 
114
 
185
         #    fi
185
         #    fi
186
         #fi
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
                 set_user_permissions
190
                 set_user_permissions
192
                 backup_unmount_drive
191
                 backup_unmount_drive
193
-                rm -rf $temp_restore_dir
192
+                rm -rf "$temp_restore_dir"
194
                 exit 859034853
193
                 exit 859034853
195
             fi
194
             fi
196
         fi
195
         fi
210
         #    fi
209
         #    fi
211
         #fi
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
                 set_user_permissions
214
                 set_user_permissions
217
                 backup_unmount_drive
215
                 backup_unmount_drive
218
-                rm -rf $temp_restore_dir
216
+                rm -rf "$temp_restore_dir"
219
                 exit 62121
217
                 exit 62121
220
             fi
218
             fi
221
         fi
219
         fi
274
             else
272
             else
275
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
273
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
276
             fi
274
             fi
275
+            # shellcheck disable=SC2181
277
             if [ ! "$?" = "0" ]; then
276
             if [ ! "$?" = "0" ]; then
278
                 echo $"Try again using the password obtained from backup"
277
                 echo $"Try again using the password obtained from backup"
279
                 db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
278
                 db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
283
                     mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
282
                     mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
284
                 fi
283
                 fi
285
             fi
284
             fi
285
+            # shellcheck disable=SC2181
286
             if [ ! "$?" = "0" ]; then
286
             if [ ! "$?" = "0" ]; then
287
                 echo "$mysqlsuccess"
287
                 echo "$mysqlsuccess"
288
                 set_user_permissions
288
                 set_user_permissions
292
             echo $"Restarting database"
292
             echo $"Restarting database"
293
             systemctl restart mariadb
293
             systemctl restart mariadb
294
             echo $"Ensure MariaDB handles authentication"
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
             mariadb_fix_authentication
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
         fi
298
         fi
299
         rm -rf $temp_restore_dir
299
         rm -rf $temp_restore_dir
300
     fi
300
     fi
328
             else
328
             else
329
                 mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
329
                 mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
330
             fi
330
             fi
331
+            # shellcheck disable=SC2181
331
             if [ ! "$?" = "0" ]; then
332
             if [ ! "$?" = "0" ]; then
332
                 echo $"Try again using the password obtained from backup"
333
                 echo $"Try again using the password obtained from backup"
333
                 db_pass=$(${PROJECT_NAME}-pass -u root -a postgresql)
334
                 db_pass=$(${PROJECT_NAME}-pass -u root -a postgresql)
337
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
338
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
338
                 fi
339
                 fi
339
             fi
340
             fi
341
+            # shellcheck disable=SC2181
340
             if [ ! "$?" = "0" ]; then
342
             if [ ! "$?" = "0" ]; then
341
                 echo "$mysqlsuccess"
343
                 echo "$mysqlsuccess"
342
                 set_user_permissions
344
                 set_user_permissions
346
             echo $"Restarting database"
348
             echo $"Restarting database"
347
             systemctl restart postgresql
349
             systemctl restart postgresql
348
             echo $"Ensure postgresql handles authentication"
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
         fi
353
         fi
352
         rm -rf $temp_restore_dir
354
         rm -rf $temp_restore_dir
353
     fi
355
     fi
411
             fi
413
             fi
412
 
414
 
413
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
418
                 fi
417
                 echo $"Restoring Mutt configurations for $USERNAME"
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
                 echo $"Restoring Mutt settings for $USERNAME"
421
                 echo $"Restoring Mutt settings for $USERNAME"
420
                 temp_restore_dir=/root/tempmutt
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
                     fi
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
                         sed -i '/set sidebar_delim/d' /etc/Muttrc
432
                         sed -i '/set sidebar_delim/d' /etc/Muttrc
431
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
433
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
432
                     fi
434
                     fi
433
                 else
435
                 else
434
                     if [ -f $temp_restore_dir/.muttrc ]; then
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
                     fi
440
                     fi
439
                     if [ -f $temp_restore_dir/Muttrc ]; then
441
                     if [ -f $temp_restore_dir/Muttrc ]; then
440
                         cp -f $temp_restore_dir/Muttrc /etc/Muttrc
442
                         cp -f $temp_restore_dir/Muttrc /etc/Muttrc
442
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
444
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
443
                     fi
445
                     fi
444
                 fi
446
                 fi
447
+                # shellcheck disable=SC2181
445
                 if [ ! "$?" = "0" ]; then
448
                 if [ ! "$?" = "0" ]; then
446
                     rm -rf $temp_restore_dir
449
                     rm -rf $temp_restore_dir
447
                     set_user_permissions
450
                     set_user_permissions
463
         for d in $USB_MOUNT/backup/gnupg/*/ ; do
466
         for d in $USB_MOUNT/backup/gnupg/*/ ; do
464
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
467
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
465
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
471
                 fi
469
                 echo $"Restoring gnupg settings for $USERNAME"
472
                 echo $"Restoring gnupg settings for $USERNAME"
470
                 temp_restore_dir=/root/tempgnupg
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
                 else
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
                     fi
480
                     fi
478
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.gnupg/
481
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.gnupg/"
479
                 fi
482
                 fi
483
+                # shellcheck disable=SC2181
480
                 if [ ! "$?" = "0" ]; then
484
                 if [ ! "$?" = "0" ]; then
481
                     rm -rf $temp_restore_dir
485
                     rm -rf $temp_restore_dir
482
                     set_user_permissions
486
                     set_user_permissions
484
                     exit 276
488
                     exit 276
485
                 fi
489
                 fi
486
                 rm -rf $temp_restore_dir
490
                 rm -rf $temp_restore_dir
487
-                gpg_set_permissions $USERNAME
491
+                gpg_set_permissions "$USERNAME"
488
                 if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
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
                         set_user_permissions
494
                         set_user_permissions
492
                         backup_unmount_drive
495
                         backup_unmount_drive
493
                         exit 283
496
                         exit 283
509
         for d in $USB_MOUNT/backup/procmail/*/ ; do
512
         for d in $USB_MOUNT/backup/procmail/*/ ; do
510
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
513
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
511
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
517
                 fi
515
                 echo $"Restoring procmail settings for $USERNAME"
518
                 echo $"Restoring procmail settings for $USERNAME"
516
                 temp_restore_dir=/root/tempprocmail
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
                 if [ -d $temp_restore_dir ]; then
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
                     else
524
                     else
522
-                        cp -f $temp_restore_dir/.procmailrc /home/$USERNAME/.procmailrc
525
+                        cp -f "$temp_restore_dir/.procmailrc" "/home/$USERNAME/.procmailrc"
523
                     fi
526
                     fi
527
+                    # shellcheck disable=SC2181
524
                     if [ ! "$?" = "0" ]; then
528
                     if [ ! "$?" = "0" ]; then
525
                         rm -rf $temp_restore_dir
529
                         rm -rf $temp_restore_dir
526
                         set_user_permissions
530
                         set_user_permissions
544
         for d in $USB_MOUNT/backup/spamassassin/*/ ; do
548
         for d in $USB_MOUNT/backup/spamassassin/*/ ; do
545
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
549
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
546
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                     fi
554
                     fi
551
                     echo $"Restoring spamassassin settings for $USERNAME"
555
                     echo $"Restoring spamassassin settings for $USERNAME"
552
                     temp_restore_dir=/root/tempspamassassin
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
                     else
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
                     fi
563
                     fi
560
-                        cp -rf $temp_restore_dir/* /home/$USERNAME/.spamassassin/
564
+                        cp -rf "$temp_restore_dir/*" "/home/$USERNAME/.spamassassin/"
561
                     fi
565
                     fi
566
+                    # shellcheck disable=SC2181
562
                     if [ ! "$?" = "0" ]; then
567
                     if [ ! "$?" = "0" ]; then
563
                         rm -rf $temp_restore_dir
568
                         rm -rf $temp_restore_dir
564
                         set_user_permissions
569
                         set_user_permissions
583
 
588
 
584
         # Make a backup of the original README file
589
         # Make a backup of the original README file
585
         # incase old passwords need to be used
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
             fi
594
             fi
590
         fi
595
         fi
591
 
596
 
592
         temp_restore_dir=/root/tempreadme
597
         temp_restore_dir=/root/tempreadme
593
         restore_directory_from_usb $temp_restore_dir readme
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
         else
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
         fi
603
         fi
604
+        # shellcheck disable=SC2181
599
         if [ ! "$?" = "0" ]; then
605
         if [ ! "$?" = "0" ]; then
600
             rm -rf $temp_restore_dir
606
             rm -rf $temp_restore_dir
601
             set_user_permissions
607
             set_user_permissions
616
         for d in $USB_MOUNT/backup/ssh/*/ ; do
622
         for d in $USB_MOUNT/backup/ssh/*/ ; do
617
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
623
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
618
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
627
                 fi
622
                 echo $"Restoring ssh keys for $USERNAME"
628
                 echo $"Restoring ssh keys for $USERNAME"
623
                 temp_restore_dir=/root/tempssh
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
                 else
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
                     fi
636
                     fi
631
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.ssh/
637
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.ssh/"
632
                 fi
638
                 fi
639
+                # shellcheck disable=SC2181
633
                 if [ ! "$?" = "0" ]; then
640
                 if [ ! "$?" = "0" ]; then
634
                     rm -rf $temp_restore_dir
641
                     rm -rf $temp_restore_dir
635
                     set_user_permissions
642
                     set_user_permissions
652
         for d in $USB_MOUNT/backup/config/*/ ; do
659
         for d in $USB_MOUNT/backup/config/*/ ; do
653
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
660
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
654
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
664
                 fi
658
                 echo $"Restoring config files for $USERNAME"
665
                 echo $"Restoring config files for $USERNAME"
659
                 temp_restore_dir=/root/tempconfig
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
                 else
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
                     fi
673
                     fi
667
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.config/
674
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.config/"
668
                 fi
675
                 fi
676
+                # shellcheck disable=SC2181
669
                 if [ ! "$?" = "0" ]; then
677
                 if [ ! "$?" = "0" ]; then
670
                     rm -rf $temp_restore_dir
678
                     rm -rf $temp_restore_dir
671
                     set_user_permissions
679
                     set_user_permissions
688
         for d in $USB_MOUNT/backup/monkeysphere/*/ ; do
696
         for d in $USB_MOUNT/backup/monkeysphere/*/ ; do
689
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
697
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
690
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
701
                 fi
694
                 echo $"Restoring monkeysphere ids for $USERNAME"
702
                 echo $"Restoring monkeysphere ids for $USERNAME"
695
                 temp_restore_dir=/root/tempmonkeysphere
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
                 else
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
                     fi
710
                     fi
703
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.monkeysphere
711
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.monkeysphere"
704
                 fi
712
                 fi
713
+                # shellcheck disable=SC2181
705
                 if [ ! "$?" = "0" ]; then
714
                 if [ ! "$?" = "0" ]; then
706
                     rm -rf $temp_restore_dir
715
                     rm -rf $temp_restore_dir
707
                     set_user_permissions
716
                     set_user_permissions
716
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
725
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
717
         read_config_param MY_EMAIL_ADDRESS
726
         read_config_param MY_EMAIL_ADDRESS
718
         MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
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
         monkeysphere-authentication update-users
730
         monkeysphere-authentication update-users
722
     fi
731
     fi
723
 }
732
 }
732
         for d in $USB_MOUNT/backup/fin/*/ ; do
741
         for d in $USB_MOUNT/backup/fin/*/ ; do
733
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
742
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
734
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
746
                 fi
738
                 echo $"Restoring fin files for $USERNAME"
747
                 echo $"Restoring fin files for $USERNAME"
739
                 temp_restore_dir=/root/tempfin
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
                 else
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
                     fi
755
                     fi
747
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.fin/
756
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.fin/"
748
                 fi
757
                 fi
758
+                # shellcheck disable=SC2181
749
                 if [ ! "$?" = "0" ]; then
759
                 if [ ! "$?" = "0" ]; then
750
                     rm -rf $temp_restore_dir
760
                     rm -rf $temp_restore_dir
751
                     set_user_permissions
761
                     set_user_permissions
768
         for d in $USB_MOUNT/backup/local/*/ ; do
778
         for d in $USB_MOUNT/backup/local/*/ ; do
769
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
779
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
770
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
783
                 fi
774
                 echo $"Restoring local files for $USERNAME"
784
                 echo $"Restoring local files for $USERNAME"
775
                 temp_restore_dir=/root/templocal
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
                 else
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
                     fi
792
                     fi
783
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.local/
793
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.local/"
784
                 fi
794
                 fi
795
+                # shellcheck disable=SC2181
785
                 if [ ! "$?" = "0" ]; then
796
                 if [ ! "$?" = "0" ]; then
786
                     rm -rf $temp_restore_dir
797
                     rm -rf $temp_restore_dir
787
                     set_user_permissions
798
                     set_user_permissions
809
         else
820
         else
810
             cp -r /root/tempssl/* /etc/ssl/
821
             cp -r /root/tempssl/* /etc/ssl/
811
         fi
822
         fi
823
+        # shellcheck disable=SC2181
812
         if [ ! "$?" = "0" ]; then
824
         if [ ! "$?" = "0" ]; then
813
             set_user_permissions
825
             set_user_permissions
814
             backup_unmount_drive
826
             backup_unmount_drive
853
         for d in $USB_MOUNT/backup/personal/*/ ; do
865
         for d in $USB_MOUNT/backup/personal/*/ ; do
854
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
866
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
855
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                     fi
871
                     fi
860
                     echo $"Restoring personal settings for $USERNAME"
872
                     echo $"Restoring personal settings for $USERNAME"
861
                     temp_restore_dir=/root/temppersonal
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
                     fi
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
                     else
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
                         fi
883
                         fi
872
-                        cp -r $temp_restore_dir/* /home/$USERNAME/personal/
884
+                        cp -r $temp_restore_dir/* "/home/$USERNAME/personal/"
873
                     fi
885
                     fi
886
+                    # shellcheck disable=SC2181
874
                     if [ ! "$?" = "0" ]; then
887
                     if [ ! "$?" = "0" ]; then
875
                         set_user_permissions
888
                         set_user_permissions
876
                         backup_unmount_drive
889
                         backup_unmount_drive
898
         else
911
         else
899
             cp -r $temp_restore_dir/* /var/spool/mlmmj/
912
             cp -r $temp_restore_dir/* /var/spool/mlmmj/
900
         fi
913
         fi
914
+        # shellcheck disable=SC2181
901
         if [ ! "$?" = "0" ]; then
915
         if [ ! "$?" = "0" ]; then
902
             set_user_permissions
916
             set_user_permissions
903
             backup_unmount_drive
917
             backup_unmount_drive
917
         for d in $USB_MOUNT/backup/mail/*/ ; do
931
         for d in $USB_MOUNT/backup/mail/*/ ; do
918
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
932
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
919
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
936
                 fi
923
                 echo $"Restoring emails for $USERNAME"
937
                 echo $"Restoring emails for $USERNAME"
924
                 temp_restore_dir=/root/tempmail
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
                 fi
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
                 else
945
                 else
932
                     tar -xzvf $temp_restore_dir/maildir.tar.gz -C /
946
                     tar -xzvf $temp_restore_dir/maildir.tar.gz -C /
933
                 fi
947
                 fi
948
+                # shellcheck disable=SC2181
934
                 if [ ! "$?" = "0" ]; then
949
                 if [ ! "$?" = "0" ]; then
935
                     set_user_permissions
950
                     set_user_permissions
936
                     backup_unmount_drive
951
                     backup_unmount_drive
943
 }
958
 }
944
 
959
 
945
 function get_restore_app {
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
             echo $"Restore $RESTORE_APP"
964
             echo $"Restore $RESTORE_APP"
950
         fi
965
         fi
951
     fi
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
 check_backup_exists
971
 check_backup_exists
957
 check_admin_user
972
 check_admin_user
958
 copy_gpg_keys
973
 copy_gpg_keys
979
 restore_personal_settings
994
 restore_personal_settings
980
 restore_mailing_list
995
 restore_mailing_list
981
 restore_email
996
 restore_email
982
-restore_apps local $RESTORE_APP
997
+restore_apps local "$RESTORE_APP"
983
 set_user_permissions
998
 set_user_permissions
984
 update_default_domain
999
 update_default_domain
985
 backup_unmount_drive
1000
 backup_unmount_drive

+ 153
- 139
src/freedombone-restore-remote Целия файл

37
 export TEXTDOMAIN=${PROJECT_NAME}-restore-remote
37
 export TEXTDOMAIN=${PROJECT_NAME}-restore-remote
38
 export TEXTDOMAINDIR="/usr/share/locale"
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
 for f in $UTILS_FILES
41
 for f in $UTILS_FILES
42
 do
42
 do
43
-    source $f
43
+    source "$f"
44
 done
44
 done
45
 
45
 
46
-SERVER_NAME=$1
46
+SERVER_NAME="$1"
47
 
47
 
48
 # whether to restore everything or just a specific application
48
 # whether to restore everything or just a specific application
49
 RESTORE_APP='all'
49
 RESTORE_APP='all'
50
 
50
 
51
-if [ ${2} ]; then
52
-    RESTORE_APP=${2}
51
+if [ "${2}" ]; then
52
+    RESTORE_APP="${2}"
53
 fi
53
 fi
54
 
54
 
55
 ADMIN_USERNAME=$(get_completion_param "Admin user")
55
 ADMIN_USERNAME=$(get_completion_param "Admin user")
60
 
60
 
61
 BACKUP_LIST=/home/${ADMIN_USERNAME}/backup.list
61
 BACKUP_LIST=/home/${ADMIN_USERNAME}/backup.list
62
 
62
 
63
-if [ ! $SERVER_NAME ]; then
63
+if [ ! "$SERVER_NAME" ]; then
64
     echo $'restorefromfriend [server]'
64
     echo $'restorefromfriend [server]'
65
     exit 1
65
     exit 1
66
 fi
66
 fi
67
 
67
 
68
-if [ ! -f $BACKUP_LIST ]; then
68
+if [ ! -f "$BACKUP_LIST" ]; then
69
     echo $"No friends list found at $BACKUP_LIST"
69
     echo $"No friends list found at $BACKUP_LIST"
70
     exit 2
70
     exit 2
71
 fi
71
 fi
72
 
72
 
73
-if ! grep -q "$SERVER_NAME" $BACKUP_LIST; then
73
+if ! grep -q "$SERVER_NAME" "$BACKUP_LIST"; then
74
     echo $"Server not found within the friends list"
74
     echo $"Server not found within the friends list"
75
     exit 3
75
     exit 3
76
 fi
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
 REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY
82
 REMOTE_SERVER=$REMOTE_SERVER:$REMOTE_DIRECTORY
83
 
83
 
84
 NOW=$(date +"%Y-%m-%d %H:%M:%S")
84
 NOW=$(date +"%Y-%m-%d %H:%M:%S")
85
 
85
 
86
 echo "$NOW Starting restore from $REMOTE_SERVER" >> /var/log/remotebackups.log
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
     echo "$NOW Restore from $REMOTE_SERVER failed" >> /var/log/remotebackups.log
88
     echo "$NOW Restore from $REMOTE_SERVER failed" >> /var/log/remotebackups.log
90
     # Send a warning email
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
     exit 790
91
     exit 790
93
 else
92
 else
94
     echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log
93
     echo "$NOW Restored encrypted data from $REMOTE_SERVER" >> /var/log/remotebackups.log
95
 fi
94
 fi
96
 
95
 
97
 # MariaDB password
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
 function copy_gpg_keys {
99
 function copy_gpg_keys {
101
     echo $"Copying GPG keys from admin user to root"
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
     gpg_set_permissions root
102
     gpg_set_permissions root
104
 }
103
 }
105
 
104
 
110
         fi
109
         fi
111
     fi
110
     fi
112
 
111
 
113
-    if [ -d $USB_MOUNT/backup/blocklist ]; then
112
+    if [ -d "$USB_MOUNT/backup/blocklist" ]; then
114
         echo $"Restoring blocklist"
113
         echo $"Restoring blocklist"
115
         temp_restore_dir=/root/tempblocklist
114
         temp_restore_dir=/root/tempblocklist
116
         restore_directory_from_friend $temp_restore_dir blocklist
115
         restore_directory_from_friend $temp_restore_dir blocklist
173
         #    fi
172
         #    fi
174
         #fi
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
                 unmount_drive
177
                 unmount_drive
180
                 rm -rf $temp_restore_dir
178
                 rm -rf $temp_restore_dir
181
                 exit 7835335
179
                 exit 7835335
196
         #    fi
194
         #    fi
197
         #fi
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
                 unmount_drive
199
                 unmount_drive
203
                 rm -rf $temp_restore_dir
200
                 rm -rf $temp_restore_dir
204
                 exit 62121
201
                 exit 62121
242
             else
239
             else
243
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
240
                 mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
244
             fi
241
             fi
242
+            # shellcheck disable=SC2181
245
             if [ ! "$?" = "0" ]; then
243
             if [ ! "$?" = "0" ]; then
246
                 echo $"Try again using the password obtained from backup"
244
                 echo $"Try again using the password obtained from backup"
247
                 db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
245
                 db_pass=$(${PROJECT_NAME}-pass -u root -a mariadb)
251
                     mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
249
                     mysqlsuccess=$(mysql -u root --password="$db_pass" mysql -o < ${temp_restore_dir}/mysql.sql)
252
                 fi
250
                 fi
253
             fi
251
             fi
252
+            # shellcheck disable=SC2181
254
             if [ ! "$?" = "0" ]; then
253
             if [ ! "$?" = "0" ]; then
255
                 echo "$mysqlsuccess"
254
                 echo "$mysqlsuccess"
256
                 exit 962
255
                 exit 962
258
             echo $"Restarting database"
257
             echo $"Restarting database"
259
             systemctl restart mariadb
258
             systemctl restart mariadb
260
             echo $"Ensure MariaDB handles authentication"
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
             mariadb_fix_authentication
261
             mariadb_fix_authentication
263
         fi
262
         fi
264
         rm -rf ${temp_restore_dir}
263
         rm -rf ${temp_restore_dir}
293
             else
292
             else
294
                 mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
293
                 mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
295
             fi
294
             fi
295
+            # shellcheck disable=SC2181
296
             if [ ! "$?" = "0" ]; then
296
             if [ ! "$?" = "0" ]; then
297
                 echo $"Try again using the password obtained from backup"
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
                 if [ -d ${temp_restore_dir}${temp_restore_dir} ]; then
299
                 if [ -d ${temp_restore_dir}${temp_restore_dir} ]; then
300
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}${temp_restore_dir}/postgresql.sql)
300
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}${temp_restore_dir}/postgresql.sql)
301
                 else
301
                 else
302
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
302
                     mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
303
                 fi
303
                 fi
304
             fi
304
             fi
305
+            # shellcheck disable=SC2181
305
             if [ ! "$?" = "0" ]; then
306
             if [ ! "$?" = "0" ]; then
306
                 echo "$mysqlsuccess"
307
                 echo "$mysqlsuccess"
307
                 exit 962
308
                 exit 962
309
             echo $"Restarting database"
310
             echo $"Restarting database"
310
             systemctl restart postgresql
311
             systemctl restart postgresql
311
             echo $"Ensure postgresql handles authentication"
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
         fi
314
         fi
314
         rm -rf ${temp_restore_dir}
315
         rm -rf ${temp_restore_dir}
315
     fi
316
     fi
367
         fi
368
         fi
368
 
369
 
369
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
374
                 fi
374
                 echo $"Restoring Mutt configurations for $USERNAME"
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
                 echo $"Restoring Mutt settings for $USERNAME"
377
                 echo $"Restoring Mutt settings for $USERNAME"
377
                 temp_restore_dir=/root/tempmutt
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
                     fi
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
                         sed -i '/set sidebar_delim/d' /etc/Muttrc
388
                         sed -i '/set sidebar_delim/d' /etc/Muttrc
388
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
389
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
389
                     fi
390
                     fi
390
                 else
391
                 else
391
                     if [ -f ${temp_restore_dir}/.muttrc ]; then
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
                     fi
396
                     fi
396
                     if [ -f ${temp_restore_dir}/Muttrc ]; then
397
                     if [ -f ${temp_restore_dir}/Muttrc ]; then
397
                         cp -f ${temp_restore_dir}/Muttrc /etc/Muttrc
398
                         cp -f ${temp_restore_dir}/Muttrc /etc/Muttrc
399
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
400
                         sed -i '/set sidebar_sort/d' /etc/Muttrc
400
                     fi
401
                     fi
401
                 fi
402
                 fi
403
+                # shellcheck disable=SC2181
402
                 if [ ! "$?" = "0" ]; then
404
                 if [ ! "$?" = "0" ]; then
403
                     rm -rf ${temp_restore_dir}
405
                     rm -rf ${temp_restore_dir}
404
                     exit 276
406
                     exit 276
417
     for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
419
     for d in $SERVER_DIRECTORY/backup/gnupg/*/ ; do
418
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
420
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
419
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
425
                 fi
424
                 echo $"Restoring gnupg settings for $USERNAME"
426
                 echo $"Restoring gnupg settings for $USERNAME"
425
                 temp_restore_dir=/root/tempgnupg
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
                 else
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
                     fi
434
                     fi
433
-                    cp -r ${temp_restore_dir}/* /home/$USERNAME/.gnupg/
435
+                    cp -r "${temp_restore_dir}/*" "/home/$USERNAME/.gnupg/"
434
                 fi
436
                 fi
437
+                # shellcheck disable=SC2181
435
                 if [ ! "$?" = "0" ]; then
438
                 if [ ! "$?" = "0" ]; then
436
                     rm -rf ${temp_restore_dir}
439
                     rm -rf ${temp_restore_dir}
437
                     exit 276
440
                     exit 276
438
                 fi
441
                 fi
439
                 rm -rf ${temp_restore_dir}
442
                 rm -rf ${temp_restore_dir}
440
                 if [[ "$USERNAME" == "$ADMIN_USERNAME" ]]; then
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
                         exit 283
445
                         exit 283
444
                     fi
446
                     fi
445
                     gpg_set_permissions root
447
                     gpg_set_permissions root
458
     for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
460
     for d in $SERVER_DIRECTORY/backup/procmail/*/ ; do
459
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
461
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
460
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
466
                 fi
465
                 echo $"Restoring procmail settings for $USERNAME"
467
                 echo $"Restoring procmail settings for $USERNAME"
466
                 temp_restore_dir=/root/tempprocmail
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
                 else
472
                 else
471
-                    cp -f ${temp_restore_dir}/.procmailrc /home/$USERNAME/.procmailrc
473
+                    cp -f "${temp_restore_dir}/.procmailrc" "/home/$USERNAME/.procmailrc"
472
                 fi
474
                 fi
475
+                # shellcheck disable=SC2181
473
                 if [ ! "$?" = "0" ]; then
476
                 if [ ! "$?" = "0" ]; then
474
                     rm -rf ${temp_restore_dir}
477
                     rm -rf ${temp_restore_dir}
475
                     exit 276
478
                     exit 276
489
     for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
492
     for d in $SERVER_DIRECTORY/backup/spamassassin/*/ ; do
490
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
493
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
491
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
498
                 fi
496
                 echo $"Restoring spamassassin settings for $USERNAME"
499
                 echo $"Restoring spamassassin settings for $USERNAME"
497
                 temp_restore_dir=/root/tempspamassassin
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
                 else
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
                     fi
507
                     fi
505
-                    cp -rf $temp_restore_dir/* /home/$USERNAME/.spamassassin/
508
+                    cp -rf $temp_restore_dir/* "/home/$USERNAME/.spamassassin/"
506
                 fi
509
                 fi
510
+                # shellcheck disable=SC2181
507
                 if [ ! "$?" = "0" ]; then
511
                 if [ ! "$?" = "0" ]; then
508
                     rm -rf $temp_restore_dir
512
                     rm -rf $temp_restore_dir
509
                     exit 276
513
                     exit 276
524
         echo $"Restoring README"
528
         echo $"Restoring README"
525
         temp_restore_dir=/root/tempreadme
529
         temp_restore_dir=/root/tempreadme
526
         restore_directory_from_friend $temp_restore_dir readme
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
         else
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
         fi
535
         fi
536
+        # shellcheck disable=SC2181
532
         if [ ! "$?" = "0" ]; then
537
         if [ ! "$?" = "0" ]; then
533
             rm -rf $temp_restore_dir
538
             rm -rf $temp_restore_dir
534
             exit 276
539
             exit 276
546
     for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
551
     for d in $SERVER_DIRECTORY/backup/ssh/*/ ; do
547
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
552
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
548
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
557
                 fi
553
                 echo $"Restoring ssh keys for $USERNAME"
558
                 echo $"Restoring ssh keys for $USERNAME"
554
                 temp_restore_dir=/root/tempssh
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
                 else
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
                     fi
566
                     fi
562
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.ssh/
567
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.ssh/"
563
                 fi
568
                 fi
569
+                # shellcheck disable=SC2181
564
                 if [ ! "$?" = "0" ]; then
570
                 if [ ! "$?" = "0" ]; then
565
                     rm -rf $temp_restore_dir
571
                     rm -rf $temp_restore_dir
566
                     exit 664
572
                     exit 664
580
     for d in $SERVER_DIRECTORY/backup/config/*/ ; do
586
     for d in $SERVER_DIRECTORY/backup/config/*/ ; do
581
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
587
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
582
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
592
                 fi
587
                 echo $"Restoring config files for $USERNAME"
593
                 echo $"Restoring config files for $USERNAME"
588
                 temp_restore_dir=/root/tempconfig
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
                 else
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
                     fi
601
                     fi
596
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.config/
602
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.config/"
597
                 fi
603
                 fi
604
+                # shellcheck disable=SC2181
598
                 if [ ! "$?" = "0" ]; then
605
                 if [ ! "$?" = "0" ]; then
599
                     rm -rf $temp_restore_dir
606
                     rm -rf $temp_restore_dir
600
                     exit 664
607
                     exit 664
614
     for d in $SERVER_DIRECTORY/backup/monkeysphere/*/ ; do
621
     for d in $SERVER_DIRECTORY/backup/monkeysphere/*/ ; do
615
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
622
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
616
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
627
                 fi
621
                 echo $"Restoring monkeysphere ids for $USERNAME"
628
                 echo $"Restoring monkeysphere ids for $USERNAME"
622
                 temp_restore_dir=/root/tempmonkeysphere
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
                 else
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
                     fi
636
                     fi
630
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.monkeysphere/
637
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.monkeysphere/"
631
                 fi
638
                 fi
639
+                # shellcheck disable=SC2181
632
                 if [ ! "$?" = "0" ]; then
640
                 if [ ! "$?" = "0" ]; then
633
                     rm -rf $temp_restore_dir
641
                     rm -rf $temp_restore_dir
634
                     exit 664
642
                     exit 664
641
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
649
         MY_EMAIL_ADDRESS="${ADMIN_USERNAME}@${HOSTNAME}"
642
         read_config_param MY_EMAIL_ADDRESS
650
         read_config_param MY_EMAIL_ADDRESS
643
         MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADMIN_USERNAME" "$MY_EMAIL_ADDRESS")
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
         monkeysphere-authentication update-users
654
         monkeysphere-authentication update-users
647
     done
655
     done
648
 }
656
 }
656
     for d in $SERVER_DIRECTORY/backup/fin/*/ ; do
664
     for d in $SERVER_DIRECTORY/backup/fin/*/ ; do
657
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
665
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
658
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
670
                 fi
663
                 echo $"Restoring fin files for $USERNAME"
671
                 echo $"Restoring fin files for $USERNAME"
664
                 temp_restore_dir=/root/tempfin
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
                 else
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
                     fi
679
                     fi
672
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.fin/
680
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.fin/"
673
                 fi
681
                 fi
682
+                # shellcheck disable=SC2181
674
                 if [ ! "$?" = "0" ]; then
683
                 if [ ! "$?" = "0" ]; then
675
                     rm -rf $temp_restore_dir
684
                     rm -rf $temp_restore_dir
676
                     exit 664
685
                     exit 664
690
     for d in $SERVER_DIRECTORY/backup/local/*/ ; do
699
     for d in $SERVER_DIRECTORY/backup/local/*/ ; do
691
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
700
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
692
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
705
                 fi
697
                 echo $"Restoring local files for $USERNAME"
706
                 echo $"Restoring local files for $USERNAME"
698
                 temp_restore_dir=/root/templocal
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
                 else
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
                     fi
714
                     fi
706
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.local/
715
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/.local/"
707
                 fi
716
                 fi
717
+                # shellcheck disable=SC2181
708
                 if [ ! "$?" = "0" ]; then
718
                 if [ ! "$?" = "0" ]; then
709
                     rm -rf $temp_restore_dir
719
                     rm -rf $temp_restore_dir
710
                     exit 664
720
                     exit 664
729
         else
739
         else
730
             cp -r /root/tempssl/* /etc/ssl/
740
             cp -r /root/tempssl/* /etc/ssl/
731
         fi
741
         fi
742
+        # shellcheck disable=SC2181
732
         if [ ! "$?" = "0" ]; then
743
         if [ ! "$?" = "0" ]; then
733
             exit 276
744
             exit 276
734
         fi
745
         fi
770
     for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
781
     for d in $SERVER_DIRECTORY/backup/personal/*/ ; do
771
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
782
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
772
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
787
                 fi
777
                 echo $"Restoring personal settings for $USERNAME"
788
                 echo $"Restoring personal settings for $USERNAME"
778
                 temp_restore_dir=/root/temppersonal
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
                     fi
794
                     fi
784
-                    mv $temp_restore_dir/home/$USERNAME/personal /home/$USERNAME
795
+                    mv "$temp_restore_dir/home/$USERNAME/personal" "/home/$USERNAME"
785
                 else
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
                     fi
799
                     fi
789
-                    cp -r $temp_restore_dir/* /home/$USERNAME/personal/
800
+                    cp -r $temp_restore_dir/* "/home/$USERNAME/personal/"
790
                 fi
801
                 fi
802
+                # shellcheck disable=SC2181
791
                 if [ ! "$?" = "0" ]; then
803
                 if [ ! "$?" = "0" ]; then
792
                     exit 18437643
804
                     exit 18437643
793
                 fi
805
                 fi
812
         else
824
         else
813
             cp -r $temp_restore_dir/* /var/spool/mlmmj/
825
             cp -r $temp_restore_dir/* /var/spool/mlmmj/
814
         fi
826
         fi
827
+        # shellcheck disable=SC2181
815
         if [ ! "$?" = "0" ]; then
828
         if [ ! "$?" = "0" ]; then
816
             exit 526
829
             exit 526
817
         fi
830
         fi
828
     for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
841
     for d in $SERVER_DIRECTORY/backup/mail/*/ ; do
829
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
842
         USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
830
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
847
                 fi
835
                 echo $"Restoring emails for $USERNAME"
848
                 echo $"Restoring emails for $USERNAME"
836
                 temp_restore_dir=/root/tempmail
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
                 fi
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
                 else
856
                 else
844
                     tar -xzvf $temp_restore_dir/maildir.tar.gz -C /
857
                     tar -xzvf $temp_restore_dir/maildir.tar.gz -C /
845
                 fi
858
                 fi
859
+                # shellcheck disable=SC2181
846
                 if [ ! "$?" = "0" ]; then
860
                 if [ ! "$?" = "0" ]; then
847
                     exit 927
861
                     exit 927
848
                 fi
862
                 fi
854
 
868
 
855
 # Social key management
869
 # Social key management
856
 # Recover any key fragments and reconstruct the gpg key
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
 copy_gpg_keys
873
 copy_gpg_keys
860
 gpg_agent_setup root
874
 gpg_agent_setup root

+ 3
- 3
src/freedombone-rmemail Целия файл

70
     show_help
70
     show_help
71
 fi
71
 fi
72
 
72
 
73
-MUTTRC=/home/$MYUSERNAME/.muttrc
73
+MUTTRC="/home/$MYUSERNAME/.muttrc"
74
 PM=/home/$MYUSERNAME/.procmailrc
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
 fi
78
 fi
79
 
79
 
80
 exit 0
80
 exit 0

+ 6
- 6
src/freedombone-rmlist Целия файл

77
 fi
77
 fi
78
 
78
 
79
 MUTTRC=/home/$MYUSERNAME/.muttrc
79
 MUTTRC=/home/$MYUSERNAME/.muttrc
80
-MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
80
+MUTT_MAILBOXES=$(grep "mailboxes =" "$MUTTRC")
81
 if [[ $MUTT_MAILBOXES == *$MAILINGLIST* ]]; then
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
 fi
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
     fi
89
     fi
90
 fi
90
 fi
91
 
91
 

+ 25
- 25
src/freedombone-rmuser Целия файл

36
 
36
 
37
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
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
 for f in $UTILS_FILES
40
 for f in $UTILS_FILES
41
 do
41
 do
42
-    source $f
42
+    source "$f"
43
 done
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
 for f in $APP_FILES
46
 for f in $APP_FILES
47
 do
47
 do
48
-    source $f
48
+    source "$f"
49
 done
49
 done
50
 
50
 
51
 read_config_param MY_USERNAME
51
 read_config_param MY_USERNAME
53
 REMOVE_USERNAME=$1
53
 REMOVE_USERNAME=$1
54
 REMOVE_OPTIONS="$2"
54
 REMOVE_OPTIONS="$2"
55
 
55
 
56
-if [ ! $REMOVE_USERNAME ]; then
56
+if [ ! "$REMOVE_USERNAME" ]; then
57
     echo $'Please specify a username to remove'
57
     echo $'Please specify a username to remove'
58
     exit 1
58
     exit 1
59
 fi
59
 fi
68
     exit 3
68
     exit 3
69
 fi
69
 fi
70
 
70
 
71
-if [ ! -d /home/$REMOVE_USERNAME ]; then
71
+if [ ! -d "/home/$REMOVE_USERNAME" ]; then
72
     echo $"Home directory does not exist for $REMOVE_USERNAME"
72
     echo $"Home directory does not exist for $REMOVE_USERNAME"
73
     exit 4
73
     exit 4
74
 fi
74
 fi
75
 
75
 
76
-if [ ! -f $COMPLETION_FILE ]; then
76
+if [ ! -f "$COMPLETION_FILE" ]; then
77
     echo $"$COMPLETION_FILE not found"
77
     echo $"$COMPLETION_FILE not found"
78
     exit 5
78
     exit 5
79
 fi
79
 fi
80
 
80
 
81
-if ! grep -q "Admin user" $COMPLETION_FILE; then
81
+if ! grep -q "Admin user" "$COMPLETION_FILE"; then
82
     echo $"No admin user specified in $COMPLETION_FILE"
82
     echo $"No admin user specified in $COMPLETION_FILE"
83
     exit 6
83
     exit 6
84
 fi
84
 fi
85
 
85
 
86
 ADMIN_USERNAME=$(get_completion_param "Admin user")
86
 ADMIN_USERNAME=$(get_completion_param "Admin user")
87
-if [ ! $ADMIN_USERNAME ]; then
87
+if [ ! "$ADMIN_USERNAME" ]; then
88
     echo $"No admin username specified in $COMPLETION_FILE"
88
     echo $"No admin username specified in $COMPLETION_FILE"
89
     exit 7
89
     exit 7
90
 fi
90
 fi
91
 
91
 
92
-if [[ $REMOVE_USERNAME == $ADMIN_USERNAME ]]; then
92
+if [[ "$REMOVE_USERNAME" == "$ADMIN_USERNAME" ]]; then
93
     echo $"The administrator user cannot be removed"
93
     echo $"The administrator user cannot be removed"
94
     exit 8
94
     exit 8
95
 fi
95
 fi
96
 
96
 
97
 if [[ "$REMOVE_OPTIONS" != '-f' && "$REMOVE_OPTIONS" != '-y' && "$REMOVE_OPTIONS" != '--force' ]]; then
97
 if [[ "$REMOVE_OPTIONS" != '-f' && "$REMOVE_OPTIONS" != '-y' && "$REMOVE_OPTIONS" != '--force' ]]; then
98
     echo $'>>> REMOVE USER <<<'
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
     if [[ $yn != 'y' && $yn != 'Y' && $yn != 'yes' && $yn != 'Yes' && $yn != 'YES' ]]; then
100
     if [[ $yn != 'y' && $yn != 'Y' && $yn != 'yes' && $yn != 'Yes' && $yn != 'YES' ]]; then
101
         echo $"User $REMOVE_USERNAME was not removed"
101
         echo $"User $REMOVE_USERNAME was not removed"
102
         exit 9
102
         exit 9
107
 
107
 
108
 if [ -f /etc/nginx/.htpasswd ]; then
108
 if [ -f /etc/nginx/.htpasswd ]; then
109
     if grep -q "${REMOVE_USERNAME}:" /etc/nginx/.htpasswd; then
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
     fi
111
     fi
112
 fi
112
 fi
113
 
113
 
114
 # remove gpg keys
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
 fi
117
 fi
118
 
118
 
119
 # remove ssh keys
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
 fi
122
 fi
123
 
123
 
124
 echo $'Detecting installed apps...'
124
 echo $'Detecting installed apps...'
126
 get_apps_installed_names
126
 get_apps_installed_names
127
 for app_name in "${APPS_INSTALLED_NAMES[@]}"
127
 for app_name in "${APPS_INSTALLED_NAMES[@]}"
128
 do
128
 do
129
-    if [[ $(function_exists remove_user_${app_name}) == "1" ]]; then
129
+    if [[ $(function_exists "remove_user_${app_name}") == "1" ]]; then
130
         echo $"Removing user from ${app_name}"
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
         fi
135
         fi
136
     fi
136
     fi
137
 done
137
 done
138
 
138
 
139
 chmod 600 /etc/shadow
139
 chmod 600 /etc/shadow
140
 chmod 600 /etc/gshadow
140
 chmod 600 /etc/gshadow
141
-userdel -r $REMOVE_USERNAME
142
-groupdel $REMOVE_USERNAME
141
+userdel -r "$REMOVE_USERNAME"
142
+groupdel "$REMOVE_USERNAME"
143
 chmod 0000 /etc/shadow
143
 chmod 0000 /etc/shadow
144
 chmod 0000 /etc/gshadow
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
 fi
148
 fi
149
 
149
 
150
 echo $"User $REMOVE_USERNAME was removed"
150
 echo $"User $REMOVE_USERNAME was removed"

+ 227
- 206
src/freedombone-sec
Файловите разлики са ограничени, защото са твърде много
Целия файл


+ 44
- 46
src/freedombone-splitkey Целия файл

90
 shift
90
 shift
91
 done
91
 done
92
 
92
 
93
-if [ ! $MY_USERNAME ]; then
93
+if [ ! "$MY_USERNAME" ]; then
94
     show_help
94
     show_help
95
 fi
95
 fi
96
-if [ ! -d /home/$MY_USERNAME ]; then
96
+if [ ! -d "/home/$MY_USERNAME" ]; then
97
     echo $"User $MY_USERNAME does not exist on the system"
97
     echo $"User $MY_USERNAME does not exist on the system"
98
     exit 7270
98
     exit 7270
99
 fi
99
 fi
100
 
100
 
101
-if [ ! -d /home/$MY_USERNAME/.gnupg ]; then
101
+if [ ! -d "/home/$MY_USERNAME/.gnupg" ]; then
102
     echo $'No gpg key found'
102
     echo $'No gpg key found'
103
     exit 5393
103
     exit 5393
104
 fi
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
         echo $'Password file not found'
108
         echo $'Password file not found'
109
         exit 62952
109
         exit 62952
110
     fi
110
     fi
111
 fi
111
 fi
112
 
112
 
113
 FRAGMENTS_DIR=/home/$MY_USERNAME/.gnupg_fragments
113
 FRAGMENTS_DIR=/home/$MY_USERNAME/.gnupg_fragments
114
-if [ -d $FRAGMENTS_DIR ]; then
114
+if [ -d "$FRAGMENTS_DIR" ]; then
115
     exit 0
115
     exit 0
116
 fi
116
 fi
117
 
117
 
118
 # get the gpg key ID
118
 # get the gpg key ID
119
-if [ ! $MY_EMAIL_ADDRESS ]; then
119
+if [ ! "$MY_EMAIL_ADDRESS" ]; then
120
     MY_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
120
     MY_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
121
 fi
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
 if [ ${#KEYID} -lt 4 ]; then
124
 if [ ${#KEYID} -lt 4 ]; then
125
     echo $"gpg key for $MY_EMAIL_ADDRESS was not found"
125
     echo $"gpg key for $MY_EMAIL_ADDRESS was not found"
126
     exit 3682
126
     exit 3682
133
 fi
133
 fi
134
 
134
 
135
 # create the key file
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
     echo $"Unable to extract public key for $KEYID"
140
     echo $"Unable to extract public key for $KEYID"
142
     exit 7835
141
     exit 7835
143
 fi
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
 else
146
 else
148
-    echo "$(printf `cat $PASSWORD_FILE`)" | \
147
+    # shellcheck disable=SC2005
148
+    echo "$(printf "%s" "$(cat "$PASSWORD_FILE")")" | \
149
         gpg --batch --passphrase-fd 0 \
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
 fi
152
 fi
153
+# shellcheck disable=SC2181
153
 if [ ! "$?" = "0" ]; then
154
 if [ ! "$?" = "0" ]; then
154
     echo $"Unable to extract private key for $KEYID"
155
     echo $"Unable to extract private key for $KEYID"
155
     exit 7823
156
     exit 7823
156
 fi
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
     echo $"Unable to extract backup public key for $MY_BACKUP_KEY_ID"
161
     echo $"Unable to extract backup public key for $MY_BACKUP_KEY_ID"
162
     exit 62928
162
     exit 62928
163
 fi
163
 fi
164
 echo "$BACKUP_DUMMY_PASSWORD" | \
164
 echo "$BACKUP_DUMMY_PASSWORD" | \
165
-    gpg --output $FRAGMENTS_DIR/backup_privkey.txt \
165
+if ! gpg --output "$FRAGMENTS_DIR/backup_privkey.txt" \
166
         --batch --passphrase-fd 0 \
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
     echo $"Unable to extract backup private key for $MY_BACKUP_KEY_ID"
169
     echo $"Unable to extract backup private key for $MY_BACKUP_KEY_ID"
171
     exit 13783
170
     exit 13783
172
 fi
171
 fi
173
 
172
 
174
 # Ensure there aren't any permissions problems when running cat
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
 KEY_SHARES=$((KEY_FRAGMENTS * 2))
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
     echo $"Unable to split the gpg key"
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
     fi
192
     fi
195
     exit 63028
193
     exit 63028
196
 fi
194
 fi
197
-shred -zu $KEYS_FILE
195
+shred -zu "$KEYS_FILE"
198
 
196
 
199
 # set permissions
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
 echo $"$KEY_SHARES key shares created"
201
 echo $"$KEY_SHARES key shares created"
204
 
202
 

+ 93
- 93
src/freedombone-syncthing Целия файл

36
 export TEXTDOMAIN=$PROJECT_NAME-syncthing
36
 export TEXTDOMAIN=$PROJECT_NAME-syncthing
37
 export TEXTDOMAINDIR="/usr/share/locale"
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
 for f in $UTILS_FILES
40
 for f in $UTILS_FILES
41
 do
41
 do
42
-  source $f
42
+    source "$f"
43
 done
43
 done
44
 
44
 
45
 # File which keeps track of what has already been installed
45
 # File which keeps track of what has already been installed
68
     for i in {1..8}
68
     for i in {1..8}
69
     do
69
     do
70
         v=""
70
         v=""
71
+        # shellcheck disable=SC2034
71
         for j in {1..2}
72
         for j in {1..2}
72
         do
73
         do
73
-            v2=`echo "obase=16;$RANDOM" | bc`
74
+            v2=$(echo "obase=16;$RANDOM" | bc)
74
             v=$v$v2
75
             v=$v$v2
75
         done
76
         done
76
         v=$(echo "$v" | cut -c1-7)
77
         v=$(echo "$v" | cut -c1-7)
77
-        if [[ ${i} < 8 ]]; then
78
+        if [ "${i}" -lt 8 ]; then
78
             v=$v"-"
79
             v=$v"-"
79
         fi
80
         fi
80
         echo -n "$v"
81
         echo -n "$v"
83
 }
84
 }
84
 
85
 
85
 function create_syncthing_config {
86
 function create_syncthing_config {
86
-    if grep -q "syncthing ID" $COMPLETION_FILE; then
87
+    if grep -q "syncthing ID" "$COMPLETION_FILE"; then
87
         SYNCTHING_ID=$(get_completion_param "syncthing ID")
88
         SYNCTHING_ID=$(get_completion_param "syncthing ID")
88
     else
89
     else
89
         if [ -f $SYNCTHING_CONFIG_FILE ]; then
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
         else
92
         else
92
             SYNCTHING_ID=$(new_syncthing_id)
93
             SYNCTHING_ID=$(new_syncthing_id)
93
         fi
94
         fi
109
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
110
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
110
             echo "    <folder id=\"$USERNAME\" path=\"/home/$USERNAME/Sync/\" ro=\"false\" rescanIntervalS=\"60\" ignorePerms=\"false\" autoNormalize=\"true\">" >> $SYNCTHING_CONFIG_FILE
111
             echo "    <folder id=\"$USERNAME\" path=\"/home/$USERNAME/Sync/\" ro=\"false\" rescanIntervalS=\"60\" ignorePerms=\"false\" autoNormalize=\"true\">" >> $SYNCTHING_CONFIG_FILE
111
             # include any specified device IDs for this user
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
                 echo "" > $TEMP_IDS_FILE
114
                 echo "" > $TEMP_IDS_FILE
114
                 while read -r line || [[ -n "$line" ]]; do
115
                 while read -r line || [[ -n "$line" ]]; do
115
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
116
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
121
                             fi
122
                             fi
122
                         fi
123
                         fi
123
                     fi
124
                     fi
124
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
125
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
125
                 rm $TEMP_IDS_FILE
126
                 rm $TEMP_IDS_FILE
126
             fi
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
         fi
142
         fi
142
     done
143
     done
143
 
144
 
147
     for d in /home/*/ ; do
148
     for d in /home/*/ ; do
148
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
149
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
149
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 while read -r line || [[ -n "$line" ]]; do
152
                 while read -r line || [[ -n "$line" ]]; do
152
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
153
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
153
                     if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
154
                     if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
158
                             fi
159
                             fi
159
                         fi
160
                         fi
160
                     fi
161
                     fi
161
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
162
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
162
             fi
163
             fi
163
         fi
164
         fi
164
     done
165
     done
165
     rm $TEMP_IDS_FILE
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
     echo "" > $TEMP_IDS_FILE
186
     echo "" > $TEMP_IDS_FILE
187
     for d in /home/*/ ; do
187
     for d in /home/*/ ; do
188
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
188
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
189
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 while read -r line || [[ -n "$line" ]]; do
191
                 while read -r line || [[ -n "$line" ]]; do
192
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
192
                     line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
193
                     if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
193
                     if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
194
                         if [ ${#line2} -gt 10 ]; then
194
                         if [ ${#line2} -gt 10 ]; then
195
                             if ! grep -q "$line2" $TEMP_IDS_FILE; then
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
                                 echo '        <address>dynamic</address>' >> $SYNCTHING_CONFIG_FILE
197
                                 echo '        <address>dynamic</address>' >> $SYNCTHING_CONFIG_FILE
198
                                 echo '    </device>' >> $SYNCTHING_CONFIG_FILE
198
                                 echo '    </device>' >> $SYNCTHING_CONFIG_FILE
199
                                 echo "$line2" >> $TEMP_IDS_FILE
199
                                 echo "$line2" >> $TEMP_IDS_FILE
200
                             fi
200
                             fi
201
                         fi
201
                         fi
202
                     fi
202
                     fi
203
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
203
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
204
             fi
204
             fi
205
         fi
205
         fi
206
     done
206
     done
207
     rm $TEMP_IDS_FILE
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
     # give each user account a file containing the device id for this server
244
     # give each user account a file containing the device id for this server
245
     # This allows it to appear within the user control panel
245
     # This allows it to appear within the user control panel
246
     for d in /home/*/ ; do
246
     for d in /home/*/ ; do
247
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
247
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
248
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
         fi
251
         fi
252
     done
252
     done
253
 }
253
 }
266
 
266
 
267
     for d in /home/*/ ; do
267
     for d in /home/*/ ; do
268
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
             CHANGED=1
270
             CHANGED=1
271
             return
271
             return
272
         fi
272
         fi
275
     for d in /home/*/ ; do
275
     for d in /home/*/ ; do
276
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
276
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
277
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 CHANGED=1
279
                 CHANGED=1
280
             fi
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
                 while read -r line || [[ -n "$line" ]]; do
283
                 while read -r line || [[ -n "$line" ]]; do
284
                     if [[ $line != *"#"* && $line != *"*"* && $line != *'/'*  && $line == *"-"* ]]; then
284
                     if [[ $line != *"#"* && $line != *"*"* && $line != *'/'*  && $line == *"-"* ]]; then
285
                         if [ ${#line} -gt 10 ]; then
285
                         if [ ${#line} -gt 10 ]; then
288
                             fi
288
                             fi
289
                         fi
289
                         fi
290
                     fi
290
                     fi
291
-                done < /home/$USERNAME/$SYNCTHING_USER_IDS_FILE
291
+                done < "/home/$USERNAME/$SYNCTHING_USER_IDS_FILE"
292
             fi
292
             fi
293
 
293
 
294
             # Permissions on user Sync directories
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
             fi
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
             fi
300
             fi
301
         fi
301
         fi
302
     done
302
     done
305
 function syncthing_set_permissions {
305
 function syncthing_set_permissions {
306
     for d in /home/*/ ; do
306
     for d in /home/*/ ; do
307
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
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
         fi
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
         fi
313
         fi
314
     done
314
     done
315
 }
315
 }

+ 56
- 53
src/freedombone-template Целия файл

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

+ 27
- 16
src/freedombone-tests Целия файл

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

+ 7
- 7
src/freedombone-unignore Целия файл

79
     fi
79
     fi
80
 fi
80
 fi
81
 
81
 
82
-MUTTRC=/home/$MYUSERNAME/.muttrc
82
+MUTTRC="/home/$MYUSERNAME/.muttrc"
83
 PM=/home/$MYUSERNAME/.procmailrc
83
 PM=/home/$MYUSERNAME/.procmailrc
84
 
84
 
85
 # unignore if subject line contains text
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
     fi
89
     fi
90
 fi
90
 fi
91
 
91
 
92
 # unignore an email address
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
     fi
96
     fi
97
 fi
97
 fi
98
 
98
 

+ 9
- 10
src/freedombone-upgrade Целия файл

42
 # clear temporary files
42
 # clear temporary files
43
 rm -rf /tmp/*
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
 for f in $UTILS_FILES
46
 for f in $UTILS_FILES
47
 do
47
 do
48
-    source $f
48
+    source "$f"
49
 done
49
 done
50
 
50
 
51
 read_config_param PROJECT_REPO
51
 read_config_param PROJECT_REPO
68
 
68
 
69
 #update-ca-certificates
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
 fi
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
         if [[ "$CURRENT_BRANCH" == *"master" ]]; then
79
         if [[ "$CURRENT_BRANCH" == *"master" ]]; then
80
             git_pull $PROJECT_REPO
80
             git_pull $PROJECT_REPO
81
         else
81
         else
88
             chmod -R +r /usr/share/${PROJECT_NAME}
88
             chmod -R +r /usr/share/${PROJECT_NAME}
89
         fi
89
         fi
90
 
90
 
91
-        ${PROJECT_NAME} -c $CONFIGURATION_FILE
92
-        if [ ! "$?" = "0" ]; then
91
+        if ! ${PROJECT_NAME} -c "$CONFIGURATION_FILE"; then
93
             exit 453536
92
             exit 453536
94
         fi
93
         fi
95
 
94
 

+ 5
- 5
src/freedombone-usb-canary Целия файл

30
 
30
 
31
 PROJECT_NAME=freedombone
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
     MY_EMAIL_ADDRESS=${ADMIN_USER}@$(cat /etc/hostname)
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
     echo "${ACTION}" > /tmp/usb-canary
38
     echo "${ACTION}" > /tmp/usb-canary
39
     echo "${MY_EMAIL_ADDRESS}" >> /tmp/usb-canary
39
     echo "${MY_EMAIL_ADDRESS}" >> /tmp/usb-canary
40
-    echo "$(date)" >> /tmp/usb-canary
40
+    date >> /tmp/usb-canary
41
 fi
41
 fi

+ 19
- 18
src/meshavahi Целия файл

71
     # include some subdirectories
71
     # include some subdirectories
72
     for dir in $DIR_TO_CHECK/*/
72
     for dir in $DIR_TO_CHECK/*/
73
     do
73
     do
74
-        REALLY_NEW_STAT="$NEW_STAT$(stat -t $dir)"
74
+        REALLY_NEW_STAT="$NEW_STAT$(stat -t "$dir")"
75
         NEW_STAT="$REALLY_NEW_STAT"
75
         NEW_STAT="$REALLY_NEW_STAT"
76
 
76
 
77
         for dir2 in "$dir"/*/
77
         for dir2 in "$dir"/*/
78
         do
78
         do
79
-            REALLY_NEW_STAT="$NEW_STAT$(stat -t $dir2)"
79
+            REALLY_NEW_STAT="$NEW_STAT$(stat -t "$dir2")"
80
             NEW_STAT="$REALLY_NEW_STAT"
80
             NEW_STAT="$REALLY_NEW_STAT"
81
 
81
 
82
             for dir3 in "$dir2"/*/
82
             for dir3 in "$dir2"/*/
83
             do
83
             do
84
-                REALLY_NEW_STAT="$NEW_STAT$(stat -t $dir3)"
84
+                REALLY_NEW_STAT="$NEW_STAT$(stat -t "$dir3")"
85
                 NEW_STAT="$REALLY_NEW_STAT"
85
                 NEW_STAT="$REALLY_NEW_STAT"
86
             done
86
             done
87
         done
87
         done
101
 
101
 
102
 function ipfs_bootstrap {
102
 function ipfs_bootstrap {
103
     # TODO switch to ipv6
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
     state=0
106
     state=0
107
     address=""
107
     address=""
126
         fi
126
         fi
127
         if [ ${state} -eq "2" ]; then
127
         if [ ${state} -eq "2" ]; then
128
             if [[ $line == *"address ="* ]]; then
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
                 state=3
130
                 state=3
131
             fi
131
             fi
132
         fi
132
         fi
133
         if [ ${state} -eq "1" ]; then
133
         if [ ${state} -eq "1" ]; then
134
             if [[ $line == *"hostname ="* ]]; then
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
                 state=2
136
                 state=2
137
             fi
137
             fi
138
         fi
138
         fi
144
     # Create a list of user sites, in alphabetical order by Tox nick
144
     # Create a list of user sites, in alphabetical order by Tox nick
145
     if [ -d /home/$MY_USERNAME/Desktop ]; then
145
     if [ -d /home/$MY_USERNAME/Desktop ]; then
146
         if [ -f ${IPFS_USERS_FILE}.new ]; then
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
             echo "${sites_list}" > ${IPFS_USERS_FILE}
148
             echo "${sites_list}" > ${IPFS_USERS_FILE}
149
             chown $MY_USERNAME:$MY_USERNAME ${IPFS_USERS_FILE}
149
             chown $MY_USERNAME:$MY_USERNAME ${IPFS_USERS_FILE}
150
             rm ${IPFS_USERS_FILE}.new
150
             rm ${IPFS_USERS_FILE}.new
155
 function detect_new_tox_users {
155
 function detect_new_tox_users {
156
     CURRENT_USERS_FILE=$1
156
     CURRENT_USERS_FILE=$1
157
 
157
 
158
-    if [ ! -f $CURRENT_USERS_FILE ]; then
158
+    if [ ! -f "$CURRENT_USERS_FILE" ]; then
159
         return
159
         return
160
     fi
160
     fi
161
 
161
 
170
             if [[ $line != "Failed*" && $line != "data "* && $line != "Anon "* && $line != "anon "* && $line != "anonymous "* && $line != "Anonymous "* ]]; then
170
             if [[ $line != "Failed*" && $line != "data "* && $line != "Anon "* && $line != "anon "* && $line != "anonymous "* && $line != "Anonymous "* ]]; then
171
                 if ! grep -q "$line" $PREV_TOX_USERS_FILE; then
171
                 if ! grep -q "$line" $PREV_TOX_USERS_FILE; then
172
                     # get the nick of the user
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
                     if [ -r "/home/$MESH_USERNAME/.dbus/Xdbus" ]; then
176
                     if [ -r "/home/$MESH_USERNAME/.dbus/Xdbus" ]; then
177
+                        # shellcheck disable=SC1090
177
                         . "/home/$MESH_USERNAME/.dbus/Xdbus"
178
                         . "/home/$MESH_USERNAME/.dbus/Xdbus"
178
                     fi
179
                     fi
179
                     export DISPLAY=:0.0
180
                     export DISPLAY=:0.0
186
     fi
187
     fi
187
 
188
 
188
     # Store the previous tox users list
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
 function detect_tox_users {
193
 function detect_tox_users {
193
     # don't show the first peer field
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
 function avahi_extract_info {
200
 function avahi_extract_info {
200
     # Create a list of bootstrap nodes
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
         exit 1
205
         exit 1
205
     fi
206
     fi
206
 }
207
 }
207
 
208
 
208
 function avahi_remove_info {
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
 if [ ! -d /etc/avahi ]; then
214
 if [ ! -d /etc/avahi ]; then