Просмотр исходного кода

Merge branch 'stretch' of https://github.com/bashrc/freedombone

Bob Mottram 7 лет назад
Родитель
Сommit
bb39f77020
100 измененных файлов: 13852 добавлений и 14258 удалений
  1. 1
    0
      Makefile
  2. Двоичные данные
      man/freedombone-image.1.gz
  3. 4
    4
      src/cronic
  4. 49
    50
      src/freedombone
  5. 58
    61
      src/freedombone-addcert
  6. 68
    69
      src/freedombone-addemail
  7. 75
    80
      src/freedombone-addlist
  8. 31
    31
      src/freedombone-addremove
  9. 93
    94
      src/freedombone-adduser
  10. 153
    152
      src/freedombone-app-akaunting
  11. 28
    29
      src/freedombone-app-batman
  12. 127
    127
      src/freedombone-app-bdsmail
  13. 301
    300
      src/freedombone-app-cryptpad
  14. 62
    57
      src/freedombone-app-dlna
  15. 256
    252
      src/freedombone-app-dokuwiki
  16. 135
    134
      src/freedombone-app-edith
  17. 147
    145
      src/freedombone-app-emacs
  18. 243
    240
      src/freedombone-app-etherpad
  19. 124
    125
      src/freedombone-app-fedwiki
  20. 252
    250
      src/freedombone-app-friendica
  21. 195
    195
      src/freedombone-app-ghost
  22. 286
    280
      src/freedombone-app-gnusocial
  23. 222
    215
      src/freedombone-app-gogs
  24. 276
    269
      src/freedombone-app-htmly
  25. 256
    254
      src/freedombone-app-hubzilla
  26. 220
    216
      src/freedombone-app-icecast
  27. 153
    153
      src/freedombone-app-ipfs
  28. 209
    204
      src/freedombone-app-irc
  29. 84
    85
      src/freedombone-app-jitsi
  30. 195
    198
      src/freedombone-app-kanboard
  31. 208
    201
      src/freedombone-app-keyserver
  32. 250
    247
      src/freedombone-app-koel
  33. 184
    184
      src/freedombone-app-lychee
  34. 86
    86
      src/freedombone-app-mailpile
  35. 164
    164
      src/freedombone-app-matrix
  36. 171
    167
      src/freedombone-app-mediagoblin
  37. 206
    206
      src/freedombone-app-movim
  38. 39
    38
      src/freedombone-app-mumble
  39. 229
    242
      src/freedombone-app-nextcloud
  40. 332
    334
      src/freedombone-app-peertube
  41. 283
    272
      src/freedombone-app-pelican
  42. 54
    48
      src/freedombone-app-pihole
  43. 335
    337
      src/freedombone-app-pleroma
  44. 283
    278
      src/freedombone-app-postactiv
  45. 161
    157
      src/freedombone-app-privatebin
  46. 114
    113
      src/freedombone-app-profanity
  47. 157
    153
      src/freedombone-app-radicale
  48. 89
    87
      src/freedombone-app-riot
  49. 201
    197
      src/freedombone-app-rss
  50. 173
    168
      src/freedombone-app-scuttlebot
  51. 607
    611
      src/freedombone-app-searx
  52. 115
    108
      src/freedombone-app-syncthing
  53. 164
    157
      src/freedombone-app-tahoelafs
  54. 202
    206
      src/freedombone-app-tox
  55. 95
    87
      src/freedombone-app-turtl
  56. 62
    60
      src/freedombone-app-vim
  57. 218
    210
      src/freedombone-app-vpn
  58. 0
    498
      src/freedombone-app-wekan
  59. 340
    330
      src/freedombone-app-xmpp
  60. 159
    158
      src/freedombone-app-zeronet
  61. 8
    8
      src/freedombone-archive-mail
  62. 61
    60
      src/freedombone-backup-local
  63. 94
    92
      src/freedombone-backup-remote
  64. 594
    654
      src/freedombone-base-email
  65. 30
    30
      src/freedombone-base-tripwire
  66. 53
    52
      src/freedombone-client
  67. 51
    55
      src/freedombone-clientcert
  68. 170
    135
      src/freedombone-config
  69. 410
    438
      src/freedombone-controlpanel
  70. 207
    220
      src/freedombone-controlpanel-user
  71. 14
    15
      src/freedombone-dhparam
  72. 8
    8
      src/freedombone-encrypt-mail
  73. 5
    8
      src/freedombone-format
  74. 8
    7
      src/freedombone-freedns
  75. 21
    21
      src/freedombone-ignore
  76. 78
    77
      src/freedombone-image
  77. 695
    661
      src/freedombone-image-customise
  78. 19
    25
      src/freedombone-image-hardware-setup
  79. 52
    52
      src/freedombone-image-make
  80. 648
    645
      src/freedombone-image-mesh
  81. 2
    2
      src/freedombone-image-vmdebootstrap
  82. 41
    43
      src/freedombone-keydrive
  83. 16
    16
      src/freedombone-logging
  84. 78
    73
      src/freedombone-mesh-batman
  85. 48
    47
      src/freedombone-mesh-blog
  86. 5
    4
      src/freedombone-mesh-connect
  87. 107
    107
      src/freedombone-mesh-install
  88. 2
    2
      src/freedombone-mesh-invite
  89. 3
    3
      src/freedombone-mesh-reset
  90. 35
    35
      src/freedombone-mesh-routing
  91. 7
    6
      src/freedombone-mesh-visit-site
  92. 44
    45
      src/freedombone-pass
  93. 18
    18
      src/freedombone-pin-cert
  94. 8
    8
      src/freedombone-powerline
  95. 31
    30
      src/freedombone-recoverkey
  96. 33
    33
      src/freedombone-remote
  97. 4
    5
      src/freedombone-renew-cert
  98. 15
    15
      src/freedombone-repair-database
  99. 145
    130
      src/freedombone-restore-local
  100. 0
    0
      src/freedombone-restore-remote

+ 1
- 0
Makefile Просмотреть файл

@@ -23,6 +23,7 @@ install:
23 23
 	mkdir -p ${DESTDIR}/usr/share/${APP}/utils
24 24
 	mkdir -p ${DESTDIR}/usr/share/${APP}/avatars
25 25
 	mkdir -p ${DESTDIR}/etc/${APP}
26
+	rm -f ${DESTDIR}/${PREFIX}/bin/${APP}-*
26 27
 	cp -r image_build/* ${DESTDIR}/etc/${APP}
27 28
 	cp img/backgrounds/${APP}_*.png ${DESTDIR}${PREFIX}/share
28 29
 	cp img/avatars/* ${DESTDIR}/usr/share/${APP}/avatars

Двоичные данные
man/freedombone-image.1.gz Просмотреть файл


+ 4
- 4
src/cronic Просмотреть файл

@@ -12,14 +12,14 @@ ERR=$TMP/cronic.err
12 12
 TRACE=$TMP/cronic.trace
13 13
 
14 14
 set +e
15
-"$@" >$OUT 2>$TRACE
15
+"$@" >"$OUT" 2>"$TRACE"
16 16
 RESULT=$?
17 17
 set -e
18 18
 
19 19
 PATTERN="^${PS4:0:1}\\+${PS4:1}"
20
-if grep -aq "$PATTERN" $TRACE
20
+if grep -aq "$PATTERN" "$TRACE"
21 21
 then
22
-    ! grep -av "$PATTERN" $TRACE > $ERR
22
+    ! grep -av "$PATTERN" "$TRACE" > "$ERR"
23 23
 else
24 24
     ERR=$TRACE
25 25
 fi
@@ -33,7 +33,7 @@ if [ $RESULT -ne 0 ]
33 33
     echo
34 34
     echo "STANDARD OUTPUT:"
35 35
     cat "$OUT"
36
-    if [ $TRACE != $ERR ]
36
+    if [ "$TRACE" != "$ERR" ]
37 37
     then
38 38
         echo
39 39
         echo "TRACE-ERROR OUTPUT:"

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

@@ -42,61 +42,61 @@ fi
42 42
 
43 43
 source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
44 44
 
45
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
45
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
46 46
 for f in $UTILS_FILES
47 47
 do
48
-    source $f
48
+    source "$f"
49 49
 done
50 50
 
51
-APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
51
+APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
52 52
 for f in $APP_FILES
53 53
 do
54
-    source $f
54
+    source "$f"
55 55
 done
56 56
 
57
-command_options=$1
57
+command_options="$1"
58 58
 
59
-if [[ $command_options == "menuconfig-full" ]]; then
59
+if [[ "$command_options" == "menuconfig-full" ]]; then
60 60
     MINIMAL_INSTALL="no"
61 61
 fi
62 62
 
63
-if [[ $command_options == "menuconfig-onion" ]]; then
63
+if [[ "$command_options" == "menuconfig-onion" ]]; then
64 64
     MINIMAL_INSTALL="yes"
65 65
     ONION_ONLY="yes"
66 66
 fi
67 67
 
68
-if [[ $command_options == "menuconfig-gnusocial" ]]; then
68
+if [[ "$command_options" == "menuconfig-gnusocial" ]]; then
69 69
     MINIMAL_INSTALL="yes"
70 70
     ONION_ONLY="no"
71 71
     SOCIALINSTANCE='gnusocial'
72 72
 fi
73 73
 
74
-if [[ $command_options == "menuconfig-postactiv" ]]; then
74
+if [[ "$command_options" == "menuconfig-postactiv" ]]; then
75 75
     MINIMAL_INSTALL="yes"
76 76
     ONION_ONLY="no"
77 77
     SOCIALINSTANCE='postactiv'
78 78
 fi
79 79
 
80
-if [ ! $CONFIGURATION_FILE ]; then
81
-    CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
80
+if [ ! "$CONFIGURATION_FILE" ]; then
81
+    CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
82 82
 fi
83
-if [ ! $COMPLETION_FILE ]; then
84
-    COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
83
+if [ ! "$COMPLETION_FILE" ]; then
84
+    COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
85 85
 fi
86 86
 
87 87
 # before the interactive config so that wifi adaptors may be detected
88 88
 setup_wifi_atheros
89 89
 
90
-if [[ $command_options == "menuconfig"* ]]; then
90
+if [[ "$command_options" == "menuconfig"* ]]; then
91 91
     if [[ "$2" == "--reset" ]]; then
92
-        if [ -f $CONFIGURATION_FILE ]; then
93
-            rm $CONFIGURATION_FILE
92
+        if [ -f "$CONFIGURATION_FILE" ]; then
93
+            rm "$CONFIGURATION_FILE"
94 94
         fi
95
-        if [ -f $COMPLETION_FILE ]; then
96
-            rm $COMPLETION_FILE
95
+        if [ -f "$COMPLETION_FILE" ]; then
96
+            rm "$COMPLETION_FILE"
97 97
         fi
98
-        if [ -f /usr/share/${PROJECT_NAME}/installed.txt ]; then
99
-            rm /usr/share/${PROJECT_NAME}/installed.txt
98
+        if [ -f "/usr/share/${PROJECT_NAME}/installed.txt" ]; then
99
+            rm "/usr/share/${PROJECT_NAME}/installed.txt"
100 100
         fi
101 101
         if [ -f /root/removed ]; then
102 102
             rm /root/removed
@@ -104,20 +104,20 @@ if [[ $command_options == "menuconfig"* ]]; then
104 104
     fi
105 105
 
106 106
     # clear the interactive file which indicates configuration success
107
-    interactive_file=$HOME/.${PROJECT_NAME}-interactive
108
-    if [ -f $interactive_file ]; then
109
-        rm $interactive_file
107
+    interactive_file="$HOME/.${PROJECT_NAME}-interactive"
108
+    if [ -f "$interactive_file" ]; then
109
+        rm "$interactive_file"
110 110
     fi
111 111
 
112 112
     interactive_configuration
113 113
 
114 114
     # check that the interactive file was created
115
-    if [ ! -f $interactive_file ]; then
115
+    if [ ! -f "$interactive_file" ]; then
116 116
         exit 6393562
117 117
     fi
118
-    rm $interactive_file
118
+    rm "$interactive_file"
119 119
 else
120
-    while [[ $# > 1 ]]
120
+    while [ $# -gt 1 ]
121 121
     do
122 122
         key="$1"
123 123
 
@@ -169,12 +169,12 @@ else
169 169
             # Static IP address for the system
170 170
             --ip)
171 171
                 shift
172
-                LOCAL_NETWORK_STATIC_IP_ADDRESS=$1
172
+                LOCAL_NETWORK_STATIC_IP_ADDRESS="$1"
173 173
                 ;;
174 174
             # IP address for the internet router
175 175
             --iprouter)
176 176
                 shift
177
-                ROUTER_IP_ADDRESS=$1
177
+                ROUTER_IP_ADDRESS="$1"
178 178
                 ;;
179 179
             # ssh port
180 180
             --ssh)
@@ -214,61 +214,61 @@ else
214 214
             # Mumble server password
215 215
             --vpass)
216 216
                 shift
217
-                MUMBLE_SERVER_PASSWORD=$1
217
+                MUMBLE_SERVER_PASSWORD="$1"
218 218
                 ;;
219 219
             # Mumble server port
220 220
             --vport)
221 221
                 shift
222
-                MUMBLE_PORT=$1
222
+                MUMBLE_PORT="$1"
223 223
                 ;;
224 224
             # DNS Nameserver 1
225 225
             --ns1)
226 226
                 shift
227
-                NAMESERVER1=$1
227
+                NAMESERVER1="$1"
228 228
                 ;;
229 229
             # DNS Nameserver 2
230 230
             --ns2)
231 231
                 shift
232
-                NAMESERVER2=$1
232
+                NAMESERVER2="$1"
233 233
                 ;;
234 234
             # DNS Nameserver 3
235 235
             --ns3)
236 236
                 shift
237
-                NAMESERVER3=$1
237
+                NAMESERVER3="$1"
238 238
                 ;;
239 239
             # DNS Nameserver 4
240 240
             --ns4)
241 241
                 shift
242
-                NAMESERVER4=$1
242
+                NAMESERVER4="$1"
243 243
                 ;;
244 244
             # DNS Nameserver 5
245 245
             --ns5)
246 246
                 shift
247
-                NAMESERVER5=$1
247
+                NAMESERVER5="$1"
248 248
                 ;;
249 249
             # DNS Nameserver 6
250 250
             --ns6)
251 251
                 shift
252
-                NAMESERVER6=$1
252
+                NAMESERVER6="$1"
253 253
                 ;;
254 254
             # Debian repository
255 255
             --repo)
256 256
                 shift
257
-                DEBIAN_REPO=$1
257
+                DEBIAN_REPO="$1"
258 258
                 ;;
259 259
             # clear the config file
260 260
             --reset)
261
-                if [ -f $CONFIGURATION_FILE ]; then
262
-                    rm $CONFIGURATION_FILE
261
+                if [ -f "$CONFIGURATION_FILE" ]; then
262
+                    rm "$CONFIGURATION_FILE"
263 263
                 fi
264
-                if [ -f $COMPLETION_FILE ]; then
265
-                    rm $COMPLETION_FILE
264
+                if [ -f "$COMPLETION_FILE" ]; then
265
+                    rm "$COMPLETION_FILE"
266 266
                 fi
267 267
                 ;;
268 268
             # minimal install
269 269
             --minimal)
270 270
                 shift
271
-                MINIMAL_INSTALL=$1
271
+                MINIMAL_INSTALL="$1"
272 272
                 ;;
273 273
             *)
274 274
                 # unknown option
@@ -293,7 +293,7 @@ function parse_args {
293 293
     read_config_param 'DDNS_USERNAME'
294 294
     read_config_param 'DDNS_PASSWORD'
295 295
 
296
-    if [ ! -d /home/$MY_USERNAME ]; then
296
+    if [ ! -d "/home/$MY_USERNAME" ]; then
297 297
         echo $"There is no user '$MY_USERNAME' on the system. Use 'adduser $MY_USERNAME' to create the user."
298 298
         exit 1
299 299
     fi
@@ -304,7 +304,7 @@ function parse_args {
304 304
             exit 2
305 305
         fi
306 306
     fi
307
-    if [ ! $MY_USERNAME ]; then
307
+    if [ ! "$MY_USERNAME" ]; then
308 308
         echo 'No username specified'
309 309
         show_help
310 310
         exit 3
@@ -312,11 +312,11 @@ function parse_args {
312 312
     if [[ $SYSTEM_TYPE != "mesh"* ]]; then
313 313
         if [[ "$DDNS_PROVIDER" != 'none' ]]; then
314 314
             if [[ $ONION_ONLY == "no" ]]; then
315
-                if [ ! $DDNS_USERNAME ]; then
315
+                if [ ! "$DDNS_USERNAME" ]; then
316 316
                     echo $'Please provide the username for your dynamic DNS provider with the --ddnsuser option'
317 317
                     exit 7823
318 318
                 fi
319
-                if [ ! $DDNS_PASSWORD ]; then
319
+                if [ ! "$DDNS_PASSWORD" ]; then
320 320
                     echo $'Please provide the password for your dynamic DNS provider with the --ddnspass option'
321 321
                     exit 6382
322 322
                 fi
@@ -324,7 +324,7 @@ function parse_args {
324 324
         fi
325 325
     fi
326 326
 
327
-    if [ ! $SYSTEM_TYPE ]; then
327
+    if [ ! "$SYSTEM_TYPE" ]; then
328 328
         SYSTEM_TYPE=$'full'
329 329
         write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
330 330
     fi
@@ -338,8 +338,7 @@ function parse_args {
338 338
 
339 339
 # run some initial tests
340 340
 clear
341
-${PROJECT_NAME}-tests
342
-if [ ! "$?" = "0" ]; then
341
+if ! "${PROJECT_NAME}-tests"; then
343 342
     exit 768252
344 343
 fi
345 344
 
@@ -354,7 +353,7 @@ upgrade_installation_from_previous_versions
354 353
 setup_utils
355 354
 setup_email
356 355
 setup_web
357
-setup_apps $command_options
356
+setup_apps "$command_options"
358 357
 setup_final
359 358
 
360 359
 echo ''

+ 58
- 61
src/freedombone-addcert Просмотреть файл

@@ -36,10 +36,10 @@ export TEXTDOMAINDIR="/usr/share/locale"
36 36
 CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
37 37
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
38 38
 
39
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
39
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
40 40
 for f in $UTILS_FILES
41 41
 do
42
-  source $f
42
+    source "$f"
43 43
 done
44 44
 
45 45
 # Don't pin certs by default
@@ -85,7 +85,7 @@ function show_help {
85 85
     exit 0
86 86
 }
87 87
 
88
-while [[ $# > 1 ]]
88
+while [ $# -gt 1 ]
89 89
 do
90 90
     key="$1"
91 91
 
@@ -145,11 +145,11 @@ do
145 145
             ;;
146 146
         --dhkey)
147 147
             shift
148
-            DH_KEYLENGTH=${1}
148
+            DH_KEYLENGTH="${1}"
149 149
             ;;
150 150
         --pin)
151 151
             shift
152
-            PIN_CERTS=${1}
152
+            PIN_CERTS="${1}"
153 153
             ;;
154 154
         *)
155 155
             # unknown option
@@ -158,8 +158,8 @@ do
158 158
     shift
159 159
 done
160 160
 
161
-if [ ! $HOSTNAME ]; then
162
-    if [ ! $LETSENCRYPT_HOSTNAME ]; then
161
+if [ ! "$HOSTNAME" ]; then
162
+    if [ ! "$LETSENCRYPT_HOSTNAME" ]; then
163 163
         echo $'No hostname specified'
164 164
         exit 5748
165 165
     fi
@@ -180,16 +180,16 @@ function remove_cert_letsencrypt {
180 180
     CERTFILE=$LETSENCRYPT_HOSTNAME
181 181
 
182 182
     # disable the site if needed
183
-    if [ -f /etc/nginx/sites-available/${LETSENCRYPT_HOSTNAME} ]; then
184
-        if grep -q "443" /etc/nginx/sites-available/${LETSENCRYPT_HOSTNAME}; then
185
-            nginx_dissite ${LETSENCRYPT_HOSTNAME}
183
+    if [ -f "/etc/nginx/sites-available/${LETSENCRYPT_HOSTNAME}" ]; then
184
+        if grep -q "443" "/etc/nginx/sites-available/${LETSENCRYPT_HOSTNAME}"; then
185
+            nginx_dissite "${LETSENCRYPT_HOSTNAME}"
186 186
         fi
187 187
     fi
188 188
 
189 189
     # remove the cert
190
-    rm -rf /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}*
191
-    rm -rf /etc/letsencrypt/archive/${LETSENCRYPT_HOSTNAME}*
192
-    rm /etc/letsencrypt/renewal/${LETSENCRYPT_HOSTNAME}.conf
190
+    rm -rf "/etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}*"
191
+    rm -rf "/etc/letsencrypt/archive/${LETSENCRYPT_HOSTNAME}*"
192
+    rm "/etc/letsencrypt/renewal/${LETSENCRYPT_HOSTNAME}.conf"
193 193
 
194 194
     # restart the web server
195 195
     systemctl restart nginx
@@ -199,14 +199,14 @@ function add_cert_letsencrypt {
199 199
     CERTFILE=$LETSENCRYPT_HOSTNAME
200 200
 
201 201
     # obtain the email address for the admin user
202
-    if [ ! $MY_EMAIL_ADDRESS ]; then
203
-        if [ -f $CONFIGURATION_FILE ]; then
202
+    if [ ! "$MY_EMAIL_ADDRESS" ]; then
203
+        if [ -f "$CONFIGURATION_FILE" ]; then
204 204
             read_config_param MY_EMAIL_ADDRESS
205 205
         fi
206 206
     fi
207
-    if [ ! $MY_EMAIL_ADDRESS ]; then
208
-        if [ -f $COMPLETION_FILE ]; then
209
-            if grep -q "Admin user:" $COMPLETION_FILE; then
207
+    if [ ! "$MY_EMAIL_ADDRESS" ]; then
208
+        if [ -f "$COMPLETION_FILE" ]; then
209
+            if grep -q "Admin user:" "$COMPLETION_FILE"; then
210 210
                 function_check get_completion_param
211 211
                 ADMIN_USER=$(get_completion_param "Admin user")
212 212
                 if [ ${#ADMIN_USER} -eq 0 ]; then
@@ -232,8 +232,7 @@ function add_cert_letsencrypt {
232 232
     chgrp -R root /etc/letsencrypt
233 233
     chmod -R 777 /etc/letsencrypt
234 234
 
235
-    certbot certonly -n --server $LETSENCRYPT_SERVER --standalone -d $LETSENCRYPT_HOSTNAME --renew-by-default --agree-tos --email $MY_EMAIL_ADDRESS
236
-    if [ ! "$?" = "0" ]; then
235
+    if ! certbot certonly -n --server "$LETSENCRYPT_SERVER" --standalone -d "$LETSENCRYPT_HOSTNAME" --renew-by-default --agree-tos --email "$MY_EMAIL_ADDRESS"; then
237 236
         echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME"
238 237
         echo $'Also see https://letsencrypt.status.io to check for any service outages'
239 238
         chgrp -R ssl-cert /etc/letsencrypt
@@ -245,42 +244,42 @@ function add_cert_letsencrypt {
245 244
     fi
246 245
 
247 246
     # replace some legacy filenames
248
-    if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt ]; then
249
-        mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
247
+    if [ -f "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt" ]; then
248
+        mv "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt" "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem"
250 249
     fi
251
-    if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt ]; then
252
-        mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
250
+    if [ -f "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt" ]; then
251
+        mv "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt" "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem"
253 252
     fi
254
-    sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
255
-    sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" /etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME
253
+    sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.bundle.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" "/etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME"
254
+    sed -i "s|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.crt|ssl_certificate /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem|g" "/etc/nginx/sites-available/$LETSENCRYPT_HOSTNAME"
256 255
 
257 256
     # link the private key
258
-    if [ -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ]; then
259
-        if [ ! -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old ]; then
260
-            mv /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old
257
+    if [ -f "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key" ]; then
258
+        if [ ! -f "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old" ]; then
259
+            mv "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key" "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key.old"
261 260
         else
262
-            rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
261
+            rm -f "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key"
263 262
         fi
264 263
     fi
265
-    if [ -L /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key ]; then
266
-        rm /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
264
+    if [ -L "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key" ]; then
265
+        rm "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key"
267 266
     fi
268
-    ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/privkey.pem /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
267
+    ln -s "/etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/privkey.pem" "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key"
269 268
 
270 269
     # link the public key
271
-    if [ -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ]; then
272
-        if [ ! -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old ]; then
273
-            mv /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old
270
+    if [ -f "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem" ]; then
271
+        if [ ! -f "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old" ]; then
272
+            mv "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem" "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem.old"
274 273
         else
275
-            rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
274
+            rm -f "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem"
276 275
         fi
277 276
     fi
278
-    if [ -L /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem ]; then
279
-        rm /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
277
+    if [ -L "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem" ]; then
278
+        rm "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem"
280 279
     fi
281
-    ln -s /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
280
+    ln -s "/etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem" "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem"
282 281
 
283
-    cp /etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem /etc/ssl/mycerts/${LETSENCRYPT_HOSTNAME}.pem
282
+    cp "/etc/letsencrypt/live/${LETSENCRYPT_HOSTNAME}/fullchain.pem" "/etc/ssl/mycerts/${LETSENCRYPT_HOSTNAME}.pem"
284 283
 
285 284
     update_default_domain
286 285
 
@@ -291,12 +290,11 @@ function add_cert_letsencrypt {
291 290
     chmod -R g=rX /etc/letsencrypt
292 291
     chown -R root:ssl-cert /etc/letsencrypt
293 292
 
294
-    nginx_ensite ${LETSENCRYPT_HOSTNAME}
293
+    nginx_ensite "${LETSENCRYPT_HOSTNAME}"
295 294
     systemctl start nginx
296 295
 
297
-    if [ $PIN_CERTS ]; then
298
-        ${PROJECT_NAME}-pin-cert $LETSENCRYPT_HOSTNAME
299
-        if [ ! "$?" = "0" ]; then
296
+    if [ "$PIN_CERTS" ]; then
297
+        if ! "${PROJECT_NAME}-pin-cert" "$LETSENCRYPT_HOSTNAME"; then
300 298
             echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned"
301 299
             exit 62878
302 300
         fi
@@ -304,21 +302,20 @@ function add_cert_letsencrypt {
304 302
 }
305 303
 
306 304
 function add_cert_selfsigned {
307
-    if [[ $ORGANISATION == "Freedombone-CA" ]]; then
305
+    if [[ "$ORGANISATION" == "Freedombone-CA" ]]; then
308 306
         CERTFILE="ca-$HOSTNAME"
309 307
     fi
310 308
 
311
-    openssl req -x509 ${EXTENSIONS} -nodes -days 3650 -sha256 \
309
+    openssl req -x509 "${EXTENSIONS}" -nodes -days 3650 -sha256 \
312 310
             -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
313
-            -newkey rsa:2048 -keyout /etc/ssl/private/${CERTFILE}.key \
314
-            -out /etc/ssl/certs/${CERTFILE}.crt
315
-    chmod 400 /etc/ssl/private/${CERTFILE}.key
316
-    chmod 640 /etc/ssl/certs/${CERTFILE}.crt
317
-    cp /etc/ssl/certs/${CERTFILE}.crt /etc/ssl/mycerts
318
-
319
-    if [ $PIN_CERTS ]; then
320
-        ${PROJECT_NAME}-pin-cert $CERTFILE
321
-        if [ ! "$?" = "0" ]; then
311
+            -newkey rsa:2048 -keyout "/etc/ssl/private/${CERTFILE}.key" \
312
+            -out "/etc/ssl/certs/${CERTFILE}.crt"
313
+    chmod 400 "/etc/ssl/private/${CERTFILE}.key"
314
+    chmod 640 "/etc/ssl/certs/${CERTFILE}.crt"
315
+    cp "/etc/ssl/certs/${CERTFILE}.crt" "/etc/ssl/mycerts"
316
+
317
+    if [ "$PIN_CERTS" ]; then
318
+        if ! "${PROJECT_NAME}-pin-cert" "$CERTFILE"; then
322 319
             echo $"Certificate for $CERTFILE could not be pinned"
323 320
             exit 62879
324 321
         fi
@@ -326,9 +323,9 @@ function add_cert_selfsigned {
326 323
 }
327 324
 
328 325
 function generate_dh_params {
329
-    if [ ! $NODH ]; then
330
-        if [ ! -f /etc/ssl/certs/${CERTFILE}.dhparam ]; then
331
-            ${PROJECT_NAME}-dhparam -h ${CERTFILE} --fast yes
326
+    if [ ! "$NODH" ]; then
327
+        if [ ! -f "/etc/ssl/certs/${CERTFILE}.dhparam" ]; then
328
+            "${PROJECT_NAME}-dhparam" -h "${CERTFILE}" --fast yes
332 329
         fi
333 330
     fi
334 331
 }
@@ -346,12 +343,12 @@ function make_cert_bundle {
346 343
 }
347 344
 
348 345
 function create_cert {
349
-    if [ $remove_cert ]; then
346
+    if [ "$remove_cert" ]; then
350 347
         remove_cert_letsencrypt
351 348
         return
352 349
     fi
353 350
 
354
-    if [ $LETSENCRYPT_HOSTNAME ]; then
351
+    if [ "$LETSENCRYPT_HOSTNAME" ]; then
355 352
         add_cert_letsencrypt
356 353
     else
357 354
         add_cert_selfsigned

+ 68
- 69
src/freedombone-addemail Просмотреть файл

@@ -47,54 +47,54 @@ function show_help {
47 47
     exit 0
48 48
 }
49 49
 
50
-while [[ $# > 1 ]]
50
+while [ $# -gt 1 ]
51 51
 do
52 52
     key="$1"
53 53
 
54 54
     case $key in
55
-    -h|--help)
56
-        show_help
57
-        ;;
58
-    -u|--user)
59
-        shift
60
-        MYUSERNAME="$1"
61
-        ;;
62
-    -e|--email)
63
-        shift
64
-        EMAILADDRESS="$1"
65
-        ;;
66
-    -s|--subject)
67
-        shift
68
-        SUBJECT_TEXT="$1"
69
-        ;;
70
-    -g|--group)
71
-        shift
72
-        GROUP_NAME="$1"
73
-        ;;
74
-    -p|--public)
75
-        shift
76
-        PUBLIC="$1"
77
-        ;;
78
-    *)
79
-        # unknown option
80
-        ;;
55
+        -h|--help)
56
+            show_help
57
+            ;;
58
+        -u|--user)
59
+            shift
60
+            MYUSERNAME="$1"
61
+            ;;
62
+        -e|--email)
63
+            shift
64
+            EMAILADDRESS="$1"
65
+            ;;
66
+        -s|--subject)
67
+            shift
68
+            SUBJECT_TEXT="$1"
69
+            ;;
70
+        -g|--group)
71
+            shift
72
+            GROUP_NAME="$1"
73
+            ;;
74
+        -p|--public)
75
+            shift
76
+            PUBLIC="$1"
77
+            ;;
78
+        *)
79
+            # unknown option
80
+            ;;
81 81
     esac
82 82
     shift
83 83
 done
84 84
 
85
-if ! [[ $MYUSERNAME && $GROUP_NAME ]]; then
85
+if ! [[ "$MYUSERNAME" && "$GROUP_NAME" ]]; then
86 86
     show_help
87 87
 fi
88 88
 
89
-if [ ${#EMAILADDRESS} -lt 2 ]; then
89
+if [ "${#EMAILADDRESS}" -lt 2 ]; then
90 90
     if [ ${#SUBJECT_TEXT} -lt 2 ]; then
91
-    show_help
91
+        show_help
92 92
     fi
93 93
 fi
94 94
 
95
-MUTTRC=/home/$MYUSERNAME/.muttrc
96
-PM=/home/$MYUSERNAME/.procmailrc
97
-LISTDIR=/home/$MYUSERNAME/Maildir/$GROUP_NAME
95
+MUTTRC="/home/$MYUSERNAME/.muttrc"
96
+PM="/home/$MYUSERNAME/.procmailrc"
97
+LISTDIR="/home/$MYUSERNAME/Maildir/$GROUP_NAME"
98 98
 
99 99
 proc_rule="  * ^From:.*$EMAILADDRESS"
100 100
 proc_comment="# Email rule for $EMAILADDRESS -> $GROUP_NAME"
@@ -104,54 +104,53 @@ if [ ${#SUBJECT_TEXT} -gt 0 ]; then
104 104
 fi
105 105
 
106 106
 if [ ! -d "$LISTDIR" ]; then
107
-    mkdir -m 700 $LISTDIR
108
-    mkdir -m 700 $LISTDIR/tmp
109
-    mkdir -m 700 $LISTDIR/new
110
-    mkdir -m 700 $LISTDIR/cur
107
+    mkdir -m 700 "$LISTDIR"
108
+    mkdir -m 700 "$LISTDIR/tmp"
109
+    mkdir -m 700 "$LISTDIR/new"
110
+    mkdir -m 700 "$LISTDIR/cur"
111 111
 fi
112
-chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
113
-if ! grep -q "$proc_comment" $PM; then
112
+chown -R "$MYUSERNAME":"$MYUSERNAME" "$LISTDIR"
113
+if ! grep -q "$proc_comment" "$PM"; then
114 114
     if [[ $PUBLIC != "yes" ]]; then
115
-    # private emails go after the encryption stage
116
-    echo '' >> $PM
117
-    echo "$proc_comment" >> $PM
118
-    echo ":0" >> $PM
119
-    echo "$proc_rule" >> $PM
120
-    echo "$LISTDIR/new" >> $PM
121
-    echo "# End of rule" >> $PM
115
+        # private emails go after the encryption stage
116
+        { echo '';
117
+          echo "$proc_comment";
118
+          echo ":0";
119
+          echo "$proc_rule";
120
+          echo "$LISTDIR/new";
121
+          echo "# End of rule"; } >> "$PM"
122 122
     else
123
-    # public emails are copied before the encryption stage
124
-    if ! grep -q '# encrypt' $PM; then
125
-        echo '' >> $PM
126
-        echo "$proc_comment" >> $PM
127
-        echo ":0" >> $PM
128
-        echo "$proc_rule" >> $PM
129
-        echo "$LISTDIR/new" >> $PM
130
-        echo "# End of rule" >> $PM
131
-    else
132
-        filter=$(echo "$proc_comment\n:0\n${proc_rule}\n$LISTDIR/new\n# End of rule\n")
133
-        sed -i "/# encrypt/i ${filter}" $PM
134
-    fi
123
+        # public emails are copied before the encryption stage
124
+        if ! grep -q '# encrypt' "$PM"; then
125
+            { echo '';
126
+              echo "$proc_comment";
127
+              echo ":0";
128
+              echo "$proc_rule";
129
+              echo "$LISTDIR/new";
130
+              echo "# End of rule"; } >> "$PM"
131
+        else
132
+            sed -i "/# encrypt/i $proc_comment\\n:0\\n${proc_rule}\\n$LISTDIR/new\\n# End of rule\\n" "$PM"
133
+        fi
135 134
     fi
136
-    chown $MYUSERNAME:$MYUSERNAME $PM
135
+    chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
137 136
 fi
138 137
 
139 138
 if [ ! -f "$MUTTRC" ]; then
140
-    cp /etc/Muttrc $MUTTRC
141
-    chown $MYUSERNAME:$MYUSERNAME $MUTTRC
139
+    cp /etc/Muttrc "$MUTTRC"
140
+    chown "$MYUSERNAME":"$MYUSERNAME" "$MUTTRC"
142 141
 fi
143 142
 
144 143
 PROCMAILLOG=/home/$MYUSERNAME/log
145
-if [ ! -d $PROCMAILLOG ]; then
146
-    mkdir $PROCMAILLOG
147
-    chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
144
+if [ ! -d "$PROCMAILLOG" ]; then
145
+    mkdir "$PROCMAILLOG"
146
+    chown -R "$MYUSERNAME":"$MYUSERNAME" "$PROCMAILLOG"
148 147
 fi
149 148
 
150
-MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
151
-if [[ $MUTT_MAILBOXES != *$GROUP_NAME* ]]; then
152
-    if ! grep -q "=$GROUP_NAME" $MUTTRC; then
153
-    sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$GROUP_NAME|g" $MUTTRC
154
-    chown $MYUSERNAME:$MYUSERNAME $MUTTRC
149
+MUTT_MAILBOXES=$(grep "mailboxes =" "$MUTTRC")
150
+if [[ "$MUTT_MAILBOXES" != *$GROUP_NAME* ]]; then
151
+    if ! grep -q "=$GROUP_NAME" "$MUTTRC"; then
152
+        sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$GROUP_NAME|g" "$MUTTRC"
153
+        chown "$MYUSERNAME":"$MYUSERNAME" "$MUTTRC"
155 154
     fi
156 155
 fi
157 156
 

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

@@ -47,124 +47,119 @@ function show_help {
47 47
     exit 0
48 48
 }
49 49
 
50
-while [[ $# > 1 ]]
50
+while [ $# -gt 1 ]
51 51
 do
52 52
     key="$1"
53 53
 
54 54
     case $key in
55
-    -h|--help)
56
-        show_help
57
-        ;;
58
-    -u|--user)
59
-        shift
60
-        MYUSERNAME="$1"
61
-        ;;
62
-    -l|--list)
63
-        shift
64
-        MAILINGLIST="$1"
65
-        ;;
66
-    -s|--subject)
67
-        shift
68
-        SUBJECTTAG="$1"
69
-        ;;
70
-    -e|--email)
71
-        shift
72
-        LIST_ADDRESS="$1"
73
-        ;;
74
-    -p|--public)
75
-        shift
76
-        PUBLIC="$1"
77
-        ;;
78
-    *)
79
-        # unknown option
80
-        ;;
55
+        -h|--help)
56
+            show_help
57
+            ;;
58
+        -u|--user)
59
+            shift
60
+            MYUSERNAME="$1"
61
+            ;;
62
+        -l|--list)
63
+            shift
64
+            MAILINGLIST="$1"
65
+            ;;
66
+        -s|--subject)
67
+            shift
68
+            SUBJECTTAG="$1"
69
+            ;;
70
+        -e|--email)
71
+            shift
72
+            LIST_ADDRESS="$1"
73
+            ;;
74
+        -p|--public)
75
+            shift
76
+            PUBLIC="$1"
77
+            ;;
78
+        *)
79
+            # unknown option
80
+            ;;
81 81
     esac
82 82
     shift
83 83
 done
84 84
 
85
-if [ ! $MYUSERNAME ]; then
85
+if [ ! "$MYUSERNAME" ]; then
86 86
     show_help
87 87
 fi
88 88
 
89
-if [[ ! $MAILINGLIST && ! $SUBJECTTAG ]]; then
89
+if [[ ! "$MAILINGLIST" && ! "$SUBJECTTAG" ]]; then
90 90
     show_help
91 91
 fi
92 92
 
93
-MUTTRC=/home/$MYUSERNAME/.muttrc
94
-PM=/home/$MYUSERNAME/.procmailrc
95
-LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
93
+MUTTRC="/home/$MYUSERNAME/.muttrc"
94
+PM="/home/$MYUSERNAME/.procmailrc"
95
+LISTDIR="/home/$MYUSERNAME/Maildir/$MAILINGLIST"
96 96
 
97
-if grep -q "=$MAILINGLIST" $MUTTRC; then
97
+if grep -q "=$MAILINGLIST" "$MUTTRC"; then
98 98
     echo $"Mailing list $MAILINGLIST was already added"
99 99
 fi
100 100
 
101 101
 if [ ! -d "$LISTDIR" ]; then
102
-    mkdir -m 700 $LISTDIR
103
-    mkdir -m 700 $LISTDIR/tmp
104
-    mkdir -m 700 $LISTDIR/new
105
-    mkdir -m 700 $LISTDIR/cur
102
+    mkdir -m 700 "$LISTDIR"
103
+    mkdir -m 700 "$LISTDIR/tmp"
104
+    mkdir -m 700 "$LISTDIR/new"
105
+    mkdir -m 700 "$LISTDIR/cur"
106 106
 fi
107 107
 
108
-chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
108
+chown -R "$MYUSERNAME":"$MYUSERNAME" "$LISTDIR"
109 109
 
110 110
 if [ ${#SUBJECTTAG} -gt 0 ]; then
111 111
     # use the subject tag
112
-    if ! grep -q "Subject:.*()\[$SUBJECTTAG\]" $PM; then
113
-    if [[ $PUBLIC != "yes" ]]; then
114
-        # private emails go after the encryption stage
115
-        filter="
116
-# Email rule for $MAILINGLIST subject [$SUBJECTTAG]
117
-:0
118
-  * ^Subject:.*()\[$SUBJECTTAG\]
119
-$LISTDIR/new
120
-# End of rule
121
-"
122
-        echo "$filter" >> $PM
123
-    else
124
-        # public emails are copied before hte encryption stage
125
-        if ! grep -q '# encrypt' $PM; then
126
-        filter="
127
-# Email rule for $MAILINGLIST subject [$SUBJECTTAG]
128
-:0
129
-  * ^Subject:.*()\[$SUBJECTTAG\]
130
-$LISTDIR/new
131
-# End of rule
132
-"
133
-        echo "$filter" >> $PM
112
+    if ! grep -q "Subject:.*()\\[$SUBJECTTAG\\]" "$PM"; then
113
+        if [[ $PUBLIC != "yes" ]]; then
114
+            # private emails go after the encryption stage
115
+            { echo "# Email rule for $MAILINGLIST subject [$SUBJECTTAG]";
116
+              echo ":0";
117
+              echo "  * ^Subject:.*()\\[$SUBJECTTAG\\]";
118
+              echo "$LISTDIR/new";
119
+              echo "# End of rule";
120
+              echo ""; } >> "$PM"
134 121
         else
135
-        filter=$(echo "# Email rule for $MAILINGLIST subject [$SUBJECTTAG]\n:0\n  * ^Subject:.*()\\\[$SUBJECTTAG\\\]\n$LISTDIR/new\n# End of rule\n")
136
-        sed -i "/# encrypt/i ${filter}" $PM
122
+            # public emails are copied before hte encryption stage
123
+            if ! grep -q '# encrypt' "$PM"; then
124
+                { echo "# Email rule for $MAILINGLIST subject [$SUBJECTTAG]";
125
+                  echo ":0";
126
+                  echo "  * ^Subject:.*()\\[$SUBJECTTAG\\]";
127
+                  echo "$LISTDIR/new";
128
+                  echo "# End of rule";
129
+                  echo ""; } >> "$PM"
130
+            else
131
+                sed -i "/# encrypt/i # Email rule for $MAILINGLIST subject [$SUBJECTTAG]\\n:0\\n  * ^Subject:.*()\\\\[$SUBJECTTAG\\\\]\\n$LISTDIR/new\\n# End of rule\\n" "$PM"
132
+            fi
137 133
         fi
138
-    fi
139
-    chown $MYUSERNAME:$MYUSERNAME $PM
134
+        chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
140 135
     fi
141 136
 else
142
-    exit $(${PROJECT_NAME}-addemail -u $MYUSERNAME -e $LIST_ADDRESS -g $MAILINGLIST --public $PUBLIC)
137
+    exit "$("${PROJECT_NAME}-addemail" -u "$MYUSERNAME" -e "$LIST_ADDRESS" -g "$MAILINGLIST" --public "$PUBLIC")"
143 138
 fi
144 139
 
145 140
 if [ ! -f "$MUTTRC" ]; then
146
-    cp /etc/Muttrc $MUTTRC
147
-    chown $MYUSERNAME:$MYUSERNAME $MUTTRC
141
+    cp /etc/Muttrc "$MUTTRC"
142
+    chown "$MYUSERNAME":"$MYUSERNAME" "$MUTTRC"
148 143
 fi
149 144
 
150
-PROCMAILLOG=/home/$MYUSERNAME/log
151
-if [ ! -d $PROCMAILLOG ]; then
152
-    mkdir $PROCMAILLOG
153
-    chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
145
+PROCMAILLOG="/home/$MYUSERNAME/log"
146
+if [ ! -d "$PROCMAILLOG" ]; then
147
+    mkdir "$PROCMAILLOG"
148
+    chown -R "$MYUSERNAME":"$MYUSERNAME" "$PROCMAILLOG"
154 149
 fi
155 150
 
156
-MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
157
-if [[ $MUTT_MAILBOXES != *$MAILINGLIST* ]]; then
158
-    if ! grep -q "=$MAILINGLIST" $MUTTRC; then
159
-    sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$MAILINGLIST|g" $MUTTRC
160
-    chown $MYUSERNAME:$MYUSERNAME $MUTTRC
151
+MUTT_MAILBOXES=$(grep "mailboxes =" "$MUTTRC")
152
+if [[ "$MUTT_MAILBOXES" != *$MAILINGLIST* ]]; then
153
+    if ! grep -q "=$MAILINGLIST" "$MUTTRC"; then
154
+        sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$MAILINGLIST|g" "$MUTTRC"
155
+        chown "$MYUSERNAME":"$MYUSERNAME" "$MUTTRC"
161 156
     fi
162 157
 fi
163 158
 
164
-if [ $LIST_ADDRESS ]; then
165
-    sed -i "s|unsubscribe $LIST_ADDRESS|subscribe $LIST_ADDRESS|g" $MUTTRC
166
-    if ! grep -q "subscribe $LIST_ADDRESS" $MUTTRC; then
167
-    echo "subscribe $LIST_ADDRESS" >> $MUTTRC
159
+if [ "$LIST_ADDRESS" ]; then
160
+    sed -i "s|unsubscribe $LIST_ADDRESS|subscribe $LIST_ADDRESS|g" "$MUTTRC"
161
+    if ! grep -q "subscribe $LIST_ADDRESS" "$MUTTRC"; then
162
+        echo "subscribe $LIST_ADDRESS" >> "$MUTTRC"
168 163
     fi
169 164
 fi
170 165
 

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

@@ -34,27 +34,27 @@ export TEXTDOMAIN=${PROJECT_NAME}-addremove
34 34
 export TEXTDOMAINDIR="/usr/share/locale"
35 35
 
36 36
 PROJECT_INSTALL_DIR=/usr/local/bin
37
-if [ -f /usr/bin/${PROJECT_NAME} ]; then
37
+if [ -f "/usr/bin/${PROJECT_NAME}" ]; then
38 38
     PROJECT_INSTALL_DIR=/usr/bin
39 39
 fi
40 40
 
41
-COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
42
-CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
41
+COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
42
+CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
43 43
 
44 44
 # Start including files
45 45
 
46
-source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
46
+source "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars"
47 47
 
48
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
48
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
49 49
 for f in $UTILS_FILES
50 50
 do
51
-  source $f
51
+    source "$f"
52 52
 done
53 53
 
54
-APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
54
+APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
55 55
 for f in $APP_FILES
56 56
 do
57
-  source $f
57
+    source "$f"
58 58
 done
59 59
 
60 60
 # End including files
@@ -67,17 +67,17 @@ function mark_unselected_apps_as_removed {
67 67
         return
68 68
     fi
69 69
 
70
-    if [ -f $REMOVED_APPS_FILE ]; then
71
-        rm $REMOVED_APPS_FILE
70
+    if [ -f "$REMOVED_APPS_FILE" ]; then
71
+        rm "$REMOVED_APPS_FILE"
72 72
     fi
73 73
 
74 74
     app_index=0
75 75
     for app_name in "${APPS_AVAILABLE[@]}"
76 76
     do
77 77
         if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
78
-            echo "_${app_name}_" >> $REMOVED_APPS_FILE
78
+            echo "_${app_name}_" >> "$REMOVED_APPS_FILE"
79 79
         fi
80
-        app_index=$[app_index+1]
80
+        app_index=$((app_index+1))
81 81
     done
82 82
 }
83 83
 
@@ -93,7 +93,7 @@ function app_expected_to_be_installed {
93 93
             echo "0"
94 94
             return
95 95
         fi
96
-        if ! grep -q "IN_DEFAULT_INSTALL=1" /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}; then
96
+        if ! grep -q "IN_DEFAULT_INSTALL=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
97 97
             echo "0"
98 98
             return
99 99
         fi
@@ -102,7 +102,7 @@ function app_expected_to_be_installed {
102 102
 }
103 103
 
104 104
 function show_apps {
105
-    select_all_apps=$1
105
+    select_all_apps="$1"
106 106
     applist=""
107 107
     n=1
108 108
     app_index=0
@@ -117,19 +117,20 @@ function show_apps {
117 117
                 applist="$applist $n $a on"
118 118
             fi
119 119
         fi
120
-        n=$[n+1]
121
-        app_index=$[app_index+1]
120
+        n=$((n+1))
121
+        app_index=$((app_index+1))
122 122
     done
123 123
 
124 124
     choices=$(dialog --stdout --backtitle $"Freedombone" \
125 125
                      --title $"Add/Remove Applications" \
126 126
                      --checklist $'Choose:' \
127
-                     27 40 20 $applist)
127
+                     27 40 20 "$applist")
128 128
 
129
+    # shellcheck disable=SC2181
129 130
     if [ $? -eq 0 ]; then
130 131
         for choice in $choices
131 132
         do
132
-            app_index=$[choice-1]
133
+            app_index=$((choice-1))
133 134
             APPS_CHOSEN[$app_index]="1"
134 135
         done
135 136
     else
@@ -151,10 +152,10 @@ function remove_apps_selected {
151 152
                 else
152 153
                     removals="${APPS_AVAILABLE[$app_index]}"
153 154
                 fi
154
-                n=$[n+1]
155
+                n=$((n+1))
155 156
             fi
156 157
         fi
157
-        app_index=$[app_index+1]
158
+        app_index=$((app_index+1))
158 159
     done
159 160
 
160 161
     # if no apps to be removed then don't do anything
@@ -166,7 +167,7 @@ function remove_apps_selected {
166 167
     dialog --title $"Remove applications" \
167 168
            --backtitle $"Freedombone" \
168 169
            --defaultno \
169
-           --yesno $"\nYou have chosen to remove $n apps.\n\n    $removals\n\nIf you choose 'yes' then this will remove both the applications and their data/messages. If you don't have a backup then you will not be able to recover the data for these applications.\n\nAre you sure that you wish to continue?" 15 60
170
+           --yesno $"\\nYou have chosen to remove $n apps.\\n\\n    $removals\\n\\nIf you choose 'yes' then this will remove both the applications and their data/messages. If you don't have a backup then you will not be able to recover the data for these applications.\\n\\nAre you sure that you wish to continue?" 15 60
170 171
     sel=$?
171 172
     case $sel in
172 173
         1) return;;
@@ -195,10 +196,10 @@ function install_apps_selected {
195 196
                 else
196 197
                     installs="${APPS_AVAILABLE[$app_index]}"
197 198
                 fi
198
-                n=$[n+1]
199
+                n=$((n+1))
199 200
             fi
200 201
         fi
201
-        app_index=$[app_index+1]
202
+        app_index=$((app_index+1))
202 203
     done
203 204
 
204 205
     # if no apps to be installed then don't do anything
@@ -212,13 +213,13 @@ function install_apps_selected {
212 213
             dialog --title $"$installs" \
213 214
                    --backtitle $"Freedombone" \
214 215
                    --defaultno \
215
-                   --yesno $"\nThis will install the $installs app\n\nProceed?" 9 40
216
+                   --yesno $"\\nThis will install the $installs app\\n\\nProceed?" 9 40
216 217
         else
217
-            dialog_height=$((15 + $n))
218
+            dialog_height=$((15 + "$n"))
218 219
             dialog --title $"Add applications" \
219 220
                    --backtitle $"Freedombone" \
220 221
                    --defaultno \
221
-                   --yesno $"\nYou have chosen to install $n apps\n\n    $installs\n\nProceed?" $dialog_height 60
222
+                   --yesno $"\\nYou have chosen to install $n apps\\n\\n    $installs\\n\\nProceed?" $dialog_height 60
222 223
         fi
223 224
         sel=$?
224 225
         case $sel in
@@ -232,14 +233,13 @@ function install_apps_selected {
232 233
     # install the apps
233 234
     read_configuration
234 235
     install_apps interactive
235
-    if [ ! $APP_INSTALLED_SUCCESS ]; then
236
+    if [ ! "$APP_INSTALLED_SUCCESS" ]; then
236 237
         echo $'One or more apps failed to install'
237 238
     fi
238 239
 }
239 240
 
240 241
 if [[ $1 == "test"* ]]; then
241
-    ${PROJECT_NAME}-tests
242
-    if [ ! "$?" = "0" ]; then
242
+    if ! ${PROJECT_NAME}-tests; then
243 243
         exit 2
244 244
     fi
245 245
 fi
@@ -251,8 +251,8 @@ if [[ ${#APPS_AVAILABLE[@]} == 0 ]]; then
251 251
     exit 1
252 252
 fi
253 253
 
254
-show_apps $1
255
-mark_unselected_apps_as_removed $1
254
+show_apps "$1"
255
+mark_unselected_apps_as_removed "$1"
256 256
 
257 257
 clear
258 258
 

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

@@ -34,18 +34,18 @@ PROJECT_NAME='freedombone'
34 34
 export TEXTDOMAIN=${PROJECT_NAME}-adduser
35 35
 export TEXTDOMAINDIR="/usr/share/locale"
36 36
 
37
-CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
37
+CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
38 38
 
39
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
39
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
40 40
 for f in $UTILS_FILES
41 41
 do
42
-    source $f
42
+    source "$f"
43 43
 done
44 44
 
45
-APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
45
+APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
46 46
 for f in $APP_FILES
47 47
 do
48
-    source $f
48
+    source "$f"
49 49
 done
50 50
 
51 51
 ADD_USERNAME=$1
@@ -55,35 +55,35 @@ SSH_PORT=2222
55 55
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
56 56
 DEFAULT_DOMAIN_NAME=
57 57
 
58
-if [ ! $ADD_USERNAME ]; then
58
+if [ ! "$ADD_USERNAME" ]; then
59 59
     echo $'No username was given'
60 60
     exit 1
61 61
 fi
62 62
 
63
-if [ -d /home/$ADD_USERNAME ]; then
63
+if [ -d "/home/$ADD_USERNAME" ]; then
64 64
     echo $"The user $ADD_USERNAME already exists"
65 65
     exit 2
66 66
 fi
67 67
 
68
-if [ ! -f $COMPLETION_FILE ]; then
68
+if [ ! -f "$COMPLETION_FILE" ]; then
69 69
     echo $"$COMPLETION_FILE not found"
70
-    userdel -r $ADD_USERNAME
70
+    userdel -r "$ADD_USERNAME"
71 71
     exit 3
72 72
 fi
73 73
 
74 74
 # Minimum number of characters in a password
75
-MINIMUM_PASSWORD_LENGTH=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords | grep 'MINIMUM_PASSWORD_LENGTH=' | head -n 1 | awk -F '=' '{print $2}')
75
+MINIMUM_PASSWORD_LENGTH=$(grep 'MINIMUM_PASSWORD_LENGTH=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords" | head -n 1 | awk -F '=' '{print $2}')
76 76
 
77
-NEW_USER_PASSWORD="$(openssl rand -base64 30 | cut -c1-${MINIMUM_PASSWORD_LENGTH})"
77
+NEW_USER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
78 78
 chmod 600 /etc/shadow
79 79
 chmod 600 /etc/gshadow
80
-useradd -m -p "$NEW_USER_PASSWORD" -s /bin/bash $ADD_USERNAME
81
-adduser $ADD_USERNAME sasl
82
-groupadd $ADD_USERNAME
80
+useradd -m -p "$NEW_USER_PASSWORD" -s /bin/bash "$ADD_USERNAME"
81
+adduser "$ADD_USERNAME" sasl
82
+groupadd "$ADD_USERNAME"
83 83
 chmod 0000 /etc/shadow
84 84
 chmod 0000 /etc/gshadow
85 85
 
86
-if [ ! -d /home/$ADD_USERNAME ]; then
86
+if [ ! -d "/home/$ADD_USERNAME" ]; then
87 87
     echo $'Home directory was not created'
88 88
     exit 4
89 89
 fi
@@ -91,15 +91,15 @@ fi
91 91
 if [ "$SSH_PUBLIC_KEY" ]; then
92 92
     if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
93 93
         if [ -f "$SSH_PUBLIC_KEY" ]; then
94
-            mkdir /home/$ADD_USERNAME/.ssh
95
-            cp $SSH_PUBLIC_KEY /home/$ADD_USERNAME/.ssh/authorized_keys
96
-            chown -R $ADD_USERNAME:$ADD_USERNAME /home/$ADD_USERNAME/.ssh
94
+            mkdir "/home/$ADD_USERNAME/.ssh"
95
+            cp "$SSH_PUBLIC_KEY" "/home/$ADD_USERNAME/.ssh/authorized_keys"
96
+            chown -R "$ADD_USERNAME":"$ADD_USERNAME" "/home/$ADD_USERNAME/.ssh"
97 97
             echo $'ssh public key installed'
98 98
         else
99 99
             if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
100
-                mkdir /home/$ADD_USERNAME/.ssh
101
-                echo "$SSH_PUBLIC_KEY" > /home/$ADD_USERNAME/.ssh/authorized_keys
102
-                chown -R $ADD_USERNAME:$ADD_USERNAME /home/$ADD_USERNAME/.ssh
100
+                mkdir "/home/$ADD_USERNAME/.ssh"
101
+                echo "$SSH_PUBLIC_KEY" > "/home/$ADD_USERNAME/.ssh/authorized_keys"
102
+                chown -R "$ADD_USERNAME":"$ADD_USERNAME" "/home/$ADD_USERNAME/.ssh"
103 103
                 echo $'ssh public key installed'
104 104
             else
105 105
                 echo $'The second parameter does not look like an ssh key'
@@ -109,55 +109,54 @@ if [ "$SSH_PUBLIC_KEY" ]; then
109 109
     fi
110 110
 fi
111 111
 
112
-if [ -d /home/$ADD_USERNAME/Maildir ]; then
113
-    if grep -q "set from=" /home/$ADD_USERNAME/.muttrc; then
114
-        sed -i "s|set from=.*|set from='$ADD_USERNAME <$ADD_USERNAME@$HOSTNAME>'|g" /home/$ADD_USERNAME/.muttrc
112
+if [ -d "/home/$ADD_USERNAME/Maildir" ]; then
113
+    if grep -q "set from=" "/home/$ADD_USERNAME/.muttrc"; then
114
+        sed -i "s|set from=.*|set from='$ADD_USERNAME <$ADD_USERNAME@$HOSTNAME>'|g" "/home/$ADD_USERNAME/.muttrc"
115 115
     else
116
-        echo "set from='$ADD_USERNAME <$ADD_USERNAME@$HOSTNAME>'" >> /home/$ADD_USERNAME/.muttrc
116
+        echo "set from='$ADD_USERNAME <$ADD_USERNAME@$HOSTNAME>'" >> "/home/$ADD_USERNAME/.muttrc"
117 117
     fi
118 118
 
119
-    USERN='$USER@'
120
-    sed -i "s|$USERN|$ADD_USERNAME@|g" /home/$ADD_USERNAME/.procmailrc
119
+    sed -i "s|\$USER@|$ADD_USERNAME@|g" "/home/$ADD_USERNAME/.procmailrc"
121 120
 fi
122 121
 
123 122
 # generate a gpg key
124 123
 echo "Making a GPG key for $ADD_USERNAME@$HOSTNAME"
125
-mkdir /home/$ADD_USERNAME/.gnupg
126
-echo "keyserver $GPG_KEYSERVER" >> /home/$ADD_USERNAME/.gnupg/gpg.conf
127
-echo 'keyserver-options auto-key-retrieve' >> /home/$ADD_USERNAME/.gnupg/gpg.conf
128
-echo '' >> /home/$ADD_USERNAME/.gnupg/gpg.conf
129
-echo '# default preferences' >> /home/$ADD_USERNAME/.gnupg/gpg.conf
130
-echo 'personal-digest-preferences SHA256' >> /home/$ADD_USERNAME/.gnupg/gpg.conf
131
-echo 'cert-digest-algo SHA256' >> /home/$ADD_USERNAME/.gnupg/gpg.conf
132
-echo 'default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed' >> /home/$ADD_USERNAME/.gnupg/gpg.conf
133
-
134
-chown -R $ADD_USERNAME:$ADD_USERNAME /home/$ADD_USERNAME/.gnupg
135
-chmod 700 /home/$ADD_USERNAME/.gnupg
136
-chmod 600 /home/$ADD_USERNAME/.gnupg/*
124
+mkdir "/home/$ADD_USERNAME/.gnupg"
125
+{ echo "keyserver $GPG_KEYSERVER";
126
+  echo 'keyserver-options auto-key-retrieve';
127
+  echo '';
128
+  echo '# default preferences';
129
+  echo 'personal-digest-preferences SHA256';
130
+  echo 'cert-digest-algo SHA256';
131
+  echo 'default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed'; } >> "/home/$ADD_USERNAME/.gnupg/gpg.conf"
132
+
133
+chown -R "$ADD_USERNAME":"$ADD_USERNAME" "/home/$ADD_USERNAME/.gnupg"
134
+chmod 700 "/home/$ADD_USERNAME/.gnupg"
135
+chmod 600 "/home/$ADD_USERNAME/.gnupg/*"
137 136
 
138 137
 # Generate a GPG key
139
-echo 'Key-Type: eddsa' > /home/$ADD_USERNAME/gpg-genkey.conf
140
-echo 'Key-Curve: Ed25519' >> /home/$ADD_USERNAME/gpg-genkey.conf
141
-echo 'Subkey-Type: eddsa' >> /home/$ADD_USERNAME/gpg-genkey.conf
142
-echo "Name-Real:  $ADD_USERNAME" >> /home/$ADD_USERNAME/gpg-genkey.conf
143
-echo "Name-Email: $ADD_USERNAME@$HOSTNAME" >> /home/$ADD_USERNAME/gpg-genkey.conf
144
-echo 'Expire-Date: 0' >> /home/$ADD_USERNAME/gpg-genkey.conf
145
-echo "Passphrase: $NEW_USER_PASSWORD" >> /home/$ADD_USERNAME/gpg-genkey.conf
146
-chown $ADD_USERNAME:$ADD_USERNAME /home/$ADD_USERNAME/gpg-genkey.conf
147
-su -m root -c "gpg --homedir /home/$ADD_USERNAME/.gnupg --batch --full-gen-key /home/$ADD_USERNAME/gpg-genkey.conf" - $ADD_USERNAME
148
-chown -R $ADD_USERNAME:$ADD_USERNAME /home/$ADD_USERNAME/.gnupg
149
-shred -zu /home/$ADD_USERNAME/gpg-genkey.conf
138
+{ echo 'Key-Type: eddsa';
139
+  echo 'Key-Curve: Ed25519';
140
+  echo 'Subkey-Type: eddsa';
141
+  echo "Name-Real:  $ADD_USERNAME";
142
+  echo "Name-Email: $ADD_USERNAME@$HOSTNAME";
143
+  echo 'Expire-Date: 0';
144
+  echo "Passphrase: $NEW_USER_PASSWORD"; } > "/home/$ADD_USERNAME/gpg-genkey.conf"
145
+chown "$ADD_USERNAME":"$ADD_USERNAME" "/home/$ADD_USERNAME/gpg-genkey.conf"
146
+su -m root -c "gpg --homedir /home/$ADD_USERNAME/.gnupg --batch --full-gen-key /home/$ADD_USERNAME/gpg-genkey.conf" - "$ADD_USERNAME"
147
+chown -R "$ADD_USERNAME":"$ADD_USERNAME" "/home/$ADD_USERNAME/.gnupg"
148
+shred -zu "/home/$ADD_USERNAME/gpg-genkey.conf"
150 149
 MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADD_USERNAME" "$ADD_USERNAME@$HOSTNAME")
151
-MY_GPG_PUBLIC_KEY=/home/$ADD_USERNAME/public_key.gpg
152
-su -m root -c "gpg --output $MY_GPG_PUBLIC_KEY --armor --export $MY_GPG_PUBLIC_KEY_ID" - $ADD_USERNAME
150
+MY_GPG_PUBLIC_KEY="/home/$ADD_USERNAME/public_key.gpg"
151
+su -m root -c "gpg --output $MY_GPG_PUBLIC_KEY --armor --export $MY_GPG_PUBLIC_KEY_ID" - "$ADD_USERNAME"
153 152
 
154
-if [ ! -f $MY_GPG_PUBLIC_KEY ]; then
153
+if [ ! -f "$MY_GPG_PUBLIC_KEY" ]; then
155 154
     echo "GPG public key was not generated for $ADD_USERNAME@$HOSTNAME $MY_GPG_PUBLIC_KEY_ID"
156
-    userdel -r $ADD_USERNAME
155
+    userdel -r "$ADD_USERNAME"
157 156
     exit 7
158 157
 fi
159 158
 
160
-gpg_agent_setup $ADD_USERNAME
159
+gpg_agent_setup "$ADD_USERNAME"
161 160
 
162 161
 # add a monkeysphere subkey
163 162
 #echo $'Adding monkeysphere subkey'
@@ -173,82 +172,82 @@ gpg_agent_setup $ADD_USERNAME
173 172
 #echo $'Updating monkeysphere users'
174 173
 #monkeysphere-authentication update-users
175 174
 
176
-if [ -f /home/$ADD_USERNAME/.muttrc ]; then
175
+if [ -f "/home/$ADD_USERNAME/.muttrc" ]; then
177 176
     # encrypt outgoing mail to the "sent" folder
178
-    if ! grep -q "pgp_encrypt_only_command" /home/$ADD_USERNAME/.muttrc; then
179
-        echo '' >> /home/$ADD_USERNAME/.muttrc
180
-        echo $'# Encrypt items in the Sent folder' >> /home/$ADD_USERNAME/.muttrc
181
-        echo "set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"" >> /home/$ADD_USERNAME/.muttrc
177
+    if ! grep -q "pgp_encrypt_only_command" "/home/$ADD_USERNAME/.muttrc"; then
178
+        { echo '';
179
+          echo $'# Encrypt items in the Sent folder';
180
+          echo "set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\""; } >> "/home/$ADD_USERNAME/.muttrc"
182 181
     else
183
-        sed -i "s|set pgp_encrypt_only_command.*|set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" /home/$ADD_USERNAME/.muttrc
182
+        sed -i "s|set pgp_encrypt_only_command.*|set pgp_encrypt_only_command=\"/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" "/home/$ADD_USERNAME/.muttrc"
184 183
     fi
185 184
 
186
-    if ! grep -q "pgp_encrypt_sign_command" /home/$ADD_USERNAME/.muttrc; then
187
-        echo "set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"" >> /home/$ADD_USERNAME/.muttrc
185
+    if ! grep -q "pgp_encrypt_sign_command" "/home/$ADD_USERNAME/.muttrc"; then
186
+        echo "set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"" >> "/home/$ADD_USERNAME/.muttrc"
188 187
     else
189
-        sed -i "s|set pgp_encrypt_sign_command.*|set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" /home/$ADD_USERNAME/.muttrc
188
+        sed -i "s|set pgp_encrypt_sign_command.*|set pgp_encrypt_sign_command=\"/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust --encrypt-to $MY_GPG_PUBLIC_KEY_ID -- -r %r -- %f\"|g" "/home/$ADD_USERNAME/.muttrc"
190 189
     fi
191 190
 fi
192 191
 
193
-if ! grep -q "Change your GPG password" /home/$ADD_USERNAME/README; then
194
-    echo '' >> /home/$ADD_USERNAME/README
195
-    echo '' >> /home/$ADD_USERNAME/README
196
-    echo $'# Change your GPG password' >> /home/$ADD_USERNAME/README
197
-    echo $"It's very important to add a password to your GPG key so that" >> /home/$ADD_USERNAME/README
198
-    echo $"if anyone does get access to your email they still won't be able" >> /home/$ADD_USERNAME/README
199
-    echo $'to read them without knowning the GPG password.' >> /home/$ADD_USERNAME/README
200
-    echo $'You can change the it with:' >> /home/$ADD_USERNAME/README
201
-    echo '' >> /home/$ADD_USERNAME/README
202
-    echo "  gpg --edit-key $MY_GPG_PUBLIC_KEY_ID" >> /home/$ADD_USERNAME/README
203
-    echo '  passwd' >> /home/$ADD_USERNAME/README
204
-    echo '  save' >> /home/$ADD_USERNAME/README
205
-    echo '  quit' >> /home/$ADD_USERNAME/README
192
+if ! grep -q "Change your GPG password" "/home/$ADD_USERNAME/README"; then
193
+    { echo '';
194
+      echo '';
195
+      echo $'# Change your GPG password';
196
+      echo $"It's very important to add a password to your GPG key so that";
197
+      echo $"if anyone does get access to your email they still won't be able";
198
+      echo $'to read them without knowning the GPG password.';
199
+      echo $'You can change the it with:';
200
+      echo '';
201
+      echo "  gpg --edit-key $MY_GPG_PUBLIC_KEY_ID";
202
+      echo '  passwd';
203
+      echo '  save';
204
+      echo '  quit'; } >> "/home/$ADD_USERNAME/README"
206 205
 fi
207 206
 
208
-chown $ADD_USERNAME:$ADD_USERNAME /home/$ADD_USERNAME/README
209
-chown $ADD_USERNAME:$ADD_USERNAME $MY_GPG_PUBLIC_KEY
210
-chmod 600 /home/$ADD_USERNAME/README
207
+chown "$ADD_USERNAME":"$ADD_USERNAME" "/home/$ADD_USERNAME/README"
208
+chown "$ADD_USERNAME":"$ADD_USERNAME" "$MY_GPG_PUBLIC_KEY"
209
+chmod 600 "/home/$ADD_USERNAME/README"
211 210
 
212 211
 echo $'Detecting installed apps...'
213 212
 detect_apps
214 213
 get_apps_installed_names
215 214
 for app_name in "${APPS_INSTALLED_NAMES[@]}"
216 215
 do
217
-    if [[ $(function_exists add_user_${app_name}) == "1" ]]; then
216
+    if [[ $(function_exists "add_user_${app_name}") == "1" ]]; then
218 217
         echo $"Adding user to ${app_name}"
219
-        app_load_variables ${app_name}
220
-        retval=$(add_user_${app_name} "$ADD_USERNAME" "$NEW_USER_PASSWORD" | tail -n 1)
218
+        app_load_variables "${app_name}"
219
+        retval=$("add_user_${app_name}" "$ADD_USERNAME" "$NEW_USER_PASSWORD" | tail -n 1)
221 220
         if [[ $retval != '0' ]]; then
222 221
             echo $"Failed with error code ${retval}"
223
-            ${PROJECT_NAME}-rmuser $ADD_USERNAME --force
222
+            "${PROJECT_NAME}-rmuser" "$ADD_USERNAME" --force
224 223
             exit 672392
225 224
         fi
226
-        if ! grep -q "${app_name}_${ADD_USERNAME}" $APP_USERS_FILE; then
227
-            echo "${app_name}_${ADD_USERNAME}" >> $APP_USERS_FILE
225
+        if ! grep -q "${app_name}_${ADD_USERNAME}" "$APP_USERS_FILE"; then
226
+            echo "${app_name}_${ADD_USERNAME}" >> "$APP_USERS_FILE"
228 227
         fi
229 228
     fi
230 229
 done
231 230
 
232 231
 if [ -f /etc/nginx/.htpasswd ]; then
233 232
     if ! grep -q "${ADD_USERNAME}:" /etc/nginx/.htpasswd; then
234
-        echo "$NEW_USER_PASSWORD" | htpasswd -i -s /etc/nginx/.htpasswd $ADD_USERNAME
233
+        echo "$NEW_USER_PASSWORD" | htpasswd -i -s /etc/nginx/.htpasswd "$ADD_USERNAME"
235 234
     fi
236 235
 fi
237 236
 
238 237
 # add user menu on ssh login
239
-if ! grep -q 'controluser' /home/$ADD_USERNAME/.bashrc; then
240
-    echo 'controluser' >> /home/$ADD_USERNAME/.bashrc
238
+if ! grep -q 'controluser' "/home/$ADD_USERNAME/.bashrc"; then
239
+    echo 'controluser' >> "/home/$ADD_USERNAME/.bashrc"
241 240
 fi
242 241
 
243 242
 # fix some gpg strangeness when searching for keys
244
-printf '%%Assuan%%\nsocket=/dev/shm/S.dirmngr\n' > /home/$ADD_USERNAME/.gnupg/S.dirmngr
245
-if [ -d /home/$ADD_USERNAME/.gnupg/crls.d ]; then
246
-    chmod +x /home/$ADD_USERNAME/.gnupg/crls.d
243
+printf '%%Assuan%%\nsocket=/dev/shm/S.dirmngr\n' > "/home/$ADD_USERNAME/.gnupg/S.dirmngr"
244
+if [ -d "/home/$ADD_USERNAME/.gnupg/crls.d" ]; then
245
+    chmod +x "/home/$ADD_USERNAME/.gnupg/crls.d"
247 246
 fi
248 247
 
249
-${PROJECT_NAME}-pass -u $ADD_USERNAME -a login -p "$NEW_USER_PASSWORD"
248
+"${PROJECT_NAME}-pass" -u "$ADD_USERNAME" -a login -p "$NEW_USER_PASSWORD"
250 249
 
251
-gpg_agent_enable $ADD_USERNAME
250
+gpg_agent_enable "$ADD_USERNAME"
252 251
 
253 252
 clear
254 253
 

+ 153
- 152
src/freedombone-app-akaunting Просмотреть файл

@@ -49,12 +49,12 @@ akaunting_variables=(ONION_ONLY
49 49
                      MY_USERNAME)
50 50
 
51 51
 function akaunting_remove_bad_links {
52
-    cd /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
52
+    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 365873658
53 53
 
54 54
     # copy jquery locally
55 55
     jquery_version='1.12.4'
56 56
     if [ ! -f jquery-${jquery_version}.js ]; then
57
-        cd /var/www/$GHOST_DOMAIN_NAME/htdocs
57
+        cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 3276324
58 58
         wget https://code.jquery.com/jquery-${jquery_version}.js
59 59
         jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
60 60
         if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
@@ -74,7 +74,7 @@ function akaunting_remove_bad_links {
74 74
     sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/dist/css/alt/AdminLTE-without-plugins.min.css
75 75
     sed -i "s|ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js|$AKAUNTING_DOMAIN_NAME/jquery-${jquery_version}.js|g" vendor/almasaeed2010/adminlte/plugins/ckeditor/samples/old/jquery.html
76 76
 
77
-    chown -R www-data:www-data /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
77
+    chown -R www-data:www-data "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
78 78
 }
79 79
 
80 80
 function logging_on_akaunting {
@@ -88,65 +88,66 @@ function logging_off_akaunting {
88 88
 function remove_user_akaunting {
89 89
     remove_username="$1"
90 90
 
91
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp akaunting
91
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp akaunting
92 92
 }
93 93
 
94 94
 function add_user_akaunting {
95 95
     new_username="$1"
96 96
     new_user_password="$2"
97 97
 
98
-    ${PROJECT_NAME}-pass -u $new_username -a akaunting -p "$new_user_password"
98
+    "${PROJECT_NAME}-pass" -u "$new_username" -a akaunting -p "$new_user_password"
99 99
 
100 100
     echo '0'
101 101
 }
102 102
 
103 103
 function install_interactive_akaunting {
104
-    if [ ! $ONION_ONLY ]; then
104
+    if [ ! "$ONION_ONLY" ]; then
105 105
         ONION_ONLY='no'
106 106
     fi
107 107
 
108
-    if [[ $ONION_ONLY != "no" ]]; then
108
+    if [[ "$ONION_ONLY" != "no" ]]; then
109 109
         AKAUNTING_DOMAIN_NAME='akaunting.local'
110 110
     else
111 111
         AKAUNTING_DETAILS_COMPLETE=
112 112
         while [ ! $AKAUNTING_DETAILS_COMPLETE ]
113 113
         do
114
-            data=$(tempfile 2>/dev/null)
115
-            trap "rm -f $data" 0 1 2 5 15
114
+            data=$(mktemp 2>/dev/null)
116 115
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
117 116
                 dialog --backtitle $"Freedombone Configuration" \
118 117
                        --title $"Akaunting Configuration" \
119
-                       --form $"\nPlease enter your Akaunting details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
118
+                       --form $"\\nPlease enter your Akaunting details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
120 119
                        $"Domain:" 1 1 "$(grep 'AKAUNTING_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
121 120
                        $"Code:" 2 1 "$(grep 'AKAUNTING_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
122
-                       2> $data
121
+                       2> "$data"
123 122
             else
124 123
                 dialog --backtitle $"Freedombone Configuration" \
125 124
                        --title $"Akaunting Configuration" \
126
-                       --form $"\nPlease enter your Akaunting details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
125
+                       --form $"\\nPlease enter your Akaunting details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
127 126
                        $"Domain:" 1 1 "$(grep 'AKAUNTING_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
128
-                       2> $data
127
+                       2> "$data"
129 128
             fi
130 129
             sel=$?
131 130
             case $sel in
132
-                1) exit 1;;
133
-                255) exit 1;;
131
+                1) rm -f "$data"
132
+                   exit 1;;
133
+                255) rm -f "$data"
134
+                     exit 1;;
134 135
             esac
135
-            AKAUNTING_DOMAIN_NAME=$(cat $data | sed -n 1p)
136
-            if [ $AKAUNTING_DOMAIN_NAME ]; then
136
+            AKAUNTING_DOMAIN_NAME=$(sed -n 1p < "$data")
137
+            if [ "$AKAUNTING_DOMAIN_NAME" ]; then
137 138
                 if [[ $AKAUNTING_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
138 139
                     AKAUNTING_DOMAIN_NAME=""
139 140
                 fi
140 141
                 TEST_DOMAIN_NAME=$AKAUNTING_DOMAIN_NAME
141 142
                 validate_domain_name
142
-                if [[ $TEST_DOMAIN_NAME != $AKAUNTING_DOMAIN_NAME ]]; then
143
+                if [[ "$TEST_DOMAIN_NAME" != "$AKAUNTING_DOMAIN_NAME" ]]; then
143 144
                     AKAUNTING_DOMAIN_NAME=
144 145
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
145 146
                 else
146 147
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
147
-                        AKAUNTING_CODE=$(cat $data | sed -n 2p)
148
+                        AKAUNTING_CODE=$(sed -n 2p < "$data")
148 149
                         validate_freedns_code "$AKAUNTING_CODE"
149
-                        if [ ! $VALID_CODE ]; then
150
+                        if [ ! "$VALID_CODE" ]; then
150 151
                             AKAUNTING_DOMAIN_NAME=
151 152
                         fi
152 153
                     fi
@@ -155,6 +156,7 @@ function install_interactive_akaunting {
155 156
             if [ $AKAUNTING_DOMAIN_NAME ]; then
156 157
                 AKAUNTING_DETAILS_COMPLETE="yes"
157 158
             fi
159
+            rm -f "$data"
158 160
         done
159 161
 
160 162
         write_config_param "AKAUNTING_CODE" "$AKAUNTING_CODE"
@@ -169,23 +171,23 @@ function change_password_akaunting {
169 171
 
170 172
     read_config_param 'AKAUNTING_DOMAIN_NAME'
171 173
 
172
-    ${PROJECT_NAME}-pass -u "$curr_username" -a akaunting -p "$new_user_password"
174
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a akaunting -p "$new_user_password"
173 175
 }
174 176
 
175 177
 function akaunting_create_database {
176
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
177
-        AKAUNTING_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
178
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
179
+        AKAUNTING_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
178 180
     else
179
-        if [ ! $AKAUNTING_ADMIN_PASSWORD ]; then
180
-            AKAUNTING_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
181
+        if [ ! "$AKAUNTING_ADMIN_PASSWORD" ]; then
182
+            AKAUNTING_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
181 183
         fi
182 184
     fi
183
-    if [ ! $AKAUNTING_ADMIN_PASSWORD ]; then
185
+    if [ ! "$AKAUNTING_ADMIN_PASSWORD" ]; then
184 186
         return
185 187
     fi
186 188
 
187 189
     function_check create_database
188
-    create_database akaunting "$AKAUNTING_ADMIN_PASSWORD" $MY_USERNAME
190
+    create_database akaunting "$AKAUNTING_ADMIN_PASSWORD" "$MY_USERNAME"
189 191
 }
190 192
 
191 193
 function reconfigure_akaunting {
@@ -198,70 +200,69 @@ function upgrade_akaunting {
198 200
         return
199 201
     fi
200 202
 
201
-    if grep -q "akaunting domain" $COMPLETION_FILE; then
203
+    if grep -q "akaunting domain" "$COMPLETION_FILE"; then
202 204
         AKAUNTING_DOMAIN_NAME=$(get_completion_param "akaunting domain")
203 205
     fi
204 206
 
205 207
     # update to the next commit
206 208
     function_check set_repo_commit
207
-    set_repo_commit /var/www/$AKAUNTING_DOMAIN_NAME/htdocs "akaunting commit" "$AKAUNTING_COMMIT" $AKAUNTING_REPO
209
+    set_repo_commit "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" "akaunting commit" "$AKAUNTING_COMMIT" "$AKAUNTING_REPO"
208 210
 
209
-    cd /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
211
+    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 367835
210 212
     install_composer
211 213
     akaunting_remove_bad_links
212 214
 
213
-    chown -R www-data:www-data /var/www/${AKAUNTING_DOMAIN_NAME}/htdocs
215
+    chown -R www-data:www-data "/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
214 216
 }
215 217
 
216 218
 
217 219
 function backup_local_akaunting {
218
-    akaunting_path=/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs
219
-    if [ -d $akaunting_path ]; then
220
-        suspend_site ${AKAUNTING_DOMAIN_NAME}
220
+    akaunting_path="/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
221
+    if [ -d "$akaunting_path" ]; then
222
+        suspend_site "${AKAUNTING_DOMAIN_NAME}"
221 223
         function_check backup_database_to_usb
222 224
         backup_database_to_usb akaunting
223
-        backup_directory_to_usb $akaunting_path akaunting
225
+        backup_directory_to_usb "$akaunting_path" akaunting
224 226
         restart_site
225 227
     fi
226 228
 }
227 229
 
228 230
 function restore_local_akaunting {
229 231
     temp_restore_dir=/root/tempakaunting
230
-    akaunting_dir=/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs
232
+    akaunting_dir="/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
231 233
 
232
-    suspend_site ${AKAUNTING_DOMAIN_NAME}
234
+    suspend_site "${AKAUNTING_DOMAIN_NAME}"
233 235
 
234 236
     function_check akaunting_create_database
235 237
     akaunting_create_database
236 238
 
237
-    restore_database akaunting ${AKAUNTING_DOMAIN_NAME}
238
-    chown www-data:www-data $akaunting_dir
239
+    restore_database akaunting "${AKAUNTING_DOMAIN_NAME}"
240
+    chown www-data:www-data "$akaunting_dir"
239 241
 
240 242
     restart_site
241 243
 }
242 244
 
243 245
 function backup_remote_akaunting {
244
-    akaunting_path=/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs
245
-    if [ -d $akaunting_path ]; then
246
-        suspend_site ${AKAUNTING_DOMAIN_NAME}
246
+    akaunting_path="/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
247
+    if [ -d "$akaunting_path" ]; then
248
+        suspend_site "${AKAUNTING_DOMAIN_NAME}"
247 249
         function_check backup_database_to_friend
248 250
         backup_database_to_friend akaunting
249
-        backup_directory_to_friend $akaunting_path akaunting
251
+        backup_directory_to_friend "$akaunting_path" akaunting
250 252
         restart_site
251 253
     fi
252 254
 }
253 255
 
254 256
 function restore_remote_akaunting {
255
-    temp_restore_dir=/root/tempakaunting
256
-    akaunting_dir=/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs
257
+    akaunting_dir="/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
257 258
 
258
-    suspend_site ${AKAUNTING_DOMAIN_NAME}
259
+    suspend_site "${AKAUNTING_DOMAIN_NAME}"
259 260
 
260 261
     function_check akaunting_create_database
261 262
     akaunting_create_database
262 263
 
263
-    restore_database_from_friend akaunting ${AKAUNTING_DOMAIN_NAME}
264
-    chown www-data:www-data $akaunting_dir
264
+    restore_database_from_friend akaunting "${AKAUNTING_DOMAIN_NAME}"
265
+    chown www-data:www-data "$akaunting_dir"
265 266
 
266 267
     restart_site
267 268
 }
@@ -274,28 +275,28 @@ function remove_akaunting {
274 275
     read_config_param "AKAUNTING_DOMAIN_NAME"
275 276
     read_config_param "MY_USERNAME"
276 277
     echo "Removing $AKAUNTING_DOMAIN_NAME"
277
-    nginx_dissite $AKAUNTING_DOMAIN_NAME
278
-    remove_certs $AKAUNTING_DOMAIN_NAME
278
+    nginx_dissite "$AKAUNTING_DOMAIN_NAME"
279
+    remove_certs "$AKAUNTING_DOMAIN_NAME"
279 280
 
280
-    if [ -d /var/www/$AKAUNTING_DOMAIN_NAME ]; then
281
-        rm -rf /var/www/$AKAUNTING_DOMAIN_NAME
281
+    if [ -d "/var/www/$AKAUNTING_DOMAIN_NAME" ]; then
282
+        rm -rf "/var/www/$AKAUNTING_DOMAIN_NAME"
282 283
     fi
283
-    if [ -f /etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME ]; then
284
-        rm /etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME
284
+    if [ -f "/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME" ]; then
285
+        rm "/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME"
285 286
     fi
286 287
     function_check drop_database
287 288
     drop_database akaunting
288 289
     function_check remove_onion_service
289
-    remove_onion_service akaunting ${AKAUNTING_ONION_PORT}
290
+    remove_onion_service akaunting "${AKAUNTING_ONION_PORT}"
290 291
     if grep -q "akaunting" /etc/crontab; then
291 292
         sed -i "/akaunting/d" /etc/crontab
292 293
     fi
293 294
     remove_app akaunting
294 295
     remove_completion_param install_akaunting
295
-    sed -i '/akaunting/d' $COMPLETION_FILE
296
+    sed -i '/akaunting/d' "$COMPLETION_FILE"
296 297
 
297 298
     function_check remove_ddns_domain
298
-    remove_ddns_domain $AKAUNTING_DOMAIN_NAME
299
+    remove_ddns_domain "$AKAUNTING_DOMAIN_NAME"
299 300
 }
300 301
 
301 302
 function install_akaunting {
@@ -303,7 +304,7 @@ function install_akaunting {
303 304
         ONION_ONLY='no'
304 305
     fi
305 306
 
306
-    if [ ! $AKAUNTING_DOMAIN_NAME ]; then
307
+    if [ ! "$AKAUNTING_DOMAIN_NAME" ]; then
307 308
         echo $'No domain name was given for akaunting'
308 309
         exit 89353
309 310
     fi
@@ -317,142 +318,142 @@ function install_akaunting {
317 318
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
318 319
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
319 320
 
320
-    if [ ! -d /var/www/$AKAUNTING_DOMAIN_NAME ]; then
321
-        mkdir /var/www/$AKAUNTING_DOMAIN_NAME
321
+    if [ ! -d "/var/www/$AKAUNTING_DOMAIN_NAME" ]; then
322
+        mkdir "/var/www/$AKAUNTING_DOMAIN_NAME"
322 323
     fi
323
-    if [ ! -d /var/www/$AKAUNTING_DOMAIN_NAME/htdocs ]; then
324
+    if [ ! -d "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" ]; then
324 325
         if [ -d /repos/akaunting ]; then
325
-            mkdir /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
326
-            cp -r -p /repos/akaunting/. /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
327
-            cd /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
326
+            mkdir "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
327
+            cp -r -p /repos/akaunting/. "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
328
+            cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 23458735
328 329
             git pull
329 330
         else
330 331
             function_check git_clone
331
-            git_clone $AKAUNTING_REPO /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
332
+            git_clone "$AKAUNTING_REPO" "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
332 333
         fi
333 334
 
334
-        if [ ! -d /var/www/$AKAUNTING_DOMAIN_NAME/htdocs ]; then
335
+        if [ ! -d "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" ]; then
335 336
             echo $'Unable to clone akaunting repo'
336 337
             exit 2589389
337 338
         fi
338 339
     fi
339 340
 
340
-    cd /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
341
-    git checkout $AKAUNTING_COMMIT -b $AKAUNTING_COMMIT
341
+    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 23468724527
342
+    git checkout "$AKAUNTING_COMMIT" -b "$AKAUNTING_COMMIT"
342 343
     set_completion_param "akaunting commit" "$AKAUNTING_COMMIT"
343 344
 
344
-    chmod g+w /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
345
-    chown -R www-data:www-data /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
345
+    chmod g+w "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
346
+    chown -R www-data:www-data "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
346 347
 
347
-    cd /var/www/$AKAUNTING_DOMAIN_NAME/htdocs
348
+    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 34783524
348 349
     install_composer
349 350
 
350 351
     function_check akaunting_create_database
351 352
     akaunting_create_database
352 353
 
353 354
     function_check add_ddns_domain
354
-    add_ddns_domain $AKAUNTING_DOMAIN_NAME
355
+    add_ddns_domain "$AKAUNTING_DOMAIN_NAME"
355 356
 
356 357
     AKAUNTING_ONION_HOSTNAME=$(add_onion_service akaunting 80 ${AKAUNTING_ONION_PORT})
357 358
 
358 359
     akaunting_nginx_site=/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME
359 360
     if [[ $ONION_ONLY == "no" ]]; then
360 361
         function_check nginx_http_redirect
361
-        nginx_http_redirect $AKAUNTING_DOMAIN_NAME "index index.php"
362
-        echo 'server {' >> $akaunting_nginx_site
363
-        echo '  listen 443 ssl;' >> $akaunting_nginx_site
364
-        echo '  #listen [::]:443 ssl;' >> $akaunting_nginx_site
365
-        echo "  server_name $AKAUNTING_DOMAIN_NAME;" >> $akaunting_nginx_site
366
-        echo '' >> $akaunting_nginx_site
362
+        nginx_http_redirect "$AKAUNTING_DOMAIN_NAME" "index index.php"
363
+        { echo 'server {';
364
+          echo '  listen 443 ssl;';
365
+          echo '  #listen [::]:443 ssl;';
366
+          echo "  server_name $AKAUNTING_DOMAIN_NAME;";
367
+          echo ''; } >> "$akaunting_nginx_site"
367 368
         function_check nginx_compress
368
-        nginx_compress $AKAUNTING_DOMAIN_NAME
369
-        echo '' >> $akaunting_nginx_site
370
-        echo '  # Security' >> $akaunting_nginx_site
369
+        nginx_compress "$AKAUNTING_DOMAIN_NAME"
370
+        echo '' >> "$akaunting_nginx_site"
371
+        echo '  # Security' >> "$akaunting_nginx_site"
371 372
         function_check nginx_ssl
372
-        nginx_ssl $AKAUNTING_DOMAIN_NAME
373
+        nginx_ssl "$AKAUNTING_DOMAIN_NAME"
373 374
 
374 375
         function_check nginx_disable_sniffing
375
-        nginx_disable_sniffing $AKAUNTING_DOMAIN_NAME
376
-
377
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $akaunting_nginx_site
378
-        echo '' >> $akaunting_nginx_site
379
-        echo '  access_log /dev/null;' >> $akaunting_nginx_site
380
-        echo '  error_log /dev/null;' >> $akaunting_nginx_site
381
-        echo '' >> $akaunting_nginx_site
382
-        echo "  root /var/www/$AKAUNTING_DOMAIN_NAME/htdocs;" >> $akaunting_nginx_site
383
-        echo '' >> $akaunting_nginx_site
384
-        echo '  index index.php;' >> $akaunting_nginx_site
385
-        echo '' >> $akaunting_nginx_site
386
-        echo '  location ~ \.php {' >> $akaunting_nginx_site
387
-        echo '    include snippets/fastcgi-php.conf;' >> $akaunting_nginx_site
388
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $akaunting_nginx_site
389
-        echo '    fastcgi_read_timeout 30;' >> $akaunting_nginx_site
390
-        echo '  }' >> $akaunting_nginx_site
391
-        echo '' >> $akaunting_nginx_site
392
-        echo '  location / {' >> $akaunting_nginx_site
376
+        nginx_disable_sniffing "$AKAUNTING_DOMAIN_NAME"
377
+
378
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
379
+          echo '';
380
+          echo '  access_log /dev/null;';
381
+          echo '  error_log /dev/null;';
382
+          echo '';
383
+          echo "  root /var/www/$AKAUNTING_DOMAIN_NAME/htdocs;";
384
+          echo '';
385
+          echo '  index index.php;';
386
+          echo '';
387
+          echo '  location ~ \.php {';
388
+          echo '    include snippets/fastcgi-php.conf;';
389
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
390
+          echo '    fastcgi_read_timeout 30;';
391
+          echo '  }';
392
+          echo '';
393
+          echo '  location / {'; } >> "$akaunting_nginx_site"
393 394
         function_check nginx_limits
394
-        nginx_limits $AKAUNTING_DOMAIN_NAME '15m'
395
-        echo '    try_files $uri $uri/ @akaunting;' >> $akaunting_nginx_site
396
-        echo '  }' >> $akaunting_nginx_site
397
-        echo '' >> $akaunting_nginx_site
398
-        echo '  location @akaunting {' >> $akaunting_nginx_site
399
-        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $akaunting_nginx_site
400
-        echo '  }' >> $akaunting_nginx_site
401
-        echo '' >> $akaunting_nginx_site
402
-        echo '  location ~ /\.(ht|git) {' >> $akaunting_nginx_site
403
-        echo '    deny all;' >> $akaunting_nginx_site
404
-        echo '  }' >> $akaunting_nginx_site
405
-        echo '' >> $akaunting_nginx_site
406
-        echo '}' >> $akaunting_nginx_site
395
+        nginx_limits "$AKAUNTING_DOMAIN_NAME" '15m'
396
+        { echo "    try_files \$uri \$uri/ @akaunting;";
397
+          echo '  }';
398
+          echo '';
399
+          echo '  location @akaunting {';
400
+          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
401
+          echo '  }';
402
+          echo '';
403
+          echo '  location ~ /\.(ht|git) {';
404
+          echo '    deny all;';
405
+          echo '  }';
406
+          echo '';
407
+          echo '}'; } >> "$akaunting_nginx_site"
407 408
     else
408
-        echo -n '' > $akaunting_nginx_site
409
+        echo -n '' > "$akaunting_nginx_site"
409 410
     fi
410
-    echo 'server {' >> $akaunting_nginx_site
411
-    echo "    listen 127.0.0.1:$AKAUNTING_ONION_PORT default_server;" >> $akaunting_nginx_site
412
-    echo "    server_name $AKAUNTING_ONION_HOSTNAME;" >> $akaunting_nginx_site
413
-    echo '' >> $akaunting_nginx_site
414
-    function_check nginx_compress
415
-    nginx_compress $AKAUNTING_DOMAIN_NAME
416
-    echo '' >> $akaunting_nginx_site
411
+    { echo 'server {';
412
+      echo "    listen 127.0.0.1:$AKAUNTING_ONION_PORT default_server;";
413
+      echo "    server_name $AKAUNTING_ONION_HOSTNAME;";
414
+      echo ''; } >> "$akaunting_nginx_site"
415
+      function_check nginx_compress
416
+    nginx_compress "$AKAUNTING_DOMAIN_NAME"
417
+    echo '' >> "$akaunting_nginx_site"
417 418
     function_check nginx_disable_sniffing
418
-    nginx_disable_sniffing $AKAUNTING_DOMAIN_NAME
419
-    echo '' >> $akaunting_nginx_site
420
-    echo '  access_log /dev/null;' >> $akaunting_nginx_site
421
-    echo '  error_log /dev/null;' >> $akaunting_nginx_site
422
-    echo '' >> $akaunting_nginx_site
423
-    echo "  root /var/www/$AKAUNTING_DOMAIN_NAME/htdocs;" >> $akaunting_nginx_site
424
-    echo '' >> $akaunting_nginx_site
425
-    echo '  index index.php;' >> $akaunting_nginx_site
426
-    echo '' >> $akaunting_nginx_site
427
-    echo '  location ~ \.php {' >> $akaunting_nginx_site
428
-    echo '    include snippets/fastcgi-php.conf;' >> $akaunting_nginx_site
429
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $akaunting_nginx_site
430
-    echo '    fastcgi_read_timeout 30;' >> $akaunting_nginx_site
431
-    echo '  }' >> $akaunting_nginx_site
432
-    echo '' >> $akaunting_nginx_site
433
-    echo '  location / {' >> $akaunting_nginx_site
419
+    nginx_disable_sniffing "$AKAUNTING_DOMAIN_NAME"
420
+    { echo '';
421
+      echo '  access_log /dev/null;';
422
+      echo '  error_log /dev/null;';
423
+      echo '';
424
+      echo "  root /var/www/$AKAUNTING_DOMAIN_NAME/htdocs;";
425
+      echo '';
426
+      echo '  index index.php;';
427
+      echo '';
428
+      echo '  location ~ \.php {';
429
+      echo '    include snippets/fastcgi-php.conf;';
430
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
431
+      echo '    fastcgi_read_timeout 30;';
432
+      echo '  }';
433
+      echo '';
434
+      echo '  location / {'; } >> "$akaunting_nginx_site"
434 435
     function_check nginx_limits
435
-    nginx_limits $AKAUNTING_DOMAIN_NAME '15m'
436
-    echo '    try_files $uri $uri/ @akaunting;' >> $akaunting_nginx_site
437
-    echo '  }' >> $akaunting_nginx_site
438
-    echo '' >> $akaunting_nginx_site
439
-    echo '  location @akaunting {' >> $akaunting_nginx_site
440
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $akaunting_nginx_site
441
-    echo '  }' >> $akaunting_nginx_site
442
-    echo '' >> $akaunting_nginx_site
443
-    echo '  location ~ /\.(ht|git) {' >> $akaunting_nginx_site
444
-    echo '    deny all;' >> $akaunting_nginx_site
445
-    echo '  }' >> $akaunting_nginx_site
446
-    echo '}' >> $akaunting_nginx_site
436
+    nginx_limits "$AKAUNTING_DOMAIN_NAME" '15m'
437
+    { echo "    try_files \$uri \$uri/ @akaunting;";
438
+      echo '  }';
439
+      echo '';
440
+      echo '  location @akaunting {';
441
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
442
+      echo '  }';
443
+      echo '';
444
+      echo '  location ~ /\.(ht|git) {';
445
+      echo '    deny all;';
446
+      echo '  }';
447
+      echo '}'; } >> "$akaunting_nginx_site"
447 448
 
448 449
     function_check configure_php
449 450
     configure_php
450 451
 
451 452
     function_check create_site_certificate
452
-    create_site_certificate $AKAUNTING_DOMAIN_NAME 'yes'
453
+    create_site_certificate "$AKAUNTING_DOMAIN_NAME" 'yes'
453 454
 
454 455
     function_check nginx_ensite
455
-    nginx_ensite $AKAUNTING_DOMAIN_NAME
456
+    nginx_ensite "$AKAUNTING_DOMAIN_NAME"
456 457
 
457 458
     akaunting_remove_bad_links
458 459
 
@@ -460,7 +461,7 @@ function install_akaunting {
460 461
     systemctl restart php7.0-fpm
461 462
     systemctl restart nginx
462 463
 
463
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a akaunting -p "$AKAUNTING_ADMIN_PASSWORD"
464
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a akaunting -p "$AKAUNTING_ADMIN_PASSWORD"
464 465
 
465 466
     set_completion_param "akaunting domain" "$AKAUNTING_DOMAIN_NAME"
466 467
 

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

@@ -53,7 +53,7 @@ function install_interactive_batman {
53 53
 }
54 54
 
55 55
 function configure_firewall_for_batman {
56
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
56
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
57 57
         return
58 58
     fi
59 59
     if [[ $ENABLE_BATMAN != "yes" ]]; then
@@ -62,7 +62,7 @@ function configure_firewall_for_batman {
62 62
 
63 63
     function_check save_firewall_settings
64 64
     save_firewall_settings
65
-    mark_completed $FUNCNAME
65
+    mark_completed "${FUNCNAME[0]}"
66 66
 }
67 67
 
68 68
 function reconfigure_batman {
@@ -90,8 +90,7 @@ function restore_remote_batman {
90 90
 }
91 91
 
92 92
 function remove_batman {
93
-    ${PROJECT_NAME}-mesh-install -f batman --remove yes
94
-    if [ ! "$?" = "0" ]; then
93
+    if ! "${PROJECT_NAME}-mesh-install" -f batman --remove yes; then
95 94
         echo $'Failed to remove batman'
96 95
         exit 79353
97 96
     fi
@@ -100,45 +99,46 @@ function remove_batman {
100 99
 }
101 100
 
102 101
 function mesh_install_batman {
102
+    # shellcheck disable=SC2154
103 103
     chroot "$rootdir" apt-get -yq install iproute bridge-utils libnetfilter-conntrack3 batctl
104 104
     chroot "$rootdir" apt-get -yq install python-dev libevent-dev ebtables python-pip git
105 105
     chroot "$rootdir" apt-get -yq install wireless-tools rfkill
106 106
 
107
-    if ! grep -q "batman_adv" $rootdir/etc/modules; then
108
-        echo 'batman_adv' >> $rootdir/etc/modules
107
+    if ! grep -q "batman_adv" "$rootdir/etc/modules"; then
108
+        echo 'batman_adv' >> "$rootdir/etc/modules"
109 109
     fi
110 110
 
111 111
     BATMAN_SCRIPT=$rootdir/var/lib/batman
112 112
 
113
-    if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
114
-        cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
113
+    if [ -f "/usr/local/bin/${PROJECT_NAME}-mesh-batman" ]; then
114
+        cp "/usr/local/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
115 115
     else
116
-        cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
116
+        cp "/usr/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
117 117
     fi
118 118
 
119 119
     BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
120
-    echo '[Unit]' > $BATMAN_DAEMON
121
-    echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
122
-    echo 'After=network.target' >> $BATMAN_DAEMON
123
-    echo '' >> $BATMAN_DAEMON
124
-    echo '[Service]' >> $BATMAN_DAEMON
125
-    echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
126
-    echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
127
-    echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
128
-    echo 'Restart=on-failure' >> $BATMAN_DAEMON
129
-    echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
130
-    echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
131
-    echo '' >> $BATMAN_DAEMON
132
-    echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
133
-    echo 'TimeoutSec=300' >> $BATMAN_DAEMON
134
-    echo '' >> $BATMAN_DAEMON
135
-    echo '[Install]' >> $BATMAN_DAEMON
136
-    echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
120
+    { echo '[Unit]';
121
+      echo 'Description=B.A.T.M.A.N. Advanced';
122
+      echo 'After=network.target';
123
+      echo '';
124
+      echo '[Service]';
125
+      echo 'RemainAfterExit=yes';
126
+      echo "ExecStart=/var/lib/batman start";
127
+      echo "ExecStop=/var/lib/batman stop";
128
+      echo 'Restart=on-failure';
129
+      echo 'SuccessExitStatus=3 4';
130
+      echo 'RestartForceExitStatus=3 4';
131
+      echo '';
132
+      echo '# Allow time for the server to start/stop';
133
+      echo 'TimeoutSec=300';
134
+      echo '';
135
+      echo '[Install]';
136
+      echo 'WantedBy=multi-user.target'; } > "$BATMAN_DAEMON"
137 137
     chroot "$rootdir" systemctl enable batman
138 138
 }
139 139
 
140 140
 function install_batman {
141
-    if [ $INSTALLING_MESH ]; then
141
+    if [ "$INSTALLING_MESH" ]; then
142 142
         mesh_install_batman
143 143
         return
144 144
     fi
@@ -146,8 +146,7 @@ function install_batman {
146 146
         return
147 147
     fi
148 148
 
149
-    ${PROJECT_NAME}-mesh-install -f batman
150
-    if [ ! "$?" = "0" ]; then
149
+    if ! "${PROJECT_NAME}-mesh-install" -f batman; then
151 150
         echo $'Failed to install batman'
152 151
         exit 72524
153 152
     fi

+ 127
- 127
src/freedombone-app-bdsmail Просмотреть файл

@@ -49,29 +49,29 @@ function bdsmail_configure_users {
49 49
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
50 50
 
51 51
             # Add the user to the i2p group
52
-            usermod -a -G i2psvc $USERNAME
52
+            usermod -a -G i2psvc "$USERNAME"
53 53
 
54
-            if [ -f /home/$USERNAME/.muttrc ]; then
54
+            if [ -f "/home/$USERNAME/.muttrc" ]; then
55 55
                 # Create a mutt i2p folder
56
-                if ! grep -q ' =i2p' /home/$USERNAME/.muttrc; then
57
-                    MUTT_MAILBOXES=$(grep "mailboxes =" /home/$USERNAME/.muttrc)
58
-                    sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =i2p|g" /home/$USERNAME/.muttrc
56
+                if ! grep -q ' =i2p' "/home/$USERNAME/.muttrc"; then
57
+                    MUTT_MAILBOXES=$(grep "mailboxes =" "/home/$USERNAME/.muttrc")
58
+                    sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =i2p|g" "/home/$USERNAME/.muttrc"
59 59
                 fi
60 60
 
61 61
                 # Create a mutt folder hook to the i2p config
62
-                if ! grep -q 'folder-hook !i2p' /home/$USERNAME/.muttrc; then
63
-                    echo 'folder-hook !i2p/*     source ~/.muttrc' >> /home/$USERNAME/.muttrc
62
+                if ! grep -q 'folder-hook !i2p' "/home/$USERNAME/.muttrc"; then
63
+                    echo 'folder-hook !i2p/*     source ~/.muttrc' >> "/home/$USERNAME/.muttrc"
64 64
                 fi
65
-                if ! grep -q 'folder-hook i2p' /home/$USERNAME/.muttrc; then
66
-                    echo 'folder-hook i2p/*     source ~/.mutt/bdsmail' >> /home/$USERNAME/.muttrc
65
+                if ! grep -q 'folder-hook i2p' "/home/$USERNAME/.muttrc"; then
66
+                    echo 'folder-hook i2p/*     source ~/.mutt/bdsmail' >> "/home/$USERNAME/.muttrc"
67 67
                 fi
68 68
             fi
69 69
 
70 70
             # Create a directory where i2p mail will be stored
71
-            if [ ! -d /home/$USERNAME/Maildir/i2p/new ]; then
72
-                mkdir -p /home/$USERNAME/Maildir/i2p/cur
73
-                mkdir -p /home/$USERNAME/Maildir/i2p/new
74
-                chown -R $USERNAME:$USERNAME /home/$USERNAME/Maildir/i2p
71
+            if [ ! -d "/home/$USERNAME/Maildir/i2p/new" ]; then
72
+                mkdir -p "/home/$USERNAME/Maildir/i2p/cur"
73
+                mkdir -p "/home/$USERNAME/Maildir/i2p/new"
74
+                chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/Maildir/i2p"
75 75
             fi
76 76
         fi
77 77
     done
@@ -93,18 +93,18 @@ function add_user_bdsmail {
93 93
     new_username="$1"
94 94
     new_user_password="$2"
95 95
 
96
-    if [ ! -d /home/$new_username/.mutt ]; then
97
-        mkdir /home/$new_username/.mutt
98
-        cp /etc/skel/.mutt/bdsmail /home/$new_username/.mutt
96
+    if [ ! -d "/home/$new_username/.mutt" ]; then
97
+        mkdir "/home/$new_username/.mutt"
98
+        cp /etc/skel/.mutt/bdsmail "/home/$new_username/.mutt"
99 99
     fi
100 100
     read_config_param MY_USERNAME
101
-    BDSMAIL_PASSWORD=$(${PROJECT_NAME}-pass -u $MY_USERNAME -a bdsmail)
102
-    sed -i "s|username|$new_username|g" /home/$new_username/.mutt/bdsmail
103
-    sed -i "s|password|$BDSMAIL_PASSWORD|g" /home/$new_username/.mutt/bdsmail
101
+    BDSMAIL_PASSWORD=$("${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a bdsmail)
102
+    sed -i "s|username|$new_username|g" "/home/$new_username/.mutt/bdsmail"
103
+    sed -i "s|password|$BDSMAIL_PASSWORD|g" "/home/$new_username/.mutt/bdsmail"
104 104
     bdsmail_configure_users
105
-    cd $BDSMAIL_DIR
106
-    $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini $new_username /home/$new_username/Maildir/i2p "$BDSMAIL_PASSWORD"
107
-    chown -R $new_username:$new_username /home/$new_username/.mutt
105
+    cd $BDSMAIL_DIR || exit 57247684234
106
+    $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini "$new_username" "/home/$new_username/Maildir/i2p" "$BDSMAIL_PASSWORD"
107
+    chown -R "$new_username":"$new_username" "/home/$new_username/.mutt"
108 108
     echo '0'
109 109
 }
110 110
 
@@ -117,16 +117,16 @@ function change_password_bdsmail {
117 117
     curr_username="$1"
118 118
     new_user_password="$2"
119 119
 
120
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a bdsmail -p "$new_user_password"
120
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a bdsmail -p "$new_user_password"
121 121
 
122 122
     for d in /home/*/ ; do
123 123
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
124 124
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
125
-            sed -i "s|set smtp_url=.*|set smtp_url=smtp://${curr_username}:${new_user_password}@127.0.0.1:$I2P_SMTP_PORT/" /home/${USERNAME}/.mutt/bdsmail
126
-            sed -i "s|set from=.*|set from=${USERNAME}@$(bdsmail_domain)|g" /home/${USERNAME}/.mutt/bdsmail
127
-            chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.mutt/bdsmail
128
-            cd $BDSMAIL_DIR
129
-            $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini $curr_username /home/$curr_username/Maildir/i2p "$new_user_password"
125
+            sed -i "s|set smtp_url=.*|set smtp_url=smtp://${curr_username}:${new_user_password}@127.0.0.1:$I2P_SMTP_PORT/" "/home/${USERNAME}/.mutt/bdsmail"
126
+            sed -i "s|set from=.*|set from=${USERNAME}@$(bdsmail_domain)|g" "/home/${USERNAME}/.mutt/bdsmail"
127
+            chown "${USERNAME}":"${USERNAME}" "/home/${USERNAME}/.mutt/bdsmail"
128
+            cd $BDSMAIL_DIR || exit 2468246
129
+            $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini "$curr_username" "/home/$curr_username/Maildir/i2p" "$new_user_password"
130 130
         fi
131 131
     done
132 132
 }
@@ -136,9 +136,9 @@ function bdsmail_update_domain {
136 136
     for d in /home/*/ ; do
137 137
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
138 138
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
139
-            cp /etc/skel/.mutt/bdsmail /home/${USERNAME}/.mutt/bdsmail
140
-            sed -i "s|set from=.*|set from=${USERNAME}@$(bdsmail_domain)|g" /home/${USERNAME}/.mutt/bdsmail
141
-            chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.mutt/bdsmail
139
+            cp /etc/skel/.mutt/bdsmail "/home/${USERNAME}/.mutt/bdsmail"
140
+            sed -i "s|set from=.*|set from=${USERNAME}@$(bdsmail_domain)|g" "/home/${USERNAME}/.mutt/bdsmail"
141
+            chown "${USERNAME}":"${USERNAME}" "/home/${USERNAME}/.mutt/bdsmail"
142 142
         fi
143 143
     done
144 144
 }
@@ -154,7 +154,7 @@ function bdsmail_wait_for_key_generation {
154 154
         sleep 30
155 155
         bds_domain=$(bdsmail_domain)
156 156
         sleep_ctr=$((sleep_ctr + 1))
157
-        if [ $sleep_ctr -gt 100 ]; then
157
+        if [ "$sleep_ctr" -gt 100 ]; then
158 158
             break
159 159
         fi
160 160
     done
@@ -178,9 +178,9 @@ function upgrade_bdsmail {
178 178
     fi
179 179
 
180 180
     # update to the next commit
181
-    set_repo_commit $BDSMAIL_DIR "bdsmail commit" "$BDSMAIL_COMMIT" $BDSMAIL_REPO
182
-    cd $BDSMAIL_DIR
183
-    make GOROOT=/home/go/go${GO_VERSION}
181
+    set_repo_commit $BDSMAIL_DIR "bdsmail commit" "$BDSMAIL_COMMIT" "$BDSMAIL_REPO"
182
+    cd $BDSMAIL_DIR || exit 2457245
183
+    make GOROOT="/home/go/go${GO_VERSION}"
184 184
     chown -R i2psvc:i2psvc $BDSMAIL_DIR
185 185
     systemctl restart bdsmail
186 186
 
@@ -210,7 +210,7 @@ function restore_local_bdsmail {
210 210
     function_check restore_directory_from_usb
211 211
     restore_directory_from_usb $temp_restore_dir bdsmail
212 212
     if [ -d $temp_restore_dir ]; then
213
-        if [ -d cp $temp_restore_dir$bdsmail_dir ]; then
213
+        if [ -d $temp_restore_dir$bdsmail_dir ]; then
214 214
             cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
215 215
         else
216 216
             if [ ! -d $bdsmail_dir ]; then
@@ -246,7 +246,7 @@ function restore_remote_bdsmail {
246 246
     function_check restore_directory_from_friend
247 247
     restore_directory_from_friend $temp_restore_dir bdsmail
248 248
     if [ -d $temp_restore_dir ]; then
249
-        if [ -d cp $temp_restore_dir$bdsmail_dir ]; then
249
+        if [ -d $temp_restore_dir$bdsmail_dir ]; then
250 250
             cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
251 251
         else
252 252
             if [ ! -d $bdsmail_dir ]; then
@@ -272,33 +272,33 @@ function remove_bdsmail {
272 272
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
273 273
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
274 274
             # remove the user from the i2p group
275
-            deluser $USERNAME i2psvc
275
+            deluser "$USERNAME" i2psvc
276 276
 
277 277
             # Remove mutt folder hook to the i2p config
278
-            if [ -f /home/$USERNAME/.muttrc ]; then
279
-                if grep -q 'folder-hook !i2p' /home/$USERNAME/.muttrc; then
280
-                    sed -i '/folder-hook !i2p/d' /home/$USERNAME/.muttrc
278
+            if [ -f "/home/$USERNAME/.muttrc" ]; then
279
+                if grep -q 'folder-hook !i2p' "/home/$USERNAME/.muttrc"; then
280
+                    sed -i '/folder-hook !i2p/d' "/home/$USERNAME/.muttrc"
281 281
                 fi
282
-                if grep -q 'folder-hook i2p' /home/$USERNAME/.muttrc; then
283
-                    sed -i '/folder-hook i2p/d' /home/$USERNAME/.muttrc
282
+                if grep -q 'folder-hook i2p' "/home/$USERNAME/.muttrc"; then
283
+                    sed -i '/folder-hook i2p/d' "/home/$USERNAME/.muttrc"
284 284
                 fi
285 285
             fi
286 286
 
287 287
             # Remove folder
288
-            if grep -q ' =i2p' /home/$USERNAME/.muttrc; then
289
-                sed -i 's| =i2p||g' /home/$USERNAME/.muttrc
288
+            if grep -q ' =i2p' "/home/$USERNAME/.muttrc"; then
289
+                sed -i 's| =i2p||g' "/home/$USERNAME/.muttrc"
290 290
             fi
291 291
 
292 292
             # NOTE: leave Maildir/i2p/cur. We might want to archive that
293 293
             # or just be reinstalling the system without losing mail
294
-            rm -rf /home/$USERNAME/Maildir/i2p/new
294
+            rm -rf "/home/$USERNAME/Maildir/i2p/new"
295 295
         fi
296 296
     done
297 297
 
298 298
     remove_i2p
299 299
     remove_app bdsmail
300 300
     remove_completion_param install_bdsmail
301
-    sed -i '/bdsmail/d' $COMPLETION_FILE
301
+    sed -i '/bdsmail/d' "$COMPLETION_FILE"
302 302
     rm -rf /etc/skel/.mutt
303 303
     if [ -d $BDSMAIL_DIR ]; then
304 304
         rm -rf $BDSMAIL_DIR
@@ -319,10 +319,10 @@ function install_bdsmail {
319 319
     if [ -d /repos/bdsmail ]; then
320 320
         mkdir $BDSMAIL_DIR
321 321
         cp -r -p /repos/bdsmail/. $BDSMAIL_DIR
322
-        cd $BDSMAIL_DIR
322
+        cd $BDSMAIL_DIR || exit 24687246
323 323
         git pull
324 324
     else
325
-        git_clone $BDSMAIL_REPO $BDSMAIL_DIR
325
+        git_clone "$BDSMAIL_REPO" "$BDSMAIL_DIR"
326 326
     fi
327 327
 
328 328
     if [ ! -d $BDSMAIL_DIR ]; then
@@ -330,14 +330,14 @@ function install_bdsmail {
330 330
         exit 5735735
331 331
     fi
332 332
 
333
-    cd $BDSMAIL_DIR
334
-    git checkout $BDSMAIL_COMMIT -b $BDSMAIL_COMMIT
333
+    cd $BDSMAIL_DIR || exit 2468246
334
+    git checkout "$BDSMAIL_COMMIT" -b "$BDSMAIL_COMMIT"
335 335
     set_completion_param "bdsmail commit" "$BDSMAIL_COMMIT"
336 336
 
337 337
     mkdir -p $BDSMAIL_DIR/Maildir/i2p
338 338
     chmod -R 700 $BDSMAIL_DIR/Maildir
339 339
 
340
-    make GOROOT=/home/go/go${GO_VERSION}
340
+    make GOROOT="/home/go/go${GO_VERSION}"
341 341
     if [ ! -f $BDSMAIL_DIR/bin/bdsconfig ]; then
342 342
         echo $'Unable to make bdsmail'
343 343
         exit 87923567842
@@ -347,72 +347,72 @@ function install_bdsmail {
347 347
     i2p_enable_sam
348 348
 
349 349
     # create configuration file
350
-    $BDSMAIL_DIR/bin/bdsconfig > $BDSMAIL_DIR/config.ini
351
-    echo '[maild]' > $BDSMAIL_DIR/config.ini
352
-    echo "i2paddr = 127.0.0.1:$I2P_SAM_PORT" >> $BDSMAIL_DIR/config.ini
353
-    echo 'i2pkeyfile = bdsmail-privkey.dat' >> $BDSMAIL_DIR/config.ini
354
-    echo "bindmail = 127.0.0.1:$I2P_SMTP_PORT" >> $BDSMAIL_DIR/config.ini
355
-    echo "bindweb = 127.0.0.1:$I2P_WEB_PORT" >> $BDSMAIL_DIR/config.ini
356
-    echo "bindpop3 = 127.0.0.1:$I2P_POP3_PORT" >> $BDSMAIL_DIR/config.ini
357
-    echo 'domain = localhost' >> $BDSMAIL_DIR/config.ini
358
-    echo 'maildir = Maildir/i2p' >> $BDSMAIL_DIR/config.ini
359
-    echo 'database = localhost.sqlite' >> $BDSMAIL_DIR/config.ini
360
-    echo 'assets = contrib/assets/web' >> $BDSMAIL_DIR/config.ini
361
-
362
-    echo '[Unit]' > /etc/systemd/system/bdsmail.service
363
-    echo 'Description=bdsmail' >> /etc/systemd/system/bdsmail.service
364
-    echo 'After=syslog.target' >> /etc/systemd/system/bdsmail.service
365
-    echo 'After=network.target' >> /etc/systemd/system/bdsmail.service
366
-    echo '' >> /etc/systemd/system/bdsmail.service
367
-    echo '[Service]' >> /etc/systemd/system/bdsmail.service
368
-    echo 'Type=simple' >> /etc/systemd/system/bdsmail.service
369
-    echo 'User=i2psvc' >> /etc/systemd/system/bdsmail.service
370
-    echo 'Group=i2psvc' >> /etc/systemd/system/bdsmail.service
371
-    echo "WorkingDirectory=$BDSMAIL_DIR" >> /etc/systemd/system/bdsmail.service
372
-    echo "ExecStart=$BDSMAIL_DIR/bin/maild $BDSMAIL_DIR/config.ini" >> /etc/systemd/system/bdsmail.service
373
-    echo 'Restart=always' >> /etc/systemd/system/bdsmail.service
374
-    echo 'Environment="USER=i2psvc"' >> /etc/systemd/system/bdsmail.service
375
-    echo '' >> /etc/systemd/system/bdsmail.service
376
-    echo '[Install]' >> /etc/systemd/system/bdsmail.service
377
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/bdsmail.service
378
-
379
-    echo '#!/usr/bin/env python2' > $BDSMAIL_DIR/get_address
380
-    echo 'import base64, hashlib, sys' >> $BDSMAIL_DIR/get_address
381
-    echo 'with open(sys.argv[1]) as f:' >> $BDSMAIL_DIR/get_address
382
-    echo "    print(base64.b32encode(hashlib.sha256(base64.b64decode(f.read(516), '-~')).digest()).strip('=')+\".b32.i2p\")" >> $BDSMAIL_DIR/get_address
350
+    #$BDSMAIL_DIR/bin/bdsconfig > $BDSMAIL_DIR/config.ini
351
+    { echo '[maild]':
352
+      echo "i2paddr = 127.0.0.1:$I2P_SAM_PORT";
353
+      echo 'i2pkeyfile = bdsmail-privkey.dat';
354
+      echo "bindmail = 127.0.0.1:$I2P_SMTP_PORT";
355
+      echo "bindweb = 127.0.0.1:$I2P_WEB_PORT";
356
+      echo "bindpop3 = 127.0.0.1:$I2P_POP3_PORT";
357
+      echo 'domain = localhost';
358
+      echo 'maildir = Maildir/i2p';
359
+      echo 'database = localhost.sqlite';
360
+      echo 'assets = contrib/assets/web'; } > $BDSMAIL_DIR/config.ini
361
+
362
+    { echo '[Unit]';
363
+      echo 'Description=bdsmail';
364
+      echo 'After=syslog.target';
365
+      echo 'After=network.target';
366
+      echo '';
367
+      echo '[Service]';
368
+      echo 'Type=simple';
369
+      echo 'User=i2psvc';
370
+      echo 'Group=i2psvc';
371
+      echo "WorkingDirectory=$BDSMAIL_DIR";
372
+      echo "ExecStart=$BDSMAIL_DIR/bin/maild $BDSMAIL_DIR/config.ini";
373
+      echo 'Restart=always';
374
+      echo 'Environment="USER=i2psvc"';
375
+      echo '';
376
+      echo '[Install]';
377
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/bdsmail.service
378
+
379
+    { echo '#!/usr/bin/env python2';
380
+      echo 'import base64, hashlib, sys';
381
+      echo 'with open(sys.argv[1]) as f:';
382
+      echo "    print(base64.b32encode(hashlib.sha256(base64.b64decode(f.read(516), '-~')).digest()).strip('=')+\".b32.i2p\")"; } > $BDSMAIL_DIR/get_address
383 383
     chmod +x $BDSMAIL_DIR/get_address
384 384
 
385 385
     chown -R i2psvc:i2psvc $BDSMAIL_DIR
386 386
     systemctl enable bdsmail
387 387
     systemctl start bdsmail
388 388
 
389
-    echo '#!/bin/bash' > /usr/bin/bdsmail_distribute
390
-    echo "BDSMAIL_DIR=$BDSMAIL_DIR" >> /usr/bin/bdsmail_distribute
391
-    echo "MAIL_DIR=\$BDSMAIL_DIR/\$(cat \$BDSMAIL_DIR/config.ini | grep 'maildir =' | awk -F ' ' '{print \$3}')" >> /usr/bin/bdsmail_distribute
392
-    echo 'if [ ! -d $MAIL_DIR/postmaster/new ]; then' >> /usr/bin/bdsmail_distribute
393
-    echo '    exit 0' >> /usr/bin/bdsmail_distribute
394
-    echo 'fi' >> /usr/bin/bdsmail_distribute
395
-    echo 'for filename in $MAIL_DIR/postmaster/new/*; do' >> /usr/bin/bdsmail_distribute
396
-    echo '    to_line=$(cat $filename | grep "To: " | head -n 1)' >> /usr/bin/bdsmail_distribute
397
-    echo "    to_username=\$(echo \"\$to_line\" | awk -F ' ' '{print \$2}' | awk -F '@' '{print \$1}')" >> /usr/bin/bdsmail_distribute
398
-    echo '    if [ -d /home/$to_username/Maildir/i2p/new ]; then' >> /usr/bin/bdsmail_distribute
399
-    echo '        chown $to_username:$to_username $filename' >> /usr/bin/bdsmail_distribute
400
-    echo '        chmod 600 $filename' >> /usr/bin/bdsmail_distribute
401
-    echo '        mv $filename /home/$to_username/Maildir/i2p/new' >> /usr/bin/bdsmail_distribute
402
-    echo '    fi' >> /usr/bin/bdsmail_distribute
403
-    echo 'done' >> /usr/bin/bdsmail_distribute
389
+    { echo '#!/bin/bash';
390
+      echo "BDSMAIL_DIR=$BDSMAIL_DIR";
391
+      echo "MAIL_DIR=\$BDSMAIL_DIR/\$(cat \$BDSMAIL_DIR/config.ini | grep 'maildir =' | awk -F ' ' '{print \$3}')";
392
+      echo "if [ ! -d \$MAIL_DIR/postmaster/new ]; then";
393
+      echo '    exit 0';
394
+      echo 'fi';
395
+      echo "for filename in \$MAIL_DIR/postmaster/new/*; do";
396
+      echo "    to_line=\$(cat \$filename | grep \"To: \" | head -n 1)";
397
+      echo "    to_username=\$(echo \"\$to_line\" | awk -F ' ' '{print \$2}' | awk -F '@' '{print \$1}')";
398
+      echo "    if [ -d /home/\$to_username/Maildir/i2p/new ]; then";
399
+      echo "        chown \$to_username:\$to_username \$filename";
400
+      echo "        chmod 600 \$filename";
401
+      echo "        mv \$filename /home/\$to_username/Maildir/i2p/new";
402
+      echo '    fi';
403
+      echo 'done'; } > /usr/bin/bdsmail_distribute
404 404
     chmod +x /usr/bin/bdsmail_distribute
405 405
 
406 406
     if ! grep -q 'bdsmail_distribute' /etc/crontab; then
407 407
         cron_add_mins 1 '/usr/bin/bdsmail_distribute 2> /dev/null'
408 408
     fi
409 409
 
410
-    echo '#!/bin/bash' > /usr/bin/bdsmail_domain
411
-    echo "cd $BDSMAIL_DIR" >> /usr/bin/bdsmail_domain
412
-    echo 'if [ ! -f bdsmail-privkey.dat ]; then' >> /usr/bin/bdsmail_domain
413
-    echo '    exit 1' >> /usr/bin/bdsmail_domain
414
-    echo 'fi' >> /usr/bin/bdsmail_domain
415
-    echo "python2 get_address bdsmail-privkey.dat | tr '[:upper:]' '[:lower:]'" >> /usr/bin/bdsmail_domain
410
+    { echo '#!/bin/bash';
411
+      echo "cd $BDSMAIL_DIR";
412
+      echo 'if [ ! -f bdsmail-privkey.dat ]; then';
413
+      echo '    exit 1';
414
+      echo 'fi';
415
+      echo "python2 get_address bdsmail-privkey.dat | tr '[:upper:]' '[:lower:]'"; } > /usr/bin/bdsmail_domain
416 416
     chmod +x /usr/bin/bdsmail_domain
417 417
 
418 418
     echo ''
@@ -422,7 +422,7 @@ function install_bdsmail {
422 422
 
423 423
     bdsmail_wait_for_key_generation
424 424
 
425
-    if [ ! $bds_domain ]; then
425
+    if [ ! "$bds_domain" ]; then
426 426
         systemctl stop bdsmail
427 427
         systemctl disable bdsmail
428 428
         remove_i2p
@@ -430,38 +430,38 @@ function install_bdsmail {
430 430
         exit 8934638
431 431
     fi
432 432
 
433
-    BDSMAIL_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
434
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a bdsmail -p "$BDSMAIL_PASSWORD"
435
-    cd $BDSMAIL_DIR
433
+    BDSMAIL_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
434
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a bdsmail -p "$BDSMAIL_PASSWORD"
435
+    cd $BDSMAIL_DIR || exit 2346872427
436 436
     $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini admin $BDSMAIL_DIR/Maildir/i2p/admin "$BDSMAIL_PASSWORD"
437 437
 
438 438
     # Create mutt configuration
439 439
     if [ ! -d /etc/skel/.mutt ]; then
440 440
         mkdir /etc/skel/.mutt
441 441
     fi
442
-    echo 'set mbox_type=Maildir' > /etc/skel/.mutt/bdsmail
443
-    echo "set smtp_url=smtp://username:password@127.0.0.1:$I2P_SMTP_PORT/" >> /etc/skel/.mutt/bdsmail
444
-    echo 'set use_from=yes' >> /etc/skel/.mutt/bdsmail
445
-    echo "set from=username@${bds_domain}" >> /etc/skel/.mutt/bdsmail
446
-    echo "set spoolfile=~/Maildir/i2p" >> /etc/skel/.mutt/bdsmail
447
-    echo 'set pgp_autoencrypt=no' >> /etc/skel/.mutt/bdsmail
448
-    echo 'set pgp_replyencrypt=no' >> /etc/skel/.mutt/bdsmail
449
-    echo 'set pgp_autosign=no' >> /etc/skel/.mutt/bdsmail
450
-    echo 'set pgp_replysign=no' >> /etc/skel/.mutt/bdsmail
442
+    { echo 'set mbox_type=Maildir';
443
+      echo "set smtp_url=smtp://username:password@127.0.0.1:$I2P_SMTP_PORT/";
444
+      echo 'set use_from=yes';
445
+      echo "set from=username@${bds_domain}";
446
+      echo "set spoolfile=~/Maildir/i2p";
447
+      echo 'set pgp_autoencrypt=no';
448
+      echo 'set pgp_replyencrypt=no';
449
+      echo 'set pgp_autosign=no';
450
+      echo 'set pgp_replysign=no'; } > /etc/skel/.mutt/bdsmail
451 451
 
452 452
     # mutt configuration for the admin user
453
-    if [ ! -d /home/$MY_USERNAME/.mutt ]; then
454
-        mkdir /home/$MY_USERNAME/.mutt
453
+    if [ ! -d "/home/$MY_USERNAME/.mutt" ]; then
454
+        mkdir "/home/$MY_USERNAME/.mutt"
455 455
     fi
456
-    cp /etc/skel/.mutt/bdsmail /home/$MY_USERNAME/.mutt
457
-    sed -i "s|username|$MY_USERNAME|g" /home/$MY_USERNAME/.mutt/bdsmail
458
-    sed -i "s|password|$BDSMAIL_PASSWORD|g" /home/$MY_USERNAME/.mutt/bdsmail
459
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt
456
+    cp /etc/skel/.mutt/bdsmail "/home/$MY_USERNAME/.mutt"
457
+    sed -i "s|username|$MY_USERNAME|g" "/home/$MY_USERNAME/.mutt/bdsmail"
458
+    sed -i "s|password|$BDSMAIL_PASSWORD|g" "/home/$MY_USERNAME/.mutt/bdsmail"
459
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.mutt"
460 460
 
461 461
     bdsmail_configure_users
462 462
 
463
-    cd $BDSMAIL_DIR
464
-    $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini $MY_USERNAME /home/$MY_USERNAME/Maildir/i2p "$BDSMAIL_PASSWORD"
463
+    cd $BDSMAIL_DIR || exit 2457245
464
+    $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini "$MY_USERNAME" "/home/$MY_USERNAME/Maildir/i2p" "$BDSMAIL_PASSWORD"
465 465
 
466 466
     APP_INSTALLED=1
467 467
 }

+ 301
- 300
src/freedombone-app-cryptpad Просмотреть файл

@@ -101,7 +101,7 @@ function upgrade_cryptpad {
101 101
     function_check set_repo_commit
102 102
     set_repo_commit $CRYPTPAD_DIR "cryptpad commit" "$CRYPTPAD_COMMIT" $CRYPTPAD_REPO
103 103
 
104
-    cd $CRYPTPAD_DIR
104
+    cd $CRYPTPAD_DIR || exit 254724
105 105
     cryptpad_create_config
106 106
     npm upgrade
107 107
     npm install
@@ -156,7 +156,7 @@ function restore_local_cryptpad {
156 156
 }
157 157
 
158 158
 function backup_remote_cryptpad {
159
-    if grep -q "cryptpad domain" $COMPLETION_FILE; then
159
+    if grep -q "cryptpad domain" "$COMPLETION_FILE"; then
160 160
         temp_backup_dir=$CRYPTPAD_DIR/datastore
161 161
         if [ -d $temp_backup_dir ]; then
162 162
             systemctl stop cryptpad
@@ -226,7 +226,7 @@ function remove_cryptpad {
226 226
     remove_onion_service cryptpad ${CRYPTPAD_ONION_PORT}
227 227
     remove_app cryptpad
228 228
     remove_completion_param install_cryptpad
229
-    sed -i '/cryptpad/d' $COMPLETION_FILE
229
+    sed -i '/cryptpad/d' "$COMPLETION_FILE"
230 230
 
231 231
     userdel -r cryptpad
232 232
 }
@@ -236,123 +236,124 @@ function cryptpad_create_config {
236 236
 
237 237
     cryptpad_prefix=
238 238
     if [[ "$cryptpad_install_type" == "mesh" ]]; then
239
-        cryptpad_prefix=$rootdir
239
+        # shellcheck disable=SC2154
240
+        cryptpad_prefix="$rootdir"
240 241
     fi
241 242
 
242
-    echo '/*@flow*/' > $cryptpad_prefix$CRYPTPAD_DIR/config.js
243
-    echo '/*' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
244
-    echo '  globals module' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
245
-    echo '*/' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
246
-    echo "var domain = ' http://localhost:${CRYPTPAD_PORT}/';" >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
247
-    echo 'module.exports = {' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
248
-    echo "        httpAddress: '::'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
249
-    echo '        httpHeaders: {' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
250
-    echo '                "X-XSS-Protection": "1; mode=block",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
251
-    echo '                "X-Content-Type-Options": "nosniff",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
252
-    echo '                "Access-Control-Allow-Origin": "*"' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
253
-    echo '        },' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
254
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
255
-    echo '        contentSecurity: [' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
256
-    echo "                \"default-src 'none'\"," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
257
-    echo "                \"style-src 'unsafe-inline' 'self' \" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
258
-    echo "                \"script-src 'self'\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
259
-    echo "                \"font-src 'self' data:\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
260
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
261
-    echo '                "child-src blob: *",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
262
-    echo '                "frame-src blob: *",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
263
-    echo '                "media-src * blob:",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
264
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
265
-    echo "                \"connect-src 'self' ws: wss: blob:\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
266
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
267
-    echo "                \"img-src 'self' data: blob:\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
268
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
269
-    echo '                "frame-ancestors *",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
270
-    echo "        ].join('; ')," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
271
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
272
-    echo '        padContentSecurity: [' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
273
-    echo "                \"default-src 'none'\"," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
274
-    echo "                \"style-src 'unsafe-inline' 'self'\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
275
-    echo "                \"script-src 'self' 'unsafe-eval' 'unsafe-inline'\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
276
-    echo "                \"font-src 'self'\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
277
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
278
-    echo '                "child-src *",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
279
-    echo '                "frame-src *",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
280
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
281
-    echo "                \"connect-src 'self' ws: wss:\" + domain," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
282
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
283
-    echo '                "img-src * blob:",' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
284
-    echo "        ].join('; ')," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
285
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
286
-    echo "        httpPort: ${CRYPTPAD_PORT}," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
287
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
288
-    echo '        // This is for allowing the cross-domain iframe to function when developing' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
289
-    echo "        httpSafePort: ${CRYPTPAD_PORT2}," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
290
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
291
-    echo "        websocketPath: '/cryptpad_websocket'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
292
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
293
-    echo '        logToStdout: false,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
294
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
295
-    echo '        verbose: false,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
296
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
297
-    echo '        mainPages: [' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
298
-    echo "                'index'" >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
299
-    echo '        ],' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
300
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
301
-    echo '        removeDonateButton: true,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
302
-    echo '        allowSubscriptions: false,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
243
+    { echo '/*@flow*/';
244
+      echo '/*';
245
+      echo '  globals module';
246
+      echo '*/';
247
+      echo "var domain = ' http://localhost:${CRYPTPAD_PORT}/';";
248
+      echo 'module.exports = {';
249
+      echo "        httpAddress: '::',";
250
+      echo '        httpHeaders: {';
251
+      echo '                "X-XSS-Protection": "1; mode=block",';
252
+      echo '                "X-Content-Type-Options": "nosniff",';
253
+      echo '                "Access-Control-Allow-Origin": "*"';
254
+      echo '        },';
255
+      echo '';
256
+      echo '        contentSecurity: [';
257
+      echo "                \"default-src 'none'\",";
258
+      echo "                \"style-src 'unsafe-inline' 'self' \" + domain,";
259
+      echo "                \"script-src 'self'\" + domain,";
260
+      echo "                \"font-src 'self' data:\" + domain,";
261
+      echo '';
262
+      echo '                "child-src blob: *",';
263
+    echo '                "frame-src blob: *",';
264
+    echo '                "media-src * blob:",';
265
+    echo '';
266
+    echo "                \"connect-src 'self' ws: wss: blob:\" + domain,";
267
+    echo '';
268
+    echo "                \"img-src 'self' data: blob:\" + domain,";
269
+    echo '';
270
+    echo '                "frame-ancestors *",';
271
+    echo "        ].join('; '),";
272
+    echo '';
273
+    echo '        padContentSecurity: [';
274
+    echo "                \"default-src 'none'\",";
275
+    echo "                \"style-src 'unsafe-inline' 'self'\" + domain,";
276
+    echo "                \"script-src 'self' 'unsafe-eval' 'unsafe-inline'\" + domain,";
277
+    echo "                \"font-src 'self'\" + domain,";
278
+    echo '';
279
+    echo '                "child-src *",';
280
+    echo '                "frame-src *",';
281
+    echo '';
282
+    echo "                \"connect-src 'self' ws: wss:\" + domain,";
283
+    echo '';
284
+    echo '                "img-src * blob:",';
285
+    echo "        ].join('; '),";
286
+    echo '';
287
+    echo "        httpPort: ${CRYPTPAD_PORT},";
288
+    echo '';
289
+    echo '        // This is for allowing the cross-domain iframe to function when developing';
290
+    echo "        httpSafePort: ${CRYPTPAD_PORT2},";
291
+    echo '';
292
+    echo "        websocketPath: '/cryptpad_websocket',";
293
+    echo '';
294
+    echo '        logToStdout: false,';
295
+    echo '';
296
+    echo '        verbose: false,';
297
+    echo '';
298
+    echo '        mainPages: [';
299
+    echo "                'index'";
300
+    echo '        ],';
301
+    echo '';
302
+    echo '        removeDonateButton: true,';
303
+    echo '        allowSubscriptions: false,'; } > "$cryptpad_prefix$CRYPTPAD_DIR/config.js"
303 304
     if [[ "$cryptpad_install_type" == "mesh" ]]; then
304
-        echo "        myDomain: 'http://P${PEER_ID}.local'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
305
+        echo "        myDomain: 'http://P${PEER_ID}.local'," >> "$cryptpad_prefix$CRYPTPAD_DIR/config.js"
305 306
     else
306 307
         CRYPTPAD_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_cryptpad/hostname)
307
-        echo "        myDomain: 'http://${CRYPTPAD_ONION_HOSTNAME}'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
308
+        echo "        myDomain: 'http://${CRYPTPAD_ONION_HOSTNAME}'," >> "$cryptpad_prefix$CRYPTPAD_DIR/config.js"
308 309
     fi
309
-    echo '        defaultStorageLimit: 50 * 1024 * 1024,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
310
-
311
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
312
-    echo '        customLimits: {' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
313
-    echo '        },' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
314
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
315
-    echo '        adminEmail: false,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
316
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
317
-    echo "        storage: './storage/file'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
318
-    echo '' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
319
-    echo "       filePath: './datastore/'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
320
-    echo "        pinPath: './pins'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
321
-    echo "        blobPath: './blob'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
322
-    echo "        blobStagingPath: './blobstage'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
323
-    echo '        channelExpirationMs: 30000,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
324
-    echo '        openFileLimit: 1024,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
325
-    echo "        rpc: './rpc.js'," >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
326
-    echo '        suppressRPCErrors: false,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
327
-    echo '        enableUploads: true,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
328
-    echo '        //restrictUploads: false,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
329
-    echo '        maxUploadSize: 20 * 1024 * 1024,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
330
-    echo '        //logFeedback: true,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
331
-    echo '        //logRPC: true,' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
332
-    echo '};' >> $cryptpad_prefix$CRYPTPAD_DIR/config.js
310
+    { echo '        defaultStorageLimit: 50 * 1024 * 1024,';
311
+      echo '';
312
+      echo '        customLimits: {';
313
+      echo '        },';
314
+      echo '';
315
+      echo '        adminEmail: false,';
316
+      echo '';
317
+      echo "        storage: './storage/file',";
318
+      echo '';
319
+      echo "       filePath: './datastore/',";
320
+      echo "        pinPath: './pins',";
321
+      echo "        blobPath: './blob',";
322
+      echo "        blobStagingPath: './blobstage',";
323
+      echo '        channelExpirationMs: 30000,';
324
+      echo '        openFileLimit: 1024,';
325
+      echo "        rpc: './rpc.js',";
326
+      echo '        suppressRPCErrors: false,';
327
+      echo '        enableUploads: true,';
328
+      echo '        //restrictUploads: false,';
329
+      echo '        maxUploadSize: 20 * 1024 * 1024,';
330
+      echo '        //logFeedback: true,';
331
+      echo '        //logRPC: true,';
332
+      echo '};'; } >> "$cryptpad_prefix$CRYPTPAD_DIR/config.js"
333 333
 
334 334
     if [[ "$cryptpad_install_type" != "mesh" ]]; then
335
-        chown cryptpad:cryptpad $cryptpad_prefix$CRYPTPAD_DIR/config.js
335
+        chown cryptpad:cryptpad "$cryptpad_prefix$CRYPTPAD_DIR/config.js"
336 336
     else
337 337
         chroot "$rootdir" chown cryptpad:cryptpad $CRYPTPAD_DIR/config.js
338 338
     fi
339 339
 }
340 340
 
341 341
 function mesh_install_cryptpad {
342
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
342
+    # shellcheck disable=SC2153
343
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
343 344
         return
344 345
     fi
345 346
 
346
-    if [ ! -d $rootdir/var/www/cryptpad ]; then
347
-        mkdir $rootdir/var/www/cryptpad
347
+    if [ ! -d "$rootdir/var/www/cryptpad" ]; then
348
+        mkdir "$rootdir/var/www/cryptpad"
348 349
     fi
349
-    if [ -d $rootdir$CRYPTPAD_DIR ]; then
350
-        rm -rf $rootdir$CRYPTPAD_DIR
350
+    if [ -d "$rootdir$CRYPTPAD_DIR" ]; then
351
+        rm -rf "$rootdir$CRYPTPAD_DIR"
351 352
     fi
352 353
 
353
-    git_clone $CRYPTPAD_REPO $rootdir$CRYPTPAD_DIR
354
+    git_clone "$CRYPTPAD_REPO" "$rootdir$CRYPTPAD_DIR"
354 355
 
355
-    if [ ! -d $rootdir$CRYPTPAD_DIR ]; then
356
+    if [ ! -d "$rootdir$CRYPTPAD_DIR" ]; then
356 357
         echo $'Unable to clone cryptpad repo'
357 358
         exit 783251
358 359
     fi
@@ -360,94 +361,94 @@ function mesh_install_cryptpad {
360 361
     # an unprivileged user to run as
361 362
     chroot "$rootdir" useradd -d $CRYPTPAD_DIR/ cryptpad
362 363
 
363
-    cd $rootdir$CRYPTPAD_DIR
364
-    git checkout $CRYPTPAD_COMMIT -b $CRYPTPAD_COMMIT
364
+    cd "$rootdir$CRYPTPAD_DIR" || exit 34683568
365
+    git checkout "$CRYPTPAD_COMMIT" -b "$CRYPTPAD_COMMIT"
365 366
 
366 367
     chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
367 368
 
368 369
     cryptpad_nginx_site=$rootdir/etc/nginx/sites-available/cryptpad
369
-    echo 'server {' > $cryptpad_nginx_site
370
-    echo "  listen 80 default_server;" >> $cryptpad_nginx_site
371
-    echo "  server_name P${PEER_ID}.local;" >> $cryptpad_nginx_site
372
-    echo '' >> $cryptpad_nginx_site
373
-    echo '  # Logs' >> $cryptpad_nginx_site
374
-    echo '  access_log /dev/null;' >> $cryptpad_nginx_site
375
-    echo '  error_log /dev/null;' >> $cryptpad_nginx_site
376
-    echo '' >> $cryptpad_nginx_site
377
-    echo '  # Root' >> $cryptpad_nginx_site
378
-    echo "  root $CRYPTPAD_DIR;" >> $cryptpad_nginx_site
379
-    echo '' >> $cryptpad_nginx_site
380
-    echo '  index index.html;' >> $cryptpad_nginx_site
381
-    echo '' >> $cryptpad_nginx_site
382
-    echo '  add_header X-XSS-Protection "1; mode=block";' >> $cryptpad_nginx_site
383
-    echo '  add_header X-Content-Type-Options nosniff;' >> $cryptpad_nginx_site
384
-    echo '  add_header X-Frame-Options SAMEORIGIN;' >> $cryptpad_nginx_site
385
-    echo '' >> $cryptpad_nginx_site
386
-    echo '  if ($uri = /pad/inner.html) {' >> $cryptpad_nginx_site
387
-    echo "    set \$scriptSrc \"'self' 'unsafe-eval' 'unsafe-inline'\";" >> $cryptpad_nginx_site
388
-    echo '  }' >> $cryptpad_nginx_site
389
-    echo '' >> $cryptpad_nginx_site
390
-    echo '  location = /cryptpad_websocket {' >> $cryptpad_nginx_site
391
-    echo "    proxy_pass http://localhost:$CRYPTPAD_PORT;" >> $cryptpad_nginx_site
392
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $cryptpad_nginx_site
393
-    echo '    proxy_set_header Host $host;' >> $cryptpad_nginx_site
394
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $cryptpad_nginx_site
395
-    echo '' >> $cryptpad_nginx_site
396
-    echo '    # WebSocket support (nginx 1.4)' >> $cryptpad_nginx_site
397
-    echo '    proxy_http_version 1.1;' >> $cryptpad_nginx_site
398
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $cryptpad_nginx_site
399
-    echo '    proxy_set_header Connection upgrade;' >> $cryptpad_nginx_site
400
-    echo '  }' >> $cryptpad_nginx_site
401
-    echo '' >> $cryptpad_nginx_site
402
-
403
-    echo '  location ^~ /customize.dist/ {' >> $cryptpad_nginx_site
404
-    echo '    # This is needed in order to prevent infinite recursion between /customize/ and the root' >> $cryptpad_nginx_site
405
-    echo '  }' >> $cryptpad_nginx_site
406
-    echo '  location ^~ /customize/ {' >> $cryptpad_nginx_site
407
-    echo '    rewrite ^/customize/(.*)$ $1 break;' >> $cryptpad_nginx_site
408
-    echo '    try_files /customize/$uri /customize.dist/$uri;' >> $cryptpad_nginx_site
409
-    echo '  }' >> $cryptpad_nginx_site
410
-    echo '  location = /api/config {' >> $cryptpad_nginx_site
411
-    echo '    default_type text/javascript;' >> $cryptpad_nginx_site
412
-    echo '    rewrite ^.*$ /customize/api/config break;' >> $cryptpad_nginx_site
413
-    echo '  }' >> $cryptpad_nginx_site
414
-    echo '' >> $cryptpad_nginx_site
415
-    echo '  location ^~ /blob/ {' >> $cryptpad_nginx_site
416
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
417
-    echo '  }' >> $cryptpad_nginx_site
418
-    echo '' >> $cryptpad_nginx_site
419
-    echo '  location ^~ /register/ {' >> $cryptpad_nginx_site
420
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
421
-    echo '  }' >> $cryptpad_nginx_site
422
-    echo '' >> $cryptpad_nginx_site
423
-    echo '  location ^~ /login/ {' >> $cryptpad_nginx_site
424
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
425
-    echo '  }' >> $cryptpad_nginx_site
426
-    echo '' >> $cryptpad_nginx_site
427
-    echo '  location ^~ /about.html {' >> $cryptpad_nginx_site
428
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
429
-    echo '  }' >> $cryptpad_nginx_site
430
-    echo '' >> $cryptpad_nginx_site
431
-    echo '  location ^~ /contact.html {' >> $cryptpad_nginx_site
432
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
433
-    echo '  }' >> $cryptpad_nginx_site
434
-    echo '' >> $cryptpad_nginx_site
435
-    echo '  location ^~ /what-is-cryptpad.html {' >> $cryptpad_nginx_site
436
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
437
-    echo '  }' >> $cryptpad_nginx_site
438
-    echo '' >> $cryptpad_nginx_site
439
-    echo '  location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media)$ {' >> $cryptpad_nginx_site
440
-    echo '    rewrite ^(.*)$ $1/ redirect;' >> $cryptpad_nginx_site
441
-    echo '  }' >> $cryptpad_nginx_site
442
-    echo '' >> $cryptpad_nginx_site
443
-    echo '  try_files /www/$uri /www/$uri/index.html /customize/$uri;' >> $cryptpad_nginx_site
444
-    echo '}' >> $cryptpad_nginx_site
445
-
446
-    cd $rootdir$CRYPTPAD_DIR
370
+    { echo 'server {';
371
+      echo "  listen 80 default_server;";
372
+      echo "  server_name P${PEER_ID}.local;";
373
+      echo '';
374
+      echo '  # Logs';
375
+      echo '  access_log /dev/null;';
376
+      echo '  error_log /dev/null;';
377
+      echo '';
378
+      echo '  # Root';
379
+      echo "  root $CRYPTPAD_DIR;";
380
+      echo '';
381
+      echo '  index index.html;';
382
+      echo '';
383
+      echo '  add_header X-XSS-Protection "1; mode=block";';
384
+      echo '  add_header X-Content-Type-Options nosniff;';
385
+      echo '  add_header X-Frame-Options SAMEORIGIN;';
386
+      echo '';
387
+      echo "  if (\$uri = /pad/inner.html) {";
388
+      echo "    set \$scriptSrc \"'self' 'unsafe-eval' 'unsafe-inline'\";";
389
+      echo '  }';
390
+      echo '';
391
+      echo '  location = /cryptpad_websocket {';
392
+      echo "    proxy_pass http://localhost:$CRYPTPAD_PORT;";
393
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
394
+      echo "    proxy_set_header Host \$host;";
395
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
396
+      echo '';
397
+      echo '    # WebSocket support (nginx 1.4)';
398
+      echo '    proxy_http_version 1.1;';
399
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
400
+      echo '    proxy_set_header Connection upgrade;';
401
+      echo '  }';
402
+      echo '';
403
+
404
+      echo '  location ^~ /customize.dist/ {';
405
+      echo '    # This is needed in order to prevent infinite recursion between /customize/ and the root';
406
+      echo '  }';
407
+      echo '  location ^~ /customize/ {';
408
+      echo "    rewrite ^/customize/(.*)\$ \$1 break;";
409
+      echo "    try_files /customize/\$uri /customize.dist/\$uri;";
410
+      echo '  }';
411
+      echo '  location = /api/config {';
412
+      echo '    default_type text/javascript;';
413
+      echo '    rewrite ^.*$ /customize/api/config break;';
414
+      echo '  }';
415
+      echo '';
416
+      echo '  location ^~ /blob/ {';
417
+      echo "    try_files \$uri =404;";
418
+      echo '  }';
419
+      echo '';
420
+      echo '  location ^~ /register/ {';
421
+      echo "    try_files \$uri =404;";
422
+      echo '  }';
423
+      echo '';
424
+      echo '  location ^~ /login/ {';
425
+      echo "    try_files \$uri =404;";
426
+      echo '  }';
427
+      echo '';
428
+      echo '  location ^~ /about.html {';
429
+      echo "    try_files \$uri =404;";
430
+      echo '  }';
431
+      echo '';
432
+      echo '  location ^~ /contact.html {';
433
+      echo "    try_files \$uri =404;";
434
+      echo '  }';
435
+      echo '';
436
+      echo '  location ^~ /what-is-cryptpad.html {';
437
+      echo "    try_files \$uri =404;";
438
+      echo '  }';
439
+      echo '';
440
+      echo '  location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media)$ {';
441
+      echo "    rewrite ^(.*)\$ \$1/ redirect;";
442
+      echo '  }';
443
+      echo '';
444
+      echo "  try_files /www/\$uri /www/\$uri/index.html /customize/\$uri;";
445
+      echo '}'; } > "$cryptpad_nginx_site"
446
+
447
+    cd "$rootdir$CRYPTPAD_DIR" || exit 6246824624527
447 448
 
448 449
     get_npm_arch
449 450
 
450
-    cat <<EOF > $rootdir/usr/bin/install_cryptpad
451
+    cat <<EOF > "$rootdir/usr/bin/install_cryptpad"
451 452
 #!/bin/bash
452 453
 cd $CRYPTPAD_DIR
453 454
 npm install --arch=$NPM_ARCH --build-from-source
@@ -456,37 +457,37 @@ chown -R cryptpad:cryptpad $CRYPTPAD_DIR
456 457
 su -c 'bower install' - cryptpad
457 458
 cp config.example.js config.js
458 459
 EOF
459
-    chmod +x $rootdir/usr/bin/install_cryptpad
460
+    chmod +x "$rootdir/usr/bin/install_cryptpad"
460 461
     chroot "$rootdir" /usr/bin/install_cryptpad
461 462
 
462
-    if [ ! -f $rootdir$CRYPTPAD_DIR/config.js ]; then
463
+    if [ ! -f "$rootdir$CRYPTPAD_DIR/config.js" ]; then
463 464
         echo $'Cryptpad config file not found'
464 465
         exit 628252
465 466
     fi
466 467
 
467
-    rm $rootdir/usr/bin/install_cryptpad
468
+    rm "$rootdir/usr/bin/install_cryptpad"
468 469
 
469 470
     cryptpad_create_config mesh
470 471
 
471 472
     chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
472 473
 
473 474
     # daemon
474
-    echo '[Unit]' > $rootdir/etc/systemd/system/cryptpad.service
475
-    echo 'Description=Cryptpad' >> $rootdir/etc/systemd/system/cryptpad.service
476
-    echo 'After=syslog.target' >> $rootdir/etc/systemd/system/cryptpad.service
477
-    echo 'After=network.target' >> $rootdir/etc/systemd/system/cryptpad.service
478
-    echo '' >> $rootdir/etc/systemd/system/cryptpad.service
479
-    echo '[Service]' >> $rootdir/etc/systemd/system/cryptpad.service
480
-    echo 'User=cryptpad' >> $rootdir/etc/systemd/system/cryptpad.service
481
-    echo 'Group=cryptpad' >> $rootdir/etc/systemd/system/cryptpad.service
482
-    echo "WorkingDirectory=$CRYPTPAD_DIR" >> $rootdir/etc/systemd/system/cryptpad.service
483
-    echo "ExecStart=/usr/local/bin/node $CRYPTPAD_DIR/server.js" >> $rootdir/etc/systemd/system/cryptpad.service
484
-    echo 'Environment=PATH=/usr/bin:/usr/local/bin' >> $rootdir/etc/systemd/system/cryptpad.service
485
-    echo 'Environment=NODE_ENV=production' >> $rootdir/etc/systemd/system/cryptpad.service
486
-    echo 'Restart=on-failure' >> $rootdir/etc/systemd/system/cryptpad.service
487
-    echo '' >> $rootdir/etc/systemd/system/cryptpad.service
488
-    echo '[Install]' >> $rootdir/etc/systemd/system/cryptpad.service
489
-    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/cryptpad.service
475
+    { echo '[Unit]';
476
+      echo 'Description=Cryptpad';
477
+      echo 'After=syslog.target';
478
+      echo 'After=network.target';
479
+      echo '';
480
+      echo '[Service]';
481
+      echo 'User=cryptpad';
482
+      echo 'Group=cryptpad';
483
+      echo "WorkingDirectory=$CRYPTPAD_DIR";
484
+      echo "ExecStart=/usr/local/bin/node $CRYPTPAD_DIR/server.js";
485
+      echo 'Environment=PATH=/usr/bin:/usr/local/bin';
486
+      echo 'Environment=NODE_ENV=production';
487
+      echo 'Restart=on-failure';
488
+      echo '';
489
+      echo '[Install]';
490
+      echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/cryptpad.service"
490 491
     chroot "$rootdir" systemctl enable cryptpad.service
491 492
 }
492 493
 
@@ -505,7 +506,7 @@ function install_cryptpad_main {
505 506
     if [ -d /repos/cryptpad ]; then
506 507
         mkdir $CRYPTPAD_DIR
507 508
         cp -r -p /repos/cryptpad/. $CRYPTPAD_DIR
508
-        cd $CRYPTPAD_DIR
509
+        cd $CRYPTPAD_DIR || exit 3468356385
509 510
         git pull
510 511
     else
511 512
         function_check git_clone
@@ -520,7 +521,7 @@ function install_cryptpad_main {
520 521
     # an unprivileged user to run as
521 522
     useradd -d $CRYPTPAD_DIR/ cryptpad
522 523
 
523
-    cd $CRYPTPAD_DIR
524
+    cd $CRYPTPAD_DIR || exit 34683655
524 525
     git checkout $CRYPTPAD_COMMIT -b $CRYPTPAD_COMMIT
525 526
     set_completion_param "cryptpad commit" "$CRYPTPAD_COMMIT"
526 527
 
@@ -529,87 +530,87 @@ function install_cryptpad_main {
529 530
     CRYPTPAD_ONION_HOSTNAME=$(add_onion_service cryptpad 80 ${CRYPTPAD_ONION_PORT})
530 531
 
531 532
     cryptpad_nginx_site=/etc/nginx/sites-available/cryptpad
532
-    echo 'server {' > $cryptpad_nginx_site
533
-    echo "  listen 127.0.0.1:$CRYPTPAD_ONION_PORT default_server;" >> $cryptpad_nginx_site
534
-    echo "  server_name $CRYPTPAD_ONION_HOSTNAME;" >> $cryptpad_nginx_site
535
-    echo '' >> $cryptpad_nginx_site
536
-    echo '  # Logs' >> $cryptpad_nginx_site
537
-    echo '  access_log /dev/null;' >> $cryptpad_nginx_site
538
-    echo '  error_log /dev/null;' >> $cryptpad_nginx_site
539
-    echo '' >> $cryptpad_nginx_site
540
-    echo '  # Root' >> $cryptpad_nginx_site
541
-    echo "  root $CRYPTPAD_DIR;" >> $cryptpad_nginx_site
542
-    echo '' >> $cryptpad_nginx_site
543
-    echo '  index index.html;' >> $cryptpad_nginx_site
544
-    echo '' >> $cryptpad_nginx_site
545
-    echo '  if ($args ~ ver=) {' >> $cryptpad_nginx_site
546
-    echo '      set $cacheControl max-age=31536000;' >> $cryptpad_nginx_site
547
-    echo '  }' >> $cryptpad_nginx_site
548
-    echo '  add_header Cache-Control $cacheControl;' >> $cryptpad_nginx_site
549
-    echo '' >> $cryptpad_nginx_site
550
-    echo '  add_header X-XSS-Protection "1; mode=block";' >> $cryptpad_nginx_site
551
-    echo '  add_header X-Content-Type-Options nosniff;' >> $cryptpad_nginx_site
552
-    echo '  add_header X-Frame-Options SAMEORIGIN;' >> $cryptpad_nginx_site
553
-    echo '' >> $cryptpad_nginx_site
554
-    echo '  if ($uri = /pad/inner.html) {' >> $cryptpad_nginx_site
555
-    echo "    set \$scriptSrc \"'self' 'unsafe-eval' 'unsafe-inline'\";" >> $cryptpad_nginx_site
556
-    echo '  }' >> $cryptpad_nginx_site
557
-    echo '' >> $cryptpad_nginx_site
558
-    echo '  location = /cryptpad_websocket {' >> $cryptpad_nginx_site
559
-    echo "    proxy_pass http://localhost:$CRYPTPAD_PORT;" >> $cryptpad_nginx_site
560
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $cryptpad_nginx_site
561
-    echo '    proxy_set_header Host $host;' >> $cryptpad_nginx_site
562
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $cryptpad_nginx_site
563
-    echo '' >> $cryptpad_nginx_site
564
-    echo '    # WebSocket support (nginx 1.4)' >> $cryptpad_nginx_site
565
-    echo '    proxy_http_version 1.1;' >> $cryptpad_nginx_site
566
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $cryptpad_nginx_site
567
-    echo '    proxy_set_header Connection upgrade;' >> $cryptpad_nginx_site
568
-    echo '  }' >> $cryptpad_nginx_site
569
-    echo '' >> $cryptpad_nginx_site
570
-
571
-    echo '  location ^~ /customize.dist/ {' >> $cryptpad_nginx_site
572
-    echo '    # This is needed in order to prevent infinite recursion between /customize/ and the root' >> $cryptpad_nginx_site
573
-    echo '  }' >> $cryptpad_nginx_site
574
-    echo '  location ^~ /customize/ {' >> $cryptpad_nginx_site
575
-    echo '    rewrite ^/customize/(.*)$ $1 break;' >> $cryptpad_nginx_site
576
-    echo '    try_files /customize/$uri /customize.dist/$uri;' >> $cryptpad_nginx_site
577
-    echo '  }' >> $cryptpad_nginx_site
578
-    echo '  location = /api/config {' >> $cryptpad_nginx_site
579
-    echo '    default_type text/javascript;' >> $cryptpad_nginx_site
580
-    echo '    rewrite ^.*$ /customize/api/config break;' >> $cryptpad_nginx_site
581
-    echo '  }' >> $cryptpad_nginx_site
582
-    echo '' >> $cryptpad_nginx_site
583
-    echo '  location ^~ /blob/ {' >> $cryptpad_nginx_site
584
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
585
-    echo '  }' >> $cryptpad_nginx_site
586
-    echo '' >> $cryptpad_nginx_site
587
-    echo '  location ^~ /register/ {' >> $cryptpad_nginx_site
588
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
589
-    echo '  }' >> $cryptpad_nginx_site
590
-    echo '' >> $cryptpad_nginx_site
591
-    echo '  location ^~ /login/ {' >> $cryptpad_nginx_site
592
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
593
-    echo '  }' >> $cryptpad_nginx_site
594
-    echo '' >> $cryptpad_nginx_site
595
-    echo '  location ^~ /about.html {' >> $cryptpad_nginx_site
596
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
597
-    echo '  }' >> $cryptpad_nginx_site
598
-    echo '' >> $cryptpad_nginx_site
599
-    echo '  location ^~ /contact.html {' >> $cryptpad_nginx_site
600
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
601
-    echo '  }' >> $cryptpad_nginx_site
602
-    echo '' >> $cryptpad_nginx_site
603
-    echo '  location ^~ /what-is-cryptpad.html {' >> $cryptpad_nginx_site
604
-    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
605
-    echo '  }' >> $cryptpad_nginx_site
606
-    echo '' >> $cryptpad_nginx_site
607
-    echo '  location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media)$ {' >> $cryptpad_nginx_site
608
-    echo '    rewrite ^(.*)$ $1/ redirect;' >> $cryptpad_nginx_site
609
-    echo '  }' >> $cryptpad_nginx_site
610
-    echo '' >> $cryptpad_nginx_site
611
-    echo '  try_files /www/$uri /www/$uri/index.html /customize/$uri;' >> $cryptpad_nginx_site
612
-    echo '}' >> $cryptpad_nginx_site
533
+    { echo 'server {';
534
+      echo "  listen 127.0.0.1:$CRYPTPAD_ONION_PORT default_server;";
535
+      echo "  server_name $CRYPTPAD_ONION_HOSTNAME;";
536
+      echo '';
537
+      echo '  # Logs';
538
+      echo '  access_log /dev/null;';
539
+      echo '  error_log /dev/null;';
540
+      echo '';
541
+      echo '  # Root';
542
+      echo "  root $CRYPTPAD_DIR;";
543
+      echo '';
544
+      echo '  index index.html;';
545
+      echo '';
546
+      echo "  if (\$args ~ ver=) {";
547
+      echo "      set \$cacheControl max-age=31536000;";
548
+      echo '  }';
549
+      echo "  add_header Cache-Control \$cacheControl;";
550
+      echo '';
551
+      echo '  add_header X-XSS-Protection "1; mode=block";';
552
+      echo '  add_header X-Content-Type-Options nosniff;';
553
+      echo '  add_header X-Frame-Options SAMEORIGIN;';
554
+      echo '';
555
+      echo "  if (\$uri = /pad/inner.html) {";
556
+      echo "    set \$scriptSrc \"'self' 'unsafe-eval' 'unsafe-inline'\";";
557
+      echo '  }';
558
+      echo '';
559
+      echo '  location = /cryptpad_websocket {';
560
+      echo "    proxy_pass http://localhost:$CRYPTPAD_PORT;";
561
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
562
+      echo "    proxy_set_header Host \$host;";
563
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
564
+      echo '';
565
+      echo '    # WebSocket support (nginx 1.4)';
566
+      echo '    proxy_http_version 1.1;';
567
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
568
+      echo '    proxy_set_header Connection upgrade;';
569
+      echo '  }';
570
+      echo '';
571
+
572
+      echo '  location ^~ /customize.dist/ {';
573
+      echo '    # This is needed in order to prevent infinite recursion between /customize/ and the root';
574
+      echo '  }';
575
+      echo '  location ^~ /customize/ {';
576
+      echo "    rewrite ^/customize/(.*)\$ \$1 break;";
577
+      echo "    try_files /customize/\$uri /customize.dist/\$uri;";
578
+      echo '  }';
579
+      echo '  location = /api/config {';
580
+      echo '    default_type text/javascript;';
581
+      echo '    rewrite ^.*$ /customize/api/config break;';
582
+      echo '  }';
583
+      echo '';
584
+      echo '  location ^~ /blob/ {';
585
+      echo "    try_files \$uri =404;";
586
+      echo '  }';
587
+      echo '';
588
+      echo '  location ^~ /register/ {';
589
+      echo "    try_files \$uri =404;";
590
+      echo '  }';
591
+      echo '';
592
+      echo '  location ^~ /login/ {';
593
+      echo "    try_files \$uri =404;";
594
+      echo '  }';
595
+      echo '';
596
+      echo '  location ^~ /about.html {';
597
+      echo "    try_files \$uri =404;";
598
+      echo '  }';
599
+      echo '';
600
+      echo '  location ^~ /contact.html {';
601
+      echo "    try_files \$uri =404;";
602
+      echo '  }';
603
+      echo '';
604
+      echo '  location ^~ /what-is-cryptpad.html {';
605
+      echo "    try_files \$uri =404;";
606
+      echo '  }';
607
+      echo '';
608
+      echo '  location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media)$ {';
609
+      echo "    rewrite ^(.*)\$ \$1/ redirect;";
610
+      echo '  }';
611
+      echo '';
612
+      echo "  try_files /www/\$uri /www/\$uri/index.html /customize/\$uri;";
613
+      echo '}'; } > $cryptpad_nginx_site
613 614
 
614 615
     function_check nginx_ensite
615 616
     nginx_ensite cryptpad
@@ -623,7 +624,7 @@ function install_cryptpad {
623 624
 
624 625
     install_cryptpad_main
625 626
 
626
-    cd $CRYPTPAD_DIR
627
+    cd $CRYPTPAD_DIR || exit 35483548
627 628
 
628 629
     npm install
629 630
     npm install -g bower@1.8.0
@@ -639,22 +640,22 @@ function install_cryptpad {
639 640
     chown -R cryptpad:cryptpad $CRYPTPAD_DIR
640 641
 
641 642
     # daemon
642
-    echo '[Unit]' > /etc/systemd/system/cryptpad.service
643
-    echo 'Description=Cryptpad' >> /etc/systemd/system/cryptpad.service
644
-    echo 'After=syslog.target' >> /etc/systemd/system/cryptpad.service
645
-    echo 'After=network.target' >> /etc/systemd/system/cryptpad.service
646
-    echo '' >> /etc/systemd/system/cryptpad.service
647
-    echo '[Service]' >> /etc/systemd/system/cryptpad.service
648
-    echo 'User=cryptpad' >> /etc/systemd/system/cryptpad.service
649
-    echo 'Group=cryptpad' >> /etc/systemd/system/cryptpad.service
650
-    echo "WorkingDirectory=$CRYPTPAD_DIR" >> /etc/systemd/system/cryptpad.service
651
-    echo "ExecStart=/usr/local/bin/node $CRYPTPAD_DIR/server.js" >> /etc/systemd/system/cryptpad.service
652
-    echo 'Environment=PATH=/usr/bin:/usr/local/bin' >> /etc/systemd/system/cryptpad.service
653
-    echo 'Environment=NODE_ENV=production' >> /etc/systemd/system/cryptpad.service
654
-    echo 'Restart=on-failure' >> /etc/systemd/system/cryptpad.service
655
-    echo '' >> /etc/systemd/system/cryptpad.service
656
-    echo '[Install]' >> /etc/systemd/system/cryptpad.service
657
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/cryptpad.service
643
+    { echo '[Unit]';
644
+      echo 'Description=Cryptpad';
645
+      echo 'After=syslog.target';
646
+      echo 'After=network.target';
647
+      echo '';
648
+      echo '[Service]';
649
+      echo 'User=cryptpad';
650
+      echo 'Group=cryptpad';
651
+      echo "WorkingDirectory=$CRYPTPAD_DIR";
652
+      echo "ExecStart=/usr/local/bin/node $CRYPTPAD_DIR/server.js";
653
+      echo 'Environment=PATH=/usr/bin:/usr/local/bin';
654
+      echo 'Environment=NODE_ENV=production';
655
+      echo 'Restart=on-failure';
656
+      echo '';
657
+      echo '[Install]';
658
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/cryptpad.service
658 659
     systemctl enable cryptpad.service
659 660
     systemctl daemon-reload
660 661
     systemctl start cryptpad.service
@@ -664,7 +665,7 @@ function install_cryptpad {
664 665
     cryptpad_generate_api_config
665 666
 
666 667
     # install again
667
-    cd $CRYPTPAD_DIR
668
+    cd $CRYPTPAD_DIR || exit 73537453
668 669
     su -c 'bower install' - cryptpad
669 670
 
670 671
     systemctl restart nginx

+ 62
- 57
src/freedombone-app-dlna Просмотреть файл

@@ -49,24 +49,27 @@ function logging_off_dlna {
49 49
 function configure_interactive_dlna {
50 50
     while true
51 51
     do
52
-        data=$(tempfile 2>/dev/null)
53
-        trap "rm -f $data" 0 1 2 5 15
52
+        data=$(mktemp 2>/dev/null)
54 53
         dialog --backtitle $"Freedombone Control Panel" \
55 54
                --title $"Media Menu" \
56 55
                --radiolist $"Choose an operation:" 13 70 3 \
57 56
                1 $"Attach a drive containing playable media" off \
58 57
                2 $"Remove a drive containing playable media" off \
59
-               3 $"Exit" on 2> $data
58
+               3 $"Exit" on 2> "$data"
60 59
         sel=$?
61 60
         case $sel in
62
-            1) break;;
63
-            255) break;;
61
+            1) rm -f "$data"
62
+               break;;
63
+            255) rm -f "$data"
64
+                 break;;
64 65
         esac
65
-        case $(cat $data) in
66
+        case $(cat "$data") in
66 67
             1) attach-music;;
67 68
             2) remove-music;;
68
-            3) break;;
69
+            3) rm -f "$data"
70
+               break;;
69 71
         esac
72
+        rm -f "$data"
70 73
     done
71 74
 }
72 75
 
@@ -84,7 +87,7 @@ function upgrade_dlna {
84 87
 }
85 88
 
86 89
 function configure_firewall_for_dlna {
87
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
90
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
88 91
         return
89 92
     fi
90 93
     if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
@@ -95,23 +98,23 @@ function configure_firewall_for_dlna {
95 98
     firewall_add DLNA 1900 udp
96 99
     firewall_add DLNA 8200 tcp
97 100
 
98
-    echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /etc/avahi/services/dlna.service
99
-    echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /etc/avahi/services/dlna.service
100
-    echo '<service-group>' >> /etc/avahi/services/dlna.service
101
-    echo '  <name replace-wildcards="yes">%h DLNA</name>' >> /etc/avahi/services/dlna.service
102
-    echo '  <service>' >> /etc/avahi/services/dlna.service
103
-    echo '    <type>_dlna._tcp</type>' >> /etc/avahi/services/dlna.service
104
-    echo "    <port>8200</port>" >> /etc/avahi/services/dlna.service
105
-    echo '  </service>' >> /etc/avahi/services/dlna.service
106
-    echo '  <service>' >> /etc/avahi/services/dlna.service
107
-    echo '    <type>_dlna._udp</type>' >> /etc/avahi/services/dlna.service
108
-    echo "    <port>1900</port>" >> /etc/avahi/services/dlna.service
109
-    echo '  </service>' >> /etc/avahi/services/dlna.service
110
-    echo '</service-group>' >> /etc/avahi/services/dlna.service
101
+    { echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->';
102
+      echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">';
103
+      echo '<service-group>';
104
+      echo '  <name replace-wildcards="yes">%h DLNA</name>';
105
+      echo '  <service>';
106
+      echo '    <type>_dlna._tcp</type>';
107
+      echo "    <port>8200</port>";
108
+      echo '  </service>';
109
+      echo '  <service>';
110
+      echo '    <type>_dlna._udp</type>';
111
+      echo "    <port>1900</port>";
112
+      echo '  </service>';
113
+      echo '</service-group>'; } > /etc/avahi/services/dlna.service
111 114
 
112 115
     systemctl restart avahi-daemon
113 116
 
114
-    mark_completed $FUNCNAME
117
+    mark_completed "${FUNCNAME[0]}"
115 118
 }
116 119
 
117 120
 function backup_local_dlna {
@@ -125,7 +128,7 @@ function backup_local_dlna {
125 128
 
126 129
 function restore_local_dlna {
127 130
     if [ -d /var/cache/minidlna ]; then
128
-        if [ -d $USB_MOUNT_DLNA/backup/dlna ]; then
131
+        if [ -d "$USB_MOUNT_DLNA/backup/dlna" ]; then
129 132
             echo $"Restoring DLNA cache"
130 133
             temp_restore_dir=/root/tempdlna
131 134
             function_check restore_directory_from_usb
@@ -135,6 +138,7 @@ function restore_local_dlna {
135 138
             else
136 139
                 cp -r $temp_restore_dir/* /var/cache/minidlna/
137 140
             fi
141
+            # shellcheck disable=SC2181
138 142
             if [ ! "$?" = "0" ]; then
139 143
                 rm -rf $temp_restore_dir
140 144
                 function_check set_user_permissions
@@ -156,7 +160,7 @@ function backup_remote_dlna {
156 160
 
157 161
 function restore_remote_dlna {
158 162
     if [ -d /var/cache/minidlna ]; then
159
-        if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
163
+        if [ -d "$SERVER_DIRECTORY/backup/dlna" ]; then
160 164
             temp_restore_dir=/root/tempdlna
161 165
             function_check restore_directory_from_friend
162 166
             restore_directory_from_friend $temp_restore_dir dlna
@@ -165,6 +169,7 @@ function restore_remote_dlna {
165 169
             else
166 170
                 cp -r $temp_restore_dir/* /var/cache/minidlna/
167 171
             fi
172
+            # shellcheck disable=SC2181
168 173
             if [ ! "$?" = "0" ]; then
169 174
                 exit 982
170 175
             fi
@@ -201,7 +206,7 @@ function install_dlna_main {
201 206
         exit 55
202 207
     fi
203 208
 
204
-    if [ ! $USB_MOUNT_DLNA ]; then
209
+    if [ ! "$USB_MOUNT_DLNA" ]; then
205 210
         USB_MOUNT_DLNA=/mnt/dlna
206 211
     fi
207 212
     if [ ${#USB_MOUNT_DLNA} -eq 0 ]; then
@@ -242,7 +247,7 @@ function install_dlna_main {
242 247
     systemctl reload minidlna
243 248
 
244 249
     sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
245
-    if ! grep -q "max_user_watches" $COMPLETION_FILE; then
250
+    if ! grep -q "max_user_watches" "$COMPLETION_FILE"; then
246 251
         echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
247 252
     fi
248 253
     /sbin/sysctl -p -q
@@ -253,43 +258,43 @@ function install_dlna_main {
253 258
 }
254 259
 
255 260
 function script_for_attaching_usb_drive {
256
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
261
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
257 262
         return
258 263
     fi
259
-    echo '#!/bin/bash' > /usr/bin/attach-music
260
-    echo "source /usr/local/bin/${PROJECT_NAME}-vars" >> /usr/bin/attach-music
261
-    echo "UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*" >> /usr/bin/attach-music
262
-    echo '' >> /usr/bin/attach-music
263
-    echo 'for f in $UTILS_FILES' >> /usr/bin/attach-music
264
-    echo 'do' >> /usr/bin/attach-music
265
-    echo '    source $f' >> /usr/bin/attach-music
266
-    echo 'done' >> /usr/bin/attach-music
267
-    echo '' >> /usr/bin/attach-music
268
-    echo 'USB_DRIVE=/dev/sda1' >> /usr/bin/attach-music
269
-    echo 'detect_usb_drive' >> /usr/bin/attach-music
270
-    echo '' >> /usr/bin/attach-music
271
-    echo 'remove-music' >> /usr/bin/attach-music
272
-    echo "if [ ! -d $USB_MOUNT_DLNA ]; then" >> /usr/bin/attach-music
273
-    echo "    mkdir $USB_MOUNT_DLNA" >> /usr/bin/attach-music
274
-    echo 'fi' >> /usr/bin/attach-music
275
-    echo -n 'mount $USB_DRIVE ' >> /usr/bin/attach-music
276
-    echo "$USB_MOUNT_DLNA" >> /usr/bin/attach-music
277
-    echo "chown root:root $USB_MOUNT_DLNA" >> /usr/bin/attach-music
278
-    echo "chown -R minidlna:minidlna $USB_MOUNT_DLNA/*" >> /usr/bin/attach-music
279
-    echo 'systemctl restart minidlna' >> /usr/bin/attach-music
280
-    echo 'minidlnad -R' >> /usr/bin/attach-music
281
-    echo 'exit 0' >> /usr/bin/attach-music
264
+    { echo '#!/bin/bash';
265
+      echo "source /usr/local/bin/${PROJECT_NAME}-vars";
266
+      echo "UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*";
267
+      echo '';
268
+      echo "for f in \$UTILS_FILES";
269
+      echo 'do';
270
+      echo "    source \$f";
271
+      echo 'done';
272
+      echo '';
273
+      echo 'USB_DRIVE=/dev/sda1';
274
+      echo 'detect_usb_drive';
275
+      echo '';
276
+      echo 'remove-music';
277
+      echo "if [ ! -d $USB_MOUNT_DLNA ]; then";
278
+      echo "    mkdir $USB_MOUNT_DLNA";
279
+      echo 'fi';
280
+      echo -n "mount \$USB_DRIVE ";
281
+      echo "$USB_MOUNT_DLNA";
282
+      echo "chown root:root $USB_MOUNT_DLNA";
283
+      echo "chown -R minidlna:minidlna $USB_MOUNT_DLNA/*";
284
+      echo 'systemctl restart minidlna';
285
+      echo 'minidlnad -R';
286
+      echo 'exit 0'; } > /usr/bin/attach-music
282 287
     chmod +x /usr/bin/attach-music
283 288
 
284
-    echo '#!/bin/bash' > /usr/bin/remove-music
285
-    echo "if [ -d $USB_MOUNT_DLNA ]; then" >> /usr/bin/remove-music
286
-    echo "  umount $USB_MOUNT_DLNA" >> /usr/bin/remove-music
287
-    echo "  rm -rf $USB_MOUNT_DLNA" >> /usr/bin/remove-music
288
-    echo 'fi' >> /usr/bin/remove-music
289
-    echo 'exit 0' >> /usr/bin/remove-music
289
+    { echo '#!/bin/bash';
290
+      echo "if [ -d $USB_MOUNT_DLNA ]; then";
291
+      echo "  umount $USB_MOUNT_DLNA";
292
+      echo "  rm -rf $USB_MOUNT_DLNA";
293
+      echo 'fi';
294
+      echo 'exit 0'; } > /usr/bin/remove-music
290 295
     chmod +x /usr/bin/remove-music
291 296
 
292
-    mark_completed $FUNCNAME
297
+    mark_completed "${FUNCNAME[0]}"
293 298
 }
294 299
 
295 300
 function install_dlna {

+ 256
- 252
src/freedombone-app-dokuwiki Просмотреть файл

@@ -75,18 +75,18 @@ function change_password_dokuwiki {
75 75
     new_user_password="$2"
76 76
 
77 77
     DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
78
-    if grep -q "$curr_username:" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php; then
78
+    if grep -q "$curr_username:" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"; then
79 79
         HASHED_DOKUWIKI_PASSWORD=$(echo -n "$new_user_password" | md5sum | awk -F ' ' '{print $1}')
80
-        existing_user=$(cat /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php | grep "$curr_username:" | hean -n 1)
80
+        existing_user=$(grep "$curr_username:" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php" | hean -n 1)
81 81
         if [[ "$existing_user" == *":admin,"* ]]; then
82
-            sed -i "s|$curr_username:.*|$curr_username:$HASHED_DOKUWIKI_PASSWORD:$curr_username:$curr_username@$HOSTNAME:admin,user,upload|g" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
82
+            sed -i "s|$curr_username:.*|$curr_username:$HASHED_DOKUWIKI_PASSWORD:$curr_username:$curr_username@$HOSTNAME:admin,user,upload|g" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
83 83
         else
84
-            sed -i "s|$curr_username:.*|$curr_username:$HASHED_DOKUWIKI_PASSWORD:$curr_username:$curr_username@$HOSTNAME:user,upload|g" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
84
+            sed -i "s|$curr_username:.*|$curr_username:$HASHED_DOKUWIKI_PASSWORD:$curr_username:$curr_username@$HOSTNAME:user,upload|g" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
85 85
         fi
86
-        cp /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
87
-        chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
88
-        chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
89
-        ${PROJECT_NAME}-pass -u $curr_username -a dokuwiki -p "$new_user_password"
86
+        cp "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
87
+        chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
88
+        chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
89
+        "${PROJECT_NAME}-pass" -u "$curr_username" -a dokuwiki -p "$new_user_password"
90 90
     fi
91 91
 }
92 92
 
@@ -96,21 +96,21 @@ function add_user_dokuwiki {
96 96
 
97 97
     DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
98 98
     HASHED_DOKUWIKI_PASSWORD=$(echo -n "$new_user_password" | md5sum | awk -F ' ' '{print $1}')
99
-    echo "$new_username:$HASHED_DOKUWIKI_PASSWORD:$new_username:$new_username@$HOSTNAME:user,upload" >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
100
-    cp /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
101
-    chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
102
-    chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
103
-    ${PROJECT_NAME}-pass -u "$new_username" -a dokuwiki -p "$new_user_password"
99
+    echo "$new_username:$HASHED_DOKUWIKI_PASSWORD:$new_username:$new_username@$HOSTNAME:user,upload" >> "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
100
+    cp "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
101
+    chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
102
+    chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
103
+    "${PROJECT_NAME}-pass" -u "$new_username" -a dokuwiki -p "$new_user_password"
104 104
 }
105 105
 
106 106
 function remove_user_dokuwiki {
107 107
     remove_username="$1"
108 108
 
109 109
     read_config_param "DOKUWIKI_DOMAIN_NAME"
110
-    if grep -q "$remove_username:" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php; then
111
-        sed -i "/$remove_username:/d" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
112
-        sed -i "/$remove_username:/d" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
113
-        ${PROJECT_NAME}-pass -u "$remove_username" --rmapp dokuwiki
110
+    if grep -q "$remove_username:" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"; then
111
+        sed -i "/$remove_username:/d" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
112
+        sed -i "/$remove_username:/d" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
113
+        "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp dokuwiki
114 114
     fi
115 115
 }
116 116
 
@@ -120,7 +120,7 @@ function reconfigure_dokuwiki {
120 120
 
121 121
 function upgrade_dokuwiki {
122 122
     function_check set_repo_commit
123
-    set_repo_commit /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs "dokuwiki commit" "$DOKUWIKI_COMMIT" $DOKUWIKI_REPO
123
+    set_repo_commit "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs" "dokuwiki commit" "$DOKUWIKI_COMMIT" $DOKUWIKI_REPO
124 124
 }
125 125
 
126 126
 function backup_local_dokuwiki {
@@ -129,18 +129,18 @@ function backup_local_dokuwiki {
129 129
     function_check backup_directory_to_usb
130 130
 
131 131
     # backup the data
132
-    source_directory=/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data
133
-    if [ -d $source_directory ]; then
132
+    source_directory="/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data"
133
+    if [ -d "$source_directory" ]; then
134 134
         dest_directory=dokuwikidat
135
-        backup_directory_to_usb $source_directory $dest_directory
135
+        backup_directory_to_usb "$source_directory" "$dest_directory"
136 136
     fi
137 137
 
138 138
     # backup the users
139
-    source_directory=/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl
140
-    if [ -d $source_directory ]; then
139
+    source_directory="/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl"
140
+    if [ -d "$source_directory" ]; then
141 141
         dest_directory=dokuwikiacl
142
-        cp /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users*.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/
143
-        backup_directory_to_usb $source_directory $dest_directory
142
+        cp "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users*.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/"
143
+        backup_directory_to_usb "$source_directory" "$dest_directory"
144 144
     fi
145 145
 }
146 146
 
@@ -153,11 +153,12 @@ function restore_local_dokuwiki {
153 153
     temp_restore_dir=/root/tempdokuwikidat
154 154
     function_check restore_directory_from_usb
155 155
     restore_directory_from_usb ${temp_restore_dir} dokuwikidat
156
-    if [ -d ${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/data ]; then
157
-        cp -r ${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/data/* /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data
156
+    if [ -d "${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/data" ]; then
157
+        cp -r "${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/data/*" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data"
158 158
     else
159
-        cp -r ${temp_restore_dir}/* /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data
159
+        cp -r "${temp_restore_dir}/*" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data"
160 160
     fi
161
+    # shellcheck disable=SC2181
161 162
     if [ ! "$?" = "0" ]; then
162 163
         function_check restore_directory_from_usb
163 164
         set_user_permissions
@@ -172,13 +173,14 @@ function restore_local_dokuwiki {
172 173
     temp_restore_dir=/root/tempdokuwikiacl
173 174
     function_check restore_directory_from_usb
174 175
     restore_directory_from_usb ${temp_restore_dir} dokuwikiacl
175
-    if [ -d ${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/lib/plugins/acl ]; then
176
-        cp ${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/lib/plugins/acl/users.auth.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/
177
-        cp ${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/lib/plugins/acl/users.auth.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/
176
+    if [ -d "${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/lib/plugins/acl" ]; then
177
+        cp "${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/lib/plugins/acl/users.auth.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/"
178
+        cp "${temp_restore_dir}/var/www/${DOKUWIKI_DOMAIN_NAME}/htdocs/lib/plugins/acl/users.auth.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/"
178 179
     else
179
-        cp ${temp_restore_dir}/users.auth.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/
180
-        cp ${temp_restore_dir}/users.auth.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/
180
+        cp "${temp_restore_dir}/users.auth.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/"
181
+        cp "${temp_restore_dir}/users.auth.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/"
181 182
     fi
183
+    # shellcheck disable=SC2181
182 184
     if [ ! "$?" = "0" ]; then
183 185
         function_check restore_directory_from_usb
184 186
         set_user_permissions
@@ -189,21 +191,21 @@ function restore_local_dokuwiki {
189 191
     fi
190 192
     rm -rf ${temp_restore_dir}
191 193
 
192
-    chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
193
-    chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
194
-    chmod -R 755 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data
195
-    chmod -R 755 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib
196
-    chown -R www-data:www-data /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
194
+    chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
195
+    chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
196
+    chmod -R 755 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data"
197
+    chmod -R 755 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib"
198
+    chown -R www-data:www-data "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs"
197 199
     echo $"Restore of Dokuwiki complete"
198 200
 }
199 201
 
200 202
 function backup_remote_dokuwiki {
201 203
     DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
202
-    if [ -d /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs ]; then
204
+    if [ -d "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs" ]; then
203 205
         echo $"Backing up dokuwiki"
204
-        backup_directory_to_friend /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data dokuwikidat
205
-        cp /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users*.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/
206
-        backup_directory_to_friend /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl dokuwikiacl
206
+        backup_directory_to_friend "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data" dokuwikidat
207
+        cp "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users*.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/"
208
+        backup_directory_to_friend "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl" dokuwikiacl
207 209
     fi
208 210
 }
209 211
 
@@ -212,15 +214,16 @@ function restore_remote_dokuwiki {
212 214
     function_check get_completion_param
213 215
     function_check restore_directory_from_friend
214 216
 
215
-    if [ -d $SERVER_DIRECTORY/backup/dokuwikidat ]; then
217
+    if [ -d "$SERVER_DIRECTORY/backup/dokuwikidat" ]; then
216 218
         echo $"Restoring Dokuwiki data for $DOKUWIKI_DOMAIN_NAME"
217 219
         temp_restore_dir=/root/tempdokuwikidat
218 220
         restore_directory_from_friend $temp_restore_dir dokuwikidat
219
-        if [ -d $temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data ]; then
220
-            cp -r $temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/* /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/
221
+        if [ -d "$temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data" ]; then
222
+            cp -r "$temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/*" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/"
221 223
         else
222
-            cp -r $temp_restore_dir/* /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/
224
+            cp -r $temp_restore_dir/* "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/"
223 225
         fi
226
+        # shellcheck disable=SC2181
224 227
         if [ ! "$?" = "0" ]; then
225 228
             exit 92634
226 229
         fi
@@ -229,15 +232,16 @@ function restore_remote_dokuwiki {
229 232
         echo $"Restore of Dokuwiki data complete"
230 233
     fi
231 234
 
232
-    if [ -d $SERVER_DIRECTORY/backup/dokuwikiacl ]; then
235
+    if [ -d "$SERVER_DIRECTORY/backup/dokuwikiacl" ]; then
233 236
         echo $"Restoring Dokuwiki users for $DOKUWIKI_DOMAIN_NAME"
234 237
         temp_restore_dir=/root/tempdokuwikiacl
235 238
         restore_directory_from_friend $temp_restore_dir dokuwikiacl
236
-        if [ -d $temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl ]; then
237
-            cp -r $temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/* /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/
239
+        if [ -d "$temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl" ]; then
240
+            cp -r "$temp_restore_dir/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/*" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/"
238 241
         else
239
-            cp -r $temp_restore_dir/* /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/
242
+            cp -r $temp_restore_dir/* "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/"
240 243
         fi
244
+        # shellcheck disable=SC2181
241 245
         if [ ! "$?" = "0" ]; then
242 246
             exit 735287
243 247
         fi
@@ -246,11 +250,11 @@ function restore_remote_dokuwiki {
246 250
         echo $"Restore of Dokuwiki users complete"
247 251
     fi
248 252
 
249
-    chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
250
-    chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
251
-    chmod -R 755 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/data
252
-    chmod -R 755 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/lib
253
-    chown -R www-data:www-data /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
253
+    chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
254
+    chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
255
+    chmod -R 755 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/data"
256
+    chmod -R 755 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data/lib"
257
+    chown -R www-data:www-data "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs"
254 258
 }
255 259
 
256 260
 function remove_dokuwiki {
@@ -259,13 +263,13 @@ function remove_dokuwiki {
259 263
     fi
260 264
     function_check remove_onion_service
261 265
     remove_onion_service dokuwiki ${DOKUWIKI_ONION_PORT}
262
-    nginx_dissite $DOKUWIKI_DOMAIN_NAME
263
-    remove_certs $DOKUWIKI_DOMAIN_NAME
264
-    if [ -f /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME ]; then
265
-        rm /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
266
+    nginx_dissite "$DOKUWIKI_DOMAIN_NAME"
267
+    remove_certs "$DOKUWIKI_DOMAIN_NAME"
268
+    if [ -f "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME" ]; then
269
+        rm "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
266 270
     fi
267
-    if [ ! -d /var/www/$DOKUWIKI_DOMAIN_NAME ]; then
268
-        rm -rf /var/www/$DOKUWIKI_DOMAIN_NAME
271
+    if [ ! -d "/var/www/$DOKUWIKI_DOMAIN_NAME" ]; then
272
+        rm -rf "/var/www/$DOKUWIKI_DOMAIN_NAME"
269 273
     fi
270 274
     if [ -d /var/lib/dokuwiki ]; then
271 275
         rm -rf /var/lib/dokuwiki
@@ -278,14 +282,14 @@ function remove_dokuwiki {
278 282
     fi
279 283
     remove_completion_param "install_dokuwiki"
280 284
     remove_completion_param "dokuwiki domain"
281
-    sed -i '/dokuwiki/d' $COMPLETION_FILE
285
+    sed -i '/dokuwiki/d' "$COMPLETION_FILE"
282 286
 
283 287
     function_check remove_ddns_domain
284
-    remove_ddns_domain $DOKUWIKI_DOMAIN_NAME
288
+    remove_ddns_domain "$DOKUWIKI_DOMAIN_NAME"
285 289
 }
286 290
 
287 291
 function install_dokuwiki {
288
-    if [ ! $DOKUWIKI_DOMAIN_NAME ]; then
292
+    if [ ! "$DOKUWIKI_DOMAIN_NAME" ]; then
289 293
         return
290 294
     fi
291 295
 
@@ -293,25 +297,25 @@ function install_dokuwiki {
293 297
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
294 298
     apt-get -yq install php-memcached memcached
295 299
 
296
-    if [ ! -d /var/www/$DOKUWIKI_DOMAIN_NAME ]; then
297
-        mkdir /var/www/$DOKUWIKI_DOMAIN_NAME
300
+    if [ ! -d "/var/www/$DOKUWIKI_DOMAIN_NAME" ]; then
301
+        mkdir "/var/www/$DOKUWIKI_DOMAIN_NAME"
298 302
     fi
299 303
 
300
-    if [ ! -f /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/install.php ]; then
301
-        cd /var/www/$DOKUWIKI_DOMAIN_NAME
304
+    if [ ! -f "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/install.php" ]; then
305
+        cd "/var/www/$DOKUWIKI_DOMAIN_NAME" || exit 23468246824
302 306
 
303 307
         if [ -d /repos/dokuwiki ]; then
304
-            mkdir /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
305
-            cp -r -p /repos/dokuwiki/. /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
306
-            cd /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
308
+            mkdir "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs"
309
+            cp -r -p /repos/dokuwiki/. "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs"
310
+            cd "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs" || exit 24687462
307 311
             git pull
308 312
         else
309 313
             function_check git_clone
310
-            git_clone $DOKUWIKI_REPO /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
314
+            git_clone "$DOKUWIKI_REPO" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs"
311 315
         fi
312 316
 
313
-        cd /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
314
-        git checkout $DOKUWIKI_COMMIT -b $DOKUWIKI_COMMIT
317
+        cd "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs" || exit 38368832
318
+        git checkout "$DOKUWIKI_COMMIT" -b "$DOKUWIKI_COMMIT"
315 319
         set_completion_param "dokuwiki commit" "$DOKUWIKI_COMMIT"
316 320
 
317 321
     fi
@@ -322,40 +326,40 @@ function install_dokuwiki {
322 326
         echo $'Removed Apache installation after Dokuwiki install'
323 327
     fi
324 328
 
325
-    echo '<?php' > /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
326
-    echo "\$conf['title'] = '${DOKUWIKI_TITLE}';" >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
327
-    echo "\$conf['lang'] = 'en';" >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
328
-    echo "\$conf['license'] = 'cc-by-sa';" >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
329
-    echo "\$conf['useacl'] = 1;" >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
330
-    echo "\$conf['superuser'] = '@admin';" >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
331
-    echo "\$conf['disableactions'] = 'register';" >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
332
-    ln -s /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/local.php
333
-
334
-    chmod 600 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php
335
-    chown -R www-data:www-data /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs
336
-    chmod -R 755 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib
337
-    chmod -R 755 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data
338
-
339
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
340
-        DOKUWIKI_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
329
+    { echo '<?php';
330
+      echo "\$conf['title'] = '${DOKUWIKI_TITLE}';";
331
+      echo "\$conf['lang'] = 'en';";
332
+      echo "\$conf['license'] = 'cc-by-sa';";
333
+      echo "\$conf['useacl'] = 1;";
334
+      echo "\$conf['superuser'] = '@admin';";
335
+      echo "\$conf['disableactions'] = 'register';"; } > "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php"
336
+    ln -s "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/local.php"
337
+
338
+    chmod 600 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/local.php"
339
+    chown -R www-data:www-data "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs"
340
+    chmod -R 755 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib"
341
+    chmod -R 755 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/data"
342
+
343
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
344
+        DOKUWIKI_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
341 345
     else
342
-        if [ ! $DOKUWIKI_ADMIN_PASSWORD ]; then
343
-            DOKUWIKI_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
346
+        if [ ! "$DOKUWIKI_ADMIN_PASSWORD" ]; then
347
+            DOKUWIKI_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
344 348
         fi
345 349
     fi
346 350
     HASHED_DOKUWIKI_PASSWORD=$(echo -n "$DOKUWIKI_ADMIN_PASSWORD" | md5sum | awk -F ' ' '{print $1}')
347
-    echo -n "$MY_USERNAME:$HASHED_DOKUWIKI_PASSWORD:$MY_NAME:$MY_EMAIL:admin,user,upload" > /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
348
-    cp /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php
349
-    chmod 640 /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php
351
+    echo -n "$MY_USERNAME:$HASHED_DOKUWIKI_PASSWORD:$MY_NAME:$MY_EMAIL:admin,user,upload" > "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
352
+    cp "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/users.auth.php"
353
+    chmod 640 "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/lib/plugins/acl/users.auth.php"
350 354
 
351
-    if ! grep -q "video/ogg" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf; then
352
-        echo 'ogv     video/ogg' >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf
355
+    if ! grep -q "video/ogg" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf"; then
356
+        echo 'ogv     video/ogg' >> "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf"
353 357
     fi
354
-    if ! grep -q "video/mp4" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf; then
355
-        echo 'mp4     video/mp4' >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf
358
+    if ! grep -q "video/mp4" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf"; then
359
+        echo 'mp4     video/mp4' >> "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf"
356 360
     fi
357
-    if ! grep -q "video/webm" /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf; then
358
-        echo 'webm    video/webm' >> /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf
361
+    if ! grep -q "video/webm" "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf"; then
362
+        echo 'webm    video/webm' >> "/var/www/$DOKUWIKI_DOMAIN_NAME/htdocs/conf/mime.conf"
359 363
     fi
360 364
 
361 365
     DOKUWIKI_ONION_HOSTNAME=$(add_onion_service dokuwiki 80 ${DOKUWIKI_ONION_PORT})
@@ -363,178 +367,178 @@ function install_dokuwiki {
363 367
 
364 368
     if [[ $ONION_ONLY == "no" ]]; then
365 369
         function_check nginx_http_redirect
366
-        nginx_http_redirect $DOKUWIKI_DOMAIN_NAME
367
-        echo 'server {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
368
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
369
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
370
-        echo "    root /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
371
-        echo "    server_name $DOKUWIKI_DOMAIN_NAME;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
372
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
373
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
374
-        echo '    index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
375
-        echo '    charset utf-8;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
376
-        echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
370
+        nginx_http_redirect "$DOKUWIKI_DOMAIN_NAME"
371
+        { echo 'server {';
372
+          echo '    listen 443 ssl;';
373
+          echo '    #listen [::]:443 ssl;';
374
+          echo "    root /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs;";
375
+          echo "    server_name $DOKUWIKI_DOMAIN_NAME;";
376
+          echo '    access_log /dev/null;';
377
+          echo "    error_log /dev/null;";
378
+          echo '    index index.php;';
379
+          echo '    charset utf-8;';
380
+          echo '    proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
377 381
         function_check nginx_ssl
378
-        nginx_ssl $DOKUWIKI_DOMAIN_NAME
382
+        nginx_ssl "$DOKUWIKI_DOMAIN_NAME"
379 383
         function_check nginx_disable_sniffing
380
-        nginx_disable_sniffing $DOKUWIKI_DOMAIN_NAME
381
-        echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
382
-        echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
383
-        echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
384
-        echo '    location / {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
384
+        nginx_disable_sniffing "$DOKUWIKI_DOMAIN_NAME"
385
+        { echo '    add_header Strict-Transport-Security "max-age=0;";';
386
+          echo '';
387
+          echo '    # rewrite to front controller as default rule';
388
+          echo '    location / {'; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
385 389
         function_check nginx_limits
386
-        nginx_limits $DOKUWIKI_DOMAIN_NAME
387
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
388
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
389
-        echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
390
-        echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
391
-        echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
392
-        echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
393
-        echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
394
-        echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
395
-        echo '        expires 30d;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
396
-        echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
397
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
398
-        echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
399
-        echo '    # block these file types' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
400
-        echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
401
-        echo '        deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
402
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
403
-        echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
404
-        echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
405
-        echo '    # or a unix socket' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
406
-        echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
390
+        nginx_limits "$DOKUWIKI_DOMAIN_NAME"
391
+        { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
392
+          echo '    }';
393
+          echo '';
394
+          echo '    # statically serve these file types when possible';
395
+          echo '    # otherwise fall back to front controller';
396
+          echo '    # allow browser to cache them';
397
+          echo '    # added .htm for advanced source code editor library';
398
+          echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
399
+          echo '        expires 30d;';
400
+          echo "        try_files \$uri /index.php?q=\$uri&\$args;";
401
+          echo '    }';
402
+          echo '';
403
+          echo '    # block these file types';
404
+          echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
405
+          echo '        deny all;';
406
+          echo '    }';
407
+          echo '';
408
+          echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
409
+          echo '    # or a unix socket';
410
+          echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
407 411
         function_check nginx_limits
408
-        nginx_limits $DOKUWIKI_DOMAIN_NAME
409
-        echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
410
-        echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
411
-        echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
412
-        echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
413
-        echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
414
-        echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
415
-        echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
416
-        echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
417
-        echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
418
-        echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
419
-        echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
420
-        echo '        # With php-fpm:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
421
-        echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
422
-        echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
423
-        echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
424
-        echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
425
-        echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
426
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
427
-        echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
428
-        echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
429
-        echo '    location ~ /\. {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
430
-        echo '        deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
431
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
432
-        echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
433
-        echo '    #deny access to store' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
434
-        echo '    location ~ /store {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
435
-        echo '        deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
436
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
437
-        echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
438
-        echo '      deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
439
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
440
-        echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
441
-        echo '      deny  all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
442
-        echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
443
-        echo '}' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
444
-        echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
412
+        nginx_limits "$DOKUWIKI_DOMAIN_NAME"
413
+        { echo '        # Zero-day exploit defense.';
414
+          echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
415
+          echo "        # Won't work properly (404 error) if the file is not stored on this";
416
+          echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
417
+          echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
418
+          echo "        # another machine. And then cross your fingers that you won't get hacked.";
419
+          echo "        try_files \$uri \$uri/ /index.php;";
420
+          echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
421
+          echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
422
+          echo '        # With php-cgi alone:';
423
+          echo '        # fastcgi_pass 127.0.0.1:9000;';
424
+          echo '        # With php-fpm:';
425
+          echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
426
+          echo '        fastcgi_read_timeout 30;';
427
+          echo '        include fastcgi_params;';
428
+          echo '        fastcgi_index index.php;';
429
+          echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
430
+          echo '    }';
431
+          echo '';
432
+          echo '    # deny access to all dot files';
433
+          echo '    location ~ /\. {';
434
+          echo '        deny all;';
435
+          echo '    }';
436
+          echo '';
437
+          echo '    #deny access to store';
438
+          echo '    location ~ /store {';
439
+          echo '        deny all;';
440
+          echo '    }';
441
+          echo '    location ~ /(data|conf|bin|inc)/ {';
442
+          echo '      deny all;';
443
+          echo '    }';
444
+          echo '    location ~ /\.ht {';
445
+          echo '      deny  all;';
446
+          echo '    }';
447
+          echo '}';
448
+          echo ''; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
445 449
     else
446
-        echo -n '' > /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
450
+        echo -n '' > "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
447 451
     fi
448
-    echo 'server {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
449
-    echo "    listen 127.0.0.1:${DOKUWIKI_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
450
-    echo "    root /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
451
-    echo "    server_name $DOKUWIKI_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
452
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
453
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
454
-    echo '    index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
455
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
456
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
452
+    { echo 'server {';
453
+      echo "    listen 127.0.0.1:${DOKUWIKI_ONION_PORT} default_server;";
454
+      echo "    root /var/www/$DOKUWIKI_DOMAIN_NAME/htdocs;";
455
+      echo "    server_name $DOKUWIKI_ONION_HOSTNAME;";
456
+      echo '    access_log /dev/null;';
457
+      echo "    error_log /dev/null;";
458
+      echo '    index index.php;';
459
+      echo '    charset utf-8;';
460
+      echo '    proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
457 461
     function_check nginx_disable_sniffing
458
-    nginx_disable_sniffing $DOKUWIKI_DOMAIN_NAME
459
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
460
-    echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
461
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
462
-    echo '    location / {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
462
+    nginx_disable_sniffing "$DOKUWIKI_DOMAIN_NAME"
463
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
464
+      echo '';
465
+      echo '    # rewrite to front controller as default rule';
466
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
463 467
     function_check nginx_limits
464
-    nginx_limits $DOKUWIKI_DOMAIN_NAME
465
-    echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
466
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
467
-    echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
468
-    echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
469
-    echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
470
-    echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
471
-    echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
472
-    echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
473
-    echo '        expires 30d;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
474
-    echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
475
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
476
-    echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
477
-    echo '    # block these file types' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
478
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
479
-    echo '        deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
480
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
481
-    echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
482
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
483
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
484
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
468
+    nginx_limits "$DOKUWIKI_DOMAIN_NAME"
469
+    { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
470
+      echo '    }';
471
+      echo '';
472
+      echo '    # statically serve these file types when possible';
473
+      echo '    # otherwise fall back to front controller';
474
+      echo '    # allow browser to cache them';
475
+      echo '    # added .htm for advanced source code editor library';
476
+      echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
477
+      echo '        expires 30d;';
478
+      echo "        try_files \$uri /index.php?q=\$uri&\$args;";
479
+      echo '    }';
480
+      echo '';
481
+      echo '    # block these file types';
482
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
483
+      echo '        deny all;';
484
+      echo '    }';
485
+      echo '';
486
+      echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
487
+      echo '    # or a unix socket';
488
+      echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
485 489
     function_check nginx_limits
486
-    nginx_limits $DOKUWIKI_DOMAIN_NAME
487
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
488
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
489
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
490
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
491
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
492
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
493
-    echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
494
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
495
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
496
-    echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
497
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
498
-    echo '        # With php-fpm:' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
499
-    echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
500
-    echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
501
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
502
-    echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
503
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
504
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
505
-    echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
506
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
507
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
508
-    echo '        deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
509
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
510
-    echo '' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
511
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
512
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
513
-    echo '        deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
514
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
515
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
516
-    echo '      deny all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
517
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
518
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
519
-    echo '      deny  all;' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
520
-    echo '    }' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
521
-    echo '}' >> /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
490
+    nginx_limits "$DOKUWIKI_DOMAIN_NAME"
491
+    { echo '        # Zero-day exploit defense.';
492
+      echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
493
+      echo "        # Won't work properly (404 error) if the file is not stored on this";
494
+      echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
495
+      echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
496
+      echo "        # another machine. And then cross your fingers that you won't get hacked.";
497
+      echo "        try_files \$uri \$uri/ /index.php;";
498
+      echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
499
+      echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
500
+      echo '        # With php-cgi alone:';
501
+      echo '        # fastcgi_pass 127.0.0.1:9000;';
502
+      echo '        # With php-fpm:';
503
+      echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
504
+      echo '        fastcgi_read_timeout 30;';
505
+      echo '        include fastcgi_params;';
506
+      echo '        fastcgi_index index.php;';
507
+      echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
508
+      echo '    }';
509
+      echo '';
510
+      echo '    # deny access to all dot files';
511
+      echo '    location ~ /\. {';
512
+      echo '        deny all;';
513
+      echo '    }';
514
+      echo '';
515
+      echo '    #deny access to store';
516
+      echo '    location ~ /store {';
517
+      echo '        deny all;';
518
+      echo '    }';
519
+      echo '    location ~ /(data|conf|bin|inc)/ {';
520
+      echo '      deny all;';
521
+      echo '    }';
522
+      echo '    location ~ /\.ht {';
523
+      echo '      deny  all;';
524
+      echo '    }';
525
+      echo '}'; } >> "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
522 526
 
523 527
     function_check create_site_certificate
524
-    create_site_certificate $DOKUWIKI_DOMAIN_NAME 'yes'
528
+    create_site_certificate "$DOKUWIKI_DOMAIN_NAME" 'yes'
525 529
 
526 530
     function_check configure_php
527 531
     configure_php
528 532
 
529
-    nginx_ensite $DOKUWIKI_DOMAIN_NAME
533
+    nginx_ensite "$DOKUWIKI_DOMAIN_NAME"
530 534
 
531 535
     systemctl restart php7.0-fpm
532 536
     systemctl restart nginx
533 537
 
534 538
     function_check add_ddns_domain
535
-    add_ddns_domain $DOKUWIKI_DOMAIN_NAME
539
+    add_ddns_domain "$DOKUWIKI_DOMAIN_NAME"
536 540
 
537
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a dokuwiki -p "$DOKUWIKI_ADMIN_PASSWORD"
541
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a dokuwiki -p "$DOKUWIKI_ADMIN_PASSWORD"
538 542
 
539 543
     APP_INSTALLED=1
540 544
 }

+ 135
- 134
src/freedombone-app-edith Просмотреть файл

@@ -50,12 +50,12 @@ edith_variables=(MY_USERNAME
50 50
 function remove_bad_links_edith {
51 51
     read_config_param EDITH_DOMAIN_NAME
52 52
 
53
-    edith_dir=/var/www/$EDITH_DOMAIN_NAME/htdocs
53
+    edith_dir="/var/www/$EDITH_DOMAIN_NAME/htdocs"
54 54
 
55 55
     # copy jquery locally
56 56
     jquery_version='1.12.4'
57 57
     if [ ! -f $edith_dir/jquery-${jquery_version}.js ]; then
58
-        cd $edith_dir
58
+        cd $edith_dir || exit 246824628
59 59
         wget https://code.jquery.com/jquery-${jquery_version}.js
60 60
         if [ -f $edith_dir/jquery-${jquery_version}.js ]; then
61 61
             jquery_hash=$(sha256sum $edith_dir/jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
@@ -79,9 +79,9 @@ function change_password_edith {
79 79
     new_user_password="$2"
80 80
 
81 81
     sed -i "/${curr_username}:/d" /etc/nginx/.edithpasswd
82
-    echo -n "$new_user_password" | htpasswd -i -s -c /etc/nginx/.edithpasswd ${curr_username}
82
+    echo -n "$new_user_password" | htpasswd -i -s -c /etc/nginx/.edithpasswd "${curr_username}"
83 83
 
84
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a ${curr_username} -p "$new_user_password"
84
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a "${curr_username}" -p "$new_user_password"
85 85
 }
86 86
 
87 87
 function logging_on_edith {
@@ -102,21 +102,20 @@ function edith_enable_login {
102 102
     dialog --title $"Enable Edith login" \
103 103
            --backtitle $"Freedombone Control Panel" \
104 104
            --defaultno \
105
-           --yesno $"\nDo you want to add a login so that random web users can't access your notes?" 10 60
105
+           --yesno $"\\nDo you want to add a login so that random web users can't access your notes?" 10 60
106 106
     sel=$?
107 107
     case $sel in
108
-        0) if grep -q '#auth_basic' /etc/nginx/sites-available/$EDITH_DOMAIN_NAME; then
109
-               sed -i 's|#auth_basic|auth_basic|g' /etc/nginx/sites-available/$EDITH_DOMAIN_NAME
108
+        0) if grep -q '#auth_basic' "/etc/nginx/sites-available/$EDITH_DOMAIN_NAME"; then
109
+               sed -i 's|#auth_basic|auth_basic|g' "/etc/nginx/sites-available/$EDITH_DOMAIN_NAME"
110 110
                systemctl restart nginx
111 111
            fi
112
-           read_config_param $MY_USERNAME
113
-           EDITH_PASSWORD=$(${PROJECT_NAME}-pass -u $MY_USERNAME -a edith)
112
+           read_config_param "$MY_USERNAME"
113
+           EDITH_PASSWORD=$("${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a edith)
114 114
            dialog --title $"Enable Edith login" \
115 115
                   --msgbox $"Edith logins are now enabled with the password $EDITH_PASSWORD" 6 65
116
-           EDITH__PASSWORD=
117 116
            ;;
118
-        1) if ! grep -q '#auth_basic' /etc/nginx/sites-available/$EDITH_DOMAIN_NAME; then
119
-               sed -i 's|auth_basic|#auth_basic|g' /etc/nginx/sites-available/$EDITH_DOMAIN_NAME
117
+        1) if ! grep -q '#auth_basic' "/etc/nginx/sites-available/$EDITH_DOMAIN_NAME"; then
118
+               sed -i 's|auth_basic|#auth_basic|g' "/etc/nginx/sites-available/$EDITH_DOMAIN_NAME"
120 119
                systemctl restart nginx
121 120
            fi
122 121
            dialog --title $"Disable Edith login" \
@@ -127,31 +126,34 @@ function edith_enable_login {
127 126
 
128 127
 function edith_browse {
129 128
     read_config_param EDITH_DOMAIN_NAME
130
-    cd /var/www/$EDITH_DOMAIN_NAME/htdocs/data
131
-    editor /var/www/$EDITH_DOMAIN_NAME/htdocs/data
129
+    cd "/var/www/$EDITH_DOMAIN_NAME/htdocs/data" || exit 24682642
130
+    editor "/var/www/$EDITH_DOMAIN_NAME/htdocs/data"
132 131
 }
133 132
 
134 133
 function configure_interactive_edith {
135 134
     while true
136 135
     do
137
-        data=$(tempfile 2>/dev/null)
138
-        trap "rm -f $data" 0 1 2 5 15
136
+        data=$(mktemp 2>/dev/null)
139 137
         dialog --backtitle $"Freedombone Control Panel" \
140 138
                --title $"Edith" \
141 139
                --radiolist $"Choose an operation:" 10 50 3 \
142 140
                1 $"Enable login" off \
143 141
                2 $"Browse notes" off \
144
-               3 $"Exit" on 2> $data
142
+               3 $"Exit" on 2> "$data"
145 143
         sel=$?
146 144
         case $sel in
147
-            1) break;;
148
-            255) break;;
145
+            1) rm -f "$data"
146
+               break;;
147
+            255) rm -f "$data"
148
+                 break;;
149 149
         esac
150
-        case $(cat $data) in
150
+        case $(cat "$data") in
151 151
             1) edith_enable_login;;
152 152
             2) edith_browse;;
153
-            3) break;;
153
+            3) rm -f "$data"
154
+               break;;
154 155
         esac
156
+        rm -f "$data"
155 157
     done
156 158
 }
157 159
 
@@ -165,24 +167,24 @@ function upgrade_edith {
165 167
 
166 168
     # update to the next commit
167 169
     function_check set_repo_commit
168
-    set_repo_commit /var/www/$EDITH_DOMAIN_NAME/htdocs "edith commit" "$EDITH_COMMIT" $EDITH_REPO
170
+    set_repo_commit "/var/www/$EDITH_DOMAIN_NAME/htdocs" "edith commit" "$EDITH_COMMIT" "$EDITH_REPO"
169 171
 
170 172
     remove_bad_links_edith
171
-    chown -R www-data:www-data /var/www/$EDITH_DOMAIN_NAME/htdocs
172
-    chmod a+w /var/www/$EDITH_DOMAIN_NAME/htdocs/data
173
+    chown -R www-data:www-data "/var/www/$EDITH_DOMAIN_NAME/htdocs"
174
+    chmod a+w "/var/www/$EDITH_DOMAIN_NAME/htdocs/data"
173 175
 }
174 176
 
175 177
 function backup_local_edith {
176 178
     read_config_param EDITH_DOMAIN_NAME
177 179
 
178 180
     function_check suspend_site
179
-    suspend_site ${EDITH_DOMAIN_NAME}
181
+    suspend_site "${EDITH_DOMAIN_NAME}"
180 182
 
181
-    source_directory=/var/www/${EDITH_DOMAIN_NAME}/htdocs/data
183
+    source_directory="/var/www/${EDITH_DOMAIN_NAME}/htdocs/data"
182 184
 
183 185
     function_check backup_directory_to_usb
184 186
     dest_directory=edith
185
-    backup_directory_to_usb $source_directory $dest_directory
187
+    backup_directory_to_usb "$source_directory" "$dest_directory"
186 188
 
187 189
     function_check restart_site
188 190
     restart_site
@@ -192,12 +194,12 @@ function restore_local_edith {
192 194
     read_config_param EDITH_DOMAIN_NAME
193 195
 
194 196
     temp_restore_dir=/root/tempedith
195
-    edith_dir=/var/www/${EDITH_DOMAIN_NAME}/htdocs/data
197
+    edith_dir="/var/www/${EDITH_DOMAIN_NAME}/htdocs/data"
196 198
 
197 199
     function_check restore_directory_from_usb
198 200
     restore_directory_from_usb $temp_restore_dir edith
199 201
     if [ -d $temp_restore_dir ]; then
200
-        if [ -d cp $temp_restore_dir$edith_dir ]; then
202
+        if [ -d $temp_restore_dir$edith_dir ]; then
201 203
             cp -rp $temp_restore_dir$edith_dir $edith_dir/
202 204
         else
203 205
             if [ ! -d $edith_dir ]; then
@@ -215,13 +217,13 @@ function backup_remote_edith {
215 217
     read_config_param EDITH_DOMAIN_NAME
216 218
 
217 219
     function_check suspend_site
218
-    suspend_site ${EDITH_DOMAIN_NAME}
220
+    suspend_site "${EDITH_DOMAIN_NAME}"
219 221
 
220
-    source_directory=/var/www/${EDITH_DOMAIN_NAME}/htdocs/data
222
+    source_directory="/var/www/${EDITH_DOMAIN_NAME}/htdocs/data"
221 223
 
222 224
     function_check backup_directory_to_friend
223 225
     dest_directory=edith
224
-    backup_directory_to_friend $source_directory $dest_directory
226
+    backup_directory_to_friend "$source_directory" "$dest_directory"
225 227
 
226 228
     function_check restart_site
227 229
     restart_site
@@ -231,12 +233,12 @@ function restore_remote_edith {
231 233
     read_config_param EDITH_DOMAIN_NAME
232 234
 
233 235
     temp_restore_dir=/root/tempedith
234
-    edith_dir=/var/www/${EDITH_DOMAIN_NAME}/htdocs/data
236
+    edith_dir="/var/www/${EDITH_DOMAIN_NAME}/htdocs/data"
235 237
 
236 238
     function_check restore_directory_from_friend
237 239
     restore_directory_from_friend $temp_restore_dir edith
238 240
     if [ -d $temp_restore_dir ]; then
239
-        if [ -d cp $temp_restore_dir$edith_dir ]; then
241
+        if [ -d $temp_restore_dir$edith_dir ]; then
240 242
             cp -rp $temp_restore_dir$edith_dir $edith_dir/
241 243
         else
242 244
             if [ ! -d $edith_dir ]; then
@@ -253,17 +255,17 @@ function restore_remote_edith {
253 255
 function remove_edith {
254 256
     nginx_dissite $EDITH_DOMAIN_NAME
255 257
 
256
-    if [ -f /etc/nginx/sites-available/$EDITH_DOMAIN_NAME ]; then
257
-        rm /etc/nginx/sites-available/$EDITH_DOMAIN_NAME
258
+    if [ -f "/etc/nginx/sites-available/$EDITH_DOMAIN_NAME" ]; then
259
+        rm "/etc/nginx/sites-available/$EDITH_DOMAIN_NAME"
258 260
     fi
259 261
 
260
-    if [ -d /var/www/$EDITH_DOMAIN_NAME ]; then
261
-        rm -rf /var/www/$EDITH_DOMAIN_NAME
262
+    if [ -d "/var/www/$EDITH_DOMAIN_NAME" ]; then
263
+        rm -rf "/var/www/$EDITH_DOMAIN_NAME"
262 264
     fi
263 265
 
264 266
     function_check remove_onion_service
265 267
     remove_onion_service edith ${EDITH_ONION_PORT}
266
-    sed -i '/edith/d' $COMPLETION_FILE
268
+    sed -i '/edith/d' "$COMPLETION_FILE"
267 269
 
268 270
     if [ -f /etc/nginx/.edithpasswd ]; then
269 271
         rm /etc/nginx/.edithpasswd
@@ -286,26 +288,26 @@ function install_edith {
286 288
     function_check install_nodejs
287 289
     install_nodejs edith
288 290
 
289
-    if [ ! ${EDITH_PASSWORD} ]; then
290
-        if [ -f ${IMAGE_PASSWORD_FILE} ]; then
291
-            EDITH_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
291
+    if [ ! "${EDITH_PASSWORD}" ]; then
292
+        if [ -f "${IMAGE_PASSWORD_FILE}" ]; then
293
+            EDITH_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
292 294
         else
293
-            EDITH_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
295
+            EDITH_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
294 296
         fi
295 297
     fi
296 298
 
297
-    if [ -d /var/www/$EDITH_DOMAIN_NAME/htdocs ]; then
298
-        rm -rf /var/www/$EDITH_DOMAIN_NAME/htdocs
299
+    if [ -d "/var/www/$EDITH_DOMAIN_NAME/htdocs" ]; then
300
+        rm -rf "/var/www/$EDITH_DOMAIN_NAME/htdocs"
299 301
     fi
300 302
 
301 303
     if [ -d /repos/edith ]; then
302
-        mkdir /var/www/$EDITH_DOMAIN_NAME/htdocs
303
-        cp -r -p /repos/edith/. /var/www/$EDITH_DOMAIN_NAME/htdocs
304
-        cd /var/www/$EDITH_DOMAIN_NAME/htdocs
304
+        mkdir "/var/www/$EDITH_DOMAIN_NAME/htdocs"
305
+        cp -r -p /repos/edith/. "/var/www/$EDITH_DOMAIN_NAME/htdocs"
306
+        cd "/var/www/$EDITH_DOMAIN_NAME/htdocs" || exit 24682462
305 307
         git pull
306 308
     else
307 309
         function_check git_clone
308
-        git_clone $EDITH_REPO /var/www/$EDITH_DOMAIN_NAME/htdocs
310
+        git_clone "$EDITH_REPO" "/var/www/$EDITH_DOMAIN_NAME/htdocs"
309 311
     fi
310 312
 
311 313
     if [ ! -d /var/www/$EDITH_DOMAIN_NAME/htdocs ]; then
@@ -313,102 +315,102 @@ function install_edith {
313 315
         exit 537593569
314 316
     fi
315 317
 
316
-    cd /var/www/$EDITH_DOMAIN_NAME/htdocs
317
-    git checkout $EDITH_COMMIT -b $EDITH_COMMIT
318
+    cd "/var/www/$EDITH_DOMAIN_NAME/htdocs" || exit 2648248
319
+    git checkout "$EDITH_COMMIT" -b "$EDITH_COMMIT"
318 320
     set_completion_param "edith commit" "$EDITH_COMMIT"
319 321
 
320
-    if [ ! -d /var/www/$EDITH_DOMAIN_NAME/htdocs/data ]; then
321
-        mkdir -p /var/www/$EDITH_DOMAIN_NAME/htdocs/data
322
+    if [ ! -d "/var/www/$EDITH_DOMAIN_NAME/htdocs/data" ]; then
323
+        mkdir -p "/var/www/$EDITH_DOMAIN_NAME/htdocs/data"
322 324
     fi
323 325
 
324 326
     EDITH_ONION_HOSTNAME=$(add_onion_service edith 80 ${EDITH_ONION_PORT})
325 327
 
326
-    edith_nginx_site=/etc/nginx/sites-available/$EDITH_DOMAIN_NAME
327
-    if [[ $ONION_ONLY == "no" ]]; then
328
+    edith_nginx_site="/etc/nginx/sites-available/$EDITH_DOMAIN_NAME"
329
+    if [[ "$ONION_ONLY" == "no" ]]; then
328 330
         function_check nginx_http_redirect
329
-        nginx_http_redirect $EDITH_DOMAIN_NAME "index index.php"
330
-        echo 'server {' >> $edith_nginx_site
331
-        echo '  listen 443 ssl;' >> $edith_nginx_site
332
-        echo '  #listen [::]:443 ssl;' >> $edith_nginx_site
333
-        echo "  server_name $EDITH_DOMAIN_NAME;" >> $edith_nginx_site
334
-        echo '' >> $edith_nginx_site
331
+        nginx_http_redirect "$EDITH_DOMAIN_NAME" "index index.php"
332
+        { echo 'server {';
333
+          echo '  listen 443 ssl;';
334
+          echo '  #listen [::]:443 ssl;';
335
+          echo "  server_name $EDITH_DOMAIN_NAME;";
336
+          echo ''; } >> "$edith_nginx_site"
335 337
         function_check nginx_compress
336
-        nginx_compress $EDITH_DOMAIN_NAME
337
-        echo '' >> $edith_nginx_site
338
-        echo '  # Security' >> $edith_nginx_site
338
+        nginx_compress "$EDITH_DOMAIN_NAME"
339
+        echo '' >> "$edith_nginx_site"
340
+        echo '  # Security' >> "$edith_nginx_site"
339 341
         function_check nginx_ssl
340
-        nginx_ssl $EDITH_DOMAIN_NAME
342
+        nginx_ssl "$EDITH_DOMAIN_NAME"
341 343
 
342 344
         function_check nginx_disable_sniffing
343
-        nginx_disable_sniffing $EDITH_DOMAIN_NAME
344
-
345
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $edith_nginx_site
346
-        echo '' >> $edith_nginx_site
347
-        echo '  access_log /dev/null;' >> $edith_nginx_site
348
-        echo '  error_log /dev/null;' >> $edith_nginx_site
349
-        echo '' >> $edith_nginx_site
350
-        echo "  root /var/www/$EDITH_DOMAIN_NAME/htdocs;" >> $edith_nginx_site
351
-        echo '' >> $edith_nginx_site
352
-        echo '  index index.php;' >> $edith_nginx_site
353
-        echo '' >> $edith_nginx_site
354
-        echo '  # PHP' >> $edith_nginx_site
355
-        echo '  location ~ \.php {' >> $edith_nginx_site
356
-        echo '    include snippets/fastcgi-php.conf;' >> $edith_nginx_site
357
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $edith_nginx_site
358
-        echo '    fastcgi_read_timeout 30;' >> $edith_nginx_site
359
-        echo '  }' >> $edith_nginx_site
360
-        echo '' >> $edith_nginx_site
361
-        echo '  # Location' >> $edith_nginx_site
362
-        echo '  location / {' >> $edith_nginx_site
345
+        nginx_disable_sniffing "$EDITH_DOMAIN_NAME"
346
+
347
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
348
+          echo '';
349
+          echo '  access_log /dev/null;';
350
+          echo '  error_log /dev/null;';
351
+          echo '';
352
+          echo "  root /var/www/$EDITH_DOMAIN_NAME/htdocs;";
353
+          echo '';
354
+          echo '  index index.php;';
355
+          echo '';
356
+          echo '  # PHP';
357
+          echo '  location ~ \.php {';
358
+          echo '    include snippets/fastcgi-php.conf;';
359
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
360
+          echo '    fastcgi_read_timeout 30;';
361
+          echo '  }';
362
+          echo '';
363
+          echo '  # Location';
364
+          echo '  location / {'; } >> "$edith_nginx_site"
363 365
         function_check nginx_limits
364
-        nginx_limits $EDITH_DOMAIN_NAME '15m'
365
-        echo '    try_files $uri $uri/ /index.php?$args;' >> $edith_nginx_site
366
-        echo "    auth_basic \"${EDITH_LOGIN_TEXT}\";" >> $edith_nginx_site
367
-        echo '    auth_basic_user_file /etc/nginx/.edithpasswd;' >> $edith_nginx_site
368
-        echo '  }' >> $edith_nginx_site
369
-        echo '}' >> $edith_nginx_site
366
+        nginx_limits "$EDITH_DOMAIN_NAME" '15m'
367
+        { echo "    try_files \$uri \$uri/ /index.php?\$args;";
368
+          echo "    auth_basic \"${EDITH_LOGIN_TEXT}\";";
369
+          echo '    auth_basic_user_file /etc/nginx/.edithpasswd;';
370
+          echo '  }';
371
+          echo '}'; } >> "$edith_nginx_site"
370 372
     else
371
-        echo -n '' > $edith_nginx_site
373
+        echo -n '' > "$edith_nginx_site"
372 374
     fi
373
-    echo 'server {' >> $edith_nginx_site
374
-    echo "    listen 127.0.0.1:$EDITH_ONION_PORT default_server;" >> $edith_nginx_site
375
-    echo "    server_name $EDITH_ONION_HOSTNAME;" >> $edith_nginx_site
376
-    echo '' >> $edith_nginx_site
375
+    { echo 'server {';
376
+      echo "    listen 127.0.0.1:$EDITH_ONION_PORT default_server;";
377
+      echo "    server_name $EDITH_ONION_HOSTNAME;";
378
+      echo ''; } >> "$edith_nginx_site"
377 379
     function_check nginx_compress
378
-    nginx_compress $EDITH_DOMAIN_NAME
379
-    echo '' >> $edith_nginx_site
380
+    nginx_compress "$EDITH_DOMAIN_NAME"
381
+    echo '' >> "$edith_nginx_site"
380 382
     function_check nginx_disable_sniffing
381
-    nginx_disable_sniffing $EDITH_DOMAIN_NAME
382
-    echo '' >> $edith_nginx_site
383
-    echo '  access_log /dev/null;' >> $edith_nginx_site
384
-    echo '  error_log /dev/null;' >> $edith_nginx_site
385
-    echo '' >> $edith_nginx_site
386
-    echo "  root /var/www/$EDITH_DOMAIN_NAME/htdocs;" >> $edith_nginx_site
387
-    echo '' >> $edith_nginx_site
388
-    echo '  index index.php;' >> $edith_nginx_site
389
-    echo '' >> $edith_nginx_site
390
-    echo '  # PHP' >> $edith_nginx_site
391
-    echo '  location ~ \.php {' >> $edith_nginx_site
392
-    echo '    include snippets/fastcgi-php.conf;' >> $edith_nginx_site
393
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $edith_nginx_site
394
-    echo '    fastcgi_read_timeout 30;' >> $edith_nginx_site
395
-    echo '  }' >> $edith_nginx_site
396
-    echo '' >> $edith_nginx_site
397
-    echo '  # Location' >> $edith_nginx_site
398
-    echo '  location / {' >> $edith_nginx_site
383
+    nginx_disable_sniffing "$EDITH_DOMAIN_NAME"
384
+    { echo '';
385
+      echo '  access_log /dev/null;';
386
+      echo '  error_log /dev/null;';
387
+      echo '';
388
+      echo "  root /var/www/$EDITH_DOMAIN_NAME/htdocs;";
389
+      echo '';
390
+      echo '  index index.php;';
391
+      echo '';
392
+      echo '  # PHP';
393
+      echo '  location ~ \.php {';
394
+      echo '    include snippets/fastcgi-php.conf;';
395
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
396
+      echo '    fastcgi_read_timeout 30;';
397
+      echo '  }';
398
+      echo '';
399
+      echo '  # Location';
400
+      echo '  location / {'; } >> "$edith_nginx_site"
399 401
     function_check nginx_limits
400 402
     nginx_limits $EDITH_DOMAIN_NAME '15m'
401
-    echo '    try_files $uri $uri/ /index.php?$args;' >> $edith_nginx_site
402
-    echo "    auth_basic \"${EDITH_LOGIN_TEXT}\";" >> $edith_nginx_site
403
-    echo '    auth_basic_user_file /etc/nginx/.edithpasswd;' >> $edith_nginx_site
404
-    echo '  }' >> $edith_nginx_site
405
-    echo '}' >> $edith_nginx_site
403
+    { echo "    try_files \$uri \$uri/ /index.php?\$args;";
404
+      echo "    auth_basic \"${EDITH_LOGIN_TEXT}\";";
405
+      echo '    auth_basic_user_file /etc/nginx/.edithpasswd;';
406
+      echo '  }';
407
+      echo '}'; } >> "$edith_nginx_site"
406 408
 
407 409
     function_check configure_php
408 410
     configure_php
409 411
 
410 412
     function_check create_site_certificate
411
-    create_site_certificate $EDITH_DOMAIN_NAME 'yes'
413
+    create_site_certificate "$EDITH_DOMAIN_NAME" 'yes'
412 414
 
413 415
     # create a password for users
414 416
     if [ ! -f /etc/nginx/.edithpasswd ]; then
@@ -417,24 +419,23 @@ function install_edith {
417 419
     if grep -q "$MY_USERNAME:" /etc/nginx/.edithpasswd; then
418 420
         sed -i "/$MY_USERNAME:/d" /etc/nginx/.edithpasswd
419 421
     fi
420
-    echo -n "$EDITH_PASSWORD" | htpasswd -i -s -c /etc/nginx/.edithpasswd $MY_USERNAME
422
+    echo -n "$EDITH_PASSWORD" | htpasswd -i -s -c /etc/nginx/.edithpasswd "$MY_USERNAME"
421 423
     if [ ! -f /etc/nginx/.edithpasswd ]; then
422 424
         echo $'/etc/nginx/.edithpasswd not found'
423 425
         exit 6537683563
424 426
     fi
425 427
 
426
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a edith -p "$EDITH_PASSWORD"
428
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a edith -p "$EDITH_PASSWORD"
427 429
 
428
-    cp /var/www/$EDITH_DOMAIN_NAME/htdocs/htaccess.example /var/www/$EDITH_DOMAIN_NAME/htdocs/.htaccess
429
-    cd /var/www/$EDITH_DOMAIN_NAME/htdocs
430
+    cp "/var/www/$EDITH_DOMAIN_NAME/htdocs/htaccess.example" "/var/www/$EDITH_DOMAIN_NAME/htdocs/.htaccess"
431
+    cd "/var/www/$EDITH_DOMAIN_NAME/htdocs" || exit 26482468
430 432
     npm install -g coffeescript uglify-js
431
-    cake build
432
-    if [ ! "$?" = "0" ]; then
433
+    if ! cake build; then
433 434
         echo $'Unable to build Edith'
434 435
         exit 7396483635
435 436
     fi
436 437
     cp config.example.php config.php
437
-    if [[ $ONION_ONLY == "no" ]]; then
438
+    if [[ "$ONION_ONLY" == "no" ]]; then
438 439
         sed -i "s|define('EDITH_URI'.*|define('EDITH_URI', 'https://$EDITH_DOMAIN_NAME');|g" config.php
439 440
     else
440 441
         sed -i "s|define('EDITH_URI'.*|define('EDITH_URI', 'http://$EDITH_ONION_HOSTNAME');|g" config.php
@@ -445,20 +446,20 @@ function install_edith {
445 446
 
446 447
     remove_bad_links_edith
447 448
 
448
-    chown -R www-data:www-data /var/www/$EDITH_DOMAIN_NAME/htdocs
449
-    chmod a+w /var/www/$EDITH_DOMAIN_NAME/htdocs/data
450
-    nginx_ensite $EDITH_DAEMON_NAME
449
+    chown -R www-data:www-data "/var/www/$EDITH_DOMAIN_NAME/htdocs"
450
+    chmod a+w "/var/www/$EDITH_DOMAIN_NAME/htdocs/data"
451
+    nginx_ensite "$EDITH_DAEMON_NAME"
451 452
     systemctl restart nginx
452 453
 
453 454
     APP_INSTALLED=1
454 455
 }
455 456
 
456 457
 function install_interactive_edith {
457
-    if [ ! $ONION_ONLY ]; then
458
+    if [ ! "$ONION_ONLY" ]; then
458 459
         ONION_ONLY='no'
459 460
     fi
460 461
 
461
-    if [[ $ONION_ONLY != "no" ]]; then
462
+    if [[ "$ONION_ONLY" != "no" ]]; then
462 463
         GHOST_DOMAIN_NAME='edith.local'
463 464
         write_config_param "EDITH_DOMAIN_NAME" "$EDITH_DOMAIN_NAME"
464 465
     else

+ 147
- 145
src/freedombone-app-emacs Просмотреть файл

@@ -57,13 +57,13 @@ function backup_local_emacs {
57 57
     for d in /home/*/ ; do
58 58
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
59 59
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
60
-            if [ -d /home/$USERNAME/.emacs.d ]; then
60
+            if [ -d "/home/$USERNAME/.emacs.d" ]; then
61 61
                 echo $"Backing up Emacs config for $USERNAME"
62
-                if [ -f /home/$USERNAME/.emacs ]; then
63
-                    cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
62
+                if [ -f "/home/$USERNAME/.emacs" ]; then
63
+                    cp "/home/$USERNAME/.emacs" "/home/$USERNAME/.emacs.d/dotemacs"
64 64
                 fi
65 65
                 function_check backup_directory_to_usb
66
-                backup_directory_to_usb /home/$USERNAME/.emacs.d emacs/$USERNAME
66
+                backup_directory_to_usb "/home/$USERNAME/.emacs.d" "emacs/$USERNAME"
67 67
             fi
68 68
         fi
69 69
     done
@@ -71,24 +71,25 @@ function backup_local_emacs {
71 71
 
72 72
 function restore_local_emacs {
73 73
     temp_restore_dir=/root/tempemacs
74
-    if [ -d $USB_MOUNT/backup/emacs ]; then
74
+    if [ -d "$USB_MOUNT/backup/emacs" ]; then
75 75
         for d in $USB_MOUNT/backup/emacs/*/ ; do
76 76
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
77 77
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
78
-                if [ ! -d /home/$USERNAME ]; then
79
-                    ${PROJECT_NAME}-adduser $USERNAME
78
+                if [ ! -d "/home/$USERNAME" ]; then
79
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
80 80
                 fi
81 81
                 echo $"Restoring Emacs config for $USERNAME"
82 82
                 function_check restore_directory_from_usb
83
-                restore_directory_from_usb $temp_restore_dir emacs/$USERNAME
84
-                if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
85
-                    cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
83
+                restore_directory_from_usb "$temp_restore_dir" "emacs/$USERNAME"
84
+                if [ -d "$temp_restore_dir/home/$USERNAME/.emacs.d" ]; then
85
+                    cp -r "$temp_restore_dir/home/$USERNAME/.emacs.d" "/home/$USERNAME/"
86 86
                 else
87
-                    if [ ! -d /home/$USERNAME/.emacs.d ]; then
88
-                        mkdir /home/$USERNAME/.emacs.d
87
+                    if [ ! -d "/home/$USERNAME/.emacs.d" ]; then
88
+                        mkdir "/home/$USERNAME/.emacs.d"
89 89
                     fi
90
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.emacs.d
90
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.emacs.d"
91 91
                 fi
92
+                # shellcheck disable=SC2181
92 93
                 if [ ! "$?" = "0" ]; then
93 94
                     rm -rf $temp_restore_dir
94 95
                     function_check set_user_permissions
@@ -97,10 +98,10 @@ function restore_local_emacs {
97 98
                     backup_unmount_drive
98 99
                     exit 664
99 100
                 fi
100
-                if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
101
-                    cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
101
+                if [ -d "$temp_restore_dir/home/$USERNAME/.emacs.d" ]; then
102
+                    cp -f "$temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs" "/home/$USERNAME/.emacs"
102 103
                 else
103
-                    cp -f $temp_restore_dir/dotemacs /home/$USERNAME/.emacs
104
+                    cp -f "$temp_restore_dir/dotemacs" "/home/$USERNAME/.emacs"
104 105
                 fi
105 106
                 rm -rf $temp_restore_dir
106 107
             fi
@@ -112,13 +113,13 @@ function backup_remote_emacs {
112 113
     for d in /home/*/ ; do
113 114
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
114 115
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
115
-            if [ -d /home/$USERNAME/.emacs.d ]; then
116
+            if [ -d "/home/$USERNAME/.emacs.d" ]; then
116 117
                 echo $"Backing up Emacs config for $USERNAME"
117
-                if [ -f /home/$USERNAME/.emacs ]; then
118
-                    cp /home/$USERNAME/.emacs /home/$USERNAME/.emacs.d/dotemacs
118
+                if [ -f "/home/$USERNAME/.emacs" ]; then
119
+                    cp "/home/$USERNAME/.emacs" "/home/$USERNAME/.emacs.d/dotemacs"
119 120
                 fi
120 121
                 function_check backup_directory_to_friend
121
-                backup_directory_to_friend /home/$USERNAME/.emacs.d emacs/$USERNAME
122
+                backup_directory_to_friend "/home/$USERNAME/.emacs.d" "emacs/$USERNAME"
122 123
             fi
123 124
         fi
124 125
     done
@@ -126,24 +127,25 @@ function backup_remote_emacs {
126 127
 
127 128
 function restore_remote_emacs {
128 129
     temp_restore_dir=/root/tempemacs
129
-    if [ -d $USB_MOUNT/backup/emacs ]; then
130
+    if [ -d "$USB_MOUNT/backup/emacs" ]; then
130 131
         for d in $USB_MOUNT/backup/emacs/*/ ; do
131 132
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
132 133
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
133
-                if [ ! -d /home/$USERNAME ]; then
134
-                    ${PROJECT_NAME}-adduser $USERNAME
134
+                if [ ! -d "/home/$USERNAME" ]; then
135
+                    "${PROJECT_NAME}-adduser" "$USERNAME"
135 136
                 fi
136 137
                 echo $"Restoring Emacs config for $USERNAME"
137 138
                 function_check restore_directory_from_friend
138
-                restore_directory_from_friend $temp_restore_dir emacs/$USERNAME
139
-                if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
140
-                    cp -r $temp_restore_dir/home/$USERNAME/.emacs.d /home/$USERNAME/
139
+                restore_directory_from_friend "$temp_restore_dir" "emacs/$USERNAME"
140
+                if [ -d "$temp_restore_dir/home/$USERNAME/.emacs.d" ]; then
141
+                    cp -r "$temp_restore_dir/home/$USERNAME/.emacs.d" "/home/$USERNAME/"
141 142
                 else
142
-                    if [ ! -d /home/$USERNAME/.emacs.d ]; then
143
-                        mkdir /home/$USERNAME/.emacs.d
143
+                    if [ ! -d "/home/$USERNAME/.emacs.d" ]; then
144
+                        mkdir "/home/$USERNAME/.emacs.d"
144 145
                     fi
145
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.emacs.d/*
146
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.emacs.d/*"
146 147
                 fi
148
+                # shellcheck disable=SC2181
147 149
                 if [ ! "$?" = "0" ]; then
148 150
                     rm -rf $temp_restore_dir
149 151
                     function_check set_user_permissions
@@ -152,10 +154,10 @@ function restore_remote_emacs {
152 154
                     backup_unmount_drive
153 155
                     exit 664
154 156
                 fi
155
-                if [ -d $temp_restore_dir/home/$USERNAME/.emacs.d ]; then
156
-                    cp -f $temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs /home/$USERNAME/.emacs
157
+                if [ -d "$temp_restore_dir/home/$USERNAME/.emacs.d" ]; then
158
+                    cp -f "$temp_restore_dir/home/$USERNAME/.emacs.d/dotemacs" "/home/$USERNAME/.emacs"
157 159
                 else
158
-                    cp -f $temp_restore_dir/dotemacs /home/$USERNAME/.emacs
160
+                    cp -f "$temp_restore_dir/dotemacs" "/home/$USERNAME/.emacs"
159 161
                 fi
160 162
                 rm -rf $temp_restore_dir
161 163
             fi
@@ -166,7 +168,7 @@ function restore_remote_emacs {
166 168
 function remove_emacs {
167 169
     apt-get -yq remove --purge emacs
168 170
     update-alternatives --set editor /usr/bin/nano
169
-    sed -i '/install_emacs/d' $COMPLETION_FILE
171
+    sed -i '/install_emacs/d' "$COMPLETION_FILE"
170 172
 
171 173
     # remove emacs as the mutt email editor
172 174
     if [ -f /etc/Muttrc ]; then
@@ -176,9 +178,9 @@ function remove_emacs {
176 178
         for d in /home/*/ ; do
177 179
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
178 180
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
179
-                if [ -f /home/$USERNAME/.muttrc ]; then
180
-                    if grep -q "set editor=" /home/$USERNAME/.muttrc; then
181
-                        sed -i '/set editor=/d' /home/$USERNAME/.muttrc
181
+                if [ -f "/home/$USERNAME/.muttrc" ]; then
182
+                    if grep -q "set editor=" "/home/$USERNAME/.muttrc"; then
183
+                        sed -i '/set editor=/d' "/home/$USERNAME/.muttrc"
182 184
                     fi
183 185
                 fi
184 186
             fi
@@ -194,74 +196,74 @@ function install_emacs {
194 196
     #echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
195 197
     #echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
196 198
     #echo '' >> /home/$MY_USERNAME/.emacs
197
-    echo $';; ===== Remove trailing whitepace ======================================' >> /home/$MY_USERNAME/.emacs
198
-    echo '' >> /home/$MY_USERNAME/.emacs
199
-    echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)" >> /home/$MY_USERNAME/.emacs
200
-    echo '' >> /home/$MY_USERNAME/.emacs
201
-    echo ';; Goto a line number with CTRL-l' >> /home/$MY_USERNAME/.emacs
202
-    echo -n '(global-set-key "\C-l" ' >> /home/$MY_USERNAME/.emacs
203
-    echo "'goto-line)" >> /home/$MY_USERNAME/.emacs
204
-    echo '' >> /home/$MY_USERNAME/.emacs
205
-    echo $';; ===== Show line numbers ==============================================' >> /home/$MY_USERNAME/.emacs
206
-    echo '' >> /home/$MY_USERNAME/.emacs
207
-    echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))" >> /home/$MY_USERNAME/.emacs
208
-    echo '' >> /home/$MY_USERNAME/.emacs
209
-    echo $';; ===== Enable line wrapping in org-mode ===============================' >> /home/$MY_USERNAME/.emacs
210
-    echo '' >> /home/$MY_USERNAME/.emacs
211
-    echo " (add-hook 'org-mode-hook" >> /home/$MY_USERNAME/.emacs
212
-    echo "           '(lambda ()" >> /home/$MY_USERNAME/.emacs
213
-    echo "              (visual-line-mode 1)))" >> /home/$MY_USERNAME/.emacs
214
-    echo '' >> /home/$MY_USERNAME/.emacs
215
-    echo $';; ===== Enable shift select in org mode ================================' >> /home/$MY_USERNAME/.emacs
216
-    echo '' >> /home/$MY_USERNAME/.emacs
217
-    echo '(setq org-support-shift-select t)' >> /home/$MY_USERNAME/.emacs
218
-    echo '' >> /home/$MY_USERNAME/.emacs
219
-    echo $';; ===== Set standard indent to 4 rather that 4 =========================' >> /home/$MY_USERNAME/.emacs
220
-    echo '' >> /home/$MY_USERNAME/.emacs
221
-    echo '(setq standard-indent 4)' >> /home/$MY_USERNAME/.emacs
222
-    echo '(setq-default tab-width 4)' >> /home/$MY_USERNAME/.emacs
223
-    echo '(setq c-basic-offset 4)' >> /home/$MY_USERNAME/.emacs
224
-    echo '' >> /home/$MY_USERNAME/.emacs
225
-    echo $';; ===== Support Wheel Mouse Scrolling ==================================' >> /home/$MY_USERNAME/.emacs
226
-    echo '' >> /home/$MY_USERNAME/.emacs
227
-    echo '(mouse-wheel-mode t)' >> /home/$MY_USERNAME/.emacs
228
-    echo '' >> /home/$MY_USERNAME/.emacs
229
-    echo $';; ===== Place Backup Files in Specific Directory =======================' >> /home/$MY_USERNAME/.emacs
230
-    echo '' >> /home/$MY_USERNAME/.emacs
231
-    echo '(setq make-backup-files t)' >> /home/$MY_USERNAME/.emacs
232
-    echo '(setq version-control t)' >> /home/$MY_USERNAME/.emacs
233
-    echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$MY_USERNAME/.emacs
234
-    echo '' >> /home/$MY_USERNAME/.emacs
235
-    echo $';; ===== Make Text mode the default mode for new buffers ================' >> /home/$MY_USERNAME/.emacs
236
-    echo '' >> /home/$MY_USERNAME/.emacs
237
-    echo "(setq default-major-mode 'text-mode)" >> /home/$MY_USERNAME/.emacs
238
-    echo '' >> /home/$MY_USERNAME/.emacs
239
-    echo $';; ===== Line length ====================================================' >> /home/$MY_USERNAME/.emacs
240
-    echo '' >> /home/$MY_USERNAME/.emacs
241
-    echo '(setq-default fill-column 72)' >> /home/$MY_USERNAME/.emacs
242
-    echo '' >> /home/$MY_USERNAME/.emacs
243
-    echo $';; ===== Enable Line and Column Numbering ===============================' >> /home/$MY_USERNAME/.emacs
244
-    echo '' >> /home/$MY_USERNAME/.emacs
245
-    echo '(line-number-mode 1)' >> /home/$MY_USERNAME/.emacs
246
-    echo '(column-number-mode 1)' >> /home/$MY_USERNAME/.emacs
247
-    echo '' >> /home/$MY_USERNAME/.emacs
248
-    echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============' >> /home/$MY_USERNAME/.emacs
249
-    echo '' >> /home/$MY_USERNAME/.emacs
250
-    echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of' >> /home/$MY_USERNAME/.emacs
251
-    echo ';; newlines when the cursor goes over the column limit.' >> /home/$MY_USERNAME/.emacs
252
-    echo '' >> /home/$MY_USERNAME/.emacs
253
-    echo ';; This should actually turn on auto-fill-mode by default in all major' >> /home/$MY_USERNAME/.emacs
254
-    echo ';; modes. The other way to do this is to turn on the fill for specific modes' >> /home/$MY_USERNAME/.emacs
255
-    echo ';; via hooks.' >> /home/$MY_USERNAME/.emacs
256
-    echo '' >> /home/$MY_USERNAME/.emacs
257
-    echo '(setq auto-fill-mode 1)' >> /home/$MY_USERNAME/.emacs
258
-    echo '' >> /home/$MY_USERNAME/.emacs
259
-    echo $';; ===== Enable GPG encryption =========================================' >> /home/$MY_USERNAME/.emacs
260
-    echo '' >> /home/$MY_USERNAME/.emacs
261
-    echo "(require 'epa)" >> /home/$MY_USERNAME/.emacs
262
-    echo '(epa-file-enable)' >> /home/$MY_USERNAME/.emacs
263
-    cp /home/$MY_USERNAME/.emacs /root/.emacs
264
-    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
199
+    { echo $';; ===== Remove trailing whitepace ======================================';
200
+      echo '';
201
+      echo ";;(add-hook 'before-save-hook 'delete-trailing-whitespace)";
202
+      echo '';
203
+      echo ';; Goto a line number with CTRL-l';
204
+      echo -n '(global-set-key "\C-l" ';
205
+      echo "'goto-line)";
206
+      echo '';
207
+      echo $';; ===== Show line numbers ==============================================';
208
+      echo '';
209
+      echo "(add-hook 'find-file-hook (lambda () (linum-mode 1)))";
210
+      echo '';
211
+      echo $';; ===== Enable line wrapping in org-mode ===============================';
212
+      echo '';
213
+      echo " (add-hook 'org-mode-hook";
214
+      echo "           '(lambda ()";
215
+      echo "              (visual-line-mode 1)))";
216
+      echo '';
217
+      echo $';; ===== Enable shift select in org mode ================================';
218
+      echo '';
219
+      echo '(setq org-support-shift-select t)';
220
+      echo '';
221
+      echo $';; ===== Set standard indent to 4 rather that 4 =========================';
222
+      echo '';
223
+      echo '(setq standard-indent 4)';
224
+      echo '(setq-default tab-width 4)';
225
+      echo '(setq c-basic-offset 4)';
226
+      echo '';
227
+      echo $';; ===== Support Wheel Mouse Scrolling ==================================';
228
+      echo '';
229
+      echo '(mouse-wheel-mode t)';
230
+      echo '';
231
+      echo $';; ===== Place Backup Files in Specific Directory =======================';
232
+      echo '';
233
+      echo '(setq make-backup-files t)';
234
+      echo '(setq version-control t)';
235
+      echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))';
236
+      echo '';
237
+      echo $';; ===== Make Text mode the default mode for new buffers ================';
238
+      echo '';
239
+      echo "(setq default-major-mode 'text-mode)";
240
+      echo '';
241
+      echo $';; ===== Line length ====================================================';
242
+      echo '';
243
+      echo '(setq-default fill-column 72)';
244
+      echo '';
245
+      echo $';; ===== Enable Line and Column Numbering ===============================';
246
+      echo '';
247
+      echo '(line-number-mode 1)';
248
+      echo '(column-number-mode 1)';
249
+      echo '';
250
+      echo $';; ===== Turn on Auto Fill mode automatically in all modes ==============';
251
+      echo '';
252
+      echo ';; Auto-fill-mode the the automatic wrapping of lines and insertion of';
253
+      echo ';; newlines when the cursor goes over the column limit.';
254
+      echo '';
255
+      echo ';; This should actually turn on auto-fill-mode by default in all major';
256
+      echo ';; modes. The other way to do this is to turn on the fill for specific modes';
257
+      echo ';; via hooks.';
258
+      echo '';
259
+      echo '(setq auto-fill-mode 1)';
260
+      echo '';
261
+      echo $';; ===== Enable GPG encryption =========================================';
262
+      echo '';
263
+      echo "(require 'epa)";
264
+      echo '(epa-file-enable)'; } >> "/home/$MY_USERNAME/.emacs"
265
+    cp "/home/$MY_USERNAME/.emacs" /root/.emacs
266
+    chown "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.emacs"
265 267
 
266 268
     # add a mutt entry to use emacs to compose emails
267 269
     if [ -f /etc/Muttrc ]; then
@@ -273,92 +275,92 @@ function install_emacs {
273 275
         for d in /home/*/ ; do
274 276
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
275 277
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
276
-                if [ -f /home/$USERNAME/.muttrc ]; then
277
-                    if ! grep -q "set editor=" /home/$USERNAME/.muttrc; then
278
-                        echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> /home/$USERNAME/.muttrc
278
+                if [ -f "/home/$USERNAME/.muttrc" ]; then
279
+                    if ! grep -q "set editor=" "/home/$USERNAME/.muttrc"; then
280
+                        echo 'set editor="emacs -q --load ~/.emacs-mutt"' >> "/home/$USERNAME/.muttrc"
279 281
                     else
280
-                        sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' /home/$USERNAME/.muttrc
282
+                        sed -i 's|set editor=.*|set editor="emacs -q --load ~/.emacs-mutt"|g' "/home/$USERNAME/.muttrc"
281 283
                     fi
282 284
                 fi
283 285
 
284 286
                 # create an Emacs configuration specifically for use with Mutt, which
285 287
                 # has word wrap and spell checking on by default
286
-                if [ ! -f /home/$USERNAME/.emacs-mutt ]; then
287
-                    echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)" > /home/$USERNAME/.emacs-mutt
288
-                    echo '(setq org-support-shift-select t)' >> /home/$USERNAME/.emacs-mutt
289
-                    echo '(setq standard-indent 4)' >> /home/$USERNAME/.emacs-mutt
290
-                    echo '(setq-default tab-width 4)' >> /home/$USERNAME/.emacs-mutt
291
-                    echo '(setq c-basic-offset 4)' >> /home/$USERNAME/.emacs-mutt
292
-                    echo '(mouse-wheel-mode t)' >> /home/$USERNAME/.emacs-mutt
293
-                    echo '(setq make-backup-files t)' >> /home/$USERNAME/.emacs-mutt
294
-                    echo '(setq version-control t)' >> /home/$USERNAME/.emacs-mutt
295
-                    echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> /home/$USERNAME/.emacs-mutt
296
-                    echo "(setq default-major-mode 'text-mode)" >> /home/$USERNAME/.emacs-mutt
297
-                    echo "(dolist (hook '(text-mode-hook))" >> /home/$USERNAME/.emacs-mutt
298
-                    echo '    (add-hook hook (lambda () (flyspell-mode 1))))' >> /home/$USERNAME/.emacs-mutt
299
-                    echo '(setq-default fill-column 72)' >> /home/$USERNAME/.emacs-mutt
288
+                if [ ! -f "/home/$USERNAME/.emacs-mutt" ]; then
289
+                    { echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)";
290
+                    echo '(setq org-support-shift-select t)';
291
+                    echo '(setq standard-indent 4)';
292
+                    echo '(setq-default tab-width 4)';
293
+                    echo '(setq c-basic-offset 4)';
294
+                    echo '(mouse-wheel-mode t)';
295
+                    echo '(setq make-backup-files t)';
296
+                    echo '(setq version-control t)';
297
+                    echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))';
298
+                    echo "(setq default-major-mode 'text-mode)";
299
+                    echo "(dolist (hook '(text-mode-hook))";
300
+                    echo '    (add-hook hook (lambda () (flyspell-mode 1))))';
301
+                    echo '(setq-default fill-column 72)'; } > "/home/$USERNAME/.emacs-mutt"
300 302
                     if [[ $DEFAULT_LANGUAGE == 'en_US'* ]]; then
301
-                        echo '(setq ispell-dictionary "american")' >> /home/$USERNAME/.emacs-mutt
303
+                        echo '(setq ispell-dictionary "american")' >> "/home/$USERNAME/.emacs-mutt"
302 304
                     fi
303 305
                     if [[ $DEFAULT_LANGUAGE == 'en_GB'* ]]; then
304
-                        echo '(setq ispell-dictionary "british")' >> /home/$USERNAME/.emacs-mutt
306
+                        echo '(setq ispell-dictionary "british")' >> "/home/$USERNAME/.emacs-mutt"
305 307
                     fi
306 308
                     if [[ $DEFAULT_LANGUAGE == 'fr_FR'* ]]; then
307
-                        echo '(setq ispell-dictionary "french")' >> /home/$USERNAME/.emacs-mutt
309
+                        echo '(setq ispell-dictionary "french")' >> "/home/$USERNAME/.emacs-mutt"
308 310
                     fi
309 311
                     if [[ $DEFAULT_LANGUAGE == 'it_IT'* ]]; then
310
-                        echo '(setq ispell-dictionary "italian")' >> /home/$USERNAME/.emacs-mutt
312
+                        echo '(setq ispell-dictionary "italian")' >> "/home/$USERNAME/.emacs-mutt"
311 313
                     fi
312 314
                     if [[ $DEFAULT_LANGUAGE == 'cs_CZ'* ]]; then
313
-                        echo '(setq ispell-dictionary "czech")' >> /home/$USERNAME/.emacs-mutt
315
+                        echo '(setq ispell-dictionary "czech")' >> "/home/$USERNAME/.emacs-mutt"
314 316
                     fi
315 317
                     if [[ $DEFAULT_LANGUAGE == 'da_DK'* ]]; then
316
-                        echo '(setq ispell-dictionary "danish")' >> /home/$USERNAME/.emacs-mutt
318
+                        echo '(setq ispell-dictionary "danish")' >> "/home/$USERNAME/.emacs-mutt"
317 319
                     fi
318 320
                     if [[ $DEFAULT_LANGUAGE == 'nl_NL'* ]]; then
319
-                        echo '(setq ispell-dictionary "dutch")' >> /home/$USERNAME/.emacs-mutt
321
+                        echo '(setq ispell-dictionary "dutch")' >> "/home/$USERNAME/.emacs-mutt"
320 322
                     fi
321 323
                     if [[ $DEFAULT_LANGUAGE == 'ru_RU'* ]]; then
322
-                        echo '(setq ispell-dictionary "russian")' >> /home/$USERNAME/.emacs-mutt
324
+                        echo '(setq ispell-dictionary "russian")' >> "/home/$USERNAME/.emacs-mutt"
323 325
                     fi
324 326
                     if [[ $DEFAULT_LANGUAGE == 'es_ES'* ]]; then
325
-                        echo '(setq ispell-dictionary "spanish")' >> /home/$USERNAME/.emacs-mutt
327
+                        echo '(setq ispell-dictionary "spanish")' >> "/home/$USERNAME/.emacs-mutt"
326 328
                     fi
327 329
                     if [[ $DEFAULT_LANGUAGE == 'sv_SE'* ]]; then
328
-                        echo '(setq ispell-dictionary "swedish")' >> /home/$USERNAME/.emacs-mutt
330
+                        echo '(setq ispell-dictionary "swedish")' >> "/home/$USERNAME/.emacs-mutt"
329 331
                     fi
330 332
                     if [[ $DEFAULT_LANGUAGE == 'no_NO'* ]]; then
331
-                        echo '(setq ispell-dictionary "norwegian")' >> /home/$USERNAME/.emacs-mutt
333
+                        echo '(setq ispell-dictionary "norwegian")' >> "/home/$USERNAME/.emacs-mutt"
332 334
                     fi
333 335
                     if [[ $DEFAULT_LANGUAGE == 'de_DE'* ]]; then
334
-                        echo '(setq ispell-dictionary "ngerman")' >> /home/$USERNAME/.emacs-mutt
336
+                        echo '(setq ispell-dictionary "ngerman")' >> "/home/$USERNAME/.emacs-mutt"
335 337
                     fi
336 338
                     if [[ $DEFAULT_LANGUAGE == 'bg_BG'* ]]; then
337
-                        echo '(setq ispell-dictionary "bulgarian")' >> /home/$USERNAME/.emacs-mutt
339
+                        echo '(setq ispell-dictionary "bulgarian")' >> "/home/$USERNAME/.emacs-mutt"
338 340
                     fi
339 341
                     if [[ $DEFAULT_LANGUAGE == 'pl'* ]]; then
340
-                        echo '(setq ispell-dictionary "polish")' >> /home/$USERNAME/.emacs-mutt
342
+                        echo '(setq ispell-dictionary "polish")' >> "/home/$USERNAME/.emacs-mutt"
341 343
                     fi
342 344
                     if [[ $DEFAULT_LANGUAGE == 'et_EE'* ]]; then
343
-                        echo '(setq ispell-dictionary "estonian")' >> /home/$USERNAME/.emacs-mutt
345
+                        echo '(setq ispell-dictionary "estonian")' >> "/home/$USERNAME/.emacs-mutt"
344 346
                     fi
345 347
                     if [[ $DEFAULT_LANGUAGE == 'lt_LT'* ]]; then
346
-                        echo '(setq ispell-dictionary "lithuanian")' >> /home/$USERNAME/.emacs-mutt
348
+                        echo '(setq ispell-dictionary "lithuanian")' >> "/home/$USERNAME/.emacs-mutt"
347 349
                     fi
348 350
                     if [[ $DEFAULT_LANGUAGE == 'uk_UA'* ]]; then
349
-                        echo '(setq ispell-dictionary "ukranian")' >> /home/$USERNAME/.emacs-mutt
351
+                        echo '(setq ispell-dictionary "ukranian")' >> "/home/$USERNAME/.emacs-mutt"
350 352
                     fi
351 353
                     if [[ $DEFAULT_LANGUAGE == 'ca_ES'* ]]; then
352
-                        echo '(setq ispell-dictionary "catalan")' >> /home/$USERNAME/.emacs-mutt
354
+                        echo '(setq ispell-dictionary "catalan")' >> "/home/$USERNAME/.emacs-mutt"
353 355
                     fi
354
-                    echo '(setq auto-fill-mode 0)' >> /home/$USERNAME/.emacs-mutt
355
-                    echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)" >> /home/$USERNAME/.emacs-mutt
356
-                    echo "(setq-default auto-fill-function 'do-auto-fill)" >> /home/$USERNAME/.emacs-mutt
357
-                    chown $USERNAME:$USERNAME /home/$USERNAME/.emacs-mutt
356
+                    { echo '(setq auto-fill-mode 0)';
357
+                      echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)";
358
+                      echo "(setq-default auto-fill-function 'do-auto-fill)"; } >> "/home/$USERNAME/.emacs-mutt"
359
+                    chown "$USERNAME":"$USERNAME" "/home/$USERNAME/.emacs-mutt"
358 360
 
359 361
                     # add the emacs mutt configuration to the user profile skeleton
360 362
                     if [ ! -f /etc/skel/.emacs-mutt ]; then
361
-                        cp /home/$USERNAME/.emacs-mutt /etc/skel/.emacs-mutt
363
+                        cp "/home/$USERNAME/.emacs-mutt" /etc/skel/.emacs-mutt
362 364
                         chown root:root /etc/skel/.emacs-mutt
363 365
                     fi
364 366
                 fi

+ 243
- 240
src/freedombone-app-etherpad Просмотреть файл

@@ -41,7 +41,7 @@ ETHERPAD_REPO="https://github.com/ether/etherpad-lite"
41 41
 ETHERPAD_COMMIT='454f539561a8d9de51ed107a29d974eb79198bc6'
42 42
 ETHERPAD_ADMIN_PASSWORD=
43 43
 ETHERPAD_TITLE=$'Freedombone Docs'
44
-ETHERPAD_WELCOME_MESSAGE=$"Welcome to ${ETHERPAD_TITLE}!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!"
44
+ETHERPAD_WELCOME_MESSAGE=$"Welcome to ${ETHERPAD_TITLE}!\\n\\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!"
45 45
 
46 46
 etherpad_variables=(ONION_ONLY
47 47
                     DEFAULT_DOMAIN_NAME
@@ -67,109 +67,109 @@ function change_password_etherpad {
67 67
     read_config_param ETHERPAD_DOMAIN_NAME
68 68
 
69 69
     if grep -q "\"$change_username\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then
70
-        user_line=$(cat /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json | grep "\"$change_username\": {")
70
+        user_line=$(grep "\"$change_username\": {" "/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json")
71 71
         if [[ "$user_line" == *"\"is_admin\": true"* ]]; then
72
-            sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": "$new_user_password", \"is_admin\": true }|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
72
+            sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": \"$new_user_password\", \"is_admin\": true }|g" "/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json"
73 73
         else
74
-            sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": "$new_user_password", \"is_admin\": false },|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
74
+            sed -i "s|\"$change_username\": {.*|\"$change_username\": { \"password\": \"$new_user_password\", \"is_admin\": false },|g" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
75 75
         fi
76
-        ${PROJECT_NAME}-pass -u $change_username -a etherpad -p "$2"
76
+        "${PROJECT_NAME}-pass" -u "$change_username" -a etherpad -p "$2"
77 77
         systemctl restart etherpad
78 78
     fi
79 79
 }
80 80
 
81 81
 function etherpad_create_database {
82
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
83
-        ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
82
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
83
+        ETHERPAD_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
84 84
     else
85
-        if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
86
-            ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
85
+        if [ ! "$ETHERPAD_ADMIN_PASSWORD" ]; then
86
+            ETHERPAD_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
87 87
         fi
88 88
     fi
89
-    if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
89
+    if [ ! "$ETHERPAD_ADMIN_PASSWORD" ]; then
90 90
         return
91 91
     fi
92 92
 
93 93
     function_check create_database
94
-    create_database etherpad "$ETHERPAD_ADMIN_PASSWORD" $MY_USERNAME
94
+    create_database etherpad "$ETHERPAD_ADMIN_PASSWORD" "$MY_USERNAME"
95 95
 }
96 96
 
97 97
 function create_etherpad_settings {
98
-    settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
99
-    echo '{' > $settings_file
100
-    echo "  \"title\": \"${ETHERPAD_TITLE}\"," >> $settings_file
101
-    echo '  "favicon": "favicon.ico",' >> $settings_file
102
-
103
-    echo '  "ip": "127.0.0.1",' >> $settings_file
104
-    echo "  \"port\" : ${ETHERPAD_PORT}," >> $settings_file
105
-
106
-    echo '  "showSettingsInAdminPage" : true,' >> $settings_file
107
-    echo '   "dbType" : "mysql",' >> $settings_file
108
-    echo '   "dbSettings" : {' >> $settings_file
109
-    echo '                    "user"    : "root",' >> $settings_file
110
-    echo '                    "host"    : "localhost",' >> $settings_file
111
-    echo "                    \"password\": \"${MARIADB_PASSWORD}\"," >> $settings_file
112
-    echo '                    "database": "etherpad",' >> $settings_file
113
-    echo '                    "charset" : "utf8mb4"' >> $settings_file
114
-    echo '                  },' >> $settings_file
115
-
116
-    echo "  \"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"," >> $settings_file
117
-
118
-    echo '  "padOptions": {' >> $settings_file
119
-    echo '    "noColors": false,' >> $settings_file
120
-    echo '    "showControls": true,' >> $settings_file
121
-    echo '    "showChat": true,' >> $settings_file
122
-    echo '    "showLineNumbers": false,' >> $settings_file
123
-    echo '    "useMonospaceFont": false,' >> $settings_file
124
-    echo '    "userName": false,' >> $settings_file
125
-    echo '    "userColor": true,' >> $settings_file
126
-    echo '    "rtl": false,' >> $settings_file
127
-    echo '    "alwaysShowChat": true,' >> $settings_file
128
-    echo '    "chatAndUsers": true,' >> $settings_file
129
-    echo '    "lang": "en-gb"' >> $settings_file
130
-    echo '  },' >> $settings_file
131
-
132
-    echo '  "suppressErrorsInPadText" : true,' >> $settings_file
133
-    echo '  "requireSession" : false,' >> $settings_file
134
-    echo '  "editOnly" : false,' >> $settings_file
135
-    echo '  "sessionNoPassword" : false,' >> $settings_file
136
-    echo '  "minify" : true,' >> $settings_file
137
-    echo '  "maxAge" : 21600, // 60 * 60 * 6 = 6 hours' >> $settings_file
138
-    echo '  "abiword" : null,' >> $settings_file
139
-    echo '  "soffice" : null,' >> $settings_file
140
-    echo '  "tidyHtml" : null,' >> $settings_file
141
-    echo '  "allowUnknownFileEnds" : false,' >> $settings_file
142
-    echo '  "requireAuthentication" : true,' >> $settings_file
143
-    echo '  "requireAuthorization" : true,' >> $settings_file
144
-    echo '  "trustProxy" : false,' >> $settings_file
145
-    echo '  "disableIPlogging" : true,' >> $settings_file
146
-
147
-    echo '  "users": {' >> $settings_file
148
-    echo "    \"${MY_USERNAME}\": { \"password\": \"${ETHERPAD_ADMIN_PASSWORD}\", \"is_admin\": true }" >> $settings_file
149
-    echo '  },' >> $settings_file
150
-
151
-    echo '  "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],' >> $settings_file
152
-    echo '  "loadTest": false,' >> $settings_file
153
-    echo '  "indentationOnNewLine": false,' >> $settings_file
154
-
155
-    echo '  "toolbar": {' >> $settings_file
156
-    echo '    "left": [' >> $settings_file
157
-    echo '      ["bold", "italic", "underline", "strikethrough"],' >> $settings_file
158
-    echo '      ["orderedlist", "unorderedlist", "indent", "outdent"],' >> $settings_file
159
-    echo '      ["undo", "redo"],' >> $settings_file
160
-    echo '      ["clearauthorship"]' >> $settings_file
161
-    echo '    ],' >> $settings_file
162
-    echo '    "right": [' >> $settings_file
163
-    echo '      ["importexport", "timeslider", "savedrevision"],' >> $settings_file
164
-    echo '      ["settings", "embed"],' >> $settings_file
165
-    echo '      ["showusers"]' >> $settings_file
166
-    echo '    ],' >> $settings_file
167
-    echo '    "timeslider": [' >> $settings_file
168
-    echo '      ["timeslider_export", "timeslider_returnToPad"]' >> $settings_file
169
-    echo '    ]' >> $settings_file
170
-    echo '  },' >> $settings_file
171
-    echo '  "loglevel": "INFO"' >> $settings_file
172
-    echo '}' >> $settings_file
98
+    settings_file="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json"
99
+    { echo '{';
100
+      echo "  \"title\": \"${ETHERPAD_TITLE}\",";
101
+      echo '  "favicon": "favicon.ico",';
102
+
103
+      echo '  "ip": "127.0.0.1",';
104
+      echo "  \"port\" : ${ETHERPAD_PORT},";
105
+
106
+      echo '  "showSettingsInAdminPage" : true,';
107
+      echo '   "dbType" : "mysql",';
108
+      echo '   "dbSettings" : {';
109
+      echo '                    "user"    : "root",';
110
+      echo '                    "host"    : "localhost",';
111
+      echo "                    \"password\": \"${MARIADB_PASSWORD}\",";
112
+      echo '                    "database": "etherpad",';
113
+      echo '                    "charset" : "utf8mb4"';
114
+      echo '                  },';
115
+
116
+      echo "  \"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\",";
117
+
118
+      echo '  "padOptions": {';
119
+      echo '    "noColors": false,';
120
+      echo '    "showControls": true,';
121
+      echo '    "showChat": true,';
122
+      echo '    "showLineNumbers": false,';
123
+      echo '    "useMonospaceFont": false,';
124
+      echo '    "userName": false,';
125
+      echo '    "userColor": true,';
126
+      echo '    "rtl": false,';
127
+      echo '    "alwaysShowChat": true,';
128
+      echo '    "chatAndUsers": true,';
129
+      echo '    "lang": "en-gb"';
130
+      echo '  },';
131
+
132
+      echo '  "suppressErrorsInPadText" : true,';
133
+      echo '  "requireSession" : false,';
134
+      echo '  "editOnly" : false,';
135
+      echo '  "sessionNoPassword" : false,';
136
+      echo '  "minify" : true,';
137
+      echo '  "maxAge" : 21600, // 60 * 60 * 6 = 6 hours';
138
+      echo '  "abiword" : null,';
139
+      echo '  "soffice" : null,';
140
+      echo '  "tidyHtml" : null,';
141
+      echo '  "allowUnknownFileEnds" : false,';
142
+      echo '  "requireAuthentication" : true,';
143
+      echo '  "requireAuthorization" : true,';
144
+      echo '  "trustProxy" : false,';
145
+      echo '  "disableIPlogging" : true,';
146
+
147
+      echo '  "users": {';
148
+      echo "    \"${MY_USERNAME}\": { \"password\": \"${ETHERPAD_ADMIN_PASSWORD}\", \"is_admin\": true }";
149
+      echo '  },';
150
+
151
+      echo '  "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],';
152
+      echo '  "loadTest": false,';
153
+      echo '  "indentationOnNewLine": false,';
154
+
155
+      echo '  "toolbar": {';
156
+      echo '    "left": [';
157
+      echo '      ["bold", "italic", "underline", "strikethrough"],';
158
+      echo '      ["orderedlist", "unorderedlist", "indent", "outdent"],';
159
+      echo '      ["undo", "redo"],';
160
+      echo '      ["clearauthorship"]';
161
+      echo '    ],';
162
+      echo '    "right": [';
163
+      echo '      ["importexport", "timeslider", "savedrevision"],';
164
+      echo '      ["settings", "embed"],';
165
+      echo '      ["showusers"]';
166
+      echo '    ],';
167
+      echo '    "timeslider": [';
168
+      echo '      ["timeslider_export", "timeslider_returnToPad"]';
169
+      echo '    ]';
170
+      echo '  },';
171
+      echo '  "loglevel": "INFO"';
172
+      echo '}'; } > $settings_file
173 173
     chmod 600 $settings_file
174 174
 }
175 175
 
@@ -177,7 +177,7 @@ function remove_user_etherpad {
177 177
     remove_username="$1"
178 178
     settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
179 179
 
180
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp etherpad
180
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp etherpad
181 181
 
182 182
     if grep -q "\"$remove_username\": {" $settings_file; then
183 183
         sed -i "/\"$remove_username\": {/d" $settings_file
@@ -191,7 +191,7 @@ function add_user_etherpad {
191 191
     settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
192 192
 
193 193
     if ! grep -q "\"$new_username\": {" $settings_file; then
194
-        ${PROJECT_NAME}-pass -u $new_username -a etherpad -p "$2"
194
+        "${PROJECT_NAME}-pass" -u "$new_username" -a etherpad -p "$2"
195 195
         sed -i "/\"users\": {/a    \"$new_username\": { \"password\": \"$new_user_password\", \"is_admin\": false }," $settings_file
196 196
         if grep -q "\"$new_username\": {" $settings_file; then
197 197
             systemctl restart etherpad
@@ -204,11 +204,11 @@ function add_user_etherpad {
204 204
 }
205 205
 
206 206
 function install_interactive_etherpad {
207
-    if [ ! $ONION_ONLY ]; then
207
+    if [ ! "$ONION_ONLY" ]; then
208 208
         ONION_ONLY='no'
209 209
     fi
210 210
 
211
-    if [[ $ONION_ONLY != "no" ]]; then
211
+    if [[ "$ONION_ONLY" != "no" ]]; then
212 212
         ETHERPAD_DOMAIN_NAME='etherpad.local'
213 213
         write_config_param "ETHERPAD_DOMAIN_NAME" "$ETHERPAD_DOMAIN_NAME"
214 214
     else
@@ -220,18 +220,17 @@ function install_interactive_etherpad {
220 220
 
221 221
 function etherpad_set_title {
222 222
     read_config_param "ETHERPAD_TITLE"
223
-    data=$(tempfile 2>/dev/null)
224
-    trap "rm -f $data" 0 1 2 5 15
223
+    data=$(mktemp 2>/dev/null)
225 224
     dialog --title $"Etherpad Title" \
226 225
            --backtitle $"Freedombone Control Panel" \
227
-           --inputbox $'Set a title for your etherpad system' 10 60 "$ETHERPAD_TITLE" 2>$data
226
+           --inputbox $'Set a title for your etherpad system' 10 60 "$ETHERPAD_TITLE" 2>"$data"
228 227
     sel=$?
229 228
     case $sel in
230 229
         0)
231
-            temp_title=$(<$data)
230
+            temp_title=$(<"$data")
232 231
             if [ ${#temp_title} -gt 0 ]; then
233 232
                 ETHERPAD_TITLE="$temp_title"
234
-                settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
233
+                settings_file="/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json"
235 234
 
236 235
                 write_config_param "ETHERPAD_TITLE" "$ETHERPAD_TITLE"
237 236
                 sed -i "s|\"title\":.*|\"title\": \"${ETHERPAD_TITLE}\"|g" $settings_file
@@ -241,22 +240,22 @@ function etherpad_set_title {
241 240
             fi
242 241
            ;;
243 242
     esac
243
+    rm -f "$data"
244 244
 }
245 245
 
246 246
 function etherpad_set_welcome_message {
247 247
     read_config_param "ETHERPAD_WELCOME_MESSAGE"
248
-    data=$(tempfile 2>/dev/null)
249
-    trap "rm -f $data" 0 1 2 5 15
248
+    data=$(mktemp 2>/dev/null)
250 249
     dialog --title $"Etherpad Welcome Message" \
251 250
            --backtitle $"Freedombone Control Panel" \
252
-           --inputbox $'Set a welcome message, which can include html formatting' 10 60 "$ETHERPAD_WELCOME_MESSAGE" 2>$data
251
+           --inputbox $'Set a welcome message, which can include html formatting' 10 60 "$ETHERPAD_WELCOME_MESSAGE" 2>"$data"
253 252
     sel=$?
254 253
     case $sel in
255 254
         0)
256
-            temp_welcome=$(<$data)
255
+            temp_welcome=$(<"$data")
257 256
             if [ ${#temp_welcome} -gt 0 ]; then
258 257
                 ETHERPAD_WELCOME_MESSAGE="$temp_welcome"
259
-                settings_file=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json
258
+                settings_file="/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/settings.json"
260 259
 
261 260
                 write_config_param "ETHERPAD_WELCOME_MESSAGE" "$ETHERPAD_WELCOME_MESSAGE"
262 261
                 sed -i "s|\"defaultPadText\" :.*|\"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"|g" $settings_file
@@ -266,29 +265,33 @@ function etherpad_set_welcome_message {
266 265
             fi
267 266
            ;;
268 267
     esac
268
+    rm -f "$data"
269 269
 }
270 270
 
271 271
 function configure_interactive_etherpad {
272 272
     while true
273 273
     do
274
-        data=$(tempfile 2>/dev/null)
275
-        trap "rm -f $data" 0 1 2 5 15
274
+        data=$(mktemp 2>/dev/null)
276 275
         dialog --backtitle $"Freedombone Control Panel" \
277 276
                --title $"Etherpad Settings" \
278 277
                --radiolist $"Choose an operation:" 12 70 3 \
279 278
                1 $"Set Title" off \
280 279
                2 $"Set a welcome message" off \
281
-               3 $"Exit" on 2> $data
280
+               3 $"Exit" on 2> "$data"
282 281
         sel=$?
283 282
         case $sel in
284
-            1) return;;
285
-            255) return;;
283
+            1) rm -f "$data"
284
+               return;;
285
+            255) rm -f "$data"
286
+                 return;;
286 287
         esac
287
-        case $(cat $data) in
288
+        case $(cat "$data") in
288 289
             1) etherpad_set_title;;
289 290
             2) etherpad_set_welcome_message;;
290
-            3) break;;
291
+            3) rm -f "$data"
292
+               break;;
291 293
         esac
294
+        rm -f "$data"
292 295
     done
293 296
 }
294 297
 
@@ -311,18 +314,18 @@ function upgrade_etherpad {
311 314
 
312 315
 function backup_local_etherpad {
313 316
     ETHERPAD_DOMAIN_NAME='etherpad'
314
-    if grep -q "etherpad domain" $COMPLETION_FILE; then
317
+    if grep -q "etherpad domain" "$COMPLETION_FILE"; then
315 318
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
316 319
     fi
317 320
 
318 321
     source_directory=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
319
-    if [ -d $source_directory ]; then
322
+    if [ -d "$source_directory" ]; then
320 323
         dest_directory=etherpad
321 324
         function_check suspend_site
322
-        suspend_site ${ETHERPAD_DOMAIN_NAME}
325
+        suspend_site "${ETHERPAD_DOMAIN_NAME}"
323 326
 
324 327
         function_check backup_directory_to_usb
325
-        backup_directory_to_usb $source_directory $dest_directory
328
+        backup_directory_to_usb "$source_directory" "$dest_directory"
326 329
 
327 330
         function_check backup_database_to_usb
328 331
         backup_database_to_usb etherpad
@@ -333,50 +336,50 @@ function backup_local_etherpad {
333 336
 }
334 337
 
335 338
 function restore_local_etherpad {
336
-    if ! grep -q "etherpad domain" $COMPLETION_FILE; then
339
+    if ! grep -q "etherpad domain" "$COMPLETION_FILE"; then
337 340
         return
338 341
     fi
339 342
     ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
340
-    if [ $ETHERPAD_DOMAIN_NAME ]; then
343
+    if [ "$ETHERPAD_DOMAIN_NAME" ]; then
341 344
         temp_restore_dir=/root/tempetherpad
342
-        etherpad_dir=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
345
+        #etherpad_dir="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs"
343 346
 
344 347
         function_check etherpad_create_database
345 348
         etherpad_create_database
346 349
 
347
-        restore_database etherpad ${ETHERPAD_DOMAIN_NAME}
350
+        restore_database etherpad "${ETHERPAD_DOMAIN_NAME}"
348 351
         if [ -d $temp_restore_dir ]; then
349 352
             rm -rf $temp_restore_dir
350 353
         fi
351 354
 
352
-        chown -R etherpad: /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
353
-        if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
354
-            chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
355
+        chown -R etherpad: "/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs"
356
+        if [ -f "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem" ]; then
357
+            chown etherpad: "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem"
355 358
         fi
356
-        if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
357
-            chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
359
+        if [ -f "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" ]; then
360
+            chown etherpad: "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key"
358 361
         fi
359 362
 
360
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
361
-        settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
362
-        sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" $settings_file
363
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
364
+        settings_file="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json"
365
+        sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" "$settings_file"
363 366
         MARIADB_PASSWORD=
364 367
     fi
365 368
 }
366 369
 
367 370
 function backup_remote_etherpad {
368
-    if grep -q "etherpad domain" $COMPLETION_FILE; then
371
+    if grep -q "etherpad domain" "$COMPLETION_FILE"; then
369 372
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
370
-        temp_backup_dir=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
371
-        if [ -d $temp_backup_dir ]; then
373
+        temp_backup_dir="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs"
374
+        if [ -d "$temp_backup_dir" ]; then
372 375
             function_check suspend_site
373
-            suspend_site ${ETHERPAD_DOMAIN_NAME}
376
+            suspend_site "${ETHERPAD_DOMAIN_NAME}"
374 377
 
375 378
             function_check backup_database_to_friend
376 379
             backup_database_to_friend etherpad
377 380
 
378 381
             function_check backup_directory_to_friend
379
-            backup_directory_to_friend $temp_backup_dir etherpad
382
+            backup_directory_to_friend "$temp_backup_dir" etherpad
380 383
 
381 384
             function_check restart_site
382 385
             restart_site
@@ -387,29 +390,29 @@ function backup_remote_etherpad {
387 390
 }
388 391
 
389 392
 function restore_remote_etherpad {
390
-    if grep -q "etherpad domain" $COMPLETION_FILE; then
393
+    if grep -q "etherpad domain" "$COMPLETION_FILE"; then
391 394
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
392 395
 
393 396
         function_check etherpad_create_database
394 397
         etherpad_create_database
395 398
 
396 399
         function_check restore_database_from_friend
397
-        restore_database_from_friend etherpad ${ETHERPAD_DOMAIN_NAME}
400
+        restore_database_from_friend etherpad "${ETHERPAD_DOMAIN_NAME}"
398 401
         if [ -d /root/tempetherpad ]; then
399 402
             rm -rf /root/tempetherpad
400 403
         fi
401 404
 
402
-        chown -R etherpad: /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
403
-        if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
404
-            chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
405
+        chown -R etherpad: "/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs"
406
+        if [ -f "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem" ]; then
407
+            chown etherpad: "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem"
405 408
         fi
406
-        if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
407
-            chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
409
+        if [ -f "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" ]; then
410
+            chown etherpad: "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key"
408 411
         fi
409 412
 
410
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
411
-        settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
412
-        sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" $settings_file
413
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
414
+        settings_file="/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json"
415
+        sed -i "s|\"password\":.*|\"password\": \"${MARIADB_PASSWORD}\",|g" "$settings_file"
413 416
         MARIADB_PASSWORD=
414 417
     fi
415 418
 }
@@ -427,13 +430,13 @@ function remove_etherpad {
427 430
         rm /etc/systemd/system/etherpad.service
428 431
     fi
429 432
     systemctl daemon-reload
430
-    nginx_dissite $ETHERPAD_DOMAIN_NAME
431
-    remove_certs $ETHERPAD_DOMAIN_NAME
432
-    if [ -d /var/www/$ETHERPAD_DOMAIN_NAME ]; then
433
-        rm -rf /var/www/$ETHERPAD_DOMAIN_NAME
433
+    nginx_dissite "$ETHERPAD_DOMAIN_NAME"
434
+    remove_certs "$ETHERPAD_DOMAIN_NAME"
435
+    if [ -d "/var/www/$ETHERPAD_DOMAIN_NAME" ]; then
436
+        rm -rf "/var/www/$ETHERPAD_DOMAIN_NAME"
434 437
     fi
435
-    if [ -f /etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME ]; then
436
-        rm /etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
438
+    if [ -f "/etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME" ]; then
439
+        rm "/etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME"
437 440
     fi
438 441
     function_check drop_database
439 442
     drop_database etherpad
@@ -441,7 +444,7 @@ function remove_etherpad {
441 444
     remove_onion_service etherpad ${ETHERPAD_ONION_PORT}
442 445
     remove_app etherpad
443 446
     remove_completion_param install_etherpad
444
-    sed -i '/etherpad/d' $COMPLETION_FILE
447
+    sed -i '/etherpad/d' "$COMPLETION_FILE"
445 448
     remove_backup_database_local etherpad
446 449
     remove_nodejs etherpad
447 450
 
@@ -449,22 +452,22 @@ function remove_etherpad {
449 452
     userdel -r etherpad
450 453
 
451 454
     function_check remove_ddns_domain
452
-    remove_ddns_domain $ETHERPAD_DOMAIN_NAME
455
+    remove_ddns_domain "$ETHERPAD_DOMAIN_NAME"
453 456
 }
454 457
 
455 458
 function install_etherpad {
456
-    if [ ! $ETHERPAD_DOMAIN_NAME ]; then
459
+    if [ ! "$ETHERPAD_DOMAIN_NAME" ]; then
457 460
         echo $'No domain name was given for etherpad'
458 461
         exit 7359
459 462
     fi
460 463
 
461 464
     check_ram_availability 2000
462 465
 
463
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
464
-        ETHERPAD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
466
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
467
+        ETHERPAD_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
465 468
     else
466
-        if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
467
-            ETHERPAD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
469
+        if [ ! "$ETHERPAD_ADMIN_PASSWORD" ]; then
470
+            ETHERPAD_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
468 471
         fi
469 472
     fi
470 473
 
@@ -484,133 +487,133 @@ function install_etherpad {
484 487
     function_check install_nodejs
485 488
     install_nodejs etherpad
486 489
 
487
-    if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME ]; then
488
-        mkdir /var/www/$ETHERPAD_DOMAIN_NAME
490
+    if [ ! -d "/var/www/$ETHERPAD_DOMAIN_NAME" ]; then
491
+        mkdir "/var/www/$ETHERPAD_DOMAIN_NAME"
489 492
     fi
490
-    if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then
493
+    if [ ! -d "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" ]; then
491 494
 
492 495
         if [ -d /repos/etherpad ]; then
493
-            mkdir /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
494
-            cp -r -p /repos/etherpad/. /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
495
-            cd /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
496
+            mkdir "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs"
497
+            cp -r -p /repos/etherpad/. "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs"
498
+            cd "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" || exit 32468346
496 499
             git pull
497 500
         else
498 501
             function_check git_clone
499
-            git_clone $ETHERPAD_REPO /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
502
+            git_clone "$ETHERPAD_REPO" "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs"
500 503
         fi
501 504
 
502
-        if [ ! -d /var/www/$ETHERPAD_DOMAIN_NAME/htdocs ]; then
505
+        if [ ! -d "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" ]; then
503 506
             echo $'Unable to clone etherpad repo'
504 507
             exit 56382
505 508
         fi
506 509
     fi
507 510
 
508
-    cd /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
509
-    git checkout $ETHERPAD_COMMIT -b $ETHERPAD_COMMIT
511
+    cd "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" || exit 24654824
512
+    git checkout "$ETHERPAD_COMMIT" -b "$ETHERPAD_COMMIT"
510 513
     set_completion_param "etherpad commit" "$ETHERPAD_COMMIT"
511 514
 
512
-    chmod a+w /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
513
-    chown www-data:www-data /var/www/$ETHERPAD_DOMAIN_NAME/htdocs
515
+    chmod a+w "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs"
516
+    chown www-data:www-data "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs"
514 517
 
515 518
     function_check etherpad_create_database
516 519
     etherpad_create_database
517 520
 
518 521
     function_check add_ddns_domain
519
-    add_ddns_domain $ETHERPAD_DOMAIN_NAME
522
+    add_ddns_domain "$ETHERPAD_DOMAIN_NAME"
520 523
 
521 524
     create_etherpad_settings
522 525
 
523
-    adduser --system --home=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/ --group etherpad
524
-    chown -R etherpad: /var/www/$ETHERPAD_DOMAIN_NAME/htdocs/
525
-
526
-    echo '[Unit]' > /etc/systemd/system/etherpad.service
527
-    echo 'Description=etherpad-lite (real-time collaborative document editing)' >> /etc/systemd/system/etherpad.service
528
-    echo 'After=syslog.target network.target' >> /etc/systemd/system/etherpad.service
529
-    echo '' >> /etc/systemd/system/etherpad.service
530
-    echo '[Service]' >> /etc/systemd/system/etherpad.service
531
-    echo 'Type=simple' >> /etc/systemd/system/etherpad.service
532
-    echo 'User=etherpad' >> /etc/systemd/system/etherpad.service
533
-    echo 'Group=etherpad' >> /etc/systemd/system/etherpad.service
534
-    echo "WorkingDirectory=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs" >> /etc/systemd/system/etherpad.service
535
-    echo "ExecStart=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/bin/run.sh" >> /etc/systemd/system/etherpad.service
536
-    echo 'Restart=on-failure' >> /etc/systemd/system/etherpad.service
537
-    echo 'SuccessExitStatus=3 4' >> /etc/systemd/system/etherpad.service
538
-    echo 'RestartForceExitStatus=3 4' >> /etc/systemd/system/etherpad.service
539
-    echo '' >> /etc/systemd/system/etherpad.service
540
-    echo '[Install]' >> /etc/systemd/system/etherpad.service
541
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/etherpad.service
526
+    adduser --system --home="/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/" --group etherpad
527
+    chown -R etherpad: "/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/"
528
+
529
+    { echo '[Unit]';
530
+      echo 'Description=etherpad-lite (real-time collaborative document editing)';
531
+      echo 'After=syslog.target network.target';
532
+      echo '';
533
+      echo '[Service]';
534
+      echo 'Type=simple';
535
+      echo 'User=etherpad';
536
+      echo 'Group=etherpad';
537
+      echo "WorkingDirectory=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs";
538
+      echo "ExecStart=/var/www/$ETHERPAD_DOMAIN_NAME/htdocs/bin/run.sh";
539
+      echo 'Restart=on-failure';
540
+      echo 'SuccessExitStatus=3 4';
541
+      echo 'RestartForceExitStatus=3 4';
542
+      echo '';
543
+      echo '[Install]';
544
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/etherpad.service
542 545
     chmod +x /etc/systemd/system/etherpad.service
543 546
 
544 547
     etherpad_nginx_site=/etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
545 548
     if [[ $ONION_ONLY == "no" ]]; then
546 549
         function_check nginx_http_redirect
547
-        nginx_http_redirect $ETHERPAD_DOMAIN_NAME
548
-        echo 'server {' >> $etherpad_nginx_site
549
-        echo '  listen 443 ssl;' >> $etherpad_nginx_site
550
-        echo '  #listen [::]:443 ssl;' >> $etherpad_nginx_site
551
-        echo "  server_name $ETHERPAD_DOMAIN_NAME;" >> $etherpad_nginx_site
552
-        echo '' >> $etherpad_nginx_site
553
-        echo '  # Security' >> $etherpad_nginx_site
550
+        nginx_http_redirect "$ETHERPAD_DOMAIN_NAME"
551
+        { echo 'server {';
552
+        echo '  listen 443 ssl;';
553
+        echo '  #listen [::]:443 ssl;';
554
+        echo "  server_name $ETHERPAD_DOMAIN_NAME;";
555
+        echo '';
556
+        echo '  # Security'; } >> "$etherpad_nginx_site"
554 557
         function_check nginx_ssl
555
-        nginx_ssl $ETHERPAD_DOMAIN_NAME
558
+        nginx_ssl "$ETHERPAD_DOMAIN_NAME"
556 559
 
557 560
         function_check nginx_disable_sniffing
558
-        nginx_disable_sniffing $ETHERPAD_DOMAIN_NAME
559
-
560
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $etherpad_nginx_site
561
-        echo '' >> $etherpad_nginx_site
562
-        echo '  # Logs' >> $etherpad_nginx_site
563
-        echo '  access_log /dev/null;' >> $etherpad_nginx_site
564
-        echo '  error_log /dev/null;' >> $etherpad_nginx_site
565
-        echo '' >> $etherpad_nginx_site
566
-        echo '  # Root' >> $etherpad_nginx_site
567
-        echo "  root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;" >> $etherpad_nginx_site
568
-        echo '' >> $etherpad_nginx_site
569
-        echo '  location / {' >> $etherpad_nginx_site
561
+        nginx_disable_sniffing "$ETHERPAD_DOMAIN_NAME"
562
+
563
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
564
+        echo '';
565
+        echo '  # Logs';
566
+        echo '  access_log /dev/null;';
567
+        echo '  error_log /dev/null;';
568
+        echo '';
569
+        echo '  # Root';
570
+        echo "  root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;";
571
+        echo '';
572
+        echo '  location / {'; } >> "$etherpad_nginx_site"
570 573
         function_check nginx_limits
571
-        nginx_limits $ETHERPAD_DOMAIN_NAME '15m'
572
-        echo "    proxy_pass        http://localhost:${ETHERPAD_PORT}/;" >> $etherpad_nginx_site
573
-        echo '    proxy_set_header  Host $host;' >> $etherpad_nginx_site
574
-        echo '    proxy_buffering   off;' >> $etherpad_nginx_site
575
-        echo '  }' >> $etherpad_nginx_site
576
-        echo '}' >> $etherpad_nginx_site
574
+        nginx_limits "$ETHERPAD_DOMAIN_NAME" '15m'
575
+        { echo "    proxy_pass        http://localhost:${ETHERPAD_PORT}/;";
576
+          echo "    proxy_set_header  Host \$host;";
577
+          echo '    proxy_buffering   off;';
578
+          echo '  }';
579
+          echo '}'; } >> "$etherpad_nginx_site"
577 580
     else
578
-        echo -n '' > $etherpad_nginx_site
581
+        echo -n '' > "$etherpad_nginx_site"
579 582
     fi
580
-    echo 'server {' >> $etherpad_nginx_site
581
-    echo "    listen 127.0.0.1:$ETHERPAD_ONION_PORT default_server;" >> $etherpad_nginx_site
582
-    echo "    server_name $ETHERPAD_DOMAIN_NAME;" >> $etherpad_nginx_site
583
-    echo '' >> $etherpad_nginx_site
583
+    { echo 'server {';
584
+      echo "    listen 127.0.0.1:$ETHERPAD_ONION_PORT default_server;";
585
+      echo "    server_name $ETHERPAD_ONION_HOSTNAME;";
586
+      echo ''; } >> "$etherpad_nginx_site"
584 587
     function_check nginx_disable_sniffing
585
-    nginx_disable_sniffing $ETHERPAD_DOMAIN_NAME
586
-    echo '' >> $etherpad_nginx_site
587
-    echo '  # Logs' >> $etherpad_nginx_site
588
-    echo '  access_log /dev/null;' >> $etherpad_nginx_site
589
-    echo '  error_log /dev/null;' >> $etherpad_nginx_site
590
-    echo '' >> $etherpad_nginx_site
591
-    echo '  # Root' >> $etherpad_nginx_site
592
-    echo "  root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;" >> $etherpad_nginx_site
593
-    echo '' >> $etherpad_nginx_site
594
-    echo '  location / {' >> $etherpad_nginx_site
588
+    nginx_disable_sniffing "$ETHERPAD_DOMAIN_NAME"
589
+    { echo '';
590
+      echo '  # Logs';
591
+      echo '  access_log /dev/null;';
592
+      echo '  error_log /dev/null;';
593
+      echo '';
594
+      echo '  # Root';
595
+      echo "  root /var/www/$ETHERPAD_DOMAIN_NAME/htdocs;";
596
+      echo '';
597
+      echo '  location / {'; } >> "$etherpad_nginx_site"
595 598
     function_check nginx_limits
596
-    nginx_limits $ETHERPAD_DOMAIN_NAME '15m'
597
-    echo "    proxy_pass        http://localhost:${ETHERPAD_PORT}/;" >> $etherpad_nginx_site
598
-    echo '    proxy_set_header  Host $host;' >> $etherpad_nginx_site
599
-    echo '    proxy_buffering   off;' >> $etherpad_nginx_site
600
-    echo '  }' >> $etherpad_nginx_site
601
-    echo '}' >> $etherpad_nginx_site
599
+    nginx_limits "$ETHERPAD_DOMAIN_NAME" '15m'
600
+    { echo "    proxy_pass        http://localhost:${ETHERPAD_PORT}/;";
601
+      echo "    proxy_set_header  Host \$host;";
602
+      echo '    proxy_buffering   off;';
603
+      echo '  }';
604
+      echo '}'; } >> "$etherpad_nginx_site"
602 605
 
603 606
     function_check create_site_certificate
604
-    create_site_certificate $ETHERPAD_DOMAIN_NAME 'yes'
607
+    create_site_certificate "$ETHERPAD_DOMAIN_NAME" 'yes'
605 608
 
606
-    if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt ]; then
607
-        mv /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
609
+    if [ -f "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt" ]; then
610
+        mv "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.crt" "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem"
608 611
     fi
609
-    if [ -f /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem ]; then
610
-        chown etherpad: /etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem
612
+    if [ -f "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem" ]; then
613
+        chown etherpad: "/etc/ssl/certs/${ETHERPAD_DOMAIN_NAME}.pem"
611 614
     fi
612
-    if [ -f /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key ]; then
613
-        chown etherpad: /etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key
615
+    if [ -f "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key" ]; then
616
+        chown etherpad: "/etc/ssl/private/${ETHERPAD_DOMAIN_NAME}.key"
614 617
     fi
615 618
     usermod -a -G ssl-cert etherpad
616 619
 
@@ -623,14 +626,14 @@ function install_etherpad {
623 626
     backup_database_local etherpad
624 627
 
625 628
     function_check nginx_ensite
626
-    nginx_ensite $ETHERPAD_DOMAIN_NAME
629
+    nginx_ensite "$ETHERPAD_DOMAIN_NAME"
627 630
 
628 631
     ETHERPAD_ONION_HOSTNAME=$(add_onion_service etherpad 80 ${ETHERPAD_ONION_PORT})
629 632
 
630
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a etherpad -p "$ETHERPAD_ADMIN_PASSWORD"
633
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a etherpad -p "$ETHERPAD_ADMIN_PASSWORD"
631 634
 
632 635
     function_check add_ddns_domain
633
-    add_ddns_domain $ETHERPAD_DOMAIN_NAME
636
+    add_ddns_domain "$ETHERPAD_DOMAIN_NAME"
634 637
 
635 638
     set_completion_param "etherpad domain" "$ETHERPAD_DOMAIN_NAME"
636 639
 

+ 124
- 125
src/freedombone-app-fedwiki Просмотреть файл

@@ -127,7 +127,7 @@ function add_user_fedwiki {
127 127
 }
128 128
 
129 129
 function install_interactive_fedwiki {
130
-    if [ ! $ONION_ONLY ]; then
130
+    if [ ! "$ONION_ONLY" ]; then
131 131
         ONION_ONLY='no'
132 132
     fi
133 133
 
@@ -148,7 +148,7 @@ function change_password_fedwiki {
148 148
         echo $'Fedwiki password is too short'
149 149
         return
150 150
     fi
151
-    ${PROJECT_NAME}-pass -u $FEDWIKI_USERNAME -a fedwiki -p "$FEDWIKI_PASSWORD"
151
+    "${PROJECT_NAME}-pass" -u "$FEDWIKI_USERNAME" -a fedwiki -p "$FEDWIKI_PASSWORD"
152 152
     sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
153 153
     sed -i "s|\"secret\":.*|\"secret\": \"${FEDWIKI_PASSWORD}\"|g" ${FEDWIKI_DATA}/status/owner.json
154 154
     systemctl daemon-reload
@@ -177,12 +177,12 @@ function upgrade_fedwiki {
177 177
 
178 178
 function backup_local_fedwiki {
179 179
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
180
-    if grep -q "fedwiki domain" $COMPLETION_FILE; then
180
+    if grep -q "fedwiki domain" "$COMPLETION_FILE"; then
181 181
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
182 182
     fi
183 183
 
184 184
     systemctl stop fedwiki
185
-    suspend_site ${FEDWIKI_DOMAIN_NAME}
185
+    suspend_site "${FEDWIKI_DOMAIN_NAME}"
186 186
 
187 187
     fedwiki_path=$FEDWIKI_DATA
188 188
     if [ -d $fedwiki_path ]; then
@@ -195,11 +195,11 @@ function backup_local_fedwiki {
195 195
 
196 196
 function restore_local_fedwiki {
197 197
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
198
-    if grep -q "fedwiki domain" $COMPLETION_FILE; then
198
+    if grep -q "fedwiki domain" "$COMPLETION_FILE"; then
199 199
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
200 200
     fi
201
-    if [ $FEDWIKI_DOMAIN_NAME ]; then
202
-        suspend_site ${FEDWIKI_DOMAIN_NAME}
201
+    if [ "$FEDWIKI_DOMAIN_NAME" ]; then
202
+        suspend_site "${FEDWIKI_DOMAIN_NAME}"
203 203
         systemctl stop fedwiki
204 204
 
205 205
         temp_restore_dir=/root/tempfedwiki
@@ -215,8 +215,8 @@ function restore_local_fedwiki {
215 215
             rm -rf $temp_restore_dir
216 216
         fi
217 217
 
218
-        FEDWIKI_PASSWORD=$(cat ${FEDWIKI_DATA}/status/owner.json | grep secret | awk -F '"' '{print $4}')
219
-        ${PROJECT_NAME}-pass -u $FEDWIKI_USERNAME -a fedwiki -p "$FEDWIKI_PASSWORD"
218
+        FEDWIKI_PASSWORD=$(grep secret "${FEDWIKI_DATA}/status/owner.json" | awk -F '"' '{print $4}')
219
+        "${PROJECT_NAME}-pass" -u "$FEDWIKI_USERNAME" -a fedwiki -p "$FEDWIKI_PASSWORD"
220 220
         sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
221 221
         write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD"
222 222
         systemctl daemon-reload
@@ -227,12 +227,12 @@ function restore_local_fedwiki {
227 227
 
228 228
 function backup_remote_fedwiki {
229 229
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
230
-    if grep -q "fedwiki domain" $COMPLETION_FILE; then
230
+    if grep -q "fedwiki domain" "$COMPLETION_FILE"; then
231 231
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
232 232
     fi
233 233
 
234 234
     systemctl stop fedwiki
235
-    suspend_site ${FEDWIKI_DOMAIN_NAME}
235
+    suspend_site "${FEDWIKI_DOMAIN_NAME}"
236 236
 
237 237
     temp_backup_dir=$FEDWIKI_DATA
238 238
     if [ -d $temp_backup_dir ]; then
@@ -248,12 +248,12 @@ function backup_remote_fedwiki {
248 248
 
249 249
 function restore_remote_fedwiki {
250 250
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
251
-    if grep -q "fedwiki domain" $COMPLETION_FILE; then
251
+    if grep -q "fedwiki domain" "$COMPLETION_FILE"; then
252 252
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
253 253
     fi
254 254
 
255 255
     systemctl stop fedwiki
256
-    suspend_site ${FEDWIKI_DOMAIN_NAME}
256
+    suspend_site "${FEDWIKI_DOMAIN_NAME}"
257 257
 
258 258
     temp_restore_dir=/root/tempfedwiki
259 259
     function_check restore_directory_from_friend
@@ -268,8 +268,8 @@ function restore_remote_fedwiki {
268 268
         rm -rf $temp_restore_dir
269 269
     fi
270 270
 
271
-    FEDWIKI_PASSWORD=$(cat ${FEDWIKI_DATA}/status/owner.json | grep secret | awk -F '"' '{print $4}')
272
-    ${PROJECT_NAME}-pass -u $FEDWIKI_USERNAME -a fedwiki -p "$FEDWIKI_PASSWORD"
271
+    FEDWIKI_PASSWORD=$(grep secret "${FEDWIKI_DATA}/status/owner.json" | awk -F '"' '{print $4}')
272
+    "${PROJECT_NAME}-pass" -u "$FEDWIKI_USERNAME" -a fedwiki -p "$FEDWIKI_PASSWORD"
273 273
     sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
274 274
     write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD"
275 275
     systemctl daemon-reload
@@ -294,20 +294,20 @@ function remove_fedwiki {
294 294
     remove_nodejs fedwiki
295 295
 
296 296
     read_config_param "FEDWIKI_DOMAIN_NAME"
297
-    nginx_dissite $FEDWIKI_DOMAIN_NAME
298
-    remove_certs ${FEDWIKI_DOMAIN_NAME}
299
-    if [ -f /etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME ]; then
300
-        rm -f /etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME
297
+    nginx_dissite "$FEDWIKI_DOMAIN_NAME"
298
+    remove_certs "${FEDWIKI_DOMAIN_NAME}"
299
+    if [ -f "/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME" ]; then
300
+        rm -f "/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME"
301 301
     fi
302
-    if [ -d /var/www/$FEDWIKI_DOMAIN_NAME ]; then
303
-        rm -rf /var/www/$FEDWIKI_DOMAIN_NAME
302
+    if [ -d "/var/www/$FEDWIKI_DOMAIN_NAME" ]; then
303
+        rm -rf "/var/www/$FEDWIKI_DOMAIN_NAME"
304 304
     fi
305 305
     remove_config_param FEDWIKI_DOMAIN_NAME
306 306
     remove_config_param FEDWIKI_CODE
307 307
     function_check remove_onion_service
308 308
     remove_onion_service fedwiki ${FEDWIKI_ONION_PORT}
309 309
     remove_completion_param "install_fedwiki"
310
-    sed -i '/fedwiki/d' $COMPLETION_FILE
310
+    sed -i '/fedwiki/d' "$COMPLETION_FILE"
311 311
 
312 312
     groupdel -f fedwiki
313 313
     userdel -r fedwiki
@@ -317,101 +317,102 @@ function remove_fedwiki {
317 317
     fi
318 318
 
319 319
     function_check remove_ddns_domain
320
-    remove_ddns_domain $FEDWIKI_DOMAIN_NAME
320
+    remove_ddns_domain "$FEDWIKI_DOMAIN_NAME"
321 321
 }
322 322
 
323 323
 function fedwiki_setup_web {
324
-    fedwiki_nginx_file=/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME
325
-
326
-    if [[ $ONION_ONLY == "no" ]]; then
327
-        echo 'server {' > $fedwiki_nginx_file
328
-        echo '  listen 80;' >> $fedwiki_nginx_file
329
-        echo '  listen [::]:80;' >> $fedwiki_nginx_file
330
-        echo "  server_name $FEDWIKI_DOMAIN_NAME;" >> $fedwiki_nginx_file
331
-        echo '  rewrite ^ https://$server_name$request_uri? permanent;' >> $fedwiki_nginx_file
332
-        echo '}' >> $fedwiki_nginx_file
333
-        echo '' >> $fedwiki_nginx_file
334
-        echo 'server {' >> $fedwiki_nginx_file
335
-        echo '  listen 443 ssl;' >> $fedwiki_nginx_file
336
-        echo '  #listen [::]:443 ssl;' >> $fedwiki_nginx_file
337
-        echo "  server_name $FEDWIKI_DOMAIN_NAME;" >> $fedwiki_nginx_file
338
-        echo '' >> $fedwiki_nginx_file
324
+    fedwiki_nginx_file="/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME"
325
+
326
+    if [[ "$ONION_ONLY" == "no" ]]; then
327
+        { echo 'server {';
328
+        echo '  listen 80;';
329
+        echo '  listen [::]:80;';
330
+        echo "  server_name $FEDWIKI_DOMAIN_NAME;";
331
+        echo "  rewrite ^ https://\$server_name\$request_uri? permanent;";
332
+        echo '}';
333
+        echo '';
334
+        echo 'server {';
335
+        echo '  listen 443 ssl;';
336
+        echo '  #listen [::]:443 ssl;';
337
+        echo "  server_name $FEDWIKI_DOMAIN_NAME;";
338
+        echo ''; } > "$fedwiki_nginx_file"
339 339
         function_check nginx_ssl
340
-        nginx_ssl $FEDWIKI_DOMAIN_NAME mobile
341
-
342
-        sed -i '/Content-Security-Policy/d' $fedwiki_nginx_file
343
-        sed -i '/X-XSS-Protection/d' $fedwiki_nginx_file
344
-        sed -i '/X-Robots-Tag/d' $fedwiki_nginx_file
345
-        sed -i '/X-Download-Options/d' $fedwiki_nginx_file
346
-        sed -i '/X-Permitted-Cross-Domain-Policies/d' $fedwiki_nginx_file
347
-
348
-        echo '  add_header X-Robots-Tag none;' >> $fedwiki_nginx_file
349
-        echo '  add_header X-Download-Options noopen;' >> $fedwiki_nginx_file
350
-        echo '  add_header X-Frame-Options DENY;' >> $fedwiki_nginx_file
351
-        echo '  add_header X-Content-Type-Options nosniff;' >> $fedwiki_nginx_file
352
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $fedwiki_nginx_file
353
-        echo '' >> $fedwiki_nginx_file
354
-        echo '  location /fonts-font-awesome/ {' >> $fedwiki_nginx_file
355
-        echo '    alias /usr/share/fonts-font-awesome/;' >> $fedwiki_nginx_file
356
-        echo '  }' >> $fedwiki_nginx_file
357
-        echo '' >> $fedwiki_nginx_file
358
-        echo '  location / {' >> $fedwiki_nginx_file
359
-        echo "    proxy_pass http://localhost:${FEDWIKI_PORT};" >> $fedwiki_nginx_file
360
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $fedwiki_nginx_file
361
-        echo '    proxy_set_header Host $host;' >> $fedwiki_nginx_file
362
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $fedwiki_nginx_file
363
-        echo '    client_max_body_size 1M;' >> $fedwiki_nginx_file
364
-        echo '  }' >> $fedwiki_nginx_file
365
-        echo '}' >> $fedwiki_nginx_file
366
-        echo '' >> $fedwiki_nginx_file
340
+        nginx_ssl "$FEDWIKI_DOMAIN_NAME" mobile
341
+
342
+        sed -i '/Content-Security-Policy/d' "$fedwiki_nginx_file"
343
+        sed -i '/X-XSS-Protection/d' "$fedwiki_nginx_file"
344
+        sed -i '/X-Robots-Tag/d' "$fedwiki_nginx_file"
345
+        sed -i '/X-Download-Options/d' "$fedwiki_nginx_file"
346
+        sed -i '/X-Permitted-Cross-Domain-Policies/d' "$fedwiki_nginx_file"
347
+
348
+        { echo '  add_header X-Robots-Tag none;';
349
+          echo '  add_header X-Download-Options noopen;';
350
+          echo '  add_header X-Frame-Options DENY;';
351
+          echo '  add_header X-Content-Type-Options nosniff;';
352
+          echo '  add_header Strict-Transport-Security max-age=15768000;';
353
+          echo '';
354
+          echo '  location /fonts-font-awesome/ {';
355
+          echo '    alias /usr/share/fonts-font-awesome/;';
356
+          echo '  }';
357
+          echo '';
358
+          echo '  location / {';
359
+          echo "    proxy_pass http://localhost:${FEDWIKI_PORT};";
360
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
361
+          echo "    proxy_set_header Host \$host;";
362
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
363
+          echo '    client_max_body_size 1M;';
364
+          echo '  }';
365
+          echo '}';
366
+          echo ''; } >> "$fedwiki_nginx_file"
367 367
     else
368
-        echo -n '' > $fedwiki_nginx_file
369
-    fi
370
-    echo 'server {' >> $fedwiki_nginx_file
371
-    echo "  listen 127.0.0.1:$FEDWIKI_ONION_PORT default_server;" >> $fedwiki_nginx_file
372
-    echo "  server_name $FEDWIKI_ONION_HOSTNAME;" >> $fedwiki_nginx_file
373
-    echo '' >> $fedwiki_nginx_file
374
-    echo '  add_header X-Robots-Tag none;' >> $fedwiki_nginx_file
375
-    echo '  add_header X-Download-Options noopen;' >> $fedwiki_nginx_file
376
-    echo '  add_header X-Frame-Options DENY;' >> $fedwiki_nginx_file
377
-    echo '  add_header X-Content-Type-Options nosniff;' >> $fedwiki_nginx_file
378
-    echo '' >> $fedwiki_nginx_file
379
-    echo '  location /fonts-font-awesome/ {' >> $fedwiki_nginx_file
380
-    echo '    alias /usr/share/fonts-font-awesome/;' >> $fedwiki_nginx_file
381
-    echo '  }' >> $fedwiki_nginx_file
382
-    echo '' >> $fedwiki_nginx_file
383
-    echo '  location / {' >> $fedwiki_nginx_file
384
-    echo "    proxy_pass http://localhost:${FEDWIKI_PORT};" >> $fedwiki_nginx_file
385
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $fedwiki_nginx_file
386
-    echo '    proxy_set_header Host $host;' >> $fedwiki_nginx_file
387
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $fedwiki_nginx_file
388
-    echo '    client_max_body_size 1M;' >> $fedwiki_nginx_file
389
-    echo '  }' >> $fedwiki_nginx_file
390
-    echo '}' >> $fedwiki_nginx_file
368
+        echo -n '' > "$fedwiki_nginx_file"
369
+    fi
370
+    { echo 'server {';
371
+      echo "  listen 127.0.0.1:$FEDWIKI_ONION_PORT default_server;";
372
+      echo "  server_name $FEDWIKI_ONION_HOSTNAME;";
373
+      echo '';
374
+      echo '  add_header X-Robots-Tag none;';
375
+      echo '  add_header X-Download-Options noopen;';
376
+      echo '  add_header X-Frame-Options DENY;';
377
+      echo '  add_header X-Content-Type-Options nosniff;';
378
+      echo '';
379
+      echo '  location /fonts-font-awesome/ {';
380
+      echo '    alias /usr/share/fonts-font-awesome/;';
381
+      echo '  }';
382
+      echo '';
383
+      echo '  location / {';
384
+      echo "    proxy_pass http://localhost:${FEDWIKI_PORT};";
385
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
386
+      echo "    proxy_set_header Host \$host;";
387
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
388
+      echo '    client_max_body_size 1M;';
389
+      echo '  }';
390
+      echo '}'; } >> "$fedwiki_nginx_file"
391 391
 
392 392
     function_check create_site_certificate
393
-    create_site_certificate $FEDWIKI_DOMAIN_NAME 'yes'
393
+    create_site_certificate "$FEDWIKI_DOMAIN_NAME" 'yes'
394 394
 
395 395
     function_check nginx_ensite
396
-    nginx_ensite $FEDWIKI_DOMAIN_NAME
396
+    nginx_ensite "$FEDWIKI_DOMAIN_NAME"
397 397
 }
398 398
 
399 399
 function install_fedwiki {
400
-    if [[ $VARIANT == "mesh"* ]]; then
400
+    # shellcheck disable=SC2153
401
+    if [[ "$VARIANT" == "mesh"* ]]; then
401 402
         return
402 403
     fi
403 404
 
404
-    if [ ! $ONION_ONLY ]; then
405
+    if [ ! "$ONION_ONLY" ]; then
405 406
         ONION_ONLY='no'
406 407
     fi
407 408
 
408
-    if [ ! $FEDWIKI_DOMAIN_NAME ]; then
409
+    if [ ! "$FEDWIKI_DOMAIN_NAME" ]; then
409 410
         echo $'The fedwiki domain name was not specified'
410 411
         exit 893635
411 412
     fi
412 413
 
413
-    if [ ! -d /var/www/$FEDWIKI_DOMAIN_NAME/htdocs ]; then
414
-        mkdir -p /var/www/$FEDWIKI_DOMAIN_NAME/htdocs
414
+    if [ ! -d "/var/www/$FEDWIKI_DOMAIN_NAME/htdocs" ]; then
415
+        mkdir -p "/var/www/$FEDWIKI_DOMAIN_NAME/htdocs"
415 416
     fi
416 417
 
417 418
     if [ ! -d $FEDWIKI_DATA ]; then
@@ -429,14 +430,12 @@ function install_fedwiki {
429 430
 
430 431
     apt-get -yq install fonts-font-awesome
431 432
 
432
-    npm install -g wiki@$FEDWIKI_VERSION
433
-    if [ ! "$?" = "0" ]; then
433
+    if ! npm install -g wiki@$FEDWIKI_VERSION; then
434 434
         echo $'Failed to install fedwiki'
435 435
         exit 6293523
436 436
     fi
437 437
 
438
-    npm install -g wiki-security-friends@0.1.0
439
-    if [ ! "$?" = "0" ]; then
438
+    if ! npm install -g wiki-security-friends@0.1.0; then
440 439
         echo $'Failed to install wiki-security-friends'
441 440
         exit 783533
442 441
     fi
@@ -457,44 +456,44 @@ function install_fedwiki {
457 456
         FEDWIKI_COOKIE="$(create_password 20)"
458 457
     fi
459 458
 
460
-    echo '[Unit]' > /etc/systemd/system/fedwiki.service
461
-    echo 'Description=Fedwiki federated wiki' >> /etc/systemd/system/fedwiki.service
462
-    echo 'After=syslog.target' >> /etc/systemd/system/fedwiki.service
463
-    echo 'After=network.target' >> /etc/systemd/system/fedwiki.service
464
-    echo '' >> /etc/systemd/system/fedwiki.service
465
-    echo '[Service]' >> /etc/systemd/system/fedwiki.service
466
-    echo 'User=fedwiki' >> /etc/systemd/system/fedwiki.service
467
-    echo 'Group=fedwiki' >> /etc/systemd/system/fedwiki.service
468
-    echo "WorkingDirectory=/usr/local/lib/node_modules/wiki" >> /etc/systemd/system/fedwiki.service
469
-    echo "ExecStart=/usr/local/bin/wiki --security_type friends --session_duration 7 --data $FEDWIKI_DATA -p $FEDWIKI_PORT --cookieSecret '${FEDWIKI_COOKIE}'" >> /etc/systemd/system/fedwiki.service
470
-    echo 'StandardOutput=syslog' >> /etc/systemd/system/fedwiki.service
471
-    echo 'StandardError=syslog' >> /etc/systemd/system/fedwiki.service
472
-    echo 'SyslogIdentifier=fedwiki' >> /etc/systemd/system/fedwiki.service
473
-    echo 'Restart=always' >> /etc/systemd/system/fedwiki.service
474
-    echo "Environment=NODE_ENV=production" >> /etc/systemd/system/fedwiki.service
475
-    echo '' >> /etc/systemd/system/fedwiki.service
476
-    echo '[Install]' >> /etc/systemd/system/fedwiki.service
477
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/fedwiki.service
459
+    { echo '[Unit]';
460
+      echo 'Description=Fedwiki federated wiki';
461
+      echo 'After=syslog.target';
462
+      echo 'After=network.target';
463
+      echo '';
464
+      echo '[Service]';
465
+      echo 'User=fedwiki';
466
+      echo 'Group=fedwiki';
467
+      echo "WorkingDirectory=/usr/local/lib/node_modules/wiki";
468
+      echo "ExecStart=/usr/local/bin/wiki --security_type friends --session_duration 7 --data $FEDWIKI_DATA -p $FEDWIKI_PORT --cookieSecret '${FEDWIKI_COOKIE}'";
469
+      echo 'StandardOutput=syslog';
470
+      echo 'StandardError=syslog';
471
+      echo 'SyslogIdentifier=fedwiki';
472
+      echo 'Restart=always';
473
+      echo "Environment=NODE_ENV=production";
474
+      echo '';
475
+      echo '[Install]';
476
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/fedwiki.service
478 477
 
479 478
     if [ ! -d ${FEDWIKI_DATA}/status ]; then
480 479
         mkdir -p ${FEDWIKI_DATA}/status
481 480
     fi
482 481
     fedwiki_auth_file=${FEDWIKI_DATA}/status/owner.json
483
-    echo '{' > $fedwiki_auth_file
484
-    echo "  \"name\": \"${MY_USERNAME}\"," >> $fedwiki_auth_file
485
-    echo '  "friend": {' >> $fedwiki_auth_file
486
-    echo "    \"secret\": \"${FEDWIKI_COOKIE}\"" >> $fedwiki_auth_file
487
-    echo '  }' >> $fedwiki_auth_file
488
-    echo '}' >> $fedwiki_auth_file
482
+    { echo '{';
483
+      echo "  \"name\": \"${MY_USERNAME}\",";
484
+      echo '  "friend": {';
485
+      echo "    \"secret\": \"${FEDWIKI_COOKIE}\"";
486
+      echo '  }';
487
+      echo '}'; } > $fedwiki_auth_file
489 488
 
490 489
     chown -R fedwiki:fedwiki $FEDWIKI_DATA
491 490
 
492 491
     fedwiki_setup_web
493 492
 
494
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a fedwiki -p "$FEDWIKI_COOKIE"
493
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a fedwiki -p "$FEDWIKI_COOKIE"
495 494
 
496 495
     function_check add_ddns_domain
497
-    add_ddns_domain $FEDWIKI_DOMAIN_NAME
496
+    add_ddns_domain "$FEDWIKI_DOMAIN_NAME"
498 497
 
499 498
     fedwiki_remove_bad_links
500 499
 

+ 252
- 250
src/freedombone-app-friendica Просмотреть файл

@@ -60,7 +60,7 @@ function logging_off_friendica {
60 60
 
61 61
 function remove_user_friendica {
62 62
     remove_username="$1"
63
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp friendica
63
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp friendica
64 64
 }
65 65
 
66 66
 function add_user_friendica {
@@ -71,27 +71,26 @@ function add_user_friendica {
71 71
 
72 72
     new_username="$1"
73 73
     new_user_password="$2"
74
-    ${PROJECT_NAME}-pass -u $new_username -a friendica -p "$new_user_password"
74
+    "${PROJECT_NAME}-pass" -u "$new_username" -a friendica -p "$new_user_password"
75 75
     echo '0'
76 76
 }
77 77
 
78 78
 function friendica_renew_cert {
79 79
     dialog --title $"Renew SSL certificate" \
80 80
            --backtitle $"Freedombone Control Panel" \
81
-           --yesno $"\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
81
+           --yesno $"\\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
82 82
     sel=$?
83 83
     case $sel in
84 84
         1) return;;
85 85
         255) return;;
86 86
     esac
87 87
     FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain")
88
-    if [ ! -d /var/www/$FRIENDICA_DOMAIN_NAME/htdocs ]; then
88
+    if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" ]; then
89 89
         dialog --title $"Renew SSL certificate" \
90 90
                --msgbox $"Friendica install directory not found" 6 40
91 91
         return
92 92
     fi
93
-    ${PROJECT_NAME}-renew-cert -h $FRIENDICA_DOMAIN_NAME -p 'letsencrypt'
94
-    if [ ! "$?" = "0" ]; then
93
+    if ! "${PROJECT_NAME}-renew-cert" -h "$FRIENDICA_DOMAIN_NAME" -p 'letsencrypt'; then
95 94
         any_key
96 95
     else
97 96
         dialog --title $"Renew SSL certificate" \
@@ -100,52 +99,54 @@ function friendica_renew_cert {
100 99
 }
101 100
 
102 101
 function friendica_channel_directory_server {
103
-    if ! grep -q "friendica domain" $COMPLETION_FILE; then
102
+    if ! grep -q "friendica domain" "$COMPLETION_FILE"; then
104 103
         dialog --title $"Friendica channel directory server" \
105 104
                --msgbox $"Friendica is not installed on this system" 6 40
106 105
         return
107 106
     fi
108 107
     FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain")
109
-    if [ ! -d /var/www/$FRIENDICA_DOMAIN_NAME/htdocs ]; then
108
+    if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" ]; then
110 109
         dialog --title $"Friendica channel directory server" \
111 110
                --msgbox $"Friendica install directory not found" 6 40
112 111
         return
113 112
     fi
114 113
 
115
-    CURR_DIR_SERVER=$(cat /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php | grep directory | awk -F "'" '{print $6}')
114
+    CURR_DIR_SERVER=$(grep directory "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php" | awk -F "'" '{print $6}')
116 115
 
117
-    data=$(tempfile 2>/dev/null)
118
-    trap "rm -f $data" 0 1 2 5 15
116
+    data=$(mktemp 2>/dev/null)
119 117
     dialog --title $"Friendica channel directory server" \
120 118
            --backtitle $"Freedombone Control Panel" \
121
-           --inputbox $"When you click on 'channel directory' this is where Friendica will obtain its list from" 8 60 "$CURR_DIR_SERVER" 2>$data
119
+           --inputbox $"When you click on 'channel directory' this is where Friendica will obtain its list from" 8 60 "$CURR_DIR_SERVER" 2>"$data"
122 120
     sel=$?
123 121
     case $sel in
124 122
         0)
125
-            friendica_domain_server=$(<$data)
123
+            friendica_domain_server=$(<"$data")
126 124
             if [[ "$friendica_domain_server" != *"."* ]]; then
125
+                rm -f "$data"
127 126
                 return
128 127
             fi
129 128
             if [[ "$friendica_domain_server" != "http"* ]]; then
130 129
                 dialog --title $"Friendica channel directory server" \
131 130
                        --msgbox $"Invalid domain - include the https://" 6 40
131
+                rm -f "$data"
132 132
                 return
133 133
             fi
134
-            sed -i "s|\['directory'\] = .*|\['directory'\] = \'$friendica_domain_server\';|g" /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php
134
+            sed -i "s|\['directory'\] = .*|\['directory'\] = \'$friendica_domain_server\';|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php"
135 135
             dialog --title $"Friendica channel directory server" \
136 136
                    --msgbox $"Domain channel directory server changed to $friendica_domain_server" 6 40
137 137
             ;;
138 138
     esac
139
+    rm -f "$data"
139 140
 }
140 141
 
141 142
 function friendica_close_registrations {
142
-    sed -i "s|REGISTER_OPEN|REGISTER_CLOSED|g" /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php
143
+    sed -i "s|REGISTER_OPEN|REGISTER_CLOSED|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php"
143 144
     dialog --title $"Friendica Account Registrations" \
144 145
            --msgbox $"New registrations are now closed" 6 40
145 146
 }
146 147
 
147 148
 function friendica_allow_registrations {
148
-    sed -i "s|REGISTER_CLOSED|REGISTER_OPEN|g" /var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php
149
+    sed -i "s|REGISTER_CLOSED|REGISTER_OPEN|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php"
149 150
     dialog --title $"Friendica Account Registrations" \
150 151
            --msgbox $"New registrations are permitted" 6 40
151 152
 }
@@ -153,8 +154,7 @@ function friendica_allow_registrations {
153 154
 function configure_interactive_friendica {
154 155
     while true
155 156
     do
156
-        data=$(tempfile 2>/dev/null)
157
-        trap "rm -f $data" 0 1 2 5 15
157
+        data=$(mktemp 2>/dev/null)
158 158
         dialog --backtitle $"Freedombone Control Panel" \
159 159
                --title $"Friendica" \
160 160
                --radiolist $"Choose an operation:" 15 70 6 \
@@ -162,19 +162,21 @@ function configure_interactive_friendica {
162 162
                2 $"Renew SSL certificate" off \
163 163
                3 $"Close new account registrations" off \
164 164
                4 $"Allow new account registrations" off \
165
-               5 $"Back to main menu" on 2> $data
165
+               5 $"Back to main menu" on 2> "$data"
166 166
         sel=$?
167 167
         case $sel in
168 168
             1) break;;
169 169
             255) break;;
170 170
         esac
171
-        case $(cat $data) in
171
+        case $(cat "$data") in
172 172
             1) friendica_channel_directory_server;;
173 173
             2) friendica_renew_cert;;
174 174
             3) friendica_close_registrations;;
175 175
             4) friendica_allow_registrations;;
176
-            5) break;;
176
+            5) rm -f "$data"
177
+               break;;
177 178
         esac
179
+        rm -f "$data"
178 180
     done
179 181
 }
180 182
 
@@ -190,7 +192,7 @@ function install_interactive_friendica {
190 192
 }
191 193
 
192 194
 function change_password_friendica {
193
-    FRIENDICA_USERNAME="$1"
195
+    #FRIENDICA_USERNAME="$1"
194 196
     FRIENDICA_PASSWORD="$2"
195 197
     if [ ${#FRIENDICA_PASSWORD} -lt 8 ]; then
196 198
         echo $'Friendica password is too short'
@@ -201,14 +203,14 @@ function change_password_friendica {
201 203
 }
202 204
 
203 205
 function friendica_create_database {
204
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
205
-        FRIENDICA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
206
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
207
+        FRIENDICA_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
206 208
     fi
207
-    if [ ! $FRIENDICA_ADMIN_PASSWORD ]; then
208
-        FRIENDICA_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
209
+    if [ ! "$FRIENDICA_ADMIN_PASSWORD" ]; then
210
+        FRIENDICA_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
209 211
     fi
210
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a friendica -p "$FRIENDICA_ADMIN_PASSWORD"
211
-    if [ ! $FRIENDICA_ADMIN_PASSWORD ]; then
212
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a friendica -p "$FRIENDICA_ADMIN_PASSWORD"
213
+    if [ ! "$FRIENDICA_ADMIN_PASSWORD" ]; then
212 214
         return
213 215
     fi
214 216
 
@@ -229,17 +231,17 @@ function upgrade_friendica {
229 231
     FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
230 232
 
231 233
     function_check set_repo_commit
232
-    set_repo_commit $FRIENDICA_PATH "friendica commit" "$FRIENDICA_COMMIT" $FRIENDICA_REPO
233
-    set_repo_commit $FRIENDICA_PATH/addon "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT" $FRIENDICA_ADDONS_REPO
234
+    set_repo_commit "$FRIENDICA_PATH" "friendica commit" "$FRIENDICA_COMMIT" $FRIENDICA_REPO
235
+    set_repo_commit "$FRIENDICA_PATH/addon" "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT" $FRIENDICA_ADDONS_REPO
234 236
 }
235 237
 
236 238
 function backup_local_friendica {
237
-    friendica_path=/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs
238
-    if [ -d $friendica_path ]; then
239
+    friendica_path="/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs"
240
+    if [ -d "$friendica_path" ]; then
239 241
         function_check backup_database_to_usb
240 242
         backup_database_to_usb friendica
241 243
 
242
-        backup_directory_to_usb $friendica_path friendica
244
+        backup_directory_to_usb "$friendica_path" friendica
243 245
     fi
244 246
 }
245 247
 
@@ -250,31 +252,31 @@ function restore_local_friendica {
250 252
     function_check friendica_create_database
251 253
     friendica_create_database
252 254
 
253
-    restore_database friendica ${FRIENDICA_DOMAIN_NAME}
254
-    if [ -d $USB_MOUNT/backup/friendica ]; then
255
-        if [ ! -d $friendica_dir/store/[data]/smarty3 ]; then
256
-            mkdir -p $friendica_dir/store/[data]/smarty3
255
+    restore_database friendica "${FRIENDICA_DOMAIN_NAME}"
256
+    if [ -d "$USB_MOUNT/backup/friendica" ]; then
257
+        if [ ! -d "$friendica_dir/store/[data]/smarty3" ]; then
258
+            mkdir -p "$friendica_dir/store/[data]/smarty3"
257 259
         fi
258
-        chmod 1777 $friendica_dir/store/[data]/smarty3
259
-        chown -R www-data:www-data $friendica_dir/*
260
+        chmod 1777 "$friendica_dir/store/[data]/smarty3"
261
+        chown -R www-data:www-data "$friendica_dir/*"
260 262
         if [ -d $temp_restore_dir ]; then
261 263
             rm -rf $temp_restore_dir
262 264
         fi
263 265
 
264
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
266
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
265 267
         FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
266
-        sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" $FRIENDICA_PATH/.htconfig.php
268
+        sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$FRIENDICA_PATH/.htconfig.php"
267 269
         MARIADB_PASSWORD=
268 270
     fi
269 271
 }
270 272
 
271 273
 function backup_remote_friendica {
272
-    temp_backup_dir=/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs
273
-    if [ -d $temp_backup_dir ]; then
274
-        suspend_site ${FRIENDICA_DOMAIN_NAME}
274
+    temp_backup_dir="/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs"
275
+    if [ -d "$temp_backup_dir" ]; then
276
+        suspend_site "${FRIENDICA_DOMAIN_NAME}"
275 277
         backup_database_to_friend friendica
276 278
         echo "Backing up Friendica installation"
277
-        backup_directory_to_friend $temp_backup_dir friendica
279
+        backup_directory_to_friend "$temp_backup_dir" friendica
278 280
         restart_site
279 281
         echo "Backup of Friendica complete"
280 282
     else
@@ -289,21 +291,21 @@ function restore_remote_friendica {
289 291
     function_check friendica_create_database
290 292
     friendica_create_database
291 293
 
292
-    restore_database_from_friend friendica ${FRIENDICA_DOMAIN_NAME}
293
-    if [ -d $SERVER_DIRECTORY/backup/friendica ]; then
294
-        if [ ! -d /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then
295
-            mkdir -p /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
294
+    restore_database_from_friend friendica "${FRIENDICA_DOMAIN_NAME}"
295
+    if [ -d "$SERVER_DIRECTORY/backup/friendica" ]; then
296
+        if [ ! -d "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3" ]; then
297
+            mkdir -p "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3"
296 298
         fi
297
-        chmod 1777 /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
298
-        chown -R www-data:www-data /var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/*
299
+        chmod 1777 "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3"
300
+        chown -R www-data:www-data "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/*"
299 301
     fi
300 302
     if [ -d /root/tempfriendica ]; then
301 303
         rm -rf /root/tempfriendica
302 304
     fi
303 305
 
304
-    MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
305
-    FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
306
-    sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" $FRIENDICA_PATH/.htconfig.php
306
+    MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
307
+    FRIENDICA_PATH="/var/www/$FRIENDICA_DOMAIN_NAME/htdocs"
308
+    sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$FRIENDICA_PATH/.htconfig.php"
307 309
     MARIADB_PASSWORD=
308 310
 }
309 311
 
@@ -311,35 +313,35 @@ function remove_friendica {
311 313
     if [ ${#FRIENDICA_DOMAIN_NAME} -eq 0 ]; then
312 314
         return
313 315
     fi
314
-    nginx_dissite $FRIENDICA_DOMAIN_NAME
315
-    remove_certs ${FRIENDICA_DOMAIN_NAME}
316
-    if [ -d /var/www/$FRIENDICA_DOMAIN_NAME ]; then
317
-        rm -rf /var/www/$FRIENDICA_DOMAIN_NAME
316
+    nginx_dissite "$FRIENDICA_DOMAIN_NAME"
317
+    remove_certs "${FRIENDICA_DOMAIN_NAME}"
318
+    if [ -d "/var/www/$FRIENDICA_DOMAIN_NAME" ]; then
319
+        rm -rf "/var/www/$FRIENDICA_DOMAIN_NAME"
318 320
     fi
319
-    if [ -f /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME ]; then
320
-        rm /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
321
+    if [ -f "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" ]; then
322
+        rm "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
321 323
     fi
322 324
     function_check drop_database
323 325
     drop_database friendica
324 326
     function_check remove_onion_service
325 327
     remove_onion_service friendica ${FRIENDICA_ONION_PORT}
326
-    sed -i '/friendica/d' $COMPLETION_FILE
328
+    sed -i '/friendica/d' "$COMPLETION_FILE"
327 329
     sed -i '/poller.php/d' /etc/crontab
328 330
 
329 331
     function_check remove_ddns_domain
330
-    remove_ddns_domain $FRIENDICA_DOMAIN_NAME
332
+    remove_ddns_domain "$FRIENDICA_DOMAIN_NAME"
331 333
 }
332 334
 
333 335
 function install_friendica {
334
-    if [ ! $FRIENDICA_DOMAIN_NAME ]; then
336
+    if [ ! "$FRIENDICA_DOMAIN_NAME" ]; then
335 337
         return
336 338
     fi
337 339
 
338
-    if [[ $ONION_ONLY != "no" ]]; then
340
+    if [[ "$ONION_ONLY" != "no" ]]; then
339 341
         return
340 342
     fi
341 343
 
342
-    FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
344
+    FRIENDICA_PATH="/var/www/$FRIENDICA_DOMAIN_NAME/htdocs"
343 345
 
344 346
     function_check install_mariadb
345 347
     install_mariadb
@@ -354,38 +356,38 @@ function install_friendica {
354 356
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
355 357
     apt-get -yq install php-memcached
356 358
 
357
-    if [ ! -d /var/www/$FRIENDICA_DOMAIN_NAME ]; then
358
-        mkdir /var/www/$FRIENDICA_DOMAIN_NAME
359
+    if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME" ]; then
360
+        mkdir "/var/www/$FRIENDICA_DOMAIN_NAME"
359 361
     fi
360
-    if [ ! -d $FRIENDICA_PATH ]; then
361
-        mkdir $FRIENDICA_PATH
362
+    if [ ! -d "$FRIENDICA_PATH" ]; then
363
+        mkdir "$FRIENDICA_PATH"
362 364
     fi
363 365
 
364
-    if [ ! -f $FRIENDICA_PATH/index.php ]; then
365
-        cd $INSTALL_DIR
366
+    if [ ! -f "$FRIENDICA_PATH/index.php" ]; then
367
+        cd "$INSTALL_DIR" || exit 2346824864
366 368
 
367 369
         if [ -d /repos/friendica ]; then
368 370
             mkdir friendica
369 371
             cp -r -p /repos/friendica/. friendica
370
-            cd friendica
372
+            cd friendica || exit 24682462
371 373
             git pull
372 374
         else
373 375
             function_check git_clone
374
-            git_clone $FRIENDICA_REPO friendica
376
+            git_clone "$FRIENDICA_REPO" friendica
375 377
         fi
376 378
 
377 379
         git checkout $FRIENDICA_COMMIT -b $FRIENDICA_COMMIT
378 380
         set_completion_param "friendica commit" "$FRIENDICA_COMMIT"
379 381
 
380
-        rm -rf $FRIENDICA_PATH
381
-        mv friendica $FRIENDICA_PATH
382
+        rm -rf "$FRIENDICA_PATH"
383
+        mv friendica "$FRIENDICA_PATH"
382 384
 
383
-        git_clone $FRIENDICA_ADDONS_REPO $FRIENDICA_PATH/addon
384
-        cd $FRIENDICA_PATH/addon
385
-        git checkout $FRIENDICA_ADDONS_COMMIT -b $FRIENDICA_ADDONS_COMMIT
385
+        git_clone "$FRIENDICA_ADDONS_REPO" "$FRIENDICA_PATH/addon"
386
+        cd "$FRIENDICA_PATH/addon" || exit 34835685
387
+        git checkout "$FRIENDICA_ADDONS_COMMIT" -b "$FRIENDICA_ADDONS_COMMIT"
386 388
         set_completion_param "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT"
387 389
 
388
-        chown -R www-data:www-data $FRIENDICA_PATH
390
+        chown -R www-data:www-data "$FRIENDICA_PATH"
389 391
     fi
390 392
 
391 393
     FRIENDICA_ONION_HOSTNAME=
@@ -400,158 +402,158 @@ function install_friendica {
400 402
     fi
401 403
 
402 404
     function_check add_ddns_domain
403
-    add_ddns_domain $FRIENDICA_DOMAIN_NAME
405
+    add_ddns_domain "$FRIENDICA_DOMAIN_NAME"
404 406
 
405
-    if [[ $ONION_ONLY == "no" ]]; then
407
+    if [[ "$ONION_ONLY" == "no" ]]; then
406 408
         function_check nginx_http_redirect
407
-        nginx_http_redirect $FRIENDICA_DOMAIN_NAME
408
-        echo 'server {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
409
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
410
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
411
-        echo "    root $FRIENDICA_PATH;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
412
-        echo "    server_name $FRIENDICA_DOMAIN_NAME;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
413
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
414
-        echo '    index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
415
-        echo '    charset utf-8;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
416
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
409
+        nginx_http_redirect "$FRIENDICA_DOMAIN_NAME"
410
+        { echo 'server {';
411
+          echo '    listen 443 ssl;';
412
+          echo '    #listen [::]:443 ssl;';
413
+          echo "    root $FRIENDICA_PATH;";
414
+          echo "    server_name $FRIENDICA_DOMAIN_NAME;";
415
+          echo "    error_log /dev/null;";
416
+          echo '    index index.php;';
417
+          echo '    charset utf-8;';
418
+          echo '    access_log /dev/null;'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
417 419
         function_check nginx_ssl
418
-        nginx_ssl $FRIENDICA_DOMAIN_NAME
420
+        nginx_ssl "$FRIENDICA_DOMAIN_NAME"
419 421
         function_check nginx_disable_sniffing
420
-        nginx_disable_sniffing $FRIENDICA_DOMAIN_NAME
421
-        echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
422
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
423
-        echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
424
-        echo '    location / {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
422
+        nginx_disable_sniffing "$FRIENDICA_DOMAIN_NAME"
423
+        { echo '    add_header Strict-Transport-Security max-age=15768000;';
424
+          echo '';
425
+          echo '    # rewrite to front controller as default rule';
426
+          echo '    location / {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
425 427
         function_check nginx_limits
426
-        nginx_limits $FRIENDICA_DOMAIN_NAME
427
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
428
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
429
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
430
-        echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
431
-        echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
432
-        echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
433
-        echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
434
-        echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
435
-        echo '        expires 30d;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
436
-        echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
437
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
438
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
439
-        echo '    # block these file types' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
440
-        echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
441
-        echo '        deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
442
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
443
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
444
-        echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
445
-        echo '    # or a unix socket' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
446
-        echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
428
+        nginx_limits "$FRIENDICA_DOMAIN_NAME"
429
+        { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
430
+          echo '    }';
431
+          echo '';
432
+          echo '    # statically serve these file types when possible';
433
+          echo '    # otherwise fall back to front controller';
434
+          echo '    # allow browser to cache them';
435
+          echo '    # added .htm for advanced source code editor library';
436
+          echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
437
+          echo '        expires 30d;';
438
+          echo "        try_files \$uri /index.php?q=\$uri&\$args;";
439
+          echo '    }';
440
+          echo '';
441
+          echo '    # block these file types';
442
+          echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
443
+          echo '        deny all;';
444
+          echo '    }';
445
+          echo '';
446
+          echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
447
+          echo '    # or a unix socket';
448
+          echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
447 449
         function_check nginx_limits
448
-        nginx_limits $FRIENDICA_DOMAIN_NAME
449
-        echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
450
-        echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
451
-        echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
452
-        echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
453
-        echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
454
-        echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
455
-        echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
456
-        echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
457
-        echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
458
-        echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
459
-        echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
460
-        echo '        # With php-fpm:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
461
-        echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
462
-        echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
463
-        echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
464
-        echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
465
-        echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
466
-        echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
467
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
468
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
469
-        echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
470
-        echo '    location ~ /\. {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
471
-        echo '        deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
472
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
473
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
474
-        echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
475
-        echo '      deny  all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
476
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
477
-        echo '}' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
478
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
450
+        nginx_limits "$FRIENDICA_DOMAIN_NAME"
451
+        { echo '        # Zero-day exploit defense.';
452
+          echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
453
+          echo "        # Won't work properly (404 error) if the file is not stored on this";
454
+          echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
455
+          echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
456
+          echo "        # another machine. And then cross your fingers that you won't get hacked.";
457
+          echo "        try_files \$uri \$uri/ /index.php;";
458
+          echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
459
+          echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
460
+          echo '        # With php-cgi alone:';
461
+          echo '        # fastcgi_pass 127.0.0.1:9000;';
462
+          echo '        # With php-fpm:';
463
+          echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
464
+          echo '        include fastcgi_params;';
465
+          echo '        fastcgi_read_timeout 30;';
466
+          echo '        fastcgi_index index.php;';
467
+          echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
468
+          echo '        fastcgi_read_timeout 300;';
469
+          echo '    }';
470
+          echo '';
471
+          echo '    # deny access to all dot files';
472
+          echo '    location ~ /\. {';
473
+          echo '        deny all;';
474
+          echo '    }';
475
+          echo '';
476
+          echo '    location ~ /\.ht {';
477
+          echo '      deny  all;';
478
+          echo '    }';
479
+          echo '}';
480
+          echo ''; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
479 481
     else
480
-        echo 'server {' > /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
481
-        echo "    listen 127.0.0.1:${FRIENDICA_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
482
-        echo "    root $FRIENDICA_PATH;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
483
-        echo "    server_name $FRIENDICA_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
484
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
485
-        echo '    index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
486
-        echo '    charset utf-8;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
487
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
488
-        echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
489
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
490
-        echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
491
-        echo '    location / {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
492
-        nginx_limits $FRIENDICA_DOMAIN_NAME
493
-        nginx_disable_sniffing $FRIENDICA_DOMAIN_NAME
494
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
495
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
496
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
497
-        echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
498
-        echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
499
-        echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
500
-        echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
501
-        echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
502
-        echo '        expires 30d;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
503
-        echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
504
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
505
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
506
-        echo '    # block these file types' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
507
-        echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
508
-        echo '        deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
509
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
510
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
511
-        echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
512
-        echo '    # or a unix socket' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
513
-        echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
514
-        nginx_limits $FRIENDICA_DOMAIN_NAME
515
-        nginx_disable_sniffing $FRIENDICA_DOMAIN_NAME
516
-        echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
517
-        echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
518
-        echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
519
-        echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
520
-        echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
521
-        echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
522
-        echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
523
-        echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
524
-        echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
525
-        echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
526
-        echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
527
-        echo '        # With php-fpm:' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
528
-        echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
529
-        echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
530
-        echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
531
-        echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
532
-        echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
533
-        echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
534
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
535
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
536
-        echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
537
-        echo '    location ~ /\. {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
538
-        echo '        deny all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
539
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
540
-        echo '' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
541
-        echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
542
-        echo '      deny  all;' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
543
-        echo '    }' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
544
-        echo '}' >> /etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME
482
+        { echo 'server {';
483
+          echo "    listen 127.0.0.1:${FRIENDICA_ONION_PORT} default_server;";
484
+          echo "    root $FRIENDICA_PATH;";
485
+          echo "    server_name $FRIENDICA_ONION_HOSTNAME;";
486
+          echo "    error_log /dev/null;";
487
+          echo '    index index.php;';
488
+          echo '    charset utf-8;';
489
+          echo '    access_log /dev/null;';
490
+          echo '    add_header Strict-Transport-Security max-age=15768000;';
491
+          echo '';
492
+          echo '    # rewrite to front controller as default rule';
493
+          echo '    location / {'; } > "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
494
+        nginx_limits "$FRIENDICA_DOMAIN_NAME"
495
+        nginx_disable_sniffing "$FRIENDICA_DOMAIN_NAME"
496
+        { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
497
+          echo '    }';
498
+          echo '';
499
+          echo '    # statically serve these file types when possible';
500
+          echo '    # otherwise fall back to front controller';
501
+          echo '    # allow browser to cache them';
502
+          echo '    # added .htm for advanced source code editor library';
503
+          echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
504
+          echo '        expires 30d;';
505
+          echo "        try_files \$uri /index.php?q=\$uri&\$args;";
506
+          echo '    }';
507
+          echo '';
508
+          echo '    # block these file types';
509
+          echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
510
+          echo '        deny all;';
511
+          echo '    }';
512
+          echo '';
513
+          echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
514
+          echo '    # or a unix socket';
515
+          echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
516
+        nginx_limits "$FRIENDICA_DOMAIN_NAME"
517
+        nginx_disable_sniffing "$FRIENDICA_DOMAIN_NAME"
518
+        { echo '        # Zero-day exploit defense.';
519
+          echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
520
+          echo "        # Won't work properly (404 error) if the file is not stored on this";
521
+          echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
522
+          echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
523
+          echo "        # another machine. And then cross your fingers that you won't get hacked.";
524
+          echo "        try_files \$uri \$uri/ /index.php;";
525
+          echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
526
+          echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
527
+          echo '        # With php-cgi alone:';
528
+          echo '        # fastcgi_pass 127.0.0.1:9000;';
529
+          echo '        # With php-fpm:';
530
+          echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
531
+          echo '        include fastcgi_params;';
532
+          echo '        fastcgi_read_timeout 30;';
533
+          echo '        fastcgi_index index.php;';
534
+          echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
535
+          echo '        fastcgi_read_timeout 300;';
536
+          echo '    }';
537
+          echo '';
538
+          echo '    # deny access to all dot files';
539
+          echo '    location ~ /\. {';
540
+          echo '        deny all;';
541
+          echo '    }';
542
+          echo '';
543
+          echo '    location ~ /\.ht {';
544
+          echo '      deny  all;';
545
+          echo '    }';
546
+          echo '}'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
545 547
     fi
546 548
 
547 549
     function_check configure_php
548 550
     configure_php
549 551
 
550 552
     function_check create_site_certificate
551
-    create_site_certificate $FRIENDICA_DOMAIN_NAME 'yes'
553
+    create_site_certificate "$FRIENDICA_DOMAIN_NAME" 'yes'
552 554
 
553
-    if [ ! -d $FRIENDICA_PATH/view/tpl/smarty3 ]; then
554
-        mkdir $FRIENDICA_PATH/view/tpl/smarty3
555
+    if [ ! -d "$FRIENDICA_PATH/view/tpl/smarty3" ]; then
556
+        mkdir "$FRIENDICA_PATH/view/tpl/smarty3"
555 557
     fi
556 558
     if [ ! -d "$FRIENDICA_PATH/store" ]; then
557 559
         mkdir "$FRIENDICA_PATH/store"
@@ -563,9 +565,9 @@ function install_friendica {
563 565
         mkdir "$FRIENDICA_PATH/store/[data]/smarty3"
564 566
         chmod 1777 "$FRIENDICA_PATH/store/[data]/smarty3"
565 567
     fi
566
-    chmod 1777 $FRIENDICA_PATH/view/tpl
568
+    chmod 1777 "$FRIENDICA_PATH/view/tpl"
567 569
     chown -R www-data:www-data "$FRIENDICA_PATH/store"
568
-    chmod 1777 $FRIENDICA_PATH/view/tpl/smarty3
570
+    chmod 1777 "$FRIENDICA_PATH/view/tpl/smarty3"
569 571
 
570 572
     # Ensure that the database gets backed up locally, if remote
571 573
     # backups are not being used
@@ -575,55 +577,55 @@ function install_friendica {
575 577
     function_check backup_database_local
576 578
     backup_database_local friendica
577 579
 
578
-    chown -R www-data:www-data $FRIENDICA_PATH
580
+    chown -R www-data:www-data "$FRIENDICA_PATH"
579 581
 
580 582
     function_check nginx_ensite
581
-    nginx_ensite $FRIENDICA_DOMAIN_NAME
583
+    nginx_ensite "$FRIENDICA_DOMAIN_NAME"
582 584
 
583 585
     # initialize the database
584
-    if [ ! -f $FRIENDICA_PATH/database.sql ]; then
586
+    if [ ! -f "$FRIENDICA_PATH/database.sql" ]; then
585 587
         echo $'No database schema found for friendica'
586 588
         exit 252782
587 589
     fi
588 590
     function_check initialise_database
589
-    initialise_database friendica $FRIENDICA_PATH/database.sql
591
+    initialise_database friendica "$FRIENDICA_PATH/database.sql"
590 592
 
591 593
     # create the config file
592
-    echo '<?php' > $FRIENDICA_PATH/.htconfig.php
593
-    echo "\$db_host = 'localhost';" >> $FRIENDICA_PATH/.htconfig.php
594
-    echo "\$db_user = 'root';" >> $FRIENDICA_PATH/.htconfig.php
595
-    echo "\$db_pass = '${MARIADB_PASSWORD}';" >> $FRIENDICA_PATH/.htconfig.php
596
-    echo "\$db_data = 'friendica';" >> $FRIENDICA_PATH/.htconfig.php
597
-    echo "\$default_timezone = 'Europe/London';" >> $FRIENDICA_PATH/.htconfig.php
594
+    { echo '<?php';
595
+      echo "\$db_host = 'localhost';";
596
+      echo "\$db_user = 'root';";
597
+      echo "\$db_pass = '${MARIADB_PASSWORD}';";
598
+      echo "\$db_data = 'friendica';";
599
+      echo "\$default_timezone = 'Europe/London';"; } > "$FRIENDICA_PATH/.htconfig.php"
598 600
     if [[ $ONION_ONLY == 'no' ]]; then
599
-        echo "\$a->config['system']['baseurl'] = 'https://${FRIENDICA_DOMAIN_NAME}';" >> $FRIENDICA_PATH/.htconfig.php
601
+        echo "\$a->config['system']['baseurl'] = 'https://${FRIENDICA_DOMAIN_NAME}';" >> "$FRIENDICA_PATH/.htconfig.php"
600 602
     else
601
-        echo "\$a->config['system']['baseurl'] = 'http://${FRIENDICA_ONION_HOSTNAME}';" >> $FRIENDICA_PATH/.htconfig.php
602
-    fi
603
-    echo "\$a->config['sitename'] = \"Friendica\";" >> $FRIENDICA_PATH/.htconfig.php
604
-    echo "\$a->config['register_policy'] = REGISTER_OPEN;" >> $FRIENDICA_PATH/.htconfig.php
605
-    echo "\$a->config['register_text'] = '';" >> $FRIENDICA_PATH/.htconfig.php
606
-    echo "\$a->config['admin_email'] = '${MY_EMAIL_ADDRESS}';" >> $FRIENDICA_PATH/.htconfig.php
607
-    echo "\$a->config['system']['no_regfullname'] = true;" >> $FRIENDICA_PATH/.htconfig.php
608
-    echo "\$a->config['max_import_size'] = 200000;" >> $FRIENDICA_PATH/.htconfig.php
609
-    echo "\$a->config['system']['maximagesize'] = 800000;" >> $FRIENDICA_PATH/.htconfig.php
610
-    echo "\$a->config['php_path'] = '/usr/bin/php';" >> $FRIENDICA_PATH/.htconfig.php
611
-    echo "\$a->config['system']['directory'] = 'http://dir.friendi.ca';" >> $FRIENDICA_PATH/.htconfig.php
612
-    echo "\$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero,smoothly';" >> $FRIENDICA_PATH/.htconfig.php
613
-    echo "\$a->config['system']['theme'] = 'vier';" >> $FRIENDICA_PATH/.htconfig.php
614
-    echo "\$a->config['system']['huburl'] = '[internal]';" >> $FRIENDICA_PATH/.htconfig.php
615
-    echo "\$a->config['system']['language'] = 'en';" >> $FRIENDICA_PATH/.htconfig.php
616
-    echo "\$a->config['system']['rino_encrypt'] = 2;" >> $FRIENDICA_PATH/.htconfig.php
617
-    echo "\$a->config['system']['allowed_link_protocols'] = array('mailto', 'cid');" >> $FRIENDICA_PATH/.htconfig.php
618
-    chown www-data:www-data $FRIENDICA_PATH/.htconfig.php
619
-    chmod 755 $FRIENDICA_PATH/.htconfig.php
603
+        echo "\$a->config['system']['baseurl'] = 'http://${FRIENDICA_ONION_HOSTNAME}';" >> "$FRIENDICA_PATH/.htconfig.php"
604
+    fi
605
+    { echo "\$a->config['sitename'] = \"Friendica\";";
606
+      echo "\$a->config['register_policy'] = REGISTER_OPEN;";
607
+      echo "\$a->config['register_text'] = '';";
608
+      echo "\$a->config['admin_email'] = '${MY_EMAIL_ADDRESS}';";
609
+      echo "\$a->config['system']['no_regfullname'] = true;";
610
+      echo "\$a->config['max_import_size'] = 200000;";
611
+      echo "\$a->config['system']['maximagesize'] = 800000;";
612
+      echo "\$a->config['php_path'] = '/usr/bin/php';";
613
+      echo "\$a->config['system']['directory'] = 'http://dir.friendi.ca';";
614
+      echo "\$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero,smoothly';";
615
+      echo "\$a->config['system']['theme'] = 'vier';";
616
+      echo "\$a->config['system']['huburl'] = '[internal]';";
617
+      echo "\$a->config['system']['language'] = 'en';";
618
+      echo "\$a->config['system']['rino_encrypt'] = 2;";
619
+      echo "\$a->config['system']['allowed_link_protocols'] = array('mailto', 'cid');"; } >> "$FRIENDICA_PATH/.htconfig.php"
620
+    chown www-data:www-data "$FRIENDICA_PATH/.htconfig.php"
621
+    chmod 755 "$FRIENDICA_PATH/.htconfig.php"
620 622
 
621 623
     systemctl restart mariadb
622 624
     systemctl restart php7.0-fpm
623 625
     systemctl restart nginx
624 626
     systemctl restart cron
625 627
 
626
-    ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$FRIENDICA_DOMAIN_NAME" -g friendica --public no
628
+    "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$FRIENDICA_DOMAIN_NAME" -g friendica --public no
627 629
 
628 630
     set_completion_param "friendica domain" "${FRIENDICA_DOMAIN_NAME}"
629 631
     APP_INSTALLED=1

+ 195
- 195
src/freedombone-app-ghost Просмотреть файл

@@ -48,14 +48,14 @@ ghost_variables=(GHOST_DOMAIN_NAME
48 48
 
49 49
 function ghost_bust {
50 50
     # kill the started ghost process
51
-    kill_pid=$(ps aux | grep "ghost run" | awk -F ' ' '{print $2}' | head -n 1)
52
-    kill -9 $kill_pid
51
+    kill_pid=$(pgrep "ghost run" | head -n 1)
52
+    kill -9 "$kill_pid"
53 53
 
54
-    kill_pid=$(ps aux | grep "ghost" | awk -F ' ' '{print $2}' | head -n 1)
55
-    kill -9 $kill_pid
54
+    kill_pid=$(pgrep "ghost" | head -n 1)
55
+    kill -9 "$kill_pid"
56 56
 
57
-    kill_pid=$(ps aux | grep "ghost" | awk -F ' ' '{print $2}' | head -n 1)
58
-    kill -9 $kill_pid
57
+    kill_pid=$(pgrep "ghost" | head -n 1)
58
+    kill -9 "$kill_pid"
59 59
 }
60 60
 
61 61
 function logging_on_ghost {
@@ -77,9 +77,9 @@ function ghost_replace_jquery {
77 77
     sed -i "s|http://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
78 78
     sed -i "s|https://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
79 79
 
80
-    cd /var/www/${GHOST_DOMAIN_NAME}/htdocs/current
81
-    find ./ -type f -exec sed -i -e 's|https://code.jquery.com|$curr_domain|g' {} \;
82
-    find ./ -type f -exec sed -i -e 's|http://code.jquery.com|$curr_domain|g' {} \;
80
+    cd "/var/www/${GHOST_DOMAIN_NAME}/htdocs/current" || exit 3468368
81
+    find ./ -type f -exec sed -i -e "s|https://code.jquery.com|$curr_domain|g" {} \;
82
+    find ./ -type f -exec sed -i -e "s|http://code.jquery.com|$curr_domain|g" {} \;
83 83
 }
84 84
 
85 85
 function ghost_rss_button {
@@ -98,14 +98,14 @@ function ghost_remove_offsite_links {
98 98
     ghost_rss_button
99 99
 
100 100
     # remove google font links
101
-    cd /var/www/$GHOST_DOMAIN_NAME/htdocs/current
102
-    find ./ -type f -exec sed -i -e 's/fonts.googleapis.com/$curr_domain/g' {} \;
101
+    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs/current" || exit 246872424
102
+    find ./ -type f -exec sed -i -e "s/fonts.googleapis.com/$curr_domain/g" {} \;
103 103
 
104 104
     # copy jquery locally
105 105
     previous_jquery_version='1.12.0'
106 106
     jquery_version='1.12.4'
107 107
     if [ ! -f /var/www/$GHOST_DOMAIN_NAME/htdocs/jquery-${jquery_version}.js ]; then
108
-        cd /var/www/$GHOST_DOMAIN_NAME/htdocs
108
+        cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 3468746824
109 109
         wget https://code.jquery.com/jquery-${jquery_version}.js
110 110
         jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
111 111
         if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
@@ -119,27 +119,27 @@ function ghost_remove_offsite_links {
119 119
 }
120 120
 
121 121
 function ghost_replace_proprietary_services {
122
-    replace_file=$1
123
-
124
-    sed -i 's|Twitter Profile|GNU Social Profile|g' $replace_file
125
-    sed -i 's|Twitter profile|GNU Social Profile|g' $replace_file
126
-    sed -i 's|Twitter Username|GNU Social Username|g' $replace_file
127
-    sed -i 's|twitter.com|quitter.se|g' $replace_file
128
-    sed -i 's|Facebook Page|Hubzilla Channel|g' $replace_file
129
-    sed -i 's|Facebook Profile|Hubzilla Channel|g' $replace_file
130
-    sed -i 's|Facebook profile|Hubzilla Channel|g' $replace_file
131
-    sed -i 's|www.facebook.com/username|hubzilladomain/username|g' $replace_file
132
-    sed -i 's|www.facebook.com/ghost|hubzilladomain/username|g' $replace_file
133
-    sed -i 's|www.facebook.com/testuser|hubzilladomain/username|g' $replace_file
134
-    sed -i 's|www.facebook.com/testing|hubzilladomain/username|g' $replace_file
135
-    sed -i 's|www.facebook.com/test|hubzilladomain/username|g' $replace_file
136
-    sed -i 's|www.facebook.com/yourUsername|hubzilladomain/username|g' $replace_file
137
-    sed -i 's|www.facebook.com/yourPage|hubzilladomain/username|g' $replace_file
138
-    sed -i 's|Facebook Username|Hubzilla Channel|g' $replace_file
139
-    sed -i 's|www.facebook.com|hubzilladomain|g' $replace_file
140
-    sed -i 's|facebook value|hubzilla value|g' $replace_file
141
-
142
-    sed -i '/<section class="share">/,/<\/section>/d' $replace_file
122
+    replace_file="$1"
123
+
124
+    sed -i 's|Twitter Profile|GNU Social Profile|g' "$replace_file"
125
+    sed -i 's|Twitter profile|GNU Social Profile|g' "$replace_file"
126
+    sed -i 's|Twitter Username|GNU Social Username|g' "$replace_file"
127
+    sed -i 's|twitter.com|quitter.se|g' "$replace_file"
128
+    sed -i 's|Facebook Page|Hubzilla Channel|g' "$replace_file"
129
+    sed -i 's|Facebook Profile|Hubzilla Channel|g' "$replace_file"
130
+    sed -i 's|Facebook profile|Hubzilla Channel|g' "$replace_file"
131
+    sed -i 's|www.facebook.com/username|hubzilladomain/username|g' "$replace_file"
132
+    sed -i 's|www.facebook.com/ghost|hubzilladomain/username|g' "$replace_file"
133
+    sed -i 's|www.facebook.com/testuser|hubzilladomain/username|g' "$replace_file"
134
+    sed -i 's|www.facebook.com/testing|hubzilladomain/username|g' "$replace_file"
135
+    sed -i 's|www.facebook.com/test|hubzilladomain/username|g' "$replace_file"
136
+    sed -i 's|www.facebook.com/yourUsername|hubzilladomain/username|g' "$replace_file"
137
+    sed -i 's|www.facebook.com/yourPage|hubzilladomain/username|g' "$replace_file"
138
+    sed -i 's|Facebook Username|Hubzilla Channel|g' "$replace_file"
139
+    sed -i 's|www.facebook.com|hubzilladomain|g' "$replace_file"
140
+    sed -i 's|facebook value|hubzilla value|g' "$replace_file"
141
+
142
+    sed -i '/<section class="share">/,/<\/section>/d' "$replace_file"
143 143
 }
144 144
 
145 145
 function ghost_replace_services {
@@ -163,7 +163,7 @@ function add_user_ghost {
163 163
 }
164 164
 
165 165
 function install_interactive_ghost {
166
-    if [ ! $ONION_ONLY ]; then
166
+    if [ ! "$ONION_ONLY" ]; then
167 167
         ONION_ONLY='no'
168 168
     fi
169 169
 
@@ -178,13 +178,13 @@ function install_interactive_ghost {
178 178
 }
179 179
 
180 180
 function change_password_ghost {
181
-    GHOST_USERNAME="$1"
181
+    #GHOST_USERNAME="$1"
182 182
     GHOST_PASSWORD="$2"
183 183
     if [ ${#GHOST_PASSWORD} -lt 8 ]; then
184 184
         echo $'Ghost password is too short'
185 185
         return
186 186
     fi
187
-    #${PROJECT_NAME}-pass -u $GHOST_USERNAME -a ghost -p "$GHOST_PASSWORD"
187
+    #"${PROJECT_NAME}-pass" -u "$GHOST_USERNAME" -a ghost -p "$GHOST_PASSWORD"
188 188
 }
189 189
 
190 190
 function reconfigure_ghost {
@@ -206,7 +206,7 @@ function upgrade_ghost {
206 206
     systemctl stop ghost
207 207
     ghost_bust
208 208
 
209
-    cd /var/www/$GHOST_DOMAIN_NAME/htdocs
209
+    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 3468463
210 210
 
211 211
     npm i -g ghost-cli
212 212
     /usr/local/bin/ghost update &
@@ -220,26 +220,26 @@ function upgrade_ghost {
220 220
     chown -R root:root /usr/local/lib
221 221
     chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
222 222
     systemctl restart ghost
223
-    sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" ${COMPLETION_FILE}
223
+    sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" "${COMPLETION_FILE}"
224 224
 }
225 225
 
226 226
 function backup_local_ghost {
227 227
     GHOST_DOMAIN_NAME='ghost.local'
228
-    if grep -q "ghost domain" $COMPLETION_FILE; then
228
+    if grep -q "ghost domain" "$COMPLETION_FILE"; then
229 229
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
230 230
     fi
231 231
 
232
-    suspend_site ${GHOST_DOMAIN_NAME}
232
+    suspend_site "${GHOST_DOMAIN_NAME}"
233 233
     systemctl stop ghost
234 234
 
235 235
     ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
236
-    if [ -d $ghost_path ]; then
237
-        backup_directory_to_usb $ghost_path ghostcontent
236
+    if [ -d "$ghost_path" ]; then
237
+        backup_directory_to_usb "$ghost_path" ghostcontent
238 238
     fi
239 239
 
240 240
     ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/current/content
241
-    if [ -d $ghost_path ]; then
242
-        backup_directory_to_usb $ghost_path ghostcurrent
241
+    if [ -d "$ghost_path" ]; then
242
+        backup_directory_to_usb "$ghost_path" ghostcurrent
243 243
     fi
244 244
 
245 245
     systemctl start ghost
@@ -248,26 +248,26 @@ function backup_local_ghost {
248 248
 
249 249
 function restore_local_ghost {
250 250
     GHOST_DOMAIN_NAME='ghost.local'
251
-    if grep -q "ghost domain" $COMPLETION_FILE; then
251
+    if grep -q "ghost domain" "$COMPLETION_FILE"; then
252 252
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
253 253
     fi
254
-    if [ $GHOST_DOMAIN_NAME ]; then
255
-        suspend_site ${GHOST_DOMAIN_NAME}
254
+    if [ "$GHOST_DOMAIN_NAME" ]; then
255
+        suspend_site "${GHOST_DOMAIN_NAME}"
256 256
         systemctl stop ghost
257 257
 
258 258
         temp_restore_dir=/root/tempghostcontent
259 259
         function_check restore_directory_from_usb
260 260
         restore_directory_from_usb $temp_restore_dir ghostcontent
261 261
         if [ -d $temp_restore_dir ]; then
262
-            if [ -d $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content ]; then
263
-                cp -r $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
262
+            if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
263
+                cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/*" "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
264 264
             else
265
-                if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs/content ]; then
266
-                    mkdir /var/www/$GHOST_DOMAIN_NAME/htdocs/content
265
+                if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
266
+                    mkdir "/var/www/$GHOST_DOMAIN_NAME/htdocs/content"
267 267
                 fi
268
-                cp -r $temp_restore_dir/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
268
+                cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
269 269
             fi
270
-            chown -R ghost:ghost /var/www/$GHOST_DOMAIN_NAME/htdocs/content
270
+            chown -R ghost:ghost "/var/www/$GHOST_DOMAIN_NAME/htdocs/content"
271 271
             rm -rf $temp_restore_dir
272 272
         fi
273 273
 
@@ -275,15 +275,15 @@ function restore_local_ghost {
275 275
         function_check restore_directory_from_usb
276 276
         restore_directory_from_usb $temp_restore_dir ghostcurrent
277 277
         if [ -d $temp_restore_dir ]; then
278
-            if [ -d $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content ]; then
279
-                cp -r $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/* /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/
278
+            if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
279
+                cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/*" "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
280 280
             else
281
-                if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content ]; then
282
-                    mkdir -p /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content
281
+                if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
282
+                    mkdir -p "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content"
283 283
                 fi
284
-                cp -r $temp_restore_dir/* /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/
284
+                cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
285 285
             fi
286
-            chown -R ghost:ghost /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content
286
+            chown -R ghost:ghost "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content"
287 287
             rm -rf $temp_restore_dir
288 288
         fi
289 289
 
@@ -294,15 +294,15 @@ function restore_local_ghost {
294 294
 
295 295
 function backup_remote_ghost {
296 296
     GHOST_DOMAIN_NAME='ghost.local'
297
-    if grep -q "ghost domain" $COMPLETION_FILE; then
297
+    if grep -q "ghost domain" "$COMPLETION_FILE"; then
298 298
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
299 299
     fi
300 300
 
301
-    suspend_site ${GHOST_DOMAIN_NAME}
301
+    suspend_site "${GHOST_DOMAIN_NAME}"
302 302
 
303 303
     temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
304
-    if [ -d $temp_backup_dir ]; then
305
-        backup_directory_to_friend $temp_backup_dir ghostcontent
304
+    if [ -d "$temp_backup_dir" ]; then
305
+        backup_directory_to_friend "$temp_backup_dir" ghostcontent
306 306
     else
307 307
         restart_site
308 308
         echo $"Ghost domain specified but not found in /var/www/${GHOST_DOMAIN_NAME}"
@@ -310,8 +310,8 @@ function backup_remote_ghost {
310 310
     fi
311 311
 
312 312
     temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/current/content
313
-    if [ -d $temp_backup_dir ]; then
314
-        backup_directory_to_friend $temp_backup_dir ghostcurrent
313
+    if [ -d "$temp_backup_dir" ]; then
314
+        backup_directory_to_friend "$temp_backup_dir" ghostcurrent
315 315
     else
316 316
         restart_site
317 317
         echo $"Ghost domain specified but not found in $temp_backup_dir"
@@ -323,10 +323,10 @@ function backup_remote_ghost {
323 323
 
324 324
 function restore_remote_ghost {
325 325
     GHOST_DOMAIN_NAME='ghost.local'
326
-    if grep -q "ghost domain" $COMPLETION_FILE; then
326
+    if grep -q "ghost domain" "$COMPLETION_FILE"; then
327 327
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
328 328
     fi
329
-    suspend_site ${GHOST_DOMAIN_NAME}
329
+    suspend_site "${GHOST_DOMAIN_NAME}"
330 330
 
331 331
     systemctl stop ghost
332 332
 
@@ -334,15 +334,15 @@ function restore_remote_ghost {
334 334
     function_check restore_directory_from_friend
335 335
     restore_directory_from_friend $temp_restore_dir ghostcontent
336 336
     if [ -d $temp_restore_dir ]; then
337
-        if [ -d $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content ]; then
338
-            cp -r $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
337
+        if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
338
+            cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/content/*" "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
339 339
         else
340
-            if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs/content ]; then
341
-                mkdir /var/www/$GHOST_DOMAIN_NAME/htdocs/content
340
+            if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
341
+                mkdir "/var/www/$GHOST_DOMAIN_NAME/htdocs/content"
342 342
             fi
343
-            cp -r $temp_restore_dir/* /var/www/$GHOST_DOMAIN_NAME/htdocs/content/
343
+            cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/content/"
344 344
         fi
345
-        chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs
345
+        chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
346 346
         rm -rf $temp_restore_dir
347 347
     fi
348 348
 
@@ -350,15 +350,15 @@ function restore_remote_ghost {
350 350
     function_check restore_directory_from_friend
351 351
     restore_directory_from_friend $temp_restore_dir ghostcurrent
352 352
     if [ -d $temp_restore_dir ]; then
353
-        if [ -d $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content ]; then
354
-            cp -r $temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/* /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/
353
+        if [ -d "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
354
+            cp -r "$temp_restore_dir/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/*" "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
355 355
         else
356
-            if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content ]; then
357
-                mkdir -p /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content
356
+            if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content" ]; then
357
+                mkdir -p "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content"
358 358
             fi
359
-            cp -r $temp_restore_dir/* /var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/
359
+            cp -r $temp_restore_dir/* "/var/www/$GHOST_DOMAIN_NAME/htdocs/current/content/"
360 360
         fi
361
-        chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs
361
+        chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
362 362
         rm -rf $temp_restore_dir
363 363
     fi
364 364
 
@@ -382,27 +382,27 @@ function remove_ghost {
382 382
     remove_nodejs ghost
383 383
 
384 384
     read_config_param "GHOST_DOMAIN_NAME"
385
-    nginx_dissite $GHOST_DOMAIN_NAME
386
-    remove_certs ${GHOST_DOMAIN_NAME}
387
-    if [ -f /etc/nginx/sites-available/$GHOST_DOMAIN_NAME ]; then
388
-        rm -f /etc/nginx/sites-available/$GHOST_DOMAIN_NAME
385
+    nginx_dissite "$GHOST_DOMAIN_NAME"
386
+    remove_certs "${GHOST_DOMAIN_NAME}"
387
+    if [ -f "/etc/nginx/sites-available/$GHOST_DOMAIN_NAME" ]; then
388
+        rm -f "/etc/nginx/sites-available/$GHOST_DOMAIN_NAME"
389 389
     fi
390
-    if [ -d /var/www/$GHOST_DOMAIN_NAME ]; then
391
-        rm -rf /var/www/$GHOST_DOMAIN_NAME
390
+    if [ -d "/var/www/$GHOST_DOMAIN_NAME" ]; then
391
+        rm -rf "/var/www/$GHOST_DOMAIN_NAME"
392 392
     fi
393 393
     remove_config_param GHOST_DOMAIN_NAME
394 394
     remove_config_param GHOST_CODE
395 395
     function_check remove_onion_service
396 396
     remove_onion_service ghost ${GHOST_ONION_PORT}
397 397
     remove_completion_param "install_ghost"
398
-    sed -i '/Ghost/d' $COMPLETION_FILE
399
-    sed -i '/ghost/d' $COMPLETION_FILE
398
+    sed -i '/Ghost/d' "$COMPLETION_FILE"
399
+    sed -i '/ghost/d' "$COMPLETION_FILE"
400 400
 
401 401
     groupdel -f ghost
402 402
     userdel -r ghost
403 403
 
404 404
     function_check remove_ddns_domain
405
-    remove_ddns_domain $GHOST_DOMAIN_NAME
405
+    remove_ddns_domain "$GHOST_DOMAIN_NAME"
406 406
 }
407 407
 
408 408
 function install_ghost {
@@ -412,7 +412,7 @@ function install_ghost {
412 412
         ONION_ONLY='no'
413 413
     fi
414 414
 
415
-    if [ ! $GHOST_DOMAIN_NAME ]; then
415
+    if [ ! "$GHOST_DOMAIN_NAME" ]; then
416 416
         echo $'The ghost domain name was not specified'
417 417
         exit 5062
418 418
     fi
@@ -420,10 +420,10 @@ function install_ghost {
420 420
     # for the avatar changing command
421 421
     apt-get -yq install unzip wget
422 422
 
423
-    if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs ]; then
424
-        mkdir -p /var/www/$GHOST_DOMAIN_NAME/htdocs
423
+    if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs" ]; then
424
+        mkdir -p "/var/www/$GHOST_DOMAIN_NAME/htdocs"
425 425
     fi
426
-    cd /var/www/$GHOST_DOMAIN_NAME/htdocs
426
+    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 26422842
427 427
 
428 428
     function_check install_nodejs
429 429
     install_nodejs ghost
@@ -440,66 +440,66 @@ function install_ghost {
440 440
     npm install -g yarn
441 441
     yarn install --no-emoji --no-progress
442 442
     yarn cache clean
443
-    adduser --system --home=/var/www/${GHOST_DOMAIN_NAME}/htdocs/ --group ghost
444
-    rm -rf /var/www/$GHOST_DOMAIN_NAME/htdocs/*
443
+    adduser --system --home="/var/www/${GHOST_DOMAIN_NAME}/htdocs/" --group ghost
444
+    rm -rf "/var/www/$GHOST_DOMAIN_NAME/htdocs/*"
445 445
     printf 'y' | ghost install ${GHOST_VERSION} --user ghost --db=sqlite3 --port ${GHOST_PORT} --verbose
446 446
 
447
-    if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs/versions ]; then
447
+    if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/versions" ]; then
448 448
         echo $'versions directory was not found'
449 449
         exit 782523462
450 450
     fi
451
-    if [ ! -d /var/www/$GHOST_DOMAIN_NAME/htdocs/content ]; then
451
+    if [ ! -d "/var/www/$GHOST_DOMAIN_NAME/htdocs/content" ]; then
452 452
         echo $'content directory was not found'
453 453
         exit 68352682
454 454
     fi
455 455
 
456 456
     npm install -g knex-migrator
457
-    if [ ! -f /var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/MigratorConfig.js ]; then
457
+    if [ ! -f "/var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/MigratorConfig.js" ]; then
458 458
         echo $'MigratorConfig.js was not found'
459 459
         exit 62783538
460 460
     fi
461
-    cp /var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/MigratorConfig.js /var/www/$GHOST_DOMAIN_NAME/htdocs
462
-    chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs
463
-    cd /var/www/$GHOST_DOMAIN_NAME/htdocs/current
461
+    cp "/var/www/$GHOST_DOMAIN_NAME/htdocs/versions/${GHOST_VERSION}/MigratorConfig.js" "/var/www/$GHOST_DOMAIN_NAME/htdocs"
462
+    chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
463
+    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs/current" || exit 783452464
464 464
     knex-migrator init
465 465
 
466 466
     ghost_bust
467 467
 
468
-    echo '{' > /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
468
+    echo '{' > "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
469 469
     if [[ "$ONION_ONLY" == 'no' ]]; then
470 470
         # NOTE: url must be http, not https
471
-        echo "  \"url\": \"http://${GHOST_DOMAIN_NAME}\"," >> /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
471
+        echo "  \"url\": \"http://${GHOST_DOMAIN_NAME}\"," >> "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
472 472
     else
473
-        echo "  \"url\": \"http://${GHOST_ONION_HOSTNAME}\"," >> /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
474
-    fi
475
-    echo '    "paths": {' >> /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
476
-    echo "        \"contentPath\": \"/var/www/${GHOST_DOMAIN_NAME}/htdocs/content\"" >> /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
477
-    echo '    }' >> /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
478
-    echo '}' >> /var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json
479
-
480
-    echo '[Unit]' > /etc/systemd/system/ghost.service
481
-    echo 'Description=Ghost Blog' >> /etc/systemd/system/ghost.service
482
-    echo 'After=syslog.target' >> /etc/systemd/system/ghost.service
483
-    echo 'After=network.target' >> /etc/systemd/system/ghost.service
484
-    echo '' >> /etc/systemd/system/ghost.service
485
-    echo '[Service]' >> /etc/systemd/system/ghost.service
486
-    echo 'Type=simple' >> /etc/systemd/system/ghost.service
487
-    echo 'User=ghost' >> /etc/systemd/system/ghost.service
488
-    echo 'Group=ghost' >> /etc/systemd/system/ghost.service
489
-    echo "WorkingDirectory=/var/www/${GHOST_DOMAIN_NAME}/htdocs" >> /etc/systemd/system/ghost.service
490
-    echo "ExecStart=/usr/local/bin/ghost run -D" >> /etc/systemd/system/ghost.service
491
-    echo "ExecStop=/usr/local/bin/ghost stop" >> /etc/systemd/system/ghost.service
492
-    echo "ExecRestart=/usr/local/bin/ghost restart" >> /etc/systemd/system/ghost.service
493
-    echo 'Restart=always' >> /etc/systemd/system/ghost.service
494
-    echo 'RestartSec=60' >> /etc/systemd/system/ghost.service
495
-    echo "Environment=NODE_ENV=development PORT=${GHOST_PORT}" >> /etc/systemd/system/ghost.service
496
-    echo '' >> /etc/systemd/system/ghost.service
497
-    echo '[Install]' >> /etc/systemd/system/ghost.service
498
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ghost.service
473
+        echo "  \"url\": \"http://${GHOST_ONION_HOSTNAME}\"," >> "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
474
+    fi
475
+    { echo '    "paths": {';
476
+      echo "        \"contentPath\": \"/var/www/${GHOST_DOMAIN_NAME}/htdocs/content\"";
477
+      echo '    }';
478
+      echo '}'; } >> "/var/www/${GHOST_DOMAIN_NAME}/htdocs/config.development.json"
479
+
480
+    { echo '[Unit]';
481
+      echo 'Description=Ghost Blog';
482
+      echo 'After=syslog.target';
483
+      echo 'After=network.target';
484
+      echo '';
485
+      echo '[Service]';
486
+      echo 'Type=simple';
487
+      echo 'User=ghost';
488
+      echo 'Group=ghost';
489
+      echo "WorkingDirectory=/var/www/${GHOST_DOMAIN_NAME}/htdocs";
490
+      echo "ExecStart=/usr/local/bin/ghost run -D";
491
+      echo "ExecStop=/usr/local/bin/ghost stop";
492
+      echo "ExecRestart=/usr/local/bin/ghost restart";
493
+      echo 'Restart=always';
494
+      echo 'RestartSec=60';
495
+      echo "Environment=NODE_ENV=development PORT=${GHOST_PORT}";
496
+      echo '';
497
+      echo '[Install]';
498
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/ghost.service
499 499
 
500 500
     ghost_remove_offsite_links
501 501
 
502
-    chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
502
+    chown -R ghost: "/var/www/${GHOST_DOMAIN_NAME}/htdocs"
503 503
 
504 504
     systemctl enable ghost
505 505
     systemctl daemon-reload
@@ -507,94 +507,94 @@ function install_ghost {
507 507
 
508 508
     if [[ ${ONION_ONLY} == "no" ]]; then
509 509
         function_check nginx_http_redirect
510
-        nginx_http_redirect ${GHOST_DOMAIN_NAME}
511
-        echo 'server {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
512
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
513
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
514
-        echo "    root /var/www/${GHOST_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
515
-        echo "    server_name ${GHOST_DOMAIN_NAME};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
516
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
517
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
518
-        echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
510
+        nginx_http_redirect "${GHOST_DOMAIN_NAME}"
511
+        { echo 'server {';
512
+          echo '    listen 443 ssl;';
513
+          echo '    #listen [::]:443 ssl;';
514
+          echo "    root /var/www/${GHOST_DOMAIN_NAME}/htdocs;";
515
+          echo "    server_name ${GHOST_DOMAIN_NAME};";
516
+          echo '    access_log /dev/null;';
517
+          echo "    error_log /dev/null;";
518
+          echo ''; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
519 519
         function_check nginx_ssl
520
-        nginx_ssl ${GHOST_DOMAIN_NAME}
520
+        nginx_ssl "${GHOST_DOMAIN_NAME}"
521 521
         function_check nginx_disable_sniffing
522
-        nginx_disable_sniffing ${GHOST_DOMAIN_NAME}
523
-        echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
524
-        echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
525
-        echo '    location / {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
522
+        nginx_disable_sniffing "${GHOST_DOMAIN_NAME}"
523
+        { echo '    add_header Strict-Transport-Security max-age=0;';
524
+          echo '';
525
+          echo '    location / {'; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
526 526
         function_check nginx_limits
527
-        nginx_limits ${GHOST_DOMAIN_NAME} '10G'
528
-        echo "        proxy_pass http://localhost:${GHOST_PORT};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
529
-        echo '    }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
530
-        echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
531
-        echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
532
-        echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
533
-        echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
534
-        echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
535
-        echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
536
-        echo '    location = /robots.txt {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
537
-        echo '        allow all;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
538
-        echo '        log_not_found off;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
539
-        echo '        access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
540
-        echo '    }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
541
-        echo '}' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
542
-        echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
527
+        nginx_limits "${GHOST_DOMAIN_NAME}" '10G'
528
+        { echo "        proxy_pass http://localhost:${GHOST_PORT};";
529
+          echo '    }';
530
+          echo '';
531
+          echo '    fastcgi_buffers 64 4K;';
532
+          echo '';
533
+          echo '    error_page 403 /core/templates/403.php;';
534
+          echo '    error_page 404 /core/templates/404.php;';
535
+          echo '';
536
+          echo '    location = /robots.txt {';
537
+          echo '        allow all;';
538
+          echo '        log_not_found off;';
539
+          echo '        access_log /dev/null;';
540
+          echo '    }';
541
+          echo '}';
542
+          echo ''; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
543 543
     else
544
-        echo -n '' > /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
545
-    fi
546
-    echo 'server {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
547
-    echo "    listen 127.0.0.1:${GHOST_ONION_PORT} default_server;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
548
-    echo "    root /var/www/$GHOST_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
549
-    echo "    server_name $GHOST_ONION_HOSTNAME;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
550
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
551
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
552
-    echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
544
+        echo -n '' > "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
545
+    fi
546
+    { echo 'server {';
547
+      echo "    listen 127.0.0.1:${GHOST_ONION_PORT} default_server;";
548
+      echo "    root /var/www/$GHOST_DOMAIN_NAME/htdocs;";
549
+      echo "    server_name $GHOST_ONION_HOSTNAME;";
550
+      echo '    access_log /dev/null;';
551
+      echo "    error_log /dev/null;";
552
+      echo ''; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
553 553
     function_check nginx_disable_sniffing
554
-    nginx_disable_sniffing ${GHOST_DOMAIN_NAME}
555
-    echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
556
-    echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
557
-    echo '    location / {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
554
+    nginx_disable_sniffing "${GHOST_DOMAIN_NAME}"
555
+    { echo '    add_header Strict-Transport-Security max-age=0;';
556
+      echo '';
557
+      echo '    location / {'; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
558 558
     function_check nginx_limits
559
-    nginx_limits ${GHOST_DOMAIN_NAME} '10G'
560
-    echo "        proxy_pass http://localhost:${GHOST_PORT};" >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
561
-    echo '    }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
562
-    echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
563
-    echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
564
-    echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
565
-    echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
566
-    echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
567
-    echo '' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
568
-    echo '    location = /robots.txt {' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
569
-    echo '        allow all;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
570
-    echo '        log_not_found off;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
571
-    echo '        access_log /dev/null;' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
572
-    echo '    }' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
573
-    echo '}' >> /etc/nginx/sites-available/${GHOST_DOMAIN_NAME}
559
+    nginx_limits "${GHOST_DOMAIN_NAME}" '10G'
560
+    { echo "        proxy_pass http://localhost:${GHOST_PORT};";
561
+      echo '    }';
562
+      echo '';
563
+      echo '    fastcgi_buffers 64 4K;';
564
+      echo '';
565
+      echo '    error_page 403 /core/templates/403.php;';
566
+      echo '    error_page 404 /core/templates/404.php;';
567
+      echo '';
568
+      echo '    location = /robots.txt {';
569
+      echo '        allow all;';
570
+      echo '        log_not_found off;';
571
+      echo '        access_log /dev/null;';
572
+      echo '    }';
573
+      echo '}'; } >> "/etc/nginx/sites-available/${GHOST_DOMAIN_NAME}"
574 574
 
575 575
     function_check create_site_certificate
576
-    create_site_certificate $GHOST_DOMAIN_NAME 'yes'
576
+    create_site_certificate "$GHOST_DOMAIN_NAME" 'yes'
577 577
 
578 578
     ghost_replace_services
579 579
 
580 580
     function_check nginx_ensite
581
-    nginx_ensite $GHOST_DOMAIN_NAME
581
+    nginx_ensite "$GHOST_DOMAIN_NAME"
582 582
 
583 583
     systemctl restart nginx
584 584
 
585
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a ghost -p "$GHOST_ADMIN_PASSWORD"
585
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a ghost -p "$GHOST_ADMIN_PASSWORD"
586 586
 
587 587
     function_check add_ddns_domain
588
-    add_ddns_domain $GHOST_DOMAIN_NAME
588
+    add_ddns_domain "$GHOST_DOMAIN_NAME"
589 589
 
590 590
     chown root:root /usr/local/bin/ghost
591 591
     chown -R root:root /usr/local/lib
592
-    chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
592
+    chown -R ghost: "/var/www/${GHOST_DOMAIN_NAME}/htdocs"
593 593
     set_completion_param "ghost domain" "$GHOST_DOMAIN_NAME"
594
-    if ! grep -q "ghost version:" ${COMPLETION_FILE}; then
595
-        echo "ghost version:${GHOST_VERSION}" >> ${COMPLETION_FILE}
594
+    if ! grep -q "ghost version:" "${COMPLETION_FILE}"; then
595
+        echo "ghost version:${GHOST_VERSION}" >> "${COMPLETION_FILE}"
596 596
     else
597
-        sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" ${COMPLETION_FILE}
597
+        sed -i "s|ghost version.*|ghost version:${GHOST_VERSION}|g" "${COMPLETION_FILE}"
598 598
     fi
599 599
 
600 600
     APP_INSTALLED=1

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


+ 222
- 215
src/freedombone-app-gogs Просмотреть файл

@@ -127,14 +127,14 @@ function gogs_parameters {
127 127
 }
128 128
 
129 129
 function gogs_create_database {
130
-    if [ -f ${IMAGE_PASSWORD_FILE} ]; then
131
-        GIT_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
130
+    if [ -f "${IMAGE_PASSWORD_FILE}" ]; then
131
+        GIT_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
132 132
     else
133
-        if [ ! ${GIT_ADMIN_PASSWORD} ]; then
134
-            GIT_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
133
+        if [ ! "${GIT_ADMIN_PASSWORD}" ]; then
134
+            GIT_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
135 135
         fi
136 136
     fi
137
-    if [ ! $GIT_ADMIN_PASSWORD ]; then
137
+    if [ ! "$GIT_ADMIN_PASSWORD" ]; then
138 138
         return
139 139
     fi
140 140
 
@@ -147,7 +147,7 @@ function reconfigure_gogs {
147 147
 }
148 148
 
149 149
 function upgrade_gogs {
150
-    if ! grep -q 'gogs version:' $COMPLETION_FILE; then
150
+    if ! grep -q 'gogs version:' "$COMPLETION_FILE"; then
151 151
         return
152 152
     fi
153 153
 
@@ -160,24 +160,24 @@ function upgrade_gogs {
160 160
 
161 161
     GOGS_CONFIG_PATH=/home/${GOGS_USERNAME}/custom/conf
162 162
     GOGS_CONFIG_FILE=$GOGS_CONFIG_PATH/app.ini
163
-    cp $GOGS_CONFIG_FILE $INSTALL_DIR/gogs_config.ini
163
+    cp "$GOGS_CONFIG_FILE $INSTALL_DIR/gogs_config.ini"
164 164
 
165
-    if [ -d $INSTALL_DIR/gogs-repositories ]; then
166
-        rm -rf $INSTALL_DIR/gogs-repositories
165
+    if [ -d "$INSTALL_DIR/gogs-repositories" ]; then
166
+        rm -rf "$INSTALL_DIR/gogs-repositories"
167 167
     fi
168 168
     if [ -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
169
-        mv /home/${GOGS_USERNAME}/gogs-repositories $INSTALL_DIR
169
+        mv "/home/${GOGS_USERNAME}/gogs-repositories" "$INSTALL_DIR"
170 170
     fi
171 171
 
172 172
     gogs_parameters
173 173
     echo "gogs binary upgrade: ${GOGS_BIN}"
174 174
 
175
-    if [ ! -d ${INSTALL_DIR} ]; then
176
-        mkdir -p ${INSTALL_DIR}
175
+    if [ ! -d "${INSTALL_DIR}" ]; then
176
+        mkdir -p "${INSTALL_DIR}"
177 177
     fi
178
-    cd ${INSTALL_DIR}
179
-    if [ -d ${INSTALL_DIR}/gogs ]; then
180
-        rm -rf ${INSTALL_DIR}/gogs
178
+    cd "${INSTALL_DIR}" || exit 26784427
179
+    if [ -d "${INSTALL_DIR}/gogs" ]; then
180
+        rm -rf "${INSTALL_DIR}/gogs"
181 181
     fi
182 182
     GOGS_FILE=linux_${CURR_ARCH}.tar.gz
183 183
     if [ ! -f ${GOGS_FILE} ]; then
@@ -196,13 +196,13 @@ function upgrade_gogs {
196 196
             unzip -o ${GOGS_FILE}
197 197
         fi
198 198
     else
199
-        tar -xzf ${INSTALL_DIR}/${GOGS_FILE}
199
+        tar -xzf "${INSTALL_DIR}/${GOGS_FILE}"
200 200
     fi
201
-    if [ ! -d ${INSTALL_DIR}/gogs ]; then
201
+    if [ ! -d "${INSTALL_DIR}/gogs" ]; then
202 202
         exit 37823
203 203
     fi
204
-    rm -rf /home/${GOGS_USERNAME}/*
205
-    cp -r ${INSTALL_DIR}/gogs/* /home/${GOGS_USERNAME}
204
+    rm -rf "/home/${GOGS_USERNAME:?}/"*
205
+    cp -r "${INSTALL_DIR}/gogs/*" "/home/${GOGS_USERNAME}"
206 206
     if [ -f ${GOGS_FILE} ]; then
207 207
         rm ${GOGS_FILE}
208 208
     fi
@@ -211,31 +211,31 @@ function upgrade_gogs {
211 211
         mkdir -p ${GOGS_CONFIG_PATH}
212 212
     fi
213 213
 
214
-    cp $INSTALL_DIR/gogs_config.ini $GOGS_CONFIG_FILE
214
+    cp "$INSTALL_DIR/gogs_config.ini" "$GOGS_CONFIG_FILE"
215 215
     if [ ! -f $GOGS_CONFIG_FILE ]; then
216 216
         echo $'Gogs ini file not upgraded'
217 217
         exit 873535
218 218
     fi
219
-    rm $INSTALL_DIR/gogs_config.ini
219
+    rm "$INSTALL_DIR/gogs_config.ini"
220 220
     if [ -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
221 221
         rm -rf /home/${GOGS_USERNAME}/gogs-repositories
222 222
     fi
223
-    if [ -d $INSTALL_DIR/gogs-repositories ]; then
224
-        mv $INSTALL_DIR/gogs-repositories /home/${GOGS_USERNAME}/gogs-repositories
223
+    if [ -d "$INSTALL_DIR/gogs-repositories" ]; then
224
+        mv "$INSTALL_DIR/gogs-repositories" "/home/${GOGS_USERNAME}/gogs-repositories"
225 225
     fi
226
-    chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
226
+    chown -R "${GOGS_USERNAME}":"${GOGS_USERNAME}" "/home/${GOGS_USERNAME}"
227 227
 
228
-    sed -i "s|gogs version.*|gogs version:$GOGS_VERSION|g" ${COMPLETION_FILE}
228
+    sed -i "s|gogs version.*|gogs version:$GOGS_VERSION|g" "${COMPLETION_FILE}"
229 229
     systemctl restart mariadb
230 230
     systemctl restart gogs
231 231
 }
232 232
 
233 233
 function backup_local_gogs {
234
-    if ! grep -q "gogs domain" ${COMPLETION_FILE}; then
234
+    if ! grep -q "gogs domain" "${COMPLETION_FILE}"; then
235 235
         return
236 236
     fi
237 237
 
238
-    if [ ! -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
238
+    if [ ! -d "/home/${GOGS_USERNAME}/gogs-repositories" ]; then
239 239
         return
240 240
     fi
241 241
 
@@ -245,15 +245,15 @@ function backup_local_gogs {
245 245
     backup_database_to_usb gogs
246 246
 
247 247
     function_check backup_directory_to_usb
248
-    backup_directory_to_usb /home/${GOGS_USERNAME}/custom gogs
249
-    backup_directory_to_usb /home/${GOGS_USERNAME}/gogs-repositories gogsrepos
250
-    backup_directory_to_usb /home/${GOGS_USERNAME}/.ssh gogsssh
248
+    backup_directory_to_usb "/home/${GOGS_USERNAME}/custom" gogs
249
+    backup_directory_to_usb "/home/${GOGS_USERNAME}/gogs-repositories" gogsrepos
250
+    backup_directory_to_usb "/home/${GOGS_USERNAME}/.ssh" gogsssh
251 251
 
252 252
     echo $"Gogs backup complete"
253 253
 }
254 254
 
255 255
 function restore_local_gogs {
256
-    if ! grep -q "gogs domain" ${COMPLETION_FILE}; then
256
+    if ! grep -q "gogs domain" "${COMPLETION_FILE}"; then
257 257
         return
258 258
     fi
259 259
 
@@ -261,22 +261,23 @@ function restore_local_gogs {
261 261
         function_check gogs_create_database
262 262
         gogs_create_database
263 263
 
264
-        GOGS_CONFIG_PATH=/home/${GOGS_USERNAME}/custom/conf
265
-        GOGS_CONFIG_FILE=${GOGS_CONFIG_PATH}/app.ini
264
+        GOGS_CONFIG_PATH="/home/${GOGS_USERNAME}/custom/conf"
265
+        GOGS_CONFIG_FILE="${GOGS_CONFIG_PATH}/app.ini"
266 266
 
267 267
         function_check restore_database
268
-        restore_database gogs ${GIT_DOMAIN_NAME}
268
+        restore_database gogs "${GIT_DOMAIN_NAME}"
269 269
         temp_restore_dir=/root/tempgogs
270
-        if [ -d ${USB_MOUNT}/backup/gogs ]; then
270
+        if [ -d "${USB_MOUNT}/backup/gogs" ]; then
271 271
             echo $"Restoring Gogs settings"
272 272
             if [ ! -d $GOGS_CONFIG_PATH ]; then
273 273
                 mkdir -p $GOGS_CONFIG_PATH
274 274
             fi
275
-            if [ -d /root/tempgogs/home/${GOGS_USERNAME}/custom ]; then
276
-                cp -r /root/tempgogs/home/${GOGS_USERNAME}/custom/* /home/${GOGS_USERNAME}/custom/
275
+            if [ -d "/root/tempgogs/home/${GOGS_USERNAME}/custom" ]; then
276
+                cp -r "/root/tempgogs/home/${GOGS_USERNAME}/custom/*" "/home/${GOGS_USERNAME}/custom/"
277 277
             else
278
-                cp -r /root/tempgogs/* /home/${GOGS_USERNAME}/custom/
278
+                cp -r "/root/tempgogs/*" "/home/${GOGS_USERNAME}/custom/"
279 279
             fi
280
+            # shellcheck disable=SC2181
280 281
             if [ ! "$?" = "0" ]; then
281 282
                 function_check set_user_permissions
282 283
                 set_user_permissions
@@ -286,15 +287,16 @@ function restore_local_gogs {
286 287
             fi
287 288
             echo $"Restoring Gogs repos"
288 289
             function_check restore_directory_from_usb
289
-            restore_directory_from_usb ${temp_restore_dir}repos gogsrepos
290
-            if [ ! -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
291
-                mkdir /home/${GOGS_USERNAME}/gogs-repositories
290
+            restore_directory_from_usb "${temp_restore_dir}repos" gogsrepos
291
+            if [ ! -d "/home/${GOGS_USERNAME}/gogs-repositories" ]; then
292
+                mkdir "/home/${GOGS_USERNAME}/gogs-repositories"
292 293
             fi
293
-            if [ -d ${temp_restore_dir}repos/home/${GOGS_USERNAME}/gogs-repositories ]; then
294
-                cp -r ${temp_restore_dir}repos/home/${GOGS_USERNAME}/gogs-repositories/* /home/${GOGS_USERNAME}/gogs-repositories/
294
+            if [ -d "${temp_restore_dir}repos/home/${GOGS_USERNAME}/gogs-repositories" ]; then
295
+                cp -r "${temp_restore_dir}repos/home/${GOGS_USERNAME}/gogs-repositories/*" "/home/${GOGS_USERNAME}/gogs-repositories/"
295 296
             else
296
-                cp -r ${temp_restore_dir}repos/* /home/${GOGS_USERNAME}/gogs-repositories/
297
+                cp -r "${temp_restore_dir}repos/*" "/home/${GOGS_USERNAME}/gogs-repositories/"
297 298
             fi
299
+            # shellcheck disable=SC2181
298 300
             if [ ! "$?" = "0" ]; then
299 301
                 function_check set_user_permissions
300 302
                 set_user_permissions
@@ -313,6 +315,7 @@ function restore_local_gogs {
313 315
             else
314 316
                 cp -r ${temp_restore_dir}/* /home/${GOGS_USERNAME}/.ssh/
315 317
             fi
318
+            # shellcheck disable=SC2181
316 319
             if [ ! "$?" = "0" ]; then
317 320
                 function_check set_user_permissions
318 321
                 set_user_permissions
@@ -326,7 +329,7 @@ function restore_local_gogs {
326 329
             chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
327 330
         fi
328 331
 
329
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
332
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
330 333
         sed -i "s|PASSWD =.*|PASSWD = $MARIADB_PASSWORD|g" ${GOGS_CONFIG_FILE}
331 334
         MARIADB_PASSWORD=
332 335
         systemctl restart gogs
@@ -363,7 +366,7 @@ function backup_remote_gogs {
363 366
 }
364 367
 
365 368
 function restore_remote_gogs {
366
-    if grep -q "gogs domain" $COMPLETION_FILE; then
369
+    if grep -q "gogs domain" "$COMPLETION_FILE"; then
367 370
         GIT_DOMAIN_NAME=$(get_completion_param "gogs domain")
368 371
 
369 372
         function_check gogs_create_database
@@ -373,8 +376,8 @@ function restore_remote_gogs {
373 376
         GOGS_CONFIG_FILE=${GOGS_CONFIG_PATH}/app.ini
374 377
 
375 378
         function_check restore_database_from_friend
376
-        restore_database_from_friend gogs ${GIT_DOMAIN_NAME}
377
-        if [ -d ${SERVER_DIRECTORY}/backup/gogs ]; then
379
+        restore_database_from_friend gogs "${GIT_DOMAIN_NAME}"
380
+        if [ -d "${SERVER_DIRECTORY}/backup/gogs" ]; then
378 381
             if [ ! -d $GOGS_CONFIG_PATH ]; then
379 382
                 mkdir -p $GOGS_CONFIG_PATH
380 383
             fi
@@ -383,6 +386,7 @@ function restore_remote_gogs {
383 386
             else
384 387
                 cp -r /root/tempgogs/* /home/${GOGS_USERNAME}/custom/
385 388
             fi
389
+            # shellcheck disable=SC2181
386 390
             if [ ! "$?" = "0" ]; then
387 391
                 exit 58852
388 392
             fi
@@ -396,6 +400,7 @@ function restore_remote_gogs {
396 400
             else
397 401
                 cp -r /root/tempgogsrepos/* /home/${GOGS_USERNAME}/gogs-repositories/
398 402
             fi
403
+            # shellcheck disable=SC2181
399 404
             if [ ! "$?" = "0" ]; then
400 405
                 exit 7649
401 406
             fi
@@ -409,6 +414,7 @@ function restore_remote_gogs {
409 414
             else
410 415
                 cp -r /root/tempgogsssh/* /home/${GOGS_USERNAME}/.ssh/
411 416
             fi
417
+            # shellcheck disable=SC2181
412 418
             if [ ! "$?" = "0" ]; then
413 419
                 exit 74239
414 420
             fi
@@ -419,7 +425,7 @@ function restore_remote_gogs {
419 425
             echo $"Restore of Gogs complete"
420 426
         fi
421 427
 
422
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
428
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
423 429
         sed -i "s|PASSWD =.*|PASSWD = $MARIADB_PASSWORD|g" ${GOGS_CONFIG_FILE}
424 430
         MARIADB_PASSWORD=
425 431
         systemctl restart gogs
@@ -433,33 +439,33 @@ function remove_gogs {
433 439
     systemctl stop gogs
434 440
     systemctl disable gogs
435 441
 
436
-    nginx_dissite ${GIT_DOMAIN_NAME}
437
-    remove_certs ${GIT_DOMAIN_NAME}
438
-    if [ -d /var/www/${GIT_DOMAIN_NAME} ]; then
439
-        rm -rf /var/www/${GIT_DOMAIN_NAME}
442
+    nginx_dissite "${GIT_DOMAIN_NAME}"
443
+    remove_certs "${GIT_DOMAIN_NAME}"
444
+    if [ -d "/var/www/${GIT_DOMAIN_NAME}" ]; then
445
+        rm -rf "/var/www/${GIT_DOMAIN_NAME}"
440 446
     fi
441
-    if [ -f /etc/nginx/sites-available/${GIT_DOMAIN_NAME} ]; then
442
-        rm /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
447
+    if [ -f "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}" ]; then
448
+        rm "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
443 449
     fi
444 450
     function_check drop_database
445 451
     drop_database gogs
446 452
     rm /etc/systemd/system/gogs.service
447 453
     systemctl daemon-reload
448
-    rm -rf /home/${GOGS_USERNAME}/*
454
+    rm -rf "/home/${GOGS_USERNAME:?}/"*
449 455
     remove_onion_service gogs ${GIT_ONION_PORT} 9418
450 456
     remove_completion_param "install_gogs"
451
-    sed -i '/gogs /d' $COMPLETION_FILE
457
+    sed -i '/gogs /d' "$COMPLETION_FILE"
452 458
     remove_backup_database_local gogs
453 459
 
454 460
     groupdel -f gogs
455 461
     userdel -r gogs
456 462
 
457 463
     function_check remove_ddns_domain
458
-    remove_ddns_domain $GIT_DOMAIN_NAME
464
+    remove_ddns_domain "$GIT_DOMAIN_NAME"
459 465
 }
460 466
 
461 467
 function install_gogs {
462
-    if [ ! $GIT_DOMAIN_NAME ]; then
468
+    if [ ! "$GIT_DOMAIN_NAME" ]; then
463 469
         return
464 470
     fi
465 471
 
@@ -474,14 +480,14 @@ function install_gogs {
474 480
 
475 481
     gogs_parameters
476 482
 
477
-    if [ ! -d ${INSTALL_DIR} ]; then
478
-        mkdir -p ${INSTALL_DIR}
483
+    if [ ! -d "${INSTALL_DIR}" ]; then
484
+        mkdir -p "${INSTALL_DIR}"
479 485
     fi
480
-    cd ${INSTALL_DIR}
481
-    if [ -d $INSTALL_DIR/gogs ]; then
482
-        rm -rf $INSTALL_DIR/gogs
486
+    cd "${INSTALL_DIR}" || exit 24682467284
487
+    if [ -d "$INSTALL_DIR/gogs" ]; then
488
+        rm -rf "$INSTALL_DIR/gogs"
483 489
     fi
484
-    GOGS_FILE=linux_${CURR_ARCH}.tar.gz
490
+    GOGS_FILE="linux_${CURR_ARCH}.tar.gz"
485 491
     if [ ! -f ${GOGS_FILE} ]; then
486 492
         wget ${GOGS_BIN}
487 493
     fi
@@ -496,13 +502,13 @@ function install_gogs {
496 502
             unzip -o ${GOGS_FILE}
497 503
         fi
498 504
     else
499
-        tar -xzf ${INSTALL_DIR}/${GOGS_FILE}
505
+        tar -xzf "${INSTALL_DIR}/${GOGS_FILE}"
500 506
     fi
501
-    if [ ! -d ${INSTALL_DIR}/gogs ]; then
507
+    if [ ! -d "${INSTALL_DIR}/gogs" ]; then
502 508
         exit 37823
503 509
     fi
504
-    rm -rf /home/${GOGS_USERNAME}/*
505
-    cp -r ${INSTALL_DIR}/gogs/* /home/${GOGS_USERNAME}
510
+    rm -rf "/home/${GOGS_USERNAME:?}/"*
511
+    cp -r "${INSTALL_DIR}/gogs/*" "/home/${GOGS_USERNAME}"
506 512
     if [ -f ${GOGS_FILE} ]; then
507 513
         rm ${GOGS_FILE}
508 514
     fi
@@ -512,9 +518,10 @@ function install_gogs {
512 518
         exit 345562
513 519
     fi
514 520
 
515
-    echo "export GOROOT=/home/go" >> /home/${GOGS_USERNAME}/.bashrc
516
-    echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> /home/${GOGS_USERNAME}/.bashrc
517
-    echo 'export PATH=$PATH:$GOPATH' >> /home/${GOGS_USERNAME}/.bashrc
521
+    { echo "export GOROOT=/home/go";
522
+      # shellcheck disable=SC2153
523
+      echo "export GOPATH=\${GOROOT}/go${GO_VERSION}/bin";
524
+      echo "export PATH=\$PATH:\$GOPATH"; } >> "/home/${GOGS_USERNAME}/.bashrc"
518 525
     chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
519 526
 
520 527
     function_check install_mariadb
@@ -536,122 +543,122 @@ function install_gogs {
536 543
 
537 544
     chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
538 545
 
539
-    echo '[Unit]' > /etc/systemd/system/gogs.service
540
-    echo 'Description=Gogs (Go Git Service)' >> /etc/systemd/system/gogs.service
541
-    echo 'After=syslog.target' >> /etc/systemd/system/gogs.service
542
-    echo 'After=network.target' >> /etc/systemd/system/gogs.service
543
-    echo 'After=mysqld.service' >> /etc/systemd/system/gogs.service
544
-    echo '' >> /etc/systemd/system/gogs.service
545
-    echo '[Service]' >> /etc/systemd/system/gogs.service
546
-    echo '#LimitMEMLOCK=infinity' >> /etc/systemd/system/gogs.service
547
-    echo '#LimitNOFILE=65535' >> /etc/systemd/system/gogs.service
548
-    echo 'Type=simple' >> /etc/systemd/system/gogs.service
549
-    echo 'User=gogs' >> /etc/systemd/system/gogs.service
550
-    echo 'Group=gogs' >> /etc/systemd/system/gogs.service
551
-    echo "WorkingDirectory=/home/${GOGS_USERNAME}" >> /etc/systemd/system/gogs.service
552
-    echo "ExecStart=/home/${GOGS_USERNAME}/gogs web" >> /etc/systemd/system/gogs.service
553
-    echo 'Restart=always' >> /etc/systemd/system/gogs.service
554
-    echo 'RestartSec=10' >> /etc/systemd/system/gogs.service
555
-    echo "Environment=\"USER=${GOGS_USERNAME}\" \"HOME=/home/${GOGS_USERNAME}\" \"GOPATH=/home/go/go${GO_VERSION}\"" >> /etc/systemd/system/gogs.service
556
-    echo '' >> /etc/systemd/system/gogs.service
557
-    echo '[Install]' >> /etc/systemd/system/gogs.service
558
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/gogs.service
546
+    { echo '[Unit]';
547
+      echo 'Description=Gogs (Go Git Service)';
548
+      echo 'After=syslog.target';
549
+      echo 'After=network.target';
550
+      echo 'After=mysqld.service';
551
+      echo '';
552
+      echo '[Service]';
553
+      echo '#LimitMEMLOCK=infinity';
554
+      echo '#LimitNOFILE=65535';
555
+      echo 'Type=simple';
556
+      echo 'User=gogs';
557
+      echo 'Group=gogs';
558
+      echo "WorkingDirectory=/home/${GOGS_USERNAME}";
559
+      echo "ExecStart=/home/${GOGS_USERNAME}/gogs web";
560
+      echo 'Restart=always';
561
+      echo 'RestartSec=10';
562
+      echo "Environment=\"USER=${GOGS_USERNAME}\" \"HOME=/home/${GOGS_USERNAME}\" \"GOPATH=/home/go/go${GO_VERSION}\"";
563
+      echo '';
564
+      echo '[Install]';
565
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/gogs.service
559 566
 
560 567
     systemctl enable gogs
561 568
     systemctl daemon-reload
562 569
     systemctl start gogs
563 570
 
564
-    if [ ! -d /var/www/${GIT_DOMAIN_NAME} ]; then
565
-        mkdir /var/www/${GIT_DOMAIN_NAME}
571
+    if [ ! -d "/var/www/${GIT_DOMAIN_NAME}" ]; then
572
+        mkdir "/var/www/${GIT_DOMAIN_NAME}"
566 573
     fi
567
-    if [ -d /var/www/${GIT_DOMAIN_NAME}/htdocs ]; then
568
-        rm -rf /var/www/${GIT_DOMAIN_NAME}/htdocs
574
+    if [ -d "/var/www/${GIT_DOMAIN_NAME}/htdocs" ]; then
575
+        rm -rf "/var/www/${GIT_DOMAIN_NAME}/htdocs"
569 576
     fi
570 577
 
571
-    if [[ ${ONION_ONLY} == "no" ]]; then
578
+    if [[ "${ONION_ONLY}" == "no" ]]; then
572 579
         function_check nginx_http_redirect
573
-        nginx_http_redirect ${GIT_DOMAIN_NAME}
574
-        echo 'server {' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
575
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
576
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
577
-        echo "    root /var/www/${GIT_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
578
-        echo "    server_name ${GIT_DOMAIN_NAME};" >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
579
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
580
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
581
-        echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
580
+        nginx_http_redirect "${GIT_DOMAIN_NAME}"
581
+        { echo 'server {';
582
+          echo '    listen 443 ssl;';
583
+          echo '    #listen [::]:443 ssl;';
584
+          echo "    root /var/www/${GIT_DOMAIN_NAME}/htdocs;";
585
+          echo "    server_name ${GIT_DOMAIN_NAME};";
586
+          echo '    access_log /dev/null;';
587
+          echo "    error_log /dev/null;";
588
+          echo ''; } >> "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
582 589
         function_check nginx_ssl
583
-        nginx_ssl ${GIT_DOMAIN_NAME}
590
+        nginx_ssl "${GIT_DOMAIN_NAME}"
584 591
         function_check nginx_disable_sniffing
585
-        nginx_disable_sniffing ${GIT_DOMAIN_NAME}
586
-        echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
587
-        echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
588
-        echo '    location / {' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
592
+        nginx_disable_sniffing "${GIT_DOMAIN_NAME}"
593
+        { echo '    add_header Strict-Transport-Security max-age=0;';
594
+          echo '';
595
+          echo '    location / {'; } >> "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
589 596
         function_check nginx_limits
590
-        nginx_limits ${GIT_DOMAIN_NAME} '10G'
591
-        echo '        proxy_pass http://localhost:3000;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
592
-        echo '    }' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
593
-        echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
594
-        echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
595
-        echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
596
-        echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
597
-        echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
598
-        echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
599
-        echo '    location = /robots.txt {' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
600
-        echo '        allow all;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
601
-        echo '        log_not_found off;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
602
-        echo '        access_log /dev/null;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
603
-        echo '    }' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
604
-        echo '}' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
605
-        echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
597
+        nginx_limits "${GIT_DOMAIN_NAME}" '10G'
598
+        { echo '        proxy_pass http://localhost:3000;';
599
+          echo '    }';
600
+          echo '';
601
+          echo '    fastcgi_buffers 64 4K;';
602
+          echo '';
603
+          echo '    error_page 403 /core/templates/403.php;';
604
+          echo '    error_page 404 /core/templates/404.php;';
605
+          echo '';
606
+          echo '    location = /robots.txt {';
607
+          echo '        allow all;';
608
+          echo '        log_not_found off;';
609
+          echo '        access_log /dev/null;';
610
+          echo '    }';
611
+          echo '}';
612
+          echo ''; } >> "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
606 613
     else
607
-        echo -n '' > /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
608
-    fi
609
-    echo 'server {' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
610
-    echo "    listen 127.0.0.1:${GIT_ONION_PORT} default_server;" >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
611
-    echo "    root /var/www/$GIT_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
612
-    echo "    server_name $GIT_DOMAIN_NAME;" >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
613
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
614
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
615
-    echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
614
+        echo -n '' > "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
615
+    fi
616
+    { echo 'server {';
617
+      echo "    listen 127.0.0.1:${GIT_ONION_PORT} default_server;";
618
+      echo "    root /var/www/$GIT_DOMAIN_NAME/htdocs;";
619
+      echo "    server_name $GIT_DOMAIN_NAME;";
620
+      echo '    access_log /dev/null;';
621
+      echo "    error_log /dev/null;";
622
+      echo ''; } >> "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
616 623
     function_check nginx_disable_sniffing
617
-    nginx_disable_sniffing ${GIT_DOMAIN_NAME}
618
-    echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
619
-    echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
620
-    echo '    location / {' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
624
+    nginx_disable_sniffing "${GIT_DOMAIN_NAME}"
625
+    { echo '    add_header Strict-Transport-Security max-age=0;';
626
+      echo '';
627
+      echo '    location / {'; } >> "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
621 628
     function_check nginx_limits
622
-    nginx_limits ${GIT_DOMAIN_NAME} '10G'
623
-    echo '        proxy_pass http://localhost:3000;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
624
-    echo '    }' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
625
-    echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
626
-    echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
627
-    echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
628
-    echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
629
-    echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
630
-    echo '' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
631
-    echo '    location = /robots.txt {' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
632
-    echo '        allow all;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
633
-    echo '        log_not_found off;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
634
-    echo '        access_log /dev/null;' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
635
-    echo '    }' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
636
-    echo '}' >> /etc/nginx/sites-available/${GIT_DOMAIN_NAME}
629
+    nginx_limits "${GIT_DOMAIN_NAME}" '10G'
630
+    { echo '        proxy_pass http://localhost:3000;';
631
+      echo '    }';
632
+      echo '';
633
+      echo '    fastcgi_buffers 64 4K;';
634
+      echo '';
635
+      echo '    error_page 403 /core/templates/403.php;';
636
+      echo '    error_page 404 /core/templates/404.php;';
637
+      echo '';
638
+      echo '    location = /robots.txt {';
639
+      echo '        allow all;';
640
+      echo '        log_not_found off;';
641
+      echo '        access_log /dev/null;';
642
+      echo '    }';
643
+      echo '}'; } >> "/etc/nginx/sites-available/${GIT_DOMAIN_NAME}"
637 644
 
638 645
     function_check configure_php
639 646
     configure_php
640 647
 
641 648
     function_check create_site_certificate
642
-    create_site_certificate ${GIT_DOMAIN_NAME} 'yes'
649
+    create_site_certificate "${GIT_DOMAIN_NAME}" 'yes'
643 650
 
644
-    nginx_ensite ${GIT_DOMAIN_NAME}
651
+    nginx_ensite "${GIT_DOMAIN_NAME}"
645 652
 
646 653
     if [ ! -d /var/lib/tor ]; then
647 654
         echo $'No Tor installation found. Gogs onion site cannot be configured.'
648 655
         exit 877367
649 656
     fi
650 657
     if ! grep -q "hidden_service_gogs" /etc/tor/torrc; then
651
-        echo 'HiddenServiceDir /var/lib/tor/hidden_service_gogs/' >> /etc/tor/torrc
652
-        echo 'HiddenServiceVersion 3' >> /etc/tor/torrc
653
-        echo "HiddenServicePort 80 127.0.0.1:${GIT_ONION_PORT}" >> /etc/tor/torrc
654
-        echo "HiddenServicePort 9418 127.0.0.1:9418" >> /etc/tor/torrc
658
+        { echo 'HiddenServiceDir /var/lib/tor/hidden_service_gogs/';
659
+          echo 'HiddenServiceVersion 3';
660
+          echo "HiddenServicePort 80 127.0.0.1:${GIT_ONION_PORT}";
661
+          echo "HiddenServicePort 9418 127.0.0.1:9418"; } >> /etc/tor/torrc
655 662
         echo $'Added onion site for Gogs'
656 663
     fi
657 664
 
@@ -670,34 +677,34 @@ function install_gogs {
670 677
     set_completion_param "gogs onion domain" "$GIT_ONION_HOSTNAME"
671 678
 
672 679
     function_check add_ddns_domain
673
-    add_ddns_domain ${GIT_DOMAIN_NAME}
680
+    add_ddns_domain "${GIT_DOMAIN_NAME}"
674 681
 
675 682
     # obtain the secret key
676
-    GOGS_SECRET_KEY="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
677
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a gogs -p "*"
683
+    GOGS_SECRET_KEY="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
684
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a gogs -p "*"
678 685
 
679 686
     # create the configuration
680
-    GOGS_CONFIG_PATH=/home/${GOGS_USERNAME}/custom/conf
687
+    GOGS_CONFIG_PATH="/home/${GOGS_USERNAME}/custom/conf"
681 688
     if [ ! -d ${GOGS_CONFIG_PATH} ]; then
682 689
         mkdir -p ${GOGS_CONFIG_PATH}
683 690
     fi
684 691
     GOGS_CONFIG_FILE=${GOGS_CONFIG_PATH}/app.ini
685
-    echo "RUN_USER = $GOGS_USERNAME" > ${GOGS_CONFIG_FILE}
686
-    echo 'RUN_MODE = prod' >> ${GOGS_CONFIG_FILE}
687
-    echo '' >> ${GOGS_CONFIG_FILE}
688
-    echo '[database]' >> ${GOGS_CONFIG_FILE}
689
-    echo 'DB_TYPE = mysql' >> ${GOGS_CONFIG_FILE}
690
-    echo 'HOST = 127.0.0.1:3306' >> ${GOGS_CONFIG_FILE}
691
-    echo 'NAME = gogs' >> ${GOGS_CONFIG_FILE}
692
-    echo 'USER = root' >> ${GOGS_CONFIG_FILE}
693
-    echo "PASSWD = $MARIADB_PASSWORD" >> ${GOGS_CONFIG_FILE}
694
-    echo 'SSL_MODE = disable' >> ${GOGS_CONFIG_FILE}
695
-    echo 'PATH = data/gogs.db' >> ${GOGS_CONFIG_FILE}
696
-    echo '' >> ${GOGS_CONFIG_FILE}
697
-    echo '[repository]' >> ${GOGS_CONFIG_FILE}
698
-    echo "ROOT = /home/$GOGS_USERNAME/gogs-repositories" >> ${GOGS_CONFIG_FILE}
699
-    echo '' >> ${GOGS_CONFIG_FILE}
700
-    echo '[server]' >> ${GOGS_CONFIG_FILE}
692
+    { echo "RUN_USER = $GOGS_USERNAME";
693
+      echo 'RUN_MODE = prod';
694
+      echo '';
695
+      echo '[database]';
696
+      echo 'DB_TYPE = mysql';
697
+      echo 'HOST = 127.0.0.1:3306';
698
+      echo 'NAME = gogs';
699
+      echo 'USER = root';
700
+      echo "PASSWD = $MARIADB_PASSWORD";
701
+      echo 'SSL_MODE = disable';
702
+      echo 'PATH = data/gogs.db';
703
+      echo '';
704
+      echo '[repository]';
705
+      echo "ROOT = /home/$GOGS_USERNAME/gogs-repositories";
706
+      echo '';
707
+      echo '[server]'; } >> ${GOGS_CONFIG_FILE}
701 708
     if [[ ${ONION_ONLY} == 'no' ]]; then
702 709
         echo "DOMAIN = ${GIT_DOMAIN_NAME}" >> ${GOGS_CONFIG_FILE}
703 710
         echo "ROOT_URL = https://$GIT_DOMAIN_NAME/" >> ${GOGS_CONFIG_FILE}
@@ -705,51 +712,51 @@ function install_gogs {
705 712
         echo "DOMAIN = ${GIT_ONION_HOSTNAME}" >> ${GOGS_CONFIG_FILE}
706 713
         echo "ROOT_URL = http://$GIT_DOMAIN_NAME/" >> ${GOGS_CONFIG_FILE}
707 714
     fi
708
-    echo 'HTTP_PORT = 3000' >> ${GOGS_CONFIG_FILE}
709
-    echo "SSH_PORT = $SSH_PORT" >> ${GOGS_CONFIG_FILE}
710
-    echo 'SSH_DOMAIN = %(DOMAIN)s' >> ${GOGS_CONFIG_FILE}
711
-    echo "CERT_FILE = /etc/ssl/certs/${GIT_DOMAIN_NAME}.pem" >> ${GOGS_CONFIG_FILE}
712
-    echo "KEY_FILE = /etc/ssl/private/${GIT_DOMAIN_NAME}.key" >> ${GOGS_CONFIG_FILE}
713
-    echo 'DISABLE_ROUTER_LOG = true' >> ${GOGS_CONFIG_FILE}
714
-    echo '' >> ${GOGS_CONFIG_FILE}
715
-    echo '[session]' >> ${GOGS_CONFIG_FILE}
716
-    echo 'PROVIDER = file' >> ${GOGS_CONFIG_FILE}
717
-    echo '' >> ${GOGS_CONFIG_FILE}
718
-    echo '[log]' >> ${GOGS_CONFIG_FILE}
719
-    echo 'MODE = file' >> ${GOGS_CONFIG_FILE}
720
-    echo 'LEVEL = Info' >> ${GOGS_CONFIG_FILE}
721
-    echo '' >> ${GOGS_CONFIG_FILE}
722
-    echo '[security]' >> ${GOGS_CONFIG_FILE}
723
-    echo 'INSTALL_LOCK = true' >> ${GOGS_CONFIG_FILE}
724
-    echo "SECRET_KEY = $GOGS_SECRET_KEY" >> ${GOGS_CONFIG_FILE}
725
-    echo '' >> ${GOGS_CONFIG_FILE}
726
-    echo '[service]' >> ${GOGS_CONFIG_FILE}
727
-    echo 'DISABLE_REGISTRATION = false' >> ${GOGS_CONFIG_FILE}
728
-    echo 'SHOW_REGISTRATION_BUTTON = true' >> ${GOGS_CONFIG_FILE}
729
-    echo 'REQUIRE_SIGNIN_VIEW = false' >> ${GOGS_CONFIG_FILE}
730
-    echo 'ENABLE_CAPTCHA = false' >> ${GOGS_CONFIG_FILE}
731
-    echo '' >> ${GOGS_CONFIG_FILE}
732
-    echo '[other]' >> ${GOGS_CONFIG_FILE}
733
-    echo 'SHOW_FOOTER_BRANDING = false' >> ${GOGS_CONFIG_FILE}
734
-    echo 'SHOW_FOOTER_VERSION = false' >> ${GOGS_CONFIG_FILE}
715
+    { echo 'HTTP_PORT = 3000';
716
+      echo "SSH_PORT = $SSH_PORT";
717
+      echo 'SSH_DOMAIN = %(DOMAIN)s';
718
+      echo "CERT_FILE = /etc/ssl/certs/${GIT_DOMAIN_NAME}.pem";
719
+      echo "KEY_FILE = /etc/ssl/private/${GIT_DOMAIN_NAME}.key";
720
+      echo 'DISABLE_ROUTER_LOG = true';
721
+      echo '';
722
+      echo '[session]';
723
+      echo 'PROVIDER = file';
724
+      echo '';
725
+      echo '[log]';
726
+      echo 'MODE = file';
727
+      echo 'LEVEL = Info';
728
+      echo '';
729
+      echo '[security]';
730
+      echo 'INSTALL_LOCK = true';
731
+      echo "SECRET_KEY = $GOGS_SECRET_KEY";
732
+      echo '';
733
+      echo '[service]';
734
+      echo 'DISABLE_REGISTRATION = false';
735
+      echo 'SHOW_REGISTRATION_BUTTON = true';
736
+      echo 'REQUIRE_SIGNIN_VIEW = false';
737
+      echo 'ENABLE_CAPTCHA = false';
738
+      echo '';
739
+      echo '[other]';
740
+      echo 'SHOW_FOOTER_BRANDING = false';
741
+      echo 'SHOW_FOOTER_VERSION = false'; } >> ${GOGS_CONFIG_FILE}
735 742
 
736 743
     chmod 750 ${GOGS_CONFIG_FILE}
737
-    chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
744
+    chown -R "${GOGS_USERNAME}":"${GOGS_USERNAME}" "/home/${GOGS_USERNAME}"
738 745
 
739 746
     systemctl restart gogs
740 747
 
741
-    if ! grep -q "gogs domain:" ${COMPLETION_FILE}; then
742
-        echo "gogs domain:${GIT_DOMAIN_NAME}" >> ${COMPLETION_FILE}
748
+    if ! grep -q "gogs domain:" "${COMPLETION_FILE}"; then
749
+        echo "gogs domain:${GIT_DOMAIN_NAME}" >> "${COMPLETION_FILE}"
743 750
     else
744
-        sed -i "s|gogs domain.*|gogs domain:${GIT_DOMAIN_NAME}|g" ${COMPLETION_FILE}
751
+        sed -i "s|gogs domain.*|gogs domain:${GIT_DOMAIN_NAME}|g" "${COMPLETION_FILE}"
745 752
     fi
746 753
 
747 754
     function_check configure_firewall_for_git
748 755
     configure_firewall_for_git
749
-    if ! grep -q "gogs version:" ${COMPLETION_FILE}; then
750
-        echo "gogs version:${GOGS_VERSION}" >> ${COMPLETION_FILE}
756
+    if ! grep -q "gogs version:" "${COMPLETION_FILE}"; then
757
+        echo "gogs version:${GOGS_VERSION}" >> "${COMPLETION_FILE}"
751 758
     else
752
-        sed -i "s|gogs version.*|gogs version:${GOGS_VERSION}|g" ${COMPLETION_FILE}
759
+        sed -i "s|gogs version.*|gogs version:${GOGS_VERSION}|g" "${COMPLETION_FILE}"
753 760
     fi
754 761
     APP_INSTALLED=1
755 762
 }

+ 276
- 269
src/freedombone-app-htmly Просмотреть файл

@@ -69,18 +69,18 @@ function set_avatar_from_url {
69 69
     fi
70 70
 
71 71
     # download the image
72
-    cd $BASE_DIR/customimages
72
+    cd "$BASE_DIR/customimages" || exit 2468246
73 73
     # convert to png
74
-    wget $AVATAR -O avatar
75
-    if [[ $AVATAR == *".gif" ]]; then
74
+    wget "$AVATAR" -O avatar
75
+    if [[ "$AVATAR" == *".gif" ]]; then
76 76
         mv avatar avatar.gif
77 77
         mogrify -format png avatar.gif
78 78
     fi
79
-    if [[ $AVATAR == *".jpg" ]]; then
79
+    if [[ "$AVATAR" == *".jpg" ]]; then
80 80
         mv avatar avatar.jpg
81 81
         mogrify -format png avatar.jpg
82 82
     fi
83
-    if [[ $AVATAR == *".jpeg" ]]; then
83
+    if [[ "$AVATAR" == *".jpeg" ]]; then
84 84
         mv avatar avatar.jpeg
85 85
         mogrify -format png avatar.jpeg
86 86
     fi
@@ -101,10 +101,10 @@ function set_avatar_from_url {
101 101
 function remove_user_htmly {
102 102
     remove_username="$1"
103 103
 
104
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp htmly
104
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp htmly
105 105
 
106
-    if [ -f /var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini ]; then
107
-        rm /var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini
106
+    if [ -f "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini" ]; then
107
+        rm "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini"
108 108
     fi
109 109
 }
110 110
 
@@ -117,39 +117,38 @@ function add_user_htmly {
117 117
     new_username="$1"
118 118
     new_user_password="$2"
119 119
 
120
-    ${PROJECT_NAME}-pass -u $new_username -a htmly -p "$new_user_password"
120
+    "${PROJECT_NAME}-pass" -u "$new_username" -a htmly -p "$new_user_password"
121 121
 
122 122
     if [ ! -d /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users ]; then
123 123
         echo '2'
124 124
         return
125 125
     fi
126
-    NEW_USER_PASSWORD_HASH=$(${PROJECT_NAME}-sec --htmlyhash "$new_user_password")
126
+    NEW_USER_PASSWORD_HASH=$("${PROJECT_NAME}-sec" --htmlyhash "$new_user_password")
127 127
     if [ ${#NEW_USER_PASSWORD_HASH} -lt 8 ]; then
128 128
         echo '3'
129 129
         return
130 130
     fi
131
-    echo ';Password' > /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
132
-    echo "password = $NEW_USER_PASSWORD_HASH" >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
133
-    echo 'encryption = password_hash' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
134
-    echo ';Role' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
135
-    echo 'role = admin' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
131
+    { echo ';Password';
132
+      echo "password = $NEW_USER_PASSWORD_HASH";
133
+      echo 'encryption = password_hash';
134
+      echo ';Role';
135
+      echo 'role = admin'; } > "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini"
136 136
     echo '0'
137 137
 }
138 138
 
139 139
 function configure_interactive_htmly {
140
-    data=$(tempfile 2>/dev/null)
141
-    trap "rm -f $data" 0 1 2 5 15
140
+    data=$(mktemp 2>/dev/null)
142 141
     dialog --title $"Change htmly avatar" \
143 142
            --backtitle $"Freedombone Control Panel" \
144
-           --inputbox $"Enter a URL for an image. It should be approximately a square image." 8 75 2>$data
143
+           --inputbox $"Enter a URL for an image. It should be approximately a square image." 8 75 2>"$data"
145 144
     sel=$?
146 145
     case $sel in
147 146
         0)
148
-            IMAGE_URL=$(<$data)
147
+            IMAGE_URL=$(<"$data")
149 148
             if [ ${#IMAGE_URL} -gt 5 ]; then
150 149
                 clear
151 150
                 AVATAR_SET=
152
-                set_avatar_from_url $IMAGE_URL
151
+                set_avatar_from_url "$IMAGE_URL"
153 152
                 if [ $AVATAR_SET ]; then
154 153
                     dialog --title $"Change htmly avatar" \
155 154
                            --msgbox $"Your htmly avatar has been changed" 6 40
@@ -157,10 +156,11 @@ function configure_interactive_htmly {
157 156
             fi
158 157
             ;;
159 158
     esac
159
+    rm -f "$data"
160 160
 }
161 161
 
162 162
 function install_interactive_htmly {
163
-    if [ ! $ONION_ONLY ]; then
163
+    if [ ! "$ONION_ONLY" ]; then
164 164
         ONION_ONLY='no'
165 165
     fi
166 166
 
@@ -186,13 +186,13 @@ function change_password_htmly {
186 186
         echo $'Htmly password is too short'
187 187
         return
188 188
     fi
189
-    ${PROJECT_NAME}-pass -u "$HTMLY_USERNAME" -a htmly -p "$HTMLY_PASSWORD"
190
-    HTMLY_PASSWORD_HASH=$(${PROJECT_NAME}-sec --htmlyhash "$HTMLY_PASSWORD")
189
+    "${PROJECT_NAME}-pass" -u "$HTMLY_USERNAME" -a htmly -p "$HTMLY_PASSWORD"
190
+    HTMLY_PASSWORD_HASH=$("${PROJECT_NAME}-sec" --htmlyhash "$HTMLY_PASSWORD")
191 191
     if [ ${#HTMLY_PASSWORD_HASH} -lt 8 ]; then
192 192
         echo $'Htmly admin password could not be hashed'
193 193
         exit 625728
194 194
     fi
195
-    sed -i "s|password =.*|password = $HTMLY_PASSWORD_HASH|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$HTMLY_USERNAME.ini
195
+    sed -i "s|password =.*|password = $HTMLY_PASSWORD_HASH|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$HTMLY_USERNAME.ini"
196 196
 }
197 197
 
198 198
 function reconfigure_htmly {
@@ -208,23 +208,23 @@ function upgrade_htmly {
208 208
     read_config_param "HTMLY_DOMAIN_NAME"
209 209
 
210 210
     function_check set_repo_commit
211
-    set_repo_commit /var/www/$HTMLY_DOMAIN_NAME/htdocs "htmly commit" "$HTMLY_COMMIT" $HTMLY_REPO
211
+    set_repo_commit "/var/www/$HTMLY_DOMAIN_NAME/htdocs" "htmly commit" "$HTMLY_COMMIT" $HTMLY_REPO
212 212
 }
213 213
 
214 214
 function backup_local_htmly {
215 215
     HTMLY_DOMAIN_NAME='htmly.local'
216
-    if grep -q "htmly domain" $COMPLETION_FILE; then
216
+    if grep -q "htmly domain" "$COMPLETION_FILE"; then
217 217
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
218 218
     fi
219 219
 
220
-    source_directory=/var/www/${HTMLY_DOMAIN_NAME}/htdocs
221
-    if [ -d $source_directory ]; then
220
+    source_directory="/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
221
+    if [ -d "$source_directory" ]; then
222 222
         dest_directory=htmly
223 223
         function_check suspend_site
224
-        suspend_site ${HTMLY_DOMAIN_NAME}
224
+        suspend_site "${HTMLY_DOMAIN_NAME}"
225 225
 
226 226
         function_check backup_directory_to_usb
227
-        backup_directory_to_usb $source_directory $dest_directory
227
+        backup_directory_to_usb "$source_directory" "$dest_directory"
228 228
 
229 229
         function_check restart_site
230 230
         restart_site
@@ -233,73 +233,74 @@ function backup_local_htmly {
233 233
 
234 234
 function restore_local_htmly {
235 235
     HTMLY_DOMAIN_NAME='htmly.local'
236
-    if grep -q "htmly domain" $COMPLETION_FILE; then
236
+    if grep -q "htmly domain" "$COMPLETION_FILE"; then
237 237
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
238 238
     fi
239
-    if [ $HTMLY_DOMAIN_NAME ]; then
239
+    if [ "$HTMLY_DOMAIN_NAME" ]; then
240 240
         temp_restore_dir=/root/temphtmly
241
-        if [ -d $USB_MOUNT/backup/htmly ]; then
241
+        if [ -d "$USB_MOUNT/backup/htmly" ]; then
242 242
             restore_directory_from_usb $temp_restore_dir htmly
243 243
         else
244 244
             restore_directory_from_usb $temp_restore_dir blog
245 245
         fi
246
-        if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
247
-            if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
248
-                rm -rf /var/www/${HTMLY_DOMAIN_NAME}/previous
246
+        if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
247
+            if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
248
+                rm -rf "/var/www/${HTMLY_DOMAIN_NAME}/previous"
249 249
             fi
250
-            mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs /var/www/${HTMLY_DOMAIN_NAME}/previous
250
+            mv "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" "/var/www/${HTMLY_DOMAIN_NAME}/previous"
251 251
         fi
252
-        if [ -d ${temp_restore_dir}/var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
252
+        if [ -d "${temp_restore_dir}/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
253 253
             temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
254
-            cp -r ${temp_source_dir} /var/www/${HTMLY_DOMAIN_NAME}/
254
+            cp -r "${temp_source_dir}" "/var/www/${HTMLY_DOMAIN_NAME}/"
255 255
         else
256
-            if [ ! -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
257
-                mkdir /var/www/${HTMLY_DOMAIN_NAME}/htdocs
256
+            if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
257
+                mkdir "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
258 258
             fi
259
-            cp -r ${temp_restore_dir}/* /var/www/${HTMLY_DOMAIN_NAME}/htdocs/
259
+            cp -r "${temp_restore_dir}/*" "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/"
260 260
         fi
261
+        # shellcheck disable=SC2181
261 262
         if [ ! "$?" = "0" ]; then
262
-            if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
263
-                mv /var/www/${HTMLY_DOMAIN_NAME}/previous /var/www/${HTMLY_DOMAIN_NAME}/htdocs
263
+            if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
264
+                mv "/var/www/${HTMLY_DOMAIN_NAME}/previous" "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
264 265
             fi
265 266
             set_user_permissions
266 267
             backup_unmount_drive
267 268
             exit 54675
268 269
         fi
269 270
         rm -rf ${temp_restore_dir}
270
-        if [ ! -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content ]; then
271
+        if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content" ]; then
271 272
             echo $"No content directory found after restoring htmly"
272 273
             set_user_permissions
273 274
             backup_unmount_drive
274 275
             exit 34578
275 276
         fi
276
-        chown -R www-data:www-data /var/www/${HTMLY_DOMAIN_NAME}/htdocs
277
+        chown -R www-data:www-data "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
277 278
         # Ensure that the bundled SSL cert is being used
278
-        if [ -f /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt ]; then
279
-            sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}
279
+        if [ -f "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt" ]; then
280
+            sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" "/etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}"
280 281
         fi
281 282
         for d in /home/*/ ; do
282 283
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
283 284
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
284
-                if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post ]; then
285
-                    mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post
285
+                if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post" ]; then
286
+                    mv "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md" "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post"
286 287
                 fi
287 288
             fi
288 289
         done
289
-        if [ -d /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME} ]; then
290
-            ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${HTMLY_DOMAIN_NAME}.key
291
-            ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem
290
+        if [ -d "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}" ]; then
291
+            ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem" "/etc/ssl/private/${HTMLY_DOMAIN_NAME}.key"
292
+            ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem" "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem"
292 293
         fi
293 294
     fi
294 295
 }
295 296
 
296 297
 function backup_remote_htmly {
297
-    if grep -q "htmly domain" $COMPLETION_FILE; then
298
+    if grep -q "htmly domain" "$COMPLETION_FILE"; then
298 299
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
299 300
         temp_backup_dir=/var/www/${HTMLY_DOMAIN_NAME}/htdocs
300
-        if [ -d $temp_backup_dir ]; then
301
+        if [ -d "$temp_backup_dir" ]; then
301 302
             echo $"Backing up htmly"
302
-            backup_directory_to_friend $temp_backup_dir htmly
303
+            backup_directory_to_friend "$temp_backup_dir" htmly
303 304
             echo $"Backup of htmly complete"
304 305
         else
305 306
             echo $"Htmly domain specified but not found in $temp_backup_dir"
@@ -309,56 +310,57 @@ function backup_remote_htmly {
309 310
 }
310 311
 
311 312
 function restore_remote_htmly {
312
-    if [ -d $SERVER_DIRECTORY/backup/htmly ]; then
313
+    if [ -d "$SERVER_DIRECTORY/backup/htmly" ]; then
313 314
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
314 315
         echo $"Restoring htmly installation $HTMLY_DOMAIN_NAME"
315 316
         temp_restore_dir=/root/temphtmly
316 317
         mkdir $temp_restore_dir
317 318
         function_check restore_directory_from_friend
318 319
         restore_directory_from_friend $temp_restore_dir htmly
319
-        if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
320
-            if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
321
-                rm -rf /var/www/${HTMLY_DOMAIN_NAME}/previous
320
+        if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
321
+            if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
322
+                rm -rf "/var/www/${HTMLY_DOMAIN_NAME}/previous"
322 323
             fi
323
-            mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs /var/www/${HTMLY_DOMAIN_NAME}/previous
324
+            mv "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" "/var/www/${HTMLY_DOMAIN_NAME}/previous"
324 325
         fi
325 326
 
326
-        if [ -d ${temp_restore_dir}/var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
327
+        if [ -d "${temp_restore_dir}/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
327 328
             temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
328
-            cp -r ${temp_source_dir} /var/www/${HTMLY_DOMAIN_NAME}/
329
+            cp -r "${temp_source_dir}" "/var/www/${HTMLY_DOMAIN_NAME}/"
329 330
         else
330
-            if [ ! -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
331
-                mkdir /var/www/${HTMLY_DOMAIN_NAME}/htdocs
331
+            if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
332
+                mkdir "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
332 333
             fi
333
-            cp -r ${temp_restore_dir}/* /var/www/${HTMLY_DOMAIN_NAME}/htdocs/
334
+            cp -r "${temp_restore_dir}/*" "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/"
334 335
         fi
335 336
 
337
+        # shellcheck disable=SC2181
336 338
         if [ ! "$?" = "0" ]; then
337
-            if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
338
-                mv /var/www/${HTMLY_DOMAIN_NAME}/previous /var/www/${HTMLY_DOMAIN_NAME}/htdocs
339
+            if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
340
+                mv "/var/www/${HTMLY_DOMAIN_NAME}/previous" "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
339 341
             fi
340 342
             exit 593
341 343
         fi
342 344
         rm -rf ${temp_restore_dir}
343
-        if [ ! -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content ]; then
345
+        if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content" ]; then
344 346
             echo $"No content directory found after restoring htmly"
345 347
             exit 287
346 348
         fi
347 349
         # Ensure that the bundled SSL cert is being used
348
-        if [ -f /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt ]; then
349
-            sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}
350
+        if [ -f "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt" ]; then
351
+            sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" "/etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}"
350 352
         fi
351 353
         for d in /home/*/ ; do
352 354
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
353 355
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
354
-                if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post ]; then
355
-                    mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post
356
+                if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post" ]; then
357
+                    mv "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md" "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post"
356 358
                 fi
357 359
             fi
358 360
         done
359
-        if [ -d /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME} ]; then
360
-            ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${HTMLY_DOMAIN_NAME}.key
361
-            ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem
361
+        if [ -d "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}" ]; then
362
+            ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem" "/etc/ssl/private/${HTMLY_DOMAIN_NAME}.key"
363
+            ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem" "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem"
362 364
         fi
363 365
         echo $"Restore of htmly complete"
364 366
     fi
@@ -370,258 +372,264 @@ function remove_htmly {
370 372
     fi
371 373
 
372 374
     read_config_param "HTMLY_DOMAIN_NAME"
373
-    nginx_dissite $HTMLY_DOMAIN_NAME
374
-    remove_certs ${HTMLY_DOMAIN_NAME}
375
-    if [ -f /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME ]; then
376
-        rm -f /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
375
+    nginx_dissite "$HTMLY_DOMAIN_NAME"
376
+    remove_certs "${HTMLY_DOMAIN_NAME}"
377
+    if [ -f "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME" ]; then
378
+        rm -f "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
377 379
     fi
378
-    if [ -d /var/www/$HTMLY_DOMAIN_NAME ]; then
379
-        rm -rf /var/www/$HTMLY_DOMAIN_NAME
380
+    if [ -d "/var/www/$HTMLY_DOMAIN_NAME" ]; then
381
+        rm -rf "/var/www/$HTMLY_DOMAIN_NAME"
380 382
     fi
381 383
     remove_config_param HTMLY_DOMAIN_NAME
382 384
     remove_config_param HTMLY_CODE
383 385
     function_check remove_onion_service
384 386
     remove_onion_service htmly ${HTMLY_ONION_PORT}
385 387
     remove_completion_param "install_htmly"
386
-    sed -i '/Htmly/d' $COMPLETION_FILE
387
-    sed -i '/htmly/d' $COMPLETION_FILE
388
+    sed -i '/Htmly/d' "$COMPLETION_FILE"
389
+    sed -i '/htmly/d' "$COMPLETION_FILE"
388 390
 
389 391
     function_check remove_ddns_domain
390
-    remove_ddns_domain $HTMLY_DOMAIN_NAME
392
+    remove_ddns_domain "$HTMLY_DOMAIN_NAME"
391 393
 }
392 394
 
393 395
 function install_htmly_social_networks {
394 396
     # set social networks
395
-    if grep -q "social.hubzilla" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini; then
396
-        sed -i "s|;social.hubzilla|social.hubzilla|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
397
-        sed -i "s|social.hubzilla.*|social.hubzilla = \"$HUBZILLA_DOMAIN_NAME\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
397
+    if grep -q "social.hubzilla" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"; then
398
+        sed -i "s|;social.hubzilla|social.hubzilla|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
399
+        sed -i "s|social.hubzilla.*|social.hubzilla = \"$HUBZILLA_DOMAIN_NAME\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
398 400
     fi
399
-    if grep -q "social.gnusocial" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini; then
400
-        sed -i "s|;social.gnusocial|social.gnusocial|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
401
-        sed -i "s|social.gnusocial.*|social.gnusocial = \"$MICROHTMLY_DOMAIN_NAME\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
401
+    if grep -q "social.gnusocial" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"; then
402
+        sed -i "s|;social.gnusocial|social.gnusocial|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
403
+        sed -i "s|social.gnusocial.*|social.gnusocial = \"$MICROHTMLY_DOMAIN_NAME\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
402 404
     fi
403 405
 
404 406
     # clear proprietary social network strings
405
-    sed -i 's|social.facebook.*|social.facebook = ""|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
406
-    sed -i 's|social.twitter.*|social.twitter = ""|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
407
-    sed -i 's|social.google.*|social.google = ""|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
407
+    sed -i 's|social.facebook.*|social.facebook = ""|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
408
+    sed -i 's|social.twitter.*|social.twitter = ""|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
409
+    sed -i 's|social.google.*|social.google = ""|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
408 410
 }
409 411
 
410 412
 function install_htmly_user {
411 413
     # create a user password
412
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
413
-        HTMLY_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
414
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
415
+        HTMLY_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
414 416
     else
415
-        HTMLY_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
417
+        HTMLY_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
416 418
     fi
417 419
 
418 420
     # create a user
419
-    HTMLY_ADMIN_PASSWORD_HASH=$(${PROJECT_NAME}-sec --htmlyhash "$HTMLY_ADMIN_PASSWORD")
421
+    HTMLY_ADMIN_PASSWORD_HASH=$("${PROJECT_NAME}-sec" --htmlyhash "$HTMLY_ADMIN_PASSWORD")
420 422
     if [ ${#HTMLY_ADMIN_PASSWORD_HASH} -lt 8 ]; then
421 423
         echo $'Htmly admin password could not be hashed'
422 424
         exit 625728
423 425
     fi
424
-    echo ';Password' > /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
425
-    echo "password = $HTMLY_ADMIN_PASSWORD_HASH" >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
426
-    echo 'encryption = password_hash' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
427
-    echo ';Role' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
428
-    echo 'role = admin' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
426
+    { echo ';Password';
427
+      echo "password = $HTMLY_ADMIN_PASSWORD_HASH";
428
+      echo 'encryption = password_hash';
429
+      echo ';Role';
430
+      echo 'role = admin'; } > "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini"
429 431
 }
430 432
 
431 433
 function install_htmly_settings {
432
-    cp /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini.example /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
433
-    sed -i "s|site.url.*|site.url = '/'|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
434
-    sed -i "s|blog.title.*|blog.title = \"$HTMLY_TITLE\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
435
-    sed -i "s|blog.tagline.*|blog.tagline = \"$HTMLY_SUBTITLE\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
436
-    sed -i 's|timezone.*|timezone = "Europe/London"|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
437
-    sed -i "s|Your name|$MY_NAME|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
434
+    cp "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini.example" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
435
+    sed -i "s|site.url.*|site.url = '/'|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
436
+    sed -i "s|blog.title.*|blog.title = \"$HTMLY_TITLE\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
437
+    sed -i "s|blog.tagline.*|blog.tagline = \"$HTMLY_SUBTITLE\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
438
+    sed -i 's|timezone.*|timezone = "Europe/London"|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
439
+    sed -i "s|Your name|$MY_NAME|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
438 440
 }
439 441
 
440 442
 function install_htmly_website {
441 443
     function_check nginx_http_redirect
442
-    nginx_http_redirect $HTMLY_DOMAIN_NAME
443
-    echo 'server {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
444
-    echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
445
-    echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
446
-    echo "    root /var/www/$HTMLY_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
447
-    echo "    server_name $HTMLY_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
448
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
449
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
450
-    echo '    index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
451
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
452
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
444
+    nginx_http_redirect "$HTMLY_DOMAIN_NAME"
445
+    { echo 'server {';
446
+      echo '    listen 443 ssl;';
447
+      echo '    #listen [::]:443 ssl;';
448
+      echo "    root /var/www/$HTMLY_DOMAIN_NAME/htdocs;";
449
+      echo "    server_name $HTMLY_DOMAIN_NAME;";
450
+      echo '    access_log /dev/null;';
451
+      echo "    error_log /dev/null;";
452
+      echo '    index index.php;';
453
+      echo '    charset utf-8;';
454
+      echo '    proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
453 455
     function_check nginx_ssl
454
-    nginx_ssl $HTMLY_DOMAIN_NAME
456
+    nginx_ssl "$HTMLY_DOMAIN_NAME"
455 457
     function_check nginx_disable_sniffing
456
-    nginx_disable_sniffing $HTMLY_DOMAIN_NAME
457
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
458
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
459
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
460
-    echo '    location / {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
458
+    nginx_disable_sniffing "$HTMLY_DOMAIN_NAME"
459
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
460
+      echo '';
461
+      echo '    # rewrite to front controller as default rule';
462
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
461 463
     function_check nginx_limits
462
-    nginx_limits $HTMLY_DOMAIN_NAME
463
-    echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
464
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
465
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
466
-    echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
467
-    echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
468
-    echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
469
-    echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
470
-    echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
471
-    echo '        expires 30d;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
472
-    echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
473
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
474
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
475
-    echo '    # block these file types' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
476
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
477
-    echo '        deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
478
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
479
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
480
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
481
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
482
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
483
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
484
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
485
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
486
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
487
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
488
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
489
-    echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
490
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
491
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
492
-    echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
493
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
494
-    echo '        # With php-fpm:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
495
-    echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
496
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
497
-    echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
498
-    echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
499
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
500
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
501
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
502
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
503
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
504
-    echo '        deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
505
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
506
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
507
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
508
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
509
-    echo '        deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
510
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
511
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
512
-    echo '      deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
513
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
514
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
515
-    echo '      deny  all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
516
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
517
-    echo '}' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
518
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
464
+    nginx_limits "$HTMLY_DOMAIN_NAME"
465
+    { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
466
+      echo '    }';
467
+      echo '';
468
+      echo '    # statically serve these file types when possible';
469
+      echo '    # otherwise fall back to front controller';
470
+      echo '    # allow browser to cache them';
471
+      echo '    # added .htm for advanced source code editor library';
472
+      echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
473
+      echo '        expires 30d;';
474
+      echo "        try_files \$uri /index.php?q=\$uri&\$args;";
475
+      echo '    }';
476
+      echo '';
477
+      echo '    # block these file types';
478
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
479
+      echo '        deny all;';
480
+      echo '    }';
481
+      echo '';
482
+      echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
483
+      echo '    # or a unix socket';
484
+      echo '    location ~* \.php$ {';
485
+      echo '        # Zero-day exploit defense.';
486
+      echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
487
+      echo "        # Won't work properly (404 error) if the file is not stored on this";
488
+      echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
489
+      echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
490
+      echo "        # another machine. And then cross your fingers that you won't get hacked.";
491
+      echo "        try_files \$uri \$uri/ /index.php;";
492
+      echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
493
+      echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
494
+      echo '        # With php-cgi alone:';
495
+      echo '        # fastcgi_pass 127.0.0.1:9000;';
496
+      echo '        # With php-fpm:';
497
+      echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
498
+      echo '        include fastcgi_params;';
499
+      echo '        fastcgi_read_timeout 30;';
500
+      echo '        fastcgi_index index.php;';
501
+      echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
502
+      echo '    }';
503
+      echo '';
504
+      echo '    # deny access to all dot files';
505
+      echo '    location ~ /\. {';
506
+      echo '        deny all;';
507
+      echo '    }';
508
+      echo '';
509
+      echo '    #deny access to store';
510
+      echo '    location ~ /store {';
511
+      echo '        deny all;';
512
+      echo '    }';
513
+      echo '    location ~ /(data|conf|bin|inc)/ {';
514
+      echo '      deny all;';
515
+      echo '    }';
516
+      echo '    location ~ /\.ht {';
517
+      echo '      deny  all;';
518
+      echo '    }';
519
+      echo '}';
520
+      echo ''; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
519 521
 }
520 522
 
521 523
 function install_htmly_website_onion {
522
-    echo 'server {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
523
-    echo "    listen 127.0.0.1:${HTMLY_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
524
-    echo "    root /var/www/$HTMLY_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
525
-    echo "    server_name $HTMLY_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
526
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
527
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
528
-    echo '    index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
529
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
530
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
524
+    { echo 'server {';
525
+      echo "    listen 127.0.0.1:${HTMLY_ONION_PORT} default_server;";
526
+      echo "    root /var/www/$HTMLY_DOMAIN_NAME/htdocs;"; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
527
+
528
+    if [[ "$ONION_ONLY" != 'yes' ]]; then
529
+        echo "    server_name $HTMLY_DOMAIN_NAME;" >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
530
+    else
531
+        echo "    server_name $HTMLY_ONION_HOSTNAME;" >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
532
+    fi
533
+
534
+    { echo '    access_log /dev/null;';
535
+      echo "    error_log /dev/null;";
536
+      echo '    index index.php;';
537
+      echo '    charset utf-8;';
538
+      echo '    proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
531 539
     function_check nginx_disable_sniffing
532
-    nginx_disable_sniffing $HTMLY_DOMAIN_NAME
533
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
534
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
535
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
536
-    echo '    location / {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
540
+    nginx_disable_sniffing "$HTMLY_DOMAIN_NAME"
541
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
542
+      echo '';
543
+      echo '    # rewrite to front controller as default rule';
544
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
537 545
     function_check nginx_limits
538
-    nginx_limits $HTMLY_DOMAIN_NAME
539
-    echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
540
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
541
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
542
-    echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
543
-    echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
544
-    echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
545
-    echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
546
-    echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
547
-    echo '        expires 30d;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
548
-    echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
549
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
550
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
551
-    echo '    # block these file types' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
552
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
553
-    echo '        deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
554
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
555
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
556
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
557
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
558
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
546
+    nginx_limits "$HTMLY_DOMAIN_NAME"
547
+    { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
548
+      echo '    }';
549
+      echo '';
550
+      echo '    # statically serve these file types when possible';
551
+      echo '    # otherwise fall back to front controller';
552
+      echo '    # allow browser to cache them';
553
+      echo '    # added .htm for advanced source code editor library';
554
+      echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
555
+      echo '        expires 30d;';
556
+      echo "        try_files \$uri /index.php?q=\$uri&\$args;";
557
+      echo '    }';
558
+      echo '';
559
+      echo '    # block these file types';
560
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
561
+      echo '        deny all;';
562
+      echo '    }';
563
+      echo '';
564
+      echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
565
+      echo '    # or a unix socket';
566
+      echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
559 567
     function_check nginx_limits
560
-    nginx_limits $HTMLY_DOMAIN_NAME
561
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
562
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
563
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
564
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
565
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
566
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
567
-    echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
568
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
569
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
570
-    echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
571
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
572
-    echo '        # With php-fpm:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
573
-    echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
574
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
575
-    echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
576
-    echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
577
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
578
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
579
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
580
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
581
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
582
-    echo '        deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
583
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
584
-    echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
585
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
586
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
587
-    echo '        deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
588
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
589
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
590
-    echo '      deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
591
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
592
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
593
-    echo '      deny  all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
594
-    echo '    }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
595
-    echo '}' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
568
+    nginx_limits "$HTMLY_DOMAIN_NAME"
569
+    { echo '        # Zero-day exploit defense.';
570
+      echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
571
+      echo "        # Won't work properly (404 error) if the file is not stored on this";
572
+      echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
573
+      echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
574
+      echo "        # another machine. And then cross your fingers that you won't get hacked.";
575
+      echo "        try_files \$uri \$uri/ /index.php;";
576
+      echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
577
+      echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
578
+      echo '        # With php-cgi alone:';
579
+      echo '        # fastcgi_pass 127.0.0.1:9000;';
580
+      echo '        # With php-fpm:';
581
+      echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
582
+      echo '        include fastcgi_params;';
583
+      echo '        fastcgi_read_timeout 30;';
584
+      echo '        fastcgi_index index.php;';
585
+      echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
586
+      echo '    }';
587
+      echo '';
588
+      echo '    # deny access to all dot files';
589
+      echo '    location ~ /\. {';
590
+      echo '        deny all;';
591
+      echo '    }';
592
+      echo '';
593
+      echo '    #deny access to store';
594
+      echo '    location ~ /store {';
595
+      echo '        deny all;';
596
+      echo '    }';
597
+      echo '    location ~ /(data|conf|bin|inc)/ {';
598
+      echo '      deny all;';
599
+      echo '    }';
600
+      echo '    location ~ /\.ht {';
601
+      echo '      deny  all;';
602
+      echo '    }';
603
+      echo '}'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
596 604
 }
597 605
 
598 606
 function install_htmly_from_repo {
599
-    if [ ! -d /var/www/$HTMLY_DOMAIN_NAME ]; then
600
-        mkdir /var/www/$HTMLY_DOMAIN_NAME
607
+    if [ ! -d "/var/www/$HTMLY_DOMAIN_NAME" ]; then
608
+        mkdir "/var/www/$HTMLY_DOMAIN_NAME"
601 609
     fi
602 610
 
603
-    cd /var/www/$HTMLY_DOMAIN_NAME
611
+    cd "/var/www/$HTMLY_DOMAIN_NAME" || exit 34684682
604 612
 
605 613
     if [ -d /repos/htmly ]; then
606 614
         mkdir htdocs
607 615
         cp -r -p /repos/htmly/. htdocs
608
-        cd htdocs
616
+        cd htdocs || exit 3468735
609 617
         git pull
610 618
     else
611 619
         git_clone $HTMLY_REPO htdocs
612 620
     fi
613 621
 
614
-    cd htdocs
622
+    cd htdocs || exit 3479835
615 623
     git checkout $HTMLY_COMMIT -b $HTMLY_COMMIT
616 624
     set_completion_param "htmly commit" "$HTMLY_COMMIT"
617 625
 }
618 626
 
619 627
 function install_htmly {
620
-    if [ ! $ONION_ONLY ]; then
628
+    if [ ! "$ONION_ONLY" ]; then
621 629
         ONION_ONLY='no'
622 630
     fi
623 631
 
624
-    if [ ! $HTMLY_DOMAIN_NAME ]; then
632
+    if [ ! "$HTMLY_DOMAIN_NAME" ]; then
625 633
         echo $'The htmly domain name was not specified'
626 634
         exit 5062
627 635
     fi
@@ -636,13 +644,14 @@ function install_htmly {
636 644
         function_check install_htmly_website
637 645
         install_htmly_website
638 646
     else
639
-        echo -n '' > /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
647
+        echo -n '' > "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
640 648
     fi
649
+    HTMLY_ONION_HOSTNAME=$(add_onion_service htmly 80 ${HTMLY_ONION_PORT})
641 650
     function_check install_htmly_website_onion
642 651
     install_htmly_website_onion
643 652
 
644 653
     function_check create_site_certificate
645
-    create_site_certificate $HTMLY_DOMAIN_NAME 'yes'
654
+    create_site_certificate "$HTMLY_DOMAIN_NAME" 'yes'
646 655
 
647 656
     function_check configure_php
648 657
     configure_php
@@ -656,20 +665,18 @@ function install_htmly {
656 665
     function_check install_htmly_user
657 666
     install_htmly_user
658 667
 
659
-    chown -R www-data:www-data /var/www/$HTMLY_DOMAIN_NAME/htdocs
660
-
661
-    HTMLY_ONION_HOSTNAME=$(add_onion_service htmly 80 ${HTMLY_ONION_PORT})
668
+    chown -R www-data:www-data "/var/www/$HTMLY_DOMAIN_NAME/htdocs"
662 669
 
663 670
     function_check nginx_ensite
664
-    nginx_ensite $HTMLY_DOMAIN_NAME
671
+    nginx_ensite "$HTMLY_DOMAIN_NAME"
665 672
 
666 673
     systemctl restart php7.0-fpm
667 674
     systemctl restart nginx
668 675
 
669
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a htmly -p "$HTMLY_ADMIN_PASSWORD"
676
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a htmly -p "$HTMLY_ADMIN_PASSWORD"
670 677
 
671 678
     function_check add_ddns_domain
672
-    add_ddns_domain $HTMLY_DOMAIN_NAME
679
+    add_ddns_domain "$HTMLY_DOMAIN_NAME"
673 680
 
674 681
     set_completion_param "htmly domain" "$HTMLY_DOMAIN_NAME"
675 682
     APP_INSTALLED=1

+ 256
- 254
src/freedombone-app-hubzilla Просмотреть файл

@@ -60,7 +60,7 @@ function logging_off_hubzilla {
60 60
 
61 61
 function remove_user_hubzilla {
62 62
     remove_username="$1"
63
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp hubzilla
63
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp hubzilla
64 64
 }
65 65
 
66 66
 function add_user_hubzilla {
@@ -71,27 +71,26 @@ function add_user_hubzilla {
71 71
 
72 72
     new_username="$1"
73 73
     new_user_password="$2"
74
-    ${PROJECT_NAME}-pass -u $new_username -a hubzilla -p "$new_user_password"
74
+    "${PROJECT_NAME}-pass" -u "$new_username" -a hubzilla -p "$new_user_password"
75 75
     echo '0'
76 76
 }
77 77
 
78 78
 function hubzilla_renew_cert {
79 79
     dialog --title $"Renew SSL certificate" \
80 80
            --backtitle $"Freedombone Control Panel" \
81
-           --yesno $"\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
81
+           --yesno $"\\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
82 82
     sel=$?
83 83
     case $sel in
84 84
         1) return;;
85 85
         255) return;;
86 86
     esac
87 87
     HUBZILLA_DOMAIN_NAME=$(get_completion_param "hubzilla domain")
88
-    if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
88
+    if [ ! -d "/var/www/$HUBZILLA_DOMAIN_NAME/htdocs" ]; then
89 89
         dialog --title $"Renew SSL certificate" \
90 90
                --msgbox $"Hubzilla install directory not found" 6 40
91 91
         return
92 92
     fi
93
-    ${PROJECT_NAME}-renew-cert -h $HUBZILLA_DOMAIN_NAME -p 'letsencrypt'
94
-    if [ ! "$?" = "0" ]; then
93
+    if ! "${PROJECT_NAME}-renew-cert" -h "$HUBZILLA_DOMAIN_NAME" -p 'letsencrypt'; then
95 94
         any_key
96 95
     else
97 96
         dialog --title $"Renew SSL certificate" \
@@ -100,68 +99,71 @@ function hubzilla_renew_cert {
100 99
 }
101 100
 
102 101
 function hubzilla_channel_directory_server {
103
-    if ! grep -q "hubzilla domain" $COMPLETION_FILE; then
102
+    if ! grep -q "hubzilla domain" "$COMPLETION_FILE"; then
104 103
         dialog --title $"Hubzilla channel directory server" \
105 104
                --msgbox $"Hubzilla is not installed on this system" 6 40
106 105
         return
107 106
     fi
108 107
     HUBZILLA_DOMAIN_NAME=$(get_completion_param "hubzilla domain")
109
-    if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME/htdocs ]; then
108
+    if [ ! -d "/var/www/$HUBZILLA_DOMAIN_NAME/htdocs" ]; then
110 109
         dialog --title $"Hubzilla channel directory server" \
111 110
                --msgbox $"Hubzilla install directory not found" 6 40
112 111
         return
113 112
     fi
114 113
 
115
-    data=$(tempfile 2>/dev/null)
116
-    trap "rm -f $data" 0 1 2 5 15
114
+    data=$(mktemp 2>/dev/null)
117 115
     dialog --title $"Hubzilla channel directory server" \
118 116
            --backtitle $"Freedombone Control Panel" \
119
-           --inputbox $"When you click on 'channel directory' this is where Hubzilla will obtain its list from" 8 60 2>$data
117
+           --inputbox $"When you click on 'channel directory' this is where Hubzilla will obtain its list from" 8 60 2>"$data"
120 118
     sel=$?
121 119
     case $sel in
122 120
         0)
123
-            hubzilla_domain_server=$(<$data)
121
+            hubzilla_domain_server=$(<"$data")
124 122
             if [[ $hubzilla_domain_server != *"."* ]]; then
123
+                rm -f "$data"
125 124
                 return
126 125
             fi
127 126
             if [[ $hubzilla_domain_server != "https"* ]]; then
128 127
                 dialog --title $"Hubzilla channel directory server" \
129
-                       --msgbox $"\nInvalid domain - include the https://" 7 60
128
+                       --msgbox $"\\nInvalid domain - include the https://" 7 60
129
+                rm -f "$data"
130 130
                 return
131 131
             fi
132
-            ./var/www/$HUBZILLA_DOMAIN_NAME/htdocs/util/config system directory_server $hubzilla_domain_server
132
+            "./var/www/$HUBZILLA_DOMAIN_NAME/htdocs/util/config" system directory_server "$hubzilla_domain_server"
133 133
             dialog --title $"Hubzilla channel directory server" \
134
-                   --msgbox $"\nDomain channel directory server changed to\n\n  $hubzilla_domain_server" 10 60
134
+                   --msgbox $"\\nDomain channel directory server changed to\\n\\n  $hubzilla_domain_server" 10 60
135 135
             ;;
136 136
     esac
137
+    rm -f "$data"
137 138
 }
138 139
 
139 140
 function configure_interactive_hubzilla {
140 141
     while true
141 142
     do
142
-        data=$(tempfile 2>/dev/null)
143
-        trap "rm -f $data" 0 1 2 5 15
143
+        data=$(mktemp 2>/dev/null)
144 144
         dialog --backtitle $"Freedombone Control Panel" \
145 145
                --title $"Hubzilla" \
146 146
                --radiolist $"Choose an operation:" 13 70 4 \
147 147
                1 $"Set channel directory server" off \
148 148
                2 $"Renew SSL certificate" off \
149
-               3 $"Back to main menu" on 2> $data
149
+               3 $"Back to main menu" on 2> "$data"
150 150
         sel=$?
151 151
         case $sel in
152 152
             1) break;;
153 153
             255) break;;
154 154
         esac
155
-        case $(cat $data) in
155
+        case $(cat "$data") in
156 156
             1) hubzilla_channel_directory_server;;
157 157
             2) hubzilla_renew_cert;;
158
-            3) break;;
158
+            3) rm -f "$data"
159
+               break;;
159 160
         esac
161
+        rm -f "$data"
160 162
     done
161 163
 }
162 164
 
163 165
 function install_interactive_hubzilla {
164
-    if [[ $ONION_ONLY != "no" ]]; then
166
+    if [[ "$ONION_ONLY" != "no" ]]; then
165 167
         return
166 168
     fi
167 169
 
@@ -172,7 +174,7 @@ function install_interactive_hubzilla {
172 174
 }
173 175
 
174 176
 function change_password_hubzilla {
175
-    HUBZILLA_USERNAME="$1"
177
+#    HUBZILLA_USERNAME="$1"
176 178
     HUBZILLA_PASSWORD="$2"
177 179
     if [ ${#HUBZILLA_PASSWORD} -lt 8 ]; then
178 180
         echo $'Hubzilla password is too short'
@@ -183,14 +185,14 @@ function change_password_hubzilla {
183 185
 }
184 186
 
185 187
 function hubzilla_create_database {
186
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
187
-        HUBZILLA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
188
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
189
+        HUBZILLA_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
188 190
     fi
189
-    if [ ! $HUBZILLA_ADMIN_PASSWORD ]; then
190
-        HUBZILLA_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
191
+    if [ ! "$HUBZILLA_ADMIN_PASSWORD" ]; then
192
+        HUBZILLA_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
191 193
     fi
192
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a hubzilla -p "$HUBZILLA_ADMIN_PASSWORD"
193
-    if [ ! $HUBZILLA_ADMIN_PASSWORD ]; then
194
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a hubzilla -p "$HUBZILLA_ADMIN_PASSWORD"
195
+    if [ ! "$HUBZILLA_ADMIN_PASSWORD" ]; then
194 196
         return
195 197
     fi
196 198
 
@@ -211,25 +213,25 @@ function upgrade_hubzilla {
211 213
     HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
212 214
 
213 215
     function_check set_repo_commit
214
-    set_repo_commit $HUBZILLA_PATH "hubzilla commit" "$HUBZILLA_COMMIT" $HUBZILLA_REPO
215
-    set_repo_commit $HUBZILLA_PATH/addon "hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT" $HUBZILLA_ADDONS_REPO
216
-    if [ -d $HUBZILLA_PATH/redmatrix-themes1 ]; then
217
-        cd $HUBZILLA_PATH/redmatrix-themes1
216
+    set_repo_commit "$HUBZILLA_PATH" "hubzilla commit" "$HUBZILLA_COMMIT" $HUBZILLA_REPO
217
+    set_repo_commit "$HUBZILLA_PATH/addon" "hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT" $HUBZILLA_ADDONS_REPO
218
+    if [ -d "$HUBZILLA_PATH/redmatrix-themes1" ]; then
219
+        cd "$HUBZILLA_PATH/redmatrix-themes1" || exit 246782456
218 220
         git merge --abort
219 221
         git stash
220 222
         git pull
221
-        cp -r $HUBZILLA_PATH/redmatrix-themes1/* $HUBZILLA_PATH/view/theme/
222
-        chown -R www-data:www-data $HUBZILLA_PATH
223
+        cp -r "$HUBZILLA_PATH/redmatrix-themes1/*" "$HUBZILLA_PATH/view/theme/"
224
+        chown -R www-data:www-data "$HUBZILLA_PATH"
223 225
     fi
224 226
 }
225 227
 
226 228
 function backup_local_hubzilla {
227 229
     hubzilla_path=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
228
-    if [ -d $hubzilla_path ]; then
230
+    if [ -d "$hubzilla_path" ]; then
229 231
         function_check backup_database_to_usb
230 232
         backup_database_to_usb hubzilla
231 233
 
232
-        backup_directory_to_usb $hubzilla_path hubzilla
234
+        backup_directory_to_usb "$hubzilla_path" hubzilla
233 235
     fi
234 236
 }
235 237
 
@@ -240,31 +242,31 @@ function restore_local_hubzilla {
240 242
     function_check hubzilla_create_database
241 243
     hubzilla_create_database
242 244
 
243
-    restore_database hubzilla ${HUBZILLA_DOMAIN_NAME}
244
-    if [ -d $USB_MOUNT/backup/hubzilla ]; then
245
-        if [ ! -d $hubzilla_dir/store/[data]/smarty3 ]; then
246
-            mkdir -p $hubzilla_dir/store/[data]/smarty3
245
+    restore_database hubzilla "${HUBZILLA_DOMAIN_NAME}"
246
+    if [ -d "$USB_MOUNT/backup/hubzilla" ]; then
247
+        if [ ! -d "$hubzilla_dir/store/[data]/smarty3" ]; then
248
+            mkdir -p "$hubzilla_dir/store/[data]/smarty3"
247 249
         fi
248
-        chmod 1777 $hubzilla_dir/store/[data]/smarty3
249
-        chown -R www-data:www-data $hubzilla_dir/*
250
+        chmod 1777 "$hubzilla_dir/store/[data]/smarty3"
251
+        chown -R www-data:www-data "$hubzilla_dir/*"
250 252
         if [ -d $temp_restore_dir ]; then
251 253
             rm -rf $temp_restore_dir
252 254
         fi
253 255
 
254
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
255
-        HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
256
-        sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" $HUBZILLA_PATH/.htconfig.php
256
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
257
+        HUBZILLA_PATH="/var/www/$HUBZILLA_DOMAIN_NAME/htdocs"
258
+        sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$HUBZILLA_PATH/.htconfig.php"
257 259
         MARIADB_PASSWORD=
258 260
     fi
259 261
 }
260 262
 
261 263
 function backup_remote_hubzilla {
262
-    temp_backup_dir=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
263
-    if [ -d $temp_backup_dir ]; then
264
-        suspend_site ${HUBZILLA_DOMAIN_NAME}
264
+    temp_backup_dir="/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs"
265
+    if [ -d "$temp_backup_dir" ]; then
266
+        suspend_site "${HUBZILLA_DOMAIN_NAME}"
265 267
         backup_database_to_friend hubzilla
266 268
         echo "Backing up Hubzilla installation"
267
-        backup_directory_to_friend $temp_backup_dir hubzilla
269
+        backup_directory_to_friend "$temp_backup_dir" hubzilla
268 270
         restart_site
269 271
         echo "Backup of Hubzilla complete"
270 272
     else
@@ -279,21 +281,21 @@ function restore_remote_hubzilla {
279 281
     function_check hubzilla_create_database
280 282
     hubzilla_create_database
281 283
 
282
-    restore_database_from_friend hubzilla ${HUBZILLA_DOMAIN_NAME}
283
-    if [ -d $SERVER_DIRECTORY/backup/hubzilla ]; then
284
-        if [ ! -d /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3 ]; then
285
-            mkdir -p /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
284
+    restore_database_from_friend hubzilla "${HUBZILLA_DOMAIN_NAME}"
285
+    if [ -d "$SERVER_DIRECTORY/backup/hubzilla" ]; then
286
+        if [ ! -d "/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3" ]; then
287
+            mkdir -p "/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3"
286 288
         fi
287
-        chmod 1777 /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3
288
-        chown -R www-data:www-data /var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/*
289
+        chmod 1777 "/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/store/[data]/smarty3"
290
+        chown -R www-data:www-data "/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs/*"
289 291
     fi
290 292
     if [ -d /root/temphubzilla ]; then
291 293
         rm -rf /root/temphubzilla
292 294
     fi
293 295
 
294
-    MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
296
+    MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
295 297
     HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
296
-    sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" $HUBZILLA_PATH/.htconfig.php
298
+    sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$HUBZILLA_PATH/.htconfig.php"
297 299
     MARIADB_PASSWORD=
298 300
 }
299 301
 
@@ -301,41 +303,41 @@ function remove_hubzilla {
301 303
     if [ ${#HUBZILLA_DOMAIN_NAME} -eq 0 ]; then
302 304
         return
303 305
     fi
304
-    nginx_dissite $HUBZILLA_DOMAIN_NAME
305
-    remove_certs ${HUBZILLA_DOMAIN_NAME}
306
-    if [ -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
307
-        rm -rf /var/www/$HUBZILLA_DOMAIN_NAME
306
+    nginx_dissite "$HUBZILLA_DOMAIN_NAME"
307
+    remove_certs "${HUBZILLA_DOMAIN_NAME}"
308
+    if [ -d "/var/www/$HUBZILLA_DOMAIN_NAME" ]; then
309
+        rm -rf "/var/www/$HUBZILLA_DOMAIN_NAME"
308 310
     fi
309
-    if [ -f /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME ]; then
310
-        rm /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
311
+    if [ -f "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME" ]; then
312
+        rm "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
311 313
     fi
312 314
     function_check drop_database
313 315
     drop_database hubzilla
314 316
     function_check remove_onion_service
315 317
     remove_onion_service hubzilla ${HUBZILLA_ONION_PORT}
316
-    sed -i '/hubzilla/d' $COMPLETION_FILE
318
+    sed -i '/hubzilla/d' "$COMPLETION_FILE"
317 319
     sed -i '/poller.php/d' /etc/crontab
318 320
 
319 321
     function_check remove_ddns_domain
320
-    remove_ddns_domain $HUBZILLA_DOMAIN_NAME
322
+    remove_ddns_domain "$HUBZILLA_DOMAIN_NAME"
321 323
 }
322 324
 
323 325
 function install_hubzilla {
324
-    if [ ! $HUBZILLA_DOMAIN_NAME ]; then
326
+    if [ ! "$HUBZILLA_DOMAIN_NAME" ]; then
325 327
         return
326 328
     fi
327 329
 
328
-    if [[ $ONION_ONLY != "no" ]]; then
330
+    if [[ "$ONION_ONLY" != "no" ]]; then
329 331
         echo $"Hubzilla won't work on an onion address"
330 332
         exit 529925
331 333
     fi
332 334
 
333
-    HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
335
+    HUBZILLA_PATH="/var/www/$HUBZILLA_DOMAIN_NAME/htdocs"
334 336
 
335 337
     function_check install_mariadb
336 338
     install_mariadb
337 339
 
338
-    if [ -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
340
+    if [ -d "/var/www/$HUBZILLA_DOMAIN_NAME" ]; then
339 341
         remove_hubzilla
340 342
     fi
341 343
 
@@ -349,44 +351,44 @@ function install_hubzilla {
349 351
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
350 352
     apt-get -yq install php-memcached memcached
351 353
 
352
-    if [ ! -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
353
-        mkdir /var/www/$HUBZILLA_DOMAIN_NAME
354
+    if [ ! -d "/var/www/$HUBZILLA_DOMAIN_NAME" ]; then
355
+        mkdir "/var/www/$HUBZILLA_DOMAIN_NAME"
354 356
     fi
355
-    if [ ! -d $HUBZILLA_PATH ]; then
356
-        mkdir -p $HUBZILLA_PATH
357
+    if [ ! -d "$HUBZILLA_PATH" ]; then
358
+        mkdir -p "$HUBZILLA_PATH"
357 359
     fi
358 360
 
359
-    if [ ! -f $HUBZILLA_PATH/index.php ]; then
361
+    if [ ! -f "$HUBZILLA_PATH/index.php" ]; then
360 362
         if [ -d /repos/hubzilla ]; then
361
-            mkdir $HUBZILLA_PATH
362
-            cp -r -p /repos/hubzilla/. $HUBZILLA_PATH
363
-            cd $HUBZILLA_PATH
363
+            mkdir "$HUBZILLA_PATH"
364
+            cp -r -p /repos/hubzilla/. "$HUBZILLA_PATH"
365
+            cd "$HUBZILLA_PATH" || exit 245672478
364 366
             git pull
365 367
         else
366 368
             function_check git_clone
367
-            git_clone $HUBZILLA_REPO $HUBZILLA_PATH
369
+            git_clone "$HUBZILLA_REPO" "$HUBZILLA_PATH"
368 370
         fi
369 371
 
370
-        git checkout $HUBZILLA_COMMIT -b $HUBZILLA_COMMIT
372
+        git checkout "$HUBZILLA_COMMIT" -b "$HUBZILLA_COMMIT"
371 373
         set_completion_param "hubzilla commit" "$HUBZILLA_COMMIT"
372 374
 
373 375
         if [ -d /repos/hubzilla-addons ]; then
374
-            mkdir $HUBZILLA_PATH/addon
375
-            cp -r -p /repos/hubzilla-addons/. $HUBZILLA_PATH/addon
376
-            cd $HUBZILLA_PATH/addon
376
+            mkdir "$HUBZILLA_PATH/addon"
377
+            cp -r -p /repos/hubzilla-addons/. "$HUBZILLA_PATH/addon"
378
+            cd "$HUBZILLA_PATH/addon" || exit 24682464
377 379
             git pull
378 380
         else
379
-            git_clone $HUBZILLA_ADDONS_REPO $HUBZILLA_PATH/addon
381
+            git_clone "$HUBZILLA_ADDONS_REPO" "$HUBZILLA_PATH/addon"
380 382
         fi
381 383
 
382
-        cd $HUBZILLA_PATH/addon
383
-        git checkout $HUBZILLA_ADDONS_COMMIT -b $HUBZILLA_ADDONS_COMMIT
384
+        cd "$HUBZILLA_PATH/addon" || exit 24982468
385
+        git checkout "$HUBZILLA_ADDONS_COMMIT" -b "$HUBZILLA_ADDONS_COMMIT"
384 386
         set_completion_param "hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT"
385 387
 
386
-        chown -R www-data:www-data $HUBZILLA_PATH
388
+        chown -R www-data:www-data "$HUBZILLA_PATH"
387 389
     fi
388 390
 
389
-    if [ ! -f $HUBZILLA_PATH/install/schema_mysql.sql ]; then
391
+    if [ ! -f "$HUBZILLA_PATH/install/schema_mysql.sql" ]; then
390 392
         echo $'No database schema found for hubzilla'
391 393
         exit 252782
392 394
     fi
@@ -403,156 +405,156 @@ function install_hubzilla {
403 405
     fi
404 406
 
405 407
     function_check add_ddns_domain
406
-    add_ddns_domain $HUBZILLA_DOMAIN_NAME
408
+    add_ddns_domain "$HUBZILLA_DOMAIN_NAME"
407 409
 
408
-    if [[ $ONION_ONLY == "no" ]]; then
410
+    if [[ "$ONION_ONLY" == "no" ]]; then
409 411
         function_check nginx_http_redirect
410
-        nginx_http_redirect $HUBZILLA_DOMAIN_NAME
411
-        echo 'server {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
412
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
413
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
414
-        echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
415
-        echo "    server_name $HUBZILLA_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
416
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
417
-        echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
418
-        echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
419
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
412
+        nginx_http_redirect "$HUBZILLA_DOMAIN_NAME"
413
+        { echo 'server {';
414
+          echo '    listen 443 ssl;';
415
+          echo '    #listen [::]:443 ssl;';
416
+          echo "    root $HUBZILLA_PATH;";
417
+          echo "    server_name $HUBZILLA_DOMAIN_NAME;";
418
+          echo "    error_log /dev/null;";
419
+          echo '    index index.php;';
420
+          echo '    charset utf-8;';
421
+          echo '    access_log /dev/null;'; } >> "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
420 422
         function_check nginx_ssl
421
-        nginx_ssl $HUBZILLA_DOMAIN_NAME
423
+        nginx_ssl "$HUBZILLA_DOMAIN_NAME"
422 424
         function_check nginx_disable_sniffing
423
-        nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
424
-        echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
425
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
426
-        echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
427
-        echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
425
+        nginx_disable_sniffing "$HUBZILLA_DOMAIN_NAME"
426
+        { echo '    add_header Strict-Transport-Security max-age=15768000;';
427
+          echo '';
428
+          echo '    # rewrite to front controller as default rule';
429
+          echo '    location / {'; } >> "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
428 430
         function_check nginx_limits
429
-        nginx_limits $HUBZILLA_DOMAIN_NAME
430
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
431
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
432
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
433
-        echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
434
-        echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
435
-        echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
436
-        echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
437
-        echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
438
-        echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
439
-        echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
440
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
441
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
442
-        echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
443
-        echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
444
-        echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
445
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
446
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
447
-        echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
448
-        echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
449
-        echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
431
+        nginx_limits "$HUBZILLA_DOMAIN_NAME"
432
+        { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
433
+          echo '    }';
434
+          echo '';
435
+          echo '    # statically serve these file types when possible';
436
+          echo '    # otherwise fall back to front controller';
437
+          echo '    # allow browser to cache them';
438
+          echo '    # added .htm for advanced source code editor library';
439
+          echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
440
+          echo '        expires 30d;';
441
+          echo "        try_files \$uri /index.php?q=\$uri&\$args;";
442
+          echo '    }';
443
+          echo '';
444
+          echo '    # block these file types';
445
+          echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
446
+          echo '        deny all;';
447
+          echo '    }';
448
+          echo '';
449
+          echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
450
+          echo '    # or a unix socket';
451
+          echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
450 452
         function_check nginx_limits
451
-        nginx_limits $HUBZILLA_DOMAIN_NAME
452
-        echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
453
-        echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
454
-        echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
455
-        echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
456
-        echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
457
-        echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
458
-        echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
459
-        echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
460
-        echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
461
-        echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
462
-        echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
463
-        echo '        # With php-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
464
-        echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
465
-        echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
466
-        echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
467
-        echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
468
-        echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
469
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
470
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
471
-        echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
472
-        echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
473
-        echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
474
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
475
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
476
-        echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
477
-        echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
478
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
479
-        echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
480
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
453
+        nginx_limits "$HUBZILLA_DOMAIN_NAME"
454
+        { echo '        # Zero-day exploit defense.';
455
+          echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
456
+          echo "        # Won't work properly (404 error) if the file is not stored on this";
457
+          echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
458
+          echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
459
+          echo "        # another machine. And then cross your fingers that you won't get hacked.";
460
+          echo "        try_files \$uri \$uri/ /index.php;";
461
+          echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
462
+          echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
463
+          echo '        # With php-cgi alone:';
464
+          echo '        # fastcgi_pass 127.0.0.1:9000;';
465
+          echo '        # With php-fpm:';
466
+          echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
467
+          echo '        include fastcgi_params;';
468
+          echo '        fastcgi_index index.php;';
469
+          echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
470
+          echo '        fastcgi_read_timeout 300;';
471
+          echo '    }';
472
+          echo '';
473
+          echo '    # deny access to all dot files';
474
+          echo '    location ~ /\. {';
475
+          echo '        deny all;';
476
+          echo '    }';
477
+          echo '';
478
+          echo '    location ~ /\.ht {';
479
+          echo '      deny  all;';
480
+          echo '    }';
481
+          echo '}';
482
+          echo ''; } >> "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
481 483
     else
482
-        echo 'server {' > /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
483
-        echo "    listen 127.0.0.1:${HUBZILLA_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
484
-        echo "    root $HUBZILLA_PATH;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
485
-        echo "    server_name $HUBZILLA_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
486
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
487
-        echo '    index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
488
-        echo '    charset utf-8;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
489
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
490
-        echo '    add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
491
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
492
-        echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
493
-        echo '    location / {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
494
-        nginx_limits $HUBZILLA_DOMAIN_NAME
495
-        nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
496
-        echo '        rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
497
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
498
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
499
-        echo '    # statically serve these file types when possible' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
500
-        echo '    # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
501
-        echo '    # allow browser to cache them' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
502
-        echo '    # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
503
-        echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
504
-        echo '        expires 30d;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
505
-        echo '        try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
506
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
507
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
508
-        echo '    # block these file types' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
509
-        echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
510
-        echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
511
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
512
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
513
-        echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
514
-        echo '    # or a unix socket' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
515
-        echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
516
-        nginx_limits $HUBZILLA_DOMAIN_NAME
517
-        nginx_disable_sniffing $HUBZILLA_DOMAIN_NAME
518
-        echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
519
-        echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
520
-        echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
521
-        echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
522
-        echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
523
-        echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
524
-        echo '        try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
525
-        echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
526
-        echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
527
-        echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
528
-        echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
529
-        echo '        # With php-fpm:' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
530
-        echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
531
-        echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
532
-        echo '        fastcgi_index index.php;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
533
-        echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
534
-        echo '        fastcgi_read_timeout 300;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
535
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
536
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
537
-        echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
538
-        echo '    location ~ /\. {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
539
-        echo '        deny all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
540
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
541
-        echo '' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
542
-        echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
543
-        echo '      deny  all;' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
544
-        echo '    }' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
545
-        echo '}' >> /etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME
484
+        { echo 'server {';
485
+        echo "    listen 127.0.0.1:${HUBZILLA_ONION_PORT} default_server;";
486
+        echo "    root $HUBZILLA_PATH;";
487
+        echo "    server_name $HUBZILLA_ONION_HOSTNAME;";
488
+        echo "    error_log /dev/null;";
489
+        echo '    index index.php;';
490
+        echo '    charset utf-8;';
491
+        echo '    access_log /dev/null;';
492
+        echo '    add_header Strict-Transport-Security max-age=15768000;';
493
+        echo '';
494
+        echo '    # rewrite to front controller as default rule';
495
+        echo '    location / {'; } > "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
496
+        nginx_limits "$HUBZILLA_DOMAIN_NAME"
497
+        nginx_disable_sniffing "$HUBZILLA_DOMAIN_NAME"
498
+        { echo "        rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
499
+          echo '    }';
500
+          echo '';
501
+          echo '    # statically serve these file types when possible';
502
+          echo '    # otherwise fall back to front controller';
503
+          echo '    # allow browser to cache them';
504
+          echo '    # added .htm for advanced source code editor library';
505
+          echo '    location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
506
+          echo '        expires 30d;';
507
+          echo "        try_files \$uri /index.php?q=\$uri&\$args;";
508
+          echo '    }';
509
+          echo '';
510
+          echo '    # block these file types';
511
+          echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
512
+          echo '        deny all;';
513
+          echo '    }';
514
+          echo '';
515
+          echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
516
+          echo '    # or a unix socket';
517
+          echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
518
+        nginx_limits "$HUBZILLA_DOMAIN_NAME"
519
+        nginx_disable_sniffing "$HUBZILLA_DOMAIN_NAME"
520
+        { echo '        # Zero-day exploit defense.';
521
+          echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
522
+          echo "        # Won't work properly (404 error) if the file is not stored on this";
523
+          echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
524
+          echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
525
+          echo "        # another machine. And then cross your fingers that you won't get hacked.";
526
+          echo "        try_files \$uri \$uri/ /index.php;";
527
+          echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
528
+          echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
529
+          echo '        # With php-cgi alone:';
530
+          echo '        # fastcgi_pass 127.0.0.1:9000;';
531
+          echo '        # With php-fpm:';
532
+          echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
533
+          echo '        include fastcgi_params;';
534
+          echo '        fastcgi_index index.php;';
535
+          echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
536
+          echo '        fastcgi_read_timeout 300;';
537
+          echo '    }';
538
+          echo '';
539
+          echo '    # deny access to all dot files';
540
+          echo '    location ~ /\. {';
541
+          echo '        deny all;';
542
+          echo '    }';
543
+          echo '';
544
+          echo '    location ~ /\.ht {';
545
+          echo '      deny  all;';
546
+          echo '    }';
547
+          echo '}'; } >> "/etc/nginx/sites-available/$HUBZILLA_DOMAIN_NAME"
546 548
     fi
547 549
 
548 550
     function_check configure_php
549 551
     configure_php
550 552
 
551 553
     function_check create_site_certificate
552
-    create_site_certificate $HUBZILLA_DOMAIN_NAME 'yes'
554
+    create_site_certificate "$HUBZILLA_DOMAIN_NAME" 'yes'
553 555
 
554
-    if [ ! -d $HUBZILLA_PATH/view/tpl/smarty3 ]; then
555
-        mkdir $HUBZILLA_PATH/view/tpl/smarty3
556
+    if [ ! -d "$HUBZILLA_PATH/view/tpl/smarty3" ]; then
557
+        mkdir "$HUBZILLA_PATH/view/tpl/smarty3"
556 558
     fi
557 559
     if [ ! -d "$HUBZILLA_PATH/store" ]; then
558 560
         mkdir "$HUBZILLA_PATH/store"
@@ -564,9 +566,9 @@ function install_hubzilla {
564 566
         mkdir "$HUBZILLA_PATH/store/[data]/smarty3"
565 567
         chmod 1777 "$HUBZILLA_PATH/store/[data]/smarty3"
566 568
     fi
567
-    chmod 1777 $HUBZILLA_PATH/view/tpl
569
+    chmod 1777 "$HUBZILLA_PATH/view/tpl"
568 570
     chown -R www-data:www-data "$HUBZILLA_PATH/store"
569
-    chmod 1777 $HUBZILLA_PATH/view/tpl/smarty3
571
+    chmod 1777 "$HUBZILLA_PATH/view/tpl/smarty3"
570 572
 
571 573
     # Ensure that the database gets backed up locally, if remote
572 574
     # backups are not being used
@@ -576,50 +578,50 @@ function install_hubzilla {
576 578
     function_check backup_database_local
577 579
     backup_database_local hubzilla
578 580
 
579
-    chown -R www-data:www-data $HUBZILLA_PATH
581
+    chown -R www-data:www-data "$HUBZILLA_PATH"
580 582
 
581 583
     function_check nginx_ensite
582
-    nginx_ensite $HUBZILLA_DOMAIN_NAME
584
+    nginx_ensite "$HUBZILLA_DOMAIN_NAME"
583 585
 
584 586
     function_check initialise_database
585
-    initialise_database hubzilla $HUBZILLA_PATH/install/schema_mysql.sql
587
+    initialise_database hubzilla "$HUBZILLA_PATH/install/schema_mysql.sql"
586 588
 
587 589
     # create the config file
588
-    echo '<?php' > $HUBZILLA_PATH/.htconfig.php
589
-    echo "\$db_host = 'localhost';" >> $HUBZILLA_PATH/.htconfig.php
590
-    echo "\$db_port = '0';" >> $HUBZILLA_PATH/.htconfig.php
591
-    echo "\$db_user = 'root';" >> $HUBZILLA_PATH/.htconfig.php
592
-    echo "\$db_pass = '${MARIADB_PASSWORD}';" >> $HUBZILLA_PATH/.htconfig.php
593
-    echo "\$db_data = 'hubzilla';" >> $HUBZILLA_PATH/.htconfig.php
594
-    echo "\$db_type = '0';" >> $HUBZILLA_PATH/.htconfig.php
595
-    echo "\$default_timezone = 'Europe/London';" >> $HUBZILLA_PATH/.htconfig.php
596
-    if [[ $ONION_ONLY == 'no' ]]; then
597
-        echo "\$a->config['system']['baseurl'] = 'https://${HUBZILLA_DOMAIN_NAME}';" >> $HUBZILLA_PATH/.htconfig.php
590
+    { echo '<?php';
591
+      echo "\$db_host = 'localhost';";
592
+      echo "\$db_port = '0';";
593
+      echo "\$db_user = 'root';";
594
+      echo "\$db_pass = '${MARIADB_PASSWORD}';";
595
+      echo "\$db_data = 'hubzilla';";
596
+      echo "\$db_type = '0';";
597
+      echo "\$default_timezone = 'Europe/London';"; } > "$HUBZILLA_PATH/.htconfig.php"
598
+    if [[ "$ONION_ONLY" == 'no' ]]; then
599
+        echo "\$a->config['system']['baseurl'] = 'https://${HUBZILLA_DOMAIN_NAME}';" >> "$HUBZILLA_PATH/.htconfig.php"
598 600
     else
599
-        echo "\$a->config['system']['baseurl'] = 'http://${HUBZILLA_ONION_HOSTNAME}';" >> $HUBZILLA_PATH/.htconfig.php
601
+        echo "\$a->config['system']['baseurl'] = 'http://${HUBZILLA_ONION_HOSTNAME}';" >> "$HUBZILLA_PATH/.htconfig.php"
600 602
     fi
601
-    echo "\$a->config['system']['sitename'] = \"Hubzilla\";" >> $HUBZILLA_PATH/.htconfig.php
603
+    echo "\$a->config['system']['sitename'] = \"Hubzilla\";" >> "$HUBZILLA_PATH/.htconfig.php"
602 604
     HUBZILLA_LOCATION_HASH="$(create_password 30)"
603
-    echo "\$a->config['system']['location_hash'] = '${HUBZILLA_LOCATION_HASH}';" >> $HUBZILLA_PATH/.htconfig.php
604
-    echo "\$a->config['system']['register_policy'] = REGISTER_OPEN;" >> $HUBZILLA_PATH/.htconfig.php
605
-    echo "\$a->config['system']['register_text'] = '';" >> $HUBZILLA_PATH/.htconfig.php
606
-    echo "\$a->config['system']['admin_email'] = '${MY_EMAIL_ADDRESS}';" >> $HUBZILLA_PATH/.htconfig.php
607
-    echo "\$a->config['system']['verify_email'] = 1;" >> $HUBZILLA_PATH/.htconfig.php
608
-    echo "\$a->config['system']['access_policy'] = ACCESS_PRIVATE;" >> $HUBZILLA_PATH/.htconfig.php
609
-    echo "\$a->config['system']['sellpage'] = '';" >> $HUBZILLA_PATH/.htconfig.php
610
-    echo "\$a->config['system']['max_import_size'] = 200000;" >> $HUBZILLA_PATH/.htconfig.php
611
-    echo "\$a->config['system']['php_path'] = '/usr/bin/php';" >> $HUBZILLA_PATH/.htconfig.php
612
-    echo "\$a->config['system']['directory_mode']  = DIRECTORY_MODE_NORMAL;" >> $HUBZILLA_PATH/.htconfig.php
613
-    echo "\$a->config['system']['theme'] = 'redbasic';" >> $HUBZILLA_PATH/.htconfig.php
614
-    chown www-data:www-data $HUBZILLA_PATH/.htconfig.php
615
-    chmod 755 $HUBZILLA_PATH/.htconfig.php
605
+    { echo "\$a->config['system']['location_hash'] = '${HUBZILLA_LOCATION_HASH}';";
606
+      echo "\$a->config['system']['register_policy'] = REGISTER_OPEN;";
607
+      echo "\$a->config['system']['register_text'] = '';";
608
+      echo "\$a->config['system']['admin_email'] = '${MY_EMAIL_ADDRESS}';";
609
+      echo "\$a->config['system']['verify_email'] = 1;";
610
+      echo "\$a->config['system']['access_policy'] = ACCESS_PRIVATE;";
611
+      echo "\$a->config['system']['sellpage'] = '';";
612
+      echo "\$a->config['system']['max_import_size'] = 200000;";
613
+      echo "\$a->config['system']['php_path'] = '/usr/bin/php';";
614
+      echo "\$a->config['system']['directory_mode']  = DIRECTORY_MODE_NORMAL;";
615
+      echo "\$a->config['system']['theme'] = 'redbasic';"; } >> "$HUBZILLA_PATH/.htconfig.php"
616
+    chown www-data:www-data "$HUBZILLA_PATH/.htconfig.php"
617
+    chmod 755 "$HUBZILLA_PATH/.htconfig.php"
616 618
 
617 619
     systemctl restart mariadb
618 620
     systemctl restart php7.0-fpm
619 621
     systemctl restart nginx
620 622
     systemctl restart cron
621 623
 
622
-    ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$HUBZILLA_DOMAIN_NAME" -g hubzilla --public no
624
+    "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$HUBZILLA_DOMAIN_NAME" -g hubzilla --public no
623 625
 
624 626
     set_completion_param "hubzilla domain" "${HUBZILLA_DOMAIN_NAME}"
625 627
     APP_INSTALLED=1

+ 220
- 216
src/freedombone-app-icecast Просмотреть файл

@@ -68,36 +68,36 @@ function icecast_update_daemon {
68 68
         rm /etc/init.d/icecast2
69 69
     fi
70 70
 
71
-    echo '#!/bin/sh' > /usr/bin/stop_icecast
72
-    echo 'kill $(pidof ices2)' >> /usr/bin/stop_icecast
73
-    echo 'systemctl stop icecast2' >> /usr/bin/stop_icecast
71
+    { echo '#!/bin/sh';
72
+      echo "kill \$(pidof ices2)";
73
+      echo 'systemctl stop icecast2'; } > /usr/bin/stop_icecast
74 74
     chmod +x /usr/bin/stop_icecast
75 75
 
76 76
     # Note that the sleep here actually is important
77
-    echo '#!/bin/bash' > /usr/bin/start_icecast
78
-    echo 'isrunning=$(ps aux | grep ices2)' >> /usr/bin/start_icecast
79
-    echo 'if [[ "$isrunning" != *"ices-playlist"* ]]; then' >> /usr/bin/start_icecast
80
-    echo '    systemctl start icecast2' >> /usr/bin/start_icecast
81
-    echo '    sleep 3' >> /usr/bin/start_icecast
82
-    echo '    cd /etc/ices2' >> /usr/bin/start_icecast
83
-    echo '    ices2 ices-playlist.xml' >> /usr/bin/start_icecast
84
-    echo 'fi' >> /usr/bin/start_icecast
77
+    { echo '#!/bin/bash';
78
+      echo "isrunning=\$(ps aux | grep ices2)";
79
+      echo "if [[ \"\$isrunning\" != *\"ices-playlist\"* ]]; then";
80
+      echo '    systemctl start icecast2';
81
+      echo '    sleep 3';
82
+      echo '    cd /etc/ices2';
83
+      echo '    ices2 ices-playlist.xml';
84
+      echo 'fi'; } > /usr/bin/start_icecast
85 85
     chmod +x /usr/bin/start_icecast
86 86
 
87
-    echo '[Unit]' > /etc/systemd/system/icecast2.service
88
-    echo 'Description=Icecast' >> /etc/systemd/system/icecast2.service
89
-    echo 'After=network.target' >> /etc/systemd/system/icecast2.service
90
-    echo 'After=tor.service' >> /etc/systemd/system/icecast2.service
91
-    echo '' >> /etc/systemd/system/icecast2.service
92
-    echo '[Service]' >> /etc/systemd/system/icecast2.service
93
-    echo 'User=icecast2' >> /etc/systemd/system/icecast2.service
94
-    echo 'Group=icecast' >> /etc/systemd/system/icecast2.service
95
-    echo 'ExecStart=/usr/bin/icecast2 -c /etc/icecast2/icecast.xml' >> /etc/systemd/system/icecast2.service
96
-    echo 'Restart=on-failure' >> /etc/systemd/system/icecast2.service
97
-    echo 'RestartSec=10' >> /etc/systemd/system/icecast2.service
98
-    echo '' >> /etc/systemd/system/icecast2.service
99
-    echo '[Install]' >> /etc/systemd/system/icecast2.service
100
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/icecast2.service
87
+    { echo '[Unit]';
88
+      echo 'Description=Icecast';
89
+      echo 'After=network.target';
90
+      echo 'After=tor.service';
91
+      echo '';
92
+      echo '[Service]';
93
+      echo 'User=icecast2';
94
+      echo 'Group=icecast';
95
+      echo 'ExecStart=/usr/bin/icecast2 -c /etc/icecast2/icecast.xml';
96
+      echo 'Restart=on-failure';
97
+      echo 'RestartSec=10';
98
+      echo '';
99
+      echo '[Install]';
100
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/icecast2.service
101 101
 
102 102
     chown -R icecast2:icecast /etc/ices2
103 103
     chown -R icecast2:icecast /etc/icecast2
@@ -121,7 +121,7 @@ function change_password_icecast {
121 121
         /etc/icecast2/icecast.xml
122 122
     sed -i "s|<password>.*|<password>${new_user_password}</password>|g" /etc/ices2/ices-playlist.xml
123 123
 
124
-    ${PROJECT_NAME}-pass -u "$curr_username" -a icecast -p "$new_user_password"
124
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a icecast -p "$new_user_password"
125 125
     start_icecast
126 126
 }
127 127
 
@@ -139,7 +139,7 @@ function reconfigure_icecast {
139 139
 
140 140
 function icecast_convert_files {
141 141
     clear
142
-    cd ${1}
142
+    cd "${1}" || exit 2346824648
143 143
 
144 144
     echo $'Converting any mp3 files to ogg format'
145 145
     find . -type f -name '*.mp3' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${0/%mp3/ogg}"' '{}' \;
@@ -153,20 +153,20 @@ function icecast_convert_files {
153 153
 }
154 154
 
155 155
 function icecast_add_file_to_playlist {
156
-    files_dir=${1}
157
-    if [ ! -d $files_dir ]; then
156
+    files_dir="${1}"
157
+    if [ ! -d "$files_dir" ]; then
158 158
         return
159 159
     fi
160 160
 
161 161
     echo $'Adding ogg files to playlist'
162
-    find $files_dir -type f -name '*.ogg' -print0 | while read -d $'\0' file; do
162
+    find "$files_dir" -type f -name '*.ogg' -print0 | while read -r -d $'\0' file; do
163 163
         if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
164 164
             echo "$file" >> $ICECAST_PLAYLIST_FILE
165 165
         fi
166 166
     done
167 167
 
168 168
     echo $'Adding ogv files to playlist'
169
-    find $files_dir -type f -name '*.ogv' -print0 | while read -d $'\0' file; do
169
+    find "$files_dir" -type f -name '*.ogv' -print0 | while read -r -d $'\0' file; do
170 170
         if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
171 171
             echo "$file" >> $ICECAST_PLAYLIST_FILE
172 172
         fi
@@ -178,14 +178,14 @@ function icecast_add_file_to_playlist {
178 178
 }
179 179
 
180 180
 function icecast_import_from_directory {
181
-    data=$(tempfile 2>/dev/null)
182
-    dialog --title "Choose a directory containing stream files" --dselect /home/$MY_USERNAME/ 30 60 2> $data
183
-    selected_dir=$(cat $data)
184
-    rm $data
181
+    data=$(mktemp 2>/dev/null)
182
+    dialog --title "Choose a directory containing stream files" --dselect "/home/$MY_USERNAME/" 30 60 2> "$data"
183
+    selected_dir=$(cat "$data")
184
+    rm -f "$data"
185 185
     if [[ "$selected_dir" == "$ICECAST_DIR" ]]; then
186 186
         return
187 187
     fi
188
-    if [ ! -d $selected_dir ]; then
188
+    if [ ! -d "$selected_dir" ]; then
189 189
         return
190 190
     fi
191 191
     if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
@@ -201,7 +201,7 @@ function icecast_import_from_directory {
201 201
     dialog --title $"Import stream files directory into Icecast" \
202 202
            --backtitle $"Freedombone Control Panel" \
203 203
            --defaultno \
204
-           --yesno $"\nImport the directory:\n\n  $selected_dir" 12 75
204
+           --yesno $"\\nImport the directory:\\n\\n  $selected_dir" 12 75
205 205
     sel=$?
206 206
     case $sel in
207 207
         1) return;;
@@ -215,8 +215,8 @@ function icecast_import_from_directory {
215 215
     dest_dir=$(basename "$selected_dir")
216 216
     mv "$selected_dir" $ICECAST_DIR
217 217
 
218
-    icecast_convert_files $ICECAST_DIR/$dest_dir
219
-    icecast_add_file_to_playlist $ICECAST_DIR/$dest_dir
218
+    icecast_convert_files "$ICECAST_DIR/$dest_dir"
219
+    icecast_add_file_to_playlist "$ICECAST_DIR/$dest_dir"
220 220
 
221 221
     dialog --title $"Import stream files directory into Icecast" \
222 222
            --msgbox $"Import success" 6 40
@@ -226,18 +226,18 @@ function icecast_import_from_usb {
226 226
     clear
227 227
     detect_usb_drive
228 228
 
229
-    if [ ! -b $USB_DRIVE ]; then
229
+    if [ ! -b "$USB_DRIVE" ]; then
230 230
         dialog --title $"Import stream files from USB drive" --msgbox $'No USB drive found' 6 50
231 231
         return
232 232
     fi
233 233
 
234
-    backup_mount_drive ${USB_DRIVE}
235
-    if [ ! -d $USB_MOUNT$ICECAST_DIR ]; then
234
+    backup_mount_drive "${USB_DRIVE}"
235
+    if [ ! -d "$USB_MOUNT$ICECAST_DIR" ]; then
236 236
         dialog --title $"Import stream files from USB drive" --msgbox $'No stream files directory found on USB drive' 6 50
237
-        backup_unmount_drive ${USB_DRIVE}
237
+        backup_unmount_drive "${USB_DRIVE}"
238 238
     fi
239
-    cp -ru $USB_MOUNT$ICECAST_DIR/* $ICECAST_DIR
240
-    backup_unmount_drive ${USB_DRIVE}
239
+    cp -ru "$USB_MOUNT$ICECAST_DIR/*" $ICECAST_DIR
240
+    backup_unmount_drive "${USB_DRIVE}"
241 241
     icecast_convert_files $ICECAST_DIR
242 242
     dialog --title $"Import stream files from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
243 243
 }
@@ -246,40 +246,41 @@ function icecast_export_to_usb {
246 246
     clear
247 247
     detect_usb_drive
248 248
 
249
-    if [ ! -b $USB_DRIVE ]; then
249
+    if [ ! -b "$USB_DRIVE" ]; then
250 250
         dialog --title $"Export stream files to USB drive" --msgbox $'No USB drive found' 6 50
251 251
         return
252 252
     fi
253 253
 
254
-    backup_mount_drive ${USB_DRIVE}
255
-    if [ ! -d $USB_MOUNT$ICECAST_DIR ]; then
256
-        mkdir -p $USB_MOUNT$ICECAST_DIR
254
+    backup_mount_drive "${USB_DRIVE}"
255
+    if [ ! -d "$USB_MOUNT$ICECAST_DIR" ]; then
256
+        mkdir -p "$USB_MOUNT$ICECAST_DIR"
257 257
     fi
258
-    cp -ru $ICECAST_DIR/* $USB_MOUNT$ICECAST_DIR
259
-    backup_unmount_drive ${USB_DRIVE}
258
+    cp -ru "$ICECAST_DIR/*" "$USB_MOUNT$ICECAST_DIR"
259
+    backup_unmount_drive "${USB_DRIVE}"
260 260
     dialog --title $"Export stream files to USB drive" --msgbox $'Export complete. You may now remove the USB drive' 6 50
261 261
 }
262 262
 
263 263
 function icecast_format_drive {
264 264
     detect_usb_drive
265
-    data=$(tempfile 2>/dev/null)
266
-    trap "rm -f $data" 0 1 2 5 15
265
+    data=$(mktemp 2>/dev/null)
267 266
     dialog --title $"Format USB drive $USB_DRIVE for stream file storage" \
268 267
            --backtitle $"Freedombone Control Panel" \
269 268
            --defaultno \
270
-           --yesno $"\nPlease confirm that you wish to format drive\n\n    ${USB_DRIVE}\n\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\n\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
269
+           --yesno $"\\nPlease confirm that you wish to format drive\\n\\n    ${USB_DRIVE}\\n\\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\\n\\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
271 270
     sel=$?
272 271
     case $sel in
273
-        1) return;;
274
-        255) return;;
272
+        1)  rm -f "$data"
273
+            return;;
274
+        255) rm -f "$data"
275
+             return;;
275 276
     esac
276
-    rm $data
277
+    rm -f "$data"
277 278
 
278 279
     clear
279 280
     echo ''
280 281
     echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
281 282
     echo ''
282
-    ${PROJECT_NAME}-format $USB_DRIVE
283
+    "${PROJECT_NAME}-format" "$USB_DRIVE"
283 284
     dialog --title $"Format USB drive $USB_DRIVE for stream file storage" --msgbox $'Format complete. You may now export stream files or remove the USB drive' 6 50
284 285
 }
285 286
 
@@ -290,42 +291,41 @@ function icecast_edit_playlist {
290 291
 }
291 292
 
292 293
 function icecast_change_login {
293
-    read_config_param $MY_USERNAME
294
-    ICECAST_USER_PASSWORD=$(${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser)
294
+    read_config_param "$MY_USERNAME"
295
+    ICECAST_USER_PASSWORD=$("${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser)
295 296
 
296
-    data=$(tempfile 2>/dev/null)
297
-    trap "rm -f $data" 0 1 2 5 15
297
+    data=$(mktemp 2>/dev/null)
298 298
     dialog --title $"Change Icecast stream visitor login" \
299 299
            --backtitle $"Freedombone Control Panel" \
300
-           --inputbox $"Enter the new login password for stream visitors" 8 60 "$ICECAST_USER_PASSWORD" 2>$data
300
+           --inputbox $"Enter the new login password for stream visitors" 8 60 "$ICECAST_USER_PASSWORD" 2>"$data"
301 301
     sel=$?
302 302
     case $sel in
303
-        0)  ICECAST_USER_PASSWORD=$(<$data)
303
+        0)  ICECAST_USER_PASSWORD=$(<"$data")
304 304
             if [[ "$ICECAST_USER_PASSWORD" != *' '* ]]; then
305 305
                 if [ ${#ICECAST_USER_PASSWORD} -gt 8 ]; then
306
-                    ${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser -p $ICECAST_USER_PASSWORD
306
+                    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser -p "$ICECAST_USER_PASSWORD"
307 307
                     dialog --title $"Change Icecast stream visitor login" \
308 308
                            --msgbox $"Password changed to $ICECAST_USER_PASSWORD" 6 75
309 309
                 fi
310 310
             fi
311 311
             ;;
312 312
     esac
313
-    rm $data
313
+    rm -f "$data"
314 314
 }
315 315
 
316 316
 function icecast_enable_login {
317 317
     dialog --title $"Enable Icecast login" \
318 318
            --backtitle $"Freedombone Control Panel" \
319 319
            --defaultno \
320
-           --yesno $"\nDo you want to add a login so that random web users can't access your stream?" 10 60
320
+           --yesno $"\\nDo you want to add a login so that random web users can't access your stream?" 10 60
321 321
     sel=$?
322 322
     case $sel in
323 323
         0) if grep -q '#auth_basic' /etc/nginx/sites-available/icecast; then
324 324
                sed -i 's|#auth_basic|auth_basic|g' /etc/nginx/sites-available/icecast
325 325
                systemctl restart nginx
326 326
            fi
327
-           read_config_param $MY_USERNAME
328
-           ICECAST_USER_PASSWORD=$(${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser)
327
+           read_config_param "$MY_USERNAME"
328
+           ICECAST_USER_PASSWORD=$("${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser)
329 329
            dialog --title $"Enable Icecast login" \
330 330
                   --msgbox $"Icecast logins are now enabled with the password $ICECAST_USER_PASSWORD" 6 65
331 331
            ICECAST_USER_PASSWORD=
@@ -341,23 +341,24 @@ function icecast_enable_login {
341 341
 }
342 342
 
343 343
 function icecast_set_stream_name {
344
-    data=$(tempfile 2>/dev/null)
345
-    trap "rm -f $data" 0 1 2 5 15
344
+    data=$(mktemp 2>/dev/null)
346 345
     dialog --backtitle $"Freedombone Control Panel" \
347 346
            --title $"Change Icecast stream details" \
348
-           --form "\n" 8 60 4 \
347
+           --form "\\n" 8 60 4 \
349 348
            $"Stream name:" 1 1 "Example stream name" 1 18 40 1000 \
350 349
            $"Description:" 2 1 "A short description of your stream" 2 18 40 1000 \
351 350
            $"Genre:" 3 1 "Example genre" 3 18 40 1000 \
352
-           2> $data
351
+           2> "$data"
353 352
     sel=$?
354 353
     case $sel in
355
-        1) return;;
356
-        255) return;;
354
+        1) rm -f "$data"
355
+           return;;
356
+        255) rm -f "$data"
357
+             return;;
357 358
     esac
358
-    stream_name=$(cat $data | sed -n 1p)
359
-    stream_description=$(cat $data | sed -n 2p)
360
-    stream_genre=$(cat $data | sed -n 3p)
359
+    stream_name=$(sed -n 1p < "$data")
360
+    stream_description=$(sed -n 2p < "$data")
361
+    stream_genre=$(sed -n 3p < "$data")
361 362
     if [ ${#stream_name} -gt 2 ]; then
362 363
         sed -i "s|<name>.*|<name>${stream_name}</name>|g" /etc/ices2/ices-playlist.xml
363 364
     fi
@@ -367,42 +368,41 @@ function icecast_set_stream_name {
367 368
     if [ ${#stream_genre} -gt 2 ]; then
368 369
         sed -i "s|<genre>.*|<genre>${stream_genre}</genre>|g" /etc/ices2/ices-playlist.xml
369 370
     fi
370
-    rm $data
371
+    rm -f "$data"
371 372
     stop_icecast
372 373
     start_icecast
373 374
 }
374 375
 
375 376
 function icecast_set_maximum_streams {
376
-    data=$(tempfile 2>/dev/null)
377
-    trap "rm -f $data" 0 1 2 5 15
377
+    data=$(mktemp 2>/dev/null)
378 378
     dialog --title $"Set the maximum clients" \
379 379
            --backtitle $"Freedombone Control Panel" \
380
-           --inputbox $"Maximum number of clients" 8 40 "10" 2>$data
380
+           --inputbox $"Maximum number of clients" 8 40 "10" 2>"$data"
381 381
     sel=$?
382 382
     case $sel in
383 383
         0)
384
-            max_clients=$(<$data)
384
+            max_clients=$(<"$data")
385 385
             if [ ${#max_clients} -gt 0 ]; then
386 386
                 if [[ "$max_clients" != *' '* ]]; then
387
-                    if [[ $max_clients =~ '^[0-9]+$' ]] ; then
387
+                    # shellcheck disable=SC2076
388
+                    if [[ "$max_clients" =~ '^[0-9]+$' ]] ; then
388 389
                         sed -i "s|<clients>.*|<clients>${max_clients}</clients>|g" /etc/icecast2/icecast.xml
389 390
                         stop_icecast
390 391
                         start_icecast
391 392
                         dialog --title $"Set the maximum clients" \
392
-                               --msgbox $"\nMaximum Icecast clients was set to ${max_clients}" 8 50
393
+                               --msgbox $"\\nMaximum Icecast clients was set to ${max_clients}" 8 50
393 394
                     fi
394 395
                 fi
395 396
             fi
396 397
             ;;
397 398
     esac
398
-    rm $data
399
+    rm -f "$data"
399 400
 }
400 401
 
401 402
 function configure_interactive_icecast {
402 403
     while true
403 404
     do
404
-        data=$(tempfile 2>/dev/null)
405
-        trap "rm -f $data" 0 1 2 5 15
405
+        data=$(mktemp 2>/dev/null)
406 406
         dialog --backtitle $"Freedombone Control Panel" \
407 407
                --title $"Icecast" \
408 408
                --radiolist $"Choose an operation:" 19 70 12 \
@@ -417,13 +417,15 @@ function configure_interactive_icecast {
417 417
                9 $"Restart stream" off \
418 418
                10 $"Set Stream Name/Description/Genre" off \
419 419
                11 $"Set maximum number of clients/streams" off \
420
-               12 $"Exit" on 2> $data
420
+               12 $"Exit" on 2> "$data"
421 421
         sel=$?
422 422
         case $sel in
423
-            1) break;;
424
-            255) break;;
423
+            1) rm -f "$data"
424
+               break;;
425
+            255) rm -f "$data"
426
+                 break;;
425 427
         esac
426
-        case $(cat $data) in
428
+        case $(cat "$data") in
427 429
             1) icecast_import_from_directory;;
428 430
             2) icecast_import_from_usb;;
429 431
             3) icecast_format_drive;;
@@ -440,8 +442,10 @@ function configure_interactive_icecast {
440 442
                start_icecast;;
441 443
             10) icecast_set_stream_name;;
442 444
             11) icecast_set_maximum_streams;;
443
-            12) break;;
445
+            12) rm -f "$data"
446
+                break;;
444 447
         esac
448
+        rm -f "$data"
445 449
     done
446 450
 }
447 451
 
@@ -556,7 +560,7 @@ function remove_icecast {
556 560
     fi
557 561
     function_check remove_onion_service
558 562
     remove_onion_service icecast ${ICECAST_ONION_PORT}
559
-    sed -i '/icecast/d' $COMPLETION_FILE
563
+    sed -i '/icecast/d' "$COMPLETION_FILE"
560 564
 }
561 565
 
562 566
 function install_icecast {
@@ -572,11 +576,11 @@ function install_icecast {
572 576
         exit 7923528
573 577
     fi
574 578
 
575
-    if [ ! ${ICECAST_PASSWORD} ]; then
576
-        if [ -f ${IMAGE_PASSWORD_FILE} ]; then
577
-            ICECAST_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
579
+    if [ ! "${ICECAST_PASSWORD}" ]; then
580
+        if [ -f "${IMAGE_PASSWORD_FILE}" ]; then
581
+            ICECAST_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
578 582
         else
579
-            ICECAST_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
583
+            ICECAST_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
580 584
         fi
581 585
     fi
582 586
 
@@ -600,22 +604,22 @@ function install_icecast {
600 604
     fi
601 605
 
602 606
     icecast_nginx_site=/etc/nginx/sites-available/icecast
603
-    echo 'server {' > $icecast_nginx_site
604
-    echo "    listen 127.0.0.1:$ICECAST_ONION_PORT default_server;" >> $icecast_nginx_site
605
-    echo "    server_name $ICECAST_ONION_HOSTNAME;" >> $icecast_nginx_site
606
-    echo '' >> $icecast_nginx_site
607
-    echo '  # Logs' >> $icecast_nginx_site
608
-    echo '  access_log /dev/null;' >> $icecast_nginx_site
609
-    echo '  error_log /dev/null;' >> $icecast_nginx_site
610
-    echo '' >> $icecast_nginx_site
611
-    echo '  location / {' >> $icecast_nginx_site
607
+    { echo 'server {';
608
+      echo "    listen 127.0.0.1:$ICECAST_ONION_PORT default_server;";
609
+      echo "    server_name $ICECAST_ONION_HOSTNAME;";
610
+      echo '';
611
+      echo '  # Logs';
612
+      echo '  access_log /dev/null;';
613
+      echo '  error_log /dev/null;';
614
+      echo '';
615
+      echo '  location / {'; } > $icecast_nginx_site
612 616
     function_check nginx_limits
613
-    nginx_limits $ICECAST_ONION_HOSTNAME '15m'
614
-    echo "      proxy_pass http://localhost:$ICECAST_PORT;" >> $icecast_nginx_site
615
-    echo "      #auth_basic \"${ICECAST_LOGIN_TEXT}\";" >> $icecast_nginx_site
616
-    echo '      #auth_basic_user_file /etc/nginx/.icepasswd;' >> $icecast_nginx_site
617
-    echo '  }' >> $icecast_nginx_site
618
-    echo '}' >> $icecast_nginx_site
617
+    nginx_limits "$ICECAST_ONION_HOSTNAME" '15m'
618
+    { echo "      proxy_pass http://localhost:$ICECAST_PORT;";
619
+      echo "      #auth_basic \"${ICECAST_LOGIN_TEXT}\";";
620
+      echo '      #auth_basic_user_file /etc/nginx/.icepasswd;';
621
+      echo '  }';
622
+      echo '}'; } >> $icecast_nginx_site
619 623
 
620 624
     if [ ! -d /var/log/ices ]; then
621 625
         mkdir -p /var/log/ices
@@ -624,105 +628,105 @@ function install_icecast {
624 628
         mkdir -p /etc/ices2
625 629
     fi
626 630
 
627
-    echo '<?xml version="1.0"?>' > /etc/ices2/ices-playlist.xml
628
-    echo '<ices>' >> /etc/ices2/ices-playlist.xml
629
-    echo '    <!-- run in background -->' >> /etc/ices2/ices-playlist.xml
630
-    echo '    <background>1</background>' >> /etc/ices2/ices-playlist.xml
631
-    echo '    <!-- where logs, etc go. -->' >> /etc/ices2/ices-playlist.xml
632
-    echo '    <logpath>/var/log/ices</logpath>' >> /etc/ices2/ices-playlist.xml
633
-    echo '    <logfile>ices.log</logfile>' >> /etc/ices2/ices-playlist.xml
634
-    echo '    <!-- 1=error,2=warn,3=info,4=debug -->' >> /etc/ices2/ices-playlist.xml
635
-    echo '    <loglevel>1</loglevel>' >> /etc/ices2/ices-playlist.xml
636
-    echo '    <!-- set this to 1 to log to the console instead of to the file above -->' >> /etc/ices2/ices-playlist.xml
637
-    echo '    <consolelog>0</consolelog>' >> /etc/ices2/ices-playlist.xml
638
-    echo '' >> /etc/ices2/ices-playlist.xml
639
-    echo '    <!-- optional filename to write process id to -->' >> /etc/ices2/ices-playlist.xml
640
-    echo '    <!-- <pidfile>/home/ices/ices.pid</pidfile> -->' >> /etc/ices2/ices-playlist.xml
641
-    echo '' >> /etc/ices2/ices-playlist.xml
642
-    echo '    <stream>' >> /etc/ices2/ices-playlist.xml
643
-    echo '        <!-- metadata used for stream listing (not currently used) -->' >> /etc/ices2/ices-playlist.xml
644
-    echo '        <metadata>' >> /etc/ices2/ices-playlist.xml
645
-    echo '            <name>Example stream name</name>' >> /etc/ices2/ices-playlist.xml
646
-    echo '            <genre>Example genre</genre>' >> /etc/ices2/ices-playlist.xml
647
-    echo '            <description>A short description of your stream</description>' >> /etc/ices2/ices-playlist.xml
648
-    echo '        </metadata>' >> /etc/ices2/ices-playlist.xml
649
-    echo '' >> /etc/ices2/ices-playlist.xml
650
-    echo '        <!-- input module' >> /etc/ices2/ices-playlist.xml
651
-    echo '' >> /etc/ices2/ices-playlist.xml
652
-    echo '            The module used here is the playlist module - it has ' >> /etc/ices2/ices-playlist.xml
653
-    echo '            "submodules" for different types of playlist. There are' >> /etc/ices2/ices-playlist.xml
654
-    echo '            two currently implemented, "basic", which is a simple' >> /etc/ices2/ices-playlist.xml
655
-    echo '            file-based playlist, and "script" which invokes a command' >> /etc/ices2/ices-playlist.xml
656
-    echo '            to returns a filename to start playing. -->' >> /etc/ices2/ices-playlist.xml
657
-    echo '' >> /etc/ices2/ices-playlist.xml
658
-    echo '        <input>' >> /etc/ices2/ices-playlist.xml
659
-    echo '            <module>playlist</module>' >> /etc/ices2/ices-playlist.xml
660
-    echo '            <param name="type">basic</param>' >> /etc/ices2/ices-playlist.xml
661
-    echo "            <param name=\"file\">$ICECAST_PLAYLIST_FILE</param>" >> /etc/ices2/ices-playlist.xml
662
-    echo '            <!-- random play -->' >> /etc/ices2/ices-playlist.xml
663
-    echo '            <param name="random">0</param>' >> /etc/ices2/ices-playlist.xml
664
-    echo '            <!-- if the playlist get updated that start at the beginning -->' >> /etc/ices2/ices-playlist.xml
665
-    echo '            <param name="restart-after-reread">0</param>' >> /etc/ices2/ices-playlist.xml
666
-    echo '            <!-- if set to 1 , plays once through, then exits. -->' >> /etc/ices2/ices-playlist.xml
667
-    echo '            <param name="once">0</param>' >> /etc/ices2/ices-playlist.xml
668
-    echo '        </input>' >> /etc/ices2/ices-playlist.xml
669
-    echo '' >> /etc/ices2/ices-playlist.xml
670
-    echo '            <!-- Stream instance' >> /etc/ices2/ices-playlist.xml
671
-    echo '            You may have one or more instances here. This allows you to ' >> /etc/ices2/ices-playlist.xml
672
-    echo '            send the same input data to one or more servers (or to different' >> /etc/ices2/ices-playlist.xml
673
-    echo '            mountpoints on the same server). Each of them can have different' >> /etc/ices2/ices-playlist.xml
674
-    echo '            parameters. This is primarily useful for a) relaying to multiple' >> /etc/ices2/ices-playlist.xml
675
-    echo '            independent servers, and b) encoding/reencoding to multiple' >> /etc/ices2/ices-playlist.xml
676
-    echo '            bitrates.' >> /etc/ices2/ices-playlist.xml
677
-    echo '            If one instance fails (for example, the associated server goes' >> /etc/ices2/ices-playlist.xml
678
-    echo '            down, etc), the others will continue to function correctly.' >> /etc/ices2/ices-playlist.xml
679
-    echo '            This example defines two instances as two mountpoints on the' >> /etc/ices2/ices-playlist.xml
680
-    echo '            same server.  -->' >> /etc/ices2/ices-playlist.xml
681
-    echo '        <instance>' >> /etc/ices2/ices-playlist.xml
682
-    echo '            <!-- Server details:' >> /etc/ices2/ices-playlist.xml
683
-    echo '                You define hostname and port for the server here, along with' >> /etc/ices2/ices-playlist.xml
684
-    echo '                the source password and mountpoint.  -->' >> /etc/ices2/ices-playlist.xml
685
-    echo '            <hostname>localhost</hostname>' >> /etc/ices2/ices-playlist.xml
686
-    echo "            <port>$ICECAST_PORT</port>" >> /etc/ices2/ices-playlist.xml
687
-    echo "            <password>$ICECAST_PASSWORD</password>" >> /etc/ices2/ices-playlist.xml
688
-    echo '            <mount>/example1.ogg</mount>' >> /etc/ices2/ices-playlist.xml
689
-    echo '            <!-- Reconnect parameters:' >> /etc/ices2/ices-playlist.xml
690
-    echo '                When something goes wrong (e.g. the server crashes, or the' >> /etc/ices2/ices-playlist.xml
691
-    echo '                network drops) and ices disconnects from the server, these' >> /etc/ices2/ices-playlist.xml
692
-    echo '                control how often it tries to reconnect, and how many times' >> /etc/ices2/ices-playlist.xml
693
-    echo '                it tries to reconnect. Delay is in seconds.' >> /etc/ices2/ices-playlist.xml
694
-    echo '                If you set reconnectattempts to -1, it will continue ' >> /etc/ices2/ices-playlist.xml
695
-    echo '                indefinately. Suggest setting reconnectdelay to a large value' >> /etc/ices2/ices-playlist.xml
696
-    echo '                if you do this.' >> /etc/ices2/ices-playlist.xml
697
-    echo '            -->' >> /etc/ices2/ices-playlist.xml
698
-    echo '            <reconnectdelay>2</reconnectdelay>' >> /etc/ices2/ices-playlist.xml
699
-    echo '            <reconnectattempts>5</reconnectattempts> ' >> /etc/ices2/ices-playlist.xml
700
-    echo '' >> /etc/ices2/ices-playlist.xml
701
-    echo '            <!-- maxqueuelength:' >> /etc/ices2/ices-playlist.xml
702
-    echo '                This describes how long the internal data queues may be. This' >> /etc/ices2/ices-playlist.xml
703
-    echo '                basically lets you control how much data gets buffered before' >> /etc/ices2/ices-playlist.xml
704
-    echo '                ices decides it cant send to the server fast enough, and ' >> /etc/ices2/ices-playlist.xml
705
-    echo '                either shuts down or flushes the queue (dropping the data)' >> /etc/ices2/ices-playlist.xml
706
-    echo '                and continues. ' >> /etc/ices2/ices-playlist.xml
707
-    echo '                For advanced users only.' >> /etc/ices2/ices-playlist.xml
708
-    echo '            -->' >> /etc/ices2/ices-playlist.xml
709
-    echo '            <maxqueuelength>80</maxqueuelength>' >> /etc/ices2/ices-playlist.xml
710
-    echo '' >> /etc/ices2/ices-playlist.xml
711
-    echo '            <!-- Live encoding/reencoding:' >> /etc/ices2/ices-playlist.xml
712
-    echo '                Currrently, the parameters given here for encoding MUST' >> /etc/ices2/ices-playlist.xml
713
-    echo '                match the input data for channels and sample rate. That ' >> /etc/ices2/ices-playlist.xml
714
-    echo '                restriction will be relaxed in the future.' >> /etc/ices2/ices-playlist.xml
715
-    echo '                Remove this section if you dont want your files getting reencoded.' >> /etc/ices2/ices-playlist.xml
716
-    echo '            -->' >> /etc/ices2/ices-playlist.xml
717
-    echo '            <encode>  ' >> /etc/ices2/ices-playlist.xml
718
-    echo '                <nominal-bitrate>64000</nominal-bitrate>' >> /etc/ices2/ices-playlist.xml
719
-    echo '                <samplerate>22050</samplerate>' >> /etc/ices2/ices-playlist.xml
720
-    echo '                <channels>1</channels>' >> /etc/ices2/ices-playlist.xml
721
-    echo '            </encode>' >> /etc/ices2/ices-playlist.xml
722
-    echo '        </instance>' >> /etc/ices2/ices-playlist.xml
723
-    echo '' >> /etc/ices2/ices-playlist.xml
724
-    echo '        </stream>' >> /etc/ices2/ices-playlist.xml
725
-    echo '</ices>' >> /etc/ices2/ices-playlist.xml
631
+    { echo '<?xml version="1.0"?>';
632
+      echo '<ices>';
633
+      echo '    <!-- run in background -->';
634
+      echo '    <background>1</background>';
635
+      echo '    <!-- where logs, etc go. -->';
636
+      echo '    <logpath>/var/log/ices</logpath>';
637
+      echo '    <logfile>ices.log</logfile>';
638
+      echo '    <!-- 1=error,2=warn,3=info,4=debug -->';
639
+      echo '    <loglevel>1</loglevel>';
640
+      echo '    <!-- set this to 1 to log to the console instead of to the file above -->';
641
+      echo '    <consolelog>0</consolelog>';
642
+      echo '';
643
+      echo '    <!-- optional filename to write process id to -->';
644
+      echo '    <!-- <pidfile>/home/ices/ices.pid</pidfile> -->';
645
+      echo '';
646
+      echo '    <stream>';
647
+      echo '        <!-- metadata used for stream listing (not currently used) -->';
648
+      echo '        <metadata>';
649
+      echo '            <name>Example stream name</name>';
650
+      echo '            <genre>Example genre</genre>';
651
+      echo '            <description>A short description of your stream</description>';
652
+      echo '        </metadata>';
653
+      echo '';
654
+      echo '        <!-- input module';
655
+      echo '';
656
+      echo '            The module used here is the playlist module - it has ';
657
+      echo '            "submodules" for different types of playlist. There are';
658
+      echo '            two currently implemented, "basic", which is a simple';
659
+      echo '            file-based playlist, and "script" which invokes a command';
660
+      echo '            to returns a filename to start playing. -->';
661
+      echo '';
662
+      echo '        <input>';
663
+      echo '            <module>playlist</module>';
664
+      echo '            <param name="type">basic</param>';
665
+      echo "            <param name=\"file\">$ICECAST_PLAYLIST_FILE</param>";
666
+      echo '            <!-- random play -->';
667
+      echo '            <param name="random">0</param>';
668
+      echo '            <!-- if the playlist get updated that start at the beginning -->';
669
+      echo '            <param name="restart-after-reread">0</param>';
670
+      echo '            <!-- if set to 1 , plays once through, then exits. -->';
671
+      echo '            <param name="once">0</param>';
672
+      echo '        </input>';
673
+      echo '';
674
+      echo '            <!-- Stream instance';
675
+      echo '            You may have one or more instances here. This allows you to ';
676
+      echo '            send the same input data to one or more servers (or to different';
677
+      echo '            mountpoints on the same server). Each of them can have different';
678
+      echo '            parameters. This is primarily useful for a) relaying to multiple';
679
+      echo '            independent servers, and b) encoding/reencoding to multiple';
680
+      echo '            bitrates.';
681
+      echo '            If one instance fails (for example, the associated server goes';
682
+      echo '            down, etc), the others will continue to function correctly.';
683
+      echo '            This example defines two instances as two mountpoints on the';
684
+      echo '            same server.  -->';
685
+      echo '        <instance>';
686
+      echo '            <!-- Server details:';
687
+      echo '                You define hostname and port for the server here, along with';
688
+      echo '                the source password and mountpoint.  -->';
689
+      echo '            <hostname>localhost</hostname>';
690
+      echo "            <port>$ICECAST_PORT</port>";
691
+      echo "            <password>$ICECAST_PASSWORD</password>";
692
+      echo '            <mount>/example1.ogg</mount>';
693
+      echo '            <!-- Reconnect parameters:';
694
+      echo '                When something goes wrong (e.g. the server crashes, or the';
695
+      echo '                network drops) and ices disconnects from the server, these';
696
+      echo '                control how often it tries to reconnect, and how many times';
697
+      echo '                it tries to reconnect. Delay is in seconds.';
698
+      echo '                If you set reconnectattempts to -1, it will continue ';
699
+      echo '                indefinately. Suggest setting reconnectdelay to a large value';
700
+      echo '                if you do this.';
701
+      echo '            -->';
702
+      echo '            <reconnectdelay>2</reconnectdelay>';
703
+      echo '            <reconnectattempts>5</reconnectattempts> ';
704
+      echo '';
705
+      echo '            <!-- maxqueuelength:';
706
+      echo '                This describes how long the internal data queues may be. This';
707
+      echo '                basically lets you control how much data gets buffered before';
708
+      echo '                ices decides it cant send to the server fast enough, and ';
709
+      echo '                either shuts down or flushes the queue (dropping the data)';
710
+      echo '                and continues. ';
711
+      echo '                For advanced users only.';
712
+      echo '            -->';
713
+      echo '            <maxqueuelength>80</maxqueuelength>';
714
+      echo '';
715
+      echo '            <!-- Live encoding/reencoding:';
716
+      echo '                Currrently, the parameters given here for encoding MUST';
717
+      echo '                match the input data for channels and sample rate. That ';
718
+      echo '                restriction will be relaxed in the future.';
719
+      echo '                Remove this section if you dont want your files getting reencoded.';
720
+      echo '            -->';
721
+      echo '            <encode>  ';
722
+      echo '                <nominal-bitrate>64000</nominal-bitrate>';
723
+      echo '                <samplerate>22050</samplerate>';
724
+      echo '                <channels>1</channels>';
725
+      echo '            </encode>';
726
+      echo '        </instance>';
727
+      echo '';
728
+      echo '        </stream>';
729
+      echo '</ices>'; } > /etc/ices2/ices-playlist.xml
726 730
 
727 731
     sed -i 's|ENABLE=.*|ENABLE=true|g' /etc/default/icecast2
728 732
 
@@ -733,18 +737,18 @@ function install_icecast {
733 737
 
734 738
 
735 739
     # create a password for users
736
-    ICECAST_USER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
740
+    ICECAST_USER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
737 741
     if grep -q "$MY_USERNAME:" /etc/nginx/.icepasswd; then
738 742
         sed -i "/$MY_USERNAME:/d" /etc/nginx/.icepasswd
739 743
     fi
740
-    echo "$ICECAST_USER_PASSWORD" | htpasswd -i -s -c /etc/nginx/.icepasswd $MY_USERNAME
744
+    echo "$ICECAST_USER_PASSWORD" | htpasswd -i -s -c /etc/nginx/.icepasswd "$MY_USERNAME"
741 745
     if [ ! -f /etc/nginx/.icepasswd ]; then
742 746
         echo $'/etc/nginx/.icepasswd not found'
743 747
         exit 73528235
744 748
     fi
745 749
 
746
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a icecast -p "$ICECAST_PASSWORD"
747
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a icecastuser -p "$ICECAST_USER_PASSWORD"
750
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecast -p "$ICECAST_PASSWORD"
751
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a icecastuser -p "$ICECAST_USER_PASSWORD"
748 752
 
749 753
     groupadd icecast
750 754
     useradd -c "Icecast system account" -d /etc/icecast2 -m -r -g icecast icecast2

+ 153
- 153
src/freedombone-app-ipfs Просмотреть файл

@@ -76,7 +76,7 @@ function upgrade_ipfs_go {
76 76
     fi
77 77
 
78 78
     function_check set_repo_commit
79
-    set_repo_commit $GOPATH/src/github.com/ipfs/go-ipfs "ipfs commit" "$IPFS_COMMIT" $IPFS_REPO
79
+    set_repo_commit "$GOPATH/src/github.com/ipfs/go-ipfs" "ipfs commit" "$IPFS_COMMIT" "$IPFS_REPO"
80 80
 }
81 81
 
82 82
 function upgrade_ipfs_js {
@@ -97,33 +97,34 @@ function upgrade_ipfs {
97 97
 }
98 98
 
99 99
 function backup_local_ipfs {
100
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
100
+    if ! grep -q "Admin user" "$COMPLETION_FILE"; then
101 101
         return
102 102
     fi
103 103
     ADMIN_USERNAME=$(get_completion_param "Admin user")
104
-    source_directory=/home/$ADMIN_USERNAME/.ipfs
105
-    if [ -d $source_directory ]; then
104
+    source_directory="/home/$ADMIN_USERNAME/.ipfs"
105
+    if [ -d "$source_directory" ]; then
106 106
         dest_directory=ipfs
107 107
         function_check backup_directory_to_usb
108
-        backup_directory_to_usb $source_directory $dest_directory
108
+        backup_directory_to_usb "$source_directory" "$dest_directory"
109 109
     fi
110 110
 }
111 111
 
112 112
 function restore_local_ipfs {
113
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
113
+    if ! grep -q "Admin user" "$COMPLETION_FILE"; then
114 114
         return
115 115
     fi
116
-    if [ -d $USB_MOUNT/backup/ipfs ]; then
116
+    if [ -d "$USB_MOUNT/backup/ipfs" ]; then
117 117
         echo $"Restoring IPFS"
118 118
         temp_restore_dir=/root/tempipfs
119 119
         function_check restore_directory_from_usb
120 120
         restore_directory_from_usb $temp_restore_dir ipfs
121 121
         ADMIN_USERNAME=$(get_completion_param "Admin user")
122
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs ]; then
123
-            cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
122
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs" ]; then
123
+            cp -rf "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/*" "/home/$ADMIN_USERNAME/.ipfs"
124 124
         else
125
-            cp -rf $temp_restore_dir/* /home/$ADMIN_USERNAME/.ipfs
125
+            cp -rf "$temp_restore_dir/*" "/home/$ADMIN_USERNAME/.ipfs"
126 126
         fi
127
+        # shellcheck disable=SC2181
127 128
         if [ ! "$?" = "0" ]; then
128 129
             rm -rf $temp_restore_dir
129 130
             function_check set_user_permissions
@@ -138,28 +139,29 @@ function restore_local_ipfs {
138 139
 }
139 140
 
140 141
 function backup_remote_ipfs {
141
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
142
+    if ! grep -q "Admin user" "$COMPLETION_FILE"; then
142 143
         return
143 144
     fi
144 145
     ADMIN_USERNAME=$(get_completion_param "Admin user")
145
-    if [ -d /home/$ADMIN_USERNAME/.ipfs ]; then
146
+    if [ -d "/home/$ADMIN_USERNAME/.ipfs" ]; then
146 147
         echo $"Backing up IPFS"
147
-        backup_directory_to_friend /home/$ADMIN_USERNAME/.ipfs ipfs
148
+        backup_directory_to_friend "/home/$ADMIN_USERNAME/.ipfs" ipfs
148 149
         echo $"Backup of IPFS complete"
149 150
     fi
150 151
 }
151 152
 
152 153
 function restore_remote_ipfs {
153
-    if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
154
+    if [ -d "$SERVER_DIRECTORY/backup/ipfs" ]; then
154 155
         echo $"Restoring IPFS"
155 156
         temp_restore_dir=/root/tempipfs
156 157
         function_check restore_directory_from_friend
157 158
         restore_directory_from_friend $temp_restore_dir ipfs
158
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs ]; then
159
-            cp -rf $temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/* /home/$ADMIN_USERNAME/.ipfs
159
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs" ]; then
160
+            cp -rf "$temp_restore_dir/home/$ADMIN_USERNAME/.ipfs/*" "/home/$ADMIN_USERNAME/.ipfs"
160 161
         else
161
-            cp -rf $temp_restore_dir/* /home/$ADMIN_USERNAME/.ipfs
162
+            cp -rf "$temp_restore_dir/*" "/home/$ADMIN_USERNAME/.ipfs"
162 163
         fi
164
+        # shellcheck disable=SC2181
163 165
         if [ ! "$?" = "0" ]; then
164 166
             function_check set_user_permissions
165 167
             set_user_permissions
@@ -177,11 +179,11 @@ function remove_ipfs_go {
177 179
     systemctl daemon-reload
178 180
     rm /etc/systemd/system/ipfs.service
179 181
     systemctl daemon-reload
180
-    rm -rf $GOPATH/src/github.com/ipfs
182
+    rm -rf "$GOPATH/src/github.com/ipfs"
181 183
     firewall_remove $IPFS_PORT tcp
182 184
     remove_completion_param install_ipfs
183 185
     remove_completion_param configure_firewall_for_ipfs
184
-    sed -i '/ipfs/d' $COMPLETION_FILE
186
+    sed -i '/ipfs/d' "$COMPLETION_FILE"
185 187
 }
186 188
 
187 189
 function remove_ipfs_js {
@@ -194,9 +196,9 @@ function remove_ipfs_js {
194 196
     npm uninstall ronin --global
195 197
 
196 198
     firewall_remove $IPFS_PORT tcp
197
-    sed -i '/install_ipfs/d' $COMPLETION_FILE
198
-    sed -i '/ipfs/d' $COMPLETION_FILE
199
-    sed -i '/configure_firewall_for_ipfs/d' $COMPLETION_FILE
199
+    sed -i '/install_ipfs/d' "$COMPLETION_FILE"
200
+    sed -i '/ipfs/d' "$COMPLETION_FILE"
201
+    sed -i '/configure_firewall_for_ipfs/d' "$COMPLETION_FILE"
200 202
 }
201 203
 
202 204
 function remove_ipfs {
@@ -205,7 +207,7 @@ function remove_ipfs {
205 207
 }
206 208
 
207 209
 function configure_firewall_for_ipfs {
208
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
210
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
209 211
         return
210 212
     fi
211 213
     if [[ $ONION_ONLY != "no" ]]; then
@@ -213,22 +215,23 @@ function configure_firewall_for_ipfs {
213 215
     fi
214 216
 
215 217
     firewall_add IPFS $IPFS_PORT tcp
216
-    mark_completed $FUNCNAME
218
+    mark_completed "${FUNCNAME[0]}"
217 219
 }
218 220
 
219 221
 function mesh_install_ipfs_js {
220
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
222
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
221 223
         return
222 224
     fi
223 225
 
224
-    chroot ${rootdir} apt-get -yq install libpam0g-dev fuse
226
+    # shellcheck disable=SC2154
227
+    chroot "${rootdir}" apt-get -yq install libpam0g-dev fuse
225 228
 
226
-    if [ ! -f ${rootdir}/usr/bin/nodejs ]; then
229
+    if [ ! -f "${rootdir}/usr/bin/nodejs" ]; then
227 230
         echo $'nodejs was not installed'
228 231
         exit 63962
229 232
     fi
230 233
 
231
-    cat <<EOF > ${rootdir}/root/install-ipfs.sh
234
+    cat <<EOF > "${rootdir}/root/install-ipfs.sh"
232 235
 #!/bin/bash
233 236
 PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
234 237
 NODE_PATH="/usr/lib/node_modules"
@@ -241,57 +244,57 @@ npm install -g ronin@${IPFS_JS_RONIN_VERSION} --save
241 244
 npm install -g ipfs@${IPFS_JS_VERSION} --save
242 245
 exit 0
243 246
 EOF
244
-    chroot ${rootdir} /bin/chmod +x /root/install-ipfs.sh
245
-    chroot ${rootdir} /root/install-ipfs.sh
246
-    rm -f ${rootdir}/root/install-ipfs.sh
247
+    chroot "${rootdir}" /bin/chmod +x /root/install-ipfs.sh
248
+    chroot "${rootdir}" /root/install-ipfs.sh
249
+    rm -f "${rootdir}/root/install-ipfs.sh"
247 250
 
248 251
     IPFS_PATH=/usr/bin
249 252
 
250
-    if [ ! -f ${rootdir}$IPFS_PATH/jsipfs ]; then
253
+    if [ ! -f "${rootdir}$IPFS_PATH/jsipfs" ]; then
251 254
         exit 637292
252 255
     fi
253 256
 
254 257
     # directories to mount to
255
-    if [ ! -d ${rootdir}/ipfs ]; then
256
-        chroot ${rootdir} /bin/mkdir /ipfs
257
-        chroot ${rootdir} /bin/mkdir /ipns
258
-        chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipfs
259
-        chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /ipns
258
+    if [ ! -d "${rootdir}/ipfs" ]; then
259
+        chroot "${rootdir}" /bin/mkdir /ipfs
260
+        chroot "${rootdir}" /bin/mkdir /ipns
261
+        chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /ipfs
262
+        chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /ipns
260 263
     fi
261 264
 
262
-    if [ -f ${rootdir}/etc/fuse.conf ]; then
263
-        chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
265
+    if [ -f "${rootdir}/etc/fuse.conf" ]; then
266
+        chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /etc/fuse.conf
264 267
     fi
265
-    if [ -f ${rootdir}/dev/fuse ]; then
266
-        chroot ${rootdir} /bin/chown $MY_USERNAME:$MY_USERNAME /dev/fuse
268
+    if [ -f "${rootdir}/dev/fuse" ]; then
269
+        chroot "${rootdir}" /bin/chown "$MY_USERNAME":"$MY_USERNAME" /dev/fuse
267 270
     fi
268 271
 
269 272
     IPFS_DAEMON_NAME=ipfs
270 273
     IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
271
-    echo '[Unit]' > $IPFS_DAEMON_FILE
272
-    echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
273
-    echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
274
-    echo 'After=network.target' >> $IPFS_DAEMON_FILE
275
-    echo '' >> $IPFS_DAEMON_FILE
276
-    echo '[Service]' >> $IPFS_DAEMON_FILE
277
-    echo 'Type=simple' >> $IPFS_DAEMON_FILE
278
-    echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
279
-    echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
280
-    echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
281
-    echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
282
-    echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
283
-    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
284
-    echo '' >> $IPFS_DAEMON_FILE
285
-    echo '[Install]' >> $IPFS_DAEMON_FILE
286
-    echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
287
-
288
-    chroot ${rootdir} systemctl enable ${IPFS_DAEMON_NAME}
289
-
290
-    mark_completed $FUNCNAME
274
+    { echo '[Unit]';
275
+      echo 'Description=IPFS javascript daemon';
276
+      echo 'After=syslog.target';
277
+      echo 'After=network.target';
278
+      echo '';
279
+      echo '[Service]';
280
+      echo 'Type=simple';
281
+      echo "User=$MY_USERNAME";
282
+      echo "Group=$MY_USERNAME";
283
+      echo "WorkingDirectory=/home/$MY_USERNAME";
284
+      echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount";
285
+      echo 'Restart=on-failure';
286
+      echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"";
287
+      echo '';
288
+      echo '[Install]';
289
+      echo 'WantedBy=multi-user.target'; } > "$IPFS_DAEMON_FILE"
290
+
291
+    chroot "${rootdir}" systemctl enable ${IPFS_DAEMON_NAME}
292
+
293
+    mark_completed "${FUNCNAME[0]}"
291 294
 }
292 295
 
293 296
 function install_ipfs_js {
294
-    if [ $INSTALLING_MESH ]; then
297
+    if [ "$INSTALLING_MESH" ]; then
295 298
         mesh_install_ipfs_js
296 299
         return
297 300
     fi
@@ -321,8 +324,8 @@ function install_ipfs_js {
321 324
     fi
322 325
 
323 326
     # initialise
324
-    su -c "$IPFS_PATH/jsipfs init -b $IPFS_KEY_LENGTH" - $MY_USERNAME
325
-    if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
327
+    su -c "$IPFS_PATH/jsipfs init -b $IPFS_KEY_LENGTH" - "$MY_USERNAME"
328
+    if [ ! -d "/home/$MY_USERNAME/.ipfs" ]; then
326 329
         echo "IPFS could not be initialised for user $MY_USERNAME"
327 330
         exit 7358
328 331
     fi
@@ -331,42 +334,42 @@ function install_ipfs_js {
331 334
     if [ ! -d /ipfs ]; then
332 335
         mkdir /ipfs
333 336
         mkdir /ipns
334
-        chown $MY_USERNAME:$MY_USERNAME /ipfs
335
-        chown $MY_USERNAME:$MY_USERNAME /ipns
337
+        chown "$MY_USERNAME":"$MY_USERNAME" /ipfs
338
+        chown "$MY_USERNAME":"$MY_USERNAME" /ipns
336 339
     fi
337 340
 
338 341
     if [ -f /etc/fuse.conf ]; then
339
-        chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
342
+        chown "$MY_USERNAME":"$MY_USERNAME" /etc/fuse.conf
340 343
     fi
341 344
     if [ -f /dev/fuse ]; then
342
-        chown $MY_USERNAME:$MY_USERNAME /dev/fuse
345
+        chown "$MY_USERNAME":"$MY_USERNAME" /dev/fuse
343 346
     fi
344 347
 
345 348
     IPFS_DAEMON_NAME=ipfs
346 349
     IPFS_DAEMON_FILE=/etc/systemd/system/${IPFS_DAEMON_NAME}.service
347
-    echo '[Unit]' > $IPFS_DAEMON_FILE
348
-    echo 'Description=IPFS javascript daemon' >> $IPFS_DAEMON_FILE
349
-    echo 'After=syslog.target' >> $IPFS_DAEMON_FILE
350
-    echo 'After=network.target' >> $IPFS_DAEMON_FILE
351
-    echo '' >> $IPFS_DAEMON_FILE
352
-    echo '[Service]' >> $IPFS_DAEMON_FILE
353
-    echo 'Type=simple' >> $IPFS_DAEMON_FILE
354
-    echo "User=$MY_USERNAME" >> $IPFS_DAEMON_FILE
355
-    echo "Group=$MY_USERNAME" >> $IPFS_DAEMON_FILE
356
-    echo "WorkingDirectory=/home/$MY_USERNAME" >> $IPFS_DAEMON_FILE
357
-    echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount" >> $IPFS_DAEMON_FILE
358
-    echo 'Restart=on-failure' >> $IPFS_DAEMON_FILE
359
-    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"" >> $IPFS_DAEMON_FILE
360
-    echo '' >> $IPFS_DAEMON_FILE
361
-    echo '[Install]' >> $IPFS_DAEMON_FILE
362
-    echo 'WantedBy=multi-user.target' >> $IPFS_DAEMON_FILE
350
+    { echo '[Unit]';
351
+      echo 'Description=IPFS javascript daemon';
352
+      echo 'After=syslog.target';
353
+      echo 'After=network.target';
354
+      echo '';
355
+      echo '[Service]';
356
+      echo 'Type=simple';
357
+      echo "User=$MY_USERNAME";
358
+      echo "Group=$MY_USERNAME";
359
+      echo "WorkingDirectory=/home/$MY_USERNAME";
360
+      echo "ExecStart=${IPFS_PATH}/jsipfs daemon --mount";
361
+      echo 'Restart=on-failure';
362
+      echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\"";
363
+      echo '';
364
+      echo '[Install]';
365
+      echo 'WantedBy=multi-user.target'; } > $IPFS_DAEMON_FILE
363 366
 
364 367
     systemctl enable ${IPFS_DAEMON_NAME}
365 368
     systemctl daemon-reload
366 369
     systemctl restart ${IPFS_DAEMON_NAME}
367 370
 
368 371
     if [ -d /etc/avahi ]; then
369
-        su -c "echo $($IPFS_PATH/jsipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
372
+        su -c "echo $($IPFS_PATH/jsipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - "$MY_USERNAME"
370 373
         if [ ! -f /tmp/ipfsid ]; then
371 374
             echo 'No IPFS identity was created'
372 375
             exit 37895
@@ -387,17 +390,17 @@ function install_ipfs_js {
387 390
 }
388 391
 
389 392
 function mesh_install_ipfs_go {
390
-    chroot ${rootdir} apt-get -yq install libpam0g-dev fuse wget
393
+    chroot "${rootdir}" apt-get -yq install libpam0g-dev fuse wget
391 394
 
392 395
     mesh_upgrade_golang
393 396
 
394 397
     IPFS_ARCH=
395 398
     IPFS_PATH=/usr/bin
396 399
 
397
-    if [ ! -d $rootdir$INSTALL_DIR/ipfs ]; then
398
-        mkdir -p $rootdir$INSTALL_DIR/ipfs
400
+    if [ ! -d "$rootdir$INSTALL_DIR/ipfs" ]; then
401
+        mkdir -p "$rootdir$INSTALL_DIR/ipfs"
399 402
     fi
400
-    cd $rootdir$INSTALL_DIR/ipfs
403
+    cd "$rootdir$INSTALL_DIR/ipfs" || exit 23468264
401 404
 
402 405
     if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
403 406
         IPFS_ARCH=386
@@ -431,42 +434,42 @@ function mesh_install_ipfs_go {
431 434
 
432 435
     IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz
433 436
     wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v${IPFS_GO_VERSION}/${IPFS_FILE}
434
-    if [ ! -f $rootdir$INSTALL_DIR/ipfs/${IPFS_FILE} ]; then
437
+    if [ ! -f "$rootdir$INSTALL_DIR/ipfs/${IPFS_FILE}" ]; then
435 438
         echo $'IPFS package could not be downloaded'
436 439
         exit 63725
437 440
     fi
438 441
     tar -xzvf ${IPFS_FILE}
439
-    if [ ! -f $rootdir$INSTALL_DIR/ipfs/go-ipfs/ipfs ]; then
442
+    if [ ! -f "$rootdir$INSTALL_DIR/ipfs/go-ipfs/ipfs" ]; then
440 443
         echo $"ipfs was not found in downloaded package"
441 444
         exit 638235
442 445
     fi
443
-    chroot "$rootdir" /bin/cp $INSTALL_DIR/ipfs/go-ipfs/ipfs $IPFS_PATH
444
-    if [ ! -f $rootdir$IPFS_PATH/ipfs ]; then
446
+    chroot "$rootdir" /bin/cp "$INSTALL_DIR/ipfs/go-ipfs/ipfs" $IPFS_PATH
447
+    if [ ! -f "$rootdir$IPFS_PATH/ipfs" ]; then
445 448
         echo $'IPFS was not installed'
446 449
         exit 63722
447 450
     fi
448 451
 
449 452
     IPFS_USER_DAEMON=${rootdir}/home/${MY_USERNAME}/.config/systemd/user/ipfs.service
450
-    mkdir -p ${rootdir}/home/${MY_USERNAME}/.config/systemd/user
451
-
452
-    echo '[Unit]' > $IPFS_USER_DAEMON
453
-    echo 'Description=IPFS go daemon' >> $IPFS_USER_DAEMON
454
-    echo 'After=syslog.target' >> $IPFS_USER_DAEMON
455
-    echo 'After=network.target' >> $IPFS_USER_DAEMON
456
-    echo '' >> $IPFS_USER_DAEMON
457
-    echo '[Service]' >> $IPFS_USER_DAEMON
458
-    echo 'Type=simple' >> $IPFS_USER_DAEMON
459
-    echo "ExecStart=$IPFS_PATH/ipfs daemon" >> $IPFS_USER_DAEMON
460
-    echo 'Restart=on-failure' >> $IPFS_USER_DAEMON
461
-    echo 'RestartSec=60' >> $IPFS_USER_DAEMON
462
-    echo '' >> $IPFS_USER_DAEMON
463
-    echo '[Install]' >> $IPFS_USER_DAEMON
464
-    echo 'WantedBy=default.target' >> $IPFS_USER_DAEMON
465
-    chroot ${rootdir} /bin/chown -R $MY_USERNAME:$MY_USERNAME /home/${MY_USERNAME}/.config
453
+    mkdir -p "${rootdir}/home/${MY_USERNAME}/.config/systemd/user"
454
+
455
+    { echo '[Unit]';
456
+      echo 'Description=IPFS go daemon';
457
+      echo 'After=syslog.target';
458
+      echo 'After=network.target';
459
+      echo '';
460
+      echo '[Service]';
461
+      echo 'Type=simple';
462
+      echo "ExecStart=$IPFS_PATH/ipfs daemon";
463
+      echo 'Restart=on-failure';
464
+      echo 'RestartSec=60';
465
+      echo '';
466
+      echo '[Install]';
467
+      echo 'WantedBy=default.target'; } > "$IPFS_USER_DAEMON"
468
+    chroot "${rootdir}" /bin/chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/${MY_USERNAME}/.config"
466 469
 }
467 470
 
468 471
 function install_ipfs_go {
469
-    if [ $INSTALLING_MESH ]; then
472
+    if [ "$INSTALLING_MESH" ]; then
470 473
         mesh_install_ipfs_go
471 474
         return
472 475
     fi
@@ -490,61 +493,58 @@ function install_ipfs_go {
490 493
         else
491 494
             sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
492 495
         fi
493
-        systemctl set-environment GOPATH=$GOPATH
496
+        systemctl set-environment GOPATH="$GOPATH"
494 497
         if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
495 498
             echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
496 499
         else
497 500
             sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
498 501
         fi
499
-        if [ ! -d $GOPATH ]; then
500
-            mkdir -p $GOPATH
502
+        if [ ! -d "$GOPATH" ]; then
503
+            mkdir -p "$GOPATH"
501 504
         fi
502 505
     fi
503 506
 
504 507
     IPFS_PATH=$GOPATH/bin
505 508
     export PATH="$GOPATH/bin:$PATH:"
506 509
     if ! grep -q 'GOPATH/bin' ~/.bashrc; then
507
-        echo 'export PATH="$GOPATH/bin:$PATH:";' >> ~/.bashrc
510
+        echo "export PATH=\"\$GOPATH/bin:\$PATH:\";" >> ~/.bashrc
508 511
     else
509 512
         sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
510 513
     fi
511 514
 
512 515
     # set gopath for the user
513
-    if ! grep -q "GOPATH=" /home/$MY_USERNAME/.bashrc; then
514
-        echo "export GOPATH=$GOPATH" >> /home/$MY_USERNAME/.bashrc
515
-        echo 'export PATH="$GOPATH/bin:$PATH:";' >> /home/$MY_USERNAME/.bashrc
516
+    if ! grep -q "GOPATH=" "/home/$MY_USERNAME/.bashrc"; then
517
+        echo "export GOPATH=$GOPATH" >> "/home/$MY_USERNAME/.bashrc"
518
+        echo "export PATH=\"\$GOPATH/bin:\$PATH:\";" >> "/home/$MY_USERNAME/.bashrc"
516 519
     else
517
-        sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" /home/$MY_USERNAME/.bashrc
520
+        sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" "/home/$MY_USERNAME/.bashrc"
518 521
     fi
519
-    chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.bashrc
522
+    chown "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.bashrc"
520 523
 
521
-    go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs
522
-    if [ ! "$?" = "0" ]; then
524
+    if ! go get -u ${IPFS_GO_REPO_BASE}/cmd/ipfs; then
523 525
         exit 8242
524 526
     fi
525 527
 
526
-    if [ ! -d $GOPATH/src/$IPFS_GO_REPO_BASE ]; then
528
+    if [ ! -d "$GOPATH/src/$IPFS_GO_REPO_BASE" ]; then
527 529
         echo $'go get failed to get ipfs'
528 530
         exit 63923
529 531
     fi
530 532
 
531
-    cd $GOPATH/src/$IPFS_GO_REPO_BASE
532
-    git checkout $IPFS_COMMIT -b $IPFS_COMMIT
533
-    if [ ! "$?" = "0" ]; then
533
+    cd "$GOPATH/src/$IPFS_GO_REPO_BASE" || exit 346824
534
+    if ! git checkout $IPFS_COMMIT -b $IPFS_COMMIT; then
534 535
         exit 735639
535 536
     fi
536 537
 
537 538
     set_completion_param "ipfs commit" "$IPFS_COMMIT"
538 539
 
539
-    make install
540
-    if [ ! "$?" = "0" ]; then
540
+    if ! make install; then
541 541
         exit 547242
542 542
     fi
543 543
 
544 544
     # initialise
545
-    chmod 755 $IPFS_PATH/ipfs
546
-    su -c "$IPFS_PATH/ipfs init -b 2048" - $MY_USERNAME
547
-    if [ ! -d /home/$MY_USERNAME/.ipfs ]; then
545
+    chmod 755 "$IPFS_PATH/ipfs"
546
+    su -c "$IPFS_PATH/ipfs init -b 2048" - "$MY_USERNAME"
547
+    if [ ! -d "/home/$MY_USERNAME/.ipfs" ]; then
548 548
         echo "IPFS could not be initialised for user $MY_USERNAME"
549 549
         exit 7358
550 550
     fi
@@ -553,40 +553,40 @@ function install_ipfs_go {
553 553
     if [ ! -d /ipfs ]; then
554 554
         mkdir /ipfs
555 555
         mkdir /ipns
556
-        chown $MY_USERNAME:$MY_USERNAME /ipfs
557
-        chown $MY_USERNAME:$MY_USERNAME /ipns
556
+        chown "$MY_USERNAME":"$MY_USERNAME" /ipfs
557
+        chown "$MY_USERNAME":"$MY_USERNAME" /ipns
558 558
     fi
559 559
 
560 560
     if [ -f /etc/fuse.conf ]; then
561
-        chown $MY_USERNAME:$MY_USERNAME /etc/fuse.conf
561
+        chown "$MY_USERNAME":"$MY_USERNAME" /etc/fuse.conf
562 562
     fi
563 563
     if [ -f /dev/fuse ]; then
564
-        chown $MY_USERNAME:$MY_USERNAME /dev/fuse
565
-    fi
566
-
567
-    echo '[Unit]' > /etc/systemd/system/ipfs.service
568
-    echo 'Description=IPFS go daemon' >> /etc/systemd/system/ipfs.service
569
-    echo 'After=syslog.target' >> /etc/systemd/system/ipfs.service
570
-    echo 'After=network.target' >> /etc/systemd/system/ipfs.service
571
-    echo '' >> /etc/systemd/system/ipfs.service
572
-    echo '[Service]' >> /etc/systemd/system/ipfs.service
573
-    echo 'Type=simple' >> /etc/systemd/system/ipfs.service
574
-    echo "User=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
575
-    echo "Group=$MY_USERNAME" >> /etc/systemd/system/ipfs.service
576
-    echo "WorkingDirectory=/home/$MY_USERNAME" >> /etc/systemd/system/ipfs.service
577
-    echo "ExecStart=$IPFS_PATH/ipfs daemon --mount" >> /etc/systemd/system/ipfs.service
578
-    echo 'Restart=on-failure' >> /etc/systemd/system/ipfs.service
579
-    echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/ipfs.service
580
-    echo '' >> /etc/systemd/system/ipfs.service
581
-    echo '[Install]' >> /etc/systemd/system/ipfs.service
582
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ipfs.service
564
+        chown "$MY_USERNAME":"$MY_USERNAME" /dev/fuse
565
+    fi
566
+
567
+    { echo '[Unit]';
568
+      echo 'Description=IPFS go daemon';
569
+      echo 'After=syslog.target';
570
+      echo 'After=network.target';
571
+      echo '';
572
+      echo '[Service]';
573
+      echo 'Type=simple';
574
+      echo "User=$MY_USERNAME";
575
+      echo "Group=$MY_USERNAME";
576
+      echo "WorkingDirectory=/home/$MY_USERNAME";
577
+      echo "ExecStart=$IPFS_PATH/ipfs daemon --mount";
578
+      echo 'Restart=on-failure';
579
+      echo "Environment=\"USER=$MY_USERNAME\" \"HOME=/home/$MY_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"";
580
+      echo '';
581
+      echo '[Install]';
582
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/ipfs.service
583 583
 
584 584
     systemctl enable ipfs
585 585
     systemctl daemon-reload
586 586
     systemctl restart ipfs
587 587
 
588 588
     if [ -d /etc/avahi ]; then
589
-        su -c "echo $($IPFS_PATH/ipfs id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - $MY_USERNAME
589
+        su -c "echo $("$IPFS_PATH/ipfs" id | grep '\"ID\":' | awk -F '\"' '{print $4}') > /tmp/ipfsid" - "$MY_USERNAME"
590 590
         if [ ! -f /tmp/ipfsid ]; then
591 591
             echo 'No IPFS identity was created'
592 592
             exit 37895

+ 209
- 204
src/freedombone-app-irc Просмотреть файл

@@ -63,7 +63,7 @@ function logging_off_irc {
63 63
 }
64 64
 
65 65
 function irc_get_global_password {
66
-    echo $(cat /etc/ngircd/ngircd.conf | grep "Password =" | head -n 1 | awk -F '=' '{print $2}')
66
+    grep "Password =" /etc/ngircd/ngircd.conf | head -n 1 | awk -F '=' '{print $2}'
67 67
 }
68 68
 
69 69
 function start_irc_bouncer {
@@ -93,70 +93,70 @@ function create_irssi_config {
93 93
         new_name="$new_username"
94 94
     fi
95 95
 
96
-    echo 'servers = (' > /home/${new_username}/.irssi/config
97
-    echo '  {' >> /home/${new_username}/.irssi/config
98
-    echo '    address = "chat.freenode.net";' >> /home/${new_username}/.irssi/config
99
-    echo '    chatnet = "Freenode";' >> /home/${new_username}/.irssi/config
100
-    echo '    port = "6667";' >> /home/${new_username}/.irssi/config
101
-    echo '    autoconnect = "no";' >> /home/${new_username}/.irssi/config
102
-    echo '  },' >> /home/${new_username}/.irssi/config
103
-    echo '  {' >> /home/${new_username}/.irssi/config
104
-    echo '    address = "irc.oftc.net";' >> /home/${new_username}/.irssi/config
105
-    echo '    chatnet = "OFTC";' >> /home/${new_username}/.irssi/config
106
-    echo '    port = "6667";' >> /home/${new_username}/.irssi/config
107
-    echo '    autoconnect = "no";' >> /home/${new_username}/.irssi/config
108
-    echo '  },' >> /home/${new_username}/.irssi/config
109
-    echo '  {' >> /home/${new_username}/.irssi/config
110
-    echo "    address = \"127.0.0.1\";" >> /home/${new_username}/.irssi/config
111
-    echo '    ssl_verify = "no";' >> /home/${new_username}/.irssi/config
96
+    { echo 'servers = (';
97
+      echo '  {';
98
+      echo '    address = "chat.freenode.net";';
99
+      echo '    chatnet = "Freenode";';
100
+      echo '    port = "6667";';
101
+      echo '    autoconnect = "no";';
102
+      echo '  },';
103
+      echo '  {';
104
+      echo '    address = "irc.oftc.net";';
105
+      echo '    chatnet = "OFTC";';
106
+      echo '    port = "6667";';
107
+      echo '    autoconnect = "no";';
108
+      echo '  },';
109
+      echo '  {';
110
+      echo "    address = \"127.0.0.1\";";
111
+      echo '    ssl_verify = "no";'; } > "/home/${new_username}/.irssi/config"
112 112
     if [[ ${ONION_ONLY} == 'no' ]]; then
113
-        echo '    use_ssl = "yes";' >> /home/${new_username}/.irssi/config
114
-        echo "    port = \"${IRC_BOUNCER_PORT}\";" >> /home/${new_username}/.irssi/config
113
+        echo '    use_ssl = "yes";' >> "/home/${new_username}/.irssi/config"
114
+        echo "    port = \"${IRC_BOUNCER_PORT}\";" >> "/home/${new_username}/.irssi/config"
115 115
     else
116
-        echo '    use_ssl = "no";' >> /home/${new_username}/.irssi/config
117
-        IRC_ONION_HOSTNAME=$(cat ${COMPLETION_FILE} | grep "irc onion domain" | head -n 1 | awk -F ':' '{print $2}')
118
-        echo "    port = \"${IRC_ONION_PORT}\";" >> /home/${new_username}/.irssi/config
119
-    fi
120
-    echo '    chatnet = "Freedombone";' >> /home/${new_username}/.irssi/config
121
-    echo '    autoconnect = "yes";' >> /home/${new_username}/.irssi/config
122
-    if [ ${IRC_PASSWORD} ]; then
123
-        echo "    password = \"${IRC_PASSWORD}\";" >> /home/${new_username}/.irssi/config
124
-    fi
125
-    echo '  }' >> /home/${new_username}/.irssi/config
126
-    echo ');' >> /home/${new_username}/.irssi/config
127
-    echo '' >> /home/${new_username}/.irssi/config
128
-    echo 'chatnets = {' >> /home/${new_username}/.irssi/config
129
-    echo '  Freedombone = {' >> /home/${new_username}/.irssi/config
130
-    echo '    type = "IRC";' >> /home/${new_username}/.irssi/config
131
-    echo '    max_kicks = "1";' >> /home/${new_username}/.irssi/config
132
-    echo '    max_msgs = "4";' >> /home/${new_username}/.irssi/config
133
-    echo '    max_whois = "1";' >> /home/${new_username}/.irssi/config
134
-    echo '  };' >> /home/${new_username}/.irssi/config
135
-    echo '  Freenode = {' >> /home/${new_username}/.irssi/config
136
-    echo '    type = "IRC";' >> /home/${new_username}/.irssi/config
137
-    echo '    max_kicks = "1";' >> /home/${new_username}/.irssi/config
138
-    echo '    max_msgs = "4";' >> /home/${new_username}/.irssi/config
139
-    echo '    max_whois = "1";' >> /home/${new_username}/.irssi/config
140
-    echo '  };' >> /home/${new_username}/.irssi/config
141
-    echo '  OFTC = {' >> /home/${new_username}/.irssi/config
142
-    echo '    type = "IRC";' >> /home/${new_username}/.irssi/config
143
-    echo '    max_kicks = "1";' >> /home/${new_username}/.irssi/config
144
-    echo '    max_msgs = "1";' >> /home/${new_username}/.irssi/config
145
-    echo '    max_whois = "1";' >> /home/${new_username}/.irssi/config
146
-    echo '  };' >> /home/${new_username}/.irssi/config
147
-    echo '};' >> /home/${new_username}/.irssi/config
148
-    echo '' >> /home/${new_username}/.irssi/config
149
-    echo 'channels = (' >> /home/${new_username}/.irssi/config
150
-    echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },' >> /home/${new_username}/.irssi/config
151
-    echo ');' >> /home/${new_username}/.irssi/config
152
-    echo '' >> /home/${new_username}/.irssi/config
153
-    echo 'settings = {' >> /home/${new_username}/.irssi/config
154
-    echo "  core = { real_name = \"$new_name\"; user_name = \"$new_username\"; nick = \"$new_username\"; };" >> /home/${new_username}/.irssi/config
155
-    echo '  "fe-text" = { actlist_sort = "refnum"; };' >> /home/${new_username}/.irssi/config
156
-    echo '};' >> /home/${new_username}/.irssi/config
157
-    echo 'ignores = ( { level = "CTCPS"; } );' >> /home/${new_username}/.irssi/config
158
-
159
-    chown -R ${new_username}:${new_username} /home/${new_username}/.irssi
116
+        echo '    use_ssl = "no";' >> "/home/${new_username}/.irssi/config"
117
+        IRC_ONION_HOSTNAME=$(grep "irc onion domain" "${COMPLETION_FILE}" | head -n 1 | awk -F ':' '{print $2}')
118
+        echo "    port = \"${IRC_ONION_PORT}\";" >> "/home/${new_username}/.irssi/config"
119
+    fi
120
+    echo '    chatnet = "Freedombone";' >> "/home/${new_username}/.irssi/config"
121
+    echo '    autoconnect = "yes";' >> "/home/${new_username}/.irssi/config"
122
+    if [ "${IRC_PASSWORD}" ]; then
123
+        echo "    password = \"${IRC_PASSWORD}\";" >> "/home/${new_username}/.irssi/config"
124
+    fi
125
+    { echo '  }';
126
+      echo ');';
127
+      echo '';
128
+      echo 'chatnets = {';
129
+      echo '  Freedombone = {';
130
+      echo '    type = "IRC";';
131
+      echo '    max_kicks = "1";';
132
+      echo '    max_msgs = "4";';
133
+      echo '    max_whois = "1";';
134
+      echo '  };';
135
+      echo '  Freenode = {';
136
+      echo '    type = "IRC";';
137
+      echo '    max_kicks = "1";';
138
+      echo '    max_msgs = "4";';
139
+      echo '    max_whois = "1";';
140
+      echo '  };';
141
+      echo '  OFTC = {';
142
+      echo '    type = "IRC";';
143
+      echo '    max_kicks = "1";';
144
+      echo '    max_msgs = "1";';
145
+      echo '    max_whois = "1";';
146
+      echo '  };';
147
+      echo '};';
148
+      echo '';
149
+      echo 'channels = (';
150
+      echo '  { name = "#freedombone"; chatnet = "Freedombone"; autojoin = "Yes"; },';
151
+      echo ');';
152
+      echo '';
153
+      echo 'settings = {';
154
+      echo "  core = { real_name = \"$new_name\"; user_name = \"$new_username\"; nick = \"$new_username\"; };";
155
+      echo '  "fe-text" = { actlist_sort = "refnum"; };';
156
+      echo '};';
157
+      echo 'ignores = ( { level = "CTCPS"; } );'; } >> "/home/${new_username}/.irssi/config"
158
+
159
+    chown -R "${new_username}":"${new_username}" "/home/${new_username}/.irssi"
160 160
 }
161 161
 
162 162
 function remove_user_irc_bouncer {
@@ -172,14 +172,14 @@ function remove_user_irc_bouncer {
172 172
 function remove_user_irc {
173 173
     remove_username="$1"
174 174
 
175
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp irc
175
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp irc
176 176
 
177
-    remove_user_irc_bouncer ${remove_username}
178
-    if [ -d /home/${remove_username}/.irssi ]; then
179
-        rm -rf /home/${remove_username}/.irssi
177
+    remove_user_irc_bouncer "${remove_username}"
178
+    if [ -d "/home/${remove_username}/.irssi" ]; then
179
+        rm -rf "/home/${remove_username}/.irssi"
180 180
     fi
181
-    if [ -d /home/${remove_username}/irclogs ]; then
182
-        rm -rf /home/${remove_username}/irclogs
181
+    if [ -d "/home/${remove_username}/irclogs" ]; then
182
+        rm -rf "/home/${remove_username}/irclogs"
183 183
     fi
184 184
 }
185 185
 
@@ -192,9 +192,9 @@ function irc_set_global_password_base {
192 192
     for d in /home/*/ ; do
193 193
         IRC_USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
194 194
         if [[ $(is_valid_user "$IRC_USERNAME") == "1" ]]; then
195
-            if [ -f /home/${IRC_USERNAME}/.irssi/config ]; then
196
-                sed -i "s|$EXISTING_IRC_PASSWORD|$NEW_IRC_PASSWORD|g" /home/${IRC_USERNAME}/.irssi/config
197
-                chown -R ${IRC_USERNAME}:${IRC_USERNAME} /home/${IRC_USERNAME}/.irssi
195
+            if [ -f "/home/${IRC_USERNAME}/.irssi/config" ]; then
196
+                sed -i "s|$EXISTING_IRC_PASSWORD|$NEW_IRC_PASSWORD|g" "/home/${IRC_USERNAME}/.irssi/config"
197
+                chown -R "${IRC_USERNAME}":"${IRC_USERNAME}" "/home/${IRC_USERNAME}/.irssi"
198 198
             fi
199 199
         fi
200 200
     done
@@ -217,11 +217,11 @@ function irc_set_global_password_base {
217 217
     sed -i "s|Server     = 127.0.0.1.*|Server     = 127.0.0.1 ${IRC_PORT} ${NEW_IRC_PASSWORD}|g" /home/znc/.znc/configs/znc.conf
218 218
 
219 219
     # Update the password
220
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a irc -p "$NEW_IRC_PASSWORD"
220
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a irc -p "$NEW_IRC_PASSWORD"
221 221
 
222 222
     # matrix bridge to irc
223
-    if [ -f $INSTALL_DIR/matrix_irc_bridge/config.yaml ]; then
224
-        sed -i "s|password: .*|password: \"$NEW_IRC_PASSWORD\"|g" $INSTALL_DIR/matrix_irc_bridge/config.yaml
223
+    if [ -f "$INSTALL_DIR/matrix_irc_bridge/config.yaml" ]; then
224
+        sed -i "s|password: .*|password: \"$NEW_IRC_PASSWORD\"|g" "$INSTALL_DIR/matrix_irc_bridge/config.yaml"
225 225
         systemctl restart matrix_irc_bridge
226 226
     fi
227 227
 
@@ -244,7 +244,7 @@ function add_user_irc_bouncer {
244 244
     new_user_password=$(irc_get_global_password)
245 245
     IRC_PASSWORD="$new_user_password"
246 246
     is_admin='true'
247
-    if [ ! $3 ]; then
247
+    if [ ! "$3" ]; then
248 248
         is_admin='false'
249 249
     fi
250 250
 
@@ -255,7 +255,7 @@ function add_user_irc_bouncer {
255 255
     read_config_param IRC_PORT
256 256
     read_config_param DEFAULT_DOMAIN_NAME
257 257
 
258
-    ${PROJECT_NAME}-pass -u $new_username -a irc -p "$new_user_password"
258
+    "${PROJECT_NAME}-pass" -u "$new_username" -a irc -p "$new_user_password"
259 259
 
260 260
     stop_irc_bouncer
261 261
 
@@ -269,73 +269,73 @@ function add_user_irc_bouncer {
269 269
         return
270 270
     fi
271 271
 
272
-    echo "<User ${new_username}>" >> /home/znc/.znc/configs/znc.conf
273
-    echo "    Admin      = ${is_admin}" >> /home/znc/.znc/configs/znc.conf
274
-    echo "    AltNick = ${new_username}_" >> /home/znc/.znc/configs/znc.conf
275
-    echo '    AppendTimestamp = false' >> /home/znc/.znc/configs/znc.conf
276
-    echo '    AutoClearChanBuffer = true' >> /home/znc/.znc/configs/znc.conf
277
-    echo '    AutoClearQueryBuffer = true' >> /home/znc/.znc/configs/znc.conf
278
-    echo "    Buffer = ${IRC_BUFFER_LENGTH}" >> /home/znc/.znc/configs/znc.conf
279
-    echo '    DenyLoadMod = false' >> /home/znc/.znc/configs/znc.conf
280
-    echo '    DenySetBindHost = false' >> /home/znc/.znc/configs/znc.conf
281
-    echo "    Ident = ${new_username}" >> /home/znc/.znc/configs/znc.conf
282
-    echo '    JoinTries = 10' >> /home/znc/.znc/configs/znc.conf
283
-    echo '    LoadModule = chansaver' >> /home/znc/.znc/configs/znc.conf
284
-    echo '    LoadModule = controlpanel' >> /home/znc/.znc/configs/znc.conf
285
-    echo '    MaxJoins = 10' >> /home/znc/.znc/configs/znc.conf
286
-    echo '    MaxNetworks = 10' >> /home/znc/.znc/configs/znc.conf
287
-    echo '    MaxQueryBuffers = 50' >> /home/znc/.znc/configs/znc.conf
288
-    echo '    MultiClients = true' >> /home/znc/.znc/configs/znc.conf
289
-    echo "    Nick = ${new_username}" >> /home/znc/.znc/configs/znc.conf
290
-    echo '    PrependTimestamp = true' >> /home/znc/.znc/configs/znc.conf
291
-    echo '    QuitMsg = Bye' >> /home/znc/.znc/configs/znc.conf
292
-    echo "    RealName = ${new_username}" >> /home/znc/.znc/configs/znc.conf
293
-    echo '    StatusPrefix = *' >> /home/znc/.znc/configs/znc.conf
294
-    echo '    TimestampFormat = [%H:%M:%S]' >> /home/znc/.znc/configs/znc.conf
295
-    echo '' >> /home/znc/.znc/configs/znc.conf
296
-    echo "    <Network ${PROJECT_NAME}>" >> /home/znc/.znc/configs/znc.conf
297
-    echo '        LoadModule = chansaver' >> /home/znc/.znc/configs/znc.conf
298
-    echo '        LoadModule = simple_away' >> /home/znc/.znc/configs/znc.conf
299
-    echo '' >> /home/znc/.znc/configs/znc.conf
300
-    echo "        Server     = 127.0.0.1 ${IRC_PORT} ${IRC_PASSWORD}" >> /home/znc/.znc/configs/znc.conf
301
-    echo '' >> /home/znc/.znc/configs/znc.conf
302
-    echo "        <Chan #${PROJECT_NAME}>" >> /home/znc/.znc/configs/znc.conf
303
-    echo '        </Chan>' >> /home/znc/.znc/configs/znc.conf
304
-    echo '    </Network>' >> /home/znc/.znc/configs/znc.conf
305
-    echo '' >> /home/znc/.znc/configs/znc.conf
306
-    echo '    <Network oftc>' >> /home/znc/.znc/configs/znc.conf
307
-    echo '        LoadModule = chansaver' >> /home/znc/.znc/configs/znc.conf
308
-    echo '        LoadModule = simple_away' >> /home/znc/.znc/configs/znc.conf
309
-    echo '        FloodBurst = 4' >> /home/znc/.znc/configs/znc.conf
310
-    echo '        FloodRate = 1.00' >> /home/znc/.znc/configs/znc.conf
311
-    echo '        IRCConnectEnabled = true' >> /home/znc/.znc/configs/znc.conf
312
-    echo '        Server = irc.oftc.net 6697' >> /home/znc/.znc/configs/znc.conf
313
-    echo '    </Network>' >> /home/znc/.znc/configs/znc.conf
314
-    echo '' >> /home/znc/.znc/configs/znc.conf
315
-    echo '    <Network freenode>' >> /home/znc/.znc/configs/znc.conf
316
-    echo '        LoadModule = chansaver' >> /home/znc/.znc/configs/znc.conf
317
-    echo '        LoadModule = simple_away' >> /home/znc/.znc/configs/znc.conf
318
-    echo '        FloodBurst = 4' >> /home/znc/.znc/configs/znc.conf
319
-    echo '        FloodRate = 1.00' >> /home/znc/.znc/configs/znc.conf
320
-    echo '        IRCConnectEnabled = true' >> /home/znc/.znc/configs/znc.conf
321
-    echo '        Server = irc.freenode.net 6697' >> /home/znc/.znc/configs/znc.conf
322
-    echo '    </Network>' >> /home/znc/.znc/configs/znc.conf
323
-    echo '' >> /home/znc/.znc/configs/znc.conf
324
-    echo '    <Pass password>' >> /home/znc/.znc/configs/znc.conf
325
-    echo "        Hash = ${new_user_hash}" >> /home/znc/.znc/configs/znc.conf
326
-    echo '        Method = sha256' >> /home/znc/.znc/configs/znc.conf
327
-    echo "        Salt = ${ZNC_SALT}" >> /home/znc/.znc/configs/znc.conf
328
-    echo '    </Pass>' >> /home/znc/.znc/configs/znc.conf
329
-    echo '</User>' >> /home/znc/.znc/configs/znc.conf
330
-
331
-    mkdir -p /home/znc/.znc/users/${new_username}/moddata
332
-    mkdir -p /home/znc/.znc/users/${new_username}/networks
333
-    mkdir /home/znc/.znc/users/${new_username}/moddata/chanserver
334
-    mkdir /home/znc/.znc/users/${new_username}/moddata/controlpanel
335
-    mkdir /home/znc/.znc/users/${new_username}/moddata/perform
336
-    mkdir /home/znc/.znc/users/${new_username}/moddata/webadmin
337
-    mkdir -p /home/znc/.znc/users/${new_username}/networks/${PROJECT_NAME}/moddata/chansaver
338
-    mkdir -p /home/znc/.znc/users/${new_username}/networks/${PROJECT_NAME}/moddata/simple_away
272
+    { echo "<User ${new_username}>";
273
+      echo "    Admin      = ${is_admin}";
274
+      echo "    AltNick = ${new_username}_";
275
+      echo '    AppendTimestamp = false';
276
+      echo '    AutoClearChanBuffer = true';
277
+      echo '    AutoClearQueryBuffer = true';
278
+      echo "    Buffer = ${IRC_BUFFER_LENGTH}";
279
+      echo '    DenyLoadMod = false';
280
+      echo '    DenySetBindHost = false';
281
+      echo "    Ident = ${new_username}";
282
+      echo '    JoinTries = 10';
283
+      echo '    LoadModule = chansaver';
284
+      echo '    LoadModule = controlpanel';
285
+      echo '    MaxJoins = 10';
286
+      echo '    MaxNetworks = 10';
287
+      echo '    MaxQueryBuffers = 50';
288
+      echo '    MultiClients = true';
289
+      echo "    Nick = ${new_username}";
290
+      echo '    PrependTimestamp = true';
291
+      echo '    QuitMsg = Bye';
292
+      echo "    RealName = ${new_username}";
293
+      echo '    StatusPrefix = *';
294
+      echo '    TimestampFormat = [%H:%M:%S]';
295
+      echo '';
296
+      echo "    <Network ${PROJECT_NAME}>";
297
+      echo '        LoadModule = chansaver';
298
+      echo '        LoadModule = simple_away';
299
+      echo '';
300
+      echo "        Server     = 127.0.0.1 ${IRC_PORT} ${IRC_PASSWORD}";
301
+      echo '';
302
+      echo "        <Chan #${PROJECT_NAME}>";
303
+      echo '        </Chan>';
304
+      echo '    </Network>';
305
+      echo '';
306
+      echo '    <Network oftc>';
307
+      echo '        LoadModule = chansaver';
308
+      echo '        LoadModule = simple_away';
309
+      echo '        FloodBurst = 4';
310
+      echo '        FloodRate = 1.00';
311
+      echo '        IRCConnectEnabled = true';
312
+      echo '        Server = irc.oftc.net 6697';
313
+      echo '    </Network>';
314
+      echo '';
315
+      echo '    <Network freenode>';
316
+      echo '        LoadModule = chansaver';
317
+      echo '        LoadModule = simple_away';
318
+      echo '        FloodBurst = 4';
319
+      echo '        FloodRate = 1.00';
320
+      echo '        IRCConnectEnabled = true';
321
+      echo '        Server = irc.freenode.net 6697';
322
+      echo '    </Network>';
323
+      echo '';
324
+      echo '    <Pass password>';
325
+      echo "        Hash = ${new_user_hash}";
326
+      echo '        Method = sha256';
327
+      echo "        Salt = ${ZNC_SALT}";
328
+      echo '    </Pass>';
329
+      echo '</User>'; } >> /home/znc/.znc/configs/znc.conf
330
+
331
+    mkdir -p "/home/znc/.znc/users/${new_username}/moddata"
332
+    mkdir -p "/home/znc/.znc/users/${new_username}/networks"
333
+    mkdir "/home/znc/.znc/users/${new_username}/moddata/chanserver"
334
+    mkdir "/home/znc/.znc/users/${new_username}/moddata/controlpanel"
335
+    mkdir "/home/znc/.znc/users/${new_username}/moddata/perform"
336
+    mkdir "/home/znc/.znc/users/${new_username}/moddata/webadmin"
337
+    mkdir -p "/home/znc/.znc/users/${new_username}/networks/${PROJECT_NAME}/moddata/chansaver"
338
+    mkdir -p "/home/znc/.znc/users/${new_username}/networks/${PROJECT_NAME}/moddata/simple_away"
339 339
 
340 340
     mkdir -p /home/znc/.znc/moddata/webadmin
341 341
 
@@ -353,8 +353,8 @@ function add_user_irc {
353 353
         IRC_PASSWORD=
354 354
     fi
355 355
 
356
-    if [ ! -d /home/${new_username}/.irssi ]; then
357
-        mkdir /home/${new_username}/.irssi
356
+    if [ ! -d "/home/${new_username}/.irssi" ]; then
357
+        mkdir "/home/${new_username}/.irssi"
358 358
     fi
359 359
 
360 360
     create_irssi_config "${new_username}"
@@ -374,19 +374,21 @@ function irc_show_password {
374 374
 
375 375
 function irc_set_global_password {
376 376
     EXISTING_IRC_PASSWORD=$(irc_get_global_password)
377
+    data=$(mktemp 2>/dev/null)
377 378
     dialog --title $"IRC Password" \
378 379
            --clear \
379 380
            --backtitle $"Freedombone Control Panel" \
380
-           --passwordbox $"Password for all IRC users, or press Enter for no password" 10 60 "$EXISTING_IRC_PASSWORD" 2> $data
381
+           --passwordbox $"Password for all IRC users, or press Enter for no password" 10 60 "$EXISTING_IRC_PASSWORD" 2> "$data"
381 382
     sel=$?
382 383
     case $sel in
383 384
         0)
384
-            NEW_IRC_PASSWORD=$(<$data)
385
+            NEW_IRC_PASSWORD=$(<"$data")
385 386
             irc_set_global_password_base "$NEW_IRC_PASSWORD"
386 387
             dialog --title $"IRC Password" \
387 388
                    --msgbox $"The IRC password was changed" 6 40
388 389
             ;;
389 390
     esac
391
+    rm -f "$data"
390 392
 }
391 393
 
392 394
 function configure_interactive_irc {
@@ -398,24 +400,26 @@ function configure_interactive_irc {
398 400
 
399 401
     while true
400 402
     do
401
-        data=$(tempfile 2>/dev/null)
402
-        trap "rm -f $data" 0 1 2 5 15
403
+        data=$(mktemp 2>/dev/null)
403 404
         dialog --backtitle $"Freedombone Control Panel" \
404 405
                --title $"IRC Menu" \
405 406
                --radiolist $"Choose an operation:" 14 70 4 \
406 407
                1 $"Set a password for all IRC users" off \
407 408
                2 $"Show current IRC login password" off \
408
-               3 $"Exit" on 2> $data
409
+               3 $"Exit" on 2> "$data"
409 410
         sel=$?
410 411
         case $sel in
411
-            1) break;;
412
-            255) break;;
412
+            1) rm -f "$data"
413
+               break;;
414
+            255) rm -f "$data"
415
+                 break;;
413 416
         esac
414
-        case $(cat $data) in
417
+        case $(cat "$data") in
415 418
             1) irc_set_global_password;;
416 419
             2) irc_show_password;;
417 420
             3) break;;
418 421
         esac
422
+        rm -f "$data"
419 423
     done
420 424
 }
421 425
 
@@ -466,7 +470,7 @@ function remove_irc {
466 470
     remove_onion_service irc ${IRC_ONION_PORT}
467 471
     remove_completion_param install_irc
468 472
     remove_completion_param configure_firewall_for_irc
469
-    sed -i '/IRC /d' ${COMPLETION_FILE}
473
+    sed -i '/IRC /d' "${COMPLETION_FILE}"
470 474
     sed -i '/znc 2> /d' /etc/crontab
471 475
     stop_irc_bouncer
472 476
     if [ -d /home/znc ]; then
@@ -481,7 +485,7 @@ function configure_firewall_for_irc {
481 485
     if [ ! -d /etc/ngircd ]; then
482 486
         return
483 487
     fi
484
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
488
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
485 489
         return
486 490
     fi
487 491
     if [[ ${INSTALLED_WITHIN_DOCKER} == "yes" ]]; then
@@ -496,7 +500,7 @@ function configure_firewall_for_irc {
496 500
     save_firewall_settings
497 501
 
498 502
     firewall_add IRC ${IRC_BOUNCER_PORT} tcp
499
-    echo 'configure_firewall_for_irc' >> ${COMPLETION_FILE}
503
+    echo 'configure_firewall_for_irc' >> "${COMPLETION_FILE}"
500 504
 }
501 505
 
502 506
 function install_irc_server {
@@ -511,29 +515,29 @@ function install_irc_server {
511 515
     fi
512 516
 
513 517
     # obtain a cert for the default domain
514
-    if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "0" ]]; then
518
+    if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}" pem)" == "0" ]]; then
515 519
         echo $'Obtaining certificate for the main domain'
516
-        create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
520
+        create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
517 521
     fi
518 522
 
519
-    if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME})" == "0" ]]; then
520
-        ${PROJECT_NAME}-addcert -h ngircd --dhkey ${DH_KEYLENGTH}
523
+    if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}")" == "0" ]]; then
524
+        "${PROJECT_NAME}-addcert" -h ngircd --dhkey "${DH_KEYLENGTH}"
521 525
         function_check check_certificates
522 526
         check_certificates ngircd
523 527
     fi
524 528
 
525 529
     DEFAULTDOMAIN=${DEFAULT_DOMAIN_NAME}
526 530
 
527
-    IRC_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
531
+    IRC_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
528 532
 
529 533
     set_password_for_all_users irc "$IRC_PASSWORD"
530 534
 
531 535
 
532
-    echo '**************************************************' > /etc/ngircd/motd
533
-    echo $'*           F R E E D O M B O N E   I R C        *' >> /etc/ngircd/motd
534
-    echo '*                                                *' >> /etc/ngircd/motd
535
-    echo $'*               Freedom in the Cloud             *' >> /etc/ngircd/motd
536
-    echo '**************************************************' >> /etc/ngircd/motd
536
+    { echo '**************************************************';
537
+      echo $'*           F R E E D O M B O N E   I R C        *';
538
+      echo '*                                                *';
539
+      echo $'*               Freedom in the Cloud             *';
540
+      echo '**************************************************'; } > /etc/ngircd/motd
537 541
     sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
538 542
     sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
539 543
     sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
@@ -541,7 +545,7 @@ function install_irc_server {
541 545
     sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
542 546
     sed -i "s/;Ports =.*/Ports = ${IRC_PORT}/g" /etc/ngircd/ngircd.conf
543 547
     if [[ $ONION_ONLY == 'no' ]]; then
544
-        if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
548
+        if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
545 549
             sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/ngircd/ngircd.conf
546 550
         else
547 551
             sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt|g" /etc/ngircd/ngircd.conf
@@ -562,10 +566,10 @@ function install_irc_server {
562 566
     sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
563 567
     sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
564 568
     IRC_SALT="$(create_password 30)"
565
-    if [ -f ${IMAGE_PASSWORD_FILE} ]; then
566
-        IRC_OPERATOR_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
569
+    if [ -f "${IMAGE_PASSWORD_FILE}" ]; then
570
+        IRC_OPERATOR_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
567 571
     else
568
-        IRC_OPERATOR_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
572
+        IRC_OPERATOR_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
569 573
     fi
570 574
     sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
571 575
     sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
@@ -574,7 +578,7 @@ function install_irc_server {
574 578
     sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
575 579
     sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
576 580
     sed -i 's|;Listen =.*|Listen = 0.0.0.0,0.0.0.0:9050,127.0.0.1,127.0.0.1:9050|g' /etc/ngircd/ngircd.conf
577
-    if [ ${IRC_PASSWORD} ]; then
581
+    if [ "${IRC_PASSWORD}" ]; then
578 582
         sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
579 583
     fi
580 584
     # upgrade a cypher
@@ -585,7 +589,8 @@ function install_irc_server {
585 589
     touch /var/run/ngircd/ngircd.pid
586 590
     chown -R irc:irc /var/run/ngircd
587 591
 
588
-    IRC_ONION_HOSTNAME=$(add_onion_service irc ${IRC_BOUNCER_PORT} ${IRC_ONION_PORT})
592
+    # shellcheck disable=SC2034
593
+    IRC_ONION_HOSTNAME=$(add_onion_service irc "${IRC_BOUNCER_PORT}" "${IRC_ONION_PORT}")
589 594
 
590 595
     if [ ! -d /var/run/ircd ]; then
591 596
         mkdir /var/run/ircd
@@ -608,8 +613,8 @@ function install_irc_client {
608 613
     fi
609 614
     apt-get -yq install irssi
610 615
 
611
-    if [ ! -d /home/${MY_USERNAME}/.irssi ]; then
612
-        mkdir /home/${MY_USERNAME}/.irssi
616
+    if [ ! -d "/home/${MY_USERNAME}/.irssi" ]; then
617
+        mkdir "/home/${MY_USERNAME}/.irssi"
613 618
     fi
614 619
 
615 620
     create_irssi_config "${MY_USERNAME}" "$MY_NAME"
@@ -632,41 +637,41 @@ function install_irc_bouncer {
632 637
     mkdir -p /home/znc/.znc/configs
633 638
     mkdir -p /home/znc/.znc/users
634 639
 
635
-    echo 'AnonIPLimit = 10' > /home/znc/.znc/configs/znc.conf
636
-    echo 'ConnectDelay = 5' >> /home/znc/.znc/configs/znc.conf
637
-    echo 'HideVersion = false' >> /home/znc/.znc/configs/znc.conf
638
-    echo 'MaxBufferSize = 500' >> /home/znc/.znc/configs/znc.conf
639
-    echo 'ProtectWebSessions = true' >> /home/znc/.znc/configs/znc.conf
640
-    echo 'SSLCertFile = /home/znc/.znc/znc.pem' >> /home/znc/.znc/configs/znc.conf
641
-    echo 'ServerThrottle = 30' >> /home/znc/.znc/configs/znc.conf
642
-    echo 'Version = 1.6.2' >> /home/znc/.znc/configs/znc.conf
643
-    echo '' >> /home/znc/.znc/configs/znc.conf
644
-    echo '<Listener listener0>' >> /home/znc/.znc/configs/znc.conf
645
-    echo '  AllowIRC = true' >> /home/znc/.znc/configs/znc.conf
646
-    echo '  AllowWeb = false' >> /home/znc/.znc/configs/znc.conf
647
-    echo '  IPv4 = true' >> /home/znc/.znc/configs/znc.conf
648
-    echo '  IPv6 = true' >> /home/znc/.znc/configs/znc.conf
649
-    echo '  Port = 6697' >> /home/znc/.znc/configs/znc.conf
650
-    if [[ ${ONION_ONLY} == 'no' ]]; then
640
+    { echo 'AnonIPLimit = 10';
641
+      echo 'ConnectDelay = 5';
642
+      echo 'HideVersion = false';
643
+      echo 'MaxBufferSize = 500';
644
+      echo 'ProtectWebSessions = true';
645
+      echo 'SSLCertFile = /home/znc/.znc/znc.pem';
646
+      echo 'ServerThrottle = 30';
647
+      echo 'Version = 1.6.2';
648
+      echo '';
649
+      echo '<Listener listener0>';
650
+      echo '  AllowIRC = true';
651
+      echo '  AllowWeb = false';
652
+      echo '  IPv4 = true';
653
+      echo '  IPv6 = true';
654
+      echo '  Port = 6697'; } > /home/znc/.znc/configs/znc.conf
655
+    if [[ "${ONION_ONLY}" == 'no' ]]; then
651 656
         echo '  SSL = true' >> /home/znc/.znc/configs/znc.conf
652 657
     else
653 658
         echo '  SSL = false' >> /home/znc/.znc/configs/znc.conf
654 659
     fi
655
-    echo '  URIPrefix = /' >> /home/znc/.znc/configs/znc.conf
656
-    echo '</Listener>' >> /home/znc/.znc/configs/znc.conf
657
-    echo '' >> /home/znc/.znc/configs/znc.conf
660
+    { echo '  URIPrefix = /';
661
+      echo '</Listener>';
662
+      echo ''; } >> /home/znc/.znc/configs/znc.conf
658 663
 
659 664
     if [ $IRC_PORT -ne $IRC_ONION_PORT ]; then
660
-        echo '<Listener listener1>' >> /home/znc/.znc/configs/znc.conf
661
-        echo '  AllowIRC = true' >> /home/znc/.znc/configs/znc.conf
662
-        echo '  AllowWeb = false' >> /home/znc/.znc/configs/znc.conf
663
-        echo '  IPv4 = true' >> /home/znc/.znc/configs/znc.conf
664
-        echo '  IPv6 = true' >> /home/znc/.znc/configs/znc.conf
665
-        echo "  Port = ${IRC_ONION_PORT}" >> /home/znc/.znc/configs/znc.conf
666
-        echo '  SSL = false' >> /home/znc/.znc/configs/znc.conf
667
-        echo '  URIPrefix = /' >> /home/znc/.znc/configs/znc.conf
668
-        echo '</Listener>' >> /home/znc/.znc/configs/znc.conf
669
-        echo '' >> /home/znc/.znc/configs/znc.conf
665
+        { echo '<Listener listener1>';
666
+          echo '  AllowIRC = true';
667
+          echo '  AllowWeb = false';
668
+          echo '  IPv4 = true';
669
+          echo '  IPv6 = true';
670
+          echo "  Port = ${IRC_ONION_PORT}";
671
+          echo '  SSL = false';
672
+          echo '  URIPrefix = /';
673
+          echo '</Listener>';
674
+          echo ''; } >> /home/znc/.znc/configs/znc.conf
670 675
     fi
671 676
 
672 677
     chown -R znc:znc /home/znc/.znc

+ 84
- 85
src/freedombone-app-jitsi Просмотреть файл

@@ -105,7 +105,7 @@ function add_user_jitsi {
105 105
 }
106 106
 
107 107
 function install_interactive_jitsi {
108
-    if [ ! ${ONION_ONLY} ]; then
108
+    if [ ! "${ONION_ONLY}" ]; then
109 109
         ONION_ONLY='no'
110 110
     fi
111 111
 
@@ -202,7 +202,7 @@ function remove_jitsi {
202 202
 
203 203
     remove_app jitsi
204 204
     remove_completion_param install_jitsi
205
-    sed -i '/jitsi/d' ${COMPLETION_FILE}
205
+    sed -i '/jitsi/d' "${COMPLETION_FILE}"
206 206
 
207 207
     function_check remove_ddns_domain
208 208
     remove_ddns_domain $JITSI_DOMAIN_NAME
@@ -233,8 +233,7 @@ function install_jitsi {
233 233
     jitsi_deb_repo=unstable #binary
234 234
     apt-get -yq install wget debconf-utils default-jre
235 235
     install_nodejs jitsi
236
-    npm install -g browserify@13.1.1
237
-    if [ ! "$?" = "0" ]; then
236
+    if ! npm install -g browserify@13.1.1; then
238 237
         remove_nodejs jitsi
239 238
         exit 638352
240 239
     fi
@@ -272,17 +271,17 @@ function install_jitsi {
272 271
 
273 272
     echo 'server_names_hash_bucket_size 64;' > $jitsi_nginx_site
274 273
     if [[ $ONION_ONLY == "no" ]]; then
275
-        echo '' >> $jitsi_nginx_site
276
-        echo 'server {' >> $jitsi_nginx_site
277
-        echo '    listen 80;' >> $jitsi_nginx_site
278
-        echo "    server_name ${JITSI_DOMAIN_NAME};" >> $jitsi_nginx_site
279
-        echo '    return 301 https://$host$request_uri;' >> $jitsi_nginx_site
280
-        echo '}' >> $jitsi_nginx_site
281
-        echo 'server {' >> $jitsi_nginx_site
282
-        echo '    listen 443 ssl;' >> $jitsi_nginx_site
283
-        echo '    #listen [::]:443 ssl;' >> $jitsi_nginx_site
284
-        echo "    server_name ${JITSI_DOMAIN_NAME};" >> $jitsi_nginx_site
285
-        echo '' >> $jitsi_nginx_site
274
+        { echo '';
275
+          echo 'server {';
276
+          echo '    listen 80;';
277
+          echo "    server_name ${JITSI_DOMAIN_NAME};";
278
+          echo "    return 301 https://\$host\$request_uri;";
279
+          echo '}';
280
+          echo 'server {';
281
+          echo '    listen 443 ssl;';
282
+          echo '    #listen [::]:443 ssl;';
283
+          echo "    server_name ${JITSI_DOMAIN_NAME};";
284
+          echo ''; } >> $jitsi_nginx_site
286 285
 
287 286
         function_check nginx_ssl
288 287
         nginx_ssl ${JITSI_DOMAIN_NAME}
@@ -290,80 +289,80 @@ function install_jitsi {
290 289
         function_check nginx_disable_sniffing
291 290
         nginx_disable_sniffing ${JITSI_DOMAIN_NAME}
292 291
 
293
-        echo '    add_header Strict-Transport-Security max-age=15768000;' >> $jitsi_nginx_site
294
-        echo '' >> $jitsi_nginx_site
295
-        echo '    root /usr/share/jitsi-meet;' >> $jitsi_nginx_site
296
-        echo '    index index.html index.htm;' >> $jitsi_nginx_site
297
-        echo '' >> $jitsi_nginx_site
298
-        echo '    location /config.js {' >> $jitsi_nginx_site
299
-        echo "        alias /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js;" >> $jitsi_nginx_site
300
-        echo '    }' >> $jitsi_nginx_site
301
-        echo '' >> $jitsi_nginx_site
302
-        echo '    location ~ ^/([a-zA-Z0-9=\?]+)$ {' >> $jitsi_nginx_site
303
-        echo '        rewrite ^/(.*)$ / break;' >> $jitsi_nginx_site
304
-        echo '    }' >> $jitsi_nginx_site
305
-        echo '' >> $jitsi_nginx_site
306
-        echo '    location / {' >> $jitsi_nginx_site
307
-        echo '        ssi on;' >> $jitsi_nginx_site
308
-        echo '    }' >> $jitsi_nginx_site
309
-        echo '' >> $jitsi_nginx_site
310
-        echo '    # Backward compatibility' >> $jitsi_nginx_site
311
-        echo '    location ~ /external_api.* {' >> $jitsi_nginx_site
312
-        echo '        root /usr/share/jitsi-meet/libs;' >> $jitsi_nginx_site
313
-        echo '    }' >> $jitsi_nginx_site
314
-        echo '' >> $jitsi_nginx_site
315
-        echo '    # Logs' >> $jitsi_nginx_site
316
-        echo '    access_log /dev/null;' >> $jitsi_nginx_site
317
-        echo '    error_log /dev/null;' >> $jitsi_nginx_site
318
-        echo '' >> $jitsi_nginx_site
319
-        echo '    # BOSH' >> $jitsi_nginx_site
320
-        echo '    location /http-bind {' >> $jitsi_nginx_site
321
-        echo '        proxy_pass      http://localhost:5280/http-bind;' >> $jitsi_nginx_site
322
-        echo '        proxy_set_header X-Forwarded-For $remote_addr;' >> $jitsi_nginx_site
323
-        echo '        proxy_set_header Host $http_host;' >> $jitsi_nginx_site
324
-        echo '    }' >> $jitsi_nginx_site
325
-        echo '}' >> $jitsi_nginx_site
326
-    fi
327
-    echo '' >> $jitsi_nginx_site
328
-    echo 'server {' >> $jitsi_nginx_site
329
-    echo "    listen 127.0.0.1:$JITSI_ONION_PORT default_server;" >> $jitsi_nginx_site
292
+        { echo '    add_header Strict-Transport-Security max-age=15768000;';
293
+          echo '';
294
+          echo '    root /usr/share/jitsi-meet;';
295
+          echo '    index index.html index.htm;';
296
+          echo '';
297
+          echo '    location /config.js {';
298
+          echo "        alias /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js;";
299
+          echo '    }';
300
+          echo '';
301
+          echo '    location ~ ^/([a-zA-Z0-9=\?]+)$ {';
302
+          echo '        rewrite ^/(.*)$ / break;';
303
+          echo '    }';
304
+          echo '';
305
+          echo '    location / {';
306
+          echo '        ssi on;';
307
+          echo '    }';
308
+          echo '';
309
+          echo '    # Backward compatibility';
310
+          echo '    location ~ /external_api.* {';
311
+          echo '        root /usr/share/jitsi-meet/libs;';
312
+          echo '    }';
313
+          echo '';
314
+          echo '    # Logs';
315
+          echo '    access_log /dev/null;';
316
+          echo '    error_log /dev/null;';
317
+          echo '';
318
+          echo '    # BOSH';
319
+          echo '    location /http-bind {';
320
+          echo '        proxy_pass      http://localhost:5280/http-bind;';
321
+          echo "        proxy_set_header X-Forwarded-For \$remote_addr;";
322
+          echo "        proxy_set_header Host \$http_host;";
323
+          echo '    }';
324
+          echo '}'; } >> $jitsi_nginx_site
325
+    fi
326
+    { echo '';
327
+      echo 'server {';
328
+      echo "    listen 127.0.0.1:$JITSI_ONION_PORT default_server;"; } >> $jitsi_nginx_site
330 329
     if [[ $ONION_ONLY == 'no' ]]; then
331 330
         echo "    server_name ${JITSI_DOMAIN_NAME};" >> $jitsi_nginx_site
332 331
     else
333 332
         echo "    server_name ${JITSI_ONION_HOSTNAME};" >> $jitsi_nginx_site
334 333
     fi
335
-    echo '' >> $jitsi_nginx_site
336
-    echo '    root /usr/share/jitsi-meet;' >> $jitsi_nginx_site
337
-    echo '    index index.html index.htm;' >> $jitsi_nginx_site
338
-    echo '' >> $jitsi_nginx_site
339
-    echo '    location /config.js {' >> $jitsi_nginx_site
340
-    echo "        alias /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js;" >> $jitsi_nginx_site
341
-    echo '    }' >> $jitsi_nginx_site
342
-    echo '' >> $jitsi_nginx_site
343
-    echo '    location ~ ^/([a-zA-Z0-9=\?]+)$ {' >> $jitsi_nginx_site
344
-    echo '        rewrite ^/(.*)$ / break;' >> $jitsi_nginx_site
345
-    echo '    }' >> $jitsi_nginx_site
346
-    echo '' >> $jitsi_nginx_site
347
-    echo '    location / {' >> $jitsi_nginx_site
348
-    echo '        ssi off;' >> $jitsi_nginx_site
349
-    echo '    }' >> $jitsi_nginx_site
350
-    echo '' >> $jitsi_nginx_site
351
-    echo '    # Backward compatibility' >> $jitsi_nginx_site
352
-    echo '    location ~ /external_api.* {' >> $jitsi_nginx_site
353
-    echo '        root /usr/share/jitsi-meet/libs;' >> $jitsi_nginx_site
354
-    echo '    }' >> $jitsi_nginx_site
355
-    echo '' >> $jitsi_nginx_site
356
-    echo '    # Logs' >> $jitsi_nginx_site
357
-    echo '    access_log /dev/null;' >> $jitsi_nginx_site
358
-    echo '    error_log /dev/null;' >> $jitsi_nginx_site
359
-    echo '' >> $jitsi_nginx_site
360
-    echo '    # BOSH' >> $jitsi_nginx_site
361
-    echo '    location /http-bind {' >> $jitsi_nginx_site
362
-    echo '        proxy_pass      http://localhost:5280/http-bind;' >> $jitsi_nginx_site
363
-    echo '        proxy_set_header X-Forwarded-For $remote_addr;' >> $jitsi_nginx_site
364
-    echo '        proxy_set_header Host $http_host;' >> $jitsi_nginx_site
365
-    echo '    }' >> $jitsi_nginx_site
366
-    echo '}' >> $jitsi_nginx_site
334
+    { echo '';
335
+      echo '    root /usr/share/jitsi-meet;';
336
+      echo '    index index.html index.htm;';
337
+      echo '';
338
+      echo '    location /config.js {';
339
+      echo "        alias /etc/jitsi/meet/${JITSI_DOMAIN_NAME}-config.js;";
340
+      echo '    }';
341
+      echo '';
342
+      echo '    location ~ ^/([a-zA-Z0-9=\?]+)$ {';
343
+      echo '        rewrite ^/(.*)$ / break;';
344
+      echo '    }';
345
+      echo '';
346
+      echo '    location / {';
347
+      echo '        ssi off;';
348
+      echo '    }';
349
+      echo '';
350
+      echo '    # Backward compatibility';
351
+      echo '    location ~ /external_api.* {';
352
+      echo '        root /usr/share/jitsi-meet/libs;';
353
+      echo '    }';
354
+      echo '';
355
+      echo '    # Logs';
356
+      echo '    access_log /dev/null;';
357
+      echo '    error_log /dev/null;';
358
+      echo '';
359
+      echo '    # BOSH';
360
+      echo '    location /http-bind {';
361
+      echo '        proxy_pass      http://localhost:5280/http-bind;';
362
+      echo "        proxy_set_header X-Forwarded-For \$remote_addr;";
363
+      echo "        proxy_set_header Host \$http_host;";
364
+      echo '    }';
365
+      echo '}'; } >> $jitsi_nginx_site
367 366
 
368 367
     sed -i "s|/var/www/${JITSI_DOMAIN_NAME}/htdocs|/usr/share/jitsi-meet|g" $jitsi_nginx_site
369 368
 
@@ -376,7 +375,7 @@ function install_jitsi {
376 375
         fi
377 376
         function_check create_site_certificate
378 377
         create_site_certificate ${JITSI_DOMAIN_NAME} 'yes'
379
-        if [[ $ONION_ONLY == "no" ]]; then
378
+        if [[ "$ONION_ONLY" == "no" ]]; then
380 379
             if [ ! -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.pem ]; then
381 380
                 exit 678363
382 381
             fi

+ 195
- 198
src/freedombone-app-kanboard Просмотреть файл

@@ -70,19 +70,19 @@ function logging_off_kanboard {
70 70
 function remove_user_kanboard {
71 71
     remove_username="$1"
72 72
 
73
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp kanboard
73
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp kanboard
74 74
 }
75 75
 
76 76
 function add_user_kanboard {
77 77
     new_username="$1"
78 78
     new_user_password="$2"
79 79
 
80
-    ${PROJECT_NAME}-pass -u $new_username -a kanboard -p "$new_user_password"
80
+    "${PROJECT_NAME}-pass" -u "$new_username" -a kanboard -p "$new_user_password"
81 81
     echo '0'
82 82
 }
83 83
 
84 84
 function install_interactive_kanboard {
85
-    if [ ! $ONION_ONLY ]; then
85
+    if [ ! "$ONION_ONLY" ]; then
86 86
         ONION_ONLY='no'
87 87
     fi
88 88
 
@@ -92,42 +92,43 @@ function install_interactive_kanboard {
92 92
         KANBOARD_DETAILS_COMPLETE=
93 93
         while [ ! $KANBOARD_DETAILS_COMPLETE ]
94 94
         do
95
-            data=$(tempfile 2>/dev/null)
96
-            trap "rm -f $data" 0 1 2 5 15
95
+            data=$(mktemp 2>/dev/null)
97 96
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
98 97
                 dialog --backtitle $"Freedombone Configuration" \
99 98
                        --title $"KanBoard Configuration" \
100
-                       --form $"\nPlease enter your KanBoard details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt." 13 55 2 \
99
+                       --form $"\\nPlease enter your KanBoard details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt." 13 55 2 \
101 100
                        $"Domain:" 1 1 "$(grep 'KANBOARD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
102 101
                        $"Code:" 2 1 "$(grep 'KANBOARD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
103
-                       2> $data
102
+                       2> "$data"
104 103
             else
105 104
                 dialog --backtitle $"Freedombone Configuration" \
106 105
                        --title $"KanBoard Configuration" \
107
-                       --form $"\nPlease enter your KanBoard details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt." 13 55 2 \
106
+                       --form $"\\nPlease enter your KanBoard details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt." 13 55 2 \
108 107
                        $"Domain:" 1 1 "$(grep 'KANBOARD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
109
-                       2> $data
108
+                       2> "$data"
110 109
             fi
111 110
             sel=$?
112 111
             case $sel in
113
-                1) exit 1;;
114
-                255) exit 1;;
112
+                1) rm -f "$data"
113
+                   exit 1;;
114
+                255) rm -f "$data"
115
+                     exit 1;;
115 116
             esac
116
-            KANBOARD_DOMAIN_NAME=$(cat $data | sed -n 1p)
117
-            if [ $KANBOARD_DOMAIN_NAME ]; then
117
+            KANBOARD_DOMAIN_NAME=$(sed -n 1p < "$data")
118
+            if [ "$KANBOARD_DOMAIN_NAME" ]; then
118 119
                 if [[ $KANBOARD_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
119 120
                     KANBOARD_DOMAIN_NAME=""
120 121
                 fi
121 122
                 TEST_DOMAIN_NAME=$KANBOARD_DOMAIN_NAME
122 123
                 validate_domain_name
123
-                if [[ $TEST_DOMAIN_NAME != $KANBOARD_DOMAIN_NAME ]]; then
124
+                if [[ "$TEST_DOMAIN_NAME" != "$KANBOARD_DOMAIN_NAME" ]]; then
124 125
                     KANBOARD_DOMAIN_NAME=
125 126
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
126 127
                 else
127 128
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
128
-                        KANBOARD_CODE=$(cat $data | sed -n 2p)
129
+                        KANBOARD_CODE=$(sed -n 2p < "$data")
129 130
                         validate_freedns_code "$KANBOARD_CODE"
130
-                        if [ ! $VALID_CODE ]; then
131
+                        if [ ! "$VALID_CODE" ]; then
131 132
                             KANBOARD_DOMAIN_NAME=
132 133
                         fi
133 134
                     fi
@@ -136,6 +137,7 @@ function install_interactive_kanboard {
136 137
             if [ $KANBOARD_DOMAIN_NAME ]; then
137 138
                 KANBOARD_DETAILS_COMPLETE="yes"
138 139
             fi
140
+            rm -f "$data"
139 141
         done
140 142
 
141 143
         # save the results in the config file
@@ -151,23 +153,23 @@ function change_password_kanboard {
151 153
 
152 154
     read_config_param 'KANBOARD_DOMAIN_NAME'
153 155
 
154
-    ${PROJECT_NAME}-pass -u "$curr_username" -a kanboard -p "$new_user_password"
156
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a kanboard -p "$new_user_password"
155 157
 }
156 158
 
157 159
 function kanboard_create_database {
158
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
159
-        KANBOARD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
160
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
161
+        KANBOARD_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
160 162
     else
161
-        if [ ! $KANBOARD_ADMIN_PASSWORD ]; then
162
-            KANBOARD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
163
+        if [ ! "$KANBOARD_ADMIN_PASSWORD" ]; then
164
+            KANBOARD_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
163 165
         fi
164 166
     fi
165
-    if [ ! $KANBOARD_ADMIN_PASSWORD ]; then
167
+    if [ ! "$KANBOARD_ADMIN_PASSWORD" ]; then
166 168
         return
167 169
     fi
168 170
 
169 171
     function_check create_database
170
-    create_database kanboard "$KANBOARD_ADMIN_PASSWORD" $MY_USERNAME
172
+    create_database kanboard "$KANBOARD_ADMIN_PASSWORD" "$MY_USERNAME"
171 173
 }
172 174
 
173 175
 function reconfigure_kanboard {
@@ -180,40 +182,40 @@ function upgrade_kanboard {
180 182
         return
181 183
     fi
182 184
 
183
-    if grep -q "kanboard domain" $COMPLETION_FILE; then
185
+    if grep -q "kanboard domain" "$COMPLETION_FILE"; then
184 186
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
185 187
     fi
186 188
 
187 189
     # update to the next commit
188 190
     function_check set_repo_commit
189
-    set_repo_commit /var/www/$KANBOARD_DOMAIN_NAME/htdocs "kanboard commit" "$KANBOARD_COMMIT" $KANBOARD_REPO
191
+    set_repo_commit "/var/www/$KANBOARD_DOMAIN_NAME/htdocs" "kanboard commit" "$KANBOARD_COMMIT" $KANBOARD_REPO
190 192
 
191
-    chown -R www-data:www-data /var/www/${KANBOARD_DOMAIN_NAME}/htdocs
193
+    chown -R www-data:www-data "/var/www/${KANBOARD_DOMAIN_NAME}/htdocs"
192 194
 }
193 195
 
194 196
 
195 197
 function backup_local_kanboard {
196 198
     KANBOARD_DOMAIN_NAME='kanboard'
197
-    if grep -q "kanboard domain" $COMPLETION_FILE; then
199
+    if grep -q "kanboard domain" "$COMPLETION_FILE"; then
198 200
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
199 201
     fi
200 202
 
201 203
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/backup
202
-    if [ ! -d $source_directory ]; then
203
-        mkdir $source_directory
204
+    if [ ! -d "$source_directory" ]; then
205
+        mkdir "$source_directory"
204 206
     fi
205
-    cp -p /var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.php $source_directory
207
+    cp -p "/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.php" "$source_directory"
206 208
 
207 209
     function_check suspend_site
208
-    suspend_site ${KANBOARD_DOMAIN_NAME}
210
+    suspend_site "${KANBOARD_DOMAIN_NAME}"
209 211
 
210 212
     function_check backup_directory_to_usb
211 213
     dest_directory=kanboardconfig
212
-    backup_directory_to_usb $source_directory $dest_directory
214
+    backup_directory_to_usb "$source_directory" "$dest_directory"
213 215
 
214 216
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/data
215 217
     dest_directory=kanboardfile
216
-    backup_directory_to_usb $source_directory $dest_directory
218
+    backup_directory_to_usb "$source_directory" "$dest_directory"
217 219
 
218 220
     function_check backup_database_to_usb
219 221
     backup_database_to_usb kanboard
@@ -223,11 +225,11 @@ function backup_local_kanboard {
223 225
 }
224 226
 
225 227
 function restore_local_kanboard {
226
-    if ! grep -q "kanboard domain" $COMPLETION_FILE; then
228
+    if ! grep -q "kanboard domain" "$COMPLETION_FILE"; then
227 229
         return
228 230
     fi
229 231
     KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
230
-    if [ $KANBOARD_DOMAIN_NAME ]; then
232
+    if [ "$KANBOARD_DOMAIN_NAME" ]; then
231 233
         echo $"Restoring kanboard"
232 234
         temp_restore_dir=/root/tempkanboard
233 235
         kanboard_dir=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs
@@ -243,30 +245,30 @@ function restore_local_kanboard {
243 245
         function_check restore_directory_from_usb
244 246
         restore_directory_from_usb $temp_restore_dir kanboardconfig
245 247
         if [ -d $temp_restore_dir ]; then
246
-            if [ -d $temp_restore_dir$kanboard_dir/backup ]; then
247
-                cp $temp_restore_dir$kanboard_dir/backup/config.php $kanboard_dir/
248
+            if [ -d "$temp_restore_dir$kanboard_dir/backup" ]; then
249
+                cp "$temp_restore_dir$kanboard_dir/backup/config.php" "$kanboard_dir/"
248 250
             else
249
-                cp $temp_restore_dir/config.php $kanboard_dir/
251
+                cp "$temp_restore_dir/config.php" "$kanboard_dir/"
250 252
             fi
251
-            chown www-data:www-data $kanboard_dir/config.php
253
+            chown www-data:www-data "$kanboard_dir/config.php"
252 254
             rm -rf $temp_restore_dir
253 255
         fi
254 256
 
255 257
         restore_directory_from_usb $temp_restore_dir kanboardfile
256 258
         if [ -d $temp_restore_dir ]; then
257
-            if [ -d $temp_restore_dir$kanboard_dir/data ]; then
258
-                cp -rp $temp_restore_dir$kanboard_dir/data $kanboard_dir/
259
+            if [ -d "$temp_restore_dir$kanboard_dir/data" ]; then
260
+                cp -rp "$temp_restore_dir$kanboard_dir/data" "$kanboard_dir/"
259 261
             else
260
-                if [ ! -d $kanboard_dir/data ]; then
261
-                    mkdir $kanboard_dir/data
262
+                if [ ! -d "$kanboard_dir/data" ]; then
263
+                    mkdir "$kanboard_dir/data"
262 264
                 fi
263
-                cp -rp $temp_restore_dir/* $kanboard_dir/data/
265
+                cp -rp "$temp_restore_dir/*" "$kanboard_dir/data/"
264 266
             fi
265
-            chown -R www-data:www-data $kanboard_dir/data
267
+            chown -R www-data:www-data "$kanboard_dir/data"
266 268
             rm -rf $temp_restore_dir
267 269
         fi
268 270
 
269
-        kanboard_update_after_restore kanboard ${KANBOARD_DOMAIN_NAME}
271
+        kanboard_update_after_restore kanboard "${KANBOARD_DOMAIN_NAME}"
270 272
 
271 273
         echo $"Restore of kanboard complete"
272 274
     fi
@@ -274,26 +276,26 @@ function restore_local_kanboard {
274 276
 
275 277
 function backup_remote_kanboard {
276 278
     KANBOARD_DOMAIN_NAME='kanboard'
277
-    if grep -q "kanboard domain" $COMPLETION_FILE; then
279
+    if grep -q "kanboard domain" "$COMPLETION_FILE"; then
278 280
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
279 281
     fi
280 282
 
281 283
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/backup
282
-    if [ ! -d $source_directory ]; then
283
-        mkdir $source_directory
284
+    if [ ! -d "$source_directory" ]; then
285
+        mkdir "$source_directory"
284 286
     fi
285
-    cp -p /var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.php $source_directory
287
+    cp -p "/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.php" "$source_directory"
286 288
 
287 289
     function_check suspend_site
288
-    suspend_site ${KANBOARD_DOMAIN_NAME}
290
+    suspend_site "${KANBOARD_DOMAIN_NAME}"
289 291
 
290 292
     function_check backup_directory_to_friend
291 293
     dest_directory=kanboardconfig
292
-    backup_directory_to_friend $source_directory $dest_directory
294
+    backup_directory_to_friend "$source_directory" "$dest_directory"
293 295
 
294 296
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/data
295 297
     dest_directory=kanboardfile
296
-    backup_directory_to_friend $source_directory $dest_directory
298
+    backup_directory_to_friend "$source_directory" "$dest_directory"
297 299
 
298 300
     function_check backup_database_to_friend
299 301
     backup_database_to_friend kanboard
@@ -303,11 +305,11 @@ function backup_remote_kanboard {
303 305
 }
304 306
 
305 307
 function restore_remote_kanboard {
306
-    if ! grep -q "kanboard domain" $COMPLETION_FILE; then
308
+    if ! grep -q "kanboard domain" "$COMPLETION_FILE"; then
307 309
         return
308 310
     fi
309 311
     KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
310
-    if [ $KANBOARD_DOMAIN_NAME ]; then
312
+    if [ "$KANBOARD_DOMAIN_NAME" ]; then
311 313
         echo $"Restoring kanboard"
312 314
         temp_restore_dir=/root/tempkanboard
313 315
         kanboard_dir=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs
@@ -324,30 +326,30 @@ function restore_remote_kanboard {
324 326
         function_check restore_directory_from_friend
325 327
         restore_directory_from_friend $temp_restore_dir kanboardconfig
326 328
         if [ -d $temp_restore_dir ]; then
327
-            if [ -d $temp_restore_dir$kanboard_dir/backup ]; then
328
-                cp $temp_restore_dir$kanboard_dir/backup/config.php $kanboard_dir/
329
+            if [ -d "$temp_restore_dir$kanboard_dir/backup" ]; then
330
+                cp "$temp_restore_dir$kanboard_dir/backup/config.php" "$kanboard_dir/"
329 331
             else
330
-                cp $temp_restore_dir/config.php $kanboard_dir/
332
+                cp "$temp_restore_dir/config.php" "$kanboard_dir/"
331 333
             fi
332
-            chown www-data:www-data $kanboard_dir/config.php
334
+            chown www-data:www-data "$kanboard_dir/config.php"
333 335
             rm -rf $temp_restore_dir
334 336
         fi
335 337
 
336 338
         restore_directory_from_friend $temp_restore_dir kanboardfile
337 339
         if [ -d $temp_restore_dir ]; then
338
-            if [ -d $temp_restore_dir$kanboard_dir/data ]; then
339
-                cp -rp $temp_restore_dir$kanboard_dir/data $kanboard_dir/
340
+            if [ -d "$temp_restore_dir$kanboard_dir/data" ]; then
341
+                cp -rp "$temp_restore_dir$kanboard_dir/data" "$kanboard_dir/"
340 342
             else
341
-                if [ ! -d $kanboard_dir/data ]; then
342
-                    mkdir $kanboard_dir/data
343
+                if [ ! -d "$kanboard_dir/data" ]; then
344
+                    mkdir "$kanboard_dir/data"
343 345
                 fi
344
-                cp -rp $temp_restore_dir/* $kanboard_dir/data/
346
+                cp -rp "$temp_restore_dir/*" "$kanboard_dir/data/"
345 347
             fi
346
-            chown -R www-data:www-data $kanboard_dir/data
348
+            chown -R www-data:www-data "$kanboard_dir/data"
347 349
             rm -rf $temp_restore_dir
348 350
         fi
349 351
 
350
-        kanboard_update_after_restore kanboard ${KANBOARD_DOMAIN_NAME}
352
+        kanboard_update_after_restore kanboard "${KANBOARD_DOMAIN_NAME}"
351 353
 
352 354
         echo $"Restore of kanboard complete"
353 355
     fi
@@ -360,14 +362,14 @@ function remove_kanboard {
360 362
     read_config_param "KANBOARD_DOMAIN_NAME"
361 363
     read_config_param "MY_USERNAME"
362 364
     echo "Removing $KANBOARD_DOMAIN_NAME"
363
-    nginx_dissite $KANBOARD_DOMAIN_NAME
364
-    remove_certs $KANBOARD_DOMAIN_NAME
365
+    nginx_dissite "$KANBOARD_DOMAIN_NAME"
366
+    remove_certs "$KANBOARD_DOMAIN_NAME"
365 367
 
366
-    if [ -d /var/www/$KANBOARD_DOMAIN_NAME ]; then
367
-        rm -rf /var/www/$KANBOARD_DOMAIN_NAME
368
+    if [ -d "/var/www/$KANBOARD_DOMAIN_NAME" ]; then
369
+        rm -rf "/var/www/$KANBOARD_DOMAIN_NAME"
368 370
     fi
369
-    if [ -f /etc/nginx/sites-available/$KANBOARD_DOMAIN_NAME ]; then
370
-        rm /etc/nginx/sites-available/$KANBOARD_DOMAIN_NAME
371
+    if [ -f "/etc/nginx/sites-available/$KANBOARD_DOMAIN_NAME" ]; then
372
+        rm "/etc/nginx/sites-available/$KANBOARD_DOMAIN_NAME"
371 373
     fi
372 374
     function_check drop_database
373 375
     drop_database kanboard
@@ -375,11 +377,11 @@ function remove_kanboard {
375 377
     remove_onion_service kanboard ${KANBOARD_ONION_PORT}
376 378
     remove_app kanboard
377 379
     remove_completion_param install_kanboard
378
-    sed -i '/kanboard/d' $COMPLETION_FILE
380
+    sed -i '/kanboard/d' "$COMPLETION_FILE"
379 381
     remove_backup_database_local kanboard
380 382
 
381 383
     function_check remove_ddns_domain
382
-    remove_ddns_domain $KANBOARD_DOMAIN_NAME
384
+    remove_ddns_domain "$KANBOARD_DOMAIN_NAME"
383 385
 }
384 386
 
385 387
 function install_kanboard {
@@ -387,12 +389,12 @@ function install_kanboard {
387 389
         ONION_ONLY='no'
388 390
     fi
389 391
 
390
-    if [ ! $KANBOARD_DOMAIN_NAME ]; then
392
+    if [ ! "$KANBOARD_DOMAIN_NAME" ]; then
391 393
         echo $'No domain name was given for kanboard'
392 394
         exit 73478
393 395
     fi
394 396
 
395
-    kanboard_hourly_script kanboard $KANBOARD_DOMAIN_NAME
397
+    kanboard_hourly_script kanboard "$KANBOARD_DOMAIN_NAME"
396 398
 
397 399
     function_check install_mariadb
398 400
     install_mariadb
@@ -406,34 +408,34 @@ function install_kanboard {
406 408
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
407 409
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
408 410
 
409
-    if [ ! -d /var/www/$KANBOARD_DOMAIN_NAME ]; then
410
-        mkdir /var/www/$KANBOARD_DOMAIN_NAME
411
+    if [ ! -d "/var/www/$KANBOARD_DOMAIN_NAME" ]; then
412
+        mkdir "/var/www/$KANBOARD_DOMAIN_NAME"
411 413
     fi
412
-    if [ ! -d /var/www/$KANBOARD_DOMAIN_NAME/htdocs ]; then
414
+    if [ ! -d "/var/www/$KANBOARD_DOMAIN_NAME/htdocs" ]; then
413 415
 
414 416
         if [ -d /repos/kanboard ]; then
415
-            mkdir /var/www/$KANBOARD_DOMAIN_NAME/htdocs
416
-            cp -r -p /repos/kanboard/. /var/www/$KANBOARD_DOMAIN_NAME/htdocs
417
-            cd /var/www/$KANBOARD_DOMAIN_NAME/htdocs
417
+            mkdir "/var/www/$KANBOARD_DOMAIN_NAME/htdocs"
418
+            cp -r -p /repos/kanboard/. "/var/www/$KANBOARD_DOMAIN_NAME/htdocs"
419
+            cd "/var/www/$KANBOARD_DOMAIN_NAME/htdocs" || exit 2468274
418 420
             git pull
419 421
         else
420 422
             function_check git_clone
421
-            git_clone $KANBOARD_REPO /var/www/$KANBOARD_DOMAIN_NAME/htdocs
423
+            git_clone "$KANBOARD_REPO" "/var/www/$KANBOARD_DOMAIN_NAME/htdocs"
422 424
         fi
423 425
 
424
-        if [ ! -d /var/www/$KANBOARD_DOMAIN_NAME/htdocs ]; then
426
+        if [ ! -d "/var/www/$KANBOARD_DOMAIN_NAME/htdocs" ]; then
425 427
             echo $'Unable to clone kanboard repo'
426 428
             exit 89365
427 429
         fi
428 430
     fi
429 431
 
430
-    cd /var/www/$KANBOARD_DOMAIN_NAME/htdocs
432
+    cd "/var/www/$KANBOARD_DOMAIN_NAME/htdocs" || exit 234682642
431 433
     git checkout $KANBOARD_COMMIT -b $KANBOARD_COMMIT
432 434
     set_completion_param "kanboard commit" "$KANBOARD_COMMIT"
433 435
 
434
-    chmod g+w /var/www/$KANBOARD_DOMAIN_NAME/htdocs
435
-    chmod a+w /var/www/$KANBOARD_DOMAIN_NAME/htdocs/data
436
-    chown -R www-data:www-data /var/www/$KANBOARD_DOMAIN_NAME/htdocs
436
+    chmod g+w "/var/www/$KANBOARD_DOMAIN_NAME/htdocs"
437
+    chmod a+w "/var/www/$KANBOARD_DOMAIN_NAME/htdocs/data"
438
+    chown -R www-data:www-data "/var/www/$KANBOARD_DOMAIN_NAME/htdocs"
437 439
 
438 440
     function_check kanboard_create_database
439 441
     kanboard_create_database
@@ -446,118 +448,118 @@ function install_kanboard {
446 448
     fi
447 449
 
448 450
     function_check add_ddns_domain
449
-    add_ddns_domain $KANBOARD_DOMAIN_NAME
451
+    add_ddns_domain "$KANBOARD_DOMAIN_NAME"
450 452
 
451 453
     KANBOARD_ONION_HOSTNAME=$(add_onion_service kanboard 80 ${KANBOARD_ONION_PORT})
452 454
 
453 455
     kanboard_nginx_site=/etc/nginx/sites-available/$KANBOARD_DOMAIN_NAME
454 456
     if [[ $ONION_ONLY == "no" ]]; then
455 457
         function_check nginx_http_redirect
456
-        nginx_http_redirect $KANBOARD_DOMAIN_NAME "index index.php"
457
-        echo 'server {' >> $kanboard_nginx_site
458
-        echo '  listen 443 ssl;' >> $kanboard_nginx_site
459
-        echo '  #listen [::]:443 ssl;' >> $kanboard_nginx_site
460
-        echo "  server_name $KANBOARD_DOMAIN_NAME;" >> $kanboard_nginx_site
461
-        echo '' >> $kanboard_nginx_site
458
+        nginx_http_redirect "$KANBOARD_DOMAIN_NAME" "index index.php"
459
+        { echo 'server {';
460
+          echo '  listen 443 ssl;';
461
+          echo '  #listen [::]:443 ssl;';
462
+          echo "  server_name $KANBOARD_DOMAIN_NAME;";
463
+          echo ''; } >> "$kanboard_nginx_site"
462 464
         function_check nginx_compress
463
-        nginx_compress $KANBOARD_DOMAIN_NAME
464
-        echo '' >> $kanboard_nginx_site
465
-        echo '  # Security' >> $kanboard_nginx_site
465
+        nginx_compress "$KANBOARD_DOMAIN_NAME"
466
+        echo '' >> "$kanboard_nginx_site"
467
+        echo '  # Security' >> "$kanboard_nginx_site"
466 468
         function_check nginx_ssl
467
-        nginx_ssl $KANBOARD_DOMAIN_NAME
469
+        nginx_ssl "$KANBOARD_DOMAIN_NAME"
468 470
 
469 471
         function_check nginx_disable_sniffing
470
-        nginx_disable_sniffing $KANBOARD_DOMAIN_NAME
471
-
472
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $kanboard_nginx_site
473
-        echo '' >> $kanboard_nginx_site
474
-        echo '  # Logs' >> $kanboard_nginx_site
475
-        echo '  access_log /dev/null;' >> $kanboard_nginx_site
476
-        echo '  error_log /dev/null;' >> $kanboard_nginx_site
477
-        echo '' >> $kanboard_nginx_site
478
-        echo '  # Root' >> $kanboard_nginx_site
479
-        echo "  root /var/www/$KANBOARD_DOMAIN_NAME/htdocs;" >> $kanboard_nginx_site
480
-        echo '' >> $kanboard_nginx_site
481
-        echo '  # Index' >> $kanboard_nginx_site
482
-        echo '  index index.php;' >> $kanboard_nginx_site
483
-        echo '' >> $kanboard_nginx_site
484
-        echo '  # PHP' >> $kanboard_nginx_site
485
-        echo '  location ~ \.php {' >> $kanboard_nginx_site
486
-        echo '    include snippets/fastcgi-php.conf;' >> $kanboard_nginx_site
487
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $kanboard_nginx_site
488
-        echo '    fastcgi_read_timeout 30;' >> $kanboard_nginx_site
489
-        echo '  }' >> $kanboard_nginx_site
490
-        echo '' >> $kanboard_nginx_site
491
-        echo '  # Location' >> $kanboard_nginx_site
492
-        echo '  location / {' >> $kanboard_nginx_site
472
+        nginx_disable_sniffing "$KANBOARD_DOMAIN_NAME"
473
+
474
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
475
+          echo '';
476
+          echo '  # Logs';
477
+          echo '  access_log /dev/null;';
478
+          echo '  error_log /dev/null;';
479
+          echo '';
480
+          echo '  # Root';
481
+          echo "  root /var/www/$KANBOARD_DOMAIN_NAME/htdocs;";
482
+          echo '';
483
+          echo '  # Index';
484
+          echo '  index index.php;';
485
+          echo '';
486
+          echo '  # PHP';
487
+          echo '  location ~ \.php {';
488
+          echo '    include snippets/fastcgi-php.conf;';
489
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
490
+          echo '    fastcgi_read_timeout 30;';
491
+          echo '  }';
492
+          echo '';
493
+          echo '  # Location';
494
+          echo '  location / {'; } >> "$kanboard_nginx_site"
493 495
         function_check nginx_limits
494
-        nginx_limits $KANBOARD_DOMAIN_NAME '15m'
495
-        echo '    try_files $uri $uri/ @kanboard;' >> $kanboard_nginx_site
496
-        echo '  }' >> $kanboard_nginx_site
497
-        echo '' >> $kanboard_nginx_site
498
-        echo '  # Fancy URLs' >> $kanboard_nginx_site
499
-        echo '  location @kanboard {' >> $kanboard_nginx_site
500
-        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $kanboard_nginx_site
501
-        echo '  }' >> $kanboard_nginx_site
502
-        echo '' >> $kanboard_nginx_site
503
-        echo '  # Restrict access that is unnecessary anyway' >> $kanboard_nginx_site
504
-        echo '  location ~ /\.(ht|git) {' >> $kanboard_nginx_site
505
-        echo '    deny all;' >> $kanboard_nginx_site
506
-        echo '  }' >> $kanboard_nginx_site
507
-        echo '}' >> $kanboard_nginx_site
496
+        nginx_limits "$KANBOARD_DOMAIN_NAME" '15m'
497
+        { echo "    try_files \$uri \$uri/ @kanboard;";
498
+          echo '  }';
499
+          echo '';
500
+          echo '  # Fancy URLs';
501
+          echo '  location @kanboard {';
502
+          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
503
+          echo '  }';
504
+          echo '';
505
+          echo '  # Restrict access that is unnecessary anyway';
506
+          echo '  location ~ /\.(ht|git) {';
507
+          echo '    deny all;';
508
+          echo '  }';
509
+          echo '}'; } >> "$kanboard_nginx_site"
508 510
     else
509
-        echo -n '' > $kanboard_nginx_site
511
+        echo -n '' > "$kanboard_nginx_site"
510 512
     fi
511
-    echo 'server {' >> $kanboard_nginx_site
512
-    echo "    listen 127.0.0.1:$KANBOARD_ONION_PORT default_server;" >> $kanboard_nginx_site
513
-    echo "    server_name $KANBOARD_ONION_HOSTNAME;" >> $kanboard_nginx_site
514
-    echo '' >> $kanboard_nginx_site
513
+    { echo 'server {';
514
+      echo "    listen 127.0.0.1:$KANBOARD_ONION_PORT default_server;";
515
+      echo "    server_name $KANBOARD_ONION_HOSTNAME;";
516
+      echo ''; } >> "$kanboard_nginx_site"
515 517
     function_check nginx_compress
516
-    nginx_compress $KANBOARD_DOMAIN_NAME
517
-    echo '' >> $kanboard_nginx_site
518
+    nginx_compress "$KANBOARD_DOMAIN_NAME"
519
+    echo '' >> "$kanboard_nginx_site"
518 520
     function_check nginx_disable_sniffing
519
-    nginx_disable_sniffing $KANBOARD_DOMAIN_NAME
520
-    echo '' >> $kanboard_nginx_site
521
-    echo '  # Logs' >> $kanboard_nginx_site
522
-    echo '  access_log /dev/null;' >> $kanboard_nginx_site
523
-    echo '  error_log /dev/null;' >> $kanboard_nginx_site
524
-    echo '' >> $kanboard_nginx_site
525
-    echo '  # Root' >> $kanboard_nginx_site
526
-    echo "  root /var/www/$KANBOARD_DOMAIN_NAME/htdocs;" >> $kanboard_nginx_site
527
-    echo '' >> $kanboard_nginx_site
528
-    echo '  # Index' >> $kanboard_nginx_site
529
-    echo '  index index.php;' >> $kanboard_nginx_site
530
-    echo '' >> $kanboard_nginx_site
531
-    echo '  # PHP' >> $kanboard_nginx_site
532
-    echo '  location ~ \.php {' >> $kanboard_nginx_site
533
-    echo '    include snippets/fastcgi-php.conf;' >> $kanboard_nginx_site
534
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $kanboard_nginx_site
535
-    echo '    fastcgi_read_timeout 30;' >> $kanboard_nginx_site
536
-    echo '  }' >> $kanboard_nginx_site
537
-    echo '' >> $kanboard_nginx_site
538
-    echo '  # Location' >> $kanboard_nginx_site
539
-    echo '  location / {' >> $kanboard_nginx_site
521
+    nginx_disable_sniffing "$KANBOARD_DOMAIN_NAME"
522
+    { echo '';
523
+      echo '  # Logs';
524
+      echo '  access_log /dev/null;';
525
+      echo '  error_log /dev/null;';
526
+      echo '';
527
+      echo '  # Root';
528
+      echo "  root /var/www/$KANBOARD_DOMAIN_NAME/htdocs;";
529
+      echo '';
530
+      echo '  # Index';
531
+      echo '  index index.php;';
532
+      echo '';
533
+      echo '  # PHP';
534
+      echo '  location ~ \.php {';
535
+      echo '    include snippets/fastcgi-php.conf;';
536
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
537
+      echo '    fastcgi_read_timeout 30;';
538
+      echo '  }';
539
+      echo '';
540
+      echo '  # Location';
541
+      echo '  location / {'; } >> "$kanboard_nginx_site"
540 542
     function_check nginx_limits
541
-    nginx_limits $KANBOARD_DOMAIN_NAME '15m'
542
-    echo '    try_files $uri $uri/ @kanboard;' >> $kanboard_nginx_site
543
-    echo '  }' >> $kanboard_nginx_site
544
-    echo '' >> $kanboard_nginx_site
545
-    echo '  # Fancy URLs' >> $kanboard_nginx_site
546
-    echo '  location @kanboard {' >> $kanboard_nginx_site
547
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $kanboard_nginx_site
548
-    echo '  }' >> $kanboard_nginx_site
549
-    echo '' >> $kanboard_nginx_site
550
-    echo '  # Restrict access that is unnecessary anyway' >> $kanboard_nginx_site
551
-    echo '  location ~ /\.(ht|git) {' >> $kanboard_nginx_site
552
-    echo '    deny all;' >> $kanboard_nginx_site
553
-    echo '  }' >> $kanboard_nginx_site
554
-    echo '}' >> $kanboard_nginx_site
543
+    nginx_limits "$KANBOARD_DOMAIN_NAME" '15m'
544
+    { echo "    try_files \$uri \$uri/ @kanboard;";
545
+      echo '  }';
546
+      echo '';
547
+      echo '  # Fancy URLs';
548
+      echo '  location @kanboard {';
549
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
550
+      echo '  }';
551
+      echo '';
552
+      echo '  # Restrict access that is unnecessary anyway';
553
+      echo '  location ~ /\.(ht|git) {';
554
+      echo '    deny all;';
555
+      echo '  }';
556
+      echo '}'; } >> "$kanboard_nginx_site"
555 557
 
556 558
     function_check configure_php
557 559
     configure_php
558 560
 
559 561
     function_check create_site_certificate
560
-    create_site_certificate $KANBOARD_DOMAIN_NAME 'yes'
562
+    create_site_certificate "$KANBOARD_DOMAIN_NAME" 'yes'
561 563
 
562 564
     # Ensure that the database gets backed up locally, if remote
563 565
     # backups are not being used
@@ -568,36 +570,31 @@ function install_kanboard {
568 570
     backup_database_local kanboard
569 571
 
570 572
     function_check nginx_ensite
571
-    nginx_ensite $KANBOARD_DOMAIN_NAME
572
-
573
-    KANBOARD_SERVER=${KANBOARD_DOMAIN_NAME}
574
-    if [[ $ONION_ONLY != 'no' ]]; then
575
-        KANBOARD_SERVER=${KANBOARD_ONION_HOSTNAME}
576
-    fi
573
+    nginx_ensite "$KANBOARD_DOMAIN_NAME"
577 574
 
578 575
     # Create the configuration
579
-    kanboard_configfile=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.php
580
-    cp /var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.default.php $kanboard_configfile
581
-    sed -i "s|define('MAIL_FROM'.*|define('MAIL_FROM', '$MY_EMAIL_ADDRESS');|g" $kanboard_configfile
582
-    sed -i "s|define('DB_DRIVER'.*|define('DB_DRIVER', 'mysql');|g" $kanboard_configfile
583
-    sed -i "s|define('DB_USERNAME'.*|define('DB_USERNAME', 'root');|g" $kanboard_configfile
584
-    sed -i "s|define('DB_PASSWORD'.*|define('DB_PASSWORD', '$MARIADB_PASSWORD');|g" $kanboard_configfile
585
-    sed -i "s|define('DB_HOSTNAME'.*|define('DB_HOSTNAME', 'localhost');|g" $kanboard_configfile
586
-    sed -i "s|define('DB_NAME'.*|define('DB_NAME', 'kanboard');|g" $kanboard_configfile
587
-    sed -i "s|define('DB_PORT'.*|define('DB_PORT', null);|g" $kanboard_configfile
576
+    kanboard_configfile="/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.php"
577
+    cp "/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/config.default.php" "$kanboard_configfile"
578
+    sed -i "s|define('MAIL_FROM'.*|define('MAIL_FROM', '$MY_EMAIL_ADDRESS');|g" "$kanboard_configfile"
579
+    sed -i "s|define('DB_DRIVER'.*|define('DB_DRIVER', 'mysql');|g" "$kanboard_configfile"
580
+    sed -i "s|define('DB_USERNAME'.*|define('DB_USERNAME', 'root');|g" "$kanboard_configfile"
581
+    sed -i "s|define('DB_PASSWORD'.*|define('DB_PASSWORD', '$MARIADB_PASSWORD');|g" "$kanboard_configfile"
582
+    sed -i "s|define('DB_HOSTNAME'.*|define('DB_HOSTNAME', 'localhost');|g" "$kanboard_configfile"
583
+    sed -i "s|define('DB_NAME'.*|define('DB_NAME', 'kanboard');|g" "$kanboard_configfile"
584
+    sed -i "s|define('DB_PORT'.*|define('DB_PORT', null);|g" "$kanboard_configfile"
588 585
     logging_off_kanboard
589 586
 
590
-    initialise_database kanboard /var/www/${KANBOARD_DOMAIN_NAME}/htdocs/app/Schema/Sql/mysql.sql
591
-    chown -R www-data:www-data /var/www/${KANBOARD_DOMAIN_NAME}/htdocs
587
+    initialise_database kanboard "/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/app/Schema/Sql/mysql.sql"
588
+    chown -R www-data:www-data "/var/www/${KANBOARD_DOMAIN_NAME}/htdocs"
592 589
 
593
-    cd /var/www/${KANBOARD_DOMAIN_NAME}/htdocs
590
+    cd "/var/www/${KANBOARD_DOMAIN_NAME}/htdocs" || exit 24582468
594 591
     install_composer
595 592
 
596 593
     systemctl restart mariadb
597 594
     systemctl restart php7.0-fpm
598 595
     systemctl restart nginx
599 596
 
600
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a kanboard -p "$KANBOARD_ADMIN_PASSWORD"
597
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a kanboard -p "$KANBOARD_ADMIN_PASSWORD"
601 598
 
602 599
     set_completion_param "kanboard domain" "$KANBOARD_DOMAIN_NAME"
603 600
 

+ 208
- 201
src/freedombone-app-keyserver Просмотреть файл

@@ -49,7 +49,7 @@ keyserver_variables=(ONION_ONLY
49 49
 function check_keyserver_directory_size {
50 50
     dirsize=$(du /var/lib/sks/DB | awk -F ' ' '{print $1}')
51 51
     # 500M
52
-    if [ $dirsize -gt 500000 ]; then
52
+    if [ "$dirsize" -gt 500000 ]; then
53 53
         echo "1"
54 54
         return
55 55
     fi
@@ -57,7 +57,7 @@ function check_keyserver_directory_size {
57 57
 }
58 58
 
59 59
 function keyserver_watchdog {
60
-    ADMIN_USERNAME=$(cat $COMPLETION_FILE | grep "Admin user" | awk -F ':' '{print $2}')
60
+    ADMIN_USERNAME=$(grep "Admin user" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
61 61
     ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
62 62
     keyserver_size_warning=$"The SKS keyserver database is getting large. Check that you aren't being spammed"
63 63
     keyserver_disabled_warning=$"The SKS keyserver has been disabled because it is getting too large. This is to prevent flooding attacks from crashing the server. You may need to restore the keyserver from backup."
@@ -67,19 +67,19 @@ function keyserver_watchdog {
67 67
 
68 68
     # check database size hourly
69 69
     keyserver_watchdog_script=/tmp/keyserver-watchdog
70
-    echo '#!/bin/bash' > $keyserver_watchdog_script
71
-    echo "dirsize=\$(du /var/lib/sks/DB | awk -F ' ' '{print \$1}')" >> $keyserver_watchdog_script
72
-    echo 'if [ $dirsize -gt 450000 ]; then' >> $keyserver_watchdog_script
73
-
74
-    echo "  echo \"$keyserver_size_warning\" | mail -s \"$keyserver_mail_subject_line\" $ADMIN_EMAIL_ADDRESS" >> $keyserver_watchdog_script
75
-
76
-    echo '  if [ $dirsize -gt 500000 ]; then' >> $keyserver_watchdog_script
77
-    echo "    nginx_dissite $KEYSERVER_DOMAIN_NAME" >> $keyserver_watchdog_script
78
-    echo '    systemctl stop sks' >> $keyserver_watchdog_script
79
-    echo '    systemctl disable sks' >> $keyserver_watchdog_script
80
-    echo "    echo \"$keyserver_disabled_warning\" | mail -s \"$keyserver_mail_subject_line_disabled\" $ADMIN_EMAIL_ADDRESS" >> $keyserver_watchdog_script
81
-    echo '  fi' >> $keyserver_watchdog_script
82
-    echo 'fi' >> $keyserver_watchdog_script
70
+    { echo '#!/bin/bash';
71
+      echo "dirsize=\$(du /var/lib/sks/DB | awk -F ' ' '{print \$1}')";
72
+      echo "if [ \$dirsize -gt 450000 ]; then";
73
+
74
+      echo "  echo \"$keyserver_size_warning\" | mail -s \"$keyserver_mail_subject_line\" $ADMIN_EMAIL_ADDRESS";
75
+
76
+      echo "  if [ \$dirsize -gt 500000 ]; then";
77
+      echo "    nginx_dissite $KEYSERVER_DOMAIN_NAME";
78
+      echo '    systemctl stop sks';
79
+      echo '    systemctl disable sks';
80
+      echo "    echo \"$keyserver_disabled_warning\" | mail -s \"$keyserver_mail_subject_line_disabled\" $ADMIN_EMAIL_ADDRESS";
81
+      echo '  fi';
82
+      echo 'fi'; } > $keyserver_watchdog_script
83 83
     chmod +x $keyserver_watchdog_script
84 84
 
85 85
     if [ ! -f /etc/cron.hourly/keyserver-watchdog ]; then
@@ -102,7 +102,7 @@ function configure_firewall_for_keyserver {
102 102
     firewall_add keyserver 11370 tcp
103 103
     firewall_add keyserver 11371 tcp
104 104
     firewall_add keyserver 11372 tcp
105
-    mark_completed $FUNCNAME
105
+    mark_completed "${FUNCNAME[0]}"
106 106
 }
107 107
 
108 108
 function keyserver_reset_database {
@@ -134,18 +134,18 @@ function upgrade_keyserver {
134 134
         return
135 135
     fi
136 136
 
137
-    if grep -q "keyserver domain" $COMPLETION_FILE; then
137
+    if grep -q "keyserver domain" "$COMPLETION_FILE"; then
138 138
         KEYSERVER_DOMAIN_NAME=$(get_completion_param "keyserver domain")
139 139
     fi
140 140
 
141 141
     # update to the next commit
142 142
     function_check set_repo_commit
143
-    set_repo_commit /var/www/$KEYSERVER_DOMAIN_NAME/htdocs "keyserver web commit" "$KEYSERVER_WEB_COMMIT" $KEYSERVER_WEB_REPO
143
+    set_repo_commit "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs" "keyserver web commit" "$KEYSERVER_WEB_COMMIT" $KEYSERVER_WEB_REPO
144 144
 
145 145
     read_config_param MY_USERNAME
146
-    USER_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
147
-    GPG_ID=$(su -m root -c "gpg --list-keys $USER_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
148
-    if [ ! $GPG_ID ]; then
146
+    USER_EMAIL_ADDRESS="$MY_USERNAME@$HOSTNAME"
147
+    GPG_ID=$(su -m root -c "gpg --list-keys \"$USER_EMAIL_ADDRESS\" | sed -n '2p' | sed 's/^[ \\t]*//'" - "$MY_USERNAME")
148
+    if [ ! "$GPG_ID" ]; then
149 149
         echo $'No GPG ID for admin user'
150 150
         exit 846336
151 151
     fi
@@ -157,17 +157,17 @@ function upgrade_keyserver {
157 157
         echo $'GPG ID not retrieved for admin user due to error'
158 158
         exit 74825
159 159
     fi
160
-    sed -i "s|###ENTERPUBLICKEYHERE###|$GPG_ID|g" /var/www/$KEYSERVER_DOMAIN_NAME/htdocs/404.html
161
-    sed -i "s|###ENTERPUBLICKEYHERE###|$GPG_ID|g" /var/www/$KEYSERVER_DOMAIN_NAME/htdocs/index.html
162
-    sed -i "s|###ENTERNAMEHERE###|$USER_EMAIL_ADDRESS|g" /var/www/$KEYSERVER_DOMAIN_NAME/htdocs/404.html
163
-    sed -i "s|###ENTERNAMEHERE###|$USER_EMAIL_ADDRESS|g" /var/www/$KEYSERVER_DOMAIN_NAME/htdocs/index.html
160
+    sed -i "s|###ENTERPUBLICKEYHERE###|$GPG_ID|g" "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs/404.html"
161
+    sed -i "s|###ENTERPUBLICKEYHERE###|$GPG_ID|g" "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs/index.html"
162
+    sed -i "s|###ENTERNAMEHERE###|$USER_EMAIL_ADDRESS|g" "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs/404.html"
163
+    sed -i "s|###ENTERNAMEHERE###|$USER_EMAIL_ADDRESS|g" "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs/index.html"
164 164
 
165
-    chown -R www-data:www-data /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
165
+    chown -R www-data:www-data "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs"
166 166
 }
167 167
 
168 168
 function backup_local_keyserver {
169 169
     # remove any unused log files
170
-    cd /var/lib/sks/DB
170
+    cd /var/lib/sks/DB || exit 2468245
171 171
     db_archive -d
172 172
 
173 173
     source_directory=/etc/sks
@@ -223,6 +223,7 @@ function restore_local_keyserver {
223 223
         fi
224 224
         cp -r $temp_restore_dir/* /var/lib/sks/DB
225 225
     fi
226
+    # shellcheck disable=SC2181
226 227
     if [ ! "$?" = "0" ]; then
227 228
         # restore the old database
228 229
         rm -rf /var/lib/sks/DB
@@ -243,12 +244,12 @@ function restore_local_keyserver {
243 244
 
244 245
     systemctl enable sks
245 246
     systemctl start sks
246
-    nginx_ensite $KEYSERVER_DOMAIN_NAME
247
+    nginx_ensite "$KEYSERVER_DOMAIN_NAME"
247 248
 }
248 249
 
249 250
 function backup_remote_keyserver {
250 251
     # remove any unused log files
251
-    cd /var/lib/sks/DB
252
+    cd /var/lib/sks/DB || exit 734624
252 253
     db_archive -d
253 254
 
254 255
     source_directory=/etc/sks
@@ -304,6 +305,7 @@ function restore_remote_keyserver {
304 305
         fi
305 306
         cp -r $temp_restore_dir/* /var/lib/sks/DB
306 307
     fi
308
+    # shellcheck disable=SC2181
307 309
     if [ ! "$?" = "0" ]; then
308 310
         # restore the old database
309 311
         rm -rf /var/lib/sks/DB
@@ -322,7 +324,7 @@ function restore_remote_keyserver {
322 324
 
323 325
     systemctl enable sks
324 326
     systemctl start sks
325
-    nginx_ensite $KEYSERVER_DOMAIN_NAME
327
+    nginx_ensite "$KEYSERVER_DOMAIN_NAME"
326 328
 }
327 329
 
328 330
 function remove_keyserver {
@@ -333,21 +335,21 @@ function remove_keyserver {
333 335
     apt-get -qy remove sks dirmngr
334 336
 
335 337
     read_config_param "KEYSERVER_DOMAIN_NAME"
336
-    nginx_dissite $KEYSERVER_DOMAIN_NAME
337
-    remove_certs ${KEYSERVER_DOMAIN_NAME}
338
-    if [ -f /etc/nginx/sites-available/$KEYSERVER_DOMAIN_NAME ]; then
339
-        rm -f /etc/nginx/sites-available/$KEYSERVER_DOMAIN_NAME
338
+    nginx_dissite "$KEYSERVER_DOMAIN_NAME"
339
+    remove_certs "${KEYSERVER_DOMAIN_NAME}"
340
+    if [ -f "/etc/nginx/sites-available/$KEYSERVER_DOMAIN_NAME" ]; then
341
+        rm -f "/etc/nginx/sites-available/$KEYSERVER_DOMAIN_NAME"
340 342
     fi
341
-    if [ -d /var/www/$KEYSERVER_DOMAIN_NAME ]; then
342
-        rm -rf /var/www/$KEYSERVER_DOMAIN_NAME
343
+    if [ -d "/var/www/$KEYSERVER_DOMAIN_NAME" ]; then
344
+        rm -rf "/var/www/$KEYSERVER_DOMAIN_NAME"
343 345
     fi
344 346
     function_check remove_ddns_domain
345
-    remove_ddns_domain $KEYSERVER_DOMAIN_NAME
347
+    remove_ddns_domain "$KEYSERVER_DOMAIN_NAME"
346 348
 
347 349
     remove_config_param KEYSERVER_DOMAIN_NAME
348 350
     remove_config_param KEYSERVER_CODE
349 351
     function_check remove_onion_service
350
-    remove_onion_service keyserver ${KEYSERVER_ONION_PORT}
352
+    remove_onion_service keyserver "${KEYSERVER_ONION_PORT}"
351 353
     remove_onion_service sks 11370 11371 11372
352 354
     remove_completion_param "install_keyserver"
353 355
 
@@ -355,15 +357,15 @@ function remove_keyserver {
355 357
     firewall_remove 11371 tcp
356 358
     firewall_remove 11372 tcp
357 359
 
358
-    sed -i '/keyserver/d' $COMPLETION_FILE
359
-    sed -i '/sks onion/d' $COMPLETION_FILE
360
+    sed -i '/keyserver/d' "$COMPLETION_FILE"
361
+    sed -i '/sks onion/d' "$COMPLETION_FILE"
360 362
     if [ -d /var/lib/sks ]; then
361 363
         rm -rf /var/lib/sks
362 364
     fi
363 365
 }
364 366
 
365 367
 function install_interactive_keyserver {
366
-    if [ ! $ONION_ONLY ]; then
368
+    if [ ! "$ONION_ONLY" ]; then
367 369
         ONION_ONLY='no'
368 370
     fi
369 371
 
@@ -388,12 +390,12 @@ function keyserver_create_membership {
388 390
         return
389 391
     fi
390 392
     systemctl stop sks
391
-    echo $"# List of other $PROJECT_NAME SKS Keyservers to sync with." > /etc/sks/membership
392
-    echo '#' >> /etc/sks/membership
393
-    echo $"# Don't add major keyservers here, because it will take an" >> /etc/sks/membership
394
-    echo $'# Infeasible amount of time to sync and backups will become' >> /etc/sks/membership
395
-    echo $'# absurdly long and probably break your system. You have been warned.' >> /etc/sks/membership
396
-    echo '' >> /etc/sks/membership
393
+    { echo $"# List of other $PROJECT_NAME SKS Keyservers to sync with.";
394
+      echo '#';
395
+      echo $"# Don't add major keyservers here, because it will take an";
396
+      echo $'# Infeasible amount of time to sync and backups will become';
397
+      echo $'# absurdly long and probably break your system. You have been warned.';
398
+      echo ''; } > /etc/sks/membership
397 399
     chown -Rc debian-sks: /etc/sks/membership
398 400
     systemctl start sks
399 401
 }
@@ -403,7 +405,7 @@ function keyserver_import_keys {
403 405
     dialog --title $"Import public keys database" \
404 406
            --backtitle $"Freedombone Control Panel" \
405 407
            --defaultno \
406
-           --yesno $"\nThis will download many gigabytes of data and so depending on your bandwidth it could take several days.\n\nContinue?" 10 60
408
+           --yesno $"\\nThis will download many gigabytes of data and so depending on your bandwidth it could take several days.\\n\\nContinue?" 10 60
407 409
     sel=$?
408 410
     case $sel in
409 411
         1) return;;
@@ -412,36 +414,38 @@ function keyserver_import_keys {
412 414
     if [ ! -d /var/lib/sks/dump ]; then
413 415
         mkdir -p /var/lib/sks/dump
414 416
     fi
415
-    cd /var/lib/sks/dump
417
+    cd /var/lib/sks/dump || exit 59242684
416 418
     echo $'Getting keyserver dump. This may take a few days or longer, so be patient.'
417 419
     rm -rf /var/lib/sks/dump/*
418 420
     KEYSERVER_DUMP_URL="https://keyserver.mattrude.com/dump/$(date +%F)/"
419 421
     wget -crp -e robots=off --level=1 --cut-dirs=3 -nH \
420
-         -A pgp,txt $KEYSERVER_DUMP_URL
422
+         -A pgp,txt "$KEYSERVER_DUMP_URL"
421 423
 
422
-    cd /var/lib/sks
424
+    cd /var/lib/sks || exit 936572424
423 425
     echo $'Building the keyserver database from the downloaded dump'
424 426
     keyserver_reset_database
425 427
 }
426 428
 
427 429
 function keyserver_sync {
428
-    data=$(tempfile 2>/dev/null)
429
-    trap "rm -f $data" 0 1 2 5 15
430
+    data=$(mktemp 2>/dev/null)
430 431
     dialog --backtitle $"Freedombone Control Panel" \
431 432
            --title $"Sync with other keyserver" \
432 433
            --form $"\nEnter details for the other server. Please be aware that it's not a good idea to sync with major keyservers which have exceptionally large databases. This is intended to sync with other $PROJECT_NAME systems each having a small database for a particular community." 16 60 3 \
433 434
            $"Domain:" 1 1 "" 1 25 32 64 \
434 435
            $"Port:" 2 1 "11370" 2 25 6 6 \
435 436
            $"Sync Email (optional):" 3 1 "pgp-public-keys@" 3 25 32 64 \
436
-           2> $data
437
+           2> "$data"
437 438
     sel=$?
438 439
     case $sel in
439
-        1) return;;
440
-        255) return;;
440
+        1) rm -f "$data"
441
+           return;;
442
+        255) rm -f "$data"
443
+             return;;
441 444
     esac
442
-    other_keyserver_domain=$(cat $data | sed -n 1p)
443
-    other_keyserver_port=$(cat $data | sed -n 2p)
444
-    other_keyserver_email=$(cat $data | sed -n 3p)
445
+    other_keyserver_domain=$(sed -n 1p < "$data")
446
+    other_keyserver_port=$(sed -n 2p < "$data")
447
+    other_keyserver_email=$(sed -n 3p < "$data")
448
+    rm -f "$data"
445 449
     if [[ "$other_keyserver_domain" != *'.'* ]]; then
446 450
         return
447 451
     fi
@@ -464,7 +468,7 @@ function keyserver_sync {
464 468
     # Warn if trying to sync
465 469
     if [[ "$other_keyserver_domain" == *"sks-keyservers.net" || "$other_keyserver_domain" == *"gnupg.net" || "$other_keyserver_domain" == *"pgp.com" || "$other_keyserver_domain" == *"pgp.mit.edu" || "$other_keyserver_domain" == *"the.earth.li" || "$other_keyserver_domain" == *"mayfirst.org" || "$other_keyserver_domain" == *"ubuntu.com" ]]; then
466 470
         dialog --title $"Sync with other keyserver" \
467
-               --msgbox $"\nDon't try to sync with the major keyservers. Your system will be overloaded with an infeasible database size." 8 60
471
+               --msgbox $"\\nDon't try to sync with the major keyservers. Your system will be overloaded with an infeasible database size." 8 60
468 472
         return
469 473
     fi
470 474
 
@@ -508,47 +512,50 @@ function keyserver_edit {
508 512
 }
509 513
 
510 514
 function keyserver_remove_key {
511
-    data=$(tempfile 2>/dev/null)
512
-    trap "rm -f $data" 0 1 2 5 15
515
+    data=$(mktemp 2>/dev/null)
513 516
     dialog --title $"Remove a key" \
514 517
            --backtitle $"Freedombone Control Panel" \
515
-           --inputbox $"Enter the ID of the key which you wish to remove:" 12 60 2>$data
518
+           --inputbox $"Enter the ID of the key which you wish to remove:" 12 60 2>"$data"
516 519
     sel=$?
517 520
     case $sel in
518 521
         0)
519
-            remove_key_id=$(<$data)
522
+            remove_key_id=$(<"$data")
520 523
             if [ ${#remove_key_id} -gt 8 ]; then
521
-                sks drop $remove_key_id
524
+                sks drop "$remove_key_id"
522 525
                 dialog --title $"Remove a key" \
523 526
                        --msgbox $"The key was removed" 6 40
524 527
             fi
525 528
             ;;
526 529
     esac
530
+    rm -f "$data"
527 531
 }
528 532
 
529 533
 function configure_interactive_keyserver {
530 534
     while true
531 535
     do
532
-        data=$(tempfile 2>/dev/null)
533
-        trap "rm -f $data" 0 1 2 5 15
536
+        data=$(mktemp 2>/dev/null)
534 537
         dialog --backtitle $"Freedombone Control Panel" \
535 538
                --title $"SKS Keyserver" \
536 539
                --radiolist $"Choose an operation:" 12 70 4 \
537 540
                1 $"Remove a key" off \
538 541
                2 $"Sync with other keyserver" off \
539 542
                3 $"Edit sync keyservers" off \
540
-               4 $"Exit" on 2> $data
543
+               4 $"Exit" on 2> "$data"
541 544
         sel=$?
542 545
         case $sel in
543
-            1) return;;
544
-            255) return;;
546
+            1) rm -f "$data"
547
+               return;;
548
+            255) rm -f "$data"
549
+                 return;;
545 550
         esac
546
-        case $(cat $data) in
551
+        case $(cat "$data") in
547 552
             1) keyserver_remove_key;;
548 553
             2) keyserver_sync;;
549 554
             3) keyserver_edit;;
550
-            4) break;;
555
+            4) rm -f "$data"
556
+               break;;
551 557
         esac
558
+        rm -f "$data"
552 559
     done
553 560
 }
554 561
 
@@ -563,7 +570,7 @@ function install_keyserver {
563 570
         mkdir /var/www/$KEYSERVER_DOMAIN_NAME
564 571
     fi
565 572
 
566
-    cd /var/www/$KEYSERVER_DOMAIN_NAME
573
+    cd "/var/www/$KEYSERVER_DOMAIN_NAME" || exit 25427642847
567 574
     if [ -d /var/www/$KEYSERVER_DOMAIN_NAME/htdocs ]; then
568 575
         rm -rf /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
569 576
     fi
@@ -571,7 +578,7 @@ function install_keyserver {
571 578
     if [ -d /repos/keyserverweb ]; then
572 579
         mkdir htdocs
573 580
         cp -r -p /repos/keyserverweb/. htdocs
574
-        cd htdocs
581
+        cd htdocs || exit 379584659
575 582
         git pull
576 583
     else
577 584
         git_clone $KEYSERVER_WEB_REPO htdocs
@@ -581,14 +588,14 @@ function install_keyserver {
581 588
         exit 6539230
582 589
     fi
583 590
 
584
-    cd /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
591
+    cd "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs" || exit 264824528
585 592
     git checkout $KEYSERVER_WEB_COMMIT -b $KEYSERVER_WEB_COMMIT
586 593
     set_completion_param "keyserver web commit" "$KEYSERVER_WEB_COMMIT"
587 594
 
588 595
 
589 596
     USER_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
590
-    GPG_ID=$(su -m root -c "gpg --list-keys $USER_EMAIL_ADDRESS | sed -n '2p' | sed 's/^[ \t]*//'" - $MY_USERNAME)
591
-    if [ ! $GPG_ID ]; then
597
+    GPG_ID=$(su -m root -c "gpg --list-keys \"$USER_EMAIL_ADDRESS\" | sed -n '2p' | sed 's/^[ \\t]*//'" - "$MY_USERNAME")
598
+    if [ ! "$GPG_ID" ]; then
592 599
         echo $'No GPG ID for admin user'
593 600
         exit 846336
594 601
     fi
@@ -659,11 +666,11 @@ function install_keyserver {
659 666
     chown debian-sks: $sksconf_file
660 667
 
661 668
     if ! grep -q "hidden_service_sks" /etc/tor/torrc; then
662
-        echo 'HiddenServiceDir /var/lib/tor/hidden_service_sks/' >> /etc/tor/torrc
663
-        echo 'HiddenServiceVersion 3' >> /etc/tor/torrc
664
-        echo "HiddenServicePort 11370 127.0.0.1:11370" >> /etc/tor/torrc
665
-        echo "HiddenServicePort 11373 127.0.0.1:11371" >> /etc/tor/torrc
666
-        echo "HiddenServicePort 11372 127.0.0.1:11372" >> /etc/tor/torrc
669
+        { echo 'HiddenServiceDir /var/lib/tor/hidden_service_sks/';
670
+          echo 'HiddenServiceVersion 3';
671
+          echo "HiddenServicePort 11370 127.0.0.1:11370";
672
+          echo "HiddenServicePort 11373 127.0.0.1:11371";
673
+          echo "HiddenServicePort 11372 127.0.0.1:11372"; } >> /etc/tor/torrc
667 674
         echo $'Added onion site for sks'
668 675
     fi
669 676
 
@@ -682,141 +689,141 @@ function install_keyserver {
682 689
     if [[ $ONION_ONLY == "no" ]]; then
683 690
         # NOTE: without http active on port 80 the keyserver doesn't work
684 691
         #       from the commandline
685
-        echo 'server {' > $keyserver_nginx_site
686
-        echo '  listen 80;' >> $keyserver_nginx_site
687
-        echo '  listen 0.0.0.0:11371;' >> $keyserver_nginx_site
688
-        echo '  listen [::]:80;' >> $keyserver_nginx_site
689
-        echo "  server_name $KEYSERVER_DOMAIN_NAME;" >> $keyserver_nginx_site
690
-        echo '' >> $keyserver_nginx_site
691
-        echo '  # Logs' >> $keyserver_nginx_site
692
-        echo '  access_log /dev/null;' >> $keyserver_nginx_site
693
-        echo '  error_log /dev/null;' >> $keyserver_nginx_site
694
-        echo '' >> $keyserver_nginx_site
695
-        echo '  # Root' >> $keyserver_nginx_site
696
-        echo "  root /var/www/$KEYSERVER_DOMAIN_NAME/htdocs;" >> $keyserver_nginx_site
697
-        echo '' >> $keyserver_nginx_site
698
-        echo '  rewrite ^/stats /pks/lookup?op=stats;' >> $keyserver_nginx_site
699
-        echo '  rewrite ^/s/(.*) /pks/lookup?search=$1;' >> $keyserver_nginx_site
700
-        echo '  rewrite ^/search/(.*) /pks/lookup?search=$1;' >> $keyserver_nginx_site
701
-        echo '  rewrite ^/g/(.*) /pks/lookup?op=get&search=$1;' >> $keyserver_nginx_site
702
-        echo '  rewrite ^/get/(.*) /pks/lookup?op=get&search=$1;' >> $keyserver_nginx_site
703
-        echo '  rewrite ^/d/(.*) /pks/lookup?op=get&options=mr&search=$1;' >> $keyserver_nginx_site
704
-        echo '  rewrite ^/download/(.*) /pks/lookup?op=get&options=mr&search=$1;' >> $keyserver_nginx_site
705
-        echo '' >> $keyserver_nginx_site
706
-        echo '  location / {' >> $keyserver_nginx_site
692
+        { echo 'server {';
693
+          echo '  listen 80;';
694
+          echo '  listen 0.0.0.0:11371;';
695
+          echo '  listen [::]:80;';
696
+          echo "  server_name $KEYSERVER_DOMAIN_NAME;";
697
+          echo '';
698
+          echo '  # Logs';
699
+          echo '  access_log /dev/null;';
700
+          echo '  error_log /dev/null;';
701
+          echo '';
702
+          echo '  # Root';
703
+          echo "  root /var/www/$KEYSERVER_DOMAIN_NAME/htdocs;";
704
+          echo '';
705
+          echo '  rewrite ^/stats /pks/lookup?op=stats;';
706
+          echo "  rewrite ^/s/(.*) /pks/lookup?search=\$1;";
707
+          echo "  rewrite ^/search/(.*) /pks/lookup?search=\$1;";
708
+          echo "  rewrite ^/g/(.*) /pks/lookup?op=get&search=\$1;";
709
+          echo "  rewrite ^/get/(.*) /pks/lookup?op=get&search=\$1;";
710
+          echo "  rewrite ^/d/(.*) /pks/lookup?op=get&options=mr&search=\$1;";
711
+          echo "  rewrite ^/download/(.*) /pks/lookup?op=get&options=mr&search=\$1;";
712
+          echo '';
713
+          echo '  location / {'; } > $keyserver_nginx_site
707 714
         function_check nginx_limits
708
-        nginx_limits $KEYSERVER_DOMAIN_NAME '128k'
709
-        echo '  }' >> $keyserver_nginx_site
710
-        echo '' >> $keyserver_nginx_site
711
-        echo '  location /pks {' >> $keyserver_nginx_site
712
-        echo '    proxy_pass         http://127.0.0.1:11373;' >> $keyserver_nginx_site
713
-        echo '    proxy_pass_header  Server;' >> $keyserver_nginx_site
714
-        echo "    add_header         Via \"1.1 $KEYSERVER_DOMAIN_NAME:11371 (nginx)\";" >> $keyserver_nginx_site
715
-        echo '    proxy_ignore_client_abort on;' >> $keyserver_nginx_site
716
-        echo '    client_max_body_size 8m;' >> $keyserver_nginx_site
717
-        echo '    client_body_buffer_size 128k;' >> $keyserver_nginx_site
718
-        echo '  }' >> $keyserver_nginx_site
719
-        echo '}' >> $keyserver_nginx_site
720
-        echo '' >> $keyserver_nginx_site
721
-        echo 'server {' >> $keyserver_nginx_site
722
-        echo '  listen 443 ssl;' >> $keyserver_nginx_site
723
-        echo '  listen 0.0.0.0:11372 ssl;' >> $keyserver_nginx_site
724
-        echo '  #listen [::]:443 ssl;' >> $keyserver_nginx_site
725
-        echo "  server_name $KEYSERVER_DOMAIN_NAME;" >> $keyserver_nginx_site
726
-        echo '' >> $keyserver_nginx_site
727
-        echo '  error_page 404 /404.html;' >> $keyserver_nginx_site
728
-        echo '' >> $keyserver_nginx_site
729
-        echo '  location ~ (.git|LICENSE|readme.md) {' >> $keyserver_nginx_site
730
-        echo '    deny all;' >> $keyserver_nginx_site
731
-        echo '    return 404;' >> $keyserver_nginx_site
732
-        echo '  }' >> $keyserver_nginx_site
733
-        echo '' >> $keyserver_nginx_site
734
-        echo '  # Security' >> $keyserver_nginx_site
715
+        nginx_limits "$KEYSERVER_DOMAIN_NAME" '128k'
716
+        { echo '  }';
717
+          echo '';
718
+          echo '  location /pks {';
719
+          echo '    proxy_pass         http://127.0.0.1:11373;';
720
+          echo '    proxy_pass_header  Server;';
721
+          echo "    add_header         Via \"1.1 $KEYSERVER_DOMAIN_NAME:11371 (nginx)\";";
722
+          echo '    proxy_ignore_client_abort on;';
723
+          echo '    client_max_body_size 8m;';
724
+          echo '    client_body_buffer_size 128k;';
725
+          echo '  }';
726
+          echo '}';
727
+          echo '';
728
+          echo 'server {';
729
+          echo '  listen 443 ssl;';
730
+          echo '  listen 0.0.0.0:11372 ssl;';
731
+          echo '  #listen [::]:443 ssl;';
732
+          echo "  server_name $KEYSERVER_DOMAIN_NAME;";
733
+          echo '';
734
+          echo '  error_page 404 /404.html;';
735
+          echo '';
736
+          echo '  location ~ (.git|LICENSE|readme.md) {';
737
+          echo '    deny all;';
738
+          echo '    return 404;';
739
+          echo '  }';
740
+          echo '';
741
+          echo '  # Security'; } >> $keyserver_nginx_site
735 742
         function_check nginx_ssl
736 743
         nginx_ssl $KEYSERVER_DOMAIN_NAME
737 744
 
738 745
         function_check nginx_disable_sniffing
739 746
         nginx_disable_sniffing $KEYSERVER_DOMAIN_NAME
740 747
 
741
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $keyserver_nginx_site
742
-        echo '' >> $keyserver_nginx_site
743
-        echo '  # Logs' >> $keyserver_nginx_site
744
-        echo '  access_log /dev/null;' >> $keyserver_nginx_site
745
-        echo '  error_log /dev/null;' >> $keyserver_nginx_site
746
-        echo '' >> $keyserver_nginx_site
747
-        echo '  # Root' >> $keyserver_nginx_site
748
-        echo "  root /var/www/$KEYSERVER_DOMAIN_NAME/htdocs;" >> $keyserver_nginx_site
749
-        echo '' >> $keyserver_nginx_site
750
-
751
-        echo '  rewrite ^/stats /pks/lookup?op=stats;' >> $keyserver_nginx_site
752
-        echo '  rewrite ^/s/(.*) /pks/lookup?search=$1;' >> $keyserver_nginx_site
753
-        echo '  rewrite ^/search/(.*) /pks/lookup?search=$1;' >> $keyserver_nginx_site
754
-        echo '  rewrite ^/g/(.*) /pks/lookup?op=get&search=$1;' >> $keyserver_nginx_site
755
-        echo '  rewrite ^/get/(.*) /pks/lookup?op=get&search=$1;' >> $keyserver_nginx_site
756
-        echo '  rewrite ^/d/(.*) /pks/lookup?op=get&options=mr&search=$1;' >> $keyserver_nginx_site
757
-        echo '  rewrite ^/download/(.*) /pks/lookup?op=get&options=mr&search=$1;' >> $keyserver_nginx_site
758
-        echo '' >> $keyserver_nginx_site
759
-        echo '  location / {' >> $keyserver_nginx_site
748
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
749
+          echo '';
750
+          echo '  # Logs';
751
+          echo '  access_log /dev/null;';
752
+          echo '  error_log /dev/null;';
753
+          echo '';
754
+          echo '  # Root';
755
+          echo "  root /var/www/$KEYSERVER_DOMAIN_NAME/htdocs;";
756
+          echo '';
757
+
758
+          echo '  rewrite ^/stats /pks/lookup?op=stats;';
759
+          echo "  rewrite ^/s/(.*) /pks/lookup?search=\$1;";
760
+          echo "  rewrite ^/search/(.*) /pks/lookup?search=\$1;";
761
+          echo "  rewrite ^/g/(.*) /pks/lookup?op=get&search=\$1;";
762
+          echo "  rewrite ^/get/(.*) /pks/lookup?op=get&search=\$1;";
763
+          echo "  rewrite ^/d/(.*) /pks/lookup?op=get&options=mr&search=\$1;";
764
+          echo "  rewrite ^/download/(.*) /pks/lookup?op=get&options=mr&search=\$1;";
765
+          echo '';
766
+          echo '  location / {'; } >> $keyserver_nginx_site
760 767
         function_check nginx_limits
761 768
         nginx_limits $KEYSERVER_DOMAIN_NAME '128k'
762
-        echo '  }' >> $keyserver_nginx_site
763
-        echo '' >> $keyserver_nginx_site
764
-        echo '  location /pks {' >> $keyserver_nginx_site
765
-        echo "    proxy_pass         http://127.0.0.1:11373;" >> $keyserver_nginx_site
766
-        echo '    proxy_pass_header  Server;' >> $keyserver_nginx_site
767
-        echo "    add_header         Via \"1.1 $KEYSERVER_DOMAIN_NAME:11372 (nginx)\";" >> $keyserver_nginx_site
768
-        echo '    proxy_ignore_client_abort on;' >> $keyserver_nginx_site
769
-        echo '    client_max_body_size 8m;' >> $keyserver_nginx_site
770
-        echo '    client_body_buffer_size 128k;' >> $keyserver_nginx_site
771
-        echo '  }' >> $keyserver_nginx_site
772
-        echo '}' >> $keyserver_nginx_site
773
-        echo '' >> $keyserver_nginx_site
769
+        { echo '  }';
770
+          echo '';
771
+          echo '  location /pks {';
772
+          echo "    proxy_pass         http://127.0.0.1:11373;";
773
+          echo '    proxy_pass_header  Server;';
774
+          echo "    add_header         Via \"1.1 $KEYSERVER_DOMAIN_NAME:11372 (nginx)\";";
775
+          echo '    proxy_ignore_client_abort on;';
776
+          echo '    client_max_body_size 8m;';
777
+          echo '    client_body_buffer_size 128k;';
778
+          echo '  }';
779
+          echo '}';
780
+          echo ''; } >> $keyserver_nginx_site
774 781
     else
775 782
         echo -n '' > $keyserver_nginx_site
776 783
     fi
777
-    echo 'server {' >> $keyserver_nginx_site
778
-    echo "  listen 127.0.0.1:$KEYSERVER_ONION_PORT default_server;" >> $keyserver_nginx_site
779
-    echo "  server_name $KEYSERVER_ONION_HOSTNAME;" >> $keyserver_nginx_site
780
-    echo '' >> $keyserver_nginx_site
781
-    echo '  error_page 404 /404.html;' >> $keyserver_nginx_site
782
-    echo '' >> $keyserver_nginx_site
783
-    echo '  location ~ (.git|LICENSE|readme.md) {' >> $keyserver_nginx_site
784
-    echo '    deny all;' >> $keyserver_nginx_site
785
-    echo '    return 404;' >> $keyserver_nginx_site
786
-    echo '  }' >> $keyserver_nginx_site
787
-    echo '' >> $keyserver_nginx_site
784
+    { echo 'server {';
785
+      echo "  listen 127.0.0.1:$KEYSERVER_ONION_PORT default_server;";
786
+      echo "  server_name $KEYSERVER_ONION_HOSTNAME;";
787
+      echo '';
788
+      echo '  error_page 404 /404.html;';
789
+      echo '';
790
+      echo '  location ~ (.git|LICENSE|readme.md) {';
791
+      echo '    deny all;';
792
+      echo '    return 404;';
793
+      echo '  }';
794
+      echo ''; } >> $keyserver_nginx_site
788 795
     function_check nginx_disable_sniffing
789 796
     nginx_disable_sniffing $KEYSERVER_DOMAIN_NAME
790
-    echo '' >> $keyserver_nginx_site
791
-    echo '  # Logs' >> $keyserver_nginx_site
792
-    echo '  access_log /dev/null;' >> $keyserver_nginx_site
793
-    echo '  error_log /dev/null;' >> $keyserver_nginx_site
794
-    echo '' >> $keyserver_nginx_site
795
-    echo '  # Root' >> $keyserver_nginx_site
796
-    echo "  root /var/www/$KEYSERVER_DOMAIN_NAME/mail;" >> $keyserver_nginx_site
797
-    echo '' >> $keyserver_nginx_site
798
-    echo '  rewrite ^/stats /pks/lookup?op=stats;' >> $keyserver_nginx_site
799
-    echo '  rewrite ^/s/(.*) /pks/lookup?search=$1;' >> $keyserver_nginx_site
800
-    echo '  rewrite ^/search/(.*) /pks/lookup?search=$1;' >> $keyserver_nginx_site
801
-    echo '  rewrite ^/g/(.*) /pks/lookup?op=get&search=$1;' >> $keyserver_nginx_site
802
-    echo '  rewrite ^/get/(.*) /pks/lookup?op=get&search=$1;' >> $keyserver_nginx_site
803
-    echo '  rewrite ^/d/(.*) /pks/lookup?op=get&options=mr&search=$1;' >> $keyserver_nginx_site
804
-    echo '  rewrite ^/download/(.*) /pks/lookup?op=get&options=mr&search=$1;' >> $keyserver_nginx_site
805
-    echo '' >> $keyserver_nginx_site
806
-    echo '  location / {' >> $keyserver_nginx_site
797
+    { echo '';
798
+      echo '  # Logs';
799
+      echo '  access_log /dev/null;';
800
+      echo '  error_log /dev/null;';
801
+      echo '';
802
+      echo '  # Root';
803
+      echo "  root /var/www/$KEYSERVER_DOMAIN_NAME/mail;";
804
+      echo '';
805
+      echo '  rewrite ^/stats /pks/lookup?op=stats;';
806
+      echo "  rewrite ^/s/(.*) /pks/lookup?search=\$1;";
807
+      echo "  rewrite ^/search/(.*) /pks/lookup?search=\$1;";
808
+      echo "  rewrite ^/g/(.*) /pks/lookup?op=get&search=\$1;";
809
+      echo "  rewrite ^/get/(.*) /pks/lookup?op=get&search=\$1;";
810
+      echo "  rewrite ^/d/(.*) /pks/lookup?op=get&options=mr&search=\$1;";
811
+      echo "  rewrite ^/download/(.*) /pks/lookup?op=get&options=mr&search=\$1;";
812
+      echo '';
813
+      echo '  location / {'; } >> $keyserver_nginx_site
807 814
     function_check nginx_limits
808 815
     nginx_limits $KEYSERVER_DOMAIN_NAME '128k'
809
-    echo '  }' >> $keyserver_nginx_site
810
-    echo '' >> $keyserver_nginx_site
811
-    echo '  location /pks {' >> $keyserver_nginx_site
812
-    echo "    proxy_pass         http://127.0.0.1:11373;" >> $keyserver_nginx_site
813
-    echo '    proxy_pass_header  Server;' >> $keyserver_nginx_site
814
-    echo "    add_header         Via \"1.1 $KEYSERVER_DOMAIN_NAME:$KEYSERVER_ONION_PORT (nginx)\";" >> $keyserver_nginx_site
815
-    echo '    proxy_ignore_client_abort on;' >> $keyserver_nginx_site
816
-    echo '    client_max_body_size 8m;' >> $keyserver_nginx_site
817
-    echo '    client_body_buffer_size 128k;' >> $keyserver_nginx_site
818
-    echo '  }' >> $keyserver_nginx_site
819
-    echo '}' >> $keyserver_nginx_site
816
+    { echo '  }';
817
+      echo '';
818
+      echo '  location /pks {';
819
+      echo "    proxy_pass         http://127.0.0.1:11373;";
820
+      echo '    proxy_pass_header  Server;';
821
+      echo "    add_header         Via \"1.1 $KEYSERVER_DOMAIN_NAME:$KEYSERVER_ONION_PORT (nginx)\";";
822
+      echo '    proxy_ignore_client_abort on;';
823
+      echo '    client_max_body_size 8m;';
824
+      echo '    client_body_buffer_size 128k;';
825
+      echo '  }';
826
+      echo '}'; } >> $keyserver_nginx_site
820 827
 
821 828
     function_check create_site_certificate
822 829
     if [ ! -f /etc/ssl/certs/${KEYSERVER_DOMAIN_NAME}.pem ]; then

+ 250
- 247
src/freedombone-app-koel Просмотреть файл

@@ -58,7 +58,7 @@ function logging_off_koel {
58 58
 }
59 59
 
60 60
 function koel_remove_gravatar {
61
-    cd /var/www/${KOEL_DOMAIN_NAME}/htdocs
61
+    cd "/var/www/${KOEL_DOMAIN_NAME}/htdocs" || exit 8345374534
62 62
     sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" node_modules/browser-sync-ui/public/js/app.js.map
63 63
     sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" public/js/app.*.js
64 64
     if ! grep -q "//Vue.set(user, 'avatar'" resources/assets/js/stores/user.js; then
@@ -69,19 +69,19 @@ function koel_remove_gravatar {
69 69
 function remove_user_koel {
70 70
     remove_username="$1"
71 71
 
72
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp koel
72
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp koel
73 73
 }
74 74
 
75 75
 function add_user_koel {
76 76
     new_username="$1"
77 77
     new_user_password="$2"
78 78
 
79
-    ${PROJECT_NAME}-pass -u $new_username -a koel -p "$new_user_password"
79
+    "${PROJECT_NAME}-pass" -u "$new_username" -a koel -p "$new_user_password"
80 80
     echo '0'
81 81
 }
82 82
 
83 83
 function install_interactive_koel {
84
-    if [ ! $ONION_ONLY ]; then
84
+    if [ ! "$ONION_ONLY" ]; then
85 85
         ONION_ONLY='no'
86 86
     fi
87 87
 
@@ -91,42 +91,43 @@ function install_interactive_koel {
91 91
         KOEL_DETAILS_COMPLETE=
92 92
         while [ ! $KOEL_DETAILS_COMPLETE ]
93 93
         do
94
-            data=$(tempfile 2>/dev/null)
95
-            trap "rm -f $data" 0 1 2 5 15
94
+            data=$(mktemp 2>/dev/null)
96 95
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
97 96
                 dialog --backtitle $"Freedombone Configuration" \
98 97
                        --title $"Koel Configuration" \
99
-                       --form $"\nPlease enter your Koel details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
98
+                       --form $"\\nPlease enter your Koel details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
100 99
                        $"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
101 100
                        $"Code:" 2 1 "$(grep 'KOEL_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
102
-                       2> $data
101
+                       2> "$data"
103 102
             else
104 103
                 dialog --backtitle $"Freedombone Configuration" \
105 104
                        --title $"Koel Configuration" \
106
-                       --form $"\nPlease enter your Koel details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
105
+                       --form $"\\nPlease enter your Koel details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
107 106
                        $"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
108
-                       2> $data
107
+                       2> "$data"
109 108
             fi
110 109
             sel=$?
111 110
             case $sel in
112
-                1) exit 1;;
113
-                255) exit 1;;
111
+                1) rm -f "$data"
112
+                   exit 1;;
113
+                255) rm -f "$data"
114
+                     exit 1;;
114 115
             esac
115
-            KOEL_DOMAIN_NAME=$(cat $data | sed -n 1p)
116
-            if [ $KOEL_DOMAIN_NAME ]; then
117
-                if [[ $KOEL_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
116
+            KOEL_DOMAIN_NAME=$(sed -n 1p < "$data")
117
+            if [ "$KOEL_DOMAIN_NAME" ]; then
118
+                if [[ "$KOEL_DOMAIN_NAME" == "$HUBZILLA_DOMAIN_NAME" ]]; then
118 119
                     KOEL_DOMAIN_NAME=""
119 120
                 fi
120 121
                 TEST_DOMAIN_NAME=$KOEL_DOMAIN_NAME
121 122
                 validate_domain_name
122
-                if [[ $TEST_DOMAIN_NAME != $KOEL_DOMAIN_NAME ]]; then
123
+                if [[ "$TEST_DOMAIN_NAME" != "$KOEL_DOMAIN_NAME" ]]; then
123 124
                     KOEL_DOMAIN_NAME=
124 125
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
125 126
                 else
126 127
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
127
-                        KOEL_CODE=$(cat $data | sed -n 2p)
128
+                        KOEL_CODE=$(sed -n 2p < "$data")
128 129
                         validate_freedns_code "$KOEL_CODE"
129
-                        if [ ! $VALID_CODE ]; then
130
+                        if [ ! "$VALID_CODE" ]; then
130 131
                             KOEL_DOMAIN_NAME=
131 132
                         fi
132 133
                     fi
@@ -135,6 +136,7 @@ function install_interactive_koel {
135 136
             if [ $KOEL_DOMAIN_NAME ]; then
136 137
                 KOEL_DETAILS_COMPLETE="yes"
137 138
             fi
139
+            rm -f "$data"
138 140
         done
139 141
 
140 142
         # save the results in the config file
@@ -150,23 +152,23 @@ function change_password_koel {
150 152
 
151 153
     read_config_param 'KOEL_DOMAIN_NAME'
152 154
 
153
-    ${PROJECT_NAME}-pass -u "$curr_username" -a koel -p "$new_user_password"
155
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a koel -p "$new_user_password"
154 156
 }
155 157
 
156 158
 function koel_create_database {
157
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
158
-        KOEL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
159
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
160
+        KOEL_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
159 161
     else
160
-        if [ ! $KOEL_ADMIN_PASSWORD ]; then
161
-            KOEL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
162
+        if [ ! "$KOEL_ADMIN_PASSWORD" ]; then
163
+            KOEL_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
162 164
         fi
163 165
     fi
164
-    if [ ! $KOEL_ADMIN_PASSWORD ]; then
166
+    if [ ! "$KOEL_ADMIN_PASSWORD" ]; then
165 167
         return
166 168
     fi
167 169
 
168 170
     function_check create_database
169
-    create_database koel "$KOEL_ADMIN_PASSWORD" $MY_USERNAME
171
+    create_database koel "$KOEL_ADMIN_PASSWORD" "$MY_USERNAME"
170 172
 }
171 173
 
172 174
 function reconfigure_koel {
@@ -174,14 +176,14 @@ function reconfigure_koel {
174 176
 }
175 177
 
176 178
 function koel_import_from_directory {
177
-    data=$(tempfile 2>/dev/null)
178
-    dialog --title "Choose a directory containing music" --dselect /home/$MY_USERNAME/ 30 60 2> $data
179
-    selected_dir=$(cat $data)
180
-    rm $data
179
+    data=$(mktemp 2>/dev/null)
180
+    dialog --title "Choose a directory containing music" --dselect "/home/$MY_USERNAME/" 30 60 2> "$data"
181
+    selected_dir=$(cat "$data")
182
+    rm -f "$data"
181 183
     if [[ "$selected_dir" == '/music' ]]; then
182 184
         return
183 185
     fi
184
-    if [ ! -d $selected_dir ]; then
186
+    if [ ! -d "$selected_dir" ]; then
185 187
         return
186 188
     fi
187 189
     if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
@@ -197,7 +199,7 @@ function koel_import_from_directory {
197 199
     dialog --title $"Import music directory" \
198 200
            --backtitle $"Freedombone Control Panel" \
199 201
            --defaultno \
200
-           --yesno $"\nImport the directory:\n\n  $selected_dir" 12 75
202
+           --yesno $"\\nImport the directory:\\n\\n  $selected_dir" 12 75
201 203
     sel=$?
202 204
     case $sel in
203 205
         1) return;;
@@ -214,18 +216,18 @@ function koel_import_from_usb {
214 216
     clear
215 217
     detect_usb_drive
216 218
 
217
-    if [ ! -b $USB_DRIVE ]; then
219
+    if [ ! -b "$USB_DRIVE" ]; then
218 220
         dialog --title $"Import music from USB drive" --msgbox $'No USB drive found' 6 50
219 221
         return
220 222
     fi
221 223
 
222
-    backup_mount_drive ${USB_DRIVE}
223
-    if [ ! -d $USB_MOUNT/Music ]; then
224
+    backup_mount_drive "${USB_DRIVE}"
225
+    if [ ! -d "$USB_MOUNT/Music" ]; then
224 226
         dialog --title $"Import music from USB drive" --msgbox $'No Music directory found on USB drive' 6 50
225
-        backup_unmount_drive ${USB_DRIVE}
227
+        backup_unmount_drive "${USB_DRIVE}"
226 228
     fi
227
-    cp -ru $USB_MOUNT/Music/* /music
228
-    backup_unmount_drive ${USB_DRIVE}
229
+    cp -ru "$USB_MOUNT/Music/*" /music
230
+    backup_unmount_drive "${USB_DRIVE}"
229 231
     dialog --title $"Import music from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
230 232
 }
231 233
 
@@ -233,28 +235,26 @@ function koel_export_to_usb {
233 235
     clear
234 236
     detect_usb_drive
235 237
 
236
-    if [ ! -b $USB_DRIVE ]; then
238
+    if [ ! -b "$USB_DRIVE" ]; then
237 239
         dialog --title $"Export music to USB drive" --msgbox $'No USB drive found' 6 50
238 240
         return
239 241
     fi
240 242
 
241
-    backup_mount_drive ${USB_DRIVE}
242
-    if [ ! -d $USB_MOUNT/Music ]; then
243
-        mkdir -p $USB_MOUNT/Music
243
+    backup_mount_drive "${USB_DRIVE}"
244
+    if [ ! -d "$USB_MOUNT/Music" ]; then
245
+        mkdir -p "$USB_MOUNT/Music"
244 246
     fi
245
-    cp -ru /music/* $USB_MOUNT/Music
246
-    backup_unmount_drive ${USB_DRIVE}
247
+    cp -ru /music/* "$USB_MOUNT/Music"
248
+    backup_unmount_drive "${USB_DRIVE}"
247 249
     dialog --title $"Export music to USB drive" --msgbox $'Export complete. You may now remove the USB drive' 6 50
248 250
 }
249 251
 
250 252
 function format_music_drive {
251 253
     detect_usb_drive
252
-    data=$(tempfile 2>/dev/null)
253
-    trap "rm -f $data" 0 1 2 5 15
254 254
     dialog --title $"Format USB drive $USB_DRIVE for music storage" \
255 255
            --backtitle $"Freedombone Control Panel" \
256 256
            --defaultno \
257
-           --yesno $"\nPlease confirm that you wish to format drive\n\n    ${USB_DRIVE}\n\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\n\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
257
+           --yesno $"\\nPlease confirm that you wish to format drive\\n\\n    ${USB_DRIVE}\\n\\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\\n\\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
258 258
     sel=$?
259 259
     case $sel in
260 260
         1) return;;
@@ -265,7 +265,7 @@ function format_music_drive {
265 265
     echo ''
266 266
     echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
267 267
     echo ''
268
-    ${PROJECT_NAME}-format $USB_DRIVE
268
+    "${PROJECT_NAME}-format" "$USB_DRIVE"
269 269
     dialog --title $"Format USB drive $USB_DRIVE for music storage" --msgbox $'Format complete. You may now export music or remove the USB drive' 6 50
270 270
 }
271 271
 
@@ -273,8 +273,7 @@ function format_music_drive {
273 273
 function configure_interactive_koel {
274 274
     while true
275 275
     do
276
-        data=$(tempfile 2>/dev/null)
277
-        trap "rm -f $data" 0 1 2 5 15
276
+        data=$(mktemp 2>/dev/null)
278 277
         dialog --backtitle $"Freedombone Control Panel" \
279 278
                --title $"Koel" \
280 279
                --radiolist $"Choose an operation:" 12 70 5 \
@@ -282,24 +281,28 @@ function configure_interactive_koel {
282 281
                2 $"Import music from USB drive" off \
283 282
                3 $"Export music to USB drive" off \
284 283
                4 $"Format a USB drive for music storage" off \
285
-               5 $"Exit" on 2> $data
284
+               5 $"Exit" on 2> "$data"
286 285
         sel=$?
287 286
         case $sel in
288
-            1) break;;
289
-            255) break;;
287
+            1) rm -f "$data"
288
+               break;;
289
+            255) rm -f "$data"
290
+                 break;;
290 291
         esac
291
-        case $(cat $data) in
292
+        case $(cat "$data") in
292 293
             1) koel_import_from_directory;;
293 294
             2) koel_import_from_usb;;
294 295
             3) koel_export_to_usb;;
295 296
             4) format_music_drive;;
296
-            5) break;;
297
+            5) rm -f "$data"
298
+               break;;
297 299
         esac
300
+        rm -f "$data"
298 301
     done
299 302
 }
300 303
 
301 304
 function upgrade_koel {
302
-    if grep -q "koel domain" $COMPLETION_FILE; then
305
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
303 306
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
304 307
     fi
305 308
 
@@ -312,12 +315,12 @@ function upgrade_koel {
312 315
 
313 316
     # update to the next commit
314 317
     function_check set_repo_commit
315
-    set_repo_commit /var/www/$KOEL_DOMAIN_NAME/htdocs "koel commit" "$KOEL_COMMIT" $KOEL_REPO
318
+    set_repo_commit "/var/www/$KOEL_DOMAIN_NAME/htdocs" "koel commit" "$KOEL_COMMIT" $KOEL_REPO
316 319
 
317
-    cd /var/www/${KOEL_DOMAIN_NAME}/htdocs
320
+    cd "/var/www/${KOEL_DOMAIN_NAME}/htdocs" || exit 7345346358
318 321
     php artisan koel:init
319 322
     koel_remove_gravatar
320
-    chown -R www-data:www-data *
323
+    chown -R www-data:www-data "/var/www/${KOEL_DOMAIN_NAME}/htdocs/*"
321 324
 
322 325
     systemctl start koel
323 326
 }
@@ -325,20 +328,20 @@ function upgrade_koel {
325 328
 
326 329
 function backup_local_koel {
327 330
     KOEL_DOMAIN_NAME='koel'
328
-    if grep -q "koel domain" $COMPLETION_FILE; then
331
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
329 332
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
330 333
     fi
331 334
 
332
-    source_directory=/var/www/${KOEL_DOMAIN_NAME}/htdocs
333
-    if [ -d $source_directory ]; then
335
+    source_directory="/var/www/${KOEL_DOMAIN_NAME}/htdocs"
336
+    if [ -d "$source_directory" ]; then
334 337
         systemctl stop koel
335 338
 
336 339
         dest_directory=koel
337 340
         function_check suspend_site
338
-        suspend_site ${KOEL_DOMAIN_NAME}
341
+        suspend_site "${KOEL_DOMAIN_NAME}"
339 342
 
340 343
         function_check backup_directory_to_usb
341
-        backup_directory_to_usb $source_directory $dest_directory
344
+        backup_directory_to_usb "$source_directory" "$dest_directory"
342 345
 
343 346
         function_check backup_database_to_usb
344 347
         backup_database_to_usb koel
@@ -351,27 +354,26 @@ function backup_local_koel {
351 354
 }
352 355
 
353 356
 function restore_local_koel {
354
-    if ! grep -q "koel domain" $COMPLETION_FILE; then
357
+    if ! grep -q "koel domain" "$COMPLETION_FILE"; then
355 358
         return
356 359
     fi
357 360
     KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
358
-    if [ $KOEL_DOMAIN_NAME ]; then
361
+    if [ "$KOEL_DOMAIN_NAME" ]; then
359 362
         echo $"Restoring koel"
360 363
         systemctl stop koel
361 364
 
362 365
         temp_restore_dir=/root/tempkoel
363
-        koel_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
364 366
 
365 367
         function_check koel_create_database
366 368
         koel_create_database
367 369
 
368
-        restore_database koel ${KOEL_DOMAIN_NAME}
370
+        restore_database koel "${KOEL_DOMAIN_NAME}"
369 371
         if [ -d $temp_restore_dir ]; then
370 372
             rm -rf $temp_restore_dir
371 373
         fi
372 374
 
373
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
374
-        cd /var/www/$KOEL_DOMAIN_NAME/htdocs
375
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
376
+        cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 274825424
375 377
         sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
376 378
         MARIADB_PASSWORD=
377 379
 
@@ -380,14 +382,14 @@ function restore_local_koel {
380 382
 }
381 383
 
382 384
 function backup_remote_koel {
383
-    if grep -q "koel domain" $COMPLETION_FILE; then
385
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
384 386
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
385 387
         temp_backup_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
386
-        if [ -d $temp_backup_dir ]; then
388
+        if [ -d "$temp_backup_dir" ]; then
387 389
             systemctl stop koel
388 390
 
389 391
             function_check suspend_site
390
-            suspend_site ${KOEL_DOMAIN_NAME}
392
+            suspend_site "${KOEL_DOMAIN_NAME}"
391 393
 
392 394
             function_check backup_database_to_friend
393 395
             backup_database_to_friend koel
@@ -395,7 +397,7 @@ function backup_remote_koel {
395 397
             echo $"Backing up Koel installation"
396 398
 
397 399
             function_check backup_directory_to_friend
398
-            backup_directory_to_friend $temp_backup_dir koel
400
+            backup_directory_to_friend "$temp_backup_dir" koel
399 401
 
400 402
             function_check restart_site
401 403
             restart_site
@@ -408,7 +410,7 @@ function backup_remote_koel {
408 410
 }
409 411
 
410 412
 function restore_remote_koel {
411
-    if grep -q "koel domain" $COMPLETION_FILE; then
413
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
412 414
         echo $"Restoring koel"
413 415
 
414 416
         systemctl stop koel
@@ -419,13 +421,13 @@ function restore_remote_koel {
419 421
         koel_create_database
420 422
 
421 423
         function_check restore_database_from_friend
422
-        restore_database_from_friend koel ${KOEL_DOMAIN_NAME}
424
+        restore_database_from_friend koel "${KOEL_DOMAIN_NAME}"
423 425
         if [ -d /root/tempkoel ]; then
424 426
             rm -rf /root/tempkoel
425 427
         fi
426 428
 
427
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
428
-        cd /var/www/$KOEL_DOMAIN_NAME/htdocs
429
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
430
+        cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 53743682
429 431
         sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
430 432
         MARIADB_PASSWORD=
431 433
 
@@ -453,14 +455,14 @@ function remove_koel {
453 455
     read_config_param "KOEL_DOMAIN_NAME"
454 456
     read_config_param "MY_USERNAME"
455 457
     echo "Removing $KOEL_DOMAIN_NAME"
456
-    nginx_dissite $KOEL_DOMAIN_NAME
457
-    remove_certs $KOEL_DOMAIN_NAME
458
+    nginx_dissite "$KOEL_DOMAIN_NAME"
459
+    remove_certs "$KOEL_DOMAIN_NAME"
458 460
 
459
-    if [ -d /var/www/$KOEL_DOMAIN_NAME ]; then
460
-        rm -rf /var/www/$KOEL_DOMAIN_NAME
461
+    if [ -d "/var/www/$KOEL_DOMAIN_NAME" ]; then
462
+        rm -rf "/var/www/$KOEL_DOMAIN_NAME"
461 463
     fi
462
-    if [ -f /etc/nginx/sites-available/$KOEL_DOMAIN_NAME ]; then
463
-        rm /etc/nginx/sites-available/$KOEL_DOMAIN_NAME
464
+    if [ -f "/etc/nginx/sites-available/$KOEL_DOMAIN_NAME" ]; then
465
+        rm "/etc/nginx/sites-available/$KOEL_DOMAIN_NAME"
464 466
     fi
465 467
     function_check drop_database
466 468
     drop_database koel
@@ -468,15 +470,15 @@ function remove_koel {
468 470
     remove_onion_service koel ${KOEL_ONION_PORT}
469 471
     remove_app koel
470 472
     remove_completion_param install_koel
471
-    sed -i '/koel/d' $COMPLETION_FILE
473
+    sed -i '/koel/d' "$COMPLETION_FILE"
472 474
     remove_backup_database_local koel
473 475
 
474 476
     function_check remove_ddns_domain
475
-    remove_ddns_domain $KOEL_DOMAIN_NAME
477
+    remove_ddns_domain "$KOEL_DOMAIN_NAME"
476 478
 }
477 479
 
478 480
 function install_koel_main {
479
-    if [ ! $KOEL_DOMAIN_NAME ]; then
481
+    if [ ! "$KOEL_DOMAIN_NAME" ]; then
480 482
         echo $'No domain name was given for koel'
481 483
         exit 7359
482 484
     fi
@@ -498,177 +500,186 @@ function install_koel_main {
498 500
     apt-get -yq install php-memcached php-intl exiftool libfcgi0ldbl
499 501
     apt-get -yq install ffmpeg
500 502
 
501
-    if [ ! -d /var/www/$KOEL_DOMAIN_NAME ]; then
502
-        mkdir /var/www/$KOEL_DOMAIN_NAME
503
+    if [ ! -d "/var/www/$KOEL_DOMAIN_NAME" ]; then
504
+        mkdir "/var/www/$KOEL_DOMAIN_NAME"
503 505
     fi
504
-    if [ ! -d /var/www/$KOEL_DOMAIN_NAME/htdocs ]; then
506
+    if [ ! -d "/var/www/$KOEL_DOMAIN_NAME/htdocs" ]; then
505 507
 
506 508
         if [ -d /repos/koel ]; then
507
-            mkdir /var/www/$KOEL_DOMAIN_NAME/htdocs
508
-            cp -r -p /repos/koel/. /var/www/$KOEL_DOMAIN_NAME/htdocs
509
-            cd /var/www/$KOEL_DOMAIN_NAME/htdocs
509
+            mkdir "/var/www/$KOEL_DOMAIN_NAME/htdocs"
510
+            cp -r -p /repos/koel/. "/var/www/$KOEL_DOMAIN_NAME/htdocs"
511
+            cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 23924295
510 512
             git pull
511 513
         else
512 514
             function_check git_clone
513
-            git_clone $KOEL_REPO /var/www/$KOEL_DOMAIN_NAME/htdocs
515
+            git_clone "$KOEL_REPO" "/var/www/$KOEL_DOMAIN_NAME/htdocs"
514 516
         fi
515 517
 
516
-        if [ ! -d /var/www/$KOEL_DOMAIN_NAME/htdocs ]; then
518
+        if [ ! -d "/var/www/$KOEL_DOMAIN_NAME/htdocs" ]; then
517 519
             echo $'Unable to clone koel repo'
518 520
             exit 365735
519 521
         fi
520 522
     fi
521 523
 
522
-    cd /var/www/$KOEL_DOMAIN_NAME/htdocs
523
-    git checkout $KOEL_COMMIT -b $KOEL_COMMIT
524
+    cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 834567242
525
+    git checkout "$KOEL_COMMIT" -b "$KOEL_COMMIT"
524 526
     set_completion_param "koel commit" "$KOEL_COMMIT"
525 527
 
526
-    chown -R www-data:www-data /var/www/$KOEL_DOMAIN_NAME/htdocs
528
+    chown -R www-data:www-data "/var/www/$KOEL_DOMAIN_NAME/htdocs"
527 529
 
528 530
     function_check koel_create_database
529 531
     koel_create_database
530 532
 
531 533
     function_check add_ddns_domain
532
-    add_ddns_domain $KOEL_DOMAIN_NAME
534
+    add_ddns_domain "$KOEL_DOMAIN_NAME"
535
+
536
+    KOEL_ONION_HOSTNAME=$(add_onion_service koel 80 ${KOEL_ONION_PORT})
533 537
 
534 538
     koel_nginx_site=/etc/nginx/sites-available/$KOEL_DOMAIN_NAME
535 539
     if [[ $ONION_ONLY == "no" ]]; then
536 540
         function_check nginx_http_redirect
537
-        nginx_http_redirect $KOEL_DOMAIN_NAME "index index.php"
538
-        echo 'server {' >> $koel_nginx_site
539
-        echo '  listen 443 ssl;' >> $koel_nginx_site
540
-        echo '  #listen [::]:443 ssl;' >> $koel_nginx_site
541
-        echo "  server_name $KOEL_DOMAIN_NAME;" >> $koel_nginx_site
542
-        echo '' >> $koel_nginx_site
541
+        nginx_http_redirect "$KOEL_DOMAIN_NAME" "index index.php"
542
+        { echo 'server {';
543
+          echo '  listen 443 ssl;';
544
+          echo '  #listen [::]:443 ssl;';
545
+          echo "  server_name $KOEL_DOMAIN_NAME;";
546
+          echo ''; } >> "$koel_nginx_site"
543 547
         function_check nginx_compress
544
-        nginx_compress $KOEL_DOMAIN_NAME
545
-        echo '    gzip_comp_level 9;' >> $koel_nginx_site
546
-        echo '' >> $koel_nginx_site
547
-        echo '  # Security' >> $koel_nginx_site
548
+        nginx_compress "$KOEL_DOMAIN_NAME"
549
+        { echo '    gzip_comp_level 9;';
550
+          echo '';
551
+          echo '  # Security'; } >> "$koel_nginx_site"
548 552
         function_check nginx_ssl mobile
549
-        nginx_ssl $KOEL_DOMAIN_NAME
553
+        nginx_ssl "$KOEL_DOMAIN_NAME"
550 554
 
551 555
         function_check nginx_disable_sniffing
552
-        nginx_disable_sniffing $KOEL_DOMAIN_NAME
553
-
554
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $koel_nginx_site
555
-        echo '' >> $koel_nginx_site
556
-        echo '  # Logs' >> $koel_nginx_site
557
-        echo '  access_log /dev/null;' >> $koel_nginx_site
558
-        echo '  error_log /dev/null;' >> $koel_nginx_site
559
-        echo '' >> $koel_nginx_site
560
-        echo '  # Root' >> $koel_nginx_site
561
-        echo "  root /var/www/$KOEL_DOMAIN_NAME/htdocs;" >> $koel_nginx_site
562
-        echo '' >> $koel_nginx_site
563
-        echo '  # Index' >> $koel_nginx_site
564
-        echo '  index index.php;' >> $koel_nginx_site
565
-        echo '' >> $koel_nginx_site
566
-        echo '  # Whitelist only index.php, robots.txt, and those start with public/ or api/' >> $koel_nginx_site
567
-        echo '  if ($request_uri !~ ^/$|index\.php|robots\.txt|api/|public/) {' >> $koel_nginx_site
568
-        echo '    return 404;' >> $koel_nginx_site
569
-        echo '  }' >> $koel_nginx_site
570
-        echo '' >> $koel_nginx_site
571
-        echo '  location /media/ {' >> $koel_nginx_site
572
-        echo '    internal;' >> $koel_nginx_site
573
-        echo '' >> $koel_nginx_site
574
-        echo '    # A X-Media-Root should be set to media_path settings from upstream' >> $koel_nginx_site
575
-        echo '    alias       $upstream_http_x_media_root;' >> $koel_nginx_site
576
-        echo '' >> $koel_nginx_site
577
-        echo '  }' >> $koel_nginx_site
578
-        echo '' >> $koel_nginx_site
579
-        echo '  # PHP' >> $koel_nginx_site
580
-        echo '  location ~ \.php {' >> $koel_nginx_site
581
-        echo '    include snippets/fastcgi-php.conf;' >> $koel_nginx_site
582
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $koel_nginx_site
583
-        echo '    fastcgi_read_timeout 30;' >> $koel_nginx_site
584
-        echo '  }' >> $koel_nginx_site
585
-        echo '' >> $koel_nginx_site
586
-        echo '  # Location' >> $koel_nginx_site
587
-        echo '  location / {' >> $koel_nginx_site
556
+        nginx_disable_sniffing "$KOEL_DOMAIN_NAME"
557
+
558
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
559
+          echo '';
560
+          echo '  # Logs';
561
+          echo '  access_log /dev/null;';
562
+          echo '  error_log /dev/null;';
563
+          echo '';
564
+          echo '  # Root';
565
+          echo "  root /var/www/$KOEL_DOMAIN_NAME/htdocs;";
566
+          echo '';
567
+          echo '  # Index';
568
+          echo '  index index.php;';
569
+          echo '';
570
+          echo '  # Whitelist only index.php, robots.txt, and those start with public/ or api/';
571
+          echo "  if (\$request_uri !~ ^/\$|index\\.php|robots\\.txt|api/|public/) {";
572
+          echo '    return 404;';
573
+          echo '  }';
574
+          echo '';
575
+          echo '  location /media/ {';
576
+          echo '    internal;';
577
+          echo '';
578
+          echo '    # A X-Media-Root should be set to media_path settings from upstream';
579
+          echo "    alias       \$upstream_http_x_media_root;";
580
+          echo '';
581
+          echo '  }';
582
+          echo '';
583
+          echo '  # PHP';
584
+          echo '  location ~ \.php {';
585
+          echo '    include snippets/fastcgi-php.conf;';
586
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
587
+          echo '    fastcgi_read_timeout 30;';
588
+          echo '  }';
589
+          echo '';
590
+          echo '  # Location';
591
+          echo '  location / {'; } >> "$koel_nginx_site"
588 592
         function_check nginx_limits
589
-        nginx_limits $KOEL_DOMAIN_NAME '15m'
590
-        echo '    try_files $uri $uri/ @koel;' >> $koel_nginx_site
591
-        echo '  }' >> $koel_nginx_site
592
-        echo '' >> $koel_nginx_site
593
-        echo '  # Fancy URLs' >> $koel_nginx_site
594
-        echo '  location @koel {' >> $koel_nginx_site
595
-        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $koel_nginx_site
596
-        echo '  }' >> $koel_nginx_site
597
-        echo '' >> $koel_nginx_site
598
-        echo '  # Restrict access that is unnecessary anyway' >> $koel_nginx_site
599
-        echo '  location ~ /\.(ht|git) {' >> $koel_nginx_site
600
-        echo '    deny all;' >> $koel_nginx_site
601
-        echo '  }' >> $koel_nginx_site
602
-        echo '' >> $koel_nginx_site
603
-        echo '}' >> $koel_nginx_site
593
+        nginx_limits "$KOEL_DOMAIN_NAME" '15m'
594
+        { echo "    try_files \$uri \$uri/ @koel;";
595
+          echo '  }';
596
+          echo '';
597
+          echo '  # Fancy URLs';
598
+          echo '  location @koel {';
599
+          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
600
+          echo '  }';
601
+          echo '';
602
+          echo '  # Restrict access that is unnecessary anyway';
603
+          echo '  location ~ /\.(ht|git) {';
604
+          echo '    deny all;';
605
+          echo '  }';
606
+          echo '';
607
+          echo '}'; } >> "$koel_nginx_site"
608
+    else
609
+        echo -n '' > "$koel_nginx_site"
610
+    fi
611
+    if [[ "$ONION_ONLY" == 'no' ]]; then
612
+        { echo 'server {';
613
+          echo "    listen 127.0.0.1:$KOEL_ONION_PORT default_server;";
614
+          echo "    server_name $KOEL_DOMAIN_NAME;";
615
+          echo ''; } >> "$koel_nginx_site"
604 616
     else
605
-        echo -n '' > $koel_nginx_site
617
+        { echo 'server {';
618
+          echo "    listen 127.0.0.1:$KOEL_ONION_PORT default_server;";
619
+          echo "    server_name $KOEL_ONION_HOSTNAME;";
620
+          echo ''; } >> "$koel_nginx_site"
606 621
     fi
607
-    echo 'server {' >> $koel_nginx_site
608
-    echo "    listen 127.0.0.1:$KOEL_ONION_PORT default_server;" >> $koel_nginx_site
609
-    echo "    server_name $KOEL_DOMAIN_NAME;" >> $koel_nginx_site
610
-    echo '' >> $koel_nginx_site
611 622
     function_check nginx_compress
612
-    nginx_compress $KOEL_DOMAIN_NAME
613
-    echo '    gzip_comp_level 9;' >> $koel_nginx_site
614
-    echo '' >> $koel_nginx_site
615
-    echo '  # Logs' >> $koel_nginx_site
616
-    echo '  access_log /dev/null;' >> $koel_nginx_site
617
-    echo '  error_log /dev/null;' >> $koel_nginx_site
618
-    echo '' >> $koel_nginx_site
619
-    echo '  # Root' >> $koel_nginx_site
620
-    echo "  root /var/www/$KOEL_DOMAIN_NAME/htdocs;" >> $koel_nginx_site
621
-    echo '' >> $koel_nginx_site
622
-    echo '  # Index' >> $koel_nginx_site
623
-    echo '  index index.php;' >> $koel_nginx_site
624
-    echo '' >> $koel_nginx_site
625
-    echo '  # Whitelist only index.php, robots.txt, and those start with public/ or api/' >> $koel_nginx_site
626
-    echo '  if ($request_uri !~ ^/$|index\.php|robots\.txt|api/|public/) {' >> $koel_nginx_site
627
-    echo '    return 404;' >> $koel_nginx_site
628
-    echo '  }' >> $koel_nginx_site
629
-    echo '' >> $koel_nginx_site
630
-    echo '  location /media/ {' >> $koel_nginx_site
631
-    echo '    internal;' >> $koel_nginx_site
632
-    echo '' >> $koel_nginx_site
633
-    echo '    # A X-Media-Root should be set to media_path settings from upstream' >> $koel_nginx_site
634
-    echo '    alias       $upstream_http_x_media_root;' >> $koel_nginx_site
635
-    echo '' >> $koel_nginx_site
636
-    echo '  }' >> $koel_nginx_site
637
-    echo '' >> $koel_nginx_site
638
-    echo '  # PHP' >> $koel_nginx_site
639
-    echo '  location ~ \.php {' >> $koel_nginx_site
640
-    echo '    include snippets/fastcgi-php.conf;' >> $koel_nginx_site
641
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $koel_nginx_site
642
-    echo '    fastcgi_read_timeout 30;' >> $koel_nginx_site
643
-    echo '  }' >> $koel_nginx_site
644
-    echo '' >> $koel_nginx_site
645
-    echo '  # Location' >> $koel_nginx_site
646
-    echo '  location / {' >> $koel_nginx_site
623
+    nginx_compress "$KOEL_DOMAIN_NAME"
624
+    { echo '    gzip_comp_level 9;';
625
+      echo '';
626
+      echo '  # Logs';
627
+      echo '  access_log /dev/null;';
628
+      echo '  error_log /dev/null;';
629
+      echo '';
630
+      echo '  # Root';
631
+      echo "  root /var/www/$KOEL_DOMAIN_NAME/htdocs;";
632
+      echo '';
633
+      echo '  # Index';
634
+      echo '  index index.php;';
635
+      echo '';
636
+      echo '  # Whitelist only index.php, robots.txt, and those start with public/ or api/';
637
+      echo "  if (\$request_uri !~ ^/\$|index\\.php|robots\\.txt|api/|public/) {";
638
+      echo '    return 404;';
639
+      echo '  }';
640
+      echo '';
641
+      echo '  location /media/ {';
642
+      echo '    internal;';
643
+      echo '';
644
+      echo '    # A X-Media-Root should be set to media_path settings from upstream';
645
+      echo "    alias       \$upstream_http_x_media_root;";
646
+      echo '';
647
+      echo '  }';
648
+      echo '';
649
+      echo '  # PHP';
650
+      echo '  location ~ \.php {';
651
+      echo '    include snippets/fastcgi-php.conf;';
652
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
653
+      echo '    fastcgi_read_timeout 30;';
654
+      echo '  }';
655
+      echo '';
656
+      echo '  # Location';
657
+      echo '  location / {'; } >> "$koel_nginx_site"
647 658
     function_check nginx_limits
648
-    nginx_limits $KOEL_DOMAIN_NAME '15m'
649
-    echo '    try_files $uri $uri/ @koel;' >> $koel_nginx_site
650
-    echo '  }' >> $koel_nginx_site
651
-    echo '' >> $koel_nginx_site
652
-    echo '  # Fancy URLs' >> $koel_nginx_site
653
-    echo '  location @koel {' >> $koel_nginx_site
654
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $koel_nginx_site
655
-    echo '  }' >> $koel_nginx_site
656
-    echo '' >> $koel_nginx_site
657
-    echo '  # Restrict access that is unnecessary anyway' >> $koel_nginx_site
658
-    echo '  location ~ /\.(ht|git) {' >> $koel_nginx_site
659
-    echo '    deny all;' >> $koel_nginx_site
660
-    echo '  }' >> $koel_nginx_site
661
-    echo '' >> $koel_nginx_site
662
-    echo '}' >> $koel_nginx_site
663
-
664
-    sed -i 's|gzip_types.*|gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;|g' $koel_nginx_site
665
-    sed -i 's|DENY;|SAMEORIGIN;|g' $koel_nginx_site
659
+    nginx_limits "$KOEL_DOMAIN_NAME" '15m'
660
+    { echo "    try_files \$uri \$uri/ @koel;";
661
+      echo '  }';
662
+      echo '';
663
+      echo '  # Fancy URLs';
664
+      echo '  location @koel {';
665
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
666
+      echo '  }';
667
+      echo '';
668
+      echo '  # Restrict access that is unnecessary anyway';
669
+      echo '  location ~ /\.(ht|git) {';
670
+      echo '    deny all;';
671
+      echo '  }';
672
+      echo '';
673
+      echo '}'; } >> "$koel_nginx_site"
674
+
675
+    sed -i 's|gzip_types.*|gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;|g' "$koel_nginx_site"
676
+    sed -i 's|DENY;|SAMEORIGIN;|g' "$koel_nginx_site"
666 677
 
667 678
     function_check configure_php
668 679
     configure_php
669 680
 
670 681
     function_check create_site_certificate
671
-    create_site_certificate $KOEL_DOMAIN_NAME 'yes'
682
+    create_site_certificate "$KOEL_DOMAIN_NAME" 'yes'
672 683
 
673 684
     # Ensure that the database gets backed up locally, if remote
674 685
     # backups are not being used
@@ -679,20 +690,13 @@ function install_koel_main {
679 690
     backup_database_local koel
680 691
 
681 692
     function_check nginx_ensite
682
-    nginx_ensite $KOEL_DOMAIN_NAME
683
-
684
-    KOEL_ONION_HOSTNAME=$(add_onion_service koel 80 ${KOEL_ONION_PORT})
685
-
686
-    KOEL_SERVER=${KOEL_DOMAIN_NAME}
687
-    if [[ $ONION_ONLY != 'no' ]]; then
688
-        KOEL_SERVER=${KOEL_ONION_HOSTNAME}
689
-    fi
693
+    nginx_ensite "$KOEL_DOMAIN_NAME"
690 694
 
691 695
     systemctl restart mariadb
692 696
     systemctl restart php7.0-fpm
693 697
     systemctl restart nginx
694 698
 
695
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a koel -p "$KOEL_ADMIN_PASSWORD"
699
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a koel -p "$KOEL_ADMIN_PASSWORD"
696 700
 
697 701
     set_completion_param "koel domain" "$KOEL_DOMAIN_NAME"
698 702
 
@@ -709,7 +713,7 @@ function install_koel {
709 713
 
710 714
     install_koel_main
711 715
 
712
-    cd /var/www/$KOEL_DOMAIN_NAME/htdocs
716
+    cd "/var/www/$KOEL_DOMAIN_NAME/htdocs" || exit 2432848
713 717
     install_composer
714 718
 
715 719
     npm install -g yarn
@@ -731,30 +735,29 @@ function install_koel {
731 735
     sed -i 's/MAIL_PORT=.*/MAIL_PORT=25/g' .env
732 736
     sed -i 's|FFMPEG_PATH=.*|FFMPEG_PATH=/usr/bin/ffmpeg|g' .env
733 737
 
734
-    php artisan koel:init
735
-    if [ ! "$?" = "0" ]; then
738
+    if ! php artisan koel:init; then
736 739
         echo $"Can't install koel:init"
737 740
         exit 78362
738 741
     fi
739 742
     koel_remove_gravatar
740
-    chown -R www-data:www-data /var/www/$KOEL_DOMAIN_NAME/htdocs
743
+    chown -R www-data:www-data "/var/www/$KOEL_DOMAIN_NAME/htdocs"
741 744
 
742 745
     # daemon
743
-    echo '[Unit]' > /etc/systemd/system/koel.service
744
-    echo 'Description=Koel (music player)' >> /etc/systemd/system/koel.service
745
-    echo 'After=syslog.target' >> /etc/systemd/system/koel.service
746
-    echo 'After=network.target' >> /etc/systemd/system/koel.service
747
-    echo '' >> /etc/systemd/system/koel.service
748
-    echo '[Service]' >> /etc/systemd/system/koel.service
749
-    echo 'Type=simple' >> /etc/systemd/system/koel.service
750
-    echo 'User=www-data' >> /etc/systemd/system/koel.service
751
-    echo 'Group=www-data' >> /etc/systemd/system/koel.service
752
-    echo "WorkingDirectory=/var/www/$KOEL_DOMAIN_NAME/htdocs" >> /etc/systemd/system/koel.service
753
-    echo "ExecStart=/usr/bin/php artisan serve --port=$KOEL_PORT" >> /etc/systemd/system/koel.service
754
-    echo 'Restart=on-failure' >> /etc/systemd/system/koel.service
755
-    echo '' >> /etc/systemd/system/koel.service
756
-    echo '[Install]' >> /etc/systemd/system/koel.service
757
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/koel.service
746
+    { echo '[Unit]';
747
+      echo 'Description=Koel (music player)';
748
+      echo 'After=syslog.target';
749
+      echo 'After=network.target';
750
+      echo '';
751
+      echo '[Service]';
752
+      echo 'Type=simple';
753
+      echo 'User=www-data';
754
+      echo 'Group=www-data';
755
+      echo "WorkingDirectory=/var/www/$KOEL_DOMAIN_NAME/htdocs";
756
+      echo "ExecStart=/usr/bin/php artisan serve --port=$KOEL_PORT";
757
+      echo 'Restart=on-failure';
758
+      echo '';
759
+      echo '[Install]';
760
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/koel.service
758 761
     systemctl enable koel.service
759 762
     systemctl daemon-reload
760 763
     systemctl start koel.service

+ 184
- 184
src/freedombone-app-lychee Просмотреть файл

@@ -55,14 +55,14 @@ function logging_off_lychee {
55 55
 }
56 56
 
57 57
 function lychee_create_database {
58
-    if [ -f ${IMAGE_PASSWORD_FILE} ]; then
59
-        LYCHEE_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
58
+    if [ -f "${IMAGE_PASSWORD_FILE}" ]; then
59
+        LYCHEE_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
60 60
     else
61
-        if [ ! ${LYCHEE_ADMIN_PASSWORD} ]; then
62
-            LYCHEE_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
61
+        if [ ! "${LYCHEE_ADMIN_PASSWORD}" ]; then
62
+            LYCHEE_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
63 63
         fi
64 64
     fi
65
-    if [ ! $LYCHEE_ADMIN_PASSWORD ]; then
65
+    if [ ! "$LYCHEE_ADMIN_PASSWORD" ]; then
66 66
         return
67 67
     fi
68 68
 
@@ -73,7 +73,7 @@ function lychee_create_database {
73 73
 function remove_user_lychee {
74 74
     remove_username="$1"
75 75
 
76
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp lychee
76
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp lychee
77 77
 }
78 78
 
79 79
 function add_user_lychee {
@@ -85,13 +85,13 @@ function add_user_lychee {
85 85
     new_username="$1"
86 86
     new_user_password="$2"
87 87
 
88
-    ${PROJECT_NAME}-pass -u $new_username -a lychee -p "$new_user_password"
88
+    "${PROJECT_NAME}-pass" -u "$new_username" -a lychee -p "$new_user_password"
89 89
 
90 90
     echo '0'
91 91
 }
92 92
 
93 93
 function install_interactive_lychee {
94
-    if [ ! $ONION_ONLY ]; then
94
+    if [ ! "$ONION_ONLY" ]; then
95 95
         ONION_ONLY='no'
96 96
     fi
97 97
 
@@ -110,12 +110,12 @@ function configure_interactive_lychee {
110 110
     get_mariadb_password
111 111
 
112 112
     dialog --title $"Lychee Configuration" \
113
-           --msgbox $"\nYou can initially install the system with:\n\n  Username: root\n  Password: $MARIADB_PASSWORD" 10 70
113
+           --msgbox $"\\nYou can initially install the system with:\\n\\n  Username: root\\n  Password: $MARIADB_PASSWORD" 10 70
114 114
 }
115 115
 
116 116
 
117 117
 function change_password_lychee {
118
-    LYCHEE_USERNAME="$1"
118
+#    LYCHEE_USERNAME="$1"
119 119
     LYCHEE_PASSWORD="$2"
120 120
     if [ ${#LYCHEE_PASSWORD} -lt 8 ]; then
121 121
         echo $'Lychee password is too short'
@@ -143,56 +143,56 @@ function upgrade_lychee {
143 143
 
144 144
 function backup_local_lychee {
145 145
     LYCHEE_DOMAIN_NAME='lychee.local'
146
-    if grep -q "lychee domain" $COMPLETION_FILE; then
146
+    if grep -q "lychee domain" "$COMPLETION_FILE"; then
147 147
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
148 148
     fi
149 149
 
150
-    lychee_path=/var/www/${LYCHEE_DOMAIN_NAME}/htdocs
151
-    if [ -d $lychee_path ]; then
150
+    lychee_path="/var/www/${LYCHEE_DOMAIN_NAME}/htdocs"
151
+    if [ -d "$lychee_path" ]; then
152 152
         function_check backup_database_to_usb
153 153
         backup_database_to_usb lychee
154 154
 
155
-        backup_directory_to_usb $lychee_path lychee
155
+        backup_directory_to_usb "$lychee_path" lychee
156 156
         restart_site
157 157
     fi
158 158
 }
159 159
 
160 160
 function restore_local_lychee {
161 161
     LYCHEE_DOMAIN_NAME='lychee.local'
162
-    if grep -q "lychee domain" $COMPLETION_FILE; then
162
+    if grep -q "lychee domain" "$COMPLETION_FILE"; then
163 163
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
164 164
     fi
165
-    if [ $LYCHEE_DOMAIN_NAME ]; then
166
-        suspend_site ${LYCHEE_DOMAIN_NAME}
165
+    if [ "$LYCHEE_DOMAIN_NAME" ]; then
166
+        suspend_site "${LYCHEE_DOMAIN_NAME}"
167 167
 
168 168
         function_check lychee_create_database
169 169
         lychee_create_database
170 170
 
171 171
         function_check restore_database
172
-        restore_database lychee ${LYCHEE_DOMAIN_NAME}
172
+        restore_database lychee "${LYCHEE_DOMAIN_NAME}"
173 173
 
174
-        if [ -f /var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php ]; then
175
-            MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
176
-            sed -i "s|dbPassword.*|dbPassword = '$MARIADB_PASSWORD';|g" /var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php
174
+        if [ -f "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php" ]; then
175
+            MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
176
+            sed -i "s|dbPassword.*|dbPassword = '$MARIADB_PASSWORD';|g" "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php"
177 177
             MARIADB_PASSWORD=
178 178
         fi
179 179
 
180 180
         restart_site
181
-        chown -R lychee: /var/www/$LYCHEE_DOMAIN_NAME/htdocs/
181
+        chown -R lychee: "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/"
182 182
     fi
183 183
 }
184 184
 
185 185
 function backup_remote_lychee {
186 186
     LYCHEE_DOMAIN_NAME='lychee.local'
187
-    if grep -q "lychee domain" $COMPLETION_FILE; then
187
+    if grep -q "lychee domain" "$COMPLETION_FILE"; then
188 188
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
189 189
     fi
190 190
 
191 191
     temp_backup_dir=/var/www/${LYCHEE_DOMAIN_NAME}/htdocs
192
-    if [ -d $temp_backup_dir ]; then
193
-        suspend_site ${LYCHEE_DOMAIN_NAME}
192
+    if [ -d "$temp_backup_dir" ]; then
193
+        suspend_site "${LYCHEE_DOMAIN_NAME}"
194 194
         backup_database_to_friend lychee
195
-        backup_directory_to_friend $temp_backup_dir lychee
195
+        backup_directory_to_friend "$temp_backup_dir" lychee
196 196
         restart_site
197 197
     else
198 198
         echo $"Lychee domain specified but not found in /var/www/${LYCHEE_DOMAIN_NAME}"
@@ -202,27 +202,27 @@ function backup_remote_lychee {
202 202
 
203 203
 function restore_remote_lychee {
204 204
     LYCHEE_DOMAIN_NAME='lychee.local'
205
-    if grep -q "lychee domain" $COMPLETION_FILE; then
205
+    if grep -q "lychee domain" "$COMPLETION_FILE"; then
206 206
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
207 207
     fi
208 208
 
209
-    suspend_site ${LYCHEE_DOMAIN_NAME}
209
+    suspend_site "${LYCHEE_DOMAIN_NAME}"
210 210
 
211 211
     function_check restore_database_from_friend
212 212
 
213 213
     function_check lychee_create_database
214 214
     lychee_create_database
215 215
 
216
-    restore_database_from_friend lychee ${LYCHEE_DOMAIN_NAME}
216
+    restore_database_from_friend lychee "${LYCHEE_DOMAIN_NAME}"
217 217
 
218
-    if [ -f /var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php ]; then
219
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
220
-        sed -i "s|dbPassword.*|dbPassword = '$MARIADB_PASSWORD';|g" /var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php
218
+    if [ -f "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php" ]; then
219
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
220
+        sed -i "s|dbPassword.*|dbPassword = '$MARIADB_PASSWORD';|g" "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/config.php"
221 221
         MARIADB_PASSWORD=
222 222
     fi
223 223
 
224 224
     restart_site
225
-    chown -R lychee: /var/www/$LYCHEE_DOMAIN_NAME/htdocs/
225
+    chown -R lychee: "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/"
226 226
 }
227 227
 
228 228
 function remove_lychee {
@@ -231,181 +231,181 @@ function remove_lychee {
231 231
     fi
232 232
 
233 233
     read_config_param "LYCHEE_DOMAIN_NAME"
234
-    nginx_dissite $LYCHEE_DOMAIN_NAME
235
-    remove_certs ${LYCHEE_DOMAIN_NAME}
234
+    nginx_dissite "$LYCHEE_DOMAIN_NAME"
235
+    remove_certs "${LYCHEE_DOMAIN_NAME}"
236 236
 
237 237
     drop_database lychee
238 238
     remove_backup_database_local lychee
239 239
 
240
-    if [ -f /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME ]; then
241
-        rm -f /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
240
+    if [ -f "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME" ]; then
241
+        rm -f "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
242 242
     fi
243
-    if [ -d /var/www/$LYCHEE_DOMAIN_NAME ]; then
244
-        rm -rf /var/www/$LYCHEE_DOMAIN_NAME
243
+    if [ -d "/var/www/$LYCHEE_DOMAIN_NAME" ]; then
244
+        rm -rf "/var/www/$LYCHEE_DOMAIN_NAME"
245 245
     fi
246 246
     remove_config_param LYCHEE_DOMAIN_NAME
247 247
     remove_config_param LYCHEE_CODE
248 248
     function_check remove_onion_service
249
-    remove_onion_service lychee ${LYCHEE_ONION_PORT}
249
+    remove_onion_service lychee "${LYCHEE_ONION_PORT}"
250 250
     remove_completion_param "install_lychee"
251
-    sed -i '/Lychee/d' $COMPLETION_FILE
252
-    sed -i '/lychee/d' $COMPLETION_FILE
251
+    sed -i '/Lychee/d' "$COMPLETION_FILE"
252
+    sed -i '/lychee/d' "$COMPLETION_FILE"
253 253
 
254 254
     function_check remove_ddns_domain
255
-    remove_ddns_domain $LYCHEE_DOMAIN_NAME
255
+    remove_ddns_domain "$LYCHEE_DOMAIN_NAME"
256 256
 }
257 257
 
258 258
 function install_lychee_website {
259 259
     function_check nginx_http_redirect
260
-    nginx_http_redirect $LYCHEE_DOMAIN_NAME
261
-    echo 'server {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
262
-    echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
263
-    echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
264
-    echo "    root /var/www/$LYCHEE_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
265
-    echo "    server_name $LYCHEE_DOMAIN_NAME;" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
266
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
267
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
268
-    echo '    index index.html;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
269
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
270
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
260
+    nginx_http_redirect "$LYCHEE_DOMAIN_NAME"
261
+    { echo 'server {';
262
+      echo '    listen 443 ssl;';
263
+      echo '    #listen [::]:443 ssl;';
264
+      echo "    root /var/www/$LYCHEE_DOMAIN_NAME/htdocs;";
265
+      echo "    server_name $LYCHEE_DOMAIN_NAME;";
266
+      echo '    access_log /dev/null;';
267
+      echo "    error_log /dev/null;";
268
+      echo '    index index.html;';
269
+      echo '    charset utf-8;';
270
+      echo '    proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
271 271
     function_check nginx_ssl
272
-    nginx_ssl $LYCHEE_DOMAIN_NAME
272
+    nginx_ssl "$LYCHEE_DOMAIN_NAME"
273 273
     function_check nginx_disable_sniffing
274
-    nginx_disable_sniffing $LYCHEE_DOMAIN_NAME
275
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
276
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
277
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
278
-    echo '    location / {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
274
+    nginx_disable_sniffing "$LYCHEE_DOMAIN_NAME"
275
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
276
+      echo '';
277
+      echo '    # rewrite to front controller as default rule';
278
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
279 279
     function_check nginx_limits
280
-    nginx_limits $LYCHEE_DOMAIN_NAME
281
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
282
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
283
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
284
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
285
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
286
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
287
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
288
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
289
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
290
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
291
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
292
-    echo '        try_files $uri $uri/ /index.html;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
293
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
294
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
295
-    echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
296
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
297
-    echo '        # With php-fpm:' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
298
-    echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
299
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
300
-    echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
301
-    echo '        fastcgi_index index.html;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
302
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
303
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
304
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
305
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
306
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
307
-    echo '        deny all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
308
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
309
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
310
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
311
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
312
-    echo '        deny all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
313
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
314
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
315
-    echo '      deny all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
316
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
317
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
318
-    echo '      deny  all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
319
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
320
-    echo '}' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
321
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
280
+    nginx_limits "$LYCHEE_DOMAIN_NAME"
281
+    { echo '    }';
282
+      echo '';
283
+      echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
284
+      echo '    # or a unix socket';
285
+      echo '    location ~* \.php$ {';
286
+      echo '        # Zero-day exploit defense.';
287
+      echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
288
+      echo "        # Won't work properly (404 error) if the file is not stored on this";
289
+      echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
290
+      echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
291
+      echo "        # another machine. And then cross your fingers that you won't get hacked.";
292
+      echo "        try_files \$uri \$uri/ /index.html;";
293
+      echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
294
+      echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
295
+      echo '        # With php-cgi alone:';
296
+      echo '        # fastcgi_pass 127.0.0.1:9000;';
297
+      echo '        # With php-fpm:';
298
+      echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
299
+      echo '        include fastcgi_params;';
300
+      echo '        fastcgi_read_timeout 30;';
301
+      echo '        fastcgi_index index.html;';
302
+      echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
303
+      echo '    }';
304
+      echo '';
305
+      echo '    # deny access to all dot files';
306
+      echo '    location ~ /\. {';
307
+      echo '        deny all;';
308
+      echo '    }';
309
+      echo '';
310
+      echo '    #deny access to store';
311
+      echo '    location ~ /store {';
312
+      echo '        deny all;';
313
+      echo '    }';
314
+      echo '    location ~ /(data|conf|bin|inc)/ {';
315
+      echo '      deny all;';
316
+      echo '    }';
317
+      echo '    location ~ /\.ht {';
318
+      echo '      deny  all;';
319
+      echo '    }';
320
+      echo '}';
321
+      echo ''; } >> "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
322 322
 }
323 323
 
324 324
 function install_lychee_website_onion {
325
-    echo 'server {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
326
-    echo "    listen 127.0.0.1:${LYCHEE_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
327
-    echo "    root /var/www/$LYCHEE_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
328
-    echo "    server_name $LYCHEE_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
329
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
330
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
331
-    echo '    index index.html;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
332
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
333
-    echo '    proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
325
+    { echo 'server {';
326
+      echo "    listen 127.0.0.1:${LYCHEE_ONION_PORT} default_server;";
327
+      echo "    root /var/www/$LYCHEE_DOMAIN_NAME/htdocs;";
328
+      echo "    server_name $LYCHEE_ONION_HOSTNAME;";
329
+      echo '    access_log /dev/null;';
330
+      echo "    error_log /dev/null;";
331
+      echo '    index index.html;';
332
+      echo '    charset utf-8;';
333
+      echo '    proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
334 334
     function_check nginx_disable_sniffing
335
-    nginx_disable_sniffing $LYCHEE_DOMAIN_NAME
336
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
337
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
338
-    echo '    # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
339
-    echo '    location / {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
335
+    nginx_disable_sniffing "$LYCHEE_DOMAIN_NAME"
336
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
337
+      echo '';
338
+      echo '    # rewrite to front controller as default rule';
339
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
340 340
     function_check nginx_limits
341
-    nginx_limits $LYCHEE_DOMAIN_NAME
342
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
343
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
344
-    echo '    # block these file types' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
345
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
346
-    echo '        deny all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
347
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
348
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
349
-    echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
350
-    echo '    # or a unix socket' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
351
-    echo '    location ~* \.php$ {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
341
+    nginx_limits "$LYCHEE_DOMAIN_NAME"
342
+    { echo '    }';
343
+      echo '';
344
+      echo '    # block these file types';
345
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
346
+      echo '        deny all;';
347
+      echo '    }';
348
+      echo '';
349
+      echo '    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
350
+      echo '    # or a unix socket';
351
+      echo '    location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
352 352
     function_check nginx_limits
353
-    nginx_limits $LYCHEE_DOMAIN_NAME
354
-    echo '        # Zero-day exploit defense.' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
355
-    echo '        # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
356
-    echo "        # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
357
-    echo "        # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
358
-    echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
359
-    echo "        # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
360
-    echo '        try_files $uri $uri/ /index.html;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
361
-    echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
362
-    echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
363
-    echo '        # With php-cgi alone:' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
364
-    echo '        # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
365
-    echo '        # With php-fpm:' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
366
-    echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
367
-    echo '        include fastcgi_params;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
368
-    echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
369
-    echo '        fastcgi_index index.html;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
370
-    echo '        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
371
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
372
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
373
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
374
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
375
-    echo '        deny all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
376
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
377
-    echo '' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
378
-    echo '    #deny access to store' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
379
-    echo '    location ~ /store {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
380
-    echo '        deny all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
381
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
382
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
383
-    echo '      deny all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
384
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
385
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
386
-    echo '      deny  all;' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
387
-    echo '    }' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
388
-    echo '}' >> /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
353
+    nginx_limits "$LYCHEE_DOMAIN_NAME"
354
+    { echo '        # Zero-day exploit defense.';
355
+      echo '        # http://forum.nginx.org/read.php?2,88845,page=3';
356
+      echo "        # Won't work properly (404 error) if the file is not stored on this";
357
+      echo "        # server, which is entirely possible with php-fpm/php-fcgi.";
358
+      echo "        # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
359
+      echo "        # another machine. And then cross your fingers that you won't get hacked.";
360
+      echo "        try_files \$uri \$uri/ /index.html;";
361
+      echo '        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
362
+      echo '        fastcgi_split_path_info ^(.+\.php)(/.+)$;';
363
+      echo '        # With php-cgi alone:';
364
+      echo '        # fastcgi_pass 127.0.0.1:9000;';
365
+      echo '        # With php-fpm:';
366
+      echo '        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
367
+      echo '        include fastcgi_params;';
368
+      echo '        fastcgi_read_timeout 30;';
369
+      echo '        fastcgi_index index.html;';
370
+      echo "        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
371
+      echo '    }';
372
+      echo '';
373
+      echo '    # deny access to all dot files';
374
+      echo '    location ~ /\. {';
375
+      echo '        deny all;';
376
+      echo '    }';
377
+      echo '';
378
+      echo '    #deny access to store';
379
+      echo '    location ~ /store {';
380
+      echo '        deny all;';
381
+      echo '    }';
382
+      echo '    location ~ /(data|conf|bin|inc)/ {';
383
+      echo '      deny all;';
384
+      echo '    }';
385
+      echo '    location ~ /\.ht {';
386
+      echo '      deny  all;';
387
+      echo '    }';
388
+      echo '}'; } >> "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
389 389
 }
390 390
 
391 391
 function install_lychee_from_repo {
392
-    if [ ! -d /var/www/$LYCHEE_DOMAIN_NAME ]; then
393
-        mkdir /var/www/$LYCHEE_DOMAIN_NAME
392
+    if [ ! -d "/var/www/$LYCHEE_DOMAIN_NAME" ]; then
393
+        mkdir "/var/www/$LYCHEE_DOMAIN_NAME"
394 394
     fi
395 395
 
396
-    cd /var/www/$LYCHEE_DOMAIN_NAME
396
+    cd "/var/www/$LYCHEE_DOMAIN_NAME" || exit 682468246
397 397
 
398 398
     if [ -d /repos/lychee ]; then
399 399
         mkdir htdocs
400 400
         cp -r -p /repos/lychee/. htdocs
401
-        cd htdocs
401
+        cd htdocs || exit 963756345
402 402
         git pull
403 403
     else
404
-        git_clone $LYCHEE_REPO htdocs
404
+        git_clone "$LYCHEE_REPO" htdocs
405 405
     fi
406 406
 
407
-    cd htdocs
408
-    git checkout $LYCHEE_COMMIT -b $LYCHEE_COMMIT
407
+    cd htdocs || exit 1437534858
408
+    git checkout "$LYCHEE_COMMIT" -b "$LYCHEE_COMMIT"
409 409
     set_completion_param "lychee commit" "$LYCHEE_COMMIT"
410 410
 }
411 411
 
@@ -414,7 +414,7 @@ function install_lychee {
414 414
         ONION_ONLY='no'
415 415
     fi
416 416
 
417
-    if [ ! $LYCHEE_DOMAIN_NAME ]; then
417
+    if [ ! "$LYCHEE_DOMAIN_NAME" ]; then
418 418
         echo $'The lychee domain name was not specified'
419 419
         exit 543672
420 420
     fi
@@ -429,7 +429,7 @@ function install_lychee {
429 429
         function_check install_lychee_website
430 430
         install_lychee_website
431 431
     else
432
-        echo -n '' > /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
432
+        echo -n '' > "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
433 433
     fi
434 434
 
435 435
     LYCHEE_ONION_HOSTNAME=$(add_onion_service lychee 80 ${LYCHEE_ONION_PORT})
@@ -438,23 +438,23 @@ function install_lychee {
438 438
     install_lychee_website_onion
439 439
 
440 440
     function_check create_site_certificate
441
-    create_site_certificate $LYCHEE_DOMAIN_NAME 'yes'
441
+    create_site_certificate "$LYCHEE_DOMAIN_NAME" 'yes'
442 442
 
443 443
     function_check configure_php
444 444
     configure_php
445 445
 
446
-    chmod -R 1777 /var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/
447
-    chmod -R 1777 /var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/
448
-    chown -R www-data:www-data /var/www/$LYCHEE_DOMAIN_NAME/htdocs
446
+    chmod -R 1777 "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/"
447
+    chmod -R 1777 "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/"
448
+    chown -R www-data:www-data "/var/www/$LYCHEE_DOMAIN_NAME/htdocs"
449 449
 
450
-    chmod 755 /var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/big/index.html
451
-    chmod 755 /var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/medium/index.html
452
-    chmod 755 /var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/import/index.html
453
-    chmod 755 /var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/thumb/index.html
454
-    chmod 755 /var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/.gitignore
450
+    chmod 755 "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/big/index.html"
451
+    chmod 755 "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/medium/index.html"
452
+    chmod 755 "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/import/index.html"
453
+    chmod 755 "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/uploads/thumb/index.html"
454
+    chmod 755 "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/data/.gitignore"
455 455
 
456 456
     function_check nginx_ensite
457
-    nginx_ensite $LYCHEE_DOMAIN_NAME
457
+    nginx_ensite "$LYCHEE_DOMAIN_NAME"
458 458
 
459 459
     function_check install_mariadb
460 460
     install_mariadb
@@ -469,10 +469,10 @@ function install_lychee {
469 469
     systemctl restart php7.0-fpm
470 470
     systemctl restart nginx
471 471
 
472
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a lychee -p "$LYCHEE_ADMIN_PASSWORD"
472
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a lychee -p "$LYCHEE_ADMIN_PASSWORD"
473 473
 
474 474
     function_check add_ddns_domain
475
-    add_ddns_domain $LYCHEE_DOMAIN_NAME
475
+    add_ddns_domain "$LYCHEE_DOMAIN_NAME"
476 476
 
477 477
     set_completion_param "lychee domain" "$LYCHEE_DOMAIN_NAME"
478 478
     APP_INSTALLED=1

+ 86
- 86
src/freedombone-app-mailpile Просмотреть файл

@@ -58,15 +58,15 @@ function logging_off_mailpile {
58 58
 
59 59
 function remove_user_mailpile {
60 60
     remove_username="$1"
61
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp mailpile
61
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp mailpile
62 62
 }
63 63
 
64 64
 function add_user_mailpile {
65
-    ${PROJECT_NAME}-pass -u $1 -a mailpile -p "$2"
65
+    "${PROJECT_NAME}-pass" -u "$1" -a mailpile -p "$2"
66 66
 }
67 67
 
68 68
 function install_interactive_mailpile {
69
-    if [ ! $ONION_ONLY ]; then
69
+    if [ ! "$ONION_ONLY" ]; then
70 70
         ONION_ONLY='no'
71 71
     fi
72 72
 
@@ -93,7 +93,7 @@ function upgrade_mailpile {
93 93
     read_config_param "MAILPILE_DOMAIN_NAME"
94 94
 
95 95
     CURR_COMMIT=$MAILPILE_COMMIT
96
-    if grep -q "mailpile commit" $COMPLETION_FILE; then
96
+    if grep -q "mailpile commit" "$COMPLETION_FILE"; then
97 97
         CURR_COMMIT=$(get_completion_param "mailpile commit")
98 98
     fi
99 99
     if [[ "$CURR_COMMIT" == "$MAILPILE_COMMIT" ]]; then
@@ -103,10 +103,10 @@ function upgrade_mailpile {
103 103
     function_check set_repo_commit
104 104
     set_repo_commit /var/www/$MAILPILE_DOMAIN_NAME/mail "mailpile commit" "$MAILPILE_COMMIT" $MAILPILE_REPO
105 105
 
106
-    cd /var/www/$MAILPILE_DOMAIN_NAME/mail
106
+    cd "/var/www/$MAILPILE_DOMAIN_NAME/mail" || exit 2346836535
107 107
     pip install -r requirements.txt
108 108
 
109
-    chown -R mailpile:mailpile /var/www/$MAILPILE_DOMAIN_NAME/mail
109
+    chown -R mailpile:mailpile "/var/www/$MAILPILE_DOMAIN_NAME/mail"
110 110
 }
111 111
 
112 112
 function backup_local_mailpile {
@@ -136,16 +136,16 @@ function remove_mailpile {
136 136
     systemctl daemon-reload
137 137
 
138 138
     read_config_param "MAILPILE_DOMAIN_NAME"
139
-    nginx_dissite $MAILPILE_DOMAIN_NAME
140
-    remove_certs ${MAILPILE_DOMAIN_NAME}
141
-    if [ -f /etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME ]; then
142
-        rm -f /etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
139
+    nginx_dissite "$MAILPILE_DOMAIN_NAME"
140
+    remove_certs "${MAILPILE_DOMAIN_NAME}"
141
+    if [ -f "/etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME" ]; then
142
+        rm -f "/etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME"
143 143
     fi
144
-    if [ -d /var/www/$MAILPILE_DOMAIN_NAME ]; then
145
-        rm -rf /var/www/$MAILPILE_DOMAIN_NAME
144
+    if [ -d "/var/www/$MAILPILE_DOMAIN_NAME" ]; then
145
+        rm -rf "/var/www/$MAILPILE_DOMAIN_NAME"
146 146
     fi
147 147
     function_check remove_ddns_domain
148
-    remove_ddns_domain $MAILPILE_DOMAIN_NAME
148
+    remove_ddns_domain "$MAILPILE_DOMAIN_NAME"
149 149
 
150 150
     groupdel -f mailpile
151 151
     userdel -r mailpile
@@ -158,8 +158,8 @@ function remove_mailpile {
158 158
 
159 159
     enable_email_encryption_at_rest
160 160
 
161
-    sed -i '/Mailpile/d' $COMPLETION_FILE
162
-    sed -i '/mailpile/d' $COMPLETION_FILE
161
+    sed -i '/Mailpile/d' "$COMPLETION_FILE"
162
+    sed -i '/mailpile/d' "$COMPLETION_FILE"
163 163
 }
164 164
 
165 165
 function install_mailpile {
@@ -178,7 +178,7 @@ function install_mailpile {
178 178
         mkdir /var/www/$MAILPILE_DOMAIN_NAME
179 179
     fi
180 180
 
181
-    cd /var/www/$MAILPILE_DOMAIN_NAME
181
+    cd "/var/www/$MAILPILE_DOMAIN_NAME" || exit 264826484
182 182
     if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail ]; then
183 183
         rm -rf /var/www/$MAILPILE_DOMAIN_NAME/mail
184 184
     fi
@@ -186,13 +186,13 @@ function install_mailpile {
186 186
     if [ -d /repos/mailpile ]; then
187 187
         mkdir mail
188 188
         cp -r -p /repos/mailpile/. mail
189
-        cd mail
189
+        cd mail || exit 245728482
190 190
         git pull
191 191
     else
192 192
         git_clone $MAILPILE_REPO mail
193 193
     fi
194 194
 
195
-    cd mail
195
+    cd mail || exit 246872468
196 196
     git checkout $MAILPILE_COMMIT -b $MAILPILE_COMMIT
197 197
     set_completion_param "mailpile commit" "$MAILPILE_COMMIT"
198 198
 
@@ -206,8 +206,8 @@ function install_mailpile {
206 206
     adduser mailpile debian-tor
207 207
     adduser mailpile www-data
208 208
     adduser mailpile mail
209
-    adduser mailpile $MY_USERNAME
210
-    if [[ $ONION_ONLY == 'no' ]]; then
209
+    adduser mailpile "$MY_USERNAME"
210
+    if [[ "$ONION_ONLY" == 'no' ]]; then
211 211
         chgrp -R ssl-cert /etc/letsencrypt
212 212
         chmod -R g=rX /etc/letsencrypt
213 213
         usermod -a -G ssl-cert mailpile
@@ -219,89 +219,89 @@ function install_mailpile {
219 219
 
220 220
     MAILPILE_ONION_HOSTNAME=$(add_onion_service mailpile 80 ${MAILPILE_ONION_PORT})
221 221
 
222
-    echo '[Unit]' > /etc/systemd/system/mailpile.service
223
-    echo 'Description=Mailpile Email Client' >> /etc/systemd/system/mailpile.service
224
-    echo 'After=syslog.target network.target nginx.target' >> /etc/systemd/system/mailpile.service
225
-    echo '' >> /etc/systemd/system/mailpile.service
226
-    echo '[Service]' >> /etc/systemd/system/mailpile.service
227
-    echo 'User=mailpile' >> /etc/systemd/system/mailpile.service
228
-    echo 'Group=mailpile' >> /etc/systemd/system/mailpile.service
229
-    echo "WorkingDirectory=/var/www/$MAILPILE_DOMAIN_NAME/mail" >> /etc/systemd/system/mailpile.service
230
-    echo "ExecStart=/var/www/$MAILPILE_DOMAIN_NAME/mail/mp --www=0.0.0.0:${MAILPILE_PORT} --wait" >> /etc/systemd/system/mailpile.service
231
-    echo 'Restart=always' >> /etc/systemd/system/mailpile.service
232
-    echo 'RestartSec=10' >> /etc/systemd/system/mailpile.service
233
-    echo '' >> /etc/systemd/system/mailpile.service
234
-    echo '[Install]' >> /etc/systemd/system/mailpile.service
235
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mailpile.service
222
+    { echo '[Unit]';
223
+      echo 'Description=Mailpile Email Client';
224
+      echo 'After=syslog.target network.target nginx.target';
225
+      echo '';
226
+      echo '[Service]';
227
+      echo 'User=mailpile';
228
+      echo 'Group=mailpile';
229
+      echo "WorkingDirectory=/var/www/$MAILPILE_DOMAIN_NAME/mail";
230
+      echo "ExecStart=/var/www/$MAILPILE_DOMAIN_NAME/mail/mp --www=0.0.0.0:${MAILPILE_PORT} --wait";
231
+      echo 'Restart=always';
232
+      echo 'RestartSec=10';
233
+      echo '';
234
+      echo '[Install]';
235
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/mailpile.service
236 236
     chmod +x /etc/systemd/system/mailpile.service
237 237
 
238 238
     mailpile_nginx_site=/etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
239 239
     if [[ $ONION_ONLY == "no" ]]; then
240 240
         function_check nginx_http_redirect
241 241
         nginx_http_redirect $MAILPILE_DOMAIN_NAME
242
-        echo 'server {' >> $mailpile_nginx_site
243
-        echo '  listen 443 ssl;' >> $mailpile_nginx_site
244
-        echo '  #listen [::]:443 ssl;' >> $mailpile_nginx_site
245
-        echo "  server_name $MAILPILE_DOMAIN_NAME;" >> $mailpile_nginx_site
246
-        echo '' >> $mailpile_nginx_site
247
-        echo '  # Security' >> $mailpile_nginx_site
242
+        { echo 'server {';
243
+          echo '  listen 443 ssl;';
244
+          echo '  #listen [::]:443 ssl;';
245
+          echo "  server_name $MAILPILE_DOMAIN_NAME;";
246
+          echo '';
247
+          echo '  # Security'; } >> $mailpile_nginx_site
248 248
         function_check nginx_ssl
249 249
         nginx_ssl $MAILPILE_DOMAIN_NAME
250 250
 
251 251
         function_check nginx_disable_sniffing
252 252
         nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
253 253
 
254
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $mailpile_nginx_site
255
-        echo '' >> $mailpile_nginx_site
256
-        echo '  # Logs' >> $mailpile_nginx_site
257
-        echo '  access_log /dev/null;' >> $mailpile_nginx_site
258
-        echo '  error_log /dev/null;' >> $mailpile_nginx_site
259
-        echo '' >> $mailpile_nginx_site
260
-        echo '  # Root' >> $mailpile_nginx_site
261
-        echo "  root /var/www/$MAILPILE_DOMAIN_NAME/mail;" >> $mailpile_nginx_site
262
-        echo '' >> $mailpile_nginx_site
263
-        echo '  location / {' >> $mailpile_nginx_site
254
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
255
+          echo '';
256
+          echo '  # Logs';
257
+          echo '  access_log /dev/null;';
258
+          echo '  error_log /dev/null;';
259
+          echo '';
260
+          echo '  # Root';
261
+          echo "  root /var/www/$MAILPILE_DOMAIN_NAME/mail;";
262
+          echo '';
263
+          echo '  location / {'; } >> $mailpile_nginx_site
264 264
         function_check nginx_limits
265 265
         nginx_limits $MAILPILE_DOMAIN_NAME '15m'
266
-        echo '    rewrite /(.*) /$1 break;' >> $mailpile_nginx_site
267
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $mailpile_nginx_site
268
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $mailpile_nginx_site
269
-        echo '    proxy_set_header Host $http_host;' >> $mailpile_nginx_site
270
-        echo '    proxy_set_header X-NginX-Proxy true;' >> $mailpile_nginx_site
271
-        echo "    proxy_pass http://localhost:${MAILPILE_PORT};" >> $mailpile_nginx_site
272
-        echo '    proxy_redirect off;' >> $mailpile_nginx_site
273
-        echo '  }' >> $mailpile_nginx_site
274
-        echo '}' >> $mailpile_nginx_site
275
-        echo '' >> $mailpile_nginx_site
266
+        { echo "    rewrite /(.*) /\$1 break;";
267
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
268
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
269
+          echo "    proxy_set_header Host \$http_host;";
270
+          echo '    proxy_set_header X-NginX-Proxy true;';
271
+          echo "    proxy_pass http://localhost:${MAILPILE_PORT};";
272
+          echo '    proxy_redirect off;';
273
+          echo '  }';
274
+          echo '}';
275
+          echo ''; } >> $mailpile_nginx_site
276 276
     else
277 277
         echo -n '' > $mailpile_nginx_site
278 278
     fi
279
-    echo 'server {' >> $mailpile_nginx_site
280
-    echo "    listen 127.0.0.1:$MAILPILE_ONION_PORT default_server;" >> $mailpile_nginx_site
281
-    echo "    server_name $MAILPILE_ONION_HOSTNAME;" >> $mailpile_nginx_site
282
-    echo '' >> $mailpile_nginx_site
279
+    { echo 'server {';
280
+      echo "    listen 127.0.0.1:$MAILPILE_ONION_PORT default_server;";
281
+      echo "    server_name $MAILPILE_ONION_HOSTNAME;";
282
+      echo ''; } >> $mailpile_nginx_site
283 283
     function_check nginx_disable_sniffing
284 284
     nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
285
-    echo '' >> $mailpile_nginx_site
286
-    echo '  # Logs' >> $mailpile_nginx_site
287
-    echo '  access_log /dev/null;' >> $mailpile_nginx_site
288
-    echo '  error_log /dev/null;' >> $mailpile_nginx_site
289
-    echo '' >> $mailpile_nginx_site
290
-    echo '  # Root' >> $mailpile_nginx_site
291
-    echo "  root /var/www/$MAILPILE_DOMAIN_NAME/mail;" >> $mailpile_nginx_site
292
-    echo '' >> $mailpile_nginx_site
293
-    echo '  location / {' >> $mailpile_nginx_site
285
+    { echo '';
286
+      echo '  # Logs';
287
+      echo '  access_log /dev/null;';
288
+      echo '  error_log /dev/null;';
289
+      echo '';
290
+      echo '  # Root';
291
+      echo "  root /var/www/$MAILPILE_DOMAIN_NAME/mail;";
292
+      echo '';
293
+      echo '  location / {'; } >> $mailpile_nginx_site
294 294
     function_check nginx_limits
295 295
     nginx_limits $MAILPILE_DOMAIN_NAME '15m'
296
-    echo '    rewrite /(.*) /$1 break;' >> $mailpile_nginx_site
297
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $mailpile_nginx_site
298
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $mailpile_nginx_site
299
-    echo '    proxy_set_header Host $http_host;' >> $mailpile_nginx_site
300
-    echo '    proxy_set_header X-NginX-Proxy true;' >> $mailpile_nginx_site
301
-    echo "    proxy_pass http://localhost:${MAILPILE_PORT};" >> $mailpile_nginx_site
302
-    echo '    proxy_redirect off;' >> $mailpile_nginx_site
303
-    echo '  }' >> $mailpile_nginx_site
304
-    echo '}' >> $mailpile_nginx_site
296
+    { echo "    rewrite /(.*) /\$1 break;";
297
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
298
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
299
+      echo "    proxy_set_header Host \$http_host;";
300
+      echo '    proxy_set_header X-NginX-Proxy true;';
301
+      echo "    proxy_pass http://localhost:${MAILPILE_PORT};";
302
+      echo '    proxy_redirect off;';
303
+      echo '  }';
304
+      echo '}'; } >> $mailpile_nginx_site
305 305
 
306 306
     function_check create_site_certificate
307 307
     if [ ! -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem ]; then
@@ -322,7 +322,7 @@ function install_mailpile {
322 322
     function_check nginx_ensite
323 323
     nginx_ensite $MAILPILE_DOMAIN_NAME
324 324
 
325
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a mailpile -p "*"
325
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a mailpile -p "*"
326 326
 
327 327
     function_check add_ddns_domain
328 328
     add_ddns_domain $MAILPILE_DOMAIN_NAME
@@ -336,7 +336,7 @@ function install_mailpile {
336 336
     if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg ]; then
337 337
         mv /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg_orig
338 338
     fi
339
-    cp -r /home/$MY_USERNAME/.gnupg /var/www/$MAILPILE_DOMAIN_NAME/mail/
339
+    cp -r "/home/$MY_USERNAME/.gnupg" "/var/www/$MAILPILE_DOMAIN_NAME/mail/"
340 340
     chown -R mailpile:mailpile /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
341 341
     chmod +x /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
342 342
 
@@ -348,8 +348,8 @@ function install_mailpile {
348 348
     sed -i 's|ssl =.*|ssl = no|g' /etc/dovecot/conf.d/10-ssl.conf
349 349
 
350 350
     # set ssl certs, just in case we want to use them later
351
-    if [[ $ONION_ONLY == "no" ]]; then
352
-        if [ -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
351
+    if [[ "$ONION_ONLY" == "no" ]]; then
352
+        if [ -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
353 353
             sed -i "s|#ssl_cert =.*|ssl_cert = </etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem|g" /etc/dovecot/conf.d/10-ssl.conf
354 354
             sed -i "s|ssl_cert =.*|ssl_cert = </etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem|g" /etc/dovecot/conf.d/10-ssl.conf
355 355
             sed -i "s|#ssl_key =.*|ssl_key = </etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/privkey.pem|g" /etc/dovecot/conf.d/10-ssl.conf

+ 164
- 164
src/freedombone-app-matrix Просмотреть файл

@@ -71,21 +71,21 @@ function matrix_expire_old_posts {
71 71
     read_config_param MATRIX_PORT
72 72
 
73 73
     matrix_remove_posts=/usr/bin/matrix-remove
74
-    echo '#!/bin/bash' > $matrix_remove_posts
75
-    echo "cd $MATRIX_DATA_DIR" >> $matrix_remove_posts
76
-    echo 'ROOM=$1' >> $matrix_remove_posts
77
-    echo "ADMIN=\"@${MY_USERNAME}:$MATRIX_DOMAIN_NAME\"" >> $matrix_remove_posts
78
-    echo "TIME='$MATRIX_EXPIRE_MONTHS months ago'" >> $matrix_remove_posts
79
-    echo "UNIX_TIMESTAMP=\$(date +%s%3N --date='TZ=\"UTC+0\" '\"\$TIME\")" >> $matrix_remove_posts
80
-    echo 'BUSY="pragma busy_timeout=20000"' >> $matrix_remove_posts
81
-    echo "BUFFER=\$(sqlite3 homeserver.db \"\$BUSY;select event_id from events where type='m.room.message' and received_ts<'\$UNIX_TIMESTAMP' and room_id='\$ROOM' order by received_ts desc limit 1;\")" >> $matrix_remove_posts
82
-    echo "EVENT_ID=\$(echo \$BUFFER|awk '{print \$2}')" >> $matrix_remove_posts
83
-
84
-    echo "BUFFER=\$(sqlite3 homeserver.db \"\$BUSY;select token from access_tokens where user_id like '\$ADMIN' order by id desc limit 1;\")" >> $matrix_remove_posts
85
-    echo "TOKEN=\$(echo \$BUFFER|awk '{print \$2}')" >> $matrix_remove_posts
86
-
87
-    echo 'set -x' >> $matrix_remove_posts
88
-    echo "curl -v -X POST 'https://$MATRIX_DOMAIN_NAME/_matrix/client/r0/admin/purge_history/'\$ROOM'/'\$EVENT_ID'?access_token='\$TOKEN" >> $matrix_remove_posts
74
+    { echo '#!/bin/bash';
75
+      echo "cd $MATRIX_DATA_DIR";
76
+      echo "ROOM=\$1";
77
+      echo "ADMIN=\"@${MY_USERNAME}:$MATRIX_DOMAIN_NAME\"";
78
+      echo "TIME='$MATRIX_EXPIRE_MONTHS months ago'";
79
+      echo "UNIX_TIMESTAMP=\$(date +%s%3N --date='TZ=\"UTC+0\" '\"\$TIME\")";
80
+      echo 'BUSY="pragma busy_timeout=20000"';
81
+      echo "BUFFER=\$(sqlite3 homeserver.db \"\$BUSY;select event_id from events where type='m.room.message' and received_ts<'\$UNIX_TIMESTAMP' and room_id='\$ROOM' order by received_ts desc limit 1;\")";
82
+      echo "EVENT_ID=\$(echo \$BUFFER|awk '{print \$2}')";
83
+
84
+      echo "BUFFER=\$(sqlite3 homeserver.db \"\$BUSY;select token from access_tokens where user_id like '\$ADMIN' order by id desc limit 1;\")";
85
+      echo "TOKEN=\$(echo \$BUFFER|awk '{print \$2}')";
86
+
87
+      echo 'set -x';
88
+      echo "curl -v -X POST 'https://$MATRIX_DOMAIN_NAME/_matrix/client/r0/admin/purge_history/'\$ROOM'/'\$EVENT_ID'?access_token='\$TOKEN"; } > $matrix_remove_posts
89 89
 
90 90
     chmod +x $matrix_remove_posts
91 91
 }
@@ -127,109 +127,109 @@ function logging_off_matrix {
127 127
 function matrix_nginx {
128 128
     matrix_nginx_site=/etc/nginx/sites-available/$MATRIX_DOMAIN_NAME
129 129
     if [[ $ONION_ONLY == "no" ]]; then
130
-        echo 'server {' > $matrix_nginx_site
131
-        echo "  listen 0.0.0.0:443;" >> $matrix_nginx_site
132
-        echo "  server_name ${MATRIX_DOMAIN_NAME};" >> $matrix_nginx_site
133
-        echo '' >> $matrix_nginx_site
134
-        echo '  # Security' >> $matrix_nginx_site
130
+        { echo 'server {';
131
+          echo "  listen 0.0.0.0:443;";
132
+          echo "  server_name ${MATRIX_DOMAIN_NAME};";
133
+          echo '';
134
+          echo '  # Security'; } > $matrix_nginx_site
135 135
         function_check nginx_ssl
136 136
         nginx_ssl ${MATRIX_DOMAIN_NAME}
137 137
 
138 138
         function_check nginx_disable_sniffing
139 139
         nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
140 140
 
141
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
142
-        echo '' >> $matrix_nginx_site
143
-        echo '  # Logs' >> $matrix_nginx_site
144
-        echo '  access_log /dev/null;' >> $matrix_nginx_site
145
-        echo '  error_log /dev/null;' >> $matrix_nginx_site
146
-        echo '' >> $matrix_nginx_site
147
-        echo '  root /var/lib/matrix/media_store;' >> $matrix_nginx_site
148
-        echo '' >> $matrix_nginx_site
149
-        echo '  # Index' >> $matrix_nginx_site
150
-        echo '  index index.html;' >> $matrix_nginx_site
151
-        echo '' >> $matrix_nginx_site
152
-        echo '  location /_matrix {' >> $matrix_nginx_site
141
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
142
+          echo '';
143
+          echo '  # Logs';
144
+          echo '  access_log /dev/null;';
145
+          echo '  error_log /dev/null;';
146
+          echo '';
147
+          echo '  root /var/lib/matrix/media_store;';
148
+          echo '';
149
+          echo '  # Index';
150
+          echo '  index index.html;';
151
+          echo '';
152
+          echo '  location /_matrix {'; } >> $matrix_nginx_site
153 153
         function_check nginx_limits
154 154
         nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
155
-        echo "    proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
156
-        echo '  }' >> $matrix_nginx_site
157
-        echo '}' >> $matrix_nginx_site
158
-        echo '' >> $matrix_nginx_site
159
-        echo 'server {' >> $matrix_nginx_site
160
-        echo "  listen 0.0.0.0:${MATRIX_HTTP_PORT};" >> $matrix_nginx_site
161
-        echo "  server_name ${MATRIX_DOMAIN_NAME};" >> $matrix_nginx_site
162
-        echo '' >> $matrix_nginx_site
163
-        echo '  # Security' >> $matrix_nginx_site
155
+        { echo "    proxy_pass http://localhost:${MATRIX_PORT};";
156
+          echo '  }';
157
+          echo '}';
158
+          echo '';
159
+          echo 'server {';
160
+          echo "  listen 0.0.0.0:${MATRIX_HTTP_PORT};";
161
+          echo "  server_name ${MATRIX_DOMAIN_NAME};";
162
+          echo '';
163
+          echo '  # Security'; } >> $matrix_nginx_site
164 164
         function_check nginx_ssl
165 165
         nginx_ssl ${MATRIX_DOMAIN_NAME}
166 166
 
167 167
         function_check nginx_disable_sniffing
168 168
         nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
169 169
 
170
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $matrix_nginx_site
171
-        echo '' >> $matrix_nginx_site
172
-        echo '  # Logs' >> $matrix_nginx_site
173
-        echo '  access_log /dev/null;' >> $matrix_nginx_site
174
-        echo '  error_log /dev/null;' >> $matrix_nginx_site
175
-        echo '' >> $matrix_nginx_site
176
-        echo '  root /var/lib/matrix/media_store;' >> $matrix_nginx_site
177
-        echo '' >> $matrix_nginx_site
178
-        echo '  # Index' >> $matrix_nginx_site
179
-        echo '  index index.html;' >> $matrix_nginx_site
180
-        echo '' >> $matrix_nginx_site
181
-        echo '  # Location' >> $matrix_nginx_site
182
-        echo '  location /_matrix {' >> $matrix_nginx_site
170
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
171
+          echo '';
172
+          echo '  # Logs';
173
+          echo '  access_log /dev/null;';
174
+          echo '  error_log /dev/null;';
175
+          echo '';
176
+          echo '  root /var/lib/matrix/media_store;';
177
+          echo '';
178
+          echo '  # Index';
179
+          echo '  index index.html;';
180
+          echo '';
181
+          echo '  # Location';
182
+          echo '  location /_matrix {'; } >> $matrix_nginx_site
183 183
         function_check nginx_limits
184 184
         nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
185
-        echo "    proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
186
-        echo '  }' >> $matrix_nginx_site
187
-        echo '}' >> $matrix_nginx_site
188
-        echo '' >> $matrix_nginx_site
185
+        { echo "    proxy_pass http://localhost:${MATRIX_PORT};";
186
+          echo '  }';
187
+          echo '}';
188
+          echo ''; } >> $matrix_nginx_site
189 189
     else
190 190
         echo -n '' > $matrix_nginx_site
191 191
     fi
192
-    echo 'server {' >> $matrix_nginx_site
193
-    echo "    listen 127.0.0.1:$MATRIX_FEDERATION_ONION_PORT default_server;" >> $matrix_nginx_site
194
-    echo "    server_name $MATRIX_DOMAIN_NAME;" >> $matrix_nginx_site
195
-    echo '' >> $matrix_nginx_site
192
+    { echo 'server {';
193
+      echo "    listen 127.0.0.1:$MATRIX_FEDERATION_ONION_PORT default_server;";
194
+      echo "    server_name $MATRIX_DOMAIN_NAME;";
195
+      echo ''; } >> $matrix_nginx_site
196 196
     function_check nginx_disable_sniffing
197 197
     nginx_disable_sniffing $MATRIX_DOMAIN_NAME
198
-    echo '' >> $matrix_nginx_site
199
-    echo '  # Logs' >> $matrix_nginx_site
200
-    echo '  access_log /dev/null;' >> $matrix_nginx_site
201
-    echo '  error_log /dev/null;' >> $matrix_nginx_site
202
-    echo '' >> $matrix_nginx_site
203
-    echo '  root /var/lib/matrix/media_store;' >> $matrix_nginx_site
204
-    echo '' >> $matrix_nginx_site
205
-    echo '  # Location' >> $matrix_nginx_site
206
-    echo '  location /_matrix {' >> $matrix_nginx_site
198
+    { echo '';
199
+      echo '  # Logs';
200
+      echo '  access_log /dev/null;';
201
+      echo '  error_log /dev/null;';
202
+      echo '';
203
+      echo '  root /var/lib/matrix/media_store;';
204
+      echo '';
205
+      echo '  # Location';
206
+      echo '  location /_matrix {'; } >> $matrix_nginx_site
207 207
     function_check nginx_limits
208 208
     nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
209
-    echo "    proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
210
-    echo '  }' >> $matrix_nginx_site
211
-    echo '}' >> $matrix_nginx_site
212
-    echo '' >> $matrix_nginx_site
213
-    echo 'server {' >> $matrix_nginx_site
214
-    echo "    listen 127.0.0.1:$MATRIX_ONION_PORT default_server;" >> $matrix_nginx_site
215
-    echo "    server_name $MATRIX_DOMAIN_NAME;" >> $matrix_nginx_site
216
-    echo '' >> $matrix_nginx_site
209
+    { echo "    proxy_pass http://localhost:${MATRIX_PORT};";
210
+      echo '  }';
211
+      echo '}';
212
+      echo '';
213
+      echo 'server {';
214
+      echo "    listen 127.0.0.1:$MATRIX_ONION_PORT default_server;";
215
+      echo "    server_name $MATRIX_DOMAIN_NAME;";
216
+      echo ''; } >> $matrix_nginx_site
217 217
     function_check nginx_disable_sniffing
218 218
     nginx_disable_sniffing $MATRIX_DOMAIN_NAME
219
-    echo '' >> $matrix_nginx_site
220
-    echo '  # Logs' >> $matrix_nginx_site
221
-    echo '  access_log /dev/null;' >> $matrix_nginx_site
222
-    echo '  error_log /dev/null;' >> $matrix_nginx_site
223
-    echo '' >> $matrix_nginx_site
224
-    echo '  root /var/lib/matrix/media_store;' >> $matrix_nginx_site
225
-    echo '' >> $matrix_nginx_site
226
-    echo '  # Location' >> $matrix_nginx_site
227
-    echo '  location /_matrix {' >> $matrix_nginx_site
219
+    { echo '';
220
+      echo '  # Logs';
221
+      echo '  access_log /dev/null;';
222
+      echo '  error_log /dev/null;';
223
+      echo '';
224
+      echo '  root /var/lib/matrix/media_store;';
225
+      echo '';
226
+      echo '  # Location';
227
+      echo '  location /_matrix {'; } >> $matrix_nginx_site
228 228
     function_check nginx_limits
229 229
     nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
230
-    echo "    proxy_pass http://localhost:${MATRIX_PORT};" >> $matrix_nginx_site
231
-    echo '  }' >> $matrix_nginx_site
232
-    echo '}' >> $matrix_nginx_site
230
+    { echo "    proxy_pass http://localhost:${MATRIX_PORT};";
231
+      echo '  }';
232
+      echo '}'; } >> $matrix_nginx_site
233 233
 
234 234
     if [ ! -d /var/www/$MATRIX_DOMAIN_NAME ]; then
235 235
         mkdir -p /var/www/$MATRIX_DOMAIN_NAME/htdocs
@@ -242,7 +242,7 @@ function matrix_nginx {
242 242
 function matrix_generate_homeserver_file {
243 243
     local filepath="${1}"
244 244
 
245
-    cd /etc/matrix
245
+    cd /etc/matrix || exit 468246824
246 246
     python -m synapse.app.homeserver \
247 247
            --config-path "${filepath}" \
248 248
            --generate-config \
@@ -251,10 +251,10 @@ function matrix_generate_homeserver_file {
251 251
 }
252 252
 
253 253
 function matrix_configure_homeserver_yaml {
254
-    local turnkey="${1}"
255
-    local filepath="${2}"
254
+    turnkey="${1}"
255
+    filepath="${2}"
256 256
 
257
-    local ymltemp="$(mktemp)"
257
+    ymltemp="$(mktemp)"
258 258
 
259 259
     awk -v TURNURIES="turn_uris: [\"turn:${MATRIX_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=udp\", \"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=tcp\"]" \
260 260
         -v TURNSHAREDSECRET="turn_shared_secret: \"${turnkey}\"" \
@@ -272,7 +272,7 @@ function matrix_configure_homeserver_yaml {
272 272
         print;
273 273
         }' "${filepath}" > "${ymltemp}"
274 274
 
275
-    mv ${ymltemp} "${filepath}"
275
+    mv "${ymltemp}" "${filepath}"
276 276
 
277 277
     if [[ $ONION_ONLY == "no" ]]; then
278 278
         sed -i "s|tls_certificate_path:.*|tls_certificate_path: \"/etc/ssl/certs/${MATRIX_DOMAIN_NAME}.pem\"|g" "${filepath}"
@@ -307,9 +307,10 @@ function matrix_diff {
307 307
     REPORT_STATS="${REPORT_STATS:-no_or_yes}"
308 308
     export MATRIX_DOMAIN_NAME REPORT_STATS
309 309
 
310
-    matrix_generate_synapse_file $INSTALL_DIR/homeserver.synapse.yaml
311
-    diff -${DIFFPARAMS} $INSTALL_DIR/homeserver.synapse.yaml ${MATRIX_DATA_DIR}/homeserver.yaml
312
-    rm $INSTALL_DIR/homeserver.synapse.yaml
310
+    matrix_generate_synapse_file "$INSTALL_DIR/homeserver.synapse.yaml"
311
+    # shellcheck disable=SC2086
312
+    diff -${DIFFPARAMS} "$INSTALL_DIR/homeserver.synapse.yaml" "${MATRIX_DATA_DIR}/homeserver.yaml"
313
+    rm "$INSTALL_DIR/homeserver.synapse.yaml"
313 314
 }
314 315
 
315 316
 function matrix_generate {
@@ -334,15 +335,15 @@ function create_matrix_user_removal_script {
334 335
     read_config_param MATRIX_DOMAIN_NAME
335 336
 
336 337
     matrix_remove_user=/usr/bin/matrix-remove-user
337
-    echo '#!/bin/bash' > $matrix_remove_user
338
-    echo "cd $MATRIX_DATA_DIR" >> $matrix_remove_user
339
-    echo 'remove_username=$1' >> $matrix_remove_user
340
-    echo "ADMIN=\"@${MY_USERNAME}:$MATRIX_DOMAIN_NAME\"" >> $matrix_remove_user
341
-    echo 'BUSY="pragma busy_timeout=20000"' >> $matrix_remove_user
342
-    echo "BUFFER=\$(sqlite3 homeserver.db \"\$BUSY;select token from access_tokens where user_id like '\$ADMIN' order by id desc limit 1;\")" >> $matrix_remove_user
343
-    echo "TOKEN=\$(echo \$BUFFER|awk '{print \$2}')" >> $matrix_remove_user
344
-    echo 'set -x' >> $matrix_remove_user
345
-    echo "curl -X POST 'https://$MATRIX_DOMAIN_NAME/_matrix/client/r0/admin/deactivate/%40\$remove_username%3A$MATRIX_DOMAIN_NAME?access_token=\$TOKEN' --data '{}'" >> $matrix_remove_user
338
+    { echo '#!/bin/bash';
339
+      echo "cd $MATRIX_DATA_DIR";
340
+      echo "remove_username=\$1";
341
+      echo "ADMIN=\"@${MY_USERNAME}:$MATRIX_DOMAIN_NAME\"";
342
+      echo 'BUSY="pragma busy_timeout=20000"';
343
+      echo "BUFFER=\$(sqlite3 homeserver.db \"\$BUSY;select token from access_tokens where user_id like '\$ADMIN' order by id desc limit 1;\")";
344
+      echo "TOKEN=\$(echo \$BUFFER|awk '{print \$2}')";
345
+      echo 'set -x';
346
+      echo "curl -X POST 'https://$MATRIX_DOMAIN_NAME/_matrix/client/r0/admin/deactivate/%40\$remove_username%3A$MATRIX_DOMAIN_NAME?access_token=\$TOKEN' --data '{}'"; } > $matrix_remove_user
346 347
 
347 348
     chmod +x $matrix_remove_user
348 349
 }
@@ -351,7 +352,7 @@ function remove_user_matrix {
351 352
     remove_username="$1"
352 353
 
353 354
     create_matrix_user_removal_script
354
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp matrix
355
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp matrix
355 356
     $matrix_remove_user "$remove_username"
356 357
 }
357 358
 
@@ -362,7 +363,7 @@ function add_user_matrix {
362 363
     read_config_param MY_USERNAME
363 364
     read_config_param MATRIX_DOMAIN_NAME
364 365
 
365
-    ${PROJECT_NAME}-pass -u $new_username -a matrix -p "$new_user_password"
366
+    "${PROJECT_NAME}-pass" -u "$new_username" -a matrix -p "$new_user_password"
366 367
 
367 368
     if [[ "$new_username" != "$MY_USERNAME" ]]; then
368 369
         echo 'no' | register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" http://localhost:${MATRIX_PORT}
@@ -373,7 +374,7 @@ function add_user_matrix {
373 374
 }
374 375
 
375 376
 function install_interactive_matrix {
376
-    if [ ! $ONION_ONLY ]; then
377
+    if [ ! "$ONION_ONLY" ]; then
377 378
         ONION_ONLY='no'
378 379
     fi
379 380
 
@@ -393,7 +394,7 @@ function install_interactive_matrix {
393 394
 }
394 395
 
395 396
 function change_password_matrix {
396
-    curr_username="$1"
397
+    #curr_username="$1"
397 398
     new_user_password="$2"
398 399
 
399 400
     #${PROJECT_NAME}-pass -u "$curr_username" -a matrix -p "$new_user_password"
@@ -418,7 +419,7 @@ function upgrade_matrix {
418 419
 
419 420
     function_check set_repo_commit
420 421
     set_repo_commit /etc/matrix "matrix commit" "$MATRIX_COMMIT" $MATRIX_REPO
421
-    cd /etc/matrix
422
+    cd /etc/matrix || exit 62476724
422 423
     pip install --upgrade --process-dependency-links .
423 424
 
424 425
     sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
@@ -467,6 +468,7 @@ function restore_local_matrix {
467 468
         else
468 469
             cp -r $temp_restore_dir/* /etc/matrix/
469 470
         fi
471
+        # shellcheck disable=SC2181
470 472
         if [ ! "$?" = "0" ]; then
471 473
             function_check backup_unmount_drive
472 474
             backup_unmount_drive
@@ -482,6 +484,7 @@ function restore_local_matrix {
482 484
         else
483 485
             cp -r $temp_restore_dir/* $MATRIX_DATA_DIR/
484 486
         fi
487
+        # shellcheck disable=SC2181
485 488
         if [ ! "$?" = "0" ]; then
486 489
             function_check backup_unmount_drive
487 490
             backup_unmount_drive
@@ -490,7 +493,7 @@ function restore_local_matrix {
490 493
         rm -rf $temp_restore_dir
491 494
         chown -R matrix:matrix $MATRIX_DATA_DIR
492 495
 
493
-        if [[ $ONION_ONLY == "no" ]]; then
496
+        if [[ "$ONION_ONLY" == "no" ]]; then
494 497
             if [ -f /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam ]; then
495 498
                 chmod 755 /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam
496 499
             fi
@@ -532,6 +535,7 @@ function restore_remote_matrix {
532 535
         else
533 536
             cp -r $temp_restore_dir/* /etc/matrix/
534 537
         fi
538
+        # shellcheck disable=SC2181
535 539
         if [ ! "$?" = "0" ]; then
536 540
             exit 38935
537 541
         fi
@@ -545,6 +549,7 @@ function restore_remote_matrix {
545 549
         else
546 550
             cp -r $temp_restore_dir/* $MATRIX_DATA_DIR/
547 551
         fi
552
+        # shellcheck disable=SC2181
548 553
         if [ ! "$?" = "0" ]; then
549 554
             exit 60923
550 555
         fi
@@ -581,7 +586,7 @@ function remove_matrix {
581 586
     fi
582 587
     systemctl daemon-reload
583 588
     apt-get -y remove --purge coturn
584
-    cd /etc/matrix
589
+    cd /etc/matrix || exit 26472462
585 590
     pip uninstall .
586 591
     rm -rf $MATRIX_DATA_DIR
587 592
     rm -rf /etc/matrix
@@ -596,7 +601,7 @@ function remove_matrix {
596 601
     systemctl restart nginx
597 602
 
598 603
     remove_completion_param install_matrix
599
-    sed -i '/matrix/d' $COMPLETION_FILE
604
+    sed -i '/matrix/d' "$COMPLETION_FILE"
600 605
 
601 606
     rm /etc/avahi/services/matrix.service
602 607
     systemctl restart avahi-daemon
@@ -608,7 +613,7 @@ function install_home_server {
608 613
         if [ -d /repos/matrix ]; then
609 614
             mkdir /etc/matrix
610 615
             cp -r -p /repos/matrix/. /etc/matrix
611
-            cd /etc/matrix
616
+            cd /etc/matrix || exit 2324962946
612 617
             git pull
613 618
         else
614 619
             function_check git_clone
@@ -621,18 +626,17 @@ function install_home_server {
621 626
         fi
622 627
     fi
623 628
 
624
-    cd /etc/matrix
629
+    cd /etc/matrix || exit 7385452724
625 630
     git checkout $MATRIX_COMMIT -b $MATRIX_COMMIT
626 631
     set_completion_param "matrix commit" "$MATRIX_COMMIT"
627
-    if [ ! -d $INSTALL_DIR/matrix ]; then
628
-        mkdir -p $INSTALL_DIR/matrix
632
+    if [ ! -d "$INSTALL_DIR/matrix" ]; then
633
+        mkdir -p "$INSTALL_DIR/matrix"
629 634
     fi
630 635
     rm -rf /usr/local/lib/python2.7/dist-packages/ldap*
631
-    if [ -d $INSTALL_DIR/matrix ]; then
632
-        rm -rf $INSTALL_DIR/matrix/*
636
+    if [ -d "$INSTALL_DIR/matrix" ]; then
637
+        rm -rf "$INSTALL_DIR/matrix/*"
633 638
     fi
634
-    pip install --upgrade --process-dependency-links . -b $INSTALL_DIR/matrix
635
-    if [ ! "$?" = "0" ]; then
639
+    if ! pip install --upgrade --process-dependency-links . -b "$INSTALL_DIR/matrix"; then
636 640
         echo $'Failed to install matrix home server'
637 641
         exit 782542
638 642
     fi
@@ -653,11 +657,6 @@ function install_home_server {
653 657
     function_check matrix_generate
654 658
     matrix_generate
655 659
 
656
-    if [[ -z ${MATRIX_DATA_DIR}/homeserver.yaml ]]; then
657
-        echo $'homeserver.yaml is zero size'
658
-        exit 783724
659
-    fi
660
-
661 660
     # Disable the web client
662 661
     sed -i 's|web_client:.*|web_client: False|g' $MATRIX_DATA_DIR/homeserver.yaml
663 662
     sed -i 's|, webclient||g' $MATRIX_DATA_DIR/homeserver.yaml
@@ -669,20 +668,20 @@ function install_home_server {
669 668
 
670 669
     sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
671 670
 
672
-    echo '[Unit]' > /etc/systemd/system/matrix.service
673
-    echo 'Description=Synapse Matrix homeserver' >> /etc/systemd/system/matrix.service
674
-    echo 'After=network.target nginx.target' >> /etc/systemd/system/matrix.service
675
-    echo '' >> /etc/systemd/system/matrix.service
676
-    echo '[Service]' >> /etc/systemd/system/matrix.service
677
-    echo 'Type=simple' >> /etc/systemd/system/matrix.service
678
-    echo 'User=matrix' >> /etc/systemd/system/matrix.service
679
-    echo "WorkingDirectory=/etc/matrix" >> /etc/systemd/system/matrix.service
680
-    echo "ExecStart=/usr/bin/python -m synapse.app.homeserver --config-path ${MATRIX_DATA_DIR}/homeserver.yaml" >> /etc/systemd/system/matrix.service
681
-    echo 'Restart=on-failure' >> /etc/systemd/system/matrix.service
682
-    echo 'RestartSec=10' >> /etc/systemd/system/matrix.service
683
-    echo '' >> /etc/systemd/system/matrix.service
684
-    echo '[Install]' >> /etc/systemd/system/matrix.service
685
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/matrix.service
671
+    { echo '[Unit]';
672
+      echo 'Description=Synapse Matrix homeserver';
673
+      echo 'After=network.target nginx.target';
674
+      echo '';
675
+      echo '[Service]';
676
+      echo 'Type=simple';
677
+      echo 'User=matrix';
678
+      echo "WorkingDirectory=/etc/matrix";
679
+      echo "ExecStart=/usr/bin/python -m synapse.app.homeserver --config-path ${MATRIX_DATA_DIR}/homeserver.yaml";
680
+      echo 'Restart=on-failure';
681
+      echo 'RestartSec=10';
682
+      echo '';
683
+      echo '[Install]';
684
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/matrix.service
686 685
     systemctl enable matrix
687 686
     systemctl daemon-reload
688 687
     systemctl start matrix
@@ -701,18 +700,19 @@ function install_home_server {
701 700
     fi
702 701
     chmod -R 700 $MATRIX_DATA_DIR/homeserver.db
703 702
 
704
-    cd $MATRIX_DATA_DIR
703
+    cd "$MATRIX_DATA_DIR" || exit 365856835
705 704
     sqlite3 homeserver.db "PRAGMA auto_vacuum = FULL;"
706 705
 
707
-    MATRIX_ONION_HOSTNAME=$(add_onion_service matrix ${MATRIX_PORT} ${MATRIX_ONION_PORT})
706
+    #MATRIX_ONION_HOSTNAME=$(add_onion_service matrix ${MATRIX_PORT} ${MATRIX_ONION_PORT})
707
+    add_onion_service matrix ${MATRIX_PORT} ${MATRIX_ONION_PORT}
708 708
     echo "HiddenServicePort ${MATRIX_HTTP_PORT} 127.0.0.1:${MATRIX_FEDERATION_ONION_PORT}" >> /etc/tor/torrc
709 709
     systemctl restart tor
710 710
 
711
-    if [ ! ${MATRIX_PASSWORD} ]; then
712
-        if [ -f ${IMAGE_PASSWORD_FILE} ]; then
713
-            MATRIX_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
711
+    if [ ! "${MATRIX_PASSWORD}" ]; then
712
+        if [ -f "${IMAGE_PASSWORD_FILE}" ]; then
713
+            MATRIX_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
714 714
         else
715
-            MATRIX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
715
+            MATRIX_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
716 716
         fi
717 717
     fi
718 718
 
@@ -733,8 +733,8 @@ function install_matrix {
733 733
 
734 734
     check_ram_availability 1500
735 735
 
736
-    if [ ! -d $INSTALL_DIR ]; then
737
-        mkdir -p $INSTALL_DIR
736
+    if [ ! -d "$INSTALL_DIR" ]; then
737
+        mkdir -p "$INSTALL_DIR"
738 738
     fi
739 739
 
740 740
     if [[ ${ONION_ONLY} == 'no' ]]; then
@@ -806,19 +806,19 @@ function install_matrix {
806 806
     set_completion_param "matrix domain" "$MATRIX_DOMAIN_NAME"
807 807
 
808 808
     # Add avahi services
809
-    echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /etc/avahi/services/matrix.service
810
-    echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /etc/avahi/services/matrix.service
811
-    echo '<service-group>' >> /etc/avahi/services/matrix.service
812
-    echo '  <name replace-wildcards="yes">%h MATRIX</name>' >> /etc/avahi/services/matrix.service
813
-    echo '  <service>' >> /etc/avahi/services/matrix.service
814
-    echo '    <type>_matrix._tcp</type>' >> /etc/avahi/services/matrix.service
815
-    echo "    <port>$MATRIX_HTTP_PORT</port>" >> /etc/avahi/services/matrix.service
816
-    echo '  </service>' >> /etc/avahi/services/matrix.service
817
-    echo '  <service>' >> /etc/avahi/services/matrix.service
818
-    echo '    <type>_matrix._udp</type>' >> /etc/avahi/services/matrix.service
819
-    echo "    <port>$MATRIX_HTTP_PORT</port>" >> /etc/avahi/services/matrix.service
820
-    echo '  </service>' >> /etc/avahi/services/matrix.service
821
-    echo '</service-group>' >> /etc/avahi/services/matrix.service
809
+    { echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->';
810
+      echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">';
811
+      echo '<service-group>';
812
+      echo '  <name replace-wildcards="yes">%h MATRIX</name>';
813
+      echo '  <service>';
814
+      echo '    <type>_matrix._tcp</type>';
815
+      echo "    <port>$MATRIX_HTTP_PORT</port>";
816
+      echo '  </service>';
817
+      echo '  <service>';
818
+      echo '    <type>_matrix._udp</type>';
819
+      echo "    <port>$MATRIX_HTTP_PORT</port>";
820
+      echo '  </service>';
821
+      echo '</service-group>'; } > /etc/avahi/services/matrix.service
822 822
 
823 823
     systemctl restart avahi-daemon
824 824
 

+ 171
- 167
src/freedombone-app-mediagoblin Просмотреть файл

@@ -71,7 +71,7 @@ function mediagoblin_fix_email {
71 71
     if ! grep -q 'import os' $mgfile; then
72 72
         sed -i '/import sys/a import os' $mgfile
73 73
     fi
74
-    sed -i "s|return mhost.sendmail(from_addr, to_addrs, message.as_string())|return os.system(\"echo '\" + message_body + \"' \| mail -s '\" + message['Subject'] + \"' \" + message['To'])|g" $mgfile
74
+    sed -i "s|return mhost.sendmail(from_addr, to_addrs, message.as_string())|return os.system(\"echo '\" + message_body + \"' \\| mail -s '\" + message['Subject'] + \"' \" + message['To'])|g" $mgfile
75 75
 }
76 76
 
77 77
 function install_interactive_mediagoblin {
@@ -92,7 +92,7 @@ function configure_interactive_mediagoblin {
92 92
     dialog --title $"Mediagoblin" \
93 93
            --backtitle $"Freedombone Control Panel" \
94 94
            --defaultno \
95
-           --yesno $"\nAllow registration of new users?" 10 60
95
+           --yesno $"\\nAllow registration of new users?" 10 60
96 96
     sel=$?
97 97
     case $sel in
98 98
         0)
@@ -139,7 +139,7 @@ function reconfigure_mediagoblin {
139 139
 }
140 140
 
141 141
 function upgrade_mediagoblin {
142
-    CURR_MEDIAGOBLIN_COMMIT=$(cat $COMPLETION_FILE | grep "mediagoblin commit" | awk -F ':' '{print $2}')
142
+    CURR_MEDIAGOBLIN_COMMIT=$(grep "mediagoblin commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
143 143
     if [[ "$CURR_MEDIAGOBLIN_COMMIT" != "$MEDIAGOBLIN_COMMIT" ]]; then
144 144
         MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
145 145
         su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git stash && git pull" - mediagoblin
@@ -182,6 +182,7 @@ function restore_local_mediagoblin {
182 182
         else
183 183
             cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
184 184
         fi
185
+        # shellcheck disable=SC2181
185 186
         if [ ! "$?" = "0" ]; then
186 187
             function_check restore_directory_from_usb
187 188
             set_user_permissions
@@ -195,6 +196,7 @@ function restore_local_mediagoblin {
195 196
         else
196 197
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
197 198
         fi
199
+        # shellcheck disable=SC2181
198 200
         if [ ! "$?" = "0" ]; then
199 201
             function_check set_user_permissions
200 202
             set_user_permissions
@@ -214,24 +216,25 @@ function backup_remote_mediagoblin {
214 216
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
215 217
     if [ -d /etc/mediagoblin ]; then
216 218
         echo $"Backing up mediagoblin"
217
-        backup_directory_to_friend $MEDIAGOBLIN_BASE_DIR mediagoblin
219
+        backup_directory_to_friend "$MEDIAGOBLIN_BASE_DIR" mediagoblin
218 220
         backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
219 221
     fi
220 222
 }
221 223
 
222 224
 function restore_remote_mediagoblin {
223 225
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
224
-    if [ -d $SERVER_DIRECTORY/backup/mediagoblin ]; then
226
+    if [ -d "$SERVER_DIRECTORY/backup/mediagoblin" ]; then
225 227
         temp_restore_dir=/root/tempmediagoblin
226 228
         function_check get_completion_param
227 229
         MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
228 230
         function_check restore_directory_from_friend
229 231
         restore_directory_from_friend $temp_restore_dir mediagoblin
230
-        if [ -d ${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR ]; then
231
-            cp -r ${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR/* $MEDIAGOBLIN_BASE_DIR/
232
+        if [ -d "${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR" ]; then
233
+            cp -r "${temp_restore_dir}$MEDIAGOBLIN_BASE_DIR/*" "$MEDIAGOBLIN_BASE_DIR/"
232 234
         else
233
-            cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
235
+            cp -r "${temp_restore_dir}/*" "$MEDIAGOBLIN_BASE_DIR/"
234 236
         fi
237
+        # shellcheck disable=SC2181
235 238
         if [ ! "$?" = "0" ]; then
236 239
             exit 264824
237 240
         fi
@@ -241,12 +244,13 @@ function restore_remote_mediagoblin {
241 244
         else
242 245
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
243 246
         fi
247
+        # shellcheck disable=SC2181
244 248
         if [ ! "$?" = "0" ]; then
245 249
             exit 268492
246 250
         fi
247 251
         rm -rf ${temp_restore_dir}
248 252
         rm -rf ${temp_restore_dir}2
249
-        chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
253
+        chown -hR mediagoblin:www-data "$MEDIAGOBLIN_BASE_DIR"
250 254
         chown -hR mediagoblin:www-data /var/lib/mediagoblin
251 255
         chmod -R g+wx /var/lib/mediagoblin
252 256
     fi
@@ -264,17 +268,17 @@ function remove_mediagoblin {
264 268
 
265 269
     function_check remove_onion_service
266 270
     remove_onion_service mediagoblin ${MEDIAGOBLIN_ONION_PORT}
267
-    nginx_dissite $MEDIAGOBLIN_DOMAIN_NAME
268
-    remove_certs $MEDIAGOBLIN_DOMAIN_NAME
271
+    nginx_dissite "$MEDIAGOBLIN_DOMAIN_NAME"
272
+    remove_certs "$MEDIAGOBLIN_DOMAIN_NAME"
269 273
     if [ -d /var/lib/mediagoblin ]; then
270 274
         rm -rf /var/lib/mediagoblin
271 275
     fi
272
-    if [ -d $MEDIAGOBLIN_BASE_DIR ]; then
273
-        rm -rf $MEDIAGOBLIN_BASE_DIR
276
+    if [ -d "$MEDIAGOBLIN_BASE_DIR" ]; then
277
+        rm -rf "$MEDIAGOBLIN_BASE_DIR"
274 278
     fi
275 279
     remove_completion_param "install_mediagoblin"
276 280
     remove_completion_param "mediagoblin domain"
277
-    sed -i '/mediagoblin/d' $COMPLETION_FILE
281
+    sed -i '/mediagoblin/d' "$COMPLETION_FILE"
278 282
 
279 283
     remove_nodejs mediagoblin
280 284
 
@@ -282,11 +286,11 @@ function remove_mediagoblin {
282 286
     userdel -r mediagoblin
283 287
 
284 288
     function_check remove_ddns_domain
285
-    remove_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
289
+    remove_ddns_domain "$MEDIAGOBLIN_DOMAIN_NAME"
286 290
 }
287 291
 
288 292
 function install_mediagoblin {
289
-    if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
293
+    if [ ! "$MEDIAGOBLIN_DOMAIN_NAME" ]; then
290 294
         return
291 295
     fi
292 296
 
@@ -304,17 +308,17 @@ function install_mediagoblin {
304 308
     useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
305 309
     usermod --append -G mediagoblin mediagoblin
306 310
     mkdir -p /var/lib/mediagoblin
307
-    mkdir -p $MEDIAGOBLIN_BASE_DIR
308
-    chown -hR mediagoblin:www-data $MEDIAGOBLIN_BASE_DIR
311
+    mkdir -p "$MEDIAGOBLIN_BASE_DIR"
312
+    chown -hR mediagoblin:www-data "$MEDIAGOBLIN_BASE_DIR"
309 313
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
310 314
     chmod -R g+wx /var/lib/mediagoblin
311 315
 
312 316
     if [ -d /repos/mediagoblin ]; then
313
-        mkdir -p $MEDIAGOBLIN_BASE_DIR/mediagoblin
314
-        cp -r -p /repos/mediagoblin/. $MEDIAGOBLIN_BASE_DIR/mediagoblin
315
-        cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
317
+        mkdir -p "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
318
+        cp -r -p /repos/mediagoblin/. "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
319
+        cd "$MEDIAGOBLIN_BASE_DIR/mediagoblin" || exit 347593563
316 320
         git pull
317
-        chown -R mediagoblin:mediagoblin $MEDIAGOBLIN_BASE_DIR/mediagoblin
321
+        chown -R mediagoblin:mediagoblin "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
318 322
     else
319 323
         su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
320 324
     fi
@@ -340,7 +344,7 @@ function install_mediagoblin {
340 344
             gstreamer1.0-plugins-ugly \
341 345
             gstreamer1.0-libav \
342 346
             python-gst-1.0 python3-gst-1.0
343
-    cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
347
+    cd "$MEDIAGOBLIN_BASE_DIR/mediagoblin" || exit 76345672472
344 348
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
345 349
 
346 350
     # Audio plugin
@@ -349,14 +353,14 @@ function install_mediagoblin {
349 353
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
350 354
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/pip install scikits.audiolab" - mediagoblin
351 355
 
352
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
353
-        MEDIAGOBLIN_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
356
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
357
+        MEDIAGOBLIN_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
354 358
     else
355
-        if [ ! $MEDIAGOBLIN_ADMIN_PASSWORD ]; then
356
-            MEDIAGOBLIN_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
359
+        if [ ! "$MEDIAGOBLIN_ADMIN_PASSWORD" ]; then
360
+            MEDIAGOBLIN_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
357 361
         fi
358 362
     fi
359
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a mediagoblin -p "$MEDIAGOBLIN_ADMIN_PASSWORD"
363
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a mediagoblin -p "$MEDIAGOBLIN_ADMIN_PASSWORD"
360 364
 
361 365
     MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
362 366
     set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
@@ -365,157 +369,157 @@ function install_mediagoblin {
365 369
 
366 370
     if [[ $ONION_ONLY == "no" ]]; then
367 371
         function_check nginx_http_redirect
368
-        nginx_http_redirect $MEDIAGOBLIN_DOMAIN_NAME
369
-        echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
370
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
371
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
372
-        echo '    include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
373
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
374
-        echo '    autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
375
-        echo '    default_type  application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
376
-        echo '    sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
377
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
372
+        nginx_http_redirect "$MEDIAGOBLIN_DOMAIN_NAME"
373
+        { echo 'server {';
374
+          echo '    listen 443 ssl;';
375
+          echo '    #listen [::]:443 ssl;';
376
+          echo '    include /etc/nginx/mime.types;';
377
+          echo '';
378
+          echo '    autoindex off;';
379
+          echo '    default_type  application/octet-stream;';
380
+          echo '    sendfile on;';
381
+          echo ''; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
378 382
         function_check nginx_ssl
379
-        nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
383
+        nginx_ssl "$MEDIAGOBLIN_DOMAIN_NAME"
380 384
         function_check nginx_disable_sniffing
381
-        nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
385
+        nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
382 386
         function_check nginx_limits
383
-        nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
384
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
385
-        echo '    client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
386
-        echo '    client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
387
-        echo '    send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
388
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
389
-        echo '    fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
390
-        echo '    fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
391
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
392
-        echo '    gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
393
-        echo '    gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
394
-        echo '    gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
395
-        echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
396
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
397
-        echo "    server_name $MEDIAGOBLIN_DOMAIN_NAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
398
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
399
-        echo '    error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
400
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
401
-
402
-        echo '    location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
403
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
404
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
405
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
406
-        echo '    location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
407
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
408
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
409
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
410
-        echo '    location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
411
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
412
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
413
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
414
-        echo '    location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
415
-        echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
416
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
417
-        echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
418
-        echo '    location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
419
-        echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
420
-        echo '        include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
421
-        echo '        fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
422
-        echo '        fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
423
-        echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
424
-        echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
425
-        echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
387
+        nginx_limits "$MEDIAGOBLIN_DOMAIN_NAME" 800m
388
+        { echo '';
389
+          echo '    client_header_timeout 10m;';
390
+          echo '    client_body_timeout 10m;';
391
+          echo '    send_timeout 10m;';
392
+          echo '';
393
+          echo '    fastcgi_read_timeout 600;';
394
+          echo '    fastcgi_send_timeout 600;';
395
+          echo '';
396
+          echo '    gzip on;';
397
+          echo '    gzip_min_length 1024;';
398
+          echo '    gzip_buffers 4 32k;';
399
+          echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;';
400
+          echo '';
401
+          echo "    server_name $MEDIAGOBLIN_DOMAIN_NAME;";
402
+          echo '    access_log /dev/null;';
403
+          echo '    error_log /dev/null;';
404
+          echo '';
405
+
406
+          echo '    location /mgoblin_static/ {';
407
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;";
408
+          echo '    }';
409
+          echo '';
410
+          echo '    location /mgoblin_media/ {';
411
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;";
412
+          echo '    }';
413
+          echo '';
414
+          echo '    location /theme_static/ {';
415
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;";
416
+          echo '    }';
417
+          echo '';
418
+          echo '    location /plugin_static/ {';
419
+          echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;";
420
+          echo '    }';
421
+          echo '';
422
+          echo '    location / {';
423
+          echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;";
424
+          echo '        include /etc/nginx/fastcgi_params;';
425
+          echo "        fastcgi_param PATH_INFO \$fastcgi_script_name;";
426
+          echo '        fastcgi_param SCRIPT_NAME "";';
427
+          echo '        fastcgi_read_timeout 30;';
428
+          echo '    }';
429
+          echo '}'; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
426 430
     else
427
-        echo -n '' > /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
431
+        echo -n '' > "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
428 432
     fi
429
-    echo 'server {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
430
-    echo "    listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
431
-    echo '    include /etc/nginx/mime.types;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
432
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
433
-    echo '    autoindex off;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
434
-    echo '    default_type  application/octet-stream;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
435
-    echo '    sendfile on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
436
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
433
+    { echo 'server {';
434
+      echo "    listen 127.0.0.1:${MEDIAGOBLIN_ONION_PORT} default_server;";
435
+      echo '    include /etc/nginx/mime.types;';
436
+      echo '';
437
+      echo '    autoindex off;';
438
+      echo '    default_type  application/octet-stream;';
439
+      echo '    sendfile on;';
440
+      echo ''; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
437 441
     function_check nginx_disable_sniffing
438
-    nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
442
+    nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
439 443
     function_check nginx_limits
440
-    nginx_limits $MEDIAGOBLIN_DOMAIN_NAME 800m
441
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
442
-    echo '    client_header_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
443
-    echo '    client_body_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
444
-    echo '    send_timeout 10m;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
445
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
446
-    echo '    fastcgi_read_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
447
-    echo '    fastcgi_send_timeout 600;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
448
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
449
-    echo '    gzip on;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
450
-    echo '    gzip_min_length 1024;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
451
-    echo '    gzip_buffers 4 32k;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
452
-    echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
453
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
454
-    echo "    server_name $MEDIAGOBLIN_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
455
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
456
-    echo '    error_log /dev/null;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
457
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
458
-
459
-    echo '    location /mgoblin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
460
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
461
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
462
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
463
-    echo '    location /mgoblin_media/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
464
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
465
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
466
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
467
-    echo '    location /theme_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
468
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
469
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
470
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
471
-    echo '    location /plugin_static/ {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
472
-    echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
473
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
474
-    echo '' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
475
-    echo '    location / {' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
476
-    echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;" >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
477
-    echo '        include /etc/nginx/fastcgi_params;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
478
-    echo '        fastcgi_param PATH_INFO $fastcgi_script_name;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
479
-    echo '        fastcgi_param SCRIPT_NAME "";' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
480
-    echo '        fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
481
-    echo '    }' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
482
-    echo '}' >> /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
483
-
484
-    echo '[Unit]' > /etc/systemd/system/mediagoblin.service
485
-    echo 'Description=Media service' >> /etc/systemd/system/mediagoblin.service
486
-    echo 'Requires=network.target' >> /etc/systemd/system/mediagoblin.service
487
-    echo 'After=network.target' >> /etc/systemd/system/mediagoblin.service
488
-    echo '' >> /etc/systemd/system/mediagoblin.service
489
-    echo '[Service]' >> /etc/systemd/system/mediagoblin.service
490
-    echo 'Type=simple' >> /etc/systemd/system/mediagoblin.service
491
-    echo 'User=mediagoblin' >> /etc/systemd/system/mediagoblin.service
492
-    echo 'Group=mediagoblin' >> /etc/systemd/system/mediagoblin.service
493
-    echo "WorkingDirectory=$MEDIAGOBLIN_BASE_DIR/mediagoblin/" >> /etc/systemd/system/mediagoblin.service
494
-    echo "ExecStart=$MEDIAGOBLIN_BASE_DIR/mediagoblin/lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=$MEDIAGOBLIN_PORT" >> /etc/systemd/system/mediagoblin.service
495
-    echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini CELERY_ALWAYS_EAGER=true" >> /etc/systemd/system/mediagoblin.service
496
-    echo 'Restart=always' >> /etc/systemd/system/mediagoblin.service
497
-    echo 'RestartSec=10' >> /etc/systemd/system/mediagoblin.service
498
-    echo '' >> /etc/systemd/system/mediagoblin.service
499
-    echo '[Install]' >> /etc/systemd/system/mediagoblin.service
500
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mediagoblin.service
444
+    nginx_limits "$MEDIAGOBLIN_DOMAIN_NAME" 800m
445
+    { echo '';
446
+      echo '    client_header_timeout 10m;';
447
+      echo '    client_body_timeout 10m;';
448
+      echo '    send_timeout 10m;';
449
+      echo '';
450
+      echo '    fastcgi_read_timeout 600;';
451
+      echo '    fastcgi_send_timeout 600;';
452
+      echo '';
453
+      echo '    gzip on;';
454
+      echo '    gzip_min_length 1024;';
455
+      echo '    gzip_buffers 4 32k;';
456
+      echo '    gzip_types text/plain application/x-javascript text/javascript text/xml text/css;';
457
+      echo '';
458
+      echo "    server_name $MEDIAGOBLIN_ONION_HOSTNAME;";
459
+      echo '    access_log /dev/null;';
460
+      echo '    error_log /dev/null;';
461
+      echo '';
462
+
463
+      echo '    location /mgoblin_static/ {';
464
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin/static/;";
465
+      echo '    }';
466
+      echo '';
467
+      echo '    location /mgoblin_media/ {';
468
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/media/public/;";
469
+      echo '    }';
470
+      echo '';
471
+      echo '    location /theme_static/ {';
472
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/theme_static/;";
473
+      echo '    }';
474
+      echo '';
475
+      echo '    location /plugin_static/ {';
476
+      echo "        alias $MEDIAGOBLIN_BASE_DIR/mediagoblin/user_dev/plugin_static/;";
477
+      echo '    }';
478
+      echo '';
479
+      echo '    location / {';
480
+      echo "        fastcgi_pass 127.0.0.1:$MEDIAGOBLIN_PORT;";
481
+      echo '        include /etc/nginx/fastcgi_params;';
482
+      echo "        fastcgi_param PATH_INFO \$fastcgi_script_name;";
483
+      echo '        fastcgi_param SCRIPT_NAME "";';
484
+      echo '        fastcgi_read_timeout 30;';
485
+      echo '    }';
486
+      echo '}'; } >> "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
487
+
488
+    { echo '[Unit]';
489
+      echo 'Description=Media service';
490
+      echo 'Requires=network.target';
491
+      echo 'After=network.target';
492
+      echo '';
493
+      echo '[Service]';
494
+      echo 'Type=simple';
495
+      echo 'User=mediagoblin';
496
+      echo 'Group=mediagoblin';
497
+      echo "WorkingDirectory=$MEDIAGOBLIN_BASE_DIR/mediagoblin/";
498
+      echo "ExecStart=$MEDIAGOBLIN_BASE_DIR/mediagoblin/lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=$MEDIAGOBLIN_PORT";
499
+      echo "Environment=MEDIAGOBLIN_CONFIG=$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini CELERY_ALWAYS_EAGER=true";
500
+      echo 'Restart=always';
501
+      echo 'RestartSec=10';
502
+      echo '';
503
+      echo '[Install]';
504
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/mediagoblin.service
501 505
     chmod +x /etc/systemd/system/mediagoblin.service
502 506
 
503 507
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
504 508
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
505 509
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg makeadmin $MY_USERNAME" - mediagoblin
506 510
 
507
-    sed -i 's|email_debug_mode.*|email_debug_mode = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
508
-    sed -i "s|email_sender_address.*|email_sender_address = \"noreply@${DEFAULT_DOMAIN_NAME}\"|g" $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
511
+    sed -i 's|email_debug_mode.*|email_debug_mode = false|g' "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
512
+    sed -i "s|email_sender_address.*|email_sender_address = \"noreply@${DEFAULT_DOMAIN_NAME}\"|g" "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
509 513
 
510
-    sed -i 's|allow_reporting.*|allow_reporting = false|g' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
514
+    sed -i 's|allow_reporting.*|allow_reporting = false|g' "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
511 515
 
512
-    if ! grep -q '[[[skip_transcode]]]' $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini; then
513
-        echo '[[[skip_transcode]]]' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
514
-        echo 'mime_types = video/webm, video/ogg, video/mp4, audio/ogg, application/ogg, application/x-annodex' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
515
-        echo 'container_formats = Matroska, Ogg, ISO MP4/M4A' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
516
-        echo 'video_codecs = VP8 video, VP9 video, Theora, H.264, H.264 / AVC, MPEG-4 video' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
517
-        echo 'audio_codecs = Vorbis, MPEG-4 AAC' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
518
-        echo 'dimensions_match = false' >> $MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini
516
+    if ! grep -q '[[[skip_transcode]]]' "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"; then
517
+        { echo '[[[skip_transcode]]]';
518
+          echo 'mime_types = video/webm, video/ogg, video/mp4, audio/ogg, application/ogg, application/x-annodex';
519
+          echo 'container_formats = Matroska, Ogg, ISO MP4/M4A';
520
+          echo 'video_codecs = VP8 video, VP9 video, Theora, H.264, H.264 / AVC, MPEG-4 video';
521
+          echo 'audio_codecs = Vorbis, MPEG-4 AAC';
522
+          echo 'dimensions_match = false'; } >> "$MEDIAGOBLIN_BASE_DIR/mediagoblin/mediagoblin_local.ini"
519 523
     fi
520 524
 
521 525
     systemctl enable mediagoblin
@@ -529,18 +533,18 @@ function install_mediagoblin {
529 533
     fi
530 534
 
531 535
     function_check create_site_certificate
532
-    create_site_certificate $MEDIAGOBLIN_DOMAIN_NAME 'yes'
536
+    create_site_certificate "$MEDIAGOBLIN_DOMAIN_NAME" 'yes'
533 537
 
534 538
     function_check configure_php
535 539
     configure_php
536 540
 
537
-    nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
541
+    nginx_ensite "$MEDIAGOBLIN_DOMAIN_NAME"
538 542
 
539 543
     systemctl restart php7.0-fpm
540 544
     systemctl restart nginx
541 545
 
542 546
     function_check add_ddns_domain
543
-    add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
547
+    add_ddns_domain "$MEDIAGOBLIN_DOMAIN_NAME"
544 548
 
545 549
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
546 550
     chmod -R g+wx /var/lib/mediagoblin

+ 206
- 206
src/freedombone-app-movim Просмотреть файл

@@ -58,19 +58,19 @@ function logging_off_movim {
58 58
 function remove_user_movim {
59 59
     remove_username="$1"
60 60
 
61
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp movim
61
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp movim
62 62
 }
63 63
 
64 64
 function add_user_movim {
65 65
     new_username="$1"
66 66
     new_user_password="$2"
67 67
 
68
-    ${PROJECT_NAME}-pass -u $new_username -a movim -p "$new_user_password"
68
+    "${PROJECT_NAME}-pass" -u "$new_username" -a movim -p "$new_user_password"
69 69
     echo '0'
70 70
 }
71 71
 
72 72
 function install_interactive_movim {
73
-    if [ ! $ONION_ONLY ]; then
73
+    if [ ! "$ONION_ONLY" ]; then
74 74
         ONION_ONLY='no'
75 75
     fi
76 76
 
@@ -80,39 +80,38 @@ function install_interactive_movim {
80 80
         MOVIM_DETAILS_COMPLETE=
81 81
         while [ ! $MOVIM_DETAILS_COMPLETE ]
82 82
         do
83
-            data=$(tempfile 2>/dev/null)
84
-            trap "rm -f $data" 0 1 2 5 15
83
+            data=$(mktemp 2>/dev/null)
85 84
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
86 85
                 dialog --backtitle $"Freedombone Configuration" \
87 86
                        --title $"Movim Configuration" \
88
-                       --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
87
+                       --form $"\\nPlease enter your Movim details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
89 88
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
90 89
                        $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
91
-                       2> $data
90
+                       2> "$data"
92 91
             else
93 92
                 dialog --backtitle $"Freedombone Configuration" \
94 93
                        --title $"Movim Configuration" \
95
-                       --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
94
+                       --form $"\\nPlease enter your Movim details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
96 95
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
97
-                       2> $data
96
+                       2> "$data"
98 97
             fi
99 98
             sel=$?
100 99
             case $sel in
101 100
                 1) exit 1;;
102 101
                 255) exit 1;;
103 102
             esac
104
-            MOVIM_DOMAIN_NAME=$(cat $data | sed -n 1p)
105
-            if [ $MOVIM_DOMAIN_NAME ]; then
103
+            MOVIM_DOMAIN_NAME=$(sed -n 1p < "$data")
104
+            if [ "$MOVIM_DOMAIN_NAME" ]; then
106 105
                 TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
107 106
                 validate_domain_name
108
-                if [[ $TEST_DOMAIN_NAME != $MOVIM_DOMAIN_NAME ]]; then
107
+                if [[ "$TEST_DOMAIN_NAME" != "$MOVIM_DOMAIN_NAME" ]]; then
109 108
                     MOVIM_DOMAIN_NAME=
110 109
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
111 110
                 else
112 111
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
113
-                        MOVIM_CODE=$(cat $data | sed -n 2p)
112
+                        MOVIM_CODE=$(sed -n 2p < "$data")
114 113
                         validate_freedns_code "$MOVIM_CODE"
115
-                        if [ ! $VALID_CODE ]; then
114
+                        if [ ! "$VALID_CODE" ]; then
116 115
                             MOVIM_DOMAIN_NAME=
117 116
                         fi
118 117
                     fi
@@ -121,6 +120,7 @@ function install_interactive_movim {
121 120
             if [ $MOVIM_DOMAIN_NAME ]; then
122 121
                 MOVIM_DETAILS_COMPLETE="yes"
123 122
             fi
123
+            rm -f "$data"
124 124
         done
125 125
 
126 126
         # save the results in the config file
@@ -136,23 +136,23 @@ function change_password_movim {
136 136
 
137 137
     read_config_param 'MOVIM_DOMAIN_NAME'
138 138
 
139
-    ${PROJECT_NAME}-pass -u "$curr_username" -a movim -p "$new_user_password"
139
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a movim -p "$new_user_password"
140 140
 }
141 141
 
142 142
 function movim_create_database {
143
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
144
-        MOVIM_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
143
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
144
+        MOVIM_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
145 145
     else
146
-        if [ ! $MOVIM_ADMIN_PASSWORD ]; then
147
-            MOVIM_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
146
+        if [ ! "$MOVIM_ADMIN_PASSWORD" ]; then
147
+            MOVIM_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
148 148
         fi
149 149
     fi
150
-    if [ ! $MOVIM_ADMIN_PASSWORD ]; then
150
+    if [ ! "$MOVIM_ADMIN_PASSWORD" ]; then
151 151
         return
152 152
     fi
153 153
 
154 154
     function_check create_database
155
-    create_database movim "$MOVIM_ADMIN_PASSWORD" $MY_USERNAME
155
+    create_database movim "$MOVIM_ADMIN_PASSWORD" "$MY_USERNAME"
156 156
 }
157 157
 
158 158
 function reconfigure_movim {
@@ -165,35 +165,35 @@ function upgrade_movim {
165 165
         return
166 166
     fi
167 167
 
168
-    if grep -q "movim domain" $COMPLETION_FILE; then
168
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
169 169
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
170 170
     fi
171 171
 
172 172
     # update to the next commit
173 173
     function_check set_repo_commit
174
-    set_repo_commit /var/www/$MOVIM_DOMAIN_NAME/htdocs "movim commit" "$MOVIM_COMMIT" $MOVIM_REPO
174
+    set_repo_commit "/var/www/$MOVIM_DOMAIN_NAME/htdocs" "movim commit" "$MOVIM_COMMIT" "$MOVIM_REPO"
175 175
 
176
-    cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
176
+    cd "/var/www/${MOVIM_DOMAIN_NAME}/htdocs" || exit 6734824522
177 177
     php composer.phar install
178 178
     php mud.php db --set
179
-    chown -R www-data:www-data /var/www/${MOVIM_DOMAIN_NAME}/htdocs
179
+    chown -R www-data:www-data "/var/www/${MOVIM_DOMAIN_NAME}/htdocs"
180 180
 }
181 181
 
182 182
 
183 183
 function backup_local_movim {
184 184
     MOVIM_DOMAIN_NAME='movim'
185
-    if grep -q "movim domain" $COMPLETION_FILE; then
185
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
186 186
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
187 187
     fi
188 188
 
189
-    source_directory=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
190
-    if [ -d $source_directory ]; then
189
+    source_directory="/var/www/${MOVIM_DOMAIN_NAME}/htdocs"
190
+    if [ -d "$source_directory" ]; then
191 191
         dest_directory=movim
192 192
         function_check suspend_site
193
-        suspend_site ${MOVIM_DOMAIN_NAME}
193
+        suspend_site "${MOVIM_DOMAIN_NAME}"
194 194
 
195 195
         function_check backup_directory_to_usb
196
-        backup_directory_to_usb $source_directory $dest_directory
196
+        backup_directory_to_usb "$source_directory" "$dest_directory"
197 197
 
198 198
         function_check backup_database_to_usb
199 199
         backup_database_to_usb movim
@@ -204,28 +204,28 @@ function backup_local_movim {
204 204
 }
205 205
 
206 206
 function restore_local_movim {
207
-    if ! grep -q "movim domain" $COMPLETION_FILE; then
207
+    if ! grep -q "movim domain" "$COMPLETION_FILE"; then
208 208
         return
209 209
     fi
210 210
     MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
211
-    if [ $MOVIM_DOMAIN_NAME ]; then
211
+    if [ "$MOVIM_DOMAIN_NAME" ]; then
212 212
         echo $"Restoring movim"
213 213
         temp_restore_dir=/root/tempmovim
214 214
         movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
215 215
         # stop the daemons
216
-        cd $movim_dir
216
+        cd "$movim_dir" || exit 7856724252
217 217
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
218 218
 
219 219
         function_check movim_create_database
220 220
         movim_create_database
221 221
 
222
-        restore_database movim ${MOVIM_DOMAIN_NAME}
222
+        restore_database movim "${MOVIM_DOMAIN_NAME}"
223 223
         if [ -d $temp_restore_dir ]; then
224 224
             rm -rf $temp_restore_dir
225 225
         fi
226 226
 
227
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
228
-        cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
227
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
228
+        cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs/config" || exit 2468724682
229 229
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
230 230
         MARIADB_PASSWORD=
231 231
 
@@ -234,18 +234,18 @@ function restore_local_movim {
234 234
 }
235 235
 
236 236
 function backup_remote_movim {
237
-    if grep -q "movim domain" $COMPLETION_FILE; then
237
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
238 238
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
239 239
         temp_backup_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
240
-        if [ -d $temp_backup_dir ]; then
240
+        if [ -d "$temp_backup_dir" ]; then
241 241
             function_check suspend_site
242
-            suspend_site ${MOVIM_DOMAIN_NAME}
242
+            suspend_site "${MOVIM_DOMAIN_NAME}"
243 243
 
244 244
             function_check backup_database_to_friend
245 245
             backup_database_to_friend movim
246 246
 
247 247
             function_check backup_directory_to_friend
248
-            backup_directory_to_friend $temp_backup_dir movim
248
+            backup_directory_to_friend "$temp_backup_dir" movim
249 249
 
250 250
             function_check restart_site
251 251
             restart_site
@@ -256,25 +256,25 @@ function backup_remote_movim {
256 256
 }
257 257
 
258 258
 function restore_remote_movim {
259
-    if grep -q "movim domain" $COMPLETION_FILE; then
259
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
260 260
         echo $"Restoring movim"
261 261
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
262 262
 
263 263
         # stop the daemons
264
-        cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
264
+        cd "/var/www/${MOVIM_DOMAIN_NAME}/htdocs" || exit 524792846827
265 265
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
266 266
 
267 267
         function_check movim_create_database
268 268
         movim_create_database
269 269
 
270 270
         function_check restore_database_from_friend
271
-        restore_database_from_friend movim ${MOVIM_DOMAIN_NAME}
271
+        restore_database_from_friend movim "${MOVIM_DOMAIN_NAME}"
272 272
         if [ -d /root/tempmovim ]; then
273 273
             rm -rf /root/tempmovim
274 274
         fi
275 275
 
276
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
277
-        cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
276
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
277
+        cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs/config" || exit 4242462487
278 278
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
279 279
         MARIADB_PASSWORD=
280 280
 
@@ -298,14 +298,14 @@ function remove_movim {
298 298
 
299 299
     read_config_param "MY_USERNAME"
300 300
     echo "Removing $MOVIM_DOMAIN_NAME"
301
-    nginx_dissite $MOVIM_DOMAIN_NAME
302
-    remove_certs $MOVIM_DOMAIN_NAME
301
+    nginx_dissite "$MOVIM_DOMAIN_NAME"
302
+    remove_certs "$MOVIM_DOMAIN_NAME"
303 303
 
304
-    if [ -d /var/www/$MOVIM_DOMAIN_NAME ]; then
305
-        rm -rf /var/www/$MOVIM_DOMAIN_NAME
304
+    if [ -d "/var/www/$MOVIM_DOMAIN_NAME" ]; then
305
+        rm -rf "/var/www/$MOVIM_DOMAIN_NAME"
306 306
     fi
307
-    if [ -f /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME ]; then
308
-        rm /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
307
+    if [ -f "/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME" ]; then
308
+        rm "/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME"
309 309
     fi
310 310
     function_check drop_database
311 311
     drop_database movim
@@ -316,15 +316,15 @@ function remove_movim {
316 316
     fi
317 317
     remove_app movim
318 318
     remove_completion_param install_movim
319
-    sed -i '/movim/d' $COMPLETION_FILE
319
+    sed -i '/movim/d' "$COMPLETION_FILE"
320 320
     remove_backup_database_local movim
321 321
 
322 322
     function_check remove_ddns_domain
323
-    remove_ddns_domain $MOVIM_DOMAIN_NAME
323
+    remove_ddns_domain "$MOVIM_DOMAIN_NAME"
324 324
 }
325 325
 
326 326
 function install_movim {
327
-    if [ ! $MOVIM_DOMAIN_NAME ]; then
327
+    if [ ! "$MOVIM_DOMAIN_NAME" ]; then
328 328
         echo $'No domain name was given for movim'
329 329
         exit 72572
330 330
     fi
@@ -333,7 +333,7 @@ function install_movim {
333 333
         return
334 334
     fi
335 335
 
336
-    movim_hourly_script movim $MOVIM_DOMAIN_NAME
336
+    movim_hourly_script movim "$MOVIM_DOMAIN_NAME"
337 337
 
338 338
     function_check install_mariadb
339 339
     install_mariadb
@@ -347,221 +347,221 @@ function install_movim {
347 347
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
348 348
     apt-get -yq install php-memcached php-intl exiftool php-imagick libfcgi0ldbl
349 349
 
350
-    if [ ! -d /var/www/$MOVIM_DOMAIN_NAME ]; then
351
-        mkdir /var/www/$MOVIM_DOMAIN_NAME
350
+    if [ ! -d "/var/www/$MOVIM_DOMAIN_NAME" ]; then
351
+        mkdir "/var/www/$MOVIM_DOMAIN_NAME"
352 352
     fi
353
-    if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
353
+    if [ ! -d "/var/www/$MOVIM_DOMAIN_NAME/htdocs" ]; then
354 354
 
355 355
         if [ -d /repos/movim ]; then
356
-            mkdir /var/www/$MOVIM_DOMAIN_NAME/htdocs
357
-            cp -r -p /repos/movim/. /var/www/$MOVIM_DOMAIN_NAME/htdocs
358
-            cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
356
+            mkdir "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
357
+            cp -r -p /repos/movim/. "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
358
+            cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 3768568325
359 359
             git pull
360 360
         else
361 361
             function_check git_clone
362
-            git_clone $MOVIM_REPO /var/www/$MOVIM_DOMAIN_NAME/htdocs
362
+            git_clone "$MOVIM_REPO" "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
363 363
         fi
364 364
 
365
-        if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
365
+        if [ ! -d "/var/www/$MOVIM_DOMAIN_NAME/htdocs" ]; then
366 366
             echo $'Unable to clone movim repo'
367 367
             exit 76285
368 368
         fi
369 369
     fi
370 370
 
371
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
371
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 7345247242
372 372
     git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
373 373
     set_completion_param "movim commit" "$MOVIM_COMMIT"
374 374
 
375 375
     # default login
376
-    if [ ! -f /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php ]; then
376
+    if [ ! -f "/var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php" ]; then
377 377
         echo $'Unable to find Config.php'
378 378
         exit 72352
379 379
     fi
380
-    sed -i "s|'admin'|'${MY_USERNAME}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
381
-    sed -i "s|'password'|'${MOVIM_ADMIN_PASSWORD}'|g" /var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php
380
+    sed -i "s|'admin'|'${MY_USERNAME}'|g" "/var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php"
381
+    sed -i "s|'password'|'${MOVIM_ADMIN_PASSWORD}'|g" "/var/www/$MOVIM_DOMAIN_NAME/htdocs/app/models/config/Config.php"
382 382
 
383 383
     # Fix typo
384 384
     sed -i 's|weksocket|websocket|g' app/widgets/AdminTest/admintest.js
385 385
 
386
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
386
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 784368245224
387 387
     install_composer
388 388
 
389
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
389
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs/config" || exit 6428764224
390 390
     cp db.example.inc.php db.inc.php
391 391
     sed -i "s|'username'.*|'username'    => 'root',|g" db.inc.php
392 392
     sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
393 393
     sed -i "s|'database'.*|'database'    => 'movim'|g" db.inc.php
394 394
     php mud.php db --set
395 395
 
396
-    chmod u+rwx /var/www/$MOVIM_DOMAIN_NAME/htdocs
397
-    chown -R www-data:www-data /var/www/$MOVIM_DOMAIN_NAME/htdocs
396
+    chmod u+rwx "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
397
+    chown -R www-data:www-data "/var/www/$MOVIM_DOMAIN_NAME/htdocs"
398 398
 
399 399
     function_check movim_create_database
400 400
     movim_create_database
401 401
 
402 402
     function_check add_ddns_domain
403
-    add_ddns_domain $MOVIM_DOMAIN_NAME
403
+    add_ddns_domain "$MOVIM_DOMAIN_NAME"
404 404
 
405 405
     MOVIM_ONION_HOSTNAME=$(add_onion_service movim 80 ${MOVIM_ONION_PORT})
406 406
 
407
-    echo '[Unit]' > /etc/systemd/system/movim.service
408
-    echo 'Description=Movim daemon' >> /etc/systemd/system/movim.service
409
-    echo 'After=network.target nginx.target' >> /etc/systemd/system/movim.service
410
-    echo '' >> /etc/systemd/system/movim.service
411
-    echo '[Service]' >> /etc/systemd/system/movim.service
412
-    echo 'Type=simple' >> /etc/systemd/system/movim.service
413
-    echo 'User=www-data' >> /etc/systemd/system/movim.service
414
-    echo "WorkingDirectory=/var/www/$MOVIM_DOMAIN_NAME/htdocs" >> /etc/systemd/system/movim.service
407
+    { echo '[Unit]';
408
+      echo 'Description=Movim daemon';
409
+      echo 'After=network.target nginx.target';
410
+      echo '';
411
+      echo '[Service]';
412
+      echo 'Type=simple';
413
+      echo 'User=www-data';
414
+      echo "WorkingDirectory=/var/www/$MOVIM_DOMAIN_NAME/htdocs"; } > /etc/systemd/system/movim.service
415 415
     if [[ $ONION_ONLY == 'no' ]]; then
416 416
         echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=https://$MOVIM_DOMAIN_NAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
417 417
     else
418 418
         echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=http://$MOVIM_ONION_HOSTNAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
419 419
     fi
420
-    echo 'StandardOutput=syslog' >> /etc/systemd/system/movim.service
421
-    echo 'SyslogIdentifier=movim' >> /etc/systemd/system/movim.service
422
-    echo 'PIDFile=/run/movim.pid' >> /etc/systemd/system/movim.service
423
-    echo 'Restart=on-failure' >> /etc/systemd/system/movim.service
424
-    echo 'RestartSec=10' >> /etc/systemd/system/movim.service
425
-    echo '' >> /etc/systemd/system/movim.service
426
-    echo '[Install]' >> /etc/systemd/system/movim.service
427
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/movim.service
420
+    { echo 'StandardOutput=syslog';
421
+      echo 'SyslogIdentifier=movim';
422
+      echo 'PIDFile=/run/movim.pid';
423
+      echo 'Restart=on-failure';
424
+      echo 'RestartSec=10';
425
+      echo '';
426
+      echo '[Install]';
427
+      echo 'WantedBy=multi-user.target'; } >> /etc/systemd/system/movim.service
428 428
     systemctl enable movim
429 429
     systemctl daemon-reload
430 430
 
431 431
     movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
432 432
     if [[ $ONION_ONLY == "no" ]]; then
433 433
         function_check nginx_http_redirect
434
-        nginx_http_redirect $MOVIM_DOMAIN_NAME "index index.php"
435
-        echo 'server {' >> $movim_nginx_site
436
-        echo '  listen 443 ssl;' >> $movim_nginx_site
437
-        echo '  #listen [::]:443 ssl;' >> $movim_nginx_site
438
-        echo "  server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
439
-        echo '' >> $movim_nginx_site
434
+        nginx_http_redirect "$MOVIM_DOMAIN_NAME" "index index.php"
435
+        { echo 'server {';
436
+          echo '  listen 443 ssl;';
437
+          echo '  #listen [::]:443 ssl;';
438
+          echo "  server_name $MOVIM_DOMAIN_NAME;";
439
+          echo ''; } >> "$movim_nginx_site"
440 440
         function_check nginx_compress
441
-        nginx_compress $MOVIM_DOMAIN_NAME
442
-        echo '' >> $movim_nginx_site
443
-        echo '  # Security' >> $movim_nginx_site
441
+        nginx_compress "$MOVIM_DOMAIN_NAME"
442
+        echo '' >> "$movim_nginx_site"
443
+        echo '  # Security' >> "$movim_nginx_site"
444 444
         function_check nginx_ssl
445
-        nginx_ssl $MOVIM_DOMAIN_NAME
445
+        nginx_ssl "$MOVIM_DOMAIN_NAME"
446 446
 
447 447
         function_check nginx_disable_sniffing
448
-        nginx_disable_sniffing $MOVIM_DOMAIN_NAME
449
-
450
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $movim_nginx_site
451
-        echo '' >> $movim_nginx_site
452
-        echo '  # Logs' >> $movim_nginx_site
453
-        echo '  access_log /dev/null;' >> $movim_nginx_site
454
-        echo '  error_log /dev/null;' >> $movim_nginx_site
455
-        echo '' >> $movim_nginx_site
456
-        echo '  # Root' >> $movim_nginx_site
457
-        echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
458
-        echo '' >> $movim_nginx_site
459
-        echo '  # Index' >> $movim_nginx_site
460
-        echo '  index index.php;' >> $movim_nginx_site
461
-        echo '' >> $movim_nginx_site
462
-        echo '  # PHP' >> $movim_nginx_site
463
-        echo '  location ~ \.php {' >> $movim_nginx_site
464
-        echo '    include snippets/fastcgi-php.conf;' >> $movim_nginx_site
465
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $movim_nginx_site
466
-        echo '    fastcgi_read_timeout 30;' >> $movim_nginx_site
467
-        echo '  }' >> $movim_nginx_site
468
-        echo '' >> $movim_nginx_site
469
-        echo '  # Location' >> $movim_nginx_site
470
-        echo '  location / {' >> $movim_nginx_site
448
+        nginx_disable_sniffing "$MOVIM_DOMAIN_NAME"
449
+
450
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
451
+          echo '';
452
+          echo '  # Logs';
453
+          echo '  access_log /dev/null;';
454
+          echo '  error_log /dev/null;';
455
+          echo '';
456
+          echo '  # Root';
457
+          echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;";
458
+          echo '';
459
+          echo '  # Index';
460
+          echo '  index index.php;';
461
+          echo '';
462
+          echo '  # PHP';
463
+          echo '  location ~ \.php {';
464
+          echo '    include snippets/fastcgi-php.conf;';
465
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
466
+          echo '    fastcgi_read_timeout 30;';
467
+          echo '  }';
468
+          echo '';
469
+          echo '  # Location';
470
+          echo '  location / {'; } >> "$movim_nginx_site"
471 471
         function_check nginx_limits
472
-        nginx_limits $MOVIM_DOMAIN_NAME '15m'
473
-        echo '    try_files $uri $uri/ @movim;' >> $movim_nginx_site
474
-        echo '  }' >> $movim_nginx_site
475
-        echo '' >> $movim_nginx_site
476
-        echo '  location /ws/ {' >> $movim_nginx_site
477
-        echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
478
-        echo '    proxy_http_version 1.1;' >> $movim_nginx_site
479
-        echo '    proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
480
-        echo '    proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
481
-        echo '    proxy_set_header Host $host;' >> $movim_nginx_site
482
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
483
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
484
-        echo '    proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
485
-        echo '    proxy_redirect off;' >> $movim_nginx_site
486
-        echo '  }' >> $movim_nginx_site
487
-        echo '' >> $movim_nginx_site
488
-        echo '  # Fancy URLs' >> $movim_nginx_site
489
-        echo '  location @movim {' >> $movim_nginx_site
490
-        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
491
-        echo '  }' >> $movim_nginx_site
492
-        echo '' >> $movim_nginx_site
493
-        echo '  # Restrict access that is unnecessary anyway' >> $movim_nginx_site
494
-        echo '  location ~ /\.(ht|git) {' >> $movim_nginx_site
495
-        echo '    deny all;' >> $movim_nginx_site
496
-        echo '  }' >> $movim_nginx_site
497
-        echo '' >> $movim_nginx_site
498
-        echo '}' >> $movim_nginx_site
472
+        nginx_limits "$MOVIM_DOMAIN_NAME" '15m'
473
+        { echo "    try_files \$uri \$uri/ @movim;";
474
+          echo '  }';
475
+          echo '';
476
+          echo '  location /ws/ {';
477
+          echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;";
478
+          echo '    proxy_http_version 1.1;';
479
+          echo "    proxy_set_header Upgrade \$http_upgrade;";
480
+          echo '    proxy_set_header Connection "Upgrade";';
481
+          echo "    proxy_set_header Host \$host;";
482
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
483
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
484
+          echo '    proxy_set_header X-Forwarded-Proto https;';
485
+          echo '    proxy_redirect off;';
486
+          echo '  }';
487
+          echo '';
488
+          echo '  # Fancy URLs';
489
+          echo '  location @movim {';
490
+          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
491
+          echo '  }';
492
+          echo '';
493
+          echo '  # Restrict access that is unnecessary anyway';
494
+          echo '  location ~ /\.(ht|git) {';
495
+          echo '    deny all;';
496
+          echo '  }';
497
+          echo '';
498
+          echo '}'; } >> "$movim_nginx_site"
499 499
     else
500
-        echo -n '' > $movim_nginx_site
500
+        echo -n '' > "$movim_nginx_site"
501 501
     fi
502
-    echo 'server {' >> $movim_nginx_site
503
-    echo "    listen 127.0.0.1:$MOVIM_ONION_PORT default_server;" >> $movim_nginx_site
504
-    echo "    server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
505
-    echo '' >> $movim_nginx_site
502
+    { echo 'server {';
503
+      echo "    listen 127.0.0.1:$MOVIM_ONION_PORT default_server;";
504
+      echo "    server_name $MOVIM_DOMAIN_NAME;";
505
+      echo ''; } >> "$movim_nginx_site"
506 506
     function_check nginx_compress
507
-    nginx_compress $MOVIM_DOMAIN_NAME
508
-    echo '' >> $movim_nginx_site
507
+    nginx_compress "$MOVIM_DOMAIN_NAME"
508
+    echo '' >> "$movim_nginx_site"
509 509
     function_check nginx_disable_sniffing
510
-    nginx_disable_sniffing $MOVIM_DOMAIN_NAME
511
-    echo '' >> $movim_nginx_site
512
-    echo '  # Logs' >> $movim_nginx_site
513
-    echo '  access_log /dev/null;' >> $movim_nginx_site
514
-    echo '  error_log /dev/null;' >> $movim_nginx_site
515
-    echo '' >> $movim_nginx_site
516
-    echo '  # Root' >> $movim_nginx_site
517
-    echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
518
-    echo '' >> $movim_nginx_site
519
-    echo '  # Index' >> $movim_nginx_site
520
-    echo '  index index.php;' >> $movim_nginx_site
521
-    echo '' >> $movim_nginx_site
522
-    echo '  # PHP' >> $movim_nginx_site
523
-    echo '  location ~ \.php {' >> $movim_nginx_site
524
-    echo '    include snippets/fastcgi-php.conf;' >> $movim_nginx_site
525
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $movim_nginx_site
526
-    echo '    fastcgi_read_timeout 30;' >> $movim_nginx_site
527
-    echo '  }' >> $movim_nginx_site
528
-    echo '' >> $movim_nginx_site
529
-    echo '  # Location' >> $movim_nginx_site
530
-    echo '  location / {' >> $movim_nginx_site
510
+    nginx_disable_sniffing "$MOVIM_DOMAIN_NAME"
511
+    { echo '';
512
+      echo '  # Logs';
513
+      echo '  access_log /dev/null;';
514
+      echo '  error_log /dev/null;';
515
+      echo '';
516
+      echo '  # Root';
517
+      echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;";
518
+      echo '';
519
+      echo '  # Index';
520
+      echo '  index index.php;';
521
+      echo '';
522
+      echo '  # PHP';
523
+      echo '  location ~ \.php {';
524
+      echo '    include snippets/fastcgi-php.conf;';
525
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
526
+      echo '    fastcgi_read_timeout 30;';
527
+      echo '  }';
528
+      echo '';
529
+      echo '  # Location';
530
+      echo '  location / {'; } >> "$movim_nginx_site"
531 531
     function_check nginx_limits
532
-    nginx_limits $MOVIM_DOMAIN_NAME '15m'
533
-    echo '    try_files $uri $uri/ @movim;' >> $movim_nginx_site
534
-    echo '  }' >> $movim_nginx_site
535
-    echo '' >> $movim_nginx_site
536
-    echo '  location /ws/ {' >> $movim_nginx_site
537
-    echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
538
-    echo '    proxy_http_version 1.1;' >> $movim_nginx_site
539
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
540
-    echo '    proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
541
-    echo '    proxy_set_header Host $host;' >> $movim_nginx_site
542
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
543
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
544
-    echo '    proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
545
-    echo '    proxy_redirect off;' >> $movim_nginx_site
546
-    echo '  }' >> $movim_nginx_site
547
-    echo '' >> $movim_nginx_site
548
-    echo '  # Fancy URLs' >> $movim_nginx_site
549
-    echo '  location @movim {' >> $movim_nginx_site
550
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
551
-    echo '  }' >> $movim_nginx_site
552
-    echo '' >> $movim_nginx_site
553
-    echo '  # Restrict access that is unnecessary anyway' >> $movim_nginx_site
554
-    echo '  location ~ /\.(ht|git) {' >> $movim_nginx_site
555
-    echo '    deny all;' >> $movim_nginx_site
556
-    echo '  }' >> $movim_nginx_site
557
-    echo '' >> $movim_nginx_site
558
-    echo '}' >> $movim_nginx_site
532
+    nginx_limits "$MOVIM_DOMAIN_NAME" '15m'
533
+    { echo "    try_files \$uri \$uri/ @movim;";
534
+      echo '  }';
535
+      echo '';
536
+      echo '  location /ws/ {';
537
+      echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;";
538
+      echo '    proxy_http_version 1.1;';
539
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
540
+      echo '    proxy_set_header Connection "Upgrade";';
541
+      echo "    proxy_set_header Host \$host;";
542
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
543
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
544
+      echo '    proxy_set_header X-Forwarded-Proto https;';
545
+      echo '    proxy_redirect off;';
546
+      echo '  }';
547
+      echo '';
548
+      echo '  # Fancy URLs';
549
+      echo '  location @movim {';
550
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
551
+      echo '  }';
552
+      echo '';
553
+      echo '  # Restrict access that is unnecessary anyway';
554
+      echo '  location ~ /\.(ht|git) {';
555
+      echo '    deny all;';
556
+      echo '  }';
557
+      echo '';
558
+      echo '}'; } >> "$movim_nginx_site"
559 559
 
560 560
     function_check configure_php
561 561
     configure_php
562 562
 
563 563
     function_check create_site_certificate
564
-    create_site_certificate $MOVIM_DOMAIN_NAME 'yes'
564
+    create_site_certificate "$MOVIM_DOMAIN_NAME" 'yes'
565 565
 
566 566
     # Ensure that the database gets backed up locally, if remote
567 567
     # backups are not being used
@@ -572,9 +572,9 @@ function install_movim {
572 572
     backup_database_local movim
573 573
 
574 574
     function_check nginx_ensite
575
-    nginx_ensite $MOVIM_DOMAIN_NAME
575
+    nginx_ensite "$MOVIM_DOMAIN_NAME"
576 576
 
577
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a movim -p "$MOVIM_ADMIN_PASSWORD"
577
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a movim -p "$MOVIM_ADMIN_PASSWORD"
578 578
 
579 579
     set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
580 580
 

+ 39
- 38
src/freedombone-app-mumble Просмотреть файл

@@ -86,7 +86,7 @@ function upgrade_mumble {
86 86
         usermod -a -G ssl-cert mumble-server
87 87
     fi
88 88
 
89
-    if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
89
+    if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
90 90
         if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
91 91
             sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
92 92
             sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
@@ -117,17 +117,18 @@ function backup_local_mumble {
117 117
 }
118 118
 
119 119
 function restore_local_mumble {
120
-    if [ -d $USB_MOUNT/backup/mumble ]; then
120
+    if [ -d "$USB_MOUNT/backup/mumble" ]; then
121 121
         echo $"Restoring mumble settings"
122 122
         temp_restore_dir=/root/tempmumble
123 123
         function_check restore_directory_from_usb
124 124
         restore_directory_from_usb $temp_restore_dir voip
125 125
         restore_directory_from_usb $temp_restore_dir mumble
126
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
127
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
126
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
127
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini" /etc/
128 128
         else
129 129
             cp -f $temp_restore_dir/mumble-server.ini /etc/
130 130
         fi
131
+        # shellcheck disable=SC2181
131 132
         if [ ! "$?" = "0" ]; then
132 133
             rm -rf $temp_restore_dir
133 134
             function_check set_user_permissions
@@ -136,11 +137,12 @@ function restore_local_mumble {
136 137
             backup_unmount_drive
137 138
             exit 3679
138 139
         fi
139
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
140
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
140
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
141
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite" /var/lib/mumble-server/
141 142
         else
142 143
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
143 144
         fi
145
+        # shellcheck disable=SC2181
144 146
         if [ ! "$?" = "0" ]; then
145 147
             rm -rf $temp_restore_dir
146 148
             function_check set_user_permissions
@@ -171,29 +173,27 @@ function backup_remote_mumble {
171 173
 }
172 174
 
173 175
 function restore_remote_mumble {
174
-    if [ -d $SERVER_DIRECTORY/backup/mumble ]; then
176
+    if [ -d "$SERVER_DIRECTORY/backup/mumble" ]; then
175 177
         echo $"Restoring Mumble settings"
176 178
         temp_restore_dir=/root/tempmumble
177 179
         function_check restore_directory_from_friend
178 180
         restore_directory_from_friend $temp_restore_dir mumble
179
-        if [ -d $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
180
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
181
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
182
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini" /etc/
181 183
         else
182 184
             cp -f $temp_restore_dir/mumble-server.ini /etc/
183 185
         fi
186
+        # shellcheck disable=SC2181
184 187
         if [ ! "$?" = "0" ]; then
185 188
             rm -rf $temp_restore_dir
186 189
             exit 7823
187 190
         fi
188
-        if [ ! "$?" = "0" ]; then
189
-            rm -rf $temp_restore_dir
190
-            exit 7823
191
-        fi
192
-        if [ $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup ]; then
193
-            cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
191
+        if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
192
+            cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite" /var/lib/mumble-server/
194 193
         else
195 194
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
196 195
         fi
196
+        # shellcheck disable=SC2181
197 197
         if [ ! "$?" = "0" ]; then
198 198
             rm -rf $temp_restore_dir
199 199
             exit 276
@@ -221,51 +221,51 @@ function remove_mumble {
221 221
     fi
222 222
     function_check remove_onion_service
223 223
     remove_onion_service mumble ${MUMBLE_PORT}
224
-    sed -i '/mumble/d' $COMPLETION_FILE
224
+    sed -i '/mumble/d' "$COMPLETION_FILE"
225 225
 }
226 226
 
227 227
 function configure_firewall_for_mumble {
228
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
228
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
229 229
         return
230 230
     fi
231 231
     if [[ $ONION_ONLY != "no" ]]; then
232 232
         return
233 233
     fi
234 234
     firewall_add Mumble ${MUMBLE_PORT}
235
-    mark_completed $FUNCNAME
235
+    mark_completed "${FUNCNAME[0]}"
236 236
 }
237 237
 
238 238
 function install_mumble {
239 239
     apt-get -yq install mumble-server
240 240
 
241
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
242
-        MUMBLE_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
241
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
242
+        MUMBLE_SERVER_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
243 243
     else
244
-        if [ ! $MUMBLE_SERVER_PASSWORD ]; then
245
-            MUMBLE_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
246
-            if [ ${#MUMBLE_SERVER_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
247
-                MUMBLE_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
244
+        if [ ! "$MUMBLE_SERVER_PASSWORD" ]; then
245
+            MUMBLE_SERVER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
246
+            if [ ${#MUMBLE_SERVER_PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
247
+                MUMBLE_SERVER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
248 248
             fi
249 249
         fi
250 250
     fi
251 251
 
252 252
     if [[ ${ONION_ONLY} == 'no' ]]; then
253
-        if [ ! -d /var/www/${DEFAULT_DOMAIN_NAME}/htdocs ]; then
254
-            mkdir /var/www/${DEFAULT_DOMAIN_NAME}/htdocs
253
+        if [ ! -d "/var/www/${DEFAULT_DOMAIN_NAME}/htdocs" ]; then
254
+            mkdir "/var/www/${DEFAULT_DOMAIN_NAME}/htdocs"
255 255
         fi
256
-        if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
257
-            if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt ]; then
258
-                rm /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt
256
+        if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
257
+            if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
258
+                rm "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt"
259 259
             fi
260
-            if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam ]; then
261
-                rm /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam
260
+            if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam" ]; then
261
+                rm "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam"
262 262
             fi
263 263
             echo $'Obtaining certificate for the main domain'
264 264
             function_check create_site_certificate
265
-            create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
266
-            chmod 755 /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam
265
+            create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
266
+            chmod 755 "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam"
267 267
 
268
-            if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt ]; then
268
+            if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
269 269
                 echo $'Incorrect certificate generated'
270 270
                 exit 78352
271 271
             fi
@@ -276,9 +276,9 @@ function install_mumble {
276 276
 
277 277
 
278 278
     # Make an ssl cert for the server
279
-    if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
279
+    if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
280 280
         if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
281
-            ${PROJECT_NAME}-addcert -h mumble --dhkey $DH_KEYLENGTH
281
+            "${PROJECT_NAME}-addcert" -h mumble --dhkey "$DH_KEYLENGTH"
282 282
             function_check check_certificates
283 283
             check_certificates mumble
284 284
         fi
@@ -318,7 +318,7 @@ function install_mumble {
318 318
         echo 'allowping=False' >> /etc/mumble-server.ini
319 319
     fi
320 320
     sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
321
-    if [ ! -f /etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem ]; then
321
+    if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
322 322
         sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
323 323
         sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
324 324
     else
@@ -335,7 +335,8 @@ function install_mumble {
335 335
     sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
336 336
     sed -i "s|port=.*|port=${MUMBLE_PORT}|g" /etc/mumble-server.ini
337 337
 
338
-    MUMBLE_ONION_HOSTNAME=$(add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT})
338
+    #MUMBLE_ONION_HOSTNAME=$(add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT})
339
+    add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT}
339 340
 
340 341
     # turn off logs by default
341 342
     sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini

+ 229
- 242
src/freedombone-app-nextcloud Просмотреть файл

@@ -60,14 +60,14 @@ function logging_off_nextcloud {
60 60
 function remove_user_nextcloud {
61 61
     remove_username="$1"
62 62
 
63
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp nextcloud
63
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp nextcloud
64 64
 }
65 65
 
66 66
 function add_user_nextcloud {
67 67
     new_username="$1"
68 68
     new_user_password="$2"
69 69
 
70
-    ${PROJECT_NAME}-pass -u $new_username -a nextcloud -p "$new_user_password"
70
+    "${PROJECT_NAME}-pass" -u "$new_username" -a nextcloud -p "$new_user_password"
71 71
     echo '0'
72 72
 }
73 73
 
@@ -76,12 +76,12 @@ function change_password_nextcloud {
76 76
 
77 77
     export OC_PASS="$2"
78 78
     su -s /bin/sh www-data -c "php occ user:resetpassword --password-from-env $curr_username"
79
-    ${PROJECT_NAME}-pass -u $curr_username -a nextcloud -p "$OC_PASS"
79
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a nextcloud -p "$OC_PASS"
80 80
     export OC_PASS=""
81 81
 }
82 82
 
83 83
 function install_interactive_nextcloud {
84
-    if [ ! $ONION_ONLY ]; then
84
+    if [ ! "$ONION_ONLY" ]; then
85 85
         ONION_ONLY='no'
86 86
     fi
87 87
 
@@ -91,42 +91,40 @@ function install_interactive_nextcloud {
91 91
         NEXTCLOUD_DETAILS_COMPLETE=
92 92
         while [ ! $NEXTCLOUD_DETAILS_COMPLETE ]
93 93
         do
94
-            data=$(tempfile 2>/dev/null)
95
-            trap "rm -f $data" 0 1 2 5 15
94
+            data=$(mktemp 2>/dev/null)
96 95
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
97 96
                 dialog --backtitle $"Freedombone Configuration" \
98 97
                        --title $"NextCloud Configuration" \
99
-                       --form $"\nPlease enter your NextCloud details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
98
+                       --form $"\\nPlease enter your NextCloud details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
100 99
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
101 100
                        $"Code:" 2 1 "$(grep 'NEXTCLOUD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
102
-                       2> $data
101
+                       2> "$data"
103 102
             else
104 103
                 dialog --backtitle $"Freedombone Configuration" \
105 104
                        --title $"NextCloud Configuration" \
106
-                       --form $"\nPlease enter your NextCloud details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 2 \
105
+                       --form $"\\nPlease enter your NextCloud details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 2 \
107 106
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
108
-                       2> $data
107
+                       2> "$data"
109 108
             fi
110 109
             sel=$?
111 110
             case $sel in
112
-                1) exit 1;;
113
-                255) exit 1;;
111
+                1) rm -f "$data"
112
+                   exit 1;;
113
+                255) rm -f "$data"
114
+                     exit 1;;
114 115
             esac
115
-            NEXTCLOUD_DOMAIN_NAME=$(cat $data | sed -n 1p)
116
-            if [ ${#img_url} -gt 1 ]; then
117
-                NEXTCLOUD_BACKGROUND_IMAGE_URL=$img_url
118
-            fi
119
-            if [ $NEXTCLOUD_DOMAIN_NAME ]; then
116
+            NEXTCLOUD_DOMAIN_NAME=$(sed -n 1p < "$data")
117
+            if [ "$NEXTCLOUD_DOMAIN_NAME" ]; then
120 118
                 TEST_DOMAIN_NAME=$NEXTCLOUD_DOMAIN_NAME
121 119
                 validate_domain_name
122
-                if [[ $TEST_DOMAIN_NAME != $NEXTCLOUD_DOMAIN_NAME ]]; then
120
+                if [[ "$TEST_DOMAIN_NAME" != "$NEXTCLOUD_DOMAIN_NAME" ]]; then
123 121
                     NEXTCLOUD_DOMAIN_NAME=
124 122
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
125 123
                 else
126 124
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
127
-                        NEXTCLOUD_CODE=$(cat $data | sed -n 2p)
125
+                        NEXTCLOUD_CODE=$(sed -n 2p < "$data")
128 126
                         validate_freedns_code "$NEXTCLOUD_CODE"
129
-                        if [ ! $VALID_CODE ]; then
127
+                        if [ ! "$VALID_CODE" ]; then
130 128
                             NEXTCLOUD_DOMAIN_NAME=
131 129
                         fi
132 130
                     fi
@@ -135,11 +133,12 @@ function install_interactive_nextcloud {
135 133
             if [ $NEXTCLOUD_DOMAIN_NAME ]; then
136 134
                 NEXTCLOUD_DETAILS_COMPLETE="yes"
137 135
             fi
136
+            rm -f "$data"
138 137
         done
139 138
 
140 139
         # remove any invalid characters
141 140
         if [ ${#NEXTCLOUD_TITLE} -gt 0 ]; then
142
-            new_title=$(echo "$NEXTCLOUD_TITLE" | sed "s|'||g")
141
+            new_title=${"$NEXTCLOUD_TITLE"//\'//}
143 142
             NEXTCLOUD_TITLE="$new_title"
144 143
         fi
145 144
 
@@ -156,23 +155,23 @@ function change_password_nextcloud {
156 155
 
157 156
     read_config_param ${NEXTCLOUD_DOMAIN_NAME}
158 157
 
159
-    ${PROJECT_NAME}-pass -u "$curr_username" -a nextcloud -p "$new_user_password"
158
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a nextcloud -p "$new_user_password"
160 159
 }
161 160
 
162 161
 function nextcloud_create_database {
163
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
164
-        NEXTCLOUD_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
162
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
163
+        NEXTCLOUD_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
165 164
     else
166
-        if [ ! $NEXTCLOUD_ADMIN_PASSWORD ]; then
167
-            NEXTCLOUD_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
165
+        if [ ! "$NEXTCLOUD_ADMIN_PASSWORD" ]; then
166
+            NEXTCLOUD_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
168 167
         fi
169 168
     fi
170
-    if [ ! $NEXTCLOUD_ADMIN_PASSWORD ]; then
169
+    if [ ! "$NEXTCLOUD_ADMIN_PASSWORD" ]; then
171 170
         return
172 171
     fi
173 172
 
174 173
     function_check create_database
175
-    create_database nextcloud "$NEXTCLOUD_ADMIN_PASSWORD" $MY_USERNAME
174
+    create_database nextcloud "$NEXTCLOUD_ADMIN_PASSWORD" "$MY_USERNAME"
176 175
 }
177 176
 
178 177
 function reconfigure_nextcloud {
@@ -186,7 +185,7 @@ function configure_interactive_nextcloud {
186 185
 function upgrade_nextcloud_base {
187 186
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
188 187
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/data
189
-    cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
188
+    cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 232547985
190 189
     sudo -u www-data ./occ maintenance:repair
191 190
     sudo -u www-data ./occ files:cleanup
192 191
     sudo -u www-data ./occ files:scan --all
@@ -200,13 +199,13 @@ function upgrade_nextcloud {
200 199
         return
201 200
     fi
202 201
 
203
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
202
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
204 203
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
205 204
     fi
206 205
 
207 206
     # update to the next commit
208 207
     function_check set_repo_commit
209
-    set_repo_commit /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs "nextcloud commit" "$NEXTCLOUD_COMMIT" $NEXTCLOUD_REPO
208
+    set_repo_commit "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" "nextcloud commit" "$NEXTCLOUD_COMMIT" "$NEXTCLOUD_REPO"
210 209
 
211 210
     upgrade_nextcloud_base
212 211
     sudo -u www-data ./occ upgrade
@@ -215,22 +214,22 @@ function upgrade_nextcloud {
215 214
 
216 215
 function backup_local_nextcloud {
217 216
     NEXTCLOUD_DOMAIN_NAME='nextcloud'
218
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
217
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
219 218
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
220 219
     fi
221 220
 
222 221
     source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
223
-    if [ -d $source_directory ]; then
222
+    if [ -d "$source_directory" ]; then
224 223
         function_check suspend_site
225
-        suspend_site ${NEXTCLOUD_DOMAIN_NAME}
224
+        suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
226 225
 
227 226
         dest_directory=nextcloudfiles
228 227
         function_check backup_directory_to_usb
229
-        backup_directory_to_usb $source_directory $dest_directory
228
+        backup_directory_to_usb "$source_directory" "$dest_directory"
230 229
 
231 230
         source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
232 231
         dest_directory=nextcloudconfig
233
-        backup_directory_to_usb $source_directory $dest_directory
232
+        backup_directory_to_usb "$source_directory" "$dest_directory"
234 233
 
235 234
         function_check backup_database_to_usb
236 235
         backup_database_to_usb nextcloud
@@ -241,26 +240,26 @@ function backup_local_nextcloud {
241 240
 }
242 241
 
243 242
 function restore_local_nextcloud {
244
-    if ! grep -q "nextcloud domain" $COMPLETION_FILE; then
243
+    if ! grep -q "nextcloud domain" "$COMPLETION_FILE"; then
245 244
         return
246 245
     fi
247 246
     NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
248
-    if [ $NEXTCLOUD_DOMAIN_NAME ]; then
247
+    if [ "$NEXTCLOUD_DOMAIN_NAME" ]; then
249 248
 
250 249
         temp_restore_dir=/root/tempnextcloud
251 250
         function_check nextcloud_create_database
252 251
         nextcloud_create_database
253
-        restore_database nextcloud ${NEXTCLOUD_DOMAIN_NAME}
252
+        restore_database nextcloud "${NEXTCLOUD_DOMAIN_NAME}"
254 253
 
255 254
         temp_restore_dir=/root/tempnextcloudfiles
256 255
         restore_directory_from_usb $temp_restore_dir nextcloudfiles
257 256
 
258
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data ]; then
259
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data /var/www/${NEXTCLOUD_DOMAIN_NAME}/
257
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" ]; then
258
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
260 259
         else
261
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/
260
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
262 261
         fi
263
-
262
+        # shellcheck disable=SC2181
264 263
         if [ ! "$?" = "0" ]; then
265 264
             set_user_permissions
266 265
             backup_unmount_drive
@@ -271,12 +270,13 @@ function restore_local_nextcloud {
271 270
         temp_restore_dir=/root/tempnextcloudconfig
272 271
         restore_directory_from_usb $temp_restore_dir nextcloudconfig
273 272
 
274
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config ]; then
275
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
273
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" ]; then
274
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
276 275
         else
277
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/
276
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/"
278 277
         fi
279 278
 
279
+        # shellcheck disable=SC2181
280 280
         if [ ! "$?" = "0" ]; then
281 281
             set_user_permissions
282 282
             backup_unmount_drive
@@ -284,9 +284,9 @@ function restore_local_nextcloud {
284 284
         fi
285 285
         rm -rf ${temp_restore_dir}
286 286
 
287
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
288
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/data
289
-        cd $nextcloud_dir
287
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
288
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/data"
289
+        cd "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs" || exit 14893545875
290 290
         sudo -u www-data ./occ maintenance:repair
291 291
         sudo -u www-data ./occ files:cleanup
292 292
         sudo -u www-data ./occ files:scan --all
@@ -294,21 +294,21 @@ function restore_local_nextcloud {
294 294
 }
295 295
 
296 296
 function backup_remote_nextcloud {
297
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
297
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
298 298
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
299 299
         temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
300
-        if [ -d $temp_backup_dir ]; then
300
+        if [ -d "$temp_backup_dir" ]; then
301 301
             function_check suspend_site
302
-            suspend_site ${NEXTCLOUD_DOMAIN_NAME}
302
+            suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
303 303
 
304 304
             function_check backup_database_to_friend
305 305
             backup_database_to_friend nextcloud
306 306
 
307 307
             function_check backup_directory_to_friend
308
-            backup_directory_to_friend $temp_backup_dir nextclouddata
308
+            backup_directory_to_friend "$temp_backup_dir" nextclouddata
309 309
 
310 310
             temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
311
-            backup_directory_to_friend $temp_backup_dir nextcloudconfig
311
+            backup_directory_to_friend "$temp_backup_dir" nextcloudconfig
312 312
 
313 313
             function_check restart_site
314 314
             restart_site
@@ -319,7 +319,7 @@ function backup_remote_nextcloud {
319 319
 }
320 320
 
321 321
 function restore_remote_nextcloud {
322
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
322
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
323 323
         echo $"Restoring nextcloud"
324 324
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
325 325
 
@@ -327,7 +327,7 @@ function restore_remote_nextcloud {
327 327
         nextcloud_create_database
328 328
 
329 329
         function_check restore_database_from_friend
330
-        restore_database_from_friend nextcloud ${NEXTCLOUD_DOMAIN_NAME}
330
+        restore_database_from_friend nextcloud "${NEXTCLOUD_DOMAIN_NAME}"
331 331
         if [ -d /root/tempnextcloud ]; then
332 332
             rm -rf /root/tempnextcloud
333 333
         fi
@@ -335,12 +335,12 @@ function restore_remote_nextcloud {
335 335
         temp_restore_dir=/root/tempnextcloudfiles
336 336
         restore_directory_from_friend $temp_restore_dir nextcloudfiles
337 337
 
338
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data ]; then
339
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data /var/www/${NEXTCLOUD_DOMAIN_NAME}/
338
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" ]; then
339
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/data" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
340 340
         else
341
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/
341
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
342 342
         fi
343
-
343
+        # shellcheck disable=SC2181
344 344
         if [ ! "$?" = "0" ]; then
345 345
             exit 768254
346 346
         fi
@@ -349,20 +349,21 @@ function restore_remote_nextcloud {
349 349
         temp_restore_dir=/root/tempnextcloudconfig
350 350
         restore_directory_from_friend $temp_restore_dir nextcloudconfig
351 351
 
352
-        if [ -d $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config ]; then
353
-            cp -r $temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
352
+        if [ -d "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" ]; then
353
+            cp -r "$temp_restore_dir/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
354 354
         else
355
-            cp -r $temp_restore_dir/* /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/
355
+            cp -r $temp_restore_dir/* "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/"
356 356
         fi
357 357
 
358
+        # shellcheck disable=SC2181
358 359
         if [ ! "$?" = "0" ]; then
359 360
             exit 573427
360 361
         fi
361 362
         rm -rf ${temp_restore_dir}
362 363
 
363
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
364
-        chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/data
365
-        cd /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
364
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
365
+        chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/data"
366
+        cd "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs" || exit 2642846824
366 367
         sudo -u www-data ./occ maintenance:repair
367 368
         sudo -u www-data ./occ files:cleanup
368 369
         sudo -u www-data ./occ files:scan --all
@@ -381,13 +382,13 @@ function remove_nextcloud {
381 382
     read_config_param "NEXTCLOUD_DOMAIN_NAME"
382 383
     read_config_param "MY_USERNAME"
383 384
     echo "Removing $NEXTCLOUD_DOMAIN_NAME"
384
-    nginx_dissite $NEXTCLOUD_DOMAIN_NAME
385
-    remove_certs $NEXTCLOUD_DOMAIN_NAME
386
-    if [ -d /var/www/$NEXTCLOUD_DOMAIN_NAME ]; then
387
-        rm -rf /var/www/$NEXTCLOUD_DOMAIN_NAME
385
+    nginx_dissite "$NEXTCLOUD_DOMAIN_NAME"
386
+    remove_certs "$NEXTCLOUD_DOMAIN_NAME"
387
+    if [ -d "/var/www/$NEXTCLOUD_DOMAIN_NAME" ]; then
388
+        rm -rf "/var/www/$NEXTCLOUD_DOMAIN_NAME"
388 389
     fi
389
-    if [ -f /etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME ]; then
390
-        rm /etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
390
+    if [ -f "/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME" ]; then
391
+        rm "/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME"
391 392
     fi
392 393
     function_check drop_database
393 394
     drop_database nextcloud
@@ -395,17 +396,17 @@ function remove_nextcloud {
395 396
     remove_onion_service nextcloud ${NEXTCLOUD_ONION_PORT}
396 397
     remove_app nextcloud
397 398
     remove_completion_param install_nextcloud
398
-    sed -i '/nextcloud/d' $COMPLETION_FILE
399
+    sed -i '/nextcloud/d' "$COMPLETION_FILE"
399 400
     remove_backup_database_local nextcloud
400 401
 
401 402
     function_check remove_ddns_domain
402
-    remove_ddns_domain $NEXTCLOUD_DOMAIN_NAME
403
+    remove_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
403 404
     systemctl restart nginx
404 405
     systemctl restart php7.0-fpm
405 406
 }
406 407
 
407 408
 function install_nextcloud_main {
408
-    if [ ! $NEXTCLOUD_DOMAIN_NAME ]; then
409
+    if [ ! "$NEXTCLOUD_DOMAIN_NAME" ]; then
409 410
         echo $'No domain name was given for nextcloud'
410 411
         exit 7359
411 412
     fi
@@ -434,34 +435,34 @@ function install_nextcloud_main {
434 435
     fi
435 436
     sed -i 's|;env[PATH]|env[PATH]|g' /etc/php/7.0/fpm/pool.d/www.conf
436 437
 
437
-    if [ ! -d /var/www/$NEXTCLOUD_DOMAIN_NAME ]; then
438
-        mkdir /var/www/$NEXTCLOUD_DOMAIN_NAME
438
+    if [ ! -d "/var/www/$NEXTCLOUD_DOMAIN_NAME" ]; then
439
+        mkdir "/var/www/$NEXTCLOUD_DOMAIN_NAME"
439 440
     fi
440
-    if [ ! -d /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs ]; then
441
+    if [ ! -d "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" ]; then
441 442
 
442 443
         if [ -d /repos/nextcloud ]; then
443
-            mkdir /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
444
-            cp -r -p /repos/nextcloud/. /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
445
-            cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
444
+            mkdir "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
445
+            cp -r -p /repos/nextcloud/. "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
446
+            cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 2783539793
446 447
             git pull
447 448
         else
448 449
             function_check git_clone
449
-            git_clone $NEXTCLOUD_REPO /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
450
+            git_clone "$NEXTCLOUD_REPO" "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
450 451
         fi
451 452
 
452
-        if [ ! -d /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs ]; then
453
+        if [ ! -d "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" ]; then
453 454
             echo $'Unable to clone nextcloud repo'
454 455
             exit 87525
455 456
         fi
456 457
     fi
457 458
 
458
-    cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
459
+    cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 3468346834
459 460
     git submodule update --init
460 461
     git checkout $NEXTCLOUD_COMMIT -b $NEXTCLOUD_COMMIT
461 462
     set_completion_param "nextcloud commit" "$NEXTCLOUD_COMMIT"
462 463
 
463
-    chmod g+w /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
464
-    chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
464
+    chmod g+w "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
465
+    chown -R www-data:www-data "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs"
465 466
 
466 467
     function_check nextcloud_create_database
467 468
     nextcloud_create_database
@@ -474,154 +475,154 @@ function install_nextcloud_main {
474 475
     fi
475 476
 
476 477
     function_check add_ddns_domain
477
-    add_ddns_domain $NEXTCLOUD_DOMAIN_NAME
478
+    add_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
478 479
 
479 480
     nextcloud_nginx_site=/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
480 481
     if [[ $ONION_ONLY == "no" ]]; then
481 482
         function_check nginx_http_redirect
482
-        nginx_http_redirect $NEXTCLOUD_DOMAIN_NAME
483
-        echo 'server {' >> $nextcloud_nginx_site
484
-        echo '  listen 443 ssl;' >> $nextcloud_nginx_site
485
-        echo '  #listen [::]:443 ssl;' >> $nextcloud_nginx_site
486
-        echo "  server_name $NEXTCLOUD_DOMAIN_NAME;" >> $nextcloud_nginx_site
487
-        echo '' >> $nextcloud_nginx_site
488
-        echo '  # Security' >> $nextcloud_nginx_site
483
+        nginx_http_redirect "$NEXTCLOUD_DOMAIN_NAME"
484
+        { echo 'server {';
485
+          echo '  listen 443 ssl;';
486
+          echo '  #listen [::]:443 ssl;';
487
+          echo "  server_name $NEXTCLOUD_DOMAIN_NAME;";
488
+          echo '';
489
+          echo '  # Security'; } >> "$nextcloud_nginx_site"
489 490
         function_check nginx_ssl
490
-        nginx_ssl $NEXTCLOUD_DOMAIN_NAME mobile
491
+        nginx_ssl "$NEXTCLOUD_DOMAIN_NAME" mobile
491 492
 
492 493
         function_check nginx_disable_sniffing
493
-        nginx_disable_sniffing $NEXTCLOUD_DOMAIN_NAME
494
-
495
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $nextcloud_nginx_site
496
-        echo '' >> $nextcloud_nginx_site
497
-        echo '  # Logs' >> $nextcloud_nginx_site
498
-        echo '  access_log /dev/null;' >> $nextcloud_nginx_site
499
-        echo '  error_log /dev/null;' >> $nextcloud_nginx_site
500
-        echo '' >> $nextcloud_nginx_site
501
-        echo '  # Root' >> $nextcloud_nginx_site
502
-        echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;" >> $nextcloud_nginx_site
503
-        echo '' >> $nextcloud_nginx_site
504
-        echo '  # Index' >> $nextcloud_nginx_site
505
-        echo '  index index.php;' >> $nextcloud_nginx_site
506
-        echo '' >> $nextcloud_nginx_site
507
-
508
-        # By default nextcloud advertises highly specific version information
509
-        # on status.php, which can obviously be used by adversaries.
510
-        # Blocking status.php prevents this information leak
511
-        echo '  location = /status.php {' >> $nextcloud_nginx_site
512
-        echo '    return 404;' >> $nextcloud_nginx_site
513
-        echo '  }' >> $nextcloud_nginx_site
514
-        echo '' >> $nextcloud_nginx_site
515
-
516
-        echo '  # PHP' >> $nextcloud_nginx_site
517
-        echo '  location ~ \.php {' >> $nextcloud_nginx_site
518
-        echo '    include snippets/fastcgi-php.conf;' >> $nextcloud_nginx_site
519
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $nextcloud_nginx_site
520
-        echo '    fastcgi_read_timeout 30;' >> $nextcloud_nginx_site
521
-        echo '  }' >> $nextcloud_nginx_site
522
-        echo '' >> $nextcloud_nginx_site
523
-        echo '  # Location' >> $nextcloud_nginx_site
524
-        echo '  location / {' >> $nextcloud_nginx_site
494
+        nginx_disable_sniffing "$NEXTCLOUD_DOMAIN_NAME"
495
+
496
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
497
+          echo '';
498
+          echo '  # Logs';
499
+          echo '  access_log /dev/null;';
500
+          echo '  error_log /dev/null;';
501
+          echo '';
502
+          echo '  # Root';
503
+          echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;";
504
+          echo '';
505
+          echo '  # Index';
506
+          echo '  index index.php;';
507
+          echo '';
508
+
509
+          # By default nextcloud advertises highly specific version information
510
+          # on status.php, which can obviously be used by adversaries.
511
+          # Blocking status.php prevents this information leak
512
+          echo '  location = /status.php {';
513
+          echo '    return 404;';
514
+          echo '  }';
515
+          echo '';
516
+
517
+          echo '  # PHP';
518
+          echo '  location ~ \.php {';
519
+          echo '    include snippets/fastcgi-php.conf;';
520
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
521
+          echo '    fastcgi_read_timeout 30;';
522
+          echo '  }';
523
+          echo '';
524
+          echo '  # Location';
525
+          echo '  location / {'; } >> "$nextcloud_nginx_site"
525 526
         function_check nginx_limits
526
-        nginx_limits $NEXTCLOUD_DOMAIN_NAME '15m'
527
-        echo '    try_files $uri $uri/ @nextcloud;' >> $nextcloud_nginx_site
528
-        echo '  }' >> $nextcloud_nginx_site
529
-        echo '' >> $nextcloud_nginx_site
530
-        echo '  # Fancy URLs' >> $nextcloud_nginx_site
531
-        echo '  location @nextcloud {' >> $nextcloud_nginx_site
532
-        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $nextcloud_nginx_site
533
-        echo '  }' >> $nextcloud_nginx_site
534
-        echo '' >> $nextcloud_nginx_site
535
-        echo '  # Restrict access that is unnecessary anyway' >> $nextcloud_nginx_site
536
-        echo '  location ~ /\.(ht|git) {' >> $nextcloud_nginx_site
537
-        echo '    deny all;' >> $nextcloud_nginx_site
538
-        echo '  }' >> $nextcloud_nginx_site
539
-        echo '' >> $nextcloud_nginx_site
540
-        echo '  location = /.well-known/carddav {' >> $nextcloud_nginx_site
541
-        echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
542
-        echo '  }' >> $nextcloud_nginx_site
543
-        echo '  location = /.well-known/caldav {' >> $nextcloud_nginx_site
544
-        echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
545
-        echo '  }' >> $nextcloud_nginx_site
546
-        echo '' >> $nextcloud_nginx_site
547
-        echo '  location /.well-known/acme-challenge { }' >> $nextcloud_nginx_site
548
-        echo '}' >> $nextcloud_nginx_site
527
+        nginx_limits "$NEXTCLOUD_DOMAIN_NAME" '15m'
528
+        { echo "    try_files \$uri \$uri/ @nextcloud;";
529
+          echo '  }';
530
+          echo '';
531
+          echo '  # Fancy URLs';
532
+          echo '  location @nextcloud {';
533
+          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
534
+          echo '  }';
535
+          echo '';
536
+          echo '  # Restrict access that is unnecessary anyway';
537
+          echo '  location ~ /\.(ht|git) {';
538
+          echo '    deny all;';
539
+          echo '  }';
540
+          echo '';
541
+          echo '  location = /.well-known/carddav {';
542
+          echo "    return 301 \$scheme://\$host/remote.php/dav;";
543
+          echo '  }';
544
+          echo '  location = /.well-known/caldav {';
545
+          echo "    return 301 \$scheme://\$host/remote.php/dav;";
546
+          echo '  }';
547
+          echo '';
548
+          echo '  location /.well-known/acme-challenge { }';
549
+          echo '}'; } >> "$nextcloud_nginx_site"
549 550
     else
550
-        echo -n '' > $nextcloud_nginx_site
551
+        echo -n '' > "$nextcloud_nginx_site"
551 552
     fi
552
-    echo 'server {' >> $nextcloud_nginx_site
553
-    echo "    listen 127.0.0.1:$NEXTCLOUD_ONION_PORT default_server;" >> $nextcloud_nginx_site
554
-    echo "    server_name $NEXTCLOUD_DOMAIN_NAME;" >> $nextcloud_nginx_site
555
-    echo '' >> $nextcloud_nginx_site
553
+    { echo 'server {';
554
+      echo "    listen 127.0.0.1:$NEXTCLOUD_ONION_PORT default_server;";
555
+      echo "    server_name $NEXTCLOUD_DOMAIN_NAME;";
556
+      echo ''; } >> "$nextcloud_nginx_site"
556 557
     function_check nginx_disable_sniffing
557
-    nginx_disable_sniffing $NEXTCLOUD_DOMAIN_NAME
558
-    echo '' >> $nextcloud_nginx_site
559
-    echo '  # Logs' >> $nextcloud_nginx_site
560
-    echo '  access_log /dev/null;' >> $nextcloud_nginx_site
561
-    echo '  error_log /dev/null;' >> $nextcloud_nginx_site
562
-    echo '' >> $nextcloud_nginx_site
563
-    echo '  # Root' >> $nextcloud_nginx_site
564
-    echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;" >> $nextcloud_nginx_site
565
-    echo '' >> $nextcloud_nginx_site
566
-    echo '  # Index' >> $nextcloud_nginx_site
567
-    echo '  index index.php;' >> $nextcloud_nginx_site
568
-    echo '' >> $nextcloud_nginx_site
569
-
570
-    # By default nextcloud advertises highly specific version information
571
-    # on status.php, which can obviously be used by adversaries.
572
-    # Blocking status.php prevents this information leak
573
-    echo '  location = /status.php {' >> $nextcloud_nginx_site
574
-    echo '    return 404;' >> $nextcloud_nginx_site
575
-    echo '  }' >> $nextcloud_nginx_site
576
-    echo '' >> $nextcloud_nginx_site
577
-
578
-    echo '  # PHP' >> $nextcloud_nginx_site
579
-    echo '  location ~ \.php {' >> $nextcloud_nginx_site
580
-    echo '    include snippets/fastcgi-php.conf;' >> $nextcloud_nginx_site
581
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $nextcloud_nginx_site
582
-    echo '    fastcgi_read_timeout 30;' >> $nextcloud_nginx_site
583
-    echo '  }' >> $nextcloud_nginx_site
584
-    echo '' >> $nextcloud_nginx_site
585
-    echo '  # Location' >> $nextcloud_nginx_site
586
-    echo '  location / {' >> $nextcloud_nginx_site
558
+    nginx_disable_sniffing "$NEXTCLOUD_DOMAIN_NAME"
559
+    { echo '';
560
+      echo '  # Logs';
561
+      echo '  access_log /dev/null;';
562
+      echo '  error_log /dev/null;';
563
+      echo '';
564
+      echo '  # Root';
565
+      echo "  root /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs;";
566
+      echo '';
567
+      echo '  # Index';
568
+      echo '  index index.php;';
569
+      echo '';
570
+
571
+      # By default nextcloud advertises highly specific version information
572
+      # on status.php, which can obviously be used by adversaries.
573
+      # Blocking status.php prevents this information leak
574
+      echo '  location = /status.php {';
575
+      echo '    return 404;';
576
+      echo '  }';
577
+      echo '';
578
+
579
+      echo '  # PHP';
580
+      echo '  location ~ \.php {';
581
+      echo '    include snippets/fastcgi-php.conf;';
582
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
583
+      echo '    fastcgi_read_timeout 30;';
584
+      echo '  }';
585
+      echo '';
586
+      echo '  # Location';
587
+      echo '  location / {'; } >> "$nextcloud_nginx_site"
587 588
     function_check nginx_limits
588
-    nginx_limits $NEXTCLOUD_DOMAIN_NAME '15m'
589
-    echo '    try_files $uri $uri/ @nextcloud;' >> $nextcloud_nginx_site
590
-    echo '  }' >> $nextcloud_nginx_site
591
-    echo '' >> $nextcloud_nginx_site
592
-    echo '  # Fancy URLs' >> $nextcloud_nginx_site
593
-    echo '  location @nextcloud {' >> $nextcloud_nginx_site
594
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $nextcloud_nginx_site
595
-    echo '  }' >> $nextcloud_nginx_site
596
-    echo '' >> $nextcloud_nginx_site
597
-    echo '  # Restrict access that is unnecessary anyway' >> $nextcloud_nginx_site
598
-    echo '  location ~ /\.(ht|git) {' >> $nextcloud_nginx_site
599
-    echo '    deny all;' >> $nextcloud_nginx_site
600
-    echo '  }' >> $nextcloud_nginx_site
601
-    echo '' >> $nextcloud_nginx_site
602
-    echo '  location = /.well-known/carddav {' >> $nextcloud_nginx_site
603
-    echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
604
-    echo '  }' >> $nextcloud_nginx_site
605
-    echo '  location = /.well-known/caldav {' >> $nextcloud_nginx_site
606
-    echo '    return 301 $scheme://$host/remote.php/dav;' >> $nextcloud_nginx_site
607
-    echo '  }' >> $nextcloud_nginx_site
608
-    echo '' >> $nextcloud_nginx_site
609
-    echo '  location /.well-known/acme-challenge { }' >> $nextcloud_nginx_site
610
-    echo '}' >> $nextcloud_nginx_site
611
-
612
-    sed -i 's| DENY;| SAMEORIGIN;|g' $nextcloud_nginx_site
589
+    nginx_limits "$NEXTCLOUD_DOMAIN_NAME" '15m'
590
+    { echo "    try_files \$uri \$uri/ @nextcloud;";
591
+      echo '  }';
592
+      echo '';
593
+      echo '  # Fancy URLs';
594
+      echo '  location @nextcloud {';
595
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
596
+      echo '  }';
597
+      echo '';
598
+      echo '  # Restrict access that is unnecessary anyway';
599
+      echo '  location ~ /\.(ht|git) {';
600
+      echo '    deny all;';
601
+      echo '  }';
602
+      echo '';
603
+      echo '  location = /.well-known/carddav {';
604
+      echo "    return 301 \$scheme://\$host/remote.php/dav;";
605
+      echo '  }';
606
+      echo '  location = /.well-known/caldav {';
607
+      echo "    return 301 \$scheme://\$host/remote.php/dav;";
608
+      echo '  }';
609
+      echo '';
610
+      echo '  location /.well-known/acme-challenge { }';
611
+      echo '}'; } >> "$nextcloud_nginx_site"
612
+
613
+    sed -i 's| DENY;| SAMEORIGIN;|g' "$nextcloud_nginx_site"
613 614
 
614 615
     # NextCloud doesn't like content-security-policy at all
615
-    sed -i '/Content-Security-Policy/d' $nextcloud_nginx_site
616
+    sed -i '/Content-Security-Policy/d' "$nextcloud_nginx_site"
616 617
 
617 618
     function_check configure_php
618 619
     configure_php
619 620
 
620 621
     function_check create_site_certificate
621
-    create_site_certificate $NEXTCLOUD_DOMAIN_NAME 'yes'
622
+    create_site_certificate "$NEXTCLOUD_DOMAIN_NAME" 'yes'
622 623
 
623
-    if [[ $ONION_ONLY == "no" ]]; then
624
-        if [ ! -f /etc/ssl/certs/${NEXTCLOUD_DOMAIN_NAME}.pem ]; then
624
+    if [[ "$ONION_ONLY" == "no" ]]; then
625
+        if [ ! -f "/etc/ssl/certs/${NEXTCLOUD_DOMAIN_NAME}.pem" ]; then
625 626
             echo $'Certificate not generated for nextcloud'
626 627
             exit 725762
627 628
         fi
@@ -636,31 +637,18 @@ function install_nextcloud_main {
636 637
     backup_database_local nextcloud
637 638
 
638 639
     function_check nginx_ensite
639
-    nginx_ensite $NEXTCLOUD_DOMAIN_NAME
640
-
641
-    # NOTE: For the typical case always enable SSL and only
642
-    # disable it if in onion only mode. This is due to complexities
643
-    # with the way URLs are generated by nextcloud
644
-    nextcloud_ssl='always'
645
-    if [[ $ONION_ONLY != 'no' ]]; then
646
-        nextcloud_ssl='never'
647
-    fi
640
+    nginx_ensite "$NEXTCLOUD_DOMAIN_NAME"
648 641
 
649 642
     NEXTCLOUD_ONION_HOSTNAME=$(add_onion_service nextcloud 80 ${NEXTCLOUD_ONION_PORT})
650 643
 
651
-    NEXTCLOUD_SERVER=${NEXTCLOUD_DOMAIN_NAME}
652
-    if [[ $ONION_ONLY != 'no' ]]; then
653
-        NEXTCLOUD_SERVER=${NEXTCLOUD_ONION_HOSTNAME}
654
-    fi
655
-
656 644
     systemctl restart php7.0-fpm
657 645
     systemctl restart nginx
658 646
 
659
-    ${PROJECT_NAME}-addemail -u $MY_USERNAME -e "noreply@$NEXTCLOUD_DOMAIN_NAME" -g nextcloud --public no
647
+    "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$NEXTCLOUD_DOMAIN_NAME" -g nextcloud --public no
660 648
 
661
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a nextcloud -p "$NEXTCLOUD_ADMIN_PASSWORD"
649
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a nextcloud -p "$NEXTCLOUD_ADMIN_PASSWORD"
662 650
 
663
-    cd /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
651
+    cd "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs" || exit 2467245247
664 652
     if [ -d config ]; then
665 653
         chown -R www-data:www-data config
666 654
     fi
@@ -669,7 +657,7 @@ function install_nextcloud_main {
669 657
     fi
670 658
 
671 659
     chmod +x occ
672
-    ./occ maintenance:install --database-name nextcloud --admin-user ${MY_USERNAME} --admin-pass "${NEXTCLOUD_ADMIN_PASSWORD}" --database mysql --database-user root --database-pass "${MARIADB_PASSWORD}"
660
+    ./occ maintenance:install --database-name nextcloud --admin-user "${MY_USERNAME}" --admin-pass "${NEXTCLOUD_ADMIN_PASSWORD}" --database mysql --database-user root --database-pass "${MARIADB_PASSWORD}"
673 661
     if [ ! -d data ]; then
674 662
         echo $'Nextcloud data directory was not found. This probably means that the installation failed.'
675 663
         echo ''
@@ -683,20 +671,19 @@ function install_nextcloud_main {
683 671
     sudo -u www-data ./occ status
684 672
     sudo -u www-data ./occ app:list
685 673
     sudo -u www-data ./occ app:enable encryption
686
-    sudo -u www-data ./occ encryption:enable
687
-    if [ ! "$?" = "0" ]; then
674
+    if ! sudo -u www-data ./occ encryption:enable; then
688 675
         echo $'Encryption not enabled'
689 676
         exit 73527
690 677
     fi
691 678
     sudo -u www-data ./occ encryption:status
692 679
     sudo -u www-data ./occ config:system:set appstoreenabled --value=false
693
-    chmod g+w /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php
694
-    chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs
680
+    chmod g+w "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php"
681
+    chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs"
695 682
     chmod 0644 .htaccess
696 683
     chmod 0750 data
697
-    chown -R www-data:www-data /var/www/${NEXTCLOUD_DOMAIN_NAME}/data
698
-    sudo -u www-data ./occ config:system:set trusted_domains 1 --value=$NEXTCLOUD_DOMAIN_NAME
699
-    sudo -u www-data ./occ config:system:set trusted_domains 2 --value=$NEXTCLOUD_ONION_HOSTNAME
684
+    chown -R www-data:www-data "/var/www/${NEXTCLOUD_DOMAIN_NAME}/data"
685
+    sudo -u www-data ./occ config:system:set trusted_domains 1 --value="$NEXTCLOUD_DOMAIN_NAME"
686
+    sudo -u www-data ./occ config:system:set trusted_domains 2 --value="$NEXTCLOUD_ONION_HOSTNAME"
700 687
     sudo -u www-data ./occ files:cleanup
701 688
     sudo -u www-data ./occ files:scan --all
702 689
     sudo -u www-data ./occ maintenance:repair
@@ -705,8 +692,8 @@ function install_nextcloud_main {
705 692
     systemctl restart mariadb
706 693
 
707 694
     # move the data directory
708
-    mv /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/data /var/www/${NEXTCLOUD_DOMAIN_NAME}/
709
-    sed -i "s|'datadirectory'.*|'datadirectory' => '/var/www/$NEXTCLOUD_DOMAIN_NAME/data',|g" /var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php
695
+    mv "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/data" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/"
696
+    sed -i "s|'datadirectory'.*|'datadirectory' => '/var/www/$NEXTCLOUD_DOMAIN_NAME/data',|g" "/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config/config.php"
710 697
 
711 698
     set_completion_param "nextcloud domain" "$NEXTCLOUD_DOMAIN_NAME"
712 699
 
@@ -714,7 +701,7 @@ function install_nextcloud_main {
714 701
 }
715 702
 
716 703
 function install_nextcloud {
717
-    if [ ! $ONION_ONLY ]; then
704
+    if [ ! "$ONION_ONLY" ]; then
718 705
         ONION_ONLY='no'
719 706
     fi
720 707
 

+ 332
- 334
src/freedombone-app-peertube Просмотреть файл

@@ -55,14 +55,14 @@ peertube_variables=(PEERTUBE_DOMAIN_NAME
55 55
                     MY_EMAIL_ADDRESS)
56 56
 
57 57
 function peertube_create_database {
58
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
59
-        PEERTUBE_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
58
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
59
+        PEERTUBE_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
60 60
     else
61
-        if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
62
-            PEERTUBE_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
61
+        if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
62
+            PEERTUBE_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
63 63
         fi
64 64
     fi
65
-    if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
65
+    if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
66 66
         return
67 67
     fi
68 68
 
@@ -82,7 +82,8 @@ function logging_off_peertube {
82 82
 }
83 83
 
84 84
 function remove_user_peertube {
85
-    remove_username="$1"
85
+    echo -n ''
86
+#    remove_username="$1"
86 87
 }
87 88
 
88 89
 function add_user_peertube {
@@ -91,14 +92,14 @@ function add_user_peertube {
91 92
         return
92 93
     fi
93 94
 
94
-    new_username="$1"
95
-    new_user_password="$2"
95
+#    new_username="$1"
96
+#    new_user_password="$2"
96 97
 
97 98
     echo '0'
98 99
 }
99 100
 
100 101
 function install_interactive_peertube {
101
-    if [ ! $ONION_ONLY ]; then
102
+    if [ ! "$ONION_ONLY" ]; then
102 103
         ONION_ONLY='no'
103 104
     fi
104 105
 
@@ -113,15 +114,14 @@ function install_interactive_peertube {
113 114
 }
114 115
 
115 116
 function peertube_set_admin_email {
116
-    read_config_param $MY_EMAIL_ADDRESS
117
-    data=$(tempfile 2>/dev/null)
118
-    trap "rm -f $data" 0 1 2 5 15
117
+    read_config_param "$MY_EMAIL_ADDRESS"
118
+    data=$(mktemp 2>/dev/null)
119 119
     dialog --title $"Set PeerTube administrator email address" \
120 120
            --backtitle $"Freedombone Control Panel" \
121
-           --inputbox $"Admin email address" 8 75 "$MY_EMAIL_ADDRESS" 2>$data
121
+           --inputbox $"Admin email address" 8 75 "$MY_EMAIL_ADDRESS" 2>"$data"
122 122
     sel=$?
123 123
     case $sel in
124
-        0)  peertube_email=$(<$data)
124
+        0)  peertube_email=$(<"$data")
125 125
             if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
126 126
                 if [ ${#peertube_email} -gt 8 ]; then
127 127
                     sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
@@ -132,13 +132,13 @@ function peertube_set_admin_email {
132 132
             fi
133 133
             ;;
134 134
     esac
135
-    rm $data
135
+    rm -f "$data"
136 136
 }
137 137
 
138 138
 function peertube_disable_signups {
139 139
     dialog --title $"Disable PeerTube signups" \
140 140
            --backtitle $"Freedombone Control Panel" \
141
-           --yesno $"\nDo you wish to disable further PeerTube signups?" 8 75
141
+           --yesno $"\\nDo you wish to disable further PeerTube signups?" 8 75
142 142
     sel=$?
143 143
     case $sel in
144 144
         0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
@@ -152,35 +152,36 @@ function peertube_disable_signups {
152 152
 function configure_interactive_peertube {
153 153
     while true
154 154
     do
155
-        data=$(tempfile 2>/dev/null)
156
-        trap "rm -f $data" 0 1 2 5 15
155
+        data=$(mktemp 2>/dev/null)
157 156
         dialog --backtitle $"Freedombone Control Panel" \
158 157
                --title $"PeerTube" \
159 158
                --radiolist $"Choose an operation:" 10 70 4 \
160 159
                1 $"Set administrator email address" off \
161 160
                2 $"Disable or enable signups" off \
162
-               3 $"Exit" on 2> $data
161
+               3 $"Exit" on 2> "$data"
163 162
         sel=$?
164 163
         case $sel in
165 164
             1) break;;
166 165
             255) break;;
167 166
         esac
168
-        case $(cat $data) in
167
+        case $(cat "$data") in
169 168
             1) peertube_set_admin_email;;
170 169
             2) peertube_disable_signups;;
171
-            3) break;;
170
+            3) rm -f "$data"
171
+               break;;
172 172
         esac
173
+        rm -f "$data"
173 174
     done
174 175
 }
175 176
 
176 177
 function change_password_peertube {
177
-    PEERTUBE_USERNAME="$1"
178
+#    PEERTUBE_USERNAME="$1"
178 179
     PEERTUBE_PASSWORD="$2"
179 180
     if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
180 181
         echo $'Peertube password is too short'
181 182
         return
182 183
     fi
183
-    #${PROJECT_NAME}-pass -u $PEERTUBE_USERNAME -a peertube -p "$PEERTUBE_PASSWORD"
184
+    #"${PROJECT_NAME}-pass" -u "$PEERTUBE_USERNAME" -a peertube -p "$PEERTUBE_PASSWORD"
184 185
 }
185 186
 
186 187
 function reconfigure_peertube {
@@ -195,7 +196,7 @@ function upgrade_peertube {
195 196
 
196 197
     read_config_param PEERTUBE_DOMAIN_NAME
197 198
     systemctl stop peertube
198
-    cd $PEERTUBE_DIR
199
+    cd "$PEERTUBE_DIR" || exit 7824552627
199 200
 
200 201
     function_check set_repo_commit
201 202
     set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
@@ -207,7 +208,7 @@ function upgrade_peertube {
207 208
 
208 209
 function backup_local_peertube {
209 210
     PEERTUBE_DOMAIN_NAME='peertube.local'
210
-    if grep -q "peertube domain" $COMPLETION_FILE; then
211
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
211 212
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
212 213
     fi
213 214
 
@@ -219,7 +220,7 @@ function backup_local_peertube {
219 220
 
220 221
     peertube_path=$PEERTUBE_DIR/videos
221 222
     if [ -d $peertube_path ]; then
222
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
223
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
223 224
         systemctl stop peertube
224 225
         backup_directory_to_usb $peertube_path peertubevideos
225 226
         systemctl start peertube
@@ -229,11 +230,11 @@ function backup_local_peertube {
229 230
 
230 231
 function restore_local_peertube {
231 232
     PEERTUBE_DOMAIN_NAME='peertube.local'
232
-    if grep -q "peertube domain" $COMPLETION_FILE; then
233
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
233 234
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
234 235
     fi
235
-    if [ $PEERTUBE_DOMAIN_NAME ]; then
236
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
236
+    if [ "$PEERTUBE_DOMAIN_NAME" ]; then
237
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
237 238
         systemctl stop peertube
238 239
 
239 240
         USE_POSTGRESQL=1
@@ -259,7 +260,7 @@ function restore_local_peertube {
259 260
 
260 261
 function backup_remote_peertube {
261 262
     PEERTUBE_DOMAIN_NAME='peertube.local'
262
-    if grep -q "peertube domain" $COMPLETION_FILE; then
263
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
263 264
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
264 265
     fi
265 266
 
@@ -272,7 +273,7 @@ function backup_remote_peertube {
272 273
     temp_backup_dir=$PEERTUBE_DIR/videos
273 274
     if [ -d $temp_backup_dir ]; then
274 275
         systemctl stop peertube
275
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
276
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
276 277
         backup_directory_to_friend $temp_backup_dir peertubevideos
277 278
         restart_site
278 279
         systemctl start peertube
@@ -284,13 +285,14 @@ function backup_remote_peertube {
284 285
 
285 286
 function restore_remote_peertube {
286 287
     PEERTUBE_DOMAIN_NAME='peertube.local'
287
-    if grep -q "peertube domain" $COMPLETION_FILE; then
288
+    if grep -q "peertube domain" "$COMPLETION_FILE"; then
288 289
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
289 290
     fi
290
-    suspend_site ${PEERTUBE_DOMAIN_NAME}
291
+    suspend_site "${PEERTUBE_DOMAIN_NAME}"
291 292
 
292 293
     systemctl stop peertube
293 294
 
295
+    # shellcheck disable=SC2034
294 296
     USE_POSTGRESQL=1
295 297
     function_check restore_database_from_friend
296 298
     restore_database_from_friend peertube
@@ -326,20 +328,20 @@ function remove_peertube {
326 328
     remove_nodejs peertube
327 329
 
328 330
     read_config_param "PEERTUBE_DOMAIN_NAME"
329
-    nginx_dissite $PEERTUBE_DOMAIN_NAME
330
-    remove_certs ${PEERTUBE_DOMAIN_NAME}
331
-    if [ -f /etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME ]; then
332
-        rm -f /etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
331
+    nginx_dissite "$PEERTUBE_DOMAIN_NAME"
332
+    remove_certs "${PEERTUBE_DOMAIN_NAME}"
333
+    if [ -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME" ]; then
334
+        rm -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME"
333 335
     fi
334
-    if [ -d /var/www/$PEERTUBE_DOMAIN_NAME ]; then
335
-        rm -rf /var/www/$PEERTUBE_DOMAIN_NAME
336
+    if [ -d "/var/www/$PEERTUBE_DOMAIN_NAME" ]; then
337
+        rm -rf "/var/www/$PEERTUBE_DOMAIN_NAME"
336 338
     fi
337 339
     remove_config_param PEERTUBE_DOMAIN_NAME
338 340
     remove_config_param PEERTUBE_CODE
339 341
     function_check remove_onion_service
340 342
     remove_onion_service peertube ${PEERTUBE_ONION_PORT}
341 343
     remove_completion_param "install_peertube"
342
-    sed -i '/peertube/d' $COMPLETION_FILE
344
+    sed -i '/peertube/d' "$COMPLETION_FILE"
343 345
 
344 346
     function_check drop_database_postgresql
345 347
     drop_database_postgresql peertube peertube
@@ -352,188 +354,189 @@ function remove_peertube {
352 354
     fi
353 355
 
354 356
     function_check remove_ddns_domain
355
-    remove_ddns_domain $PEERTUBE_DOMAIN_NAME
357
+    remove_ddns_domain "$PEERTUBE_DOMAIN_NAME"
356 358
 }
357 359
 
358 360
 function peertube_setup_web {
359 361
     peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
360 362
 
361 363
     if [[ $ONION_ONLY == "no" ]]; then
362
-        echo 'server {' > $peertube_nginx_file
363
-        echo '  listen 80;' >> $peertube_nginx_file
364
-        echo '  listen [::]:80;' >> $peertube_nginx_file
365
-        echo "  server_name $PEERTUBE_DOMAIN_NAME;" >> $peertube_nginx_file
366
-        echo '  rewrite ^ https://$server_name$request_uri? permanent;' >> $peertube_nginx_file
367
-        echo '}' >> $peertube_nginx_file
368
-        echo '' >> $peertube_nginx_file
369
-        echo 'server {' >> $peertube_nginx_file
370
-        echo '  listen 443 ssl http2;' >> $peertube_nginx_file
371
-        echo '  #listen [::]:443 ssl http2;' >> $peertube_nginx_file
372
-        echo "  server_name $PEERTUBE_DOMAIN_NAME;" >> $peertube_nginx_file
373
-        echo '' >> $peertube_nginx_file
364
+        { echo 'server {';
365
+          echo '  listen 80;';
366
+          echo '  listen [::]:80;';
367
+          echo "  server_name $PEERTUBE_DOMAIN_NAME;";
368
+          echo "  rewrite ^ https://\$server_name\$request_uri? permanent;";
369
+          echo '}';
370
+          echo '';
371
+          echo 'server {';
372
+          echo '  listen 443 ssl http2;';
373
+          echo '  #listen [::]:443 ssl http2;';
374
+          echo "  server_name $PEERTUBE_DOMAIN_NAME;";
375
+          echo ''; } > "$peertube_nginx_file"
374 376
         function_check nginx_ssl
375
-        nginx_ssl $PEERTUBE_DOMAIN_NAME mobile
377
+        nginx_ssl "$PEERTUBE_DOMAIN_NAME" mobile
376 378
 
377 379
         function_check nginx_disable_sniffing
378
-        nginx_disable_sniffing $PEERTUBE_DOMAIN_NAME
379
-
380
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $peertube_nginx_file
381
-        echo '' >> $peertube_nginx_file
382
-        echo '  location / {' >> $peertube_nginx_file
383
-        echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
384
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
385
-        echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
386
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
387
-        echo '' >> $peertube_nginx_file
388
-        echo '    # For the video upload' >> $peertube_nginx_file
389
-        echo '    client_max_body_size 2G;' >> $peertube_nginx_file
390
-        echo '  }' >> $peertube_nginx_file
391
-        echo '' >> $peertube_nginx_file
392
-        echo '  location /static/webseed {' >> $peertube_nginx_file
393
-        echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
394
-        echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
395
-        echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
396
-        echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
397
-        echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
398
-        echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
399
-        echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
400
-        echo '      return 204;' >> $peertube_nginx_file
401
-        echo '    }' >> $peertube_nginx_file
402
-        echo '' >> $peertube_nginx_file
403
-        echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
404
-        echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
405
-        echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
406
-        echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
407
-        echo '    }' >> $peertube_nginx_file
408
-        echo '' >> $peertube_nginx_file
409
-        echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
410
-        echo '  }' >> $peertube_nginx_file
411
-        echo '' >> $peertube_nginx_file
412
-        echo '  # Websocket tracker' >> $peertube_nginx_file
413
-        echo '  location /tracker/socket {' >> $peertube_nginx_file
414
-        echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
415
-        echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
416
-        echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
417
-        echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
418
-        echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
419
-        echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
420
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
421
-        echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
422
-        echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
423
-        echo '  }' >> $peertube_nginx_file
424
-        echo '}' >> $peertube_nginx_file
380
+        nginx_disable_sniffing "$PEERTUBE_DOMAIN_NAME"
381
+
382
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
383
+          echo '';
384
+          echo '  location / {';
385
+          echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
386
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
387
+          echo "    proxy_set_header Host \$host;";
388
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
389
+          echo '';
390
+          echo '    # For the video upload';
391
+          echo '    client_max_body_size 2G;';
392
+          echo '  }';
393
+          echo '';
394
+          echo '  location /static/webseed {';
395
+          echo "    if (\$request_method = 'OPTIONS') {";
396
+          echo "      add_header 'Access-Control-Allow-Origin' '*';";
397
+          echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
398
+          echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
399
+          echo "      add_header 'Access-Control-Max-Age' 1728000;";
400
+          echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
401
+          echo "      add_header 'Content-Length' 0;";
402
+          echo '      return 204;';
403
+          echo '    }';
404
+          echo '';
405
+          echo "    if (\$request_method = 'GET') {";
406
+          echo "      add_header 'Access-Control-Allow-Origin' '*';";
407
+          echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
408
+          echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
409
+          echo '    }';
410
+          echo '';
411
+          echo "    alias $PEERTUBE_DIR/videos;";
412
+          echo '  }';
413
+          echo '';
414
+          echo '  # Websocket tracker';
415
+          echo '  location /tracker/socket {';
416
+          echo '    # Peers send a message to the tracker every 15 minutes';
417
+          echo '    # Dont close the websocket before this time';
418
+          echo '    proxy_read_timeout 1200s;';
419
+          echo "    proxy_set_header Upgrade \$http_upgrade;";
420
+          echo '    proxy_set_header Connection "upgrade";';
421
+          echo '    proxy_http_version 1.1;';
422
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
423
+          echo "    proxy_set_header Host \$host;";
424
+          echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
425
+          echo '  }';
426
+          echo '}'; } >> "$peertube_nginx_file"
425 427
     else
426
-        echo -n '' > $peertube_nginx_file
427
-    fi
428
-    echo 'server {' >> $peertube_nginx_file
429
-    echo "  listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;" >> $peertube_nginx_file
430
-    echo "  server_name $PEERTUBE_ONION_HOSTNAME;" >> $peertube_nginx_file
431
-    echo '' >> $peertube_nginx_file
432
-    echo '  location / {' >> $peertube_nginx_file
433
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
434
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
435
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
436
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
437
-    echo '' >> $peertube_nginx_file
438
-    echo '    # For the video upload' >> $peertube_nginx_file
439
-    echo '    client_max_body_size 2G;' >> $peertube_nginx_file
440
-    echo '  }' >> $peertube_nginx_file
441
-    echo '' >> $peertube_nginx_file
442
-    echo '  location /static/webseed {' >> $peertube_nginx_file
443
-    echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
444
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
445
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
446
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
447
-    echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
448
-    echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
449
-    echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
450
-    echo '      return 204;' >> $peertube_nginx_file
451
-    echo '    }' >> $peertube_nginx_file
452
-    echo '' >> $peertube_nginx_file
453
-    echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
454
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
455
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
456
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
457
-    echo '    }' >> $peertube_nginx_file
458
-    echo '' >> $peertube_nginx_file
459
-    echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
460
-    echo '  }' >> $peertube_nginx_file
461
-    echo '' >> $peertube_nginx_file
462
-    echo '  # Websocket tracker' >> $peertube_nginx_file
463
-    echo '  location /tracker/socket {' >> $peertube_nginx_file
464
-    echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
465
-    echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
466
-    echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
467
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
468
-    echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
469
-    echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
470
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
471
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
472
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
473
-    echo '  }' >> $peertube_nginx_file
474
-    echo '}' >> $peertube_nginx_file
428
+        echo -n '' > "$peertube_nginx_file"
429
+    fi
430
+    { echo 'server {';
431
+      echo "  listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;";
432
+      echo "  server_name $PEERTUBE_ONION_HOSTNAME;";
433
+      echo '';
434
+      echo '  location / {';
435
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
436
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
437
+      echo "    proxy_set_header Host \$host;";
438
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
439
+      echo '';
440
+      echo '    # For the video upload';
441
+      echo '    client_max_body_size 2G;';
442
+      echo '  }';
443
+      echo '';
444
+      echo '  location /static/webseed {';
445
+      echo "    if (\$request_method = 'OPTIONS') {";
446
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
447
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
448
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
449
+      echo "      add_header 'Access-Control-Max-Age' 1728000;";
450
+      echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
451
+      echo "      add_header 'Content-Length' 0;";
452
+      echo '      return 204;';
453
+      echo '    }';
454
+      echo '';
455
+      echo "    if (\$request_method = 'GET') {";
456
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
457
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
458
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
459
+      echo '    }';
460
+      echo '';
461
+      echo "    alias $PEERTUBE_DIR/videos;";
462
+      echo '  }';
463
+      echo '';
464
+      echo '  # Websocket tracker';
465
+      echo '  location /tracker/socket {';
466
+      echo '    # Peers send a message to the tracker every 15 minutes';
467
+      echo '    # Dont close the websocket before this time';
468
+      echo '    proxy_read_timeout 1200s;';
469
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
470
+      echo '    proxy_set_header Connection "upgrade";';
471
+      echo '    proxy_http_version 1.1;';
472
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
473
+      echo "    proxy_set_header Host \$host;";
474
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
475
+      echo '  }';
476
+      echo '}'; } >> "$peertube_nginx_file"
475 477
 
476 478
     # CSP currently causes an error
477
-    sed -i '/Content-Security-Policy/d' $peertube_nginx_file
479
+    sed -i '/Content-Security-Policy/d' "$peertube_nginx_file"
478 480
 
479 481
     function_check create_site_certificate
480
-    create_site_certificate $PEERTUBE_DOMAIN_NAME 'yes'
482
+    create_site_certificate "$PEERTUBE_DOMAIN_NAME" 'yes'
481 483
 
482 484
     function_check nginx_ensite
483
-    nginx_ensite $PEERTUBE_DOMAIN_NAME
485
+    nginx_ensite "$PEERTUBE_DOMAIN_NAME"
484 486
 }
485 487
 
486 488
 function mesh_peertube_setup_web {
489
+    # shellcheck disable=SC2154
487 490
     peertube_nginx_file=$rootdir/etc/nginx/sites-available/peertube
488 491
 
489
-    echo 'server {' >> $peertube_nginx_file
490
-    echo "  listen $MESH_PEERTUBE_PORT http2;" >> $peertube_nginx_file
491
-    echo '  listen [::]:$MESH_PEERTUBE_PORT http2;' >> $peertube_nginx_file
492
-    echo '  server_name $HOSTNAME;' >> $peertube_nginx_file
493
-    echo '' >> $peertube_nginx_file
494
-    echo '  location / {' >> $peertube_nginx_file
495
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
496
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $peertube_nginx_file
497
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
498
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
499
-    echo '' >> $peertube_nginx_file
500
-    echo '    # For the video upload' >> $peertube_nginx_file
501
-    echo '    client_max_body_size 2G;' >> $peertube_nginx_file
502
-    echo '  }' >> $peertube_nginx_file
503
-    echo '' >> $peertube_nginx_file
504
-    echo '  location /static/webseed {' >> $peertube_nginx_file
505
-    echo "    if (\$request_method = 'OPTIONS') {" >> $peertube_nginx_file
506
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
507
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
508
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
509
-    echo "      add_header 'Access-Control-Max-Age' 1728000;" >> $peertube_nginx_file
510
-    echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';" >> $peertube_nginx_file
511
-    echo "      add_header 'Content-Length' 0;" >> $peertube_nginx_file
512
-    echo '      return 204;' >> $peertube_nginx_file
513
-    echo '    }' >> $peertube_nginx_file
514
-    echo '' >> $peertube_nginx_file
515
-    echo "    if (\$request_method = 'GET') {" >> $peertube_nginx_file
516
-    echo "      add_header 'Access-Control-Allow-Origin' '*';" >> $peertube_nginx_file
517
-    echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';" >> $peertube_nginx_file
518
-    echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';" >> $peertube_nginx_file
519
-    echo '    }' >> $peertube_nginx_file
520
-    echo '' >> $peertube_nginx_file
521
-    echo "    alias $PEERTUBE_DIR/videos;" >> $peertube_nginx_file
522
-    echo '  }' >> $peertube_nginx_file
523
-    echo '' >> $peertube_nginx_file
524
-    echo '  # Websocket tracker' >> $peertube_nginx_file
525
-    echo '  location /tracker/socket {' >> $peertube_nginx_file
526
-    echo '    # Peers send a message to the tracker every 15 minutes' >> $peertube_nginx_file
527
-    echo '    # Dont close the websocket before this time' >> $peertube_nginx_file
528
-    echo '    proxy_read_timeout 1200s;' >> $peertube_nginx_file
529
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $peertube_nginx_file
530
-    echo '    proxy_set_header Connection "upgrade";' >> $peertube_nginx_file
531
-    echo '    proxy_http_version 1.1;' >> $peertube_nginx_file
532
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $peertube_nginx_file
533
-    echo '    proxy_set_header Host $host;' >> $peertube_nginx_file
534
-    echo "    proxy_pass http://localhost:${PEERTUBE_PORT};" >> $peertube_nginx_file
535
-    echo '  }' >> $peertube_nginx_file
536
-    echo '}' >> $peertube_nginx_file
492
+    { echo 'server {';
493
+      echo "  listen $MESH_PEERTUBE_PORT http2;";
494
+      echo "  listen [::]:\$MESH_PEERTUBE_PORT http2;";
495
+      echo "  server_name \$HOSTNAME;";
496
+      echo '';
497
+      echo '  location / {';
498
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
499
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
500
+      echo "    proxy_set_header Host \$host;";
501
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
502
+      echo '';
503
+      echo '    # For the video upload';
504
+      echo '    client_max_body_size 2G;';
505
+      echo '  }';
506
+      echo '';
507
+      echo '  location /static/webseed {';
508
+      echo "    if (\$request_method = 'OPTIONS') {";
509
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
510
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
511
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
512
+      echo "      add_header 'Access-Control-Max-Age' 1728000;";
513
+      echo "      add_header 'Content-Type' 'text/plain charset=UTF-8';";
514
+      echo "      add_header 'Content-Length' 0;";
515
+      echo '      return 204;';
516
+      echo '    }';
517
+      echo '';
518
+      echo "    if (\$request_method = 'GET') {";
519
+      echo "      add_header 'Access-Control-Allow-Origin' '*';";
520
+      echo "      add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
521
+      echo "      add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
522
+      echo '    }';
523
+      echo '';
524
+      echo "    alias $PEERTUBE_DIR/videos;";
525
+      echo '  }';
526
+      echo '';
527
+      echo '  # Websocket tracker';
528
+      echo '  location /tracker/socket {';
529
+      echo '    # Peers send a message to the tracker every 15 minutes';
530
+      echo '    # Dont close the websocket before this time';
531
+      echo '    proxy_read_timeout 1200s;';
532
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
533
+      echo "    proxy_set_header Connection \"upgrade\";";
534
+      echo '    proxy_http_version 1.1;';
535
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
536
+      echo "    proxy_set_header Host \$host;";
537
+      echo "    proxy_pass http://localhost:${PEERTUBE_PORT};";
538
+      echo '  }';
539
+      echo '}'; } > "$peertube_nginx_file"
537 540
 }
538 541
 
539 542
 function peertube_create_config {
@@ -541,84 +544,85 @@ function peertube_create_config {
541 544
 
542 545
     peertube_config_file=$peertube_prefix$PEERTUBE_DIR/config/production.yaml
543 546
 
544
-    echo 'listen:' > $peertube_config_file
545
-    echo "  port: $PEERTUBE_PORT" >> $peertube_config_file
546
-    echo '' >> $peertube_config_file
547
-    echo '# Correspond to your reverse proxy "listen" configuration' >> $peertube_config_file
548
-    echo 'webserver:' >> $peertube_config_file
549
-    if [ ! $peertube_prefix ]; then
550
-        if [[ $ONION_ONLY == 'no' ]]; then
551
-            echo '  https: true' >> $peertube_config_file
552
-            echo "  hostname: '$PEERTUBE_DOMAIN_NAME'" >> $peertube_config_file
553
-            echo '  port: 443' >> $peertube_config_file
547
+    { echo 'listen:';
548
+      echo "  port: $PEERTUBE_PORT";
549
+      echo '';
550
+      echo '# Correspond to your reverse proxy "listen" configuration';
551
+      echo 'webserver:'; } > "$peertube_config_file"
552
+    if [ ! "$peertube_prefix" ]; then
553
+        if [[ "$ONION_ONLY" == 'no' ]]; then
554
+            { echo '  https: true';
555
+              echo "  hostname: '$PEERTUBE_DOMAIN_NAME'";
556
+              echo '  port: 443'; } >> "$peertube_config_file"
554 557
         else
555
-            echo '  https: false' >> $peertube_config_file
556
-            echo "  hostname: '$PEERTUBE_ONION_HOSTNAME'" >> $peertube_config_file
557
-            echo '  port: 80' >> $peertube_config_file
558
+            { echo '  https: false';
559
+              echo "  hostname: '$PEERTUBE_ONION_HOSTNAME'";
560
+              echo '  port: 80'; } >> "$peertube_config_file"
558 561
         fi
559 562
     else
560
-        echo '  https: false' >> $peertube_config_file
561
-        echo "  hostname: ''" >> $peertube_config_file
562
-        echo "  port: $MESH_PEERTUBE_PORT" >> $peertube_config_file
563
-    fi
564
-    echo '' >> $peertube_config_file
565
-    echo '# Your database name will be "peertube"+database.suffix' >> $peertube_config_file
566
-    echo 'database:' >> $peertube_config_file
567
-    echo "  hostname: 'localhost'" >> $peertube_config_file
568
-    echo '  port: 5432' >> $peertube_config_file
569
-    echo "  suffix: ''" >> $peertube_config_file
570
-    echo "  username: 'peertube'" >> $peertube_config_file
571
-    if [ ! $peertube_prefix ]; then
572
-        echo "  password: '$PEERTUBE_ADMIN_PASSWORD'" >> $peertube_config_file
563
+        { echo '  https: false';
564
+          echo "  hostname: ''";
565
+          echo "  port: $MESH_PEERTUBE_PORT"; } >> "$peertube_config_file"
566
+    fi
567
+    { echo '';
568
+      echo '# Your database name will be "peertube"+database.suffix';
569
+      echo 'database:';
570
+      echo "  hostname: 'localhost'";
571
+      echo '  port: 5432';
572
+      echo "  suffix: ''";
573
+      echo "  username: 'peertube'"; } >> "$peertube_config_file"
574
+    if [ ! "$peertube_prefix" ]; then
575
+        echo "  password: '$PEERTUBE_ADMIN_PASSWORD'" >> "$peertube_config_file"
573 576
     else
574
-        echo "  password: ''" >> $peertube_config_file
575
-    fi
576
-    echo '' >> $peertube_config_file
577
-    echo '# From the project root directory' >> $peertube_config_file
578
-    echo 'storage:' >> $peertube_config_file
579
-    echo "  certs: 'certs/'" >> $peertube_config_file
580
-    echo "  videos: 'videos/'" >> $peertube_config_file
581
-    echo "  logs: 'logs/'" >> $peertube_config_file
582
-    echo "  previews: 'previews/'" >> $peertube_config_file
583
-    echo "  thumbnails: 'thumbnails/'" >> $peertube_config_file
584
-    echo "  torrents: 'torrents/'" >> $peertube_config_file
585
-    echo "  cache: 'cache/'" >> $peertube_config_file
586
-    echo '' >> $peertube_config_file
587
-    echo 'cache:' >> $peertube_config_file
588
-    echo '  previews:' >> $peertube_config_file
589
-    echo '    size: 10 # Max number of previews you want to cache' >> $peertube_config_file
590
-    echo '' >> $peertube_config_file
591
-    echo 'admin:' >> $peertube_config_file
592
-    # This is deliberately a dummy email address
593
-    echo "  email: 'testuser@testdomain.net'" >> $peertube_config_file
594
-    echo '' >> $peertube_config_file
595
-    echo 'signup:' >> $peertube_config_file
596
-    echo '  enabled: true' >> $peertube_config_file
597
-    echo '  limit: 5 # When the limit is reached, registrations are disabled. -1 == unlimited' >> $peertube_config_file
598
-    echo '' >> $peertube_config_file
599
-    echo 'user:' >> $peertube_config_file
600
-    echo '  # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).' >> $peertube_config_file
601
-    echo '  # -1 == unlimited' >> $peertube_config_file
602
-    echo '  video_quota: -1' >> $peertube_config_file
603
-    echo '' >> $peertube_config_file
604
-    echo '# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag' >> $peertube_config_file
605
-    echo '# Uses a lot of CPU!' >> $peertube_config_file
606
-    echo 'transcoding:' >> $peertube_config_file
607
-    echo '  enabled: true' >> $peertube_config_file
608
-    echo '  threads: 2' >> $peertube_config_file
609
-    echo '  resolutions: # Only created if the original video has a higher resolution' >> $peertube_config_file
610
-    echo '    240p: true' >> $peertube_config_file
611
-    echo '    360p: false' >> $peertube_config_file
612
-    echo '    480p: false' >> $peertube_config_file
613
-    echo '    720p: false' >> $peertube_config_file
614
-    echo '    1080p: false' >> $peertube_config_file
577
+        echo "  password: ''" >> "$peertube_config_file"
578
+    fi
579
+    { echo '';
580
+      echo '# From the project root directory';
581
+      echo 'storage:';
582
+      echo "  certs: 'certs/'";
583
+      echo "  videos: 'videos/'";
584
+      echo "  logs: 'logs/'";
585
+      echo "  previews: 'previews/'";
586
+      echo "  thumbnails: 'thumbnails/'";
587
+      echo "  torrents: 'torrents/'";
588
+      echo "  cache: 'cache/'";
589
+      echo '';
590
+      echo 'cache:';
591
+      echo '  previews:';
592
+      echo '    size: 10 # Max number of previews you want to cache';
593
+      echo '';
594
+      echo 'admin:';
595
+      # This is deliberately a dummy email address
596
+      echo "  email: 'testuser@testdomain.net'";
597
+      echo '';
598
+      echo 'signup:';
599
+      echo '  enabled: true';
600
+      echo '  limit: 5 # When the limit is reached, registrations are disabled. -1 == unlimited';
601
+      echo '';
602
+      echo 'user:';
603
+      echo '  # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).';
604
+      echo '  # -1 == unlimited';
605
+      echo '  video_quota: -1';
606
+      echo '';
607
+      echo '# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag';
608
+      echo '# Uses a lot of CPU!';
609
+      echo 'transcoding:';
610
+      echo '  enabled: true';
611
+      echo '  threads: 2';
612
+      echo '  resolutions: # Only created if the original video has a higher resolution';
613
+      echo '    240p: true';
614
+      echo '    360p: false';
615
+      echo '    480p: false';
616
+      echo '    720p: false';
617
+      echo '    1080p: false'; } >> "$peertube_config_file"
615 618
 }
616 619
 
617 620
 function mesh_install_peertube {
618
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
621
+    # shellcheck disable=SC2153
622
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
619 623
         return
620 624
     fi
621
-    if [[ $ARCHITECTURE != 'x86_64' && $ARCHITECTURE != 'amd64' ]]; then
625
+    if [[ "$ARCHITECTURE" != 'x86_64' && "$ARCHITECTURE" != 'amd64' ]]; then
622 626
         return
623 627
     fi
624 628
 
@@ -627,22 +631,21 @@ function mesh_install_peertube {
627 631
     function_check install_postgresql
628 632
     install_postgresql
629 633
 
630
-    if [ -d $rootdir$PEERTUBE_DIR ]; then
631
-        rm -rf $rootdir$PEERTUBE_DIR
634
+    if [ -d "$rootdir$PEERTUBE_DIR" ]; then
635
+        rm -rf "$rootdir$PEERTUBE_DIR"
632 636
     fi
633 637
 
634
-    git clone $PEERTUBE_REPO $rootdir$PEERTUBE_DIR
638
+    git clone "$PEERTUBE_REPO" "$rootdir$PEERTUBE_DIR"
635 639
 
636 640
     chroot "$rootdir" groupadd peertube
637 641
     chroot "$rootdir" useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
638 642
 
639
-    cd $rootdir$PEERTUBE_DIR
643
+    cd "$rootdir$PEERTUBE_DIR" || exit 246824524
640 644
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
641 645
 
642
-
643 646
     get_npm_arch
644 647
 
645
-    cat <<EOF > $rootdir/usr/bin/install_peertube
648
+    cat <<EOF > "$rootdir/usr/bin/install_peertube"
646 649
 #!/bin/bash
647 650
 cd $PEERTUBE_DIR
648 651
 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
@@ -683,34 +686,33 @@ if [ ! "\$?" = "0" ]; then
683 686
     exit 5293593
684 687
 fi
685 688
 EOF
686
-    chmod +x $rootdir/usr/bin/install_peertube
687
-    chroot "$rootdir" /usr/bin/install_peertube
688
-    if [ ! "$?" = "0" ]; then
689
+    chmod +x "$rootdir/usr/bin/install_peertube"
690
+    if ! chroot "$rootdir" /usr/bin/install_peertube; then
689 691
         echo $'PeerTube install failed'
690 692
         exit 735638
691 693
     fi
692 694
 
693
-    echo '[Unit]' > $rootdir/etc/systemd/system/peertube.service
694
-    echo 'Description=PeerTube Decentralized video streaming platform' >> $rootdir/etc/systemd/system/peertube.service
695
-    echo 'After=syslog.target' >> $rootdir/etc/systemd/system/peertube.service
696
-    echo 'After=network.target' >> $rootdir/etc/systemd/system/peertube.service
697
-    echo '' >> $rootdir/etc/systemd/system/peertube.service
698
-    echo '[Service]' >> $rootdir/etc/systemd/system/peertube.service
699
-    echo 'User=peertube' >> $rootdir/etc/systemd/system/peertube.service
700
-    echo 'Group=peertube' >> $rootdir/etc/systemd/system/peertube.service
701
-    echo "WorkingDirectory=$PEERTUBE_DIR" >> $rootdir/etc/systemd/system/peertube.service
702
-    echo "ExecStart=/usr/local/bin/npm start" >> $rootdir/etc/systemd/system/peertube.service
703
-    echo "ExecStop=/usr/local/bin/npm stop" >> $rootdir/etc/systemd/system/peertube.service
704
-    echo 'StandardOutput=syslog' >> $rootdir/etc/systemd/system/peertube.service
705
-    echo 'StandardError=syslog' >> $rootdir/etc/systemd/system/peertube.service
706
-    echo 'SyslogIdentifier=peertube' >> $rootdir/etc/systemd/system/peertube.service
707
-    echo 'Restart=always' >> $rootdir/etc/systemd/system/peertube.service
708
-    echo "Environment=NODE_ENV=production" >> $rootdir/etc/systemd/system/peertube.service
709
-    echo '' >> $rootdir/etc/systemd/system/peertube.service
710
-    echo '[Install]' >> $rootdir/etc/systemd/system/peertube.service
711
-    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/peertube.service
712
-
713
-    peertube_create_config $rootdir
695
+    { echo '[Unit]';
696
+      echo 'Description=PeerTube Decentralized video streaming platform';
697
+      echo 'After=syslog.target';
698
+      echo 'After=network.target';
699
+      echo '';
700
+      echo '[Service]';
701
+      echo 'User=peertube';
702
+      echo 'Group=peertube';
703
+      echo "WorkingDirectory=$PEERTUBE_DIR";
704
+      echo "ExecStart=/usr/local/bin/npm start";
705
+      echo "ExecStop=/usr/local/bin/npm stop";
706
+      echo 'StandardOutput=syslog';
707
+      echo 'StandardError=syslog';
708
+      echo 'SyslogIdentifier=peertube';
709
+      echo 'Restart=always';
710
+      echo "Environment=NODE_ENV=production";
711
+      echo '';
712
+      echo '[Install]';
713
+      echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/peertube.service"
714
+
715
+    peertube_create_config "$rootdir"
714 716
 
715 717
     chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
716 718
 
@@ -730,7 +732,7 @@ function install_peertube {
730 732
         ONION_ONLY='no'
731 733
     fi
732 734
 
733
-    if [ ! $PEERTUBE_DOMAIN_NAME ]; then
735
+    if [ ! "$PEERTUBE_DOMAIN_NAME" ]; then
734 736
         echo $'The peertube domain name was not specified'
735 737
         exit 783523
736 738
     fi
@@ -740,8 +742,8 @@ function install_peertube {
740 742
     function_check install_postgresql
741 743
     install_postgresql
742 744
 
743
-    if [ ! -d /var/www/$PEERTUBE_DOMAIN_NAME/htdocs ]; then
744
-        mkdir -p /var/www/$PEERTUBE_DOMAIN_NAME/htdocs
745
+    if [ ! -d "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs" ]; then
746
+        mkdir -p "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs"
745 747
     fi
746 748
 
747 749
     if [ -d $PEERTUBE_DIR ]; then
@@ -759,60 +761,56 @@ function install_peertube {
759 761
     if [ -d /repos/peertube ]; then
760 762
         mkdir -p $PEERTUBE_DIR
761 763
         cp -r -p /repos/peertube/. $PEERTUBE_DIR
762
-        cd $PEERTUBE_DIR
764
+        cd "$PEERTUBE_DIR" || exit 642874682
763 765
         git pull
764 766
     else
765 767
         function_check git_clone
766 768
         git_clone $PEERTUBE_REPO $PEERTUBE_DIR
767 769
     fi
768 770
 
769
-    cd $PEERTUBE_DIR
771
+    cd "$PEERTUBE_DIR" || exit 27492742
770 772
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
771 773
     set_completion_param "peertube commit" "$PEERTUBE_COMMIT"
772 774
 
773
-    npm install -g yarn
774
-    if [ ! "$?" = "0" ]; then
775
+    if ! npm install -g yarn; then
775 776
         echo $'Failed to install yarn'
776 777
         exit 79353234
777 778
     fi
778 779
     yarn add -D webpack --network-concurrency 1
779
-    yarn install
780
-    if [ ! "$?" = "0" ]; then
780
+    if ! yarn install; then
781 781
         echo $'Failed to run yarn install'
782 782
         exit 63754235
783 783
     fi
784
-    npm install
785
-    if [ ! "$?" = "0" ]; then
784
+    if ! npm install; then
786 785
         echo $'Failed to install peertube'
787 786
         exit 7835243
788 787
     fi
789
-    npm run build
790
-    if [ ! "$?" = "0" ]; then
788
+    if ! npm run build; then
791 789
         echo $'Failed to build peertube'
792 790
         exit 5293593
793 791
     fi
794 792
 
795 793
     PEERTUBE_ONION_HOSTNAME=$(add_onion_service peertube 80 ${PEERTUBE_ONION_PORT})
796 794
 
797
-    echo '[Unit]' > /etc/systemd/system/peertube.service
798
-    echo 'Description=PeerTube Decentralized video streaming platform' >> /etc/systemd/system/peertube.service
799
-    echo 'After=syslog.target' >> /etc/systemd/system/peertube.service
800
-    echo 'After=network.target' >> /etc/systemd/system/peertube.service
801
-    echo '' >> /etc/systemd/system/peertube.service
802
-    echo '[Service]' >> /etc/systemd/system/peertube.service
803
-    echo 'User=peertube' >> /etc/systemd/system/peertube.service
804
-    echo 'Group=peertube' >> /etc/systemd/system/peertube.service
805
-    echo "WorkingDirectory=$PEERTUBE_DIR" >> /etc/systemd/system/peertube.service
806
-    echo "ExecStart=/usr/local/bin/npm start" >> /etc/systemd/system/peertube.service
807
-    echo "ExecStop=/usr/local/bin/npm stop" >> /etc/systemd/system/peertube.service
808
-    echo 'StandardOutput=syslog' >> /etc/systemd/system/peertube.service
809
-    echo 'StandardError=syslog' >> /etc/systemd/system/peertube.service
810
-    echo 'SyslogIdentifier=peertube' >> /etc/systemd/system/peertube.service
811
-    echo 'Restart=always' >> /etc/systemd/system/peertube.service
812
-    echo "Environment=NODE_ENV=production" >> /etc/systemd/system/peertube.service
813
-    echo '' >> /etc/systemd/system/peertube.service
814
-    echo '[Install]' >> /etc/systemd/system/peertube.service
815
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/peertube.service
795
+    { echo '[Unit]';
796
+      echo 'Description=PeerTube Decentralized video streaming platform';
797
+      echo 'After=syslog.target';
798
+      echo 'After=network.target';
799
+      echo '';
800
+      echo '[Service]';
801
+      echo 'User=peertube';
802
+      echo 'Group=peertube';
803
+      echo "WorkingDirectory=$PEERTUBE_DIR";
804
+      echo "ExecStart=/usr/local/bin/npm start";
805
+      echo "ExecStop=/usr/local/bin/npm stop";
806
+      echo 'StandardOutput=syslog';
807
+      echo 'StandardError=syslog';
808
+      echo 'SyslogIdentifier=peertube';
809
+      echo 'Restart=always';
810
+      echo "Environment=NODE_ENV=production";
811
+      echo '';
812
+      echo '[Install]';
813
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/peertube.service
816 814
 
817 815
     peertube_create_config
818 816
 
@@ -820,10 +818,10 @@ function install_peertube {
820 818
 
821 819
     peertube_setup_web
822 820
 
823
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a peertube -p "$PEERTUBE_ADMIN_PASSWORD"
821
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a peertube -p "$PEERTUBE_ADMIN_PASSWORD"
824 822
 
825 823
     function_check add_ddns_domain
826
-    add_ddns_domain $PEERTUBE_DOMAIN_NAME
824
+    add_ddns_domain "$PEERTUBE_DOMAIN_NAME"
827 825
 
828 826
     systemctl enable peertube
829 827
     systemctl daemon-reload

+ 283
- 272
src/freedombone-app-pelican Просмотреть файл

@@ -50,12 +50,12 @@ pelican_variables=(MY_USERNAME
50 50
                    PELICAN_BLOG_CODE)
51 51
 
52 52
 function pelican_remove_bad_blog_links {
53
-    find ./ -type f -name *.css -exec sed -i -e '/googleapi/d' {} \;
54
-    find ./ -type f -name *.scss -exec sed -i -e '/googleapi/d' {} \;
55
-    find ./ -type f -name *.html -exec sed -i -e '/googleapi/d' {} \;
56
-    find ./ -type f -name *.css -exec sed -i -e '/bootstrapcdn/d' {} \;
57
-    find ./ -type f -name *.scss -exec sed -i -e '/bootstrapcdn/d' {} \;
58
-    find ./ -type f -name *.html -exec sed -i -e '/bootstrapcdn/d' {} \;
53
+    find ./ -type f -name "*.css" -exec sed -i -e '/googleapi/d' {} \;
54
+    find ./ -type f -name "*.scss" -exec sed -i -e '/googleapi/d' {} \;
55
+    find ./ -type f -name "*.html" -exec sed -i -e '/googleapi/d' {} \;
56
+    find ./ -type f -name "*.css" -exec sed -i -e '/bootstrapcdn/d' {} \;
57
+    find ./ -type f -name "*.scss" -exec sed -i -e '/bootstrapcdn/d' {} \;
58
+    find ./ -type f -name "*.html" -exec sed -i -e '/bootstrapcdn/d' {} \;
59 59
 }
60 60
 
61 61
 function logging_on_pelican {
@@ -73,104 +73,104 @@ function install_pelican_website {
73 73
     fi
74 74
     function_check nginx_http_redirect
75 75
     nginx_http_redirect $PELICAN_DOMAIN_NAME
76
-    echo 'server {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
77
-    echo '    listen 443 ssl;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
78
-    echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
79
-    echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
80
-    echo "    server_name ${PELICAN_DOMAIN_NAME};" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
81
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
82
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
83
-    echo '    index index.html;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
84
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
76
+    { echo 'server {';
77
+      echo '    listen 443 ssl;';
78
+      echo '    #listen [::]:443 ssl;';
79
+      echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
80
+      echo "    server_name ${PELICAN_DOMAIN_NAME};";
81
+      echo '    access_log /dev/null;';
82
+      echo "    error_log /dev/null;";
83
+      echo '    index index.html;';
84
+      echo '    charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
85 85
     function_check nginx_ssl
86
-    nginx_ssl $PELICAN_DOMAIN_NAME
86
+    nginx_ssl "$PELICAN_DOMAIN_NAME"
87 87
     function_check nginx_disable_sniffing
88
-    nginx_disable_sniffing $PELICAN_DOMAIN_NAME
89
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
90
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
91
-    echo '    location / {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
88
+    nginx_disable_sniffing "$PELICAN_DOMAIN_NAME"
89
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
90
+      echo '';
91
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
92 92
     function_check nginx_limits
93
-    nginx_limits $PELICAN_DOMAIN_NAME
94
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
95
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
96
-    echo '    # block these file types' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
97
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
98
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
99
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
100
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
101
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
102
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
103
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
104
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
105
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
106
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
107
-    echo '      deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
108
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
109
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
110
-    echo '      deny  all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
111
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
112
-    echo '}' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
113
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
93
+    nginx_limits "$PELICAN_DOMAIN_NAME"
94
+    { echo '    }';
95
+      echo '';
96
+      echo '    # block these file types';
97
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
98
+      echo '        deny all;';
99
+      echo '    }';
100
+      echo '';
101
+      echo '    # deny access to all dot files';
102
+      echo '    location ~ /\. {';
103
+      echo '        deny all;';
104
+      echo '    }';
105
+      echo '';
106
+      echo '    location ~ /(data|conf|bin|inc)/ {';
107
+      echo '      deny all;';
108
+      echo '    }';
109
+      echo '    location ~ /\.ht {';
110
+      echo '      deny  all;';
111
+      echo '    }';
112
+      echo '}';
113
+      echo ''; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
114 114
 
115 115
     function_check create_site_certificate
116
-    create_site_certificate $PELICAN_DOMAIN_NAME 'yes'
116
+    create_site_certificate "$PELICAN_DOMAIN_NAME" 'yes'
117 117
 }
118 118
 
119 119
 function install_pelican_website_onion {
120
-    echo 'server {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
121
-    echo "    listen 127.0.0.1:${PELICAN_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
122
-    echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
123
-    echo "    server_name ${PELICAN_DOMAIN_NAME};" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
124
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
125
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
126
-    echo '    index index.html;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
127
-    echo '    charset utf-8;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
120
+    { echo 'server {';
121
+      echo "    listen 127.0.0.1:${PELICAN_ONION_PORT} default_server;";
122
+      echo "    root /var/www/${PELICAN_DOMAIN_NAME}/htdocs;";
123
+      echo "    server_name ${PELICAN_DOMAIN_NAME};";
124
+      echo '    access_log /dev/null;';
125
+      echo "    error_log /dev/null;";
126
+      echo '    index index.html;';
127
+      echo '    charset utf-8;'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
128 128
     function_check nginx_disable_sniffing
129
-    nginx_disable_sniffing $PELICAN_DOMAIN_NAME
130
-    echo '    add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
131
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
132
-    echo '    location / {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
129
+    nginx_disable_sniffing "$PELICAN_DOMAIN_NAME"
130
+    { echo '    add_header Strict-Transport-Security "max-age=0;";';
131
+      echo '';
132
+      echo '    location / {'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
133 133
     function_check nginx_limits
134
-    nginx_limits $PELICAN_DOMAIN_NAME
135
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
136
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
137
-    echo '    # block these file types' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
138
-    echo '    location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
139
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
140
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
141
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
142
-    echo '    # deny access to all dot files' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
143
-    echo '    location ~ /\. {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
144
-    echo '        deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
145
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
146
-    echo '' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
147
-    echo '    location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
148
-    echo '      deny all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
149
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
150
-    echo '    location ~ /\.ht {' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
151
-    echo '      deny  all;' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
152
-    echo '    }' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
153
-    echo '}' >> /etc/nginx/sites-available/$PELICAN_DOMAIN_NAME
134
+    nginx_limits "$PELICAN_DOMAIN_NAME"
135
+    { echo '    }';
136
+      echo '';
137
+      echo '    # block these file types';
138
+      echo '    location ~* \.(tpl|md|tgz|log|out)$ {';
139
+      echo '        deny all;';
140
+      echo '    }';
141
+      echo '';
142
+      echo '    # deny access to all dot files';
143
+      echo '    location ~ /\. {';
144
+      echo '        deny all;';
145
+      echo '    }';
146
+      echo '';
147
+      echo '    location ~ /(data|conf|bin|inc)/ {';
148
+      echo '      deny all;';
149
+      echo '    }';
150
+      echo '    location ~ /\.ht {';
151
+      echo '      deny  all;';
152
+      echo '    }';
153
+      echo '}'; } >> "/etc/nginx/sites-available/$PELICAN_DOMAIN_NAME"
154 154
 }
155 155
 
156 156
 function pelican_editor_config {
157 157
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican ]; then
158
-        echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)" > $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
159
-        echo '(setq org-support-shift-select t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
160
-        echo '(setq standard-indent 4)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
161
-        echo '(setq-default tab-width 4)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
162
-        echo '(setq c-basic-offset 4)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
163
-        echo '(mouse-wheel-mode t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
164
-        echo '(setq make-backup-files t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
165
-        echo '(setq version-control t)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
166
-        echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
167
-        echo "(setq default-major-mode 'text-mode)" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
168
-        echo "(dolist (hook '(text-mode-hook))" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
169
-        echo '    (add-hook hook (lambda () (flyspell-mode 1))))' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
170
-        echo '(setq-default fill-column 72)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
171
-        echo '(setq auto-fill-mode 0)' >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
172
-        echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
173
-        echo "(setq-default auto-fill-function 'do-auto-fill)" >> $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican
158
+        { echo "(add-hook 'before-save-hook 'delete-trailing-whitespace)";
159
+          echo '(setq org-support-shift-select t)';
160
+          echo '(setq standard-indent 4)';
161
+          echo '(setq-default tab-width 4)';
162
+          echo '(setq c-basic-offset 4)';
163
+          echo '(mouse-wheel-mode t)';
164
+          echo '(setq make-backup-files t)';
165
+          echo '(setq version-control t)';
166
+          echo '(setq backup-directory-alist (quote ((".*" . "~/.emacs_backups/"))))';
167
+          echo "(setq default-major-mode 'text-mode)";
168
+          echo "(dolist (hook '(text-mode-hook))";
169
+          echo '    (add-hook hook (lambda () (flyspell-mode 1))))';
170
+          echo '(setq-default fill-column 72)';
171
+          echo '(setq auto-fill-mode 0)';
172
+          echo "(add-hook 'text-mode-hook 'turn-on-auto-fill)";
173
+          echo "(setq-default auto-fill-function 'do-auto-fill)"; } > "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican"
174 174
     fi
175 175
 }
176 176
 
@@ -179,7 +179,7 @@ function pelican_regenerate_blog {
179 179
     echo ''
180 180
     echo $'Regenerating blog...'
181 181
 
182
-    cd $PELICAN_BLOG_INSTALL_DIR
182
+    cd "$PELICAN_BLOG_INSTALL_DIR" || exit 463856348
183 183
     make html
184 184
     cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
185 185
     chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
@@ -189,19 +189,19 @@ function pelican_new_blog {
189 189
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
190 190
 
191 191
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry ]; then
192
-        echo $'Title: Blog Post Title' > $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
193
-        echo $"Date: ${DATESTR}" >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
194
-        echo $"Author: $(toxid --showuser)" >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
195
-        echo $'Category: default' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
196
-        echo $'Tags: blog, tag' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
197
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
198
-        echo $'Add your text here' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
199
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
200
-        echo -n $'To include an image copy it into the /etc/blog/content/images directory, ' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
201
-        echo $'then link to it with:' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
202
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
203
-        echo $'![My image]({filename}images/myimage.jpg)' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
204
-        echo  '' >> $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
192
+        { echo $'Title: Blog Post Title';
193
+          echo $"Date: ${DATESTR}";
194
+          echo $"Author: $(toxid --showuser)";
195
+          echo $'Category: default';
196
+          echo $'Tags: blog, tag';
197
+          echo  '';
198
+          echo $'Add your text here';
199
+          echo  '';
200
+          echo -n $'To include an image copy it into the /etc/blog/content/images directory, ';
201
+          echo $'then link to it with:';
202
+          echo  '';
203
+          echo $'![My image]({filename}images/myimage.jpg)';
204
+          echo  ''; } > $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry
205 205
     fi
206 206
 
207 207
     if [ -f /usr/bin/emacs ]; then
@@ -222,7 +222,7 @@ function pelican_new_blog {
222 222
 
223 223
     # move to the content directory
224 224
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
225
-    mv $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry $BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md
225
+    mv "$PELICAN_BLOG_INSTALL_DIR/.new-blog-entry" "$BLOG_CONTENT_PATH/${CURRENT_INDEX}_post.md"
226 226
 
227 227
     # increment the index
228 228
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
@@ -238,14 +238,14 @@ function pelican_edit_blog {
238 238
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
239 239
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
240 240
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
241
-    if [ ! -f $LAST_BLOG_ENTRY ]; then
241
+    if [ ! -f "$LAST_BLOG_ENTRY" ]; then
242 242
         return
243 243
     fi
244 244
 
245 245
     if [ -f /usr/bin/emacs ]; then
246
-        emacs -q --load $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican $LAST_BLOG_ENTRY
246
+        emacs -q --load "$PELICAN_BLOG_INSTALL_DIR/.emacs-pelican" "$LAST_BLOG_ENTRY"
247 247
     else
248
-        editor $LAST_BLOG_ENTRY
248
+        editor "$LAST_BLOG_ENTRY"
249 249
     fi
250 250
 
251 251
     pelican_regenerate_blog
@@ -258,18 +258,18 @@ function pelican_delete_blog {
258 258
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
259 259
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
260 260
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
261
-    if [ ! -f $LAST_BLOG_ENTRY ]; then
261
+    if [ ! -f "$LAST_BLOG_ENTRY" ]; then
262 262
         return
263 263
     fi
264 264
 
265 265
     dialog --title $"Delete the previous blog entry" \
266 266
            --backtitle $"Freedombone Mesh" \
267 267
            --defaultno \
268
-           --yesno $"\nAre you sure that you wish to delete the previous blog entry?" 8 60
268
+           --yesno $"\\nAre you sure that you wish to delete the previous blog entry?" 8 60
269 269
     sel=$?
270 270
     case $sel in
271
-        0) rm $LAST_BLOG_ENTRY
272
-           if [ $CURRENT_INDEX -gt 0 ]; then
271
+        0) rm "$LAST_BLOG_ENTRY"
272
+           if [ "$CURRENT_INDEX" -gt 0 ]; then
273 273
                CURRENT_INDEX=$PREVIOUS_INDEX
274 274
                echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
275 275
            else
@@ -297,8 +297,8 @@ function pelican_change_theme {
297 297
     for a in "${THEMES[@]}"
298 298
     do
299 299
         is_selected='off'
300
-        if [ $curr_theme_index ]; then
301
-            if [ $n -eq $curr_theme_index ]; then
300
+        if [ "$curr_theme_index" ]; then
301
+            if [ $n -eq "$curr_theme_index" ]; then
302 302
                 is_selected='on'
303 303
             fi
304 304
         else
@@ -308,28 +308,30 @@ function pelican_change_theme {
308 308
         fi
309 309
 
310 310
         themelist="$themelist $n $a $is_selected"
311
-        n=$[n+1]
312
-        theme_index=$[theme_index+1]
311
+        n=$((n+1))
312
+        theme_index=$((theme_index+1))
313 313
     done
314 314
 
315
-    data=$(tempfile 2>/dev/null)
316
-    trap "rm -f $data" 0 1 2 5 15
315
+    data=$(mktemp 2>/dev/null)
317 316
     dialog --backtitle $"Freedombone Mesh" \
318 317
            --title $"Select Blog Theme" \
319 318
            --radiolist $'Choose:' \
320
-           80 40 20 $themelist 2> $data
319
+           80 40 20 "$themelist" 2> "$data"
321 320
     sel=$?
322 321
     case $sel in
323
-        1) return;;
324
-        255) return;;
322
+        1) rm -f "$data"
323
+           return;;
324
+        255) rm -f "$data"
325
+             return;;
325 326
     esac
326
-    CHOSEN_THEME_INDEX=$(cat $data)
327
+    CHOSEN_THEME_INDEX=$(cat "$data")
328
+    rm -f "$data"
327 329
     echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
328 330
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
329 331
 
330 332
     CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
331 333
 
332
-    cd $PELICAN_BLOG_INSTALL_DIR/themes/$CHOSEN_THEME
334
+    cd "$PELICAN_BLOG_INSTALL_DIR/themes/$CHOSEN_THEME" || exit 2648268284
333 335
     pelican_remove_bad_blog_links
334 336
 
335 337
     if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
@@ -341,8 +343,7 @@ function pelican_change_theme {
341 343
 }
342 344
 
343 345
 function configure_interactive_pelican {
344
-    data=$(tempfile 2>/dev/null)
345
-    trap "rm -f $data" 0 1 2 5 15
346
+    data=$(mktemp 2>/dev/null)
346 347
     dialog --backtitle $"Freedombone Configuration" \
347 348
            --title $"Pelican Blogging" \
348 349
            --radiolist $"Choose an operation:" 18 50 11 \
@@ -350,23 +351,25 @@ function configure_interactive_pelican {
350 351
            2 $"Edit the previous blog entry" off \
351 352
            3 $"Delete the previous blog entry" off \
352 353
            4 $"Change theme" off \
353
-           5 $"Exit" off 2> $data
354
+           5 $"Exit" off 2> "$data"
354 355
     sel=$?
355 356
     case $sel in
356
-        1) return;;
357
-        255) return;;
357
+        1) rm -f "$data"
358
+           return;;
359
+        255) rm -f "$data"
360
+             return;;
358 361
     esac
359
-    case $(cat $data) in
362
+    case $(cat "$data") in
360 363
         1) pelican_new_blog;;
361 364
         2) pelican_edit_blog;;
362 365
         3) pelican_delete_blog;;
363 366
         4) pelican_change_theme;;
364
-        5) break;;
365 367
     esac
368
+    rm -f "$data"
366 369
 }
367 370
 
368 371
 function install_interactive_pelican {
369
-    if [ ! $ONION_ONLY ]; then
372
+    if [ ! "$ONION_ONLY" ]; then
370 373
         ONION_ONLY='no'
371 374
     fi
372 375
 
@@ -376,42 +379,43 @@ function install_interactive_pelican {
376 379
         PELICAN_DETAILS_COMPLETE=
377 380
         while [ ! $PELICAN_DETAILS_COMPLETE ]
378 381
         do
379
-            data=$(tempfile 2>/dev/null)
380
-            trap "rm -f $data" 0 1 2 5 15
382
+            data=$(mktemp 2>/dev/null)
381 383
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
382 384
                 dialog --backtitle $"Freedombone Configuration" \
383 385
                        --title $"Pelican Blog Configuration" \
384
-                       --form $"\nPlease enter your blog details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
386
+                       --form $"\\nPlease enter your blog details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
385 387
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
386 388
                        $"Code:" 2 1 "$(grep 'PELICAN_BLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
387
-                       2> $data
389
+                       2> "$data"
388 390
             else
389 391
                 dialog --backtitle $"Freedombone Configuration" \
390 392
                        --title $"Pelican Blog Configuration" \
391
-                       --form $"\nPlease enter your GNU Social details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
393
+                       --form $"\\nPlease enter your GNU Social details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
392 394
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
393
-                       2> $data
395
+                       2> "$data"
394 396
             fi
395 397
             sel=$?
396 398
             case $sel in
397
-                1) exit 1;;
398
-                255) exit 1;;
399
+                1) rm -f "$data"
400
+                   exit 1;;
401
+                255) rm -f "$data"
402
+                     exit 1;;
399 403
             esac
400
-            PELICAN_DOMAIN_NAME=$(cat $data | sed -n 1p)
401
-            if [ $PELICAN_DOMAIN_NAME ]; then
404
+            PELICAN_DOMAIN_NAME=$(sed -n 1p < "$data")
405
+            if [ "$PELICAN_DOMAIN_NAME" ]; then
402 406
                 if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
403 407
                     PELICAN_DOMAIN_NAME=""
404 408
                 fi
405 409
                 TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
406 410
                 validate_domain_name
407
-                if [[ $TEST_DOMAIN_NAME != $PELICAN_DOMAIN_NAME ]]; then
411
+                if [[ "$TEST_DOMAIN_NAME" != "$PELICAN_DOMAIN_NAME" ]]; then
408 412
                     PELICAN_DOMAIN_NAME=
409 413
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
410 414
                 else
411 415
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
412
-                        PELICAN_BLOG_CODE=$(cat $data | sed -n 2p)
416
+                        PELICAN_BLOG_CODE=$(sed -n 2p < "$data")
413 417
                         validate_freedns_code "$PELICAN_BLOG_CODE"
414
-                        if [ ! $VALID_CODE ]; then
418
+                        if [ ! "$VALID_CODE" ]; then
415 419
                             PELICAN_DOMAIN_NAME=
416 420
                         fi
417 421
                     fi
@@ -420,6 +424,7 @@ function install_interactive_pelican {
420 424
             if [ $PELICAN_DOMAIN_NAME ]; then
421 425
                 PELICAN_DETAILS_COMPLETE="yes"
422 426
             fi
427
+            rm -f "$data"
423 428
         done
424 429
 
425 430
         # save the results in the config file
@@ -454,7 +459,7 @@ function backup_local_pelican {
454 459
 
455 460
 function restore_local_pelican {
456 461
     if [ -d /etc/blog ]; then
457
-        if [ -d $USB_MOUNT_DLNA/backup/pelican ]; then
462
+        if [ -d "$USB_MOUNT_DLNA/backup/pelican" ]; then
458 463
             temp_restore_dir=/root/temppelican
459 464
             function_check restore_directory_from_usb
460 465
             restore_directory_from_usb $temp_restore_dir pelican
@@ -463,6 +468,7 @@ function restore_local_pelican {
463 468
             else
464 469
                 cp -r $temp_restore_dir/* /etc/blog/
465 470
             fi
471
+            # shellcheck disable=SC2181
466 472
             if [ ! "$?" = "0" ]; then
467 473
                 rm -rf $temp_restore_dir
468 474
                 function_check set_user_permissions
@@ -475,7 +481,7 @@ function restore_local_pelican {
475 481
         fi
476 482
     fi
477 483
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
478
-        if [ -d $USB_MOUNT_DLNA/backup/pelican-site ]; then
484
+        if [ -d "$USB_MOUNT_DLNA/backup/pelican-site" ]; then
479 485
             temp_restore_dir=/root/temppelican-site
480 486
             function_check restore_directory_from_usb
481 487
             restore_directory_from_usb $temp_restore_dir pelican-site
@@ -484,6 +490,7 @@ function restore_local_pelican {
484 490
             else
485 491
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
486 492
             fi
493
+            # shellcheck disable=SC2181
487 494
             if [ ! "$?" = "0" ]; then
488 495
                 rm -rf $temp_restore_dir
489 496
                 function_check set_user_permissions
@@ -508,7 +515,7 @@ function backup_remote_pelican {
508 515
 
509 516
 function restore_remote_pelican {
510 517
     if [ -d /etc/blog ]; then
511
-        if [ -d $SERVER_DIRECTORY/backup/pelican ]; then
518
+        if [ -d "$SERVER_DIRECTORY/backup/pelican" ]; then
512 519
             temp_restore_dir=/root/temppelican
513 520
             function_check restore_directory_from_friend
514 521
             restore_directory_from_friend $temp_restore_dir pelican
@@ -517,6 +524,7 @@ function restore_remote_pelican {
517 524
             else
518 525
                 cp -r $temp_restore_dir/* /etc/blog/
519 526
             fi
527
+            # shellcheck disable=SC2181
520 528
             if [ ! "$?" = "0" ]; then
521 529
                 exit 782352
522 530
             fi
@@ -524,7 +532,7 @@ function restore_remote_pelican {
524 532
         fi
525 533
     fi
526 534
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
527
-        if [ -d $SERVER_DIRECTORY/backup/pelican-site ]; then
535
+        if [ -d "$SERVER_DIRECTORY/backup/pelican-site" ]; then
528 536
             temp_restore_dir=/root/temppelican-site
529 537
             function_check restore_directory_from_friend
530 538
             restore_directory_from_friend $temp_restore_dir pelican-site
@@ -533,6 +541,7 @@ function restore_remote_pelican {
533 541
             else
534 542
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
535 543
             fi
544
+            # shellcheck disable=SC2181
536 545
             if [ ! "$?" = "0" ]; then
537 546
                 exit 76382562
538 547
             fi
@@ -561,112 +570,112 @@ function remove_pelican {
561 570
 }
562 571
 
563 572
 function create_pelican_conf {
564
-    STATIC_BLOG_FILE=$1
565
-
566
-    echo '#!/usr/bin/env python' > $STATIC_BLOG_FILE
567
-    echo '# -*- coding: utf-8 -*- #' >> $STATIC_BLOG_FILE
568
-    echo 'from __future__ import unicode_literals' >> $STATIC_BLOG_FILE
569
-    echo '' >> $STATIC_BLOG_FILE
570
-    echo "AUTHOR=u\"$MY_USERNAME\"" >> $STATIC_BLOG_FILE
571
-    echo "SITENAME=u'$DEFAULT_BLOG_TITLE'" >> $STATIC_BLOG_FILE
572
-    echo "SITEURL=''" >> $STATIC_BLOG_FILE
573
-    echo "PATH='content'" >> $STATIC_BLOG_FILE
574
-    echo 'TIMEZONE=u"Europe/London"' >> $STATIC_BLOG_FILE
575
-    echo "DEFAULT_LANG=u'en'" >> $STATIC_BLOG_FILE
576
-    echo '' >> $STATIC_BLOG_FILE
577
-    echo 'FEED_ALL_ATOM=None' >> $STATIC_BLOG_FILE
578
-    echo 'CATEGORY_FEED_ATOM=None' >> $STATIC_BLOG_FILE
579
-    echo 'TRANSLATION_FEED_ATOM=None' >> $STATIC_BLOG_FILE
580
-    echo 'AUTHOR_FEED_ATOM=None' >> $STATIC_BLOG_FILE
581
-    echo 'AUTHOR_FEED_RSS=None' >> $STATIC_BLOG_FILE
582
-    echo '' >> $STATIC_BLOG_FILE
583
-    echo 'DEFAULT_PAGINATION=False' >> $STATIC_BLOG_FILE
584
-    echo 'RELATIVE_URLS=True' >> $STATIC_BLOG_FILE
585
-    echo "THEME='themes/nice-blog'" >> $STATIC_BLOG_FILE
573
+    STATIC_BLOG_FILE="$1"
574
+
575
+    { echo '#!/usr/bin/env python';
576
+      echo '# -*- coding: utf-8 -*- #';
577
+      echo 'from __future__ import unicode_literals';
578
+      echo '';
579
+      echo "AUTHOR=u\"$MY_USERNAME\"";
580
+      echo "SITENAME=u'$DEFAULT_BLOG_TITLE'";
581
+      echo "SITEURL=''";
582
+      echo "PATH='content'";
583
+      echo 'TIMEZONE=u"Europe/London"';
584
+      echo "DEFAULT_LANG=u'en'";
585
+      echo '';
586
+      echo 'FEED_ALL_ATOM=None';
587
+      echo 'CATEGORY_FEED_ATOM=None';
588
+      echo 'TRANSLATION_FEED_ATOM=None';
589
+      echo 'AUTHOR_FEED_ATOM=None';
590
+      echo 'AUTHOR_FEED_RSS=None';
591
+      echo '';
592
+      echo 'DEFAULT_PAGINATION=False';
593
+      echo 'RELATIVE_URLS=True';
594
+      echo "THEME='themes/nice-blog'"; } > "$STATIC_BLOG_FILE"
586 595
 }
587 596
 
588 597
 function create_pelican_makefile {
589
-    STATIC_BLOG_FILE=$1
590
-
591
-    echo 'PY?=python' > $STATIC_BLOG_FILE
592
-    echo 'PELICAN?=pelican' >> $STATIC_BLOG_FILE
593
-    echo 'PELICANOPTS=' >> $STATIC_BLOG_FILE
594
-    echo '' >> $STATIC_BLOG_FILE
595
-    echo 'BASEDIR=$(CURDIR)' >> $STATIC_BLOG_FILE
596
-    echo 'INPUTDIR=$(BASEDIR)/content' >> $STATIC_BLOG_FILE
597
-    echo "OUTPUTDIR=$PELICAN_BLOG_PATH" >> $STATIC_BLOG_FILE
598
-    echo 'CONFFILE=$(BASEDIR)/pelicanconf.py' >> $STATIC_BLOG_FILE
599
-    echo 'PUBLISHCONF=$(BASEDIR)/publishconf.py' >> $STATIC_BLOG_FILE
600
-    echo '' >> $STATIC_BLOG_FILE
601
-    echo 'DEBUG ?= 0' >> $STATIC_BLOG_FILE
602
-    echo 'ifeq ($(DEBUG), 1)' >> $STATIC_BLOG_FILE
603
-    echo -e '\tPELICANOPTS += -D' >> $STATIC_BLOG_FILE
604
-    echo 'endif' >> $STATIC_BLOG_FILE
605
-    echo '' >> $STATIC_BLOG_FILE
606
-    echo 'RELATIVE ?= 0' >> $STATIC_BLOG_FILE
607
-    echo 'ifeq ($(RELATIVE), 1)' >> $STATIC_BLOG_FILE
608
-    echo -e '\tPELICANOPTS += --relative-urls' >> $STATIC_BLOG_FILE
609
-    echo 'endif' >> $STATIC_BLOG_FILE
610
-    echo '' >> $STATIC_BLOG_FILE
611
-    echo 'html:' >> $STATIC_BLOG_FILE
612
-    echo -e '\t$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
613
-    echo '' >> $STATIC_BLOG_FILE
614
-    echo 'clean:' >> $STATIC_BLOG_FILE
615
-    echo -e '\t[ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)' >> $STATIC_BLOG_FILE
616
-    echo '' >> $STATIC_BLOG_FILE
617
-    echo 'regenerate:' >> $STATIC_BLOG_FILE
618
-    echo -e '\t$(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
619
-    echo '' >> $STATIC_BLOG_FILE
620
-    echo 'serve:' >> $STATIC_BLOG_FILE
621
-    echo 'ifdef PORT' >> $STATIC_BLOG_FILE
622
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT)' >> $STATIC_BLOG_FILE
623
-    echo 'else' >> $STATIC_BLOG_FILE
624
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server' >> $STATIC_BLOG_FILE
625
-    echo 'endif' >> $STATIC_BLOG_FILE
626
-    echo '' >> $STATIC_BLOG_FILE
627
-    echo 'serve-global:' >> $STATIC_BLOG_FILE
628
-    echo 'ifdef SERVER' >> $STATIC_BLOG_FILE
629
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER)' >> $STATIC_BLOG_FILE
630
-    echo 'else' >> $STATIC_BLOG_FILE
631
-    echo -e '\tcd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0' >> $STATIC_BLOG_FILE
632
-    echo 'endif' >> $STATIC_BLOG_FILE
633
-    echo '' >> $STATIC_BLOG_FILE
634
-    echo 'devserver:' >> $STATIC_BLOG_FILE
635
-    echo 'ifdef PORT' >> $STATIC_BLOG_FILE
636
-    echo -e '\t$(BASEDIR)/develop_server.sh restart $(PORT)' >> $STATIC_BLOG_FILE
637
-    echo 'else' >> $STATIC_BLOG_FILE
638
-    echo -e '\t$(BASEDIR)/develop_server.sh restart' >> $STATIC_BLOG_FILE
639
-    echo 'endif' >> $STATIC_BLOG_FILE
640
-    echo '' >> $STATIC_BLOG_FILE
641
-    echo 'stopserver:' >> $STATIC_BLOG_FILE
642
-    echo -e '\t$(BASEDIR)/develop_server.sh stop' >> $STATIC_BLOG_FILE
643
-    echo -e '\t@echo "Stopped Pelican and SimpleHTTPServer processes running in background."' >> $STATIC_BLOG_FILE
644
-    echo '' >> $STATIC_BLOG_FILE
645
-    echo 'publish:' >> $STATIC_BLOG_FILE
646
-    echo -e '\t$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)' >> $STATIC_BLOG_FILE
647
-    echo '' >> $STATIC_BLOG_FILE
648
-    echo '.PHONY: html clean regenerate serve serve-global devserver publish' >> $STATIC_BLOG_FILE
598
+    STATIC_BLOG_FILE="$1"
599
+
600
+    { echo 'PY?=python';
601
+      echo 'PELICAN?=pelican';
602
+      echo 'PELICANOPTS=';
603
+      echo '';
604
+      echo "BASEDIR=\$(CURDIR)";
605
+      echo "INPUTDIR=\$(BASEDIR)/content";
606
+      echo "OUTPUTDIR=$PELICAN_BLOG_PATH";
607
+      echo "CONFFILE=\$(BASEDIR)/pelicanconf.py";
608
+      echo "PUBLISHCONF=\$(BASEDIR)/publishconf.py";
609
+      echo '';
610
+      echo 'DEBUG ?= 0';
611
+      echo "ifeq (\$(DEBUG), 1)";
612
+      echo -e '\tPELICANOPTS += -D';
613
+      echo 'endif';
614
+      echo '';
615
+      echo 'RELATIVE ?= 0';
616
+      echo "ifeq (\$(RELATIVE), 1)";
617
+      echo -e '\tPELICANOPTS += --relative-urls';
618
+      echo 'endif';
619
+      echo '';
620
+      echo 'html:';
621
+      echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
622
+      echo '';
623
+      echo 'clean:';
624
+      echo -e "\\t[ ! -d \$(OUTPUTDIR) ] || rm -rf \$(OUTPUTDIR)";
625
+      echo '';
626
+      echo 'regenerate:';
627
+      echo -e "\\t\$(PELICAN) -r \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(CONFFILE) \$(PELICANOPTS)";
628
+      echo '';
629
+      echo 'serve:';
630
+      echo 'ifdef PORT';
631
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server \$(PORT)";
632
+      echo 'else';
633
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server";
634
+      echo 'endif';
635
+      echo '';
636
+      echo 'serve-global:';
637
+      echo 'ifdef SERVER';
638
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 \$(SERVER)";
639
+      echo 'else';
640
+      echo -e "\\tcd \$(OUTPUTDIR) && \$(PY) -m pelican.server 80 0.0.0.0";
641
+      echo 'endif';
642
+      echo '';
643
+      echo 'devserver:';
644
+      echo 'ifdef PORT';
645
+      echo -e "\\t\$(BASEDIR)/develop_server.sh restart \$(PORT)";
646
+      echo 'else';
647
+      echo -e "\\t\$(BASEDIR)/develop_server.sh restart";
648
+      echo 'endif';
649
+      echo '';
650
+      echo 'stopserver:';
651
+      echo -e "\\t\$(BASEDIR)/develop_server.sh stop";
652
+      echo -e '\t@echo "Stopped Pelican and SimpleHTTPServer processes running in background."';
653
+      echo '';
654
+      echo 'publish:';
655
+      echo -e "\\t\$(PELICAN) \$(INPUTDIR) -o \$(OUTPUTDIR) -s \$(PUBLISHCONF) \$(PELICANOPTS)";
656
+      echo '';
657
+      echo '.PHONY: html clean regenerate serve serve-global devserver publish'; } > "$STATIC_BLOG_FILE"
649 658
 }
650 659
 
651 660
 function create_pelican_publish_conf {
652 661
     STATIC_BLOG_FILE=$1
653 662
 
654
-    echo '#!/usr/bin/env python' > $STATIC_BLOG_FILE
655
-    echo '# -*- coding: utf-8 -*- #' >> $STATIC_BLOG_FILE
656
-    echo 'from __future__ import unicode_literals' >> $STATIC_BLOG_FILE
657
-    echo '' >> $STATIC_BLOG_FILE
658
-    echo 'import os' >> $STATIC_BLOG_FILE
659
-    echo 'import sys' >> $STATIC_BLOG_FILE
660
-    echo 'sys.path.append(os.curdir)' >> $STATIC_BLOG_FILE
661
-    echo 'from pelicanconf import *' >> $STATIC_BLOG_FILE
662
-    echo '' >> $STATIC_BLOG_FILE
663
-    echo "SITEURL = ''" >> $STATIC_BLOG_FILE
664
-    echo 'RELATIVE_URLS = True' >> $STATIC_BLOG_FILE
665
-    echo '' >> $STATIC_BLOG_FILE
666
-    echo "FEED_ALL_ATOM = 'feeds/all.atom.xml'" >> $STATIC_BLOG_FILE
667
-    echo "CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'" >> $STATIC_BLOG_FILE
668
-    echo '' >> $STATIC_BLOG_FILE
669
-    echo 'DELETE_OUTPUT_DIRECTORY = True' >> $STATIC_BLOG_FILE
663
+    { echo '#!/usr/bin/env python';
664
+      echo '# -*- coding: utf-8 -*- #';
665
+      echo 'from __future__ import unicode_literals';
666
+      echo '';
667
+      echo 'import os';
668
+      echo 'import sys';
669
+      echo 'sys.path.append(os.curdir)';
670
+      echo 'from pelicanconf import *';
671
+      echo '';
672
+      echo "SITEURL = ''";
673
+      echo 'RELATIVE_URLS = True';
674
+      echo '';
675
+      echo "FEED_ALL_ATOM = 'feeds/all.atom.xml'";
676
+      echo "CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'";
677
+      echo '';
678
+      echo 'DELETE_OUTPUT_DIRECTORY = True'; } > "$STATIC_BLOG_FILE"
670 679
 }
671 680
 
672 681
 function pelican_themes {
@@ -747,10 +756,12 @@ function pelican_themes {
747 756
 }
748 757
 
749 758
 function mesh_install_pelican {
750
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" && $VARIANT != "usb" ]]; then
759
+    # shellcheck disable=SC2153
760
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" && "$VARIANT" != "usb" ]]; then
751 761
         return
752 762
     fi
753 763
 
764
+    # shellcheck disable=SC2154
754 765
     chroot "$rootdir" apt-get -yq install python-pip
755 766
     chroot "$rootdir" pip install ipython
756 767
     chroot "$rootdir" pip install Markdown
@@ -760,34 +771,34 @@ function mesh_install_pelican {
760 771
     PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
761 772
     PELICAN_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
762 773
 
763
-    if [ ! -d $rootdir$PELICAN_BLOG_INSTALL_DIR ]; then
764
-        mkdir -p $rootdir$PELICAN_BLOG_INSTALL_DIR
774
+    if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR" ]; then
775
+        mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR"
765 776
     fi
766 777
 
767
-    if [ ! -d $rootdir$PELICAN_BLOG_PATH ]; then
768
-        mkdir -p $rootdir$PELICAN_BLOG_PATH
778
+    if [ ! -d "$rootdir$PELICAN_BLOG_PATH" ]; then
779
+        mkdir -p "$rootdir$PELICAN_BLOG_PATH"
769 780
     fi
770 781
 
771
-    if [ ! -d $rootdir$PELICAN_BLOG_INSTALL_DIR/content/images ]; then
772
-        mkdir -p $rootdir$PELICAN_BLOG_INSTALL_DIR/content/images
782
+    if [ ! -d "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images" ]; then
783
+        mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/content/images"
773 784
     fi
774 785
 
775
-    create_pelican_conf $rootdir$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
776
-    create_pelican_makefile $rootdir$PELICAN_BLOG_INSTALL_DIR/Makefile
777
-    create_pelican_publish_conf $rootdir$PELICAN_BLOG_INSTALL_DIR/publishconf.py
786
+    create_pelican_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
787
+    create_pelican_makefile "$rootdir$PELICAN_BLOG_INSTALL_DIR/Makefile"
788
+    create_pelican_publish_conf "$rootdir$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
778 789
 
779
-    mkdir -p $rootdir$PELICAN_BLOG_INSTALL_DIR/themes
780
-    cd $rootdir$PELICAN_BLOG_INSTALL_DIR/themes
790
+    mkdir -p "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes"
791
+    cd "$rootdir$PELICAN_BLOG_INSTALL_DIR/themes" || exit 74624524
781 792
     pelican_themes
782 793
 
783 794
     #git clone --recursive $PELICAN_PLUGINS_REPO $rootdir$PELICAN_BLOG_INSTALL_DIR/plugins
784 795
 
785
-    chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME $PELICAN_BLOG_INSTALL_DIR
786
-    chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Public
796
+    chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
797
+    chroot "$rootdir" chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/Public"
787 798
 }
788 799
 
789 800
 function install_pelican {
790
-    if [ $INSTALLING_MESH ]; then
801
+    if [ "$INSTALLING_MESH" ]; then
791 802
         mesh_install_pelican
792 803
         return
793 804
     fi
@@ -800,29 +811,29 @@ function install_pelican {
800 811
 
801 812
     PELICAN_BLOG_PATH=/var/www/$PELICAN_DOMAIN_NAME/htdocs
802 813
 
803
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR ]; then
804
-        mkdir -p $PELICAN_BLOG_INSTALL_DIR
814
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR" ]; then
815
+        mkdir -p "$PELICAN_BLOG_INSTALL_DIR"
805 816
     fi
806 817
 
807 818
     if [ ! -d $PELICAN_BLOG_PATH ]; then
808 819
         mkdir -p $PELICAN_BLOG_PATH
809 820
     fi
810 821
 
811
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR/content ]; then
812
-        mkdir -p $PELICAN_BLOG_INSTALL_DIR/content
822
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/content" ]; then
823
+        mkdir -p "$PELICAN_BLOG_INSTALL_DIR/content"
813 824
     fi
814 825
 
815
-    create_pelican_conf $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py
816
-    create_pelican_makefile $PELICAN_BLOG_INSTALL_DIR/Makefile
817
-    create_pelican_publish_conf $PELICAN_BLOG_INSTALL_DIR/publishconf.py
826
+    create_pelican_conf "$PELICAN_BLOG_INSTALL_DIR/pelicanconf.py"
827
+    create_pelican_makefile "$PELICAN_BLOG_INSTALL_DIR/Makefile"
828
+    create_pelican_publish_conf "$PELICAN_BLOG_INSTALL_DIR/publishconf.py"
818 829
 
819
-    mkdir -p $PELICAN_THEMES_REPO $PELICAN_BLOG_INSTALL_DIR/themes
820
-    cd $PELICAN_THEMES_REPO $PELICAN_BLOG_INSTALL_DIR/themes
830
+    mkdir -p "$PELICAN_THEMES_REPO" "$PELICAN_BLOG_INSTALL_DIR/themes"
831
+    cd "$PELICAN_BLOG_INSTALL_DIR/themes" || exit 45357282883
821 832
     pelican_themes
822 833
 
823 834
     #git clone --recursive $PELICAN_PLUGINS_REPO $PELICAN_BLOG_INSTALL_DIR/plugins
824 835
 
825
-    chown -R $MY_USERNAME:$MY_USERNAME $PELICAN_BLOG_INSTALL_DIR
836
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "$PELICAN_BLOG_INSTALL_DIR"
826 837
     chown -R www-data:www-data $PELICAN_BLOG_PATH
827 838
 
828 839
     pelican_editor_config
@@ -834,7 +845,7 @@ function install_pelican {
834 845
     install_pelican_website_onion
835 846
 
836 847
     pelican_regenerate_blog
837
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR/output ]; then
848
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/output" ]; then
838 849
         echo $'Failed to generate pelican blog'
839 850
         exit 521892
840 851
     fi

+ 54
- 48
src/freedombone-app-pihole Просмотреть файл

@@ -66,17 +66,17 @@ function pihole_copy_files {
66 66
     if [ ! -d /etc/.pihole ]; then
67 67
         mkdir /etc/.pihole
68 68
     fi
69
-    cp $INSTALL_DIR/pihole/adlists.default /etc/.pihole/adlists.default
70
-    cp $INSTALL_DIR/pihole/adlists.default $piholeDir/adlists.default
69
+    cp "$INSTALL_DIR/pihole/adlists.default" /etc/.pihole/adlists.default
70
+    cp "$INSTALL_DIR/pihole/adlists.default" $piholeDir/adlists.default
71 71
     if [ ! -f $PIHOLE_CUSTOM_ADLIST ]; then
72
-        cp $INSTALL_DIR/pihole/adlists.default $PIHOLE_CUSTOM_ADLIST
72
+        cp "$INSTALL_DIR/pihole/adlists.default" $PIHOLE_CUSTOM_ADLIST
73 73
     fi
74
-    cp $INSTALL_DIR/pihole/advanced/Scripts/* /opt/$piholeBasename
74
+    cp "$INSTALL_DIR/pihole/advanced/Scripts/*" /opt/$piholeBasename
75 75
     if [ -f /etc/dnsmasq.d/01-pihole.conf ]; then
76 76
         rm /etc/dnsmasq.d/01-pihole.conf
77 77
     fi
78
-    cp $INSTALL_DIR/pihole/advanced/pihole.cron /etc/cron.d/pihole
79
-    cp $INSTALL_DIR/pihole/gravity.sh /opt/$piholeBasename
78
+    cp "$INSTALL_DIR/pihole/advanced/pihole.cron" /etc/cron.d/pihole
79
+    cp "$INSTALL_DIR/pihole/gravity.sh" /opt/$piholeBasename
80 80
     chmod +x /opt/pihole/*.sh
81 81
 }
82 82
 
@@ -95,7 +95,7 @@ function pihole_update {
95 95
         return
96 96
     fi
97 97
 
98
-    if [ ! -f $HOME/${PROJECT_NAME}-wifi.cfg ]; then
98
+    if [ ! -f "$HOME/${PROJECT_NAME}-wifi.cfg" ]; then
99 99
         PIHOLE_IFACE=eth0
100 100
     else
101 101
         read_config_param WIFI_INTERFACE
@@ -114,13 +114,13 @@ function pihole_update {
114 114
     echo "piholeDNS1=${PIHOLE_DNS1}" >> ${setupVars}
115 115
     echo "piholeDNS2=${PIHOLE_DNS1}" >> ${setupVars}
116 116
 
117
-    echo 'domain-needed' > /etc/dnsmasq.conf
118
-    echo 'bogus-priv' >> /etc/dnsmasq.conf
119
-    echo 'no-resolv' >> /etc/dnsmasq.conf
120
-    echo "server=${PIHOLE_DNS1}" >> /etc/dnsmasq.conf
121
-    echo "server=${PIHOLE_DNS2}" >> /etc/dnsmasq.conf
122
-    echo "interface=${PIHOLE_IFACE}" >> /etc/dnsmasq.conf
123
-    echo 'listen-address=127.0.0.1' >> /etc/dnsmasq.conf
117
+    { echo 'domain-needed';
118
+      echo 'bogus-priv';
119
+      echo 'no-resolv';
120
+      echo "server=${PIHOLE_DNS1}";
121
+      echo "server=${PIHOLE_DNS2}";
122
+      echo "interface=${PIHOLE_IFACE}";
123
+      echo 'listen-address=127.0.0.1'; } > /etc/dnsmasq.conf
124 124
 
125 125
     pihole -g
126 126
     systemctl restart dnsmasq
@@ -132,8 +132,7 @@ function pihole_update {
132 132
 }
133 133
 
134 134
 function pihole_change_upstream_dns {
135
-    data=$(tempfile 2>/dev/null)
136
-    trap "rm -f $data" 0 1 2 5 15
135
+    data=$(mktemp 2>/dev/null)
137 136
     dialog --backtitle $"Ad Blocker Upstream DNS" \
138 137
            --radiolist $"Pick a domain name service (DNS):" 28 50 19 \
139 138
            1 $"Digital Courage" on \
@@ -154,13 +153,15 @@ function pihole_change_upstream_dns {
154 153
            16 $"DNS.Watch" off \
155 154
            17 $"uncensoreddns.org" off \
156 155
            18 $"Lorraine Data Network" off \
157
-           19 $"Google" off 2> $data
156
+           19 $"Google" off 2> "$data"
158 157
     sel=$?
159 158
     case $sel in
160
-        1) exit 1;;
161
-        255) exit 1;;
159
+        1) rm -f "$data"
160
+           exit 1;;
161
+        255) rm -f "$data"
162
+             exit 1;;
162 163
     esac
163
-    case $(cat $data) in
164
+    case $(cat "$data") in
164 165
         1) PIHOLE_DNS1='85.214.73.63'
165 166
            PIHOLE_DNS2='213.73.91.35'
166 167
            ;;
@@ -218,10 +219,12 @@ function pihole_change_upstream_dns {
218 219
         19) PIHOLE_DNS1='8.8.8.8'
219 220
             PIHOLE_DNS2='4.4.4.4'
220 221
             dialog --title $"WARNING" \
221
-                   --msgbox $"\nGoogle's main purpose for providing DNS resolvers is to spy upon people and know which sites they are visiting.\n\nThis is something to consider, and you should only really be using Google DNS as a last resort if other resolvers are unavailable." 12 60
222
+                   --msgbox $"\\nGoogle's main purpose for providing DNS resolvers is to spy upon people and know which sites they are visiting.\\n\\nThis is something to consider, and you should only really be using Google DNS as a last resort if other resolvers are unavailable." 12 60
222 223
             ;;
223
-        255) exit 1;;
224
+        255) rm -f "$data"
225
+             exit 1;;
224 226
     esac
227
+    rm -f "$data"
225 228
     write_config_param "PIHOLE_DNS1" "$PIHOLE_DNS1"
226 229
     write_config_param "PIHOLE_DNS2" "$PIHOLE_DNS2"
227 230
 }
@@ -252,8 +255,7 @@ function pihole_resume {
252 255
 function configure_interactive_pihole {
253 256
     while true
254 257
     do
255
-        data=$(tempfile 2>/dev/null)
256
-        trap "rm -f $data" 0 1 2 5 15
258
+        data=$(mktemp 2>/dev/null)
257 259
         dialog --backtitle $"Freedombone Control Panel" \
258 260
                --title $"Ad Blocker" \
259 261
                --radiolist $"Choose an operation:" 16 70 7 \
@@ -263,13 +265,15 @@ function configure_interactive_pihole {
263 265
                4 $"Change upstream DNS servers" off \
264 266
                5 $"Pause blocker" off \
265 267
                6 $"Resume blocker" off \
266
-               7 $"Exit" on 2> $data
268
+               7 $"Exit" on 2> "$data"
267 269
         sel=$?
268 270
         case $sel in
269
-            1) exit 1;;
270
-            255) exit 1;;
271
+            1) rm -f "$data"
272
+               exit 1;;
273
+            255) rm -f "$data"
274
+                 exit 1;;
271 275
         esac
272
-        case $(cat $data) in
276
+        case $(cat "$data") in
273 277
             1) editor $PIHOLE_CUSTOM_ADLIST
274 278
                update_pihole_interactive
275 279
                ;;
@@ -286,8 +290,10 @@ function configure_interactive_pihole {
286 290
                ;;
287 291
             6) pihole_resume
288 292
                ;;
289
-            7) break;;
293
+            7) rm -f "$data"
294
+               break;;
290 295
         esac
296
+        rm -f "$data"
291 297
     done
292 298
 }
293 299
 
@@ -306,7 +312,7 @@ function upgrade_pihole {
306 312
     fi
307 313
 
308 314
     function_check set_repo_commit
309
-    set_repo_commit $INSTALL_DIR/pihole "pihole commit" "$PIHOLE_COMMIT" $PIHOLE_REPO
315
+    set_repo_commit "$INSTALL_DIR/pihole" "pihole commit" "$PIHOLE_COMMIT" $PIHOLE_REPO
310 316
 
311 317
     pihole_copy_files
312 318
     pihole_update
@@ -367,8 +373,8 @@ function remove_pihole {
367 373
         rm /etc/cron.d/pihole
368 374
     fi
369 375
 
370
-    if [ -d $INSTALL_DIR/pihole ]; then
371
-        rm -rf $INSTALL_DIR/pihole
376
+    if [ -d "$INSTALL_DIR/pihole" ]; then
377
+        rm -rf "$INSTALL_DIR/pihole"
372 378
     fi
373 379
 
374 380
     firewall_remove 53
@@ -391,27 +397,27 @@ function install_pihole {
391 397
 
392 398
     systemctl enable dnsmasq
393 399
 
394
-    if [ ! -d $INSTALL_DIR ]; then
395
-        mkdir -p $INSTALL_DIR
400
+    if [ ! -d "$INSTALL_DIR" ]; then
401
+        mkdir -p "$INSTALL_DIR"
396 402
     fi
397 403
 
398
-    if [ ! -d $INSTALL_DIR/pihole ]; then
399
-        cd $INSTALL_DIR
404
+    if [ ! -d "$INSTALL_DIR/pihole" ]; then
405
+        cd "$INSTALL_DIR" || exit 78245624527
400 406
 
401 407
         if [ -d /repos/pihole ]; then
402 408
             mkdir pihole
403 409
             cp -r -p /repos/pihole/. pihole
404
-            cd pihole
410
+            cd pihole || exit 24572424684
405 411
             git pull
406 412
         else
407 413
             git_clone $PIHOLE_REPO pihole
408 414
         fi
409 415
 
410
-        if [ ! -d $INSTALL_DIR/pihole ]; then
416
+        if [ ! -d "$INSTALL_DIR/pihole" ]; then
411 417
             exit 523925
412 418
         fi
413
-        cd $INSTALL_DIR/pihole
414
-        git checkout $PIHOLE_COMMIT -b $PIHOLE_COMMIT
419
+        cd "$INSTALL_DIR/pihole" || exit 2682468242
420
+        git checkout "$PIHOLE_COMMIT" -b "$PIHOLE_COMMIT"
415 421
         set_completion_param "pihole commit" "$PIHOLE_COMMIT"
416 422
     fi
417 423
 
@@ -420,21 +426,21 @@ function install_pihole {
420 426
     fi
421 427
 
422 428
     # blank file which takes the place of ads
423
-    echo '<html>' > /var/www/pihole/htdocs/index.html
424
-    echo '<body>' >> /var/www/pihole/htdocs/index.html
425
-    echo '</body>' >> /var/www/pihole/htdocs/index.html
426
-    echo '</html>' >> /var/www/pihole/htdocs/index.html
429
+    { echo '<html>';
430
+      echo '<body>';
431
+      echo '</body>';
432
+      echo '</html>'; } > /var/www/pihole/htdocs/index.html
427 433
 
428
-    if [ ! -f $INSTALL_DIR/pihole/gravity.sh ]; then
434
+    if [ ! -f "$INSTALL_DIR/pihole/gravity.sh" ]; then
429 435
         exit 26738
430 436
     fi
431
-    cp $INSTALL_DIR/pihole/gravity.sh /usr/local/bin/gravity.sh
437
+    cp "$INSTALL_DIR/pihole/gravity.sh" /usr/local/bin/gravity.sh
432 438
     chmod 755 /usr/local/bin/gravity.sh
433 439
 
434
-    if [ ! -f $INSTALL_DIR/pihole/pihole ]; then
440
+    if [ ! -f "$INSTALL_DIR/pihole/pihole" ]; then
435 441
         exit 52935
436 442
     fi
437
-    cp $INSTALL_DIR/pihole/pihole /usr/local/bin/pihole
443
+    cp "$INSTALL_DIR/pihole/pihole" /usr/local/bin/pihole
438 444
     chmod 755 /usr/local/bin/pihole
439 445
 
440 446
     if [ ! -d $piholeDir ]; then

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


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


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

@@ -56,7 +56,7 @@ function secure_privatebin {
56 56
     find "${pbpath}/" -type d -print0 | xargs -0 chmod 0550
57 57
 
58 58
     chown -R ${rootuser}:${htgroup} "${pbpath}/"
59
-    chown -R www-data:www-data ${pbdata}
59
+    chown -R www-data:www-data "${pbdata}"
60 60
 }
61 61
 
62 62
 function logging_on_privatebin {
@@ -68,63 +68,65 @@ function logging_off_privatebin {
68 68
 }
69 69
 
70 70
 function remove_user_privatebin {
71
-    remove_username="$1"
71
+    echo -n ''
72
+#    remove_username="$1"
72 73
 }
73 74
 
74 75
 function add_user_privatebin {
75
-    new_username="$1"
76
-    new_user_password="$2"
76
+#    new_username="$1"
77
+#    new_user_password="$2"
77 78
 
78 79
     echo '0'
79 80
 }
80 81
 
81 82
 function install_interactive_privatebin {
82
-    if [ ! $ONION_ONLY ]; then
83
+    if [ ! "$ONION_ONLY" ]; then
83 84
         ONION_ONLY='no'
84 85
     fi
85 86
 
86
-    if [[ $ONION_ONLY != "no" ]]; then
87
+    if [[ "$ONION_ONLY" != "no" ]]; then
87 88
         PRIVATEBIN_DOMAIN_NAME='privatebin.local'
88 89
     else
89 90
         PRIVATEBIN_DETAILS_COMPLETE=
90 91
         while [ ! $PRIVATEBIN_DETAILS_COMPLETE ]
91 92
         do
92
-            data=$(tempfile 2>/dev/null)
93
-            trap "rm -f $data" 0 1 2 5 15
93
+            data=$(mktemp 2>/dev/null)
94 94
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
95 95
                 dialog --backtitle $"Freedombone Configuration" \
96 96
                        --title $"PrivateBin Configuration" \
97
-                       --form $"\nPlease enter your PrivateBin details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
97
+                       --form $"\\nPlease enter your PrivateBin details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
98 98
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
99 99
                        $"Code:" 2 1 "$(grep 'PRIVATEBIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
100
-                       2> $data
100
+                       2> "$data"
101 101
             else
102 102
                 dialog --backtitle $"Freedombone Configuration" \
103 103
                        --title $"PrivateBin Configuration" \
104
-                       --form $"\nPlease enter your PrivateBin details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
104
+                       --form $"\\nPlease enter your PrivateBin details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
105 105
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
106
-                       2> $data
106
+                       2> "$data"
107 107
             fi
108 108
             sel=$?
109 109
             case $sel in
110
-                1) exit 1;;
111
-                255) exit 1;;
110
+                1) rm -f "$data"
111
+                   exit 1;;
112
+                255) rm -f "$data"
113
+                     exit 1;;
112 114
             esac
113
-            PRIVATEBIN_DOMAIN_NAME=$(cat $data | sed -n 1p)
114
-            if [ $PRIVATEBIN_DOMAIN_NAME ]; then
115
-                if [[ $PRIVATEBIN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
115
+            PRIVATEBIN_DOMAIN_NAME=$(sed -n 1p < "$data")
116
+            if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
117
+                if [[ "$PRIVATEBIN_DOMAIN_NAME" == "$HUBZILLA_DOMAIN_NAME" ]]; then
116 118
                     PRIVATEBIN_DOMAIN_NAME=""
117 119
                 fi
118 120
                 TEST_DOMAIN_NAME=$PRIVATEBIN_DOMAIN_NAME
119 121
                 validate_domain_name
120
-                if [[ $TEST_DOMAIN_NAME != $PRIVATEBIN_DOMAIN_NAME ]]; then
122
+                if [[ "$TEST_DOMAIN_NAME" != "$PRIVATEBIN_DOMAIN_NAME" ]]; then
121 123
                     PRIVATEBIN_DOMAIN_NAME=
122 124
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
123 125
                 else
124 126
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
125
-                        PRIVATEBIN_CODE=$(cat $data | sed -n 2p)
127
+                        PRIVATEBIN_CODE=$(sed -n 2p < "$data")
126 128
                         validate_freedns_code "$PRIVATEBIN_CODE"
127
-                        if [ ! $VALID_CODE ]; then
129
+                        if [ ! "$VALID_CODE" ]; then
128 130
                             PRIVATEBIN_DOMAIN_NAME=
129 131
                         fi
130 132
                     fi
@@ -133,6 +135,7 @@ function install_interactive_privatebin {
133 135
             if [ $PRIVATEBIN_DOMAIN_NAME ]; then
134 136
                 PRIVATEBIN_DETAILS_COMPLETE="yes"
135 137
             fi
138
+            rm -f "$data"
136 139
         done
137 140
 
138 141
         write_config_param "PRIVATEBIN_CODE" "$PRIVATEBIN_CODE"
@@ -142,8 +145,9 @@ function install_interactive_privatebin {
142 145
 }
143 146
 
144 147
 function change_password_privatebin {
145
-    curr_username="$1"
146
-    new_user_password="$2"
148
+#    curr_username="$1"
149
+#    new_user_password="$2"
150
+    echo -n ''
147 151
 }
148 152
 
149 153
 function reconfigure_privatebin {
@@ -156,13 +160,13 @@ function upgrade_privatebin {
156 160
         return
157 161
     fi
158 162
 
159
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
163
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
160 164
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
161 165
     fi
162 166
 
163 167
     # update to the next commit
164 168
     function_check set_repo_commit
165
-    set_repo_commit /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs "privatebin commit" "$PRIVATEBIN_COMMIT" $PRIVATEBIN_REPO
169
+    set_repo_commit "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" "privatebin commit" "$PRIVATEBIN_COMMIT" "$PRIVATEBIN_REPO"
166 170
 
167 171
     secure_privatebin
168 172
 }
@@ -170,40 +174,40 @@ function upgrade_privatebin {
170 174
 
171 175
 function backup_local_privatebin {
172 176
     PRIVATEBIN_DOMAIN_NAME='privatebin'
173
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
177
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
174 178
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
175 179
     fi
176 180
 
177
-    source_directory=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
181
+    source_directory="/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data"
178 182
 
179 183
     function_check suspend_site
180
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
184
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
181 185
 
182 186
     function_check backup_directory_to_usb
183 187
     dest_directory=privatebin
184
-    backup_directory_to_usb $source_directory $dest_directory
188
+    backup_directory_to_usb "$source_directory" "$dest_directory"
185 189
 
186 190
     function_check restart_site
187 191
     restart_site
188 192
 }
189 193
 
190 194
 function restore_local_privatebin {
191
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
195
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
192 196
         return
193 197
     fi
194 198
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
195
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
199
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
196 200
         echo $"Restoring privatebin"
197 201
         temp_restore_dir=/root/tempprivatebin
198
-        privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
202
+        privatebin_dir="/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data"
199 203
 
200 204
         function_check restore_directory_from_usb
201 205
         restore_directory_from_usb $temp_restore_dir privatebin
202 206
         if [ -d $temp_restore_dir ]; then
203
-            if [ -d cp $temp_restore_dir$privatebin_dir ]; then
204
-                cp -rp $temp_restore_dir$privatebin_dir/* $privatebin_dir/
207
+            if [ -d "$temp_restore_dir$privatebin_dir" ]; then
208
+                cp -rp "$temp_restore_dir$privatebin_dir/*" "$privatebin_dir/"
205 209
             else
206
-                cp -rp $temp_restore_dir/* $privatebin_dir/
210
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
207 211
             fi
208 212
             secure_privatebin
209 213
             rm -rf $temp_restore_dir
@@ -215,39 +219,39 @@ function restore_local_privatebin {
215 219
 
216 220
 function backup_remote_privatebin {
217 221
     PRIVATEBIN_DOMAIN_NAME='privatebin'
218
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
222
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
219 223
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
220 224
     fi
221 225
 
222
-    source_directory=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
226
+    source_directory="/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data"
223 227
 
224 228
     function_check suspend_site
225
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
229
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
226 230
 
227 231
     function_check backup_directory_to_friend
228 232
     dest_directory=privatebin
229
-    backup_directory_to_friend $source_directory $dest_directory
233
+    backup_directory_to_friend "$source_directory" "$dest_directory"
230 234
 
231 235
     function_check restart_site
232 236
     restart_site
233 237
 }
234 238
 
235 239
 function restore_remote_privatebin {
236
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
240
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
237 241
         return
238 242
     fi
239 243
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
240
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
244
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
241 245
         temp_restore_dir=/root/tempprivatebin
242 246
         privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
243 247
 
244 248
         function_check restore_directory_from_friend
245 249
         restore_directory_from_friend $temp_restore_dir privatebin
246 250
         if [ -d $temp_restore_dir ]; then
247
-            if [ -d cp $temp_restore_dir$privatebin_dir ]; then
248
-                cp -rp $temp_restore_dir$privatebin_dir/* $privatebin_dir/
251
+            if [ -d "$temp_restore_dir$privatebin_dir" ]; then
252
+                cp -rp "$temp_restore_dir$privatebin_dir/*" "$privatebin_dir/"
249 253
             else
250
-                cp -rp $temp_restore_dir/* $privatebin_dir/
254
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
251 255
             fi
252 256
             secure_privatebin
253 257
             rm -rf $temp_restore_dir
@@ -262,14 +266,14 @@ function remove_privatebin {
262 266
     read_config_param "PRIVATEBIN_DOMAIN_NAME"
263 267
     read_config_param "MY_USERNAME"
264 268
     echo "Removing $PRIVATEBIN_DOMAIN_NAME"
265
-    nginx_dissite $PRIVATEBIN_DOMAIN_NAME
266
-    remove_certs $PRIVATEBIN_DOMAIN_NAME
269
+    nginx_dissite "$PRIVATEBIN_DOMAIN_NAME"
270
+    remove_certs "$PRIVATEBIN_DOMAIN_NAME"
267 271
 
268
-    if [ -d /var/www/$PRIVATEBIN_DOMAIN_NAME ]; then
269
-        rm -rf /var/www/$PRIVATEBIN_DOMAIN_NAME
272
+    if [ -d "/var/www/$PRIVATEBIN_DOMAIN_NAME" ]; then
273
+        rm -rf "/var/www/$PRIVATEBIN_DOMAIN_NAME"
270 274
     fi
271
-    if [ -f /etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME ]; then
272
-        rm /etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
275
+    if [ -f "/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME" ]; then
276
+        rm "/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME"
273 277
     fi
274 278
     function_check remove_onion_service
275 279
     remove_onion_service privatebin ${PRIVATEBIN_ONION_PORT}
@@ -278,18 +282,18 @@ function remove_privatebin {
278 282
     fi
279 283
     remove_app privatebin
280 284
     remove_completion_param install_privatebin
281
-    sed -i '/privatebin/d' $COMPLETION_FILE
285
+    sed -i '/privatebin/d' "$COMPLETION_FILE"
282 286
 
283 287
     function_check remove_ddns_domain
284
-    remove_ddns_domain $PRIVATEBIN_DOMAIN_NAME
288
+    remove_ddns_domain "$PRIVATEBIN_DOMAIN_NAME"
285 289
 }
286 290
 
287 291
 function install_privatebin {
288
-    if [ ! $ONION_ONLY ]; then
292
+    if [ ! "$ONION_ONLY" ]; then
289 293
         ONION_ONLY='no'
290 294
     fi
291 295
 
292
-    if [ ! $PRIVATEBIN_DOMAIN_NAME ]; then
296
+    if [ ! "$PRIVATEBIN_DOMAIN_NAME" ]; then
293 297
         echo $'No domain name was given for privatebin'
294 298
         exit 7359
295 299
     fi
@@ -298,153 +302,153 @@ function install_privatebin {
298 302
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
299 303
     apt-get -yq install php-libsodium libsodium18 php-mcrypt
300 304
 
301
-    if [ ! -d /var/www/$PRIVATEBIN_DOMAIN_NAME ]; then
302
-        mkdir /var/www/$PRIVATEBIN_DOMAIN_NAME
305
+    if [ ! -d "/var/www/$PRIVATEBIN_DOMAIN_NAME" ]; then
306
+        mkdir "/var/www/$PRIVATEBIN_DOMAIN_NAME"
303 307
     fi
304
-    if [ ! -d /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs ]; then
308
+    if [ ! -d "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" ]; then
305 309
 
306 310
         if [ -d /repos/privatebin ]; then
307
-            mkdir /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
308
-            cp -r -p /repos/privatebin/. /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
309
-            cd /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
311
+            mkdir "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
312
+            cp -r -p /repos/privatebin/. "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
313
+            cd "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" || exit 3468246824
310 314
             git pull
311 315
         else
312 316
             function_check git_clone
313
-            git_clone $PRIVATEBIN_REPO /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
317
+            git_clone "$PRIVATEBIN_REPO" "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
314 318
         fi
315 319
 
316
-        if [ ! -d /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs ]; then
320
+        if [ ! -d "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" ]; then
317 321
             echo $'Unable to clone privatebin repo'
318 322
             exit 63763873
319 323
         fi
320 324
     fi
321 325
 
322
-    cd /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
323
-    git checkout $PRIVATEBIN_COMMIT -b $PRIVATEBIN_COMMIT
326
+    cd "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs" || exit 24682462
327
+    git checkout "$PRIVATEBIN_COMMIT" -b "$PRIVATEBIN_COMMIT"
324 328
     set_completion_param "privatebin commit" "$PRIVATEBIN_COMMIT"
325 329
 
326
-    chmod g+w /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
327
-    chown -R www-data:www-data /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs
330
+    chmod g+w "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
331
+    chown -R www-data:www-data "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs"
328 332
 
329 333
     function_check add_ddns_domain
330
-    add_ddns_domain $PRIVATEBIN_DOMAIN_NAME
334
+    add_ddns_domain "$PRIVATEBIN_DOMAIN_NAME"
331 335
 
332 336
     PRIVATEBIN_ONION_HOSTNAME=$(add_onion_service privatebin 80 ${PRIVATEBIN_ONION_PORT})
333 337
 
334 338
     privatebin_nginx_site=/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
335 339
     if [[ $ONION_ONLY == "no" ]]; then
336 340
         function_check nginx_http_redirect
337
-        nginx_http_redirect $PRIVATEBIN_DOMAIN_NAME "index index.php"
338
-        echo 'server {' >> $privatebin_nginx_site
339
-        echo '  listen 443 ssl;' >> $privatebin_nginx_site
340
-        echo '  #listen [::]:443 ssl;' >> $privatebin_nginx_site
341
-        echo "  server_name $PRIVATEBIN_DOMAIN_NAME;" >> $privatebin_nginx_site
342
-        echo '' >> $privatebin_nginx_site
341
+        nginx_http_redirect "$PRIVATEBIN_DOMAIN_NAME" "index index.php"
342
+        { echo 'server {';
343
+          echo '  listen 443 ssl;';
344
+          echo '  #listen [::]:443 ssl;';
345
+          echo "  server_name $PRIVATEBIN_DOMAIN_NAME;";
346
+          echo ''; } >> "$privatebin_nginx_site"
343 347
         function_check nginx_compress
344
-        nginx_compress $PRIVATEBIN_DOMAIN_NAME
345
-        echo '' >> $privatebin_nginx_site
346
-        echo '  # Security' >> $privatebin_nginx_site
348
+        nginx_compress "$PRIVATEBIN_DOMAIN_NAME"
349
+        echo '' >> "$privatebin_nginx_site"
350
+        echo '  # Security' >> "$privatebin_nginx_site"
347 351
         function_check nginx_ssl
348
-        nginx_ssl $PRIVATEBIN_DOMAIN_NAME
352
+        nginx_ssl "$PRIVATEBIN_DOMAIN_NAME"
349 353
 
350 354
         function_check nginx_disable_sniffing
351
-        nginx_disable_sniffing $PRIVATEBIN_DOMAIN_NAME
352
-
353
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $privatebin_nginx_site
354
-        echo '' >> $privatebin_nginx_site
355
-        echo '  # Logs' >> $privatebin_nginx_site
356
-        echo '  access_log /dev/null;' >> $privatebin_nginx_site
357
-        echo '  error_log /dev/null;' >> $privatebin_nginx_site
358
-        echo '' >> $privatebin_nginx_site
359
-        echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;" >> $privatebin_nginx_site
360
-        echo '' >> $privatebin_nginx_site
361
-        echo '  index index.php;' >> $privatebin_nginx_site
362
-        echo '' >> $privatebin_nginx_site
363
-        echo '  location ~ \.php {' >> $privatebin_nginx_site
364
-        echo '    include snippets/fastcgi-php.conf;' >> $privatebin_nginx_site
365
-        echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $privatebin_nginx_site
366
-        echo '    fastcgi_read_timeout 30;' >> $privatebin_nginx_site
367
-        echo '  }' >> $privatebin_nginx_site
368
-        echo '' >> $privatebin_nginx_site
369
-        echo '  # Location' >> $privatebin_nginx_site
370
-        echo '  location / {' >> $privatebin_nginx_site
355
+        nginx_disable_sniffing "$PRIVATEBIN_DOMAIN_NAME"
356
+
357
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
358
+          echo '';
359
+          echo '  # Logs';
360
+          echo '  access_log /dev/null;';
361
+          echo '  error_log /dev/null;';
362
+          echo '';
363
+          echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;";
364
+          echo '';
365
+          echo '  index index.php;';
366
+          echo '';
367
+          echo '  location ~ \.php {';
368
+          echo '    include snippets/fastcgi-php.conf;';
369
+          echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
370
+          echo '    fastcgi_read_timeout 30;';
371
+          echo '  }';
372
+          echo '';
373
+          echo '  # Location';
374
+          echo '  location / {'; } >> "$privatebin_nginx_site"
371 375
         function_check nginx_limits
372
-        nginx_limits $PRIVATEBIN_DOMAIN_NAME '15m'
373
-        echo '    try_files $uri $uri/ @privatebin;' >> $privatebin_nginx_site
374
-        echo '  }' >> $privatebin_nginx_site
375
-        echo '' >> $privatebin_nginx_site
376
-        echo '  # Restrict access that is unnecessary anyway' >> $privatebin_nginx_site
377
-        echo '  location ~ /\.(ht|git) {' >> $privatebin_nginx_site
378
-        echo '    deny all;' >> $privatebin_nginx_site
379
-        echo '  }' >> $privatebin_nginx_site
380
-        echo '}' >> $privatebin_nginx_site
381
-        echo '' >> $privatebin_nginx_site
376
+        nginx_limits "$PRIVATEBIN_DOMAIN_NAME" '15m'
377
+        { echo "    try_files \$uri \$uri/ @privatebin;";
378
+          echo '  }';
379
+          echo '';
380
+          echo '  # Restrict access that is unnecessary anyway';
381
+          echo '  location ~ /\.(ht|git) {';
382
+          echo '    deny all;';
383
+          echo '  }';
384
+          echo '}';
385
+          echo ''; } >> "$privatebin_nginx_site"
382 386
     else
383
-        echo -n '' > $privatebin_nginx_site
387
+        echo -n '' > "$privatebin_nginx_site"
384 388
     fi
385
-    echo 'server {' >> $privatebin_nginx_site
386
-    echo "    listen 127.0.0.1:$PRIVATEBIN_ONION_PORT default_server;" >> $privatebin_nginx_site
387
-    echo "    server_name $PRIVATEBIN_ONION_HOSTNAME;" >> $privatebin_nginx_site
388
-    echo '' >> $privatebin_nginx_site
389
+    { echo 'server {';
390
+      echo "    listen 127.0.0.1:$PRIVATEBIN_ONION_PORT default_server;";
391
+      echo "    server_name $PRIVATEBIN_ONION_HOSTNAME;";
392
+      echo ''; } >> "$privatebin_nginx_site"
389 393
     function_check nginx_compress
390
-    nginx_compress $PRIVATEBIN_DOMAIN_NAME
391
-    echo '' >> $privatebin_nginx_site
394
+    nginx_compress "$PRIVATEBIN_DOMAIN_NAME"
395
+    echo '' >> "$privatebin_nginx_site"
392 396
     function_check nginx_disable_sniffing
393
-    nginx_disable_sniffing $PRIVATEBIN_DOMAIN_NAME
394
-    echo '' >> $privatebin_nginx_site
395
-    echo '  # Logs' >> $privatebin_nginx_site
396
-    echo '  access_log /dev/null;' >> $privatebin_nginx_site
397
-    echo '  error_log /dev/null;' >> $privatebin_nginx_site
398
-    echo '' >> $privatebin_nginx_site
399
-    echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;" >> $privatebin_nginx_site
400
-    echo '' >> $privatebin_nginx_site
401
-    echo '  index index.php;' >> $privatebin_nginx_site
402
-    echo '' >> $privatebin_nginx_site
403
-    echo '  location ~ \.php {' >> $privatebin_nginx_site
404
-    echo '    include snippets/fastcgi-php.conf;' >> $privatebin_nginx_site
405
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> $privatebin_nginx_site
406
-    echo '    fastcgi_read_timeout 30;' >> $privatebin_nginx_site
407
-    echo '  }' >> $privatebin_nginx_site
408
-    echo '' >> $privatebin_nginx_site
409
-    echo '  # Location' >> $privatebin_nginx_site
410
-    echo '  location / {' >> $privatebin_nginx_site
397
+    nginx_disable_sniffing "$PRIVATEBIN_DOMAIN_NAME"
398
+    { echo '';
399
+      echo '  # Logs';
400
+      echo '  access_log /dev/null;';
401
+      echo '  error_log /dev/null;';
402
+      echo '';
403
+      echo "  root /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs;";
404
+      echo '';
405
+      echo '  index index.php;';
406
+      echo '';
407
+      echo '  location ~ \.php {';
408
+      echo '    include snippets/fastcgi-php.conf;';
409
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
410
+      echo '    fastcgi_read_timeout 30;';
411
+      echo '  }';
412
+      echo '';
413
+      echo '  # Location';
414
+      echo '  location / {'; } >> "$privatebin_nginx_site"
411 415
     function_check nginx_limits
412
-    nginx_limits $PRIVATEBIN_DOMAIN_NAME '15m'
413
-    echo '    try_files $uri $uri/ @privatebin;' >> $privatebin_nginx_site
414
-    echo '  }' >> $privatebin_nginx_site
415
-    echo '' >> $privatebin_nginx_site
416
-    echo '  # Restrict access that is unnecessary anyway' >> $privatebin_nginx_site
417
-    echo '  location ~ /\.(ht|git) {' >> $privatebin_nginx_site
418
-    echo '    deny all;' >> $privatebin_nginx_site
419
-    echo '  }' >> $privatebin_nginx_site
420
-    echo '}' >> $privatebin_nginx_site
416
+    nginx_limits "$PRIVATEBIN_DOMAIN_NAME" '15m'
417
+    { echo "    try_files \$uri \$uri/ @privatebin;";
418
+      echo '  }';
419
+      echo '';
420
+      echo '  # Restrict access that is unnecessary anyway';
421
+      echo '  location ~ /\.(ht|git) {';
422
+      echo '    deny all;';
423
+      echo '  }';
424
+      echo '}'; } >> "$privatebin_nginx_site"
421 425
 
422 426
     function_check configure_php
423 427
     configure_php
424 428
 
425 429
     function_check create_site_certificate
426
-    create_site_certificate $PRIVATEBIN_DOMAIN_NAME 'yes'
430
+    create_site_certificate "$PRIVATEBIN_DOMAIN_NAME" 'yes'
427 431
 
428 432
     function_check nginx_ensite
429
-    nginx_ensite $PRIVATEBIN_DOMAIN_NAME
433
+    nginx_ensite "$PRIVATEBIN_DOMAIN_NAME"
430 434
 
431
-    cp /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.sample.php /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
435
+    cp "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.sample.php" "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
432 436
 
433 437
     # Change some defaults
434
-    sed -i 's|; qrcode|qrcode|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
435
-    sed -i 's|default =.*|default = "1day"|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
436
-    sed -i 's|languagedefault =.*|languagedefault = "en"|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
437
-    sed -i 's|1week =|; 1week =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
438
-    sed -i 's|1month =|; 1month =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
439
-    sed -i 's|1year =|; 1year =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
440
-    sed -i 's|never =|; never =|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
441
-    sed -i 's|limit = 10|limit = 30|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
442
-    sed -i 's|limit = 300|limit = 0|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
443
-    sed -i 's|batchsize =.*|batchsize = 100|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
444
-    sed -i 's|sizelimit =.*|sizelimit = 32768|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
445
-    sed -i 's|defaultformatter =.*|defaultformatter = "markdown"|g' /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php
446
-
447
-    mkdir -p /var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/data
438
+    sed -i 's|; qrcode|qrcode|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
439
+    sed -i 's|default =.*|default = "1day"|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
440
+    sed -i 's|languagedefault =.*|languagedefault = "en"|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
441
+    sed -i 's|1week =|; 1week =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
442
+    sed -i 's|1month =|; 1month =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
443
+    sed -i 's|1year =|; 1year =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
444
+    sed -i 's|never =|; never =|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
445
+    sed -i 's|limit = 10|limit = 30|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
446
+    sed -i 's|limit = 300|limit = 0|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
447
+    sed -i 's|batchsize =.*|batchsize = 100|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
448
+    sed -i 's|sizelimit =.*|sizelimit = 32768|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
449
+    sed -i 's|defaultformatter =.*|defaultformatter = "markdown"|g' "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/cfg/conf.php"
450
+
451
+    mkdir -p "/var/www/$PRIVATEBIN_DOMAIN_NAME/htdocs/data"
448 452
 
449 453
     secure_privatebin
450 454
 

+ 114
- 113
src/freedombone-app-profanity Просмотреть файл

@@ -57,12 +57,13 @@ function logging_off_profanity {
57 57
 }
58 58
 
59 59
 function remove_user_profanity {
60
-    remove_username="$1"
60
+    echo -n ''
61
+#    remove_username="$1"
61 62
 }
62 63
 
63 64
 function add_user_profanity {
64
-    new_username="$1"
65
-    new_user_password="$2"
65
+#    new_username="$1"
66
+#    new_user_password="$2"
66 67
 
67 68
     echo '0'
68 69
 }
@@ -82,19 +83,19 @@ function change_password_profanity {
82 83
 
83 84
     read_config_param DEFAULT_DOMAIN_NAME
84 85
 
85
-    ${PROJECT_NAME}-pass -u $curr_username -a xmpp -p "$new_user_password"
86
+    "${PROJECT_NAME}-pass" -u "$curr_username" -a xmpp -p "$new_user_password"
86 87
 
87 88
     # TODO: this is currently interactive. Really there needs to be a
88 89
     # non-interactive password change option for prosodyctl
89 90
     clear
90 91
     echo ''
91 92
     echo $'Currently Prosody requires password changes to be done interactively'
92
-    prosodyctl passwd ${curr_username}@${DEFAULT_DOMAIN_NAME}
93
+    prosodyctl passwd "${curr_username}@${DEFAULT_DOMAIN_NAME}"
93 94
 
94 95
     XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
95 96
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
96
-    if [ -f $XMPP_CLIENT_ACCOUNTS ]; then
97
-        sed -i "s|password=.*|password=$new_user_password|g" $XMPP_CLIENT_ACCOUNTS
97
+    if [ -f "$XMPP_CLIENT_ACCOUNTS" ]; then
98
+        sed -i "s|password=.*|password=$new_user_password|g" "$XMPP_CLIENT_ACCOUNTS"
98 99
     fi
99 100
 }
100 101
 
@@ -110,11 +111,11 @@ function upgrade_profanity {
110 111
 
111 112
     rm -rf /tmp/*
112 113
 
113
-    CURR_LIBMESODE_COMMIT=$(cat $COMPLETION_FILE | grep "libmesode commit" | awk -F ':' '{print $2}')
114
+    CURR_LIBMESODE_COMMIT=$(grep "libmesode commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
114 115
     if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
115 116
         function_check set_repo_commit
116
-        set_repo_commit $INSTALL_DIR/libmesode "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
117
-        cd $INSTALL_DIR/libmesode
117
+        set_repo_commit "$INSTALL_DIR/libmesode" "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
118
+        cd "$INSTALL_DIR/libmesode" || exit 42682682
118 119
         ./bootstrap.sh
119 120
         ./configure
120 121
         make
@@ -124,42 +125,42 @@ function upgrade_profanity {
124 125
 
125 126
     rm -rf /tmp/*
126 127
 
127
-    CURR_PROFANITY_COMMIT=$(cat $COMPLETION_FILE | grep "profanity commit" | awk -F ':' '{print $2}')
128
+    CURR_PROFANITY_COMMIT=$(grep "profanity commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
128 129
     if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
129 130
         function_check set_repo_commit
130
-        set_repo_commit $INSTALL_DIR/profanity "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
131
-        cd $INSTALL_DIR/profanity
131
+        set_repo_commit "$INSTALL_DIR/profanity" "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
132
+        cd "$INSTALL_DIR/profanity" || exit 248242684
132 133
         ./bootstrap.sh
133 134
         ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
134 135
         make
135 136
         make install
136 137
     fi
137 138
 
138
-    CURR_PROFANITY_OMEMO_PLUGIN_COMMIT=$(cat $COMPLETION_FILE | grep "profanity omemo plugin commit" | awk -F ':' '{print $2}')
139
+    CURR_PROFANITY_OMEMO_PLUGIN_COMMIT=$(grep "profanity omemo plugin commit" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
139 140
     if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
140 141
         # upgrade omemo plugins for all users
141
-        set_repo_commit $INSTALL_DIR/profanity-omemo-plugin "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
142
-        cd $INSTALL_DIR/profanity-omemo-plugin
143
-        sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
142
+        set_repo_commit "$INSTALL_DIR/profanity-omemo-plugin" "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
143
+        cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 2468246284
144
+        sed -i 's|python setup.py|python2.7 setup.py|g' "$INSTALL_DIR/profanity-omemo-plugin/install.sh"
144 145
         pip uninstall -y profanity-omemo-plugin
145 146
         ./install.sh
146 147
         for d in /home/*/ ; do
147 148
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
148 149
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
149
-                if [ ! -d /home/$USERNAME/.local/share/profanity/plugins ]; then
150
-                    mkdir -p /home/$USERNAME/.local/share/profanity/plugins
150
+                if [ ! -d "/home/$USERNAME/.local/share/profanity/plugins" ]; then
151
+                    mkdir -p "/home/$USERNAME/.local/share/profanity/plugins"
151 152
                 fi
152
-                if [ -f $INSTALL_DIR/profanity-omemo-plugin/omemo.py ]; then
153
-                    rm $INSTALL_DIR/profanity-omemo-plugin/omemo.*
153
+                if [ -f "$INSTALL_DIR/profanity-omemo-plugin/omemo.py" ]; then
154
+                    rm "$INSTALL_DIR/profanity-omemo-plugin/omemo.*"
154 155
                 fi
155
-                cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$USERNAME/.local/share/profanity/plugins
156
-                chown -R $USERNAME:$USERNAME /home/$USERNAME/.local
156
+                cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/home/$USERNAME/.local/share/profanity/plugins"
157
+                chown -R "$USERNAME":"$USERNAME" "/home/$USERNAME/.local"
157 158
             fi
158 159
         done
159 160
         if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
160 161
             rm /etc/skel/.local/share/profanity/plugins/omemo.*
161 162
         fi
162
-        cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
163
+        cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/etc/skel/.local/share/profanity/plugins"
163 164
     fi
164 165
 
165 166
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
@@ -183,11 +184,11 @@ function restore_remote_profanity {
183 184
 
184 185
 function remove_profanity {
185 186
     if [ -f /usr/local/bin/profanity ]; then
186
-        cd $INSTALL_DIR/profanity
187
+        cd "$INSTALL_DIR/profanity" || exit 4628462848
187 188
         make uninstall
188 189
 
189 190
         remove_completion_param install_profanity
190
-        sed -i '/profanity/d' $COMPLETION_FILE
191
+        sed -i '/profanity/d' "$COMPLETION_FILE"
191 192
     fi
192 193
 }
193 194
 
@@ -197,8 +198,8 @@ function install_profanity {
197 198
         return
198 199
     fi
199 200
     # install profanity from source in order to get OMEMO support
200
-    if [ ! -d $INSTALL_DIR ]; then
201
-        mkdir -p $INSTALL_DIR
201
+    if [ ! -d "$INSTALL_DIR" ]; then
202
+        mkdir -p "$INSTALL_DIR"
202 203
     fi
203 204
 
204 205
     apt-get -yq install automake autoconf autoconf-archive libtool build-essential
@@ -207,15 +208,15 @@ function install_profanity {
207 208
 
208 209
     # dependency for profanity not available in debian
209 210
     if [ -d /repos/libmesode ]; then
210
-        mkdir $INSTALL_DIR/libmesode
211
-        cp -r -p /repos/libmesode/. $INSTALL_DIR/libmesode
212
-        cd $INSTALL_DIR/libmesode
211
+        mkdir "$INSTALL_DIR/libmesode"
212
+        cp -r -p /repos/libmesode/. "$INSTALL_DIR/libmesode"
213
+        cd "$INSTALL_DIR/libmesode" || exit 46287642846872
213 214
         git pull
214 215
     else
215
-        git_clone $LIBMESODE_REPO $INSTALL_DIR/libmesode
216
+        git_clone "$LIBMESODE_REPO" "$INSTALL_DIR/libmesode"
216 217
     fi
217 218
 
218
-    cd $INSTALL_DIR/libmesode
219
+    cd "$INSTALL_DIR/libmesode" || exit 2468246284
219 220
     git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
220 221
     ./bootstrap.sh
221 222
     ./configure
@@ -225,15 +226,15 @@ function install_profanity {
225 226
 
226 227
     # build profanity
227 228
     if [ -d /repos/profanity ]; then
228
-        mkdir $INSTALL_DIR/profanity
229
-        cp -r -p /repos/profanity/. $INSTALL_DIR/profanity
230
-        cd $INSTALL_DIR/profanity
229
+        mkdir "$INSTALL_DIR/profanity"
230
+        cp -r -p /repos/profanity/. "$INSTALL_DIR/profanity"
231
+        cd "$INSTALL_DIR/profanity" || exit 2468246824
231 232
         git pull
232 233
     else
233
-        git_clone $PROFANITY_REPO $INSTALL_DIR/profanity
234
+        git_clone "$PROFANITY_REPO" "$INSTALL_DIR/profanity"
234 235
     fi
235 236
 
236
-    cd $INSTALL_DIR/profanity
237
+    cd "$INSTALL_DIR/profanity" || exit 54287452858
237 238
     git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
238 239
     ./bootstrap.sh
239 240
     ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
@@ -249,116 +250,116 @@ function install_profanity {
249 250
     apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev
250 251
 
251 252
     if [ -d /repos/profanity-omemo ]; then
252
-        mkdir $INSTALL_DIR/profanity-omemo-plugin
253
-        cp -r -p /repos/profanity-omemo/. $INSTALL_DIR/profanity-omemo-plugin
254
-        cd $INSTALL_DIR/profanity-omemo-plugin
253
+        mkdir "$INSTALL_DIR/profanity-omemo-plugin"
254
+        cp -r -p /repos/profanity-omemo/. "$INSTALL_DIR/profanity-omemo-plugin"
255
+        cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 24682462842
255 256
         git pull
256 257
     else
257
-        git_clone $PROFANITY_OMEMO_PLUGIN_REPO $INSTALL_DIR/profanity-omemo-plugin
258
+        git_clone "$PROFANITY_OMEMO_PLUGIN_REPO" "$INSTALL_DIR/profanity-omemo-plugin"
258 259
     fi
259 260
 
260
-    cd $INSTALL_DIR/profanity-omemo-plugin
261
+    cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 6428468248
261 262
     git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT
262
-    if [ ! -f $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py ]; then
263
+    if [ ! -f "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" ]; then
263 264
         echo $'prof_omemo_plugin.py not found'
264 265
         exit 389225
265 266
     fi
266
-    sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
267
+    sed -i 's|python setup.py|python2.7 setup.py|g' "$INSTALL_DIR/profanity-omemo-plugin/install.sh"
267 268
     ./install.sh
268 269
 
269 270
     mkdir -p /etc/skel/.local/share/profanity/plugins
270
-    cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
271
-    cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$MY_USERNAME/.local/share/profanity/plugins
272
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
271
+    cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" /etc/skel/.local/share/profanity/plugins
272
+    cp "$INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py" "/home/$MY_USERNAME/.local/share/profanity/plugins"
273
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.local"
273 274
 
274 275
     XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
275 276
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
276
-    if [ ! -d $XMPP_CLIENT_DIR ]; then
277
-        mkdir -p $XMPP_CLIENT_DIR
277
+    if [ ! -d "$XMPP_CLIENT_DIR" ]; then
278
+        mkdir -p "$XMPP_CLIENT_DIR"
278 279
     fi
279 280
 
280 281
     XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
281
-    MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME")
282
+    #MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$MY_USERNAME" "$MY_USERNAME@$DEFAULT_DOMAIN_NAME")
282 283
 
283 284
     if [[ $ONION_ONLY == 'no' ]]; then
284
-        echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
285
-        echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
286
-        echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
287
-        echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
288
-        # There is a bug where profanity doesn't refresh the screen
289
-        # after gpg-agent has asked for a password, so for now
290
-        # don't set the gpg key by default
291
-        #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
292
-        echo "pgp.keyid=" >> $XMPP_CLIENT_ACCOUNTS
293
-        echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
294
-        echo "muc.service=chat.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
295
-        echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
296
-        echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
297
-        echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
298
-        echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
299
-        echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
300
-        echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
301
-        echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
302
-        echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
285
+        { echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]";
286
+          echo 'enabled=true';
287
+          echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}";
288
+          echo "server=$XMPP_ONION_HOSTNAME";
289
+          # There is a bug where profanity doesn't refresh the screen
290
+          # after gpg-agent has asked for a password, so for now
291
+          # don't set the gpg key by default
292
+          #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID";
293
+          echo "pgp.keyid=";
294
+          echo 'resource=profanity';
295
+          echo "muc.service=chat.${DEFAULT_DOMAIN_NAME}";
296
+          echo "muc.nick=${MY_USERNAME}";
297
+          echo 'presence.last=online';
298
+          echo 'presence.login=online';
299
+          echo 'priority.online=0';
300
+          echo 'priority.chat=0';
301
+          echo 'priority.away=0';
302
+          echo 'priority.xa=0';
303
+          echo 'priority.dnd=0'; } > "$XMPP_CLIENT_ACCOUNTS"
303 304
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
304
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
305
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
305 306
         fi
306 307
     fi
307 308
 
308 309
     if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
309
-        echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
310
+        echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> "$XMPP_CLIENT_ACCOUNTS"
310 311
         if [[ $ONION_ONLY == 'no' ]]; then
311
-            echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
312
+            echo 'enabled=false' >> "$XMPP_CLIENT_ACCOUNTS"
312 313
         else
313
-            echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
314
+            echo 'enabled=true' >> "$XMPP_CLIENT_ACCOUNTS"
314 315
         fi
315
-        echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
316
-        echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
317
-        # There is a bug where profanity doesn't refresh the screen
318
-        # after gpg-agent has asked for a password, so for now
319
-        # don't set the gpg key by default
320
-        #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
321
-        echo "pgp.keyid=" >> $XMPP_CLIENT_ACCOUNTS
322
-        echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
323
-        echo "muc.service=${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
324
-        echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
325
-        echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
326
-        echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
327
-        echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
328
-        echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
329
-        echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
330
-        echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
331
-        echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
316
+        { echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}";
317
+          echo "server=$XMPP_ONION_HOSTNAME";
318
+          # There is a bug where profanity doesn't refresh the screen
319
+          # after gpg-agent has asked for a password, so for now
320
+          # don't set the gpg key by default
321
+          #echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID";
322
+          echo "pgp.keyid=";
323
+          echo 'resource=profanity';
324
+          echo "muc.service=${XMPP_ONION_HOSTNAME}";
325
+          echo "muc.nick=${MY_USERNAME}";
326
+          echo 'presence.last=online';
327
+          echo 'presence.login=online';
328
+          echo 'priority.online=0';
329
+          echo 'priority.chat=0';
330
+          echo 'priority.away=0';
331
+          echo 'priority.xa=0';
332
+          echo 'priority.dnd=0'; } >> "$XMPP_CLIENT_ACCOUNTS"
332 333
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
333
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
334
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
334 335
         fi
335 336
     fi
336 337
 
337
-    if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
338
-        mkdir -p /home/$MY_USERNAME/.config/profanity
338
+    if [ ! -d "/home/$MY_USERNAME/.config/profanity" ]; then
339
+        mkdir -p "/home/$MY_USERNAME/.config/profanity"
339 340
     fi
340
-    echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
341
+    echo '[connection]' > "/home/$MY_USERNAME/.config/profanity/profrc"
341 342
     if [[ $ONION_ONLY == 'no' ]]; then
342
-        echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
343
+        echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc"
343 344
     else
344
-        echo "account=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
345
+        echo "account=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> "/home/$MY_USERNAME/.config/profanity/profrc"
345 346
     fi
346
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
347
-    echo '[plugins]' >> /home/$MY_USERNAME/.config/profanity/profrc
348
-    echo 'load=prof_omemo_plugin.py;' >> /home/$MY_USERNAME/.config/profanity/profrc
349
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
350
-    echo '[otr]' >> /home/$MY_USERNAME/.config/profanity/profrc
351
-    echo 'policy=opportunistic' >> /home/$MY_USERNAME/.config/profanity/profrc
352
-    echo 'log=off' >> /home/$MY_USERNAME/.config/profanity/profrc
353
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
354
-    echo '[pgp]' >> /home/$MY_USERNAME/.config/profanity/profrc
355
-    echo 'log=off' >> /home/$MY_USERNAME/.config/profanity/profrc
356
-    echo '' >> /home/$MY_USERNAME/.config/profanity/profrc
357
-    echo '[ui]' >> /home/$MY_USERNAME/.config/profanity/profrc
358
-    echo 'enc.warn=true' >> /home/$MY_USERNAME/.config/profanity/profrc
359
-
360
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
361
-    chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
347
+    { echo '';
348
+      echo '[plugins]';
349
+      echo 'load=prof_omemo_plugin.py;';
350
+      echo '';
351
+      echo '[otr]';
352
+      echo 'policy=opportunistic';
353
+      echo 'log=off';
354
+      echo '';
355
+      echo '[pgp]';
356
+      echo 'log=off';
357
+      echo '';
358
+      echo '[ui]';
359
+      echo 'enc.warn=true'; } >> "/home/$MY_USERNAME/.config/profanity/profrc"
360
+
361
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.local"
362
+    chown -R "$MY_USERNAME":"$MY_USERNAME" "/home/$MY_USERNAME/.config"
362 363
 
363 364
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
364 365
     APP_INSTALLED=1

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

@@ -61,15 +61,15 @@ function logging_off_radicale {
61 61
 function remove_user_radicale {
62 62
     remove_username="$1"
63 63
 
64
-    ${PROJECT_NAME}-pass -u $remove_username --rmapp radicale
64
+    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp radicale
65 65
 
66 66
     if grep -q "${remove_username}:" ${RADICALE_USERS}; then
67 67
         sed -i "/${remove_username}:/d" ${RADICALE_USERS}
68
-        if [ -d /var/www/radicale/collections/${remove_username} ]; then
69
-            rm -rf /var/www/radicale/collections/${remove_username}
68
+        if [ -d "/var/www/radicale/collections/${remove_username}" ]; then
69
+            rm -rf "/var/www/radicale/collections/${remove_username}"
70 70
         fi
71
-        if [ -f /var/www/radicale/collections/${remove_username}.props ]; then
72
-            rm /var/www/radicale/collections/${remove_username}.props
71
+        if [ -f "/var/www/radicale/collections/${remove_username}.props" ]; then
72
+            rm "/var/www/radicale/collections/${remove_username}.props"
73 73
         fi
74 74
         systemctl restart radicale
75 75
     fi
@@ -79,7 +79,7 @@ function add_user_radicale {
79 79
     new_username="$1"
80 80
     new_user_password="$2"
81 81
 
82
-    ${PROJECT_NAME}-pass -u $new_username -a radicale -p "$new_user_password"
82
+    "${PROJECT_NAME}-pass" -u "$new_username" -a radicale -p "$new_user_password"
83 83
 
84 84
     if [ ! -f ${RADICALE_USERS} ]; then
85 85
         touch ${RADICALE_USERS}
@@ -88,13 +88,13 @@ function add_user_radicale {
88 88
     if ! grep -q "$new_username:" ${RADICALE_USERS}; then
89 89
         htpasswd -bd ${RADICALE_USERS} "$new_username" "$new_user_password"
90 90
 
91
-        echo '{"ICAL:calendar-color": "#9e50df"}' > /var/www/radicale/collections/${new_username}.props
92
-        mkdir /var/www/radicale/collections/${new_username}
93
-        echo '{"ICAL:calendar-color": "#de631a", "tag": "VCALENDAR"}' > /var/www/radicale/collections/${new_username}/calendar.props
94
-        echo 'BEGIN:VCALENDAR' > /var/www/radicale/collections/${new_username}/calendar
95
-        echo 'PRODID:-//Radicale//NONSGML Radicale Server//EN' >> /var/www/radicale/collections/${new_username}/calendar
96
-        echo 'VERSION:2.0' >> /var/www/radicale/collections/${new_username}/calendar
97
-        echo 'END:VCALENDAR' >> /var/www/radicale/collections/${new_username}/calendar
91
+        echo '{"ICAL:calendar-color": "#9e50df"}' > "/var/www/radicale/collections/${new_username}.props"
92
+        mkdir "/var/www/radicale/collections/${new_username}"
93
+        echo '{"ICAL:calendar-color": "#de631a", "tag": "VCALENDAR"}' > "/var/www/radicale/collections/${new_username}/calendar.props"
94
+        { echo 'BEGIN:VCALENDAR';
95
+          echo 'PRODID:-//Radicale//NONSGML Radicale Server//EN';
96
+          echo 'VERSION:2.0';
97
+          echo 'END:VCALENDAR'; } >> "/var/www/radicale/collections/${new_username}/calendar"
98 98
 
99 99
         chown -R www-data:www-data /var/www/radicale
100 100
         chmod -R 755 /var/www/radicale/*
@@ -107,7 +107,7 @@ function change_password_radicale {
107 107
     existing_username="$1"
108 108
     new_user_password="$2"
109 109
 
110
-    ${PROJECT_NAME}-pass -u $existing_username -a radicale -p "$new_user_password"
110
+    "${PROJECT_NAME}-pass" -u "$existing_username" -a radicale -p "$new_user_password"
111 111
 
112 112
     if grep -q "${existing_username}:" ${RADICALE_USERS}; then
113 113
         sed -i "/${existing_username}:/d" ${RADICALE_USERS}
@@ -127,14 +127,14 @@ function reconfigure_radicale {
127 127
     rm -rf /var/log/radicale/*
128 128
 
129 129
     # create an admin password
130
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
131
-        RADICALE_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
130
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
131
+        RADICALE_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
132 132
     else
133
-        RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
133
+        RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
134 134
     fi
135 135
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
136 136
 
137
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a radicale -p "$RADICALE_PASSWORD"
137
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a radicale -p "$RADICALE_PASSWORD"
138 138
 
139 139
     touch /var/log/radicale/radicale.log
140 140
     chown -R www-data:www-data /var/log/radicale
@@ -145,7 +145,7 @@ function upgrade_radicale {
145 145
         return
146 146
     fi
147 147
 
148
-    if ! grep -q "radicale version:" $COMPLETION_FILE; then
148
+    if ! grep -q "radicale version:" "$COMPLETION_FILE"; then
149 149
         return
150 150
     fi
151 151
 
@@ -155,7 +155,7 @@ function upgrade_radicale {
155 155
     fi
156 156
 
157 157
     # get the source
158
-    cd /var/www/radicale
158
+    cd /var/www/radicale || exit 62784628468
159 159
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
160 160
 
161 161
     # check the hash
@@ -170,7 +170,7 @@ function upgrade_radicale {
170 170
         exit 73529
171 171
     fi
172 172
     rm Radicale-${RADICALE_VERSION}.tar.gz
173
-    cd Radicale-${RADICALE_VERSION}
173
+    cd "Radicale-${RADICALE_VERSION}" || exit 264824684
174 174
 
175 175
     # move the old command
176 176
     mv /usr/local/bin/radicale /usr/local/bin/radicale_previous
@@ -186,9 +186,9 @@ function upgrade_radicale {
186 186
     fi
187 187
 
188 188
     # remove the old source
189
-    rm -rf Radicale-${CURR_RADICALE_VERSION}
189
+    rm -rf "Radicale-${CURR_RADICALE_VERSION}" || exit 6842684282
190 190
 
191
-    sed -i "s|radicale version.*|radicale version:$RADICALE_VERSION|g" ${COMPLETION_FILE}
191
+    sed -i "s|radicale version.*|radicale version:$RADICALE_VERSION|g" "${COMPLETION_FILE}"
192 192
     chown -R www-data:www-data /var/www/radicale
193 193
     systemctl restart radicale
194 194
     systemctl restart nginx
@@ -219,6 +219,7 @@ function restore_local_radicale {
219 219
         else
220 220
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
221 221
         fi
222
+        # shellcheck disable=SC2181
222 223
         if [ ! "$?" = "0" ]; then
223 224
             function_check backup_unmount_drive
224 225
             backup_unmount_drive
@@ -233,6 +234,7 @@ function restore_local_radicale {
233 234
         else
234 235
             cp -r $temp_restore_dir/* /var/www/radicale/*
235 236
         fi
237
+        # shellcheck disable=SC2181
236 238
         if [ ! "$?" = "0" ]; then
237 239
             function_check backup_unmount_drive
238 240
             backup_unmount_drive
@@ -264,6 +266,7 @@ function restore_remote_radicale {
264 266
         else
265 267
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
266 268
         fi
269
+        # shellcheck disable=SC2181
267 270
         if [ ! "$?" = "0" ]; then
268 271
             exit 236746
269 272
         fi
@@ -276,6 +279,7 @@ function restore_remote_radicale {
276 279
         else
277 280
             cp -r $temp_restore_dir/* /var/www/radicale
278 281
         fi
282
+        # shellcheck disable=SC2181
279 283
         if [ ! "$?" = "0" ]; then
280 284
             exit 3674284
281 285
         fi
@@ -332,17 +336,17 @@ function remove_radicale {
332 336
     fi
333 337
 
334 338
     remove_completion_param install_radicale
335
-    sed -i '/radicale/d' $COMPLETION_FILE
336
-    sed -i '/# Start radicale/,/# End radicale/d' /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
339
+    sed -i '/radicale/d' "$COMPLETION_FILE"
340
+    sed -i '/# Start radicale/,/# End radicale/d' "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
337 341
     systemctl restart nginx
338 342
 }
339 343
 
340 344
 function install_radicale {
341 345
     if [[ $ONION_ONLY == 'no' ]]; then
342 346
         # obtain a cert for the default domain
343
-        if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "0" ]]; then
347
+        if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}" pem)" == "0" ]]; then
344 348
             echo $'Obtaining certificate for the main domain'
345
-            create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
349
+            create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
346 350
         fi
347 351
     fi
348 352
 
@@ -368,7 +372,7 @@ function install_radicale {
368 372
     fi
369 373
 
370 374
     # get the source
371
-    cd /var/www/radicale
375
+    cd /var/www/radicale || exit 462874628
372 376
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
373 377
 
374 378
     # check the hash
@@ -383,7 +387,7 @@ function install_radicale {
383 387
         exit 623252
384 388
     fi
385 389
     rm Radicale-${RADICALE_VERSION}.tar.gz
386
-    cd Radicale-${RADICALE_VERSION}
390
+    cd "Radicale-${RADICALE_VERSION}" || exit 872462842
387 391
     python setup.py install
388 392
     if [ ! -f /usr/local/bin/radicale ]; then
389 393
         echo $'Radicale did not install'
@@ -398,52 +402,52 @@ function install_radicale {
398 402
     fi
399 403
 
400 404
     # create the configuration
401
-    echo '[server]' >  ${RADICALE_DIRECTORY}/config
402
-    echo 'hosts=localhost:52322' >> ${RADICALE_DIRECTORY}/config
403
-    echo 'ssl = False' >> ${RADICALE_DIRECTORY}/config
404
-    echo 'daemon = False' >> ${RADICALE_DIRECTORY}/config
405
-    echo 'base_prefix=/radicale/' >> ${RADICALE_DIRECTORY}/config
406
-    echo '' >> ${RADICALE_DIRECTORY}/config
407
-    echo '[storage]' >> ${RADICALE_DIRECTORY}/config
408
-    echo 'type = filesystem' >> ${RADICALE_DIRECTORY}/config
409
-    echo "filesystem_folder = /var/www/radicale/collections" >> ${RADICALE_DIRECTORY}/config
410
-    echo '' >> ${RADICALE_DIRECTORY}/config
411
-    echo '[well-known]' >> ${RADICALE_DIRECTORY}/config
412
-    echo "caldav = '/%(user)s/caldav/'" >> ${RADICALE_DIRECTORY}/config
413
-    echo "carddav = '/%(user)s/carddav/'" >> ${RADICALE_DIRECTORY}/config
414
-    echo '' >> ${RADICALE_DIRECTORY}/config
415
-    echo '#[auth]' >> ${RADICALE_DIRECTORY}/config
416
-    echo '#imap_hostname = localhost' >> ${RADICALE_DIRECTORY}/config
417
-    echo '#imap_port = 143' >> ${RADICALE_DIRECTORY}/config
418
-    echo '#imap_ssl = False' >> ${RADICALE_DIRECTORY}/config
419
-    echo '' >> ${RADICALE_DIRECTORY}/config
420
-    echo '[logging]' >> ${RADICALE_DIRECTORY}/config
421
-    echo 'debug = False' >> ${RADICALE_DIRECTORY}/config
405
+    { echo '[server]';
406
+      echo 'hosts=localhost:52322';
407
+      echo 'ssl = False';
408
+      echo 'daemon = False';
409
+      echo 'base_prefix=/radicale/';
410
+      echo '';
411
+      echo '[storage]';
412
+      echo 'type = filesystem';
413
+      echo "filesystem_folder = /var/www/radicale/collections";
414
+      echo '';
415
+      echo '[well-known]';
416
+      echo "caldav = '/%(user)s/caldav/'";
417
+      echo "carddav = '/%(user)s/carddav/'";
418
+      echo '';
419
+      echo '#[auth]';
420
+      echo '#imap_hostname = localhost';
421
+      echo '#imap_port = 143';
422
+      echo '#imap_ssl = False';
423
+      echo '';
424
+      echo '[logging]';
425
+      echo 'debug = False'; } > "${RADICALE_DIRECTORY}/config"
422 426
 
423 427
     # create an admin password
424 428
     if [ ${#RADICALE_PASSWORD} -lt 8 ]; then
425
-        if [ -f $IMAGE_PASSWORD_FILE ]; then
426
-            RADICALE_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
429
+        if [ -f "$IMAGE_PASSWORD_FILE" ]; then
430
+            RADICALE_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
427 431
         else
428
-            RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
432
+            RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
429 433
         fi
430 434
     fi
431 435
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
432 436
 
433
-    echo '[Unit]' > /etc/systemd/system/radicale.service
434
-    echo 'Description=Radicale CalDAV Server' >> /etc/systemd/system/radicale.service
435
-    echo 'After=network.target' >> /etc/systemd/system/radicale.service
436
-    echo '' >> /etc/systemd/system/radicale.service
437
-    echo '[Service]' >> /etc/systemd/system/radicale.service
438
-    echo 'Type=simple' >> /etc/systemd/system/radicale.service
439
-    echo 'User=www-data' >> /etc/systemd/system/radicale.service
440
-    echo 'Group=www-data' >> /etc/systemd/system/radicale.service
441
-    echo "ExecStart=/usr/local/bin/radicale --config ${RADICALE_DIRECTORY}/config" >> /etc/systemd/system/radicale.service
442
-    echo 'Restart=on-failure' >> /etc/systemd/system/radicale.service
443
-    echo 'RestartSec=10' >> /etc/systemd/system/radicale.service
444
-    echo '' >> /etc/systemd/system/radicale.service
445
-    echo '[Install]' >> /etc/systemd/system/radicale.service
446
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/radicale.service
437
+    { echo '[Unit]';
438
+      echo 'Description=Radicale CalDAV Server';
439
+      echo 'After=network.target';
440
+      echo '';
441
+      echo '[Service]';
442
+      echo 'Type=simple';
443
+      echo 'User=www-data';
444
+      echo 'Group=www-data';
445
+      echo "ExecStart=/usr/local/bin/radicale --config ${RADICALE_DIRECTORY}/config";
446
+      echo 'Restart=on-failure';
447
+      echo 'RestartSec=10';
448
+      echo '';
449
+      echo '[Install]';
450
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/radicale.service
447 451
 
448 452
     addresses_str=$"Addresses"
449 453
     echo "{\"tag\": \"VADDRESSBOOK\", \"D:displayname\": \"${addresses_str}\"}" > /var/www/radicale/collections/addresses.props
@@ -461,107 +465,107 @@ function install_radicale {
461 465
     systemctl enable radicale
462 466
     systemctl start radicale
463 467
 
464
-    if [ ! -f /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME} ]; then
468
+    if [ ! -f "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}" ]; then
465 469
         # create a new site config
466 470
         RADICALE_ONION_HOSTNAME=$(add_onion_service radicale 80 ${RADICALE_ONION_PORT})
467 471
 
468 472
         if [[ $ONION_ONLY == 'no' ]]; then
469
-            echo 'server {' > /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
470
-            echo "    listen 443 ssl;" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
471
-            echo "    #listen [::]:443 ssl;" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
472
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
473
+            { echo 'server {';
474
+              echo "    listen 443 ssl;";
475
+              echo "    #listen [::]:443 ssl;";
476
+              echo ''; } > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
473 477
             function_check nginx_ssl
474
-            nginx_ssl ${DEFAULT_DOMAIN_NAME} mobile
478
+            nginx_ssl "${DEFAULT_DOMAIN_NAME}" mobile
475 479
             function_check nginx_disable_sniffing
476
-            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
477
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
478
-            echo "    server_name ${DEFAULT_DOMAIN_NAME};" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
479
-
480
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
481
-            echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
482
-            echo '    error_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
483
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
484
-            echo '    # Start radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
485
-            echo '    location @radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
486
-            echo '        auth_basic "Radicale";' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
487
-            echo '        auth_basic_user_file /var/www/radicale/users;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
488
-            echo '        proxy_pass http://localhost:52322;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
489
-            echo '        proxy_buffering off;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
490
-            echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
491
-            echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
492
-            echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
493
-            echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
494
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
495
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
496
-            echo '    location /radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
497
-            echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
498
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
499
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
500
-            echo '    location /.well-known/carddav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
501
-            echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
502
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
503
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
504
-            echo '    location /.well-known/caldav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
505
-            echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
506
-            echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
507
-            echo '    # End radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
508
-            echo '}' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
509
-            echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
480
+            nginx_disable_sniffing "${DEFAULT_DOMAIN_NAME}"
481
+            { echo '';
482
+              echo "    server_name ${DEFAULT_DOMAIN_NAME};";
483
+
484
+              echo '';
485
+              echo '    access_log /dev/null;';
486
+              echo '    error_log /dev/null;';
487
+              echo '';
488
+              echo '    # Start radicale';
489
+              echo '    location @radicale {';
490
+              echo '        auth_basic "Radicale";';
491
+              echo '        auth_basic_user_file /var/www/radicale/users;';
492
+              echo '        proxy_pass http://localhost:52322;';
493
+              echo '        proxy_buffering off;';
494
+              echo "        proxy_set_header Host \$host;";
495
+              echo "        proxy_set_header X-Real-IP \$remote_addr;";
496
+              echo "        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
497
+              echo "        proxy_set_header X-Forwarded-Proto \$scheme;";
498
+              echo '    }';
499
+              echo '';
500
+              echo '    location /radicale {';
501
+              echo "        try_files \$uri @radicale;";
502
+              echo '    }';
503
+              echo '';
504
+              echo '    location /.well-known/carddav {';
505
+              echo "        try_files \$uri @radicale;";
506
+              echo '    }';
507
+              echo '';
508
+              echo '    location /.well-known/caldav {';
509
+              echo "        try_files \$uri @radicale;";
510
+              echo '    }';
511
+              echo '    # End radicale';
512
+              echo '}';
513
+              echo ''; } >> "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
510 514
         else
511
-            echo -n '' > /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
515
+            echo -n '' > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
512 516
         fi
513
-        echo 'server {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
514
-        echo "    listen localhost:${RADICALE_ONION_PORT} default_server;" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
515
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
516
-        echo "    server_name ${RADICALE_ONION_HOSTNAME};" >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
517
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
518
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
519
-        echo '    error_log /dev/null;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
520
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
521
-        echo '    # Start radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
522
-        echo '    location @radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
523
-        echo '        auth_basic "Radicale";' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
524
-        echo '        auth_basic_user_file /var/www/radicale/users;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
525
-        echo '        proxy_pass http://localhost:52322;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
526
-        echo '        proxy_buffering off;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
527
-        echo '        proxy_set_header Host $host;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
528
-        echo '        proxy_set_header X-Real-IP $remote_addr;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
529
-        echo '        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
530
-        echo '        proxy_set_header X-Forwarded-Proto $scheme;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
531
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
532
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
533
-        echo '    location /radicale {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
534
-        echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
535
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
536
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
537
-        echo '    location /.well-known/carddav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
538
-        echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
539
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
540
-        echo '' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
541
-        echo '    location /.well-known/caldav {' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
542
-        echo '        try_files $uri @radicale;' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
543
-        echo '    }' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
544
-        echo '    # End radicale' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
545
-        echo '}' >> /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
517
+        { echo 'server {';
518
+          echo "    listen localhost:${RADICALE_ONION_PORT} default_server;";
519
+          echo '';
520
+          echo "    server_name ${RADICALE_ONION_HOSTNAME};";
521
+          echo '';
522
+          echo '    access_log /dev/null;';
523
+          echo '    error_log /dev/null;';
524
+          echo '';
525
+          echo '    # Start radicale';
526
+          echo '    location @radicale {';
527
+          echo '        auth_basic "Radicale";';
528
+          echo '        auth_basic_user_file /var/www/radicale/users;';
529
+          echo '        proxy_pass http://localhost:52322;';
530
+          echo '        proxy_buffering off;';
531
+          echo "        proxy_set_header Host \$host;";
532
+          echo "        proxy_set_header X-Real-IP \$remote_addr;";
533
+          echo "        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
534
+          echo "        proxy_set_header X-Forwarded-Proto \$scheme;";
535
+          echo '    }';
536
+          echo '';
537
+          echo '    location /radicale {';
538
+          echo "        try_files \$uri @radicale;";
539
+          echo '    }';
540
+          echo '';
541
+          echo '    location /.well-known/carddav {';
542
+          echo "        try_files \$uri @radicale;";
543
+          echo '    }';
544
+          echo '';
545
+          echo '    location /.well-known/caldav {';
546
+          echo "        try_files \$uri @radicale;";
547
+          echo '    }';
548
+          echo '    # End radicale';
549
+          echo '}'; } >> "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
546 550
 
547 551
         set_completion_param "radicale onion domain" "${RADICALE_ONION_HOSTNAME}"
548 552
     else
549 553
         # alter the existing site config
550
-        if ! grep -q "# Start radicale" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}; then
551
-            sed -i '/]:443/a    # Start radicale\n  location @radicale {\n    auth_basic "Radicale";\n    auth_basic_user_file \/var\/www\/radicale\/users;\n    proxy_pass http:\/\/localhost:52322;\n    proxy_buffering off;\n    proxy_set_header Host $host;\n    proxy_set_header X-Real-IP $remote_addr;\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header X-Forwarded-Proto $scheme;\n  }\n\n  location \/radicale {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/carddav {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/caldav {\n      try_files $uri @radicale;\n  }\n  # End radicale' /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
552
-            sed -i '/listen localhost/a    # Start radicale\n  location @radicale {\n    auth_basic "Radicale";\n    auth_basic_user_file \/var\/www\/radicale\/users;\n    proxy_pass http:\/\/localhost:52322;\n    proxy_buffering off;\n    proxy_set_header Host $host;\n    proxy_set_header X-Real-IP $remote_addr;\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header X-Forwarded-Proto $scheme;\n  }\n\n  location \/radicale {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/carddav {\n      try_files $uri @radicale;\n  }\n\n  location \/.well-known\/caldav {\n      try_files $uri @radicale;\n  }\n  # End radicale' /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
554
+        if ! grep -q "# Start radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"; then
555
+            sed -i "/]:443/a    # Start radicale\\n  location @radicale {\\n    auth_basic \"Radicale\";\\n    auth_basic_user_file \\/var\\/www\\/radicale\\/users;\\n    proxy_pass http:\\/\\/localhost:52322;\\n    proxy_buffering off;\\n    proxy_set_header Host \$host;\\n    proxy_set_header X-Real-IP \$remote_addr;\\n    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;\\n    proxy_set_header X-Forwarded-Proto \$scheme;\\n  }\\n\\n  location \\/radicale {\\n      try_files \$uri @radicale;\\n  }\\n\\n  location \\/.well-known\\/carddav {\\n      try_files \$uri @radicale;\\n  }\\n\\n  location \\/.well-known\\/caldav {\\n      try_files \$uri @radicale;\\n  }\\n  # End radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
556
+            sed -i "/listen localhost/a    # Start radicale\\n  location @radicale {\\n    auth_basic \"Radicale\";\\n    auth_basic_user_file \\/var\\/www\\/radicale\\/users;\\n    proxy_pass http:\\/\\/localhost:52322;\\n    proxy_buffering off;\\n    proxy_set_header Host \$host;\\n    proxy_set_header X-Real-IP \$remote_addr;\\n    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;\\n    proxy_set_header X-Forwarded-Proto \$scheme;\\n  }\\n\\n  location \\/radicale {\\n      try_files \$uri @radicale;\\n  }\\n\\n  location \\/.well-known\\/carddav {\\n      try_files \$uri @radicale;\\n  }\\n\\n  location \\/.well-known\\/caldav {\\n      try_files \$uri @radicale;\\n  }\\n  # End radicale" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
553 557
         fi
554 558
     fi
555 559
 
556 560
     # create a certificate
557
-    if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
558
-        if [ ! -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt ]; then
559
-            ${PROJECT_NAME}-addcert -h $DEFAULT_DOMAIN_NAME --dhkey ${DH_KEYLENGTH}
560
-            check_certificates $DEFAULT_DOMAIN_NAME
561
+    if [ ! -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
562
+        if [ ! -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
563
+            "${PROJECT_NAME}-addcert" -h "$DEFAULT_DOMAIN_NAME" --dhkey "${DH_KEYLENGTH}"
564
+            check_certificates "$DEFAULT_DOMAIN_NAME"
561 565
         fi
562 566
     fi
563 567
 
564
-    if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
568
+    if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
565 569
         sed -i "s|radicale.crt|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
566 570
         sed -i "s|radicale.pem|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
567 571
     fi
@@ -572,13 +576,13 @@ function install_radicale {
572 576
 
573 577
     systemctl restart nginx
574 578
 
575
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a radicale -p "$RADICALE_PASSWORD"
579
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a radicale -p "$RADICALE_PASSWORD"
576 580
 
577 581
     # keep track of the version so we can check for upgrades
578
-    if ! grep -q "radicale version:" ${COMPLETION_FILE}; then
579
-        echo "radicale version:${RADICALE_VERSION}" >> ${COMPLETION_FILE}
582
+    if ! grep -q "radicale version:" "${COMPLETION_FILE}"; then
583
+        echo "radicale version:${RADICALE_VERSION}" >> "${COMPLETION_FILE}"
580 584
     else
581
-        sed -i "s|radicale version.*|radicale version:${RADICALE_VERSION}|g" ${COMPLETION_FILE}
585
+        sed -i "s|radicale version.*|radicale version:${RADICALE_VERSION}|g" "${COMPLETION_FILE}"
582 586
     fi
583 587
 
584 588
     APP_INSTALLED=1

+ 89
- 87
src/freedombone-app-riot Просмотреть файл

@@ -76,39 +76,40 @@ function install_interactive_riot {
76 76
         RIOT_DETAILS_COMPLETE=
77 77
         while [ ! $RIOT_DETAILS_COMPLETE ]
78 78
         do
79
-            data=$(tempfile 2>/dev/null)
80
-            trap "rm -f $data" 0 1 2 5 15
79
+            data=$(mktemp 2>/dev/null)
81 80
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
82 81
                 dialog --backtitle $"Freedombone Configuration" \
83 82
                        --title $"Riot Web user interface for Matrix" \
84
-                       --form $"\nPlease enter your details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
83
+                       --form $"\\nPlease enter your details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 3 \
85 84
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
86 85
                        $"Code:" 2 1 "$(grep 'RIOT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
87
-                       2> $data
86
+                       2> "$data"
88 87
             else
89 88
                 dialog --backtitle $"Freedombone Configuration" \
90 89
                        --title $"Riot Web user interface for Matrix" \
91
-                       --form $"\nPlease enter your details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 2 \
90
+                       --form $"\\nPlease enter your details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 13 65 2 \
92 91
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
93
-                       2> $data
92
+                       2> "$data"
94 93
             fi
95 94
             sel=$?
96 95
             case $sel in
97
-                1) exit 1;;
98
-                255) exit 1;;
96
+                1) rm -f "$data"
97
+                   exit 1;;
98
+                255) rm -f "$data"
99
+                     exit 1;;
99 100
             esac
100
-            RIOT_DOMAIN_NAME=$(cat $data | sed -n 1p)
101
-            if [ $RIOT_DOMAIN_NAME ]; then
101
+            RIOT_DOMAIN_NAME=$(sed -n 1p < "$data")
102
+            if [ "$RIOT_DOMAIN_NAME" ]; then
102 103
                 TEST_DOMAIN_NAME=$RIOT_DOMAIN_NAME
103 104
                 validate_domain_name
104
-                if [[ $TEST_DOMAIN_NAME != $RIOT_DOMAIN_NAME ]]; then
105
+                if [[ "$TEST_DOMAIN_NAME" != "$RIOT_DOMAIN_NAME" ]]; then
105 106
                     RIOT_DOMAIN_NAME=
106 107
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
107 108
                 else
108 109
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
109
-                        RIOT_CODE=$(cat $data | sed -n 2p)
110
+                        RIOT_CODE=$(sed -n 2p < "$data")
110 111
                         validate_freedns_code "$RIOT_CODE"
111
-                        if [ ! $VALID_CODE ]; then
112
+                        if [ ! "$VALID_CODE" ]; then
112 113
                             RIOT_DOMAIN_NAME=
113 114
                         fi
114 115
                     fi
@@ -117,6 +118,7 @@ function install_interactive_riot {
117 118
             if [ $RIOT_DOMAIN_NAME ]; then
118 119
                 RIOT_DETAILS_COMPLETE="yes"
119 120
             fi
121
+            rm -f "$data"
120 122
         done
121 123
 
122 124
         # save the results in the config file
@@ -132,14 +134,14 @@ function reconfigure_riot {
132 134
 
133 135
 function riot_download {
134 136
     # download
135
-    if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
136
-        wget ${RIOT_DOWNLOAD_URL}/${RIOT_FILENAME}.tar.gz -O $INSTALL_DIR/${RIOT_FILENAME}.tar.gz
137
+    if [ ! -f "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz" ]; then
138
+        wget "${RIOT_DOWNLOAD_URL}/${RIOT_FILENAME}.tar.gz" -O "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz"
137 139
     fi
138
-    if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
140
+    if [ ! -f "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz" ]; then
139 141
         echo $'Unable to download Riot Web from releases'
140 142
         exit 62836
141 143
     fi
142
-    cd $INSTALL_DIR
144
+    cd "$INSTALL_DIR" || exit 2468724628
143 145
 
144 146
     # check the hash
145 147
     curr_hash=$(sha256sum ${RIOT_FILENAME}.tar.gz | awk -F ' ' '{print $1}')
@@ -149,17 +151,17 @@ function riot_download {
149 151
     fi
150 152
 
151 153
     tar -xzvf ${RIOT_FILENAME}.tar.gz
152
-    if [ ! -d $INSTALL_DIR/${RIOT_FILENAME} ]; then
154
+    if [ ! -d "$INSTALL_DIR/${RIOT_FILENAME}" ]; then
153 155
         echo $'Unable to extract Riot Web tarball'
154 156
         exit 542826
155 157
     fi
156
-    cp -r $INSTALL_DIR/${RIOT_FILENAME}/* /var/www/$RIOT_DOMAIN_NAME/htdocs
158
+    cp -r "$INSTALL_DIR/${RIOT_FILENAME}/*" "/var/www/$RIOT_DOMAIN_NAME/htdocs"
157 159
 
158
-    chown -R www-data:www-data /var/www/$RIOT_DOMAIN_NAME/htdocs
160
+    chown -R www-data:www-data "/var/www/$RIOT_DOMAIN_NAME/htdocs"
159 161
 }
160 162
 
161 163
 function upgrade_riot {
162
-    if ! grep -q 'riot version:' $COMPLETION_FILE; then
164
+    if ! grep -q 'riot version:' "$COMPLETION_FILE"; then
163 165
         return
164 166
     fi
165 167
 
@@ -171,7 +173,7 @@ function upgrade_riot {
171 173
     fi
172 174
 
173 175
     riot_download
174
-    sed -i "s|riot version.*|riot version:$RIOT_VERSION|g" ${COMPLETION_FILE}
176
+    sed -i "s|riot version.*|riot version:$RIOT_VERSION|g" "${COMPLETION_FILE}"
175 177
     riot_remove_bad_links
176 178
 
177 179
     systemctl restart nginx
@@ -207,7 +209,7 @@ function remove_riot {
207 209
     fi
208 210
 
209 211
     remove_completion_param install_riot
210
-    sed -i '/riot /d' $COMPLETION_FILE
212
+    sed -i '/riot /d' "$COMPLETION_FILE"
211 213
 }
212 214
 
213 215
 function install_riot {
@@ -216,7 +218,7 @@ function install_riot {
216 218
     fi
217 219
 
218 220
     # check that matrix has been installed
219
-    if [ ! $MATRIX_DOMAIN_NAME ]; then
221
+    if [ ! "$MATRIX_DOMAIN_NAME" ]; then
220 222
         exit 687292
221 223
     fi
222 224
     if [[ "$MATRIX_DOMAIN_NAME" != *'.'* ]]; then
@@ -235,32 +237,32 @@ function install_riot {
235 237
         mkdir -p /var/www/$RIOT_DOMAIN_NAME/htdocs
236 238
     fi
237 239
 
238
-    if [ ! -d $INSTALL_DIR ]; then
239
-        mkdir $INSTALL_DIR
240
+    if [ ! -d "$INSTALL_DIR" ]; then
241
+        mkdir "$INSTALL_DIR"
240 242
     fi
241 243
 
242 244
     riot_download
243 245
 
244
-    cd /var/www/$RIOT_DOMAIN_NAME/htdocs
246
+    cd "/var/www/$RIOT_DOMAIN_NAME/htdocs" || exit 4628462876
245 247
 
246
-    if [[ $ONION_ONLY == 'no' ]]; then
248
+    if [[ "$ONION_ONLY" == 'no' ]]; then
247 249
         riot_config_file="config.${RIOT_DOMAIN_NAME}.json"
248 250
         cp config.sample.json $riot_config_file
249
-        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" $riot_config_file
250
-        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" $riot_config_file
251
-        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"https://${MATRIX_DOMAIN_NAME}/bugs\",|g" $riot_config_file
252
-        sed -i "/\"servers\":/a \"${MATRIX_DOMAIN_NAME}\"," $riot_config_file
251
+        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" "$riot_config_file"
252
+        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"https://${MATRIX_DOMAIN_NAME}\",|g" "$riot_config_file"
253
+        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"https://${MATRIX_DOMAIN_NAME}/bugs\",|g" "$riot_config_file"
254
+        sed -i "/\"servers\":/a \"${MATRIX_DOMAIN_NAME}\"," "$riot_config_file"
253 255
     else
254 256
         riot_config_file="config.${MATRIX_ONION_DOMAIN_NAME}.json"
255
-        cp config.sample.json $riot_config_file
256
-        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" $riot_config_file
257
-        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" $riot_config_file
258
-        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}/bugs\",|g" $riot_config_file
259
-        sed -i "/\"servers\":/a \"${MATRIX_ONION_DOMAIN_NAME}\"," $riot_config_file
257
+        cp config.sample.json "$riot_config_file"
258
+        sed -i "s|\"default_hs_url\":.*|\"default_hs_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" "$riot_config_file"
259
+        sed -i "s|\"default_is_url\":.*|\"default_is_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}\",|g" "$riot_config_file"
260
+        sed -i "s|\"bug_report_endpoint_url\":.*|\"bug_report_endpoint_url\": \"http://${MATRIX_ONION_DOMAIN_NAME}/bugs\",|g" "$riot_config_file"
261
+        sed -i "/\"servers\":/a \"${MATRIX_ONION_DOMAIN_NAME}\"," "$riot_config_file"
260 262
     fi
261
-    sed -i "s|\"integrations_ui_url\":.*|\"integrations_ui_url\": \"\",|g" $riot_config_file
262
-    sed -i "s|\"integrations_rest_url\":.*|\"integrations_rest_url\": \"\",|g" $riot_config_file
263
-    sed -i 's|https://piwik.riot.im/||g' $riot_config_file
263
+    sed -i "s|\"integrations_ui_url\":.*|\"integrations_ui_url\": \"\",|g" "$riot_config_file"
264
+    sed -i "s|\"integrations_rest_url\":.*|\"integrations_rest_url\": \"\",|g" "$riot_config_file"
265
+    sed -i 's|https://piwik.riot.im/||g' "$riot_config_file"
264 266
 
265 267
     RIOT_ONION_HOSTNAME=$(add_onion_service riot 80 ${RIOT_ONION_PORT})
266 268
 
@@ -268,68 +270,68 @@ function install_riot {
268 270
     if [[ $ONION_ONLY == "no" ]]; then
269 271
         function_check nginx_http_redirect
270 272
         nginx_http_redirect $RIOT_DOMAIN_NAME
271
-        echo 'server {' >> $riot_nginx_site
272
-        echo '  listen 443 ssl;' >> $riot_nginx_site
273
-        echo '  #listen [::]:443 ssl;' >> $riot_nginx_site
274
-        echo "  server_name $RIOT_DOMAIN_NAME;" >> $riot_nginx_site
275
-        echo '' >> $riot_nginx_site
276
-        echo '  # Security' >> $riot_nginx_site
273
+        { echo 'server {';
274
+          echo '  listen 443 ssl;';
275
+          echo '  #listen [::]:443 ssl;';
276
+          echo "  server_name $RIOT_DOMAIN_NAME;";
277
+          echo '';
278
+          echo '  # Security'; } >> $riot_nginx_site
277 279
         function_check nginx_ssl
278 280
         nginx_ssl $RIOT_DOMAIN_NAME
279 281
 
280 282
         function_check nginx_disable_sniffing
281 283
         nginx_disable_sniffing $RIOT_DOMAIN_NAME
282 284
 
283
-        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $riot_nginx_site
284
-        echo '' >> $riot_nginx_site
285
-        echo '  # Logs' >> $riot_nginx_site
286
-        echo '  access_log /dev/null;' >> $riot_nginx_site
287
-        echo '  error_log /dev/null;' >> $riot_nginx_site
288
-        echo '' >> $riot_nginx_site
289
-        echo '  # Root' >> $riot_nginx_site
290
-        echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;" >> $riot_nginx_site
291
-        echo '' >> $riot_nginx_site
292
-        echo '  index index.html;' >> $riot_nginx_site
293
-        echo '' >> $riot_nginx_site
294
-        echo '  location / {' >> $riot_nginx_site
285
+        { echo '  add_header Strict-Transport-Security max-age=15768000;';
286
+          echo '';
287
+          echo '  # Logs';
288
+          echo '  access_log /dev/null;';
289
+          echo '  error_log /dev/null;';
290
+          echo '';
291
+          echo '  # Root';
292
+          echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;";
293
+          echo '';
294
+          echo '  index index.html;';
295
+          echo '';
296
+          echo '  location / {'; } >> $riot_nginx_site
295 297
         function_check nginx_limits
296 298
         nginx_limits $RIOT_DOMAIN_NAME '15m'
297
-        echo '  }' >> $riot_nginx_site
298
-        echo '}' >> $riot_nginx_site
299
-        echo '' >> $riot_nginx_site
299
+        { echo '  }';
300
+          echo '}';
301
+          echo ''; } >> $riot_nginx_site
300 302
     else
301 303
         echo -n '' > $riot_nginx_site
302 304
     fi
303
-    echo 'server {' >> $riot_nginx_site
304
-    echo "    listen 127.0.0.1:$RIOT_ONION_PORT default_server;" >> $riot_nginx_site
305
-    echo "    server_name $RIOT_ONION_HOSTNAME;" >> $riot_nginx_site
306
-    echo '' >> $riot_nginx_site
305
+    { echo 'server {';
306
+      echo "    listen 127.0.0.1:$RIOT_ONION_PORT default_server;";
307
+      echo "    server_name $RIOT_ONION_HOSTNAME;";
308
+      echo ''; } >> $riot_nginx_site
307 309
     function_check nginx_disable_sniffing
308 310
     nginx_disable_sniffing $RIOT_DOMAIN_NAME
309
-    echo '' >> $riot_nginx_site
310
-    echo '  # Logs' >> $riot_nginx_site
311
-    echo '  access_log /dev/null;' >> $riot_nginx_site
312
-    echo '  error_log /dev/null;' >> $riot_nginx_site
313
-    echo '' >> $riot_nginx_site
314
-    echo '  # Root' >> $riot_nginx_site
315
-    echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;" >> $riot_nginx_site
316
-    echo '' >> $riot_nginx_site
317
-    echo '  index index.html;' >> $riot_nginx_site
318
-    echo '' >> $riot_nginx_site
319
-    echo '  location / {' >> $riot_nginx_site
311
+    { echo '';
312
+      echo '  # Logs';
313
+      echo '  access_log /dev/null;';
314
+      echo '  error_log /dev/null;';
315
+      echo '';
316
+      echo '  # Root';
317
+      echo "  root /var/www/$RIOT_DOMAIN_NAME/htdocs;";
318
+      echo '';
319
+      echo '  index index.html;';
320
+      echo '';
321
+      echo '  location / {'; } >> $riot_nginx_site
320 322
     function_check nginx_limits
321 323
     nginx_limits $RIOT_DOMAIN_NAME '15m'
322
-    echo '  }' >> $riot_nginx_site
323
-    echo '}' >> $riot_nginx_site
324
+    echo '  }' >> "$riot_nginx_site"
325
+    echo '}' >> "$riot_nginx_site"
324 326
 
325
-    sed '/Content-Security-Policy/d' $riot_nginx_site
326
-    sed -i 's| DENY;| SAMEORIGIN;|g' $riot_nginx_site
327
-    sed -i 's|limit_conn conn_limit_per_ip.*|limit_conn conn_limit_per_ip 50;|g' $riot_nginx_site
328
-    sed -i 's|limit_req zone.*|limit_req zone=req_limit_per_ip burst=20 nodelay;|g' $riot_nginx_site
327
+    sed '/Content-Security-Policy/d' "$riot_nginx_site"
328
+    sed -i 's| DENY;| SAMEORIGIN;|g' "$riot_nginx_site"
329
+    sed -i 's|limit_conn conn_limit_per_ip.*|limit_conn conn_limit_per_ip 50;|g' "$riot_nginx_site"
330
+    sed -i 's|limit_req zone.*|limit_req zone=req_limit_per_ip burst=20 nodelay;|g' "$riot_nginx_site"
329 331
 
330 332
     function_check create_site_certificate
331
-    if [ ! -f /etc/ssl/certs/${RIOT_DOMAIN_NAME}.pem ]; then
332
-        create_site_certificate $RIOT_DOMAIN_NAME 'yes'
333
+    if [ ! -f "/etc/ssl/certs/${RIOT_DOMAIN_NAME}.pem" ]; then
334
+        create_site_certificate "$RIOT_DOMAIN_NAME" 'yes'
333 335
     fi
334 336
 
335 337
     function_check nginx_ensite
@@ -344,10 +346,10 @@ function install_riot {
344 346
     systemctl restart nginx
345 347
 
346 348
     set_completion_param "riot domain" "$RIOT_DOMAIN_NAME"
347
-    if ! grep -q "riot version:" ${COMPLETION_FILE}; then
348
-        echo "riot version:${RIOT_VERSION}" >> ${COMPLETION_FILE}
349
+    if ! grep -q "riot version:" "${COMPLETION_FILE}"; then
350
+        echo "riot version:${RIOT_VERSION}" >> "${COMPLETION_FILE}"
349 351
     else
350
-        sed -i "s|riot version.*|riot version:${RIOT_VERSION}|g" ${COMPLETION_FILE}
352
+        sed -i "s|riot version.*|riot version:${RIOT_VERSION}|g" "${COMPLETION_FILE}"
351 353
     fi
352 354
     APP_INSTALLED=1
353 355
 }

+ 201
- 197
src/freedombone-app-rss Просмотреть файл

@@ -62,12 +62,13 @@ function logging_off_rss {
62 62
 }
63 63
 
64 64
 function remove_user_rss {
65
-    remove_username="$1"
65
+    echo -n ''
66
+#    remove_username="$1"
66 67
 }
67 68
 
68 69
 function add_user_rss {
69
-    new_username="$1"
70
-    new_user_password="$2"
70
+#    new_username="$1"
71
+#    new_user_password="$2"
71 72
     echo '0'
72 73
 }
73 74
 
@@ -77,26 +78,27 @@ function install_interactive_rss {
77 78
 }
78 79
 
79 80
 function change_password_rss {
80
-    curr_username="$1"
81
-    new_user_password="$2"
81
+    echo -n ''
82
+#    curr_username="$1"
83
+#    new_user_password="$2"
82 84
 
83 85
     #${PROJECT_NAME}-pass -u "$curr_username" -a rss -p "$new_user_password"
84 86
 }
85 87
 
86 88
 function rss_create_database {
87
-    if [ -f $IMAGE_PASSWORD_FILE ]; then
88
-        RSS_READER_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
89
+    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
90
+        RSS_READER_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
89 91
     else
90
-        if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
91
-            RSS_READER_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
92
+        if [ ! "$RSS_READER_ADMIN_PASSWORD" ]; then
93
+            RSS_READER_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
92 94
         fi
93 95
     fi
94
-    if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
96
+    if [ ! "$RSS_READER_ADMIN_PASSWORD" ]; then
95 97
         return
96 98
     fi
97 99
 
98 100
     function_check create_database
99
-    create_database ttrss "$RSS_READER_ADMIN_PASSWORD" $MY_USERNAME
101
+    create_database ttrss "$RSS_READER_ADMIN_PASSWORD" "$MY_USERNAME"
100 102
 }
101 103
 
102 104
 function reconfigure_rss {
@@ -131,8 +133,8 @@ function upgrade_rss {
131 133
         # remove any previous install
132 134
         if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
133 135
             if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
134
-                sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
135
-                sed -i '/rss mobile reader commit/d' $COMPLETION_FILE
136
+                sed -i '/install_rss_mobile_reader/d' "$COMPLETION_FILE"
137
+                sed -i '/rss mobile reader commit/d' "$COMPLETION_FILE"
136 138
                 rm -rf $RSS_READER_PATH/g2ttree-mobile
137 139
             fi
138 140
         fi
@@ -184,6 +186,7 @@ function restore_local_rss {
184 186
                 fi
185 187
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
186 188
             fi
189
+            # shellcheck disable=SC2181
187 190
             if [ ! "$?" = "0" ]; then
188 191
                 function_check set_user_permissions
189 192
                 set_user_permissions
@@ -193,12 +196,12 @@ function restore_local_rss {
193 196
                 exit 528823
194 197
             fi
195 198
             if [ -d /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME} ]; then
196
-                ln -s /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${2}.key
197
-                ln -s /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${2}.pem
199
+                ln -s "/etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/privkey.pem" "/etc/ssl/private/${2}.key"
200
+                ln -s "/etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME}/fullchain.pem" "/etc/ssl/certs/${2}.pem"
198 201
             else
199 202
                 # Ensure that the bundled SSL cert is being used
200 203
                 if [ -f /etc/ssl/certs/${RSS_READER_DOMAIN_NAME}.bundle.crt ]; then
201
-                    sed -i "s|${RSS_READER_DOMAIN_NAME}.crt|${RSS_READER_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${2}
204
+                    sed -i "s|${RSS_READER_DOMAIN_NAME}.crt|${RSS_READER_DOMAIN_NAME}.bundle.crt|g" "/etc/nginx/sites-available/${2}"
202 205
                 fi
203 206
             fi
204 207
         fi
@@ -207,14 +210,14 @@ function restore_local_rss {
207 210
     function_check rss_modifications
208 211
     rss_modifications
209 212
 
210
-    if [ -d $USB_MOUNT/backup/ttrss ]; then
213
+    if [ -d "$USB_MOUNT/backup/ttrss" ]; then
211 214
         chown -R www-data:www-data /etc/share/tt-rss
212 215
         if [ -d $temp_restore_dir ]; then
213 216
             rm -rf $temp_restore_dir
214 217
         fi
215 218
     fi
216 219
 
217
-    MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
220
+    MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
218 221
     sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
219 222
     MARIADB_PASSWORD=
220 223
 }
@@ -245,7 +248,7 @@ function backup_remote_rss {
245 248
 
246 249
 function restore_remote_rss {
247 250
     temp_restore_dir=/root/tempttrss
248
-    if grep -q "rss reader domain" $COMPLETION_FILE; then
251
+    if grep -q "rss reader domain" "$COMPLETION_FILE"; then
249 252
         echo $"Restoring ttrss"
250 253
         function_check get_mariadb_password
251 254
         get_mariadb_password
@@ -263,6 +266,7 @@ function restore_remote_rss {
263 266
                 fi
264 267
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
265 268
             fi
269
+            # shellcheck disable=SC2181
266 270
             if [ ! "$?" = "0" ]; then
267 271
                 exit 6391
268 272
             fi
@@ -280,14 +284,14 @@ function restore_remote_rss {
280 284
         function_check rss_modifications
281 285
         rss_modifications
282 286
 
283
-        if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
287
+        if [ -d "$SERVER_DIRECTORY/backup/ttrss" ]; then
284 288
             chown -R www-data:www-data /etc/share/tt-rss
285 289
         fi
286 290
         if [ -d /root/tempttrss ]; then
287 291
             rm -rf /root/tempttrss
288 292
         fi
289 293
 
290
-        MARIADB_PASSWORD=$(${PROJECT_NAME}-pass -u root -a mariadb)
294
+        MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
291 295
         sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
292 296
         MARIADB_PASSWORD=
293 297
 
@@ -313,9 +317,9 @@ function remove_rss {
313 317
     function_check drop_database
314 318
     drop_database ttrss
315 319
     remove_completion_param install_rss
316
-    sed -i '/RSS /d' $COMPLETION_FILE
317
-    sed -i '/rss /d' $COMPLETION_FILE
318
-    sed -i '/rss_/d' $COMPLETION_FILE
320
+    sed -i '/RSS /d' "$COMPLETION_FILE"
321
+    sed -i '/rss /d' "$COMPLETION_FILE"
322
+    sed -i '/rss_/d' "$COMPLETION_FILE"
319 323
     remove_backup_database_local ttrss
320 324
 }
321 325
 
@@ -329,15 +333,15 @@ function rss_modifications {
329 333
 
330 334
     # ensure that socks5 proxy is used
331 335
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/plugins/af_unburn/init.php; then
332
-        sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/plugins/af_unburn/init.php
336
+        sed -i "/curl_setopt(\$ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\\\t\\t\\t\\t\\tcurl_setopt(\$ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);" "$RSS_READER_PATH/plugins/af_unburn/init.php"
333 337
         rss_modified=1
334 338
     fi
335 339
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/include/functions.php; then
336
-        sed -i '/curl_setopt($ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\t\t\t\tcurl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);' $RSS_READER_PATH/include/functions.php
340
+        sed -i "/curl_setopt(\$ch, CURLOPT_PROXY, _CURL_HTTP_PROXY);/a \\\\t\\t\\t\\tcurl_setopt(\$ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);" "$RSS_READER_PATH/include/functions.php"
337 341
         rss_modified=1
338 342
     fi
339 343
     if [ $rss_modified ]; then
340
-        cd $RSS_READER_PATH
344
+        cd $RSS_READER_PATH || exit 564286428
341 345
         git commit -a -m"Modify for Tor proxying"
342 346
     fi
343 347
     chown -R www-data:www-data $RSS_READER_PATH
@@ -358,12 +362,12 @@ function install_rss_main {
358 362
     if [ ! -d /etc/share ]; then
359 363
         mkdir /etc/share
360 364
     fi
361
-    cd /etc/share
365
+    cd /etc/share || exit 46284628
362 366
 
363 367
     if [ -d /repos/rss ]; then
364 368
         mkdir tt-rss
365 369
         cp -r -p /repos/rss/. tt-rss
366
-        cd tt-rss
370
+        cd tt-rss || exit 462846822
367 371
         git pull
368 372
     else
369 373
         function_check git_clone
@@ -374,7 +378,7 @@ function install_rss_main {
374 378
         echo $'Could not clone RSS reader repo'
375 379
         exit 52925
376 380
     fi
377
-    cd $RSS_READER_PATH
381
+    cd $RSS_READER_PATH || exit 42479825792593
378 382
     git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
379 383
     set_completion_param "rss reader commit" "$RSS_READER_COMMIT"
380 384
 
@@ -397,151 +401,151 @@ function install_rss_main {
397 401
     USE_V2_ONION_ADDRESS=1
398 402
     RSS_MOBILE_READER_ONION_HOSTNAME=$(add_onion_service mobilerss 80 ${RSS_MOBILE_READER_ONION_PORT})
399 403
 
400
-    echo 'server {' > /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
401
-    echo "  listen 127.0.0.1:$RSS_MOBILE_READER_ONION_PORT;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
402
-    echo "  server_name $RSS_MOBILE_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
403
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
404
-    echo '  access_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
405
-    echo '  error_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
406
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
407
-    echo '  root /etc/share/ttrss-mobile;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
408
-    echo '  index index.html index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
409
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
410
-    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
411
-    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
412
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
413
-    echo '    fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
414
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
415
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
416
-    echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
417
-    echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
418
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
419
-    echo '  location /tt-rss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
420
-    echo '    try_files $uri $uri/ @ttrss_base;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
421
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
422
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
423
-    echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
424
-    echo '    rewrite ^(.*)$ /index.html?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
425
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
426
-    echo '  location @ttrss_base {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
427
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
428
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
429
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
430
-    echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
431
-    echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
432
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
433
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
434
-    echo '  add_header X-XSS-Protection "1; mode=block";' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
435
-    echo '  add_header X-Robots-Tag none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
436
-    echo '  add_header X-Download-Options noopen;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
437
-    echo '  add_header X-Permitted-Cross-Domain-Policies none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
438
-    echo '  add_header X-Frame-Options SAMEORIGIN;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
439
-    echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
440
-    echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
441
-    echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
442
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
443
-    echo 'server {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
444
-    echo "  listen 127.0.0.1:$RSS_READER_ONION_PORT default_server;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
445
-    echo "  server_name $RSS_READER_ONION_HOSTNAME;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
446
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
447
-    echo '  access_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
448
-    echo '  error_log /dev/null;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
449
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
450
-    echo '  root /etc/share/tt-rss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
451
-    echo '  index index.php;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
452
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
453
-    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
454
-    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
455
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
456
-    echo '    fastcgi_read_timeout 30;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
457
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
458
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
459
-    echo '  set $mobile_rewrite do_not_perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
460
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
461
-    echo '  ## chi http_user_agent for mobile / smart phones ##' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
462
-    echo '  if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
463
-    echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
464
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
465
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
466
-    echo '  if ($http_user_agent ~* "^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-)") {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
467
-    echo '    set $mobile_rewrite perform;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
468
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
469
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
470
-    echo '  if ($mobile_rewrite = perform) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
471
-    echo "    rewrite ^/(.*) http://$RSS_MOBILE_READER_ONION_HOSTNAME permanent;" >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
472
-    echo '    break;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
473
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
474
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
475
-    echo '  location ~ \.php {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
476
-    echo '    include snippets/fastcgi-php.conf;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
477
-    echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
478
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
479
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
480
-    echo '  location / {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
481
-    echo '    try_files $uri $uri/ @ttrss;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
482
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
483
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
484
-    echo '  location @ttrss {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
485
-    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
486
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
487
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
488
-    echo '  location ~ /\.(git) {' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
489
-    echo '    deny all;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
490
-    echo '  }' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
491
-    echo '' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
492
-    echo '  add_header X-XSS-Protection "1; mode=block";' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
493
-    echo '  add_header X-Robots-Tag none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
494
-    echo '  add_header X-Download-Options noopen;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
495
-    echo '  add_header X-Permitted-Cross-Domain-Policies none;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
496
-    echo '  add_header X-Frame-Options SAMEORIGIN;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
497
-    echo '  add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
498
-    echo '  client_max_body_size 15m;' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
499
-    echo '}' >> /etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME
404
+    { echo 'server {';
405
+      echo "  listen 127.0.0.1:$RSS_MOBILE_READER_ONION_PORT;";
406
+      echo "  server_name $RSS_MOBILE_READER_ONION_HOSTNAME;";
407
+      echo '';
408
+      echo '  access_log /dev/null;';
409
+      echo '  error_log /dev/null;';
410
+      echo '';
411
+      echo '  root /etc/share/ttrss-mobile;';
412
+      echo '  index index.html index.php;';
413
+      echo '';
414
+      echo '  location ~ \.php {';
415
+      echo '    include snippets/fastcgi-php.conf;';
416
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
417
+      echo '    fastcgi_read_timeout 30;';
418
+      echo '  }';
419
+      echo '';
420
+      echo '  location / {';
421
+      echo "    try_files \$uri \$uri/ @ttrss;";
422
+      echo '  }';
423
+      echo '  location /tt-rss {';
424
+      echo "    try_files \$uri \$uri/ @ttrss_base;";
425
+      echo '  }';
426
+      echo '';
427
+      echo '  location @ttrss {';
428
+      echo "    rewrite ^(.*)\$ /index.html?p=\$1 last;";
429
+      echo '  }';
430
+      echo '  location @ttrss_base {';
431
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
432
+      echo '  }';
433
+      echo '';
434
+      echo '  location ~ /\.(git) {';
435
+      echo '    deny all;';
436
+      echo '  }';
437
+      echo '';
438
+      echo '  add_header X-XSS-Protection "1; mode=block";';
439
+      echo '  add_header X-Robots-Tag none;';
440
+      echo '  add_header X-Download-Options noopen;';
441
+      echo '  add_header X-Permitted-Cross-Domain-Policies none;';
442
+      echo '  add_header X-Frame-Options SAMEORIGIN;';
443
+      echo '  add_header X-Content-Type-Options nosniff;';
444
+      echo '  client_max_body_size 15m;';
445
+      echo '}';
446
+      echo '';
447
+      echo 'server {';
448
+      echo "  listen 127.0.0.1:$RSS_READER_ONION_PORT default_server;";
449
+      echo "  server_name $RSS_READER_ONION_HOSTNAME;";
450
+      echo '';
451
+      echo '  access_log /dev/null;';
452
+      echo '  error_log /dev/null;';
453
+      echo '';
454
+      echo '  root /etc/share/tt-rss;';
455
+      echo '  index index.php;';
456
+      echo '';
457
+      echo '  location ~ \.php {';
458
+      echo '    include snippets/fastcgi-php.conf;';
459
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
460
+      echo '    fastcgi_read_timeout 30;';
461
+      echo '  }';
462
+      echo '';
463
+      echo "  set \$mobile_rewrite do_not_perform;";
464
+      echo '';
465
+      echo '  ## chi http_user_agent for mobile / smart phones ##';
466
+      echo "  if (\$http_user_agent ~* \"(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino\") {";
467
+      echo "    set \$mobile_rewrite perform;";
468
+      echo '  }';
469
+      echo '';
470
+      echo "  if (\$http_user_agent ~* \"^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-)\") {";
471
+      echo "    set \$mobile_rewrite perform;";
472
+      echo '  }';
473
+      echo '';
474
+      echo "  if (\$mobile_rewrite = perform) {";
475
+      echo "    rewrite ^/(.*) http://$RSS_MOBILE_READER_ONION_HOSTNAME permanent;";
476
+      echo '    break;';
477
+      echo '  }';
478
+      echo '';
479
+      echo '  location ~ \.php {';
480
+      echo '    include snippets/fastcgi-php.conf;';
481
+      echo '    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
482
+      echo '  }';
483
+      echo '';
484
+      echo '  location / {';
485
+      echo "    try_files \$uri \$uri/ @ttrss;";
486
+      echo '  }';
487
+      echo '';
488
+      echo '  location @ttrss {';
489
+      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
490
+      echo '  }';
491
+      echo '';
492
+      echo '  location ~ /\.(git) {';
493
+      echo '    deny all;';
494
+      echo '  }';
495
+      echo '';
496
+      echo '  add_header X-XSS-Protection "1; mode=block";';
497
+      echo '  add_header X-Robots-Tag none;';
498
+      echo '  add_header X-Download-Options noopen;';
499
+      echo '  add_header X-Permitted-Cross-Domain-Policies none;';
500
+      echo '  add_header X-Frame-Options SAMEORIGIN;';
501
+      echo '  add_header X-Content-Type-Options nosniff;';
502
+      echo '  client_max_body_size 15m;';
503
+      echo '}'; } > "/etc/nginx/sites-available/$RSS_READER_DOMAIN_NAME"
500 504
 
501 505
     if [ ! -f $RSS_READER_PATH/config.php ]; then
502 506
         # generate a config file
503 507
         RSS_FEED_CRYPT_KEY="$(create_password 24)"
504
-        echo '<?php' > $RSS_READER_PATH/config.php
505
-        echo "  define('_CURL_HTTP_PROXY', '127.0.0.1:9050');" >> $RSS_READER_PATH/config.php
506
-        echo "  define('DB_TYPE', 'mysql');" >> $RSS_READER_PATH/config.php
507
-        echo "  define('DB_HOST', 'localhost');" >> $RSS_READER_PATH/config.php
508
-        echo "  define('DB_USER', 'root');" >> $RSS_READER_PATH/config.php
509
-        echo "  define('DB_NAME', 'ttrss');" >> $RSS_READER_PATH/config.php
510
-        echo "  define('DB_PASS', '${MARIADB_PASSWORD}');" >> $RSS_READER_PATH/config.php
511
-        echo "  define('DB_PORT', '3306');" >> $RSS_READER_PATH/config.php
512
-        echo "  define('MYSQL_CHARSET', 'UTF8');" >> $RSS_READER_PATH/config.php
513
-        echo "  define('SELF_URL_PATH', 'http://${RSS_READER_ONION_HOSTNAME}/');" >> $RSS_READER_PATH/config.php
514
-        echo "  define('FEED_CRYPT_KEY', '${RSS_FEED_CRYPT_KEY}');" >> $RSS_READER_PATH/config.php
515
-        echo "  define('SINGLE_USER_MODE', false);" >> $RSS_READER_PATH/config.php
516
-        echo "  define('SIMPLE_UPDATE_MODE', false);" >> $RSS_READER_PATH/config.php
517
-        echo "  define('PHP_EXECUTABLE', '/usr/bin/php');" >> $RSS_READER_PATH/config.php
518
-        echo "  define('LOCK_DIRECTORY', 'lock');" >> $RSS_READER_PATH/config.php
519
-        echo "  define('CACHE_DIR', 'cache');" >> $RSS_READER_PATH/config.php
520
-        echo "  define('ICONS_DIR', \"feed-icons\");" >> $RSS_READER_PATH/config.php
521
-        echo "  define('ICONS_URL', \"feed-icons\");" >> $RSS_READER_PATH/config.php
522
-        echo "  define('AUTH_AUTO_CREATE', true);" >> $RSS_READER_PATH/config.php
523
-        echo "  define('AUTH_AUTO_LOGIN', true);" >> $RSS_READER_PATH/config.php
524
-        echo "  define('FORCE_ARTICLE_PURGE', 0);" >> $RSS_READER_PATH/config.php
525
-        echo "  define('PUBSUBHUBBUB_HUB', '');" >> $RSS_READER_PATH/config.php
526
-        echo "  define('PUBSUBHUBBUB_ENABLED', false);" >> $RSS_READER_PATH/config.php
527
-        echo "  define('SPHINX_SERVER', 'localhost:9312');" >> $RSS_READER_PATH/config.php
528
-        echo "  define('SPHINX_INDEX', 'ttrss, delta');" >> $RSS_READER_PATH/config.php
529
-        echo "  define('ENABLE_REGISTRATION', false);" >> $RSS_READER_PATH/config.php
530
-        echo "  define('REG_NOTIFY_ADDRESS', '${MY_EMAIL_ADDRESS}');" >> $RSS_READER_PATH/config.php
531
-        echo "  define('REG_MAX_USERS', 10);" >> $RSS_READER_PATH/config.php
532
-        echo "  define('SESSION_COOKIE_LIFETIME', 86400);" >> $RSS_READER_PATH/config.php
533
-        echo "  define('SMTP_FROM_NAME', 'Tiny Tiny RSS');" >> $RSS_READER_PATH/config.php
534
-        echo "  define('SMTP_FROM_ADDRESS', 'noreply@${RSS_READER_ONION_HOSTNAME}');" >> $RSS_READER_PATH/config.php
535
-        echo "  define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');" >> $RSS_READER_PATH/config.php
536
-        echo "  define('SMTP_SERVER', '');" >> $RSS_READER_PATH/config.php
537
-        echo "  define('SMTP_LOGIN', '');" >> $RSS_READER_PATH/config.php
538
-        echo "  define('SMTP_PASSWORD', '');" >> $RSS_READER_PATH/config.php
539
-        echo "  define('SMTP_SECURE', '');" >> $RSS_READER_PATH/config.php
540
-        echo "  define('CHECK_FOR_UPDATES', false);" >> $RSS_READER_PATH/config.php
541
-        echo "  define('ENABLE_GZIP_OUTPUT', false);" >> $RSS_READER_PATH/config.php
542
-        echo "  define('PLUGINS', 'auth_internal, note, gnusocial');" >> $RSS_READER_PATH/config.php
543
-        echo "  define('LOG_DESTINATION', 'sql');" >> $RSS_READER_PATH/config.php
544
-        echo "  define('CONFIG_VERSION', 26);" >> $RSS_READER_PATH/config.php
508
+        { echo '<?php';
509
+          echo "  define('_CURL_HTTP_PROXY', '127.0.0.1:9050');";
510
+          echo "  define('DB_TYPE', 'mysql');";
511
+          echo "  define('DB_HOST', 'localhost');";
512
+          echo "  define('DB_USER', 'root');";
513
+          echo "  define('DB_NAME', 'ttrss');";
514
+          echo "  define('DB_PASS', '${MARIADB_PASSWORD}');";
515
+          echo "  define('DB_PORT', '3306');";
516
+          echo "  define('MYSQL_CHARSET', 'UTF8');";
517
+          echo "  define('SELF_URL_PATH', 'http://${RSS_READER_ONION_HOSTNAME}/');";
518
+          echo "  define('FEED_CRYPT_KEY', '${RSS_FEED_CRYPT_KEY}');";
519
+          echo "  define('SINGLE_USER_MODE', false);";
520
+          echo "  define('SIMPLE_UPDATE_MODE', false);";
521
+          echo "  define('PHP_EXECUTABLE', '/usr/bin/php');";
522
+          echo "  define('LOCK_DIRECTORY', 'lock');";
523
+          echo "  define('CACHE_DIR', 'cache');";
524
+          echo "  define('ICONS_DIR', \"feed-icons\");";
525
+          echo "  define('ICONS_URL', \"feed-icons\");";
526
+          echo "  define('AUTH_AUTO_CREATE', true);";
527
+          echo "  define('AUTH_AUTO_LOGIN', true);";
528
+          echo "  define('FORCE_ARTICLE_PURGE', 0);";
529
+          echo "  define('PUBSUBHUBBUB_HUB', '');";
530
+          echo "  define('PUBSUBHUBBUB_ENABLED', false);";
531
+          echo "  define('SPHINX_SERVER', 'localhost:9312');";
532
+          echo "  define('SPHINX_INDEX', 'ttrss, delta');";
533
+          echo "  define('ENABLE_REGISTRATION', false);";
534
+          echo "  define('REG_NOTIFY_ADDRESS', '${MY_EMAIL_ADDRESS}');";
535
+          echo "  define('REG_MAX_USERS', 10);";
536
+          echo "  define('SESSION_COOKIE_LIFETIME', 86400);";
537
+          echo "  define('SMTP_FROM_NAME', 'Tiny Tiny RSS');";
538
+          echo "  define('SMTP_FROM_ADDRESS', 'noreply@${RSS_READER_ONION_HOSTNAME}');";
539
+          echo "  define('DIGEST_SUBJECT', '[tt-rss] New headlines for last 24 hours');";
540
+          echo "  define('SMTP_SERVER', '');";
541
+          echo "  define('SMTP_LOGIN', '');";
542
+          echo "  define('SMTP_PASSWORD', '');";
543
+          echo "  define('SMTP_SECURE', '');";
544
+          echo "  define('CHECK_FOR_UPDATES', false);";
545
+          echo "  define('ENABLE_GZIP_OUTPUT', false);";
546
+          echo "  define('PLUGINS', 'auth_internal, note, gnusocial');";
547
+          echo "  define('LOG_DESTINATION', 'sql');";
548
+          echo "  define('CONFIG_VERSION', 26);"; } > $RSS_READER_PATH/config.php
545 549
     fi
546 550
 
547 551
     # initialize the database
@@ -569,28 +573,28 @@ function install_rss_main {
569 573
     systemctl restart nginx
570 574
 
571 575
     # daemon to update feeds
572
-    echo '[Unit]' > /etc/systemd/system/ttrss.service
573
-    echo 'Description=ttrss_backend' >> /etc/systemd/system/ttrss.service
574
-    echo 'After=network.target mariadb.service' >> /etc/systemd/system/ttrss.service
575
-    echo 'After=tor.service' >> /etc/systemd/system/ttrss.service
576
-    echo '' >> /etc/systemd/system/ttrss.service
577
-    echo '[Service]' >> /etc/systemd/system/ttrss.service
578
-    echo 'User=www-data' >> /etc/systemd/system/ttrss.service
579
-    echo "ExecStart=/usr/bin/php $RSS_READER_PATH/update.php --daemon" >> /etc/systemd/system/ttrss.service
580
-    echo '' >> /etc/systemd/system/ttrss.service
581
-    echo '[Install]' >> /etc/systemd/system/ttrss.service
582
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/ttrss.service
576
+    { echo '[Unit]';
577
+      echo 'Description=ttrss_backend';
578
+      echo 'After=network.target mariadb.service';
579
+      echo 'After=tor.service';
580
+      echo '';
581
+      echo '[Service]';
582
+      echo 'User=www-data';
583
+      echo "ExecStart=/usr/bin/php $RSS_READER_PATH/update.php --daemon";
584
+      echo '';
585
+      echo '[Install]';
586
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/ttrss.service
583 587
     systemctl enable ttrss
584 588
     systemctl daemon-reload
585 589
     systemctl start ttrss
586 590
 
587
-    ${PROJECT_NAME}-pass -u $MY_USERNAME -a rss -p "$RSS_READER_ADMIN_PASSWORD"
591
+    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a rss -p "$RSS_READER_ADMIN_PASSWORD"
588 592
 
589 593
     install_completed rss_main
590 594
 }
591 595
 
592 596
 function install_rss_gnusocial {
593
-    if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
597
+    if [ ! "$GNUSOCIAL_DOMAIN_NAME" ]; then
594 598
         return
595 599
     fi
596 600
 
@@ -604,23 +608,23 @@ function install_rss_gnusocial {
604 608
     set_repo_commit $RSS_READER_GNUSOCIAL_PATH "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT" $RSS_READER_GNUSOCIAL_REPO
605 609
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
606 610
 
607
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
611
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
608 612
         return
609 613
     fi
610 614
 
611
-    if [ ! -d $INSTALL_DIR ]; then
612
-        mkdir -p $INSTALL_DIR
615
+    if [ ! -d "$INSTALL_DIR" ]; then
616
+        mkdir -p "$INSTALL_DIR"
613 617
     fi
614 618
 
615
-    cd $INSTALL_DIR
619
+    cd "$INSTALL_DIR" || exit 7246284
616 620
     function_check git_clone
617 621
     git_clone $RSS_READER_GNUSOCIAL_REPO ttrss-gnusocial
618
-    if [ ! -d $INSTALL_DIR/ttrss-gnusocial ]; then
622
+    if [ ! -d "$INSTALL_DIR/ttrss-gnusocial" ]; then
619 623
         echo $'Could not clone repo for RSS reader gnusocial plugin'
620 624
         exit 52838
621 625
     fi
622
-    cp -r $INSTALL_DIR/ttrss-gnusocial $RSS_READER_GNUSOCIAL_PATH
623
-    cd $RSS_READER_GNUSOCIAL_PATH
626
+    cp -r "$INSTALL_DIR/ttrss-gnusocial" $RSS_READER_GNUSOCIAL_PATH
627
+    cd "$RSS_READER_GNUSOCIAL_PATH" || exit 782462424
624 628
     git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
625 629
     set_completion_param "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT"
626 630
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
@@ -642,22 +646,22 @@ function install_rss_mobile_reader {
642 646
     # remove any previous install
643 647
     if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
644 648
         if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
645
-            sed -i '/install_rss_mobile_reader/d' $COMPLETION_FILE
646
-            sed -i '/rss mobile reader commit/d' $COMPLETION_FILE
649
+            sed -i '/install_rss_mobile_reader/d' "$COMPLETION_FILE"
650
+            sed -i '/rss mobile reader commit/d' "$COMPLETION_FILE"
647 651
             rm -rf $RSS_READER_PATH/g2ttree-mobile
648 652
         fi
649 653
     fi
650 654
 
651
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
655
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
652 656
         return
653 657
     fi
654 658
 
655
-    cd /etc/share
659
+    cd /etc/share || exit 7498264462
656 660
 
657 661
     if [ -d /repos/rss-mobile ]; then
658 662
         mkdir ttrss-mobile
659 663
         cp -r -p /repos/rss-mobile/. ttrss-mobile
660
-        cd ttrss-mobile
664
+        cd ttrss-mobile || exit 462846284682
661 665
         git pull
662 666
     else
663 667
         function_check git_clone
@@ -668,7 +672,7 @@ function install_rss_mobile_reader {
668 672
         echo $'Could not clone RSS mobile reader repo'
669 673
         exit 24816
670 674
     fi
671
-    cd $RSS_MOBILE_READER_PATH
675
+    cd "$RSS_MOBILE_READER_PATH" || exit 462846246824
672 676
     git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
673 677
     set_completion_param "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT"
674 678
 

+ 173
- 168
src/freedombone-app-scuttlebot Просмотреть файл

@@ -61,39 +61,44 @@ function scuttlebot_create_invite {
61 61
     invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
62 62
 
63 63
     clear
64
-    echo -e '\n\nYour Scuttlebot invite code is:\n\n'${invite_string}'\n\n'
64
+    echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${invite_string}\\n\\n"
65
+    # shellcheck disable=SC2034
65 66
     read -n1 -r -p $"Press any key to continue..." key
66 67
 }
67 68
 
68 69
 function configure_interactive_scuttlebot {
69 70
     while true
70 71
     do
71
-        data=$(tempfile 2>/dev/null)
72
-        trap "rm -f $data" 0 1 2 5 15
72
+        data=$(mktemp 2>/dev/null)
73 73
         dialog --backtitle $"Freedombone Control Panel" \
74 74
                --title $"Scuttlebot" \
75 75
                --radiolist $"Choose an operation:" 10 50 2 \
76 76
                1 $"Create an invite" off \
77
-               2 $"Exit" on 2> $data
77
+               2 $"Exit" on 2> "$data"
78 78
         sel=$?
79 79
         case $sel in
80
-            1) return;;
81
-            255) return;;
80
+            1) rm -f "$data"
81
+               return;;
82
+            255) rm -f "$data"
83
+                 return;;
82 84
         esac
83
-        case $(cat $data) in
85
+        case $(cat "$data") in
84 86
             1) scuttlebot_create_invite;;
85
-            2) break;;
87
+            2) rm -f "$data"
88
+               break;;
86 89
         esac
90
+        rm -f "$data"
87 91
     done
88 92
 }
89 93
 
90 94
 function remove_user_scuttlebot {
91
-    remove_username="$1"
95
+    echo -n ''
96
+#    remove_username="$1"
92 97
 }
93 98
 
94 99
 function add_user_scuttlebot {
95
-    new_username="$1"
96
-    new_user_password="$2"
100
+#    new_username="$1"
101
+#    new_user_password="$2"
97 102
     echo '0'
98 103
 }
99 104
 
@@ -109,8 +114,8 @@ function install_interactive_scuttlebot {
109 114
 }
110 115
 
111 116
 function change_password_scuttlebot {
112
-    new_username="$1"
113
-    new_user_password="$2"
117
+#    new_username="$1"
118
+#    new_user_password="$2"
114 119
     echo '0'
115 120
 }
116 121
 
@@ -123,7 +128,7 @@ function reconfigure_scuttlebot {
123 128
 }
124 129
 
125 130
 function upgrade_scuttlebot {
126
-    if ! grep -q 'scuttlebot version:' $COMPLETION_FILE; then
131
+    if ! grep -q 'scuttlebot version:' $"COMPLETION_FILE"; then
127 132
         return
128 133
     fi
129 134
 
@@ -134,11 +139,10 @@ function upgrade_scuttlebot {
134 139
         return
135 140
     fi
136 141
 
137
-    npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save
138
-    if [ ! "$?" = "0" ]; then
142
+    if ! npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save; then
139 143
         return
140 144
     fi
141
-    sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
145
+    sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
142 146
 }
143 147
 
144 148
 function backup_local_scuttlebot {
@@ -218,71 +222,72 @@ function remove_scuttlebot {
218 222
     fi
219 223
 
220 224
     remove_completion_param install_scuttlebot
221
-    sed -i '/scuttlebot /d' $COMPLETION_FILE
225
+    sed -i '/scuttlebot /d' "$COMPLETION_FILE"
222 226
 }
223 227
 
224 228
 function git_ssb_script {
225 229
     if [[ "$1" == "mesh" ]]; then
230
+        # shellcheck disable=SC2154
226 231
         git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
227 232
         git_ssb_daemon_filename=$rootdir/etc/systemd/system/git_ssb.service
228 233
     else
229 234
         git_ssb_script_name=/usr/bin/git-ssb-create
230 235
         git_ssb_daemon_filename=/etc/systemd/system/git_ssb.service
231 236
     fi
232
-    echo '#!/bin/bash' > $git_ssb_script_name
233
-    echo 'reponame="$1"' >> $git_ssb_script_name
234
-    echo '' >> $git_ssb_script_name
235
-    echo 'if [[ "$reponame" != "" ]]; then' >> $git_ssb_script_name
236
-    echo '  mkdir $reponame' >> $git_ssb_script_name
237
-    echo '  cd $reponame' >> $git_ssb_script_name
238
-    echo '  git init' >> $git_ssb_script_name
239
-    echo '  git ssb create ssb $reponame' >> $git_ssb_script_name
240
-    echo '  git push --tags ssb master' >> $git_ssb_script_name
241
-    echo 'fi' >> $git_ssb_script_name
242
-    echo 'exit 0' >> $git_ssb_script_name
237
+    { echo '#!/bin/bash';
238
+      echo "reponame=\"\$1\"";
239
+      echo '';
240
+      echo "if [[ \"\$reponame\" != \"\" ]]; then";
241
+      echo "  mkdir \$reponame";
242
+      echo "  cd \$reponame";
243
+      echo '  git init';
244
+      echo "  git ssb create ssb \$reponame";
245
+      echo '  git push --tags ssb master';
246
+      echo 'fi';
247
+      echo 'exit 0'; } > $git_ssb_script_name
243 248
     chmod +x $git_ssb_script_name
244 249
 
245
-    echo '[Unit]' > $git_ssb_daemon_filename
246
-    echo 'Description=Git SSB (SSB git web interface)' >> $git_ssb_daemon_filename
247
-    echo 'After=syslog.target' >> $git_ssb_daemon_filename
248
-    echo 'After=network.target' >> $git_ssb_daemon_filename
249
-    echo 'After=scuttlebot.target' >> $git_ssb_daemon_filename
250
-    echo '' >> $git_ssb_daemon_filename
251
-    echo '[Service]' >> $git_ssb_daemon_filename
252
-    echo 'Type=simple' >> $git_ssb_daemon_filename
253
-    echo 'User=scuttlebot' >> $git_ssb_daemon_filename
254
-    echo 'Group=scuttlebot' >> $git_ssb_daemon_filename
255
-    echo "WorkingDirectory=/etc/scuttlebot" >> $git_ssb_daemon_filename
256
-    echo "ExecStart=/usr/bin/git ssb web --public localhost:$GIT_SSB_PORT" >> $git_ssb_daemon_filename
257
-    echo 'Restart=always' >> $git_ssb_daemon_filename
258
-    echo 'Environment="USER=scuttlebot"' >> $git_ssb_daemon_filename
259
-    echo '' >> $git_ssb_daemon_filename
260
-    echo '[Install]' >> $git_ssb_daemon_filename
261
-    echo 'WantedBy=multi-user.target' >> $git_ssb_daemon_filename
250
+    { echo '[Unit]';
251
+      echo 'Description=Git SSB (SSB git web interface)';
252
+      echo 'After=syslog.target';
253
+      echo 'After=network.target';
254
+      echo 'After=scuttlebot.target';
255
+      echo '';
256
+      echo '[Service]';
257
+      echo 'Type=simple';
258
+      echo 'User=scuttlebot';
259
+      echo 'Group=scuttlebot';
260
+      echo "WorkingDirectory=/etc/scuttlebot";
261
+      echo "ExecStart=/usr/bin/git ssb web --public localhost:$GIT_SSB_PORT";
262
+      echo 'Restart=always';
263
+      echo 'Environment="USER=scuttlebot"';
264
+      echo '';
265
+      echo '[Install]';
266
+      echo 'WantedBy=multi-user.target'; } > $git_ssb_daemon_filename
262 267
 }
263 268
 
264 269
 function scuttlebot_git_setup {
265 270
     if [[ "$1" == "mesh" ]]; then
266
-        if [ ! -d $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight ]; then
267
-            mkdir $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight
271
+        if [ ! -d "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight" ]; then
272
+            mkdir "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight"
268 273
         fi
269
-        if [ ! -f $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css ]; then
274
+        if [ ! -f "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css" ]; then
270 275
             echo $'Could not find foundation.css'
271 276
             exit 347687245
272 277
         fi
273
-        cp $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css $rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css
278
+        cp "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/highlight.js/styles/foundation.css" "$rootdir/usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web/highlight/foundation.css"
274 279
 
275 280
         git_ssb_nginx_site=$rootdir/etc/nginx/sites-available/git_ssb
276
-        echo 'server {' > $git_ssb_nginx_site
277
-        echo "  listen $NGINX_GIT_SSB_PORT default_server;" >> $git_ssb_nginx_site
278
-        echo "  server_name P${PEER_ID}.local;" >> $git_ssb_nginx_site
279
-        echo '' >> $git_ssb_nginx_site
280
-        echo '  access_log /dev/null;' >> $git_ssb_nginx_site
281
-        echo '  error_log /dev/null;' >> $git_ssb_nginx_site
282
-        echo '' >> $git_ssb_nginx_site
283
-        echo '  add_header X-XSS-Protection "1; mode=block";' >> $git_ssb_nginx_site
284
-        echo '  add_header X-Content-Type-Options nosniff;' >> $git_ssb_nginx_site
285
-        echo '  add_header X-Frame-Options SAMEORIGIN;' >> $git_ssb_nginx_site
281
+        { echo 'server {';
282
+          echo "  listen $NGINX_GIT_SSB_PORT default_server;";
283
+          echo "  server_name P${PEER_ID}.local;";
284
+          echo '';
285
+          echo '  access_log /dev/null;';
286
+          echo '  error_log /dev/null;';
287
+          echo '';
288
+          echo '  add_header X-XSS-Protection "1; mode=block";';
289
+          echo '  add_header X-Content-Type-Options nosniff;';
290
+          echo '  add_header X-Frame-Options SAMEORIGIN;'; } > "$git_ssb_nginx_site"
286 291
     else
287 292
         if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
288 293
             exit 7357225
@@ -300,15 +305,15 @@ function scuttlebot_git_setup {
300 305
         git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
301 306
         function_check nginx_http_redirect
302 307
         nginx_http_redirect $SCUTTLEBOT_DOMAIN_NAME "index index.html"
303
-        echo 'server {' >> $git_ssb_nginx_site
304
-        echo '  listen 443 ssl;' >> $git_ssb_nginx_site
305
-        echo '  #listen [::]:443 ssl;' >> $git_ssb_nginx_site
306
-        echo "  server_name $SCUTTLEBOT_DOMAIN_NAME;" >> $git_ssb_nginx_site
307
-        echo '' >> $git_ssb_nginx_site
308
+        { echo 'server {';
309
+          echo '  listen 443 ssl;';
310
+          echo '  #listen [::]:443 ssl;';
311
+          echo "  server_name $SCUTTLEBOT_DOMAIN_NAME;";
312
+          echo ''; } >> $git_ssb_nginx_site
308 313
         function_check nginx_compress
309 314
         nginx_compress $SCUTTLEBOT_DOMAIN_NAME
310
-        echo '' >> $git_ssb_nginx_site
311
-        echo '  # Security' >> $git_ssb_nginx_site
315
+        echo '' >> "$git_ssb_nginx_site"
316
+        echo '  # Security' >> "$git_ssb_nginx_site"
312 317
         function_check nginx_ssl
313 318
         nginx_ssl $SCUTTLEBOT_DOMAIN_NAME
314 319
 
@@ -316,45 +321,45 @@ function scuttlebot_git_setup {
316 321
         nginx_disable_sniffing $SCUTTLEBOT_DOMAIN_NAME
317 322
     fi
318 323
 
319
-    echo '' >> $git_ssb_nginx_site
320
-    echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;' >> $git_ssb_nginx_site
321
-    echo '' >> $git_ssb_nginx_site
322
-    echo '  location = / {' >> $git_ssb_nginx_site
323
-    echo "    proxy_pass http://localhost:${GIT_SSB_PORT};" >> $git_ssb_nginx_site
324
-    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $git_ssb_nginx_site
325
-    echo '    proxy_set_header Host $host;' >> $git_ssb_nginx_site
326
-    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $git_ssb_nginx_site
327
-    echo '    proxy_http_version 1.1;' >> $git_ssb_nginx_site
328
-    echo '    proxy_set_header Upgrade $http_upgrade;' >> $git_ssb_nginx_site
329
-    echo '    proxy_set_header Connection upgrade;' >> $git_ssb_nginx_site
330
-    echo '  }' >> $git_ssb_nginx_site
331
-    echo '}' >> $git_ssb_nginx_site
332
-
333
-    if [ $SCUTTLEBOT_ONION_HOSTNAME ]; then
334
-        echo '' >> $git_ssb_nginx_site
335
-        echo 'server {' >> $git_ssb_nginx_site
336
-        echo "  listen 127.0.0.1:${SCUTTLEBOT_ONION_PORT} default_server;" >> $git_ssb_nginx_site
337
-        echo "  server_name ${SCUTTLEBOT_ONION_HOSTNAME};" >> $git_ssb_nginx_site
338
-        echo '' >> $git_ssb_nginx_site
339
-        echo '  access_log /dev/null;' >> $git_ssb_nginx_site
340
-        echo '  error_log /dev/null;' >> $git_ssb_nginx_site
341
-        echo '' >> $git_ssb_nginx_site
342
-        echo '  add_header X-XSS-Protection "1; mode=block";' >> $git_ssb_nginx_site
343
-        echo '  add_header X-Content-Type-Options nosniff;' >> $git_ssb_nginx_site
344
-        echo '  add_header X-Frame-Options SAMEORIGIN;' >> $git_ssb_nginx_site
345
-        echo '' >> $git_ssb_nginx_site
346
-        echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;' >> $git_ssb_nginx_site
347
-        echo '' >> $git_ssb_nginx_site
348
-        echo '  location = / {' >> $git_ssb_nginx_site
349
-        echo "    proxy_pass http://localhost:${GIT_SSB_PORT};" >> $git_ssb_nginx_site
350
-        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $git_ssb_nginx_site
351
-        echo '    proxy_set_header Host $host;' >> $git_ssb_nginx_site
352
-        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $git_ssb_nginx_site
353
-        echo '    proxy_http_version 1.1;' >> $git_ssb_nginx_site
354
-        echo '    proxy_set_header Upgrade $http_upgrade;' >> $git_ssb_nginx_site
355
-        echo '    proxy_set_header Connection upgrade;' >> $git_ssb_nginx_site
356
-        echo '  }' >> $git_ssb_nginx_site
357
-        echo '}' >> $git_ssb_nginx_site
324
+    { echo '';
325
+      echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;';
326
+      echo '';
327
+      echo '  location = / {';
328
+      echo "    proxy_pass http://localhost:${GIT_SSB_PORT};";
329
+      echo "    proxy_set_header X-Real-IP \$remote_addr;";
330
+      echo "    proxy_set_header Host \$host;";
331
+      echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
332
+      echo '    proxy_http_version 1.1;';
333
+      echo "    proxy_set_header Upgrade \$http_upgrade;";
334
+      echo '    proxy_set_header Connection upgrade;';
335
+      echo '  }';
336
+      echo '}'; } >> $git_ssb_nginx_site
337
+
338
+    if [ "$SCUTTLEBOT_ONION_HOSTNAME" ]; then
339
+        { echo '';
340
+          echo 'server {';
341
+          echo "  listen 127.0.0.1:${SCUTTLEBOT_ONION_PORT} default_server;";
342
+          echo "  server_name ${SCUTTLEBOT_ONION_HOSTNAME};";
343
+          echo '';
344
+          echo '  access_log /dev/null;';
345
+          echo '  error_log /dev/null;';
346
+          echo '';
347
+          echo '  add_header X-XSS-Protection "1; mode=block";';
348
+          echo '  add_header X-Content-Type-Options nosniff;';
349
+          echo '  add_header X-Frame-Options SAMEORIGIN;';
350
+          echo '';
351
+          echo '  root /usr/local/lib/node_modules/git-ssb/node_modules/git-ssb-web;';
352
+          echo '';
353
+          echo '  location = / {';
354
+          echo "    proxy_pass http://localhost:${GIT_SSB_PORT};";
355
+          echo "    proxy_set_header X-Real-IP \$remote_addr;";
356
+          echo "    proxy_set_header Host \$host;";
357
+          echo "    proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
358
+          echo '    proxy_http_version 1.1;';
359
+          echo "    proxy_set_header Upgrade \$http_upgrade;";
360
+          echo '    proxy_set_header Connection upgrade;';
361
+          echo '  }';
362
+          echo '}'; } >> $git_ssb_nginx_site
358 363
     fi
359 364
     if [[ "$1" != "mesh" ]]; then
360 365
         nginx_ensite git_ssb
@@ -364,23 +369,23 @@ function scuttlebot_git_setup {
364 369
 function mesh_install_dat {
365 370
     get_npm_arch
366 371
 
367
-    cat <<EOF > $rootdir/usr/bin/install_dat
372
+    cat <<EOF > "$rootdir/usr/bin/install_dat"
368 373
 #!/bin/bash
369 374
 npm install --arch=$NPM_ARCH -g dat
370 375
 npm install --arch=$NPM_ARCH -g @garbados/dat-boi
371 376
 npm install --arch=$NPM_ARCH -g add-to-systemd
372
-add-to-systemd dat-boi --user $(whoami) `which dat-boi`
377
+add-to-systemd dat-boi --user "$(whoami)" "$(which dat-boi)"
373 378
 EOF
374 379
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
375 380
     chroot "$rootdir" /usr/bin/install_dat
376
-    rm $rootdir/usr/bin/install_dat
381
+    rm "$rootdir/usr/bin/install_dat"
377 382
 }
378 383
 
379 384
 function install_dat {
380 385
     npm install -g dat
381 386
     npm install -g @garbados/dat-boi
382 387
     npm install -g add-to-systemd
383
-    add-to-systemd dat-boi --user $(whoami) `which dat-boi`
388
+    add-to-systemd dat-boi --user "$(whoami)" "$(which dat-boi)"
384 389
 }
385 390
 
386 391
 function mesh_install_scuttlebot {
@@ -390,7 +395,7 @@ function mesh_install_scuttlebot {
390 395
 
391 396
     get_npm_arch
392 397
 
393
-    cat <<EOF > $rootdir/usr/bin/install_scuttlebot
398
+    cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
394 399
 #!/bin/bash
395 400
 npm install --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}
396 401
 npm install --arch=$NPM_ARCH -g git-ssb
@@ -398,37 +403,37 @@ npm install --arch=$NPM_ARCH -g git-remote-ssb
398 403
 EOF
399 404
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
400 405
     chroot "$rootdir" /usr/bin/install_scuttlebot
401
-    rm $rootdir/usr/bin/install_scuttlebot
406
+    rm "$rootdir/usr/bin/install_scuttlebot"
402 407
 
403
-    if [ ! -f $rootdir/usr/local/bin/sbot ]; then
408
+    if [ ! -f "$rootdir/usr/local/bin/sbot" ]; then
404 409
         echo $'Scuttlebot was not installed'
405 410
         exit 528253
406 411
     fi
407 412
 
408
-    if [ ! -d $rootdir/etc/scuttlebot ]; then
409
-        mkdir -p $rootdir/etc/scuttlebot
413
+    if [ ! -d "$rootdir/etc/scuttlebot" ]; then
414
+        mkdir -p "$rootdir/etc/scuttlebot"
410 415
     fi
411 416
 
412 417
     # an unprivileged user to run as
413 418
     chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
414 419
 
415 420
     # daemon
416
-    echo '[Unit]' > $rootdir/etc/systemd/system/scuttlebot.service
417
-    echo 'Description=Scuttlebot (messaging system)' >> $rootdir/etc/systemd/system/scuttlebot.service
418
-    echo 'After=syslog.target' >> $rootdir/etc/systemd/system/scuttlebot.service
419
-    echo 'After=network.target' >> $rootdir/etc/systemd/system/scuttlebot.service
420
-    echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
421
-    echo '[Service]' >> $rootdir/etc/systemd/system/scuttlebot.service
422
-    echo 'Type=simple' >> $rootdir/etc/systemd/system/scuttlebot.service
423
-    echo 'User=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
424
-    echo 'Group=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
425
-    echo "WorkingDirectory=/etc/scuttlebot" >> $rootdir/etc/systemd/system/scuttlebot.service
426
-    echo 'ExecStart=/usr/local/bin/sbot server' >> $rootdir/etc/systemd/system/scuttlebot.service
427
-    echo 'Restart=always' >> $rootdir/etc/systemd/system/scuttlebot.service
428
-    echo 'Environment="USER=scuttlebot"' >> $rootdir/etc/systemd/system/scuttlebot.service
429
-    echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
430
-    echo '[Install]' >> $rootdir/etc/systemd/system/scuttlebot.service
431
-    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/scuttlebot.service
421
+    { echo '[Unit]';
422
+      echo 'Description=Scuttlebot (messaging system)';
423
+      echo 'After=syslog.target';
424
+      echo 'After=network.target';
425
+      echo '';
426
+      echo '[Service]';
427
+      echo 'Type=simple';
428
+      echo 'User=scuttlebot';
429
+      echo 'Group=scuttlebot';
430
+      echo "WorkingDirectory=/etc/scuttlebot";
431
+      echo 'ExecStart=/usr/local/bin/sbot server';
432
+      echo 'Restart=always';
433
+      echo 'Environment="USER=scuttlebot"';
434
+      echo '';
435
+      echo '[Install]';
436
+      echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/scuttlebot.service"
432 437
 
433 438
     scuttlebot_git_setup mesh
434 439
     git_ssb_script mesh
@@ -455,22 +460,22 @@ function install_scuttlebot {
455 460
     useradd -d /etc/scuttlebot/ scuttlebot
456 461
 
457 462
     # daemon
458
-    echo '[Unit]' > /etc/systemd/system/scuttlebot.service
459
-    echo 'Description=Scuttlebot (messaging system)' >> /etc/systemd/system/scuttlebot.service
460
-    echo 'After=syslog.target' >> /etc/systemd/system/scuttlebot.service
461
-    echo 'After=network.target' >> /etc/systemd/system/scuttlebot.service
462
-    echo '' >> /etc/systemd/system/scuttlebot.service
463
-    echo '[Service]' >> /etc/systemd/system/scuttlebot.service
464
-    echo 'Type=simple' >> /etc/systemd/system/scuttlebot.service
465
-    echo 'User=scuttlebot' >> /etc/systemd/system/scuttlebot.service
466
-    echo 'Group=scuttlebot' >> /etc/systemd/system/scuttlebot.service
467
-    echo "WorkingDirectory=/etc/scuttlebot" >> /etc/systemd/system/scuttlebot.service
468
-    echo 'ExecStart=/usr/local/bin/sbot server' >> /etc/systemd/system/scuttlebot.service
469
-    echo 'Restart=always' >> /etc/systemd/system/scuttlebot.service
470
-    echo 'Environment="USER=scuttlebot"' >> /etc/systemd/system/scuttlebot.service
471
-    echo '' >> /etc/systemd/system/scuttlebot.service
472
-    echo '[Install]' >> /etc/systemd/system/scuttlebot.service
473
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/scuttlebot.service
463
+    { echo '[Unit]';
464
+      echo 'Description=Scuttlebot (messaging system)';
465
+      echo 'After=syslog.target';
466
+      echo 'After=network.target';
467
+      echo '';
468
+      echo '[Service]';
469
+      echo 'Type=simple';
470
+      echo 'User=scuttlebot';
471
+      echo 'Group=scuttlebot';
472
+      echo "WorkingDirectory=/etc/scuttlebot";
473
+      echo 'ExecStart=/usr/local/bin/sbot server';
474
+      echo 'Restart=always';
475
+      echo 'Environment="USER=scuttlebot"';
476
+      echo '';
477
+      echo '[Install]';
478
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/scuttlebot.service
474 479
 
475 480
     chown -R scuttlebot:scuttlebot /etc/scuttlebot
476 481
 
@@ -489,24 +494,24 @@ function install_scuttlebot {
489 494
         exit 73528
490 495
     fi
491 496
 
492
-    echo '{' > /etc/scuttlebot/.ssb/config
493
-    echo "  \"host\": \"${DEFAULT_DOMAIN_NAME}\"," >> /etc/scuttlebot/.ssb/config
494
-    echo "  \"port\": ${SCUTTLEBOT_PORT}," >> /etc/scuttlebot/.ssb/config
495
-    echo '  "timeout": 30000,' >> /etc/scuttlebot/.ssb/config
496
-    echo '  "pub": true,' >> /etc/scuttlebot/.ssb/config
497
-    echo '  "local": true,' >> /etc/scuttlebot/.ssb/config
498
-    echo '  "friends": {' >> /etc/scuttlebot/.ssb/config
499
-    echo '    "dunbar": 150,' >> /etc/scuttlebot/.ssb/config
500
-    echo '    "hops": 3' >> /etc/scuttlebot/.ssb/config
501
-    echo '  },' >> /etc/scuttlebot/.ssb/config
502
-    echo '  "gossip": {' >> /etc/scuttlebot/.ssb/config
503
-    echo '    "connections": 2' >> /etc/scuttlebot/.ssb/config
504
-    echo '  },' >> /etc/scuttlebot/.ssb/config
505
-    echo '  "master": [],' >> /etc/scuttlebot/.ssb/config
506
-    echo '  "logging": {' >> /etc/scuttlebot/.ssb/config
507
-    echo '    "level": "error"' >> /etc/scuttlebot/.ssb/config
508
-    echo '  }' >> /etc/scuttlebot/.ssb/config
509
-    echo '}' >> /etc/scuttlebot/.ssb/config
497
+    { echo '{';
498
+      echo "  \"host\": \"${DEFAULT_DOMAIN_NAME}\",";
499
+      echo "  \"port\": ${SCUTTLEBOT_PORT},";
500
+      echo '  "timeout": 30000,';
501
+      echo '  "pub": true,';
502
+      echo '  "local": true,';
503
+      echo '  "friends": {';
504
+      echo '    "dunbar": 150,';
505
+      echo '    "hops": 3';
506
+      echo '  },';
507
+      echo '  "gossip": {';
508
+      echo '    "connections": 2';
509
+      echo '  },';
510
+      echo '  "master": [],';
511
+      echo '  "logging": {';
512
+      echo '    "level": "error"';
513
+      echo '  }';
514
+      echo '}'; } > /etc/scuttlebot/.ssb/config
510 515
     chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
511 516
     systemctl restart scuttlebot.service
512 517
 
@@ -527,10 +532,10 @@ function install_scuttlebot {
527 532
 
528 533
     systemctl restart nginx
529 534
 
530
-    if ! grep -q "scuttlebot version:" ${COMPLETION_FILE}; then
531
-        echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> ${COMPLETION_FILE}
535
+    if ! grep -q "scuttlebot version:" "${COMPLETION_FILE}"; then
536
+        echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> "${COMPLETION_FILE}"
532 537
     else
533
-        sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
538
+        sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
534 539
     fi
535 540
 
536 541
     APP_INSTALLED=1

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


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

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

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

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

+ 202
- 206
src/freedombone-app-tox Просмотреть файл

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

+ 95
- 87
src/freedombone-app-turtl Просмотреть файл

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

+ 62
- 60
src/freedombone-app-vim Просмотреть файл

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

+ 218
- 210
src/freedombone-app-vpn Просмотреть файл

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

+ 0
- 498
src/freedombone-app-wekan Просмотреть файл

@@ -1,498 +0,0 @@
1
-#!/bin/bash
2
-#
3
-# .---.                  .              .
4
-# |                      |              |
5
-# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
-# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
-# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
-#
9
-#                    Freedom in the Cloud
10
-#
11
-# Wekan kanban
12
-#
13
-# License
14
-# =======
15
-#
16
-# Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
17
-#
18
-# This program is free software: you can redistribute it and/or modify
19
-# it under the terms of the GNU Affero General Public License as published by
20
-# the Free Software Foundation, either version 3 of the License, or
21
-# (at your option) any later version.
22
-#
23
-# This program is distributed in the hope that it will be useful,
24
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
-# GNU Affero General Public License for more details.
27
-#
28
-# You should have received a copy of the GNU Affero General Public License
29
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
-
31
-VARIANTS=''
32
-
33
-IN_DEFAULT_INSTALL=0
34
-SHOW_ON_ABOUT=0
35
-
36
-WEKAN_DOMAIN_NAME=
37
-WEKAN_CODE=
38
-WEKAN_PORT=8081
39
-WEKAN_ONION_PORT=8120
40
-WEKAN_REPO="https://github.com/wekan/wekan"
41
-WEKAN_COMMIT='dc547c38d1f5ca72729f6d8f81eb03671ca15934'
42
-FLOW_ROUTER_REPO="git://github.com/wekan/flow-router.git"
43
-FLOW_ROUTER_COMMIT='0c1f6423ed9b68eb00cfb1a19492438917a38956'
44
-WEKAN_DIR=/etc/wekan
45
-
46
-wekan_variables=(ONION_ONLY
47
-                 WEKAN_DOMAIN_NAME
48
-                 WEKAN_CODE
49
-                 DDNS_PROVIDER
50
-                 MY_USERNAME)
51
-
52
-function logging_on_wekan {
53
-    echo -n ''
54
-}
55
-
56
-function logging_off_wekan {
57
-    echo -n ''
58
-}
59
-
60
-function remove_user_wekan {
61
-    remove_username="$1"
62
-}
63
-
64
-function add_user_wekan {
65
-    new_username="$1"
66
-    new_user_password="$2"
67
-    echo '0'
68
-}
69
-
70
-function install_interactive_wekan {
71
-    if [[ $ONION_ONLY != "no" ]]; then
72
-        GIT_DOMAIN_NAME='wekan.local'
73
-        write_config_param "WEKAN_DOMAIN_NAME" "$WEKAN_DOMAIN_NAME"
74
-    else
75
-        function_check interactive_site_details
76
-        interactive_site_details wekan
77
-    fi
78
-    APP_INSTALLED=1
79
-}
80
-
81
-function change_password_wekan {
82
-    curr_username="$1"
83
-    new_user_password="$2"
84
-}
85
-
86
-function reconfigure_wekan {
87
-    echo -n ''
88
-}
89
-
90
-function upgrade_wekan {
91
-    CURR_WEKAN_COMMIT=$(get_completion_param "wekan commit")
92
-    if [[ "$CURR_WEKAN_COMMIT" == "$WEKAN_COMMIT" ]]; then
93
-        return
94
-    fi
95
-
96
-    systemctl stop wekan
97
-
98
-    # update to the next commit
99
-    function_check set_repo_commit
100
-    set_repo_commit $WEKAN_DIR "wekan commit" "$WEKAN_COMMIT" $WEKAN_REPO
101
-
102
-    systemctl start wekan
103
-}
104
-
105
-function backup_local_wekan {
106
-    source_directory=$WEKAN_DIR/data
107
-    if [ -d $source_directory ]; then
108
-        systemctl stop wekan
109
-
110
-        dest_directory=wekan
111
-        function_check suspend_site
112
-        suspend_site wekan
113
-
114
-        function_check backup_database_to_usb
115
-        backup_database_to_usb wekan
116
-
117
-        function_check backup_directory_to_usb
118
-        backup_directory_to_usb $source_directory $dest_directory
119
-
120
-        function_check restart_site
121
-        restart_site
122
-
123
-        systemctl start wekan
124
-    fi
125
-}
126
-
127
-function restore_local_wekan {
128
-    if [ -d $WEKAN_DIR ]; then
129
-        systemctl stop wekan
130
-
131
-        function_check restore_database
132
-        restore_database gogs ${WEKAN_DOMAIN_NAME}
133
-
134
-        temp_restore_dir=/root/tempwekan
135
-        function_check restore_directory_from_usb
136
-        restore_directory_from_usb $temp_restore_dir wekan
137
-        if [ -d $temp_restore_dir$WEKAN_DIR/data ]; then
138
-            cp -r $temp_restore_dir$WEKAN_DIR/data/* $WEKAN_DIR/data/
139
-        else
140
-            cp -r $temp_restore_dir/* $WEKAN_DIR/data/
141
-        fi
142
-        rm -rf $temp_restore_dir
143
-        systemctl start wekan
144
-    fi
145
-}
146
-
147
-function backup_remote_wekan {
148
-    if grep -q "wekan domain" $COMPLETION_FILE; then
149
-        temp_backup_dir=$WEKAN_DIR/data
150
-        if [ -d $temp_backup_dir ]; then
151
-            systemctl stop wekan
152
-
153
-            function_check suspend_site
154
-            suspend_site wekan
155
-
156
-            echo $"Backing up Wekan installation"
157
-
158
-            function_check backup_database_to_friend
159
-            backup_database_to_friend wekan
160
-
161
-            function_check backup_directory_to_friend
162
-            backup_directory_to_friend $temp_backup_dir wekan
163
-
164
-            function_check restart_site
165
-            restart_site
166
-
167
-            systemctl start wekan
168
-        else
169
-            echo $"wekan domain specified but not found in ${temp_backup_dir}"
170
-        fi
171
-    fi
172
-}
173
-
174
-function restore_remote_wekan {
175
-    if [ -d $WEKAN_DIR ]; then
176
-        systemctl stop wekan
177
-
178
-        function_check restore_database_from_friend
179
-        restore_database_from_friend wekan
180
-
181
-        temp_restore_dir=/root/tempwekan
182
-        function_check restore_directory_from_usb
183
-        restore_directory_from_friend $temp_restore_dir wekan
184
-        if [ -d $temp_restore_dir$WEKAN_DIR/data ]; then
185
-            cp -r $temp_restore_dir$WEKAN_DIR/data/* $WEKAN_DIR/data/
186
-        else
187
-            cp -r $temp_restore_dir/* $WEKAN_DIR/data/
188
-        fi
189
-        rm -rf $temp_restore_dir
190
-        systemctl start wekan
191
-    fi
192
-}
193
-
194
-function remove_wekan {
195
-    systemctl stop wekan
196
-    systemctl disable wekan
197
-    if [ -f /etc/systemd/system/wekan.service ]; then
198
-        rm /etc/systemd/system/wekan.service
199
-    fi
200
-    systemctl daemon-reload
201
-
202
-    function_check remove_nodejs
203
-    remove_nodejs wekan
204
-
205
-    nginx_dissite wekan
206
-
207
-    if [ -d $WEKAN_DIR ]; then
208
-        rm -rf $WEKAN_DIR
209
-    fi
210
-    if [ -f /etc/nginx/sites-available/wekan ]; then
211
-        rm /etc/nginx/sites-available/wekan
212
-    fi
213
-    function_check drop_database
214
-    drop_database wekan
215
-    function_check remove_onion_service
216
-    remove_onion_service wekan ${WEKAN_ONION_PORT}
217
-    remove_app wekan
218
-    remove_completion_param install_wekan
219
-    sed -i '/wekan/d' $COMPLETION_FILE
220
-
221
-    groupdel -f wekan
222
-    userdel -r wekan
223
-    remove_meteor
224
-}
225
-
226
-function wekan_create_database {
227
-    if [ -f ${IMAGE_PASSWORD_FILE} ]; then
228
-        WEKAN_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
229
-    else
230
-        if [ ! ${GIT_ADMIN_PASSWORD} ]; then
231
-            WEKAN_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
232
-        fi
233
-    fi
234
-    if [ ! $WEKAN_ADMIN_PASSWORD ]; then
235
-        return
236
-    fi
237
-
238
-    function_check create_database
239
-    create_database gogs "$WEKAN_ADMIN_PASSWORD"
240
-}
241
-
242
-function install_wekan_main {
243
-    if [[ $(app_is_installed wekan_main) == "1" ]]; then
244
-        return
245
-    fi
246
-
247
-    if [ ! -d /var/www/wekan ]; then
248
-        mkdir /var/www/wekan
249
-    fi
250
-    if [ -d $WEKAN_DIR ]; then
251
-        rm -rf $WEKAN_DIR
252
-    fi
253
-
254
-    if [ -d /repos/wekan ]; then
255
-        mkdir -p $WEKAN_DIR
256
-        cp -r -p /repos/wekan/. $WEKAN_DIR
257
-        cd $WEKAN_DIR
258
-        git pull
259
-    else
260
-        function_check git_clone
261
-        git_clone $WEKAN_REPO $WEKAN_DIR
262
-    fi
263
-
264
-    if [ ! -d $WEKAN_DIR ]; then
265
-        echo $'Unable to clone wekan repo'
266
-        exit 783251
267
-    fi
268
-
269
-    # an unprivileged user to run as
270
-    groupadd wekan
271
-    useradd -c "Wekan account" -d $WEKAN_DIR/ -m -r -g wekan wekan
272
-
273
-    cd $WEKAN_DIR
274
-    git checkout $WEKAN_COMMIT -b $WEKAN_COMMIT
275
-    set_completion_param "wekan commit" "$WEKAN_COMMIT"
276
-
277
-    chown -R wekan:wekan $WEKAN_DIR
278
-
279
-    WEKAN_ONION_HOSTNAME=$(add_onion_service wekan 80 ${WEKAN_ONION_PORT})
280
-    set_completion_param "wekan onion domain" "$WEKAN_ONION_HOSTNAME"
281
-
282
-    wekan_nginx_site=/etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
283
-    if [[ ${ONION_ONLY} == "no" ]]; then
284
-        function_check nginx_http_redirect
285
-        nginx_http_redirect ${WEKAN_DOMAIN_NAME}
286
-        echo 'server {' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
287
-        echo '    listen 443 ssl;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
288
-        echo '    #listen [::]:443 ssl;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
289
-        echo "    root /var/www/${WEKAN_DOMAIN_NAME}/htdocs;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
290
-        echo "    server_name ${WEKAN_DOMAIN_NAME};" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
291
-        echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
292
-        echo "    error_log /dev/null;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
293
-        echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
294
-        function_check nginx_ssl
295
-        nginx_ssl ${WEKAN_DOMAIN_NAME}
296
-        function_check nginx_disable_sniffing
297
-        nginx_disable_sniffing ${WEKAN_DOMAIN_NAME}
298
-        echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
299
-        echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
300
-        echo '    location / {' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
301
-        function_check nginx_limits
302
-        nginx_limits ${WEKAN_DOMAIN_NAME} '15m'
303
-        echo "        proxy_pass http://localhost:$WEKAN_PORT;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
304
-        echo '    }' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
305
-        echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
306
-        echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
307
-        echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
308
-        echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
309
-        echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
310
-        echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
311
-        echo '    location = /robots.txt {' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
312
-        echo '        allow all;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
313
-        echo '        log_not_found off;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
314
-        echo '        access_log /dev/null;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
315
-        echo '    }' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
316
-        echo '}' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
317
-        echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
318
-    else
319
-        echo -n '' > /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
320
-    fi
321
-    echo 'server {' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
322
-    echo "    listen 127.0.0.1:${WEKAN_ONION_PORT} default_server;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
323
-    echo "    root /var/www/$WEKAN_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
324
-    echo "    server_name $WEKAN_DOMAIN_NAME;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
325
-    echo '    access_log /dev/null;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
326
-    echo "    error_log /dev/null;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
327
-    echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
328
-    function_check nginx_disable_sniffing
329
-    nginx_disable_sniffing ${WEKAN_DOMAIN_NAME}
330
-    echo '    add_header Strict-Transport-Security max-age=0;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
331
-    echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
332
-    echo '    location / {' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
333
-    function_check nginx_limits
334
-    nginx_limits ${WEKAN_DOMAIN_NAME} '15m'
335
-    echo "        proxy_pass http://localhost:$WEKAN_PORT;" >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
336
-    echo '    }' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
337
-    echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
338
-    echo '    fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
339
-    echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
340
-    echo '    error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
341
-    echo '    error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
342
-    echo '' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
343
-    echo '    location = /robots.txt {' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
344
-    echo '        allow all;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
345
-    echo '        log_not_found off;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
346
-    echo '        access_log /dev/null;' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
347
-    echo '    }' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
348
-    echo '}' >> /etc/nginx/sites-available/${WEKAN_DOMAIN_NAME}
349
-
350
-    function_check nginx_ensite
351
-    nginx_ensite wekan
352
-
353
-    install_completed wekan_main
354
-}
355
-
356
-function install_wekan {
357
-    apt-get -qy install build-essential c++ capnproto curl
358
-
359
-    function_check install_nodejs
360
-    install_nodejs wekan
361
-
362
-    install_wekan_main
363
-    install_meteor
364
-
365
-    cd $WEKAN_DIR
366
-
367
-    su -c 'npm install babel-runtime' - wekan
368
-    su -c 'npm install node-gyp' - wekan
369
-    su -c 'npm install node-pre-gyp' - wekan
370
-    su -c 'npm install fibers' - wekan
371
-    su -c 'npm install bcrypt' - wekan
372
-    su -c 'npm install bson' - wekan
373
-    su -c 'npm install es6-promise' - wekan
374
-    su -c 'npm install meteor-node-stubs' - wekan
375
-    su -c 'npm install winston' - wekan
376
-    su -c 'npm install winston-zulip' - wekan
377
-    su -c 'npm install xss' - wekan
378
-
379
-    # Remove any directories from previous installs
380
-    if [ -d $WEKAN_DIR/.meteor ]; then
381
-        rm -rf $WEKAN_DIR/.meteor
382
-    fi
383
-    if [ -d $WEKAN_DIR/app ]; then
384
-        rm -rf $WEKAN_DIR/app
385
-    fi
386
-    if [ -d $WEKAN_DIR/app_build ]; then
387
-        rm -rf $WEKAN_DIR/app_build
388
-    fi
389
-
390
-    # Get additional packages
391
-    mkdir -p $WEKAN_DIR/.meteor/packages
392
-    chown wekan:wekan --recursive $WEKAN_DIR/.meteor
393
-    cd $WEKAN_DIR/.meteor/packages
394
-    if [ ! -d /repos/flowrouter ]; then
395
-        su -c "git clone --depth 1 -b master $FLOW_ROUTER_REPO kadira-flow-router" - wekan
396
-    else
397
-        mkdir kadira-flow-router
398
-        cp -r -p /repos/flowrouter/. kadira-flow-router
399
-        cd kadira-flow-router
400
-        git pull
401
-        cd ..
402
-    fi
403
-    cd kadira-flow-router
404
-    git checkout $FLOW_ROUTER_COMMIT -b $FLOW_ROUTER_COMMIT
405
-    cd ..
406
-    if [ ! -d /repos/meteoruseraccounts ]; then
407
-        su -c "git clone --depth 1 -b master $METEOR_USERACCOUNTS_REPO meteor-useraccounts-core" - wekan
408
-    else
409
-        mkdir meteor-useraccounts-core
410
-        cp -r -p /repos/meteoruseraccounts/. meteor-useraccounts-core
411
-        cd meteor-useraccounts-core
412
-        git pull
413
-        cd ..
414
-    fi
415
-    cd meteor-useraccounts-core
416
-    git checkout $METEOR_USERACCOUNTS_COMMIT -b $METEOR_USERACCOUNTS_COMMIT
417
-    cd ..
418
-    if [ ! -f $WEKAN_DIR/.meteor/packages/meteor-useraccounts-core/package.js ]; then
419
-        echo $"File not found: $WEKAN_DIR/.meteor/packages/meteor-useraccounts-core/package.js"
420
-        exit 7289529
421
-    fi
422
-    sed -i 's/api\.versionsFrom/\/\/api.versionsFrom/' $WEKAN_DIR/.meteor/packages/meteor-useraccounts-core/package.js
423
-    cd $WEKAN_DIR/.meteor
424
-    su -c "$WEKAN_DIR/.meteor/meteor -- help" - wekan
425
-
426
-    # Build app
427
-    if [ ! -d $WEKAN_DIR/app ]; then
428
-        echo $'No app subdirectory found'
429
-        exit 294569
430
-    fi
431
-    cd $WEKAN_DIR/app
432
-    su -c "$WEKAN_DIR/.meteor/meteor add standard-minifier-js" - wekan
433
-    su -c "$WEKAN_DIR/.meteor/meteor npm install" - wekan
434
-    su -c "$WEKAN_DIR/.meteor/meteor build --directory $WEKAN_DIR/app_build" - wekan
435
-    cp $WEKAN_DIR/app/fix-download-unicode/cfs_access-point.txt $WEKAN_DIR/app_build/bundle/programs/server/packages/cfs_access-point.js
436
-    chown wekan:wekan $WEKAN_DIR/app_build/bundle/programs/server/packages/cfs_access-point.js
437
-    sed -i "s|build\/Release\/bson|browser_build\/bson|g" $WEKAN_DIR/app_build/bundle/programs/server/npm/node_modules/meteor/cfs_gridfs/node_modules/mongodb/node_modules/bson/ext/index.js
438
-    if [ ! -d $WEKAN_DIR/app_build/bundle/programs/server/npm/node_modules/meteor/npm-bcrypt ]; then
439
-        echo $"No subdirectory found: $WEKAN_DIR/app_build/bundle/programs/server/npm/node_modules/meteor/npm-bcrypt"
440
-        exit 479832
441
-    fi
442
-    cd $WEKAN_DIR/app_build/bundle/programs/server/npm/node_modules/meteor/npm-bcrypt
443
-    su -c 'rm -rf node_modules/bcrypt' - wekan
444
-    su -c 'npm install bcrypt' - wekan
445
-    cd $WEKAN_DIR/app_build/bundle/programs/server/
446
-    su -c 'npm install' - wekan
447
-    mv $WEKAN_DIR/app_build/bundle ../build
448
-
449
-    if [ ! -f $WEKAN_DIR/build/main.js ]; then
450
-        echo $'main.js not found'
451
-        exit 7828252
452
-    fi
453
-
454
-    # Cleanup
455
-    rm -R $WEKAN_DIR/.meteor
456
-    rm -R $WEKAN_DIR/app
457
-    rm -R $WEKAN_DIR/app_build
458
-
459
-    chown -R wekan:wekan $WEKAN_DIR
460
-
461
-    function_check install_mariadb
462
-    install_mariadb
463
-
464
-    function_check get_mariadb_password
465
-    get_mariadb_password
466
-
467
-    function_check wekan_create_database
468
-    wekan_create_database
469
-
470
-    # daemon
471
-    echo '[Unit]' > /etc/systemd/system/wekan.service
472
-    echo 'Description=Wekan' >> /etc/systemd/system/wekan.service
473
-    echo 'After=syslog.target' >> /etc/systemd/system/wekan.service
474
-    echo 'After=network.target' >> /etc/systemd/system/wekan.service
475
-    echo '' >> /etc/systemd/system/wekan.service
476
-    echo '[Service]' >> /etc/systemd/system/wekan.service
477
-    echo 'User=wekan' >> /etc/systemd/system/wekan.service
478
-    echo 'Group=wekan' >> /etc/systemd/system/wekan.service
479
-    echo "WorkingDirectory=$WEKAN_DIR" >> /etc/systemd/system/wekan.service
480
-    echo "ExecStart=/usr/local/bin/node $WEKAN_DIR/build/main.js" >> /etc/systemd/system/wekan.service
481
-    echo 'Environment=PATH=/usr/bin:/usr/local/bin' >> /etc/systemd/system/wekan.service
482
-    echo 'Environment=NODE_ENV=production' >> /etc/systemd/system/wekan.service
483
-    echo 'Restart=on-failure' >> /etc/systemd/system/wekan.service
484
-    echo '' >> /etc/systemd/system/wekan.service
485
-    echo '[Install]' >> /etc/systemd/system/wekan.service
486
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/wekan.service
487
-    systemctl enable wekan.service
488
-    systemctl daemon-reload
489
-    systemctl start wekan.service
490
-
491
-    systemctl restart nginx
492
-
493
-    set_completion_param "wekan domain" "$WEKAN_DOMAIN_NAME"
494
-
495
-    APP_INSTALLED=1
496
-}
497
-
498
-# NOTE: deliberately there is no "exit 0"

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


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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


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


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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Некоторые файлы не были показаны из-за большого количества измененных файлов