浏览代码

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

Bob Mottram 7 年前
父节点
当前提交
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
 	mkdir -p ${DESTDIR}/usr/share/${APP}/utils
23
 	mkdir -p ${DESTDIR}/usr/share/${APP}/utils
24
 	mkdir -p ${DESTDIR}/usr/share/${APP}/avatars
24
 	mkdir -p ${DESTDIR}/usr/share/${APP}/avatars
25
 	mkdir -p ${DESTDIR}/etc/${APP}
25
 	mkdir -p ${DESTDIR}/etc/${APP}
26
+	rm -f ${DESTDIR}/${PREFIX}/bin/${APP}-*
26
 	cp -r image_build/* ${DESTDIR}/etc/${APP}
27
 	cp -r image_build/* ${DESTDIR}/etc/${APP}
27
 	cp img/backgrounds/${APP}_*.png ${DESTDIR}${PREFIX}/share
28
 	cp img/backgrounds/${APP}_*.png ${DESTDIR}${PREFIX}/share
28
 	cp img/avatars/* ${DESTDIR}/usr/share/${APP}/avatars
29
 	cp img/avatars/* ${DESTDIR}/usr/share/${APP}/avatars

二进制
man/freedombone-image.1.gz 查看文件


+ 4
- 4
src/cronic 查看文件

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

+ 49
- 50
src/freedombone 查看文件

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

+ 58
- 61
src/freedombone-addcert 查看文件

36
 CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
36
 CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
37
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
37
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
38
 
38
 
39
-UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
39
+UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
40
 for f in $UTILS_FILES
40
 for f in $UTILS_FILES
41
 do
41
 do
42
-  source $f
42
+    source "$f"
43
 done
43
 done
44
 
44
 
45
 # Don't pin certs by default
45
 # Don't pin certs by default
85
     exit 0
85
     exit 0
86
 }
86
 }
87
 
87
 
88
-while [[ $# > 1 ]]
88
+while [ $# -gt 1 ]
89
 do
89
 do
90
     key="$1"
90
     key="$1"
91
 
91
 
145
             ;;
145
             ;;
146
         --dhkey)
146
         --dhkey)
147
             shift
147
             shift
148
-            DH_KEYLENGTH=${1}
148
+            DH_KEYLENGTH="${1}"
149
             ;;
149
             ;;
150
         --pin)
150
         --pin)
151
             shift
151
             shift
152
-            PIN_CERTS=${1}
152
+            PIN_CERTS="${1}"
153
             ;;
153
             ;;
154
         *)
154
         *)
155
             # unknown option
155
             # unknown option
158
     shift
158
     shift
159
 done
159
 done
160
 
160
 
161
-if [ ! $HOSTNAME ]; then
162
-    if [ ! $LETSENCRYPT_HOSTNAME ]; then
161
+if [ ! "$HOSTNAME" ]; then
162
+    if [ ! "$LETSENCRYPT_HOSTNAME" ]; then
163
         echo $'No hostname specified'
163
         echo $'No hostname specified'
164
         exit 5748
164
         exit 5748
165
     fi
165
     fi
180
     CERTFILE=$LETSENCRYPT_HOSTNAME
180
     CERTFILE=$LETSENCRYPT_HOSTNAME
181
 
181
 
182
     # disable the site if needed
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
         fi
186
         fi
187
     fi
187
     fi
188
 
188
 
189
     # remove the cert
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
     # restart the web server
194
     # restart the web server
195
     systemctl restart nginx
195
     systemctl restart nginx
199
     CERTFILE=$LETSENCRYPT_HOSTNAME
199
     CERTFILE=$LETSENCRYPT_HOSTNAME
200
 
200
 
201
     # obtain the email address for the admin user
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
             read_config_param MY_EMAIL_ADDRESS
204
             read_config_param MY_EMAIL_ADDRESS
205
         fi
205
         fi
206
     fi
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
                 function_check get_completion_param
210
                 function_check get_completion_param
211
                 ADMIN_USER=$(get_completion_param "Admin user")
211
                 ADMIN_USER=$(get_completion_param "Admin user")
212
                 if [ ${#ADMIN_USER} -eq 0 ]; then
212
                 if [ ${#ADMIN_USER} -eq 0 ]; then
232
     chgrp -R root /etc/letsencrypt
232
     chgrp -R root /etc/letsencrypt
233
     chmod -R 777 /etc/letsencrypt
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
         echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME"
236
         echo $"Failed to install letsencrypt for domain $LETSENCRYPT_HOSTNAME"
238
         echo $'Also see https://letsencrypt.status.io to check for any service outages'
237
         echo $'Also see https://letsencrypt.status.io to check for any service outages'
239
         chgrp -R ssl-cert /etc/letsencrypt
238
         chgrp -R ssl-cert /etc/letsencrypt
245
     fi
244
     fi
246
 
245
 
247
     # replace some legacy filenames
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
     fi
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
     fi
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
     # link the private key
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
         else
260
         else
262
-            rm -f /etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key
261
+            rm -f "/etc/ssl/private/${LETSENCRYPT_HOSTNAME}.key"
263
         fi
262
         fi
264
     fi
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
     fi
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
     # link the public key
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
         else
273
         else
275
-            rm -f /etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem
274
+            rm -f "/etc/ssl/certs/${LETSENCRYPT_HOSTNAME}.pem"
276
         fi
275
         fi
277
     fi
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
     fi
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
     update_default_domain
284
     update_default_domain
286
 
285
 
291
     chmod -R g=rX /etc/letsencrypt
290
     chmod -R g=rX /etc/letsencrypt
292
     chown -R root:ssl-cert /etc/letsencrypt
291
     chown -R root:ssl-cert /etc/letsencrypt
293
 
292
 
294
-    nginx_ensite ${LETSENCRYPT_HOSTNAME}
293
+    nginx_ensite "${LETSENCRYPT_HOSTNAME}"
295
     systemctl start nginx
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
             echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned"
298
             echo $"Certificate for $LETSENCRYPT_HOSTNAME could not be pinned"
301
             exit 62878
299
             exit 62878
302
         fi
300
         fi
304
 }
302
 }
305
 
303
 
306
 function add_cert_selfsigned {
304
 function add_cert_selfsigned {
307
-    if [[ $ORGANISATION == "Freedombone-CA" ]]; then
305
+    if [[ "$ORGANISATION" == "Freedombone-CA" ]]; then
308
         CERTFILE="ca-$HOSTNAME"
306
         CERTFILE="ca-$HOSTNAME"
309
     fi
307
     fi
310
 
308
 
311
-    openssl req -x509 ${EXTENSIONS} -nodes -days 3650 -sha256 \
309
+    openssl req -x509 "${EXTENSIONS}" -nodes -days 3650 -sha256 \
312
             -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" \
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
             echo $"Certificate for $CERTFILE could not be pinned"
319
             echo $"Certificate for $CERTFILE could not be pinned"
323
             exit 62879
320
             exit 62879
324
         fi
321
         fi
326
 }
323
 }
327
 
324
 
328
 function generate_dh_params {
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
         fi
329
         fi
333
     fi
330
     fi
334
 }
331
 }
346
 }
343
 }
347
 
344
 
348
 function create_cert {
345
 function create_cert {
349
-    if [ $remove_cert ]; then
346
+    if [ "$remove_cert" ]; then
350
         remove_cert_letsencrypt
347
         remove_cert_letsencrypt
351
         return
348
         return
352
     fi
349
     fi
353
 
350
 
354
-    if [ $LETSENCRYPT_HOSTNAME ]; then
351
+    if [ "$LETSENCRYPT_HOSTNAME" ]; then
355
         add_cert_letsencrypt
352
         add_cert_letsencrypt
356
     else
353
     else
357
         add_cert_selfsigned
354
         add_cert_selfsigned

+ 68
- 69
src/freedombone-addemail 查看文件

47
     exit 0
47
     exit 0
48
 }
48
 }
49
 
49
 
50
-while [[ $# > 1 ]]
50
+while [ $# -gt 1 ]
51
 do
51
 do
52
     key="$1"
52
     key="$1"
53
 
53
 
54
     case $key in
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
     esac
81
     esac
82
     shift
82
     shift
83
 done
83
 done
84
 
84
 
85
-if ! [[ $MYUSERNAME && $GROUP_NAME ]]; then
85
+if ! [[ "$MYUSERNAME" && "$GROUP_NAME" ]]; then
86
     show_help
86
     show_help
87
 fi
87
 fi
88
 
88
 
89
-if [ ${#EMAILADDRESS} -lt 2 ]; then
89
+if [ "${#EMAILADDRESS}" -lt 2 ]; then
90
     if [ ${#SUBJECT_TEXT} -lt 2 ]; then
90
     if [ ${#SUBJECT_TEXT} -lt 2 ]; then
91
-    show_help
91
+        show_help
92
     fi
92
     fi
93
 fi
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
 proc_rule="  * ^From:.*$EMAILADDRESS"
99
 proc_rule="  * ^From:.*$EMAILADDRESS"
100
 proc_comment="# Email rule for $EMAILADDRESS -> $GROUP_NAME"
100
 proc_comment="# Email rule for $EMAILADDRESS -> $GROUP_NAME"
104
 fi
104
 fi
105
 
105
 
106
 if [ ! -d "$LISTDIR" ]; then
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
 fi
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
     if [[ $PUBLIC != "yes" ]]; then
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
     else
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
     fi
134
     fi
136
-    chown $MYUSERNAME:$MYUSERNAME $PM
135
+    chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
137
 fi
136
 fi
138
 
137
 
139
 if [ ! -f "$MUTTRC" ]; then
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
 fi
141
 fi
143
 
142
 
144
 PROCMAILLOG=/home/$MYUSERNAME/log
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
 fi
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
     fi
154
     fi
156
 fi
155
 fi
157
 
156
 

+ 75
- 80
src/freedombone-addlist 查看文件

47
     exit 0
47
     exit 0
48
 }
48
 }
49
 
49
 
50
-while [[ $# > 1 ]]
50
+while [ $# -gt 1 ]
51
 do
51
 do
52
     key="$1"
52
     key="$1"
53
 
53
 
54
     case $key in
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
     esac
81
     esac
82
     shift
82
     shift
83
 done
83
 done
84
 
84
 
85
-if [ ! $MYUSERNAME ]; then
85
+if [ ! "$MYUSERNAME" ]; then
86
     show_help
86
     show_help
87
 fi
87
 fi
88
 
88
 
89
-if [[ ! $MAILINGLIST && ! $SUBJECTTAG ]]; then
89
+if [[ ! "$MAILINGLIST" && ! "$SUBJECTTAG" ]]; then
90
     show_help
90
     show_help
91
 fi
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
     echo $"Mailing list $MAILINGLIST was already added"
98
     echo $"Mailing list $MAILINGLIST was already added"
99
 fi
99
 fi
100
 
100
 
101
 if [ ! -d "$LISTDIR" ]; then
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
 fi
106
 fi
107
 
107
 
108
-chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
108
+chown -R "$MYUSERNAME":"$MYUSERNAME" "$LISTDIR"
109
 
109
 
110
 if [ ${#SUBJECTTAG} -gt 0 ]; then
110
 if [ ${#SUBJECTTAG} -gt 0 ]; then
111
     # use the subject tag
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
         else
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
         fi
133
         fi
138
-    fi
139
-    chown $MYUSERNAME:$MYUSERNAME $PM
134
+        chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
140
     fi
135
     fi
141
 else
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
 fi
138
 fi
144
 
139
 
145
 if [ ! -f "$MUTTRC" ]; then
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
 fi
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
 fi
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
     fi
156
     fi
162
 fi
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
     fi
163
     fi
169
 fi
164
 fi
170
 
165
 

+ 31
- 31
src/freedombone-addremove 查看文件

34
 export TEXTDOMAINDIR="/usr/share/locale"
34
 export TEXTDOMAINDIR="/usr/share/locale"
35
 
35
 
36
 PROJECT_INSTALL_DIR=/usr/local/bin
36
 PROJECT_INSTALL_DIR=/usr/local/bin
37
-if [ -f /usr/bin/${PROJECT_NAME} ]; then
37
+if [ -f "/usr/bin/${PROJECT_NAME}" ]; then
38
     PROJECT_INSTALL_DIR=/usr/bin
38
     PROJECT_INSTALL_DIR=/usr/bin
39
 fi
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
 # Start including files
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
 for f in $UTILS_FILES
49
 for f in $UTILS_FILES
50
 do
50
 do
51
-  source $f
51
+    source "$f"
52
 done
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
 for f in $APP_FILES
55
 for f in $APP_FILES
56
 do
56
 do
57
-  source $f
57
+    source "$f"
58
 done
58
 done
59
 
59
 
60
 # End including files
60
 # End including files
67
         return
67
         return
68
     fi
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
     fi
72
     fi
73
 
73
 
74
     app_index=0
74
     app_index=0
75
     for app_name in "${APPS_AVAILABLE[@]}"
75
     for app_name in "${APPS_AVAILABLE[@]}"
76
     do
76
     do
77
         if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
77
         if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then
78
-            echo "_${app_name}_" >> $REMOVED_APPS_FILE
78
+            echo "_${app_name}_" >> "$REMOVED_APPS_FILE"
79
         fi
79
         fi
80
-        app_index=$[app_index+1]
80
+        app_index=$((app_index+1))
81
     done
81
     done
82
 }
82
 }
83
 
83
 
93
             echo "0"
93
             echo "0"
94
             return
94
             return
95
         fi
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
             echo "0"
97
             echo "0"
98
             return
98
             return
99
         fi
99
         fi
102
 }
102
 }
103
 
103
 
104
 function show_apps {
104
 function show_apps {
105
-    select_all_apps=$1
105
+    select_all_apps="$1"
106
     applist=""
106
     applist=""
107
     n=1
107
     n=1
108
     app_index=0
108
     app_index=0
117
                 applist="$applist $n $a on"
117
                 applist="$applist $n $a on"
118
             fi
118
             fi
119
         fi
119
         fi
120
-        n=$[n+1]
121
-        app_index=$[app_index+1]
120
+        n=$((n+1))
121
+        app_index=$((app_index+1))
122
     done
122
     done
123
 
123
 
124
     choices=$(dialog --stdout --backtitle $"Freedombone" \
124
     choices=$(dialog --stdout --backtitle $"Freedombone" \
125
                      --title $"Add/Remove Applications" \
125
                      --title $"Add/Remove Applications" \
126
                      --checklist $'Choose:' \
126
                      --checklist $'Choose:' \
127
-                     27 40 20 $applist)
127
+                     27 40 20 "$applist")
128
 
128
 
129
+    # shellcheck disable=SC2181
129
     if [ $? -eq 0 ]; then
130
     if [ $? -eq 0 ]; then
130
         for choice in $choices
131
         for choice in $choices
131
         do
132
         do
132
-            app_index=$[choice-1]
133
+            app_index=$((choice-1))
133
             APPS_CHOSEN[$app_index]="1"
134
             APPS_CHOSEN[$app_index]="1"
134
         done
135
         done
135
     else
136
     else
151
                 else
152
                 else
152
                     removals="${APPS_AVAILABLE[$app_index]}"
153
                     removals="${APPS_AVAILABLE[$app_index]}"
153
                 fi
154
                 fi
154
-                n=$[n+1]
155
+                n=$((n+1))
155
             fi
156
             fi
156
         fi
157
         fi
157
-        app_index=$[app_index+1]
158
+        app_index=$((app_index+1))
158
     done
159
     done
159
 
160
 
160
     # if no apps to be removed then don't do anything
161
     # if no apps to be removed then don't do anything
166
     dialog --title $"Remove applications" \
167
     dialog --title $"Remove applications" \
167
            --backtitle $"Freedombone" \
168
            --backtitle $"Freedombone" \
168
            --defaultno \
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
     sel=$?
171
     sel=$?
171
     case $sel in
172
     case $sel in
172
         1) return;;
173
         1) return;;
195
                 else
196
                 else
196
                     installs="${APPS_AVAILABLE[$app_index]}"
197
                     installs="${APPS_AVAILABLE[$app_index]}"
197
                 fi
198
                 fi
198
-                n=$[n+1]
199
+                n=$((n+1))
199
             fi
200
             fi
200
         fi
201
         fi
201
-        app_index=$[app_index+1]
202
+        app_index=$((app_index+1))
202
     done
203
     done
203
 
204
 
204
     # if no apps to be installed then don't do anything
205
     # if no apps to be installed then don't do anything
212
             dialog --title $"$installs" \
213
             dialog --title $"$installs" \
213
                    --backtitle $"Freedombone" \
214
                    --backtitle $"Freedombone" \
214
                    --defaultno \
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
         else
217
         else
217
-            dialog_height=$((15 + $n))
218
+            dialog_height=$((15 + "$n"))
218
             dialog --title $"Add applications" \
219
             dialog --title $"Add applications" \
219
                    --backtitle $"Freedombone" \
220
                    --backtitle $"Freedombone" \
220
                    --defaultno \
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
         fi
223
         fi
223
         sel=$?
224
         sel=$?
224
         case $sel in
225
         case $sel in
232
     # install the apps
233
     # install the apps
233
     read_configuration
234
     read_configuration
234
     install_apps interactive
235
     install_apps interactive
235
-    if [ ! $APP_INSTALLED_SUCCESS ]; then
236
+    if [ ! "$APP_INSTALLED_SUCCESS" ]; then
236
         echo $'One or more apps failed to install'
237
         echo $'One or more apps failed to install'
237
     fi
238
     fi
238
 }
239
 }
239
 
240
 
240
 if [[ $1 == "test"* ]]; then
241
 if [[ $1 == "test"* ]]; then
241
-    ${PROJECT_NAME}-tests
242
-    if [ ! "$?" = "0" ]; then
242
+    if ! ${PROJECT_NAME}-tests; then
243
         exit 2
243
         exit 2
244
     fi
244
     fi
245
 fi
245
 fi
251
     exit 1
251
     exit 1
252
 fi
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
 clear
257
 clear
258
 
258
 

+ 93
- 94
src/freedombone-adduser 查看文件

34
 export TEXTDOMAIN=${PROJECT_NAME}-adduser
34
 export TEXTDOMAIN=${PROJECT_NAME}-adduser
35
 export TEXTDOMAINDIR="/usr/share/locale"
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
 for f in $UTILS_FILES
40
 for f in $UTILS_FILES
41
 do
41
 do
42
-    source $f
42
+    source "$f"
43
 done
43
 done
44
 
44
 
45
-APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
45
+APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
46
 for f in $APP_FILES
46
 for f in $APP_FILES
47
 do
47
 do
48
-    source $f
48
+    source "$f"
49
 done
49
 done
50
 
50
 
51
 ADD_USERNAME=$1
51
 ADD_USERNAME=$1
55
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
55
 COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
56
 DEFAULT_DOMAIN_NAME=
56
 DEFAULT_DOMAIN_NAME=
57
 
57
 
58
-if [ ! $ADD_USERNAME ]; then
58
+if [ ! "$ADD_USERNAME" ]; then
59
     echo $'No username was given'
59
     echo $'No username was given'
60
     exit 1
60
     exit 1
61
 fi
61
 fi
62
 
62
 
63
-if [ -d /home/$ADD_USERNAME ]; then
63
+if [ -d "/home/$ADD_USERNAME" ]; then
64
     echo $"The user $ADD_USERNAME already exists"
64
     echo $"The user $ADD_USERNAME already exists"
65
     exit 2
65
     exit 2
66
 fi
66
 fi
67
 
67
 
68
-if [ ! -f $COMPLETION_FILE ]; then
68
+if [ ! -f "$COMPLETION_FILE" ]; then
69
     echo $"$COMPLETION_FILE not found"
69
     echo $"$COMPLETION_FILE not found"
70
-    userdel -r $ADD_USERNAME
70
+    userdel -r "$ADD_USERNAME"
71
     exit 3
71
     exit 3
72
 fi
72
 fi
73
 
73
 
74
 # Minimum number of characters in a password
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
 chmod 600 /etc/shadow
78
 chmod 600 /etc/shadow
79
 chmod 600 /etc/gshadow
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
 chmod 0000 /etc/shadow
83
 chmod 0000 /etc/shadow
84
 chmod 0000 /etc/gshadow
84
 chmod 0000 /etc/gshadow
85
 
85
 
86
-if [ ! -d /home/$ADD_USERNAME ]; then
86
+if [ ! -d "/home/$ADD_USERNAME" ]; then
87
     echo $'Home directory was not created'
87
     echo $'Home directory was not created'
88
     exit 4
88
     exit 4
89
 fi
89
 fi
91
 if [ "$SSH_PUBLIC_KEY" ]; then
91
 if [ "$SSH_PUBLIC_KEY" ]; then
92
     if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
92
     if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
93
         if [ -f "$SSH_PUBLIC_KEY" ]; then
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
             echo $'ssh public key installed'
97
             echo $'ssh public key installed'
98
         else
98
         else
99
             if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
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
                 echo $'ssh public key installed'
103
                 echo $'ssh public key installed'
104
             else
104
             else
105
                 echo $'The second parameter does not look like an ssh key'
105
                 echo $'The second parameter does not look like an ssh key'
109
     fi
109
     fi
110
 fi
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
     else
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
     fi
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
 fi
120
 fi
122
 
121
 
123
 # generate a gpg key
122
 # generate a gpg key
124
 echo "Making a GPG key for $ADD_USERNAME@$HOSTNAME"
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
 # Generate a GPG key
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
 MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$ADD_USERNAME" "$ADD_USERNAME@$HOSTNAME")
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
     echo "GPG public key was not generated for $ADD_USERNAME@$HOSTNAME $MY_GPG_PUBLIC_KEY_ID"
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
     exit 7
156
     exit 7
158
 fi
157
 fi
159
 
158
 
160
-gpg_agent_setup $ADD_USERNAME
159
+gpg_agent_setup "$ADD_USERNAME"
161
 
160
 
162
 # add a monkeysphere subkey
161
 # add a monkeysphere subkey
163
 #echo $'Adding monkeysphere subkey'
162
 #echo $'Adding monkeysphere subkey'
173
 #echo $'Updating monkeysphere users'
172
 #echo $'Updating monkeysphere users'
174
 #monkeysphere-authentication update-users
173
 #monkeysphere-authentication update-users
175
 
174
 
176
-if [ -f /home/$ADD_USERNAME/.muttrc ]; then
175
+if [ -f "/home/$ADD_USERNAME/.muttrc" ]; then
177
     # encrypt outgoing mail to the "sent" folder
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
     else
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
     fi
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
     else
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
     fi
189
     fi
191
 fi
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
 fi
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
 echo $'Detecting installed apps...'
211
 echo $'Detecting installed apps...'
213
 detect_apps
212
 detect_apps
214
 get_apps_installed_names
213
 get_apps_installed_names
215
 for app_name in "${APPS_INSTALLED_NAMES[@]}"
214
 for app_name in "${APPS_INSTALLED_NAMES[@]}"
216
 do
215
 do
217
-    if [[ $(function_exists add_user_${app_name}) == "1" ]]; then
216
+    if [[ $(function_exists "add_user_${app_name}") == "1" ]]; then
218
         echo $"Adding user to ${app_name}"
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
         if [[ $retval != '0' ]]; then
220
         if [[ $retval != '0' ]]; then
222
             echo $"Failed with error code ${retval}"
221
             echo $"Failed with error code ${retval}"
223
-            ${PROJECT_NAME}-rmuser $ADD_USERNAME --force
222
+            "${PROJECT_NAME}-rmuser" "$ADD_USERNAME" --force
224
             exit 672392
223
             exit 672392
225
         fi
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
         fi
227
         fi
229
     fi
228
     fi
230
 done
229
 done
231
 
230
 
232
 if [ -f /etc/nginx/.htpasswd ]; then
231
 if [ -f /etc/nginx/.htpasswd ]; then
233
     if ! grep -q "${ADD_USERNAME}:" /etc/nginx/.htpasswd; then
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
     fi
234
     fi
236
 fi
235
 fi
237
 
236
 
238
 # add user menu on ssh login
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
 fi
240
 fi
242
 
241
 
243
 # fix some gpg strangeness when searching for keys
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
 fi
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
 clear
252
 clear
254
 
253
 

+ 153
- 152
src/freedombone-app-akaunting 查看文件

49
                      MY_USERNAME)
49
                      MY_USERNAME)
50
 
50
 
51
 function akaunting_remove_bad_links {
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
     # copy jquery locally
54
     # copy jquery locally
55
     jquery_version='1.12.4'
55
     jquery_version='1.12.4'
56
     if [ ! -f jquery-${jquery_version}.js ]; then
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
         wget https://code.jquery.com/jquery-${jquery_version}.js
58
         wget https://code.jquery.com/jquery-${jquery_version}.js
59
         jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
59
         jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
60
         if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
60
         if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
74
     sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/dist/css/alt/AdminLTE-without-plugins.min.css
74
     sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/dist/css/alt/AdminLTE-without-plugins.min.css
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
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
 function logging_on_akaunting {
80
 function logging_on_akaunting {
88
 function remove_user_akaunting {
88
 function remove_user_akaunting {
89
     remove_username="$1"
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
 function add_user_akaunting {
94
 function add_user_akaunting {
95
     new_username="$1"
95
     new_username="$1"
96
     new_user_password="$2"
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
     echo '0'
100
     echo '0'
101
 }
101
 }
102
 
102
 
103
 function install_interactive_akaunting {
103
 function install_interactive_akaunting {
104
-    if [ ! $ONION_ONLY ]; then
104
+    if [ ! "$ONION_ONLY" ]; then
105
         ONION_ONLY='no'
105
         ONION_ONLY='no'
106
     fi
106
     fi
107
 
107
 
108
-    if [[ $ONION_ONLY != "no" ]]; then
108
+    if [[ "$ONION_ONLY" != "no" ]]; then
109
         AKAUNTING_DOMAIN_NAME='akaunting.local'
109
         AKAUNTING_DOMAIN_NAME='akaunting.local'
110
     else
110
     else
111
         AKAUNTING_DETAILS_COMPLETE=
111
         AKAUNTING_DETAILS_COMPLETE=
112
         while [ ! $AKAUNTING_DETAILS_COMPLETE ]
112
         while [ ! $AKAUNTING_DETAILS_COMPLETE ]
113
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
115
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
117
                 dialog --backtitle $"Freedombone Configuration" \
116
                 dialog --backtitle $"Freedombone Configuration" \
118
                        --title $"Akaunting Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'AKAUNTING_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
119
                        $"Domain:" 1 1 "$(grep 'AKAUNTING_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
121
                        $"Code:" 2 1 "$(grep 'AKAUNTING_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
120
                        $"Code:" 2 1 "$(grep 'AKAUNTING_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
122
-                       2> $data
121
+                       2> "$data"
123
             else
122
             else
124
                 dialog --backtitle $"Freedombone Configuration" \
123
                 dialog --backtitle $"Freedombone Configuration" \
125
                        --title $"Akaunting Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'AKAUNTING_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
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
             fi
128
             fi
130
             sel=$?
129
             sel=$?
131
             case $sel in
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
             esac
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
                 if [[ $AKAUNTING_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
138
                 if [[ $AKAUNTING_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
138
                     AKAUNTING_DOMAIN_NAME=""
139
                     AKAUNTING_DOMAIN_NAME=""
139
                 fi
140
                 fi
140
                 TEST_DOMAIN_NAME=$AKAUNTING_DOMAIN_NAME
141
                 TEST_DOMAIN_NAME=$AKAUNTING_DOMAIN_NAME
141
                 validate_domain_name
142
                 validate_domain_name
142
-                if [[ $TEST_DOMAIN_NAME != $AKAUNTING_DOMAIN_NAME ]]; then
143
+                if [[ "$TEST_DOMAIN_NAME" != "$AKAUNTING_DOMAIN_NAME" ]]; then
143
                     AKAUNTING_DOMAIN_NAME=
144
                     AKAUNTING_DOMAIN_NAME=
144
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
145
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
145
                 else
146
                 else
146
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$AKAUNTING_CODE"
149
                         validate_freedns_code "$AKAUNTING_CODE"
149
-                        if [ ! $VALID_CODE ]; then
150
+                        if [ ! "$VALID_CODE" ]; then
150
                             AKAUNTING_DOMAIN_NAME=
151
                             AKAUNTING_DOMAIN_NAME=
151
                         fi
152
                         fi
152
                     fi
153
                     fi
155
             if [ $AKAUNTING_DOMAIN_NAME ]; then
156
             if [ $AKAUNTING_DOMAIN_NAME ]; then
156
                 AKAUNTING_DETAILS_COMPLETE="yes"
157
                 AKAUNTING_DETAILS_COMPLETE="yes"
157
             fi
158
             fi
159
+            rm -f "$data"
158
         done
160
         done
159
 
161
 
160
         write_config_param "AKAUNTING_CODE" "$AKAUNTING_CODE"
162
         write_config_param "AKAUNTING_CODE" "$AKAUNTING_CODE"
169
 
171
 
170
     read_config_param 'AKAUNTING_DOMAIN_NAME'
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
 function akaunting_create_database {
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
     else
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
         fi
183
         fi
182
     fi
184
     fi
183
-    if [ ! $AKAUNTING_ADMIN_PASSWORD ]; then
185
+    if [ ! "$AKAUNTING_ADMIN_PASSWORD" ]; then
184
         return
186
         return
185
     fi
187
     fi
186
 
188
 
187
     function_check create_database
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
 function reconfigure_akaunting {
193
 function reconfigure_akaunting {
198
         return
200
         return
199
     fi
201
     fi
200
 
202
 
201
-    if grep -q "akaunting domain" $COMPLETION_FILE; then
203
+    if grep -q "akaunting domain" "$COMPLETION_FILE"; then
202
         AKAUNTING_DOMAIN_NAME=$(get_completion_param "akaunting domain")
204
         AKAUNTING_DOMAIN_NAME=$(get_completion_param "akaunting domain")
203
     fi
205
     fi
204
 
206
 
205
     # update to the next commit
207
     # update to the next commit
206
     function_check set_repo_commit
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
     install_composer
212
     install_composer
211
     akaunting_remove_bad_links
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
 function backup_local_akaunting {
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
         function_check backup_database_to_usb
223
         function_check backup_database_to_usb
222
         backup_database_to_usb akaunting
224
         backup_database_to_usb akaunting
223
-        backup_directory_to_usb $akaunting_path akaunting
225
+        backup_directory_to_usb "$akaunting_path" akaunting
224
         restart_site
226
         restart_site
225
     fi
227
     fi
226
 }
228
 }
227
 
229
 
228
 function restore_local_akaunting {
230
 function restore_local_akaunting {
229
     temp_restore_dir=/root/tempakaunting
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
     function_check akaunting_create_database
236
     function_check akaunting_create_database
235
     akaunting_create_database
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
     restart_site
242
     restart_site
241
 }
243
 }
242
 
244
 
243
 function backup_remote_akaunting {
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
         function_check backup_database_to_friend
249
         function_check backup_database_to_friend
248
         backup_database_to_friend akaunting
250
         backup_database_to_friend akaunting
249
-        backup_directory_to_friend $akaunting_path akaunting
251
+        backup_directory_to_friend "$akaunting_path" akaunting
250
         restart_site
252
         restart_site
251
     fi
253
     fi
252
 }
254
 }
253
 
255
 
254
 function restore_remote_akaunting {
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
     function_check akaunting_create_database
261
     function_check akaunting_create_database
261
     akaunting_create_database
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
     restart_site
267
     restart_site
267
 }
268
 }
274
     read_config_param "AKAUNTING_DOMAIN_NAME"
275
     read_config_param "AKAUNTING_DOMAIN_NAME"
275
     read_config_param "MY_USERNAME"
276
     read_config_param "MY_USERNAME"
276
     echo "Removing $AKAUNTING_DOMAIN_NAME"
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
     fi
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
     fi
286
     fi
286
     function_check drop_database
287
     function_check drop_database
287
     drop_database akaunting
288
     drop_database akaunting
288
     function_check remove_onion_service
289
     function_check remove_onion_service
289
-    remove_onion_service akaunting ${AKAUNTING_ONION_PORT}
290
+    remove_onion_service akaunting "${AKAUNTING_ONION_PORT}"
290
     if grep -q "akaunting" /etc/crontab; then
291
     if grep -q "akaunting" /etc/crontab; then
291
         sed -i "/akaunting/d" /etc/crontab
292
         sed -i "/akaunting/d" /etc/crontab
292
     fi
293
     fi
293
     remove_app akaunting
294
     remove_app akaunting
294
     remove_completion_param install_akaunting
295
     remove_completion_param install_akaunting
295
-    sed -i '/akaunting/d' $COMPLETION_FILE
296
+    sed -i '/akaunting/d' "$COMPLETION_FILE"
296
 
297
 
297
     function_check remove_ddns_domain
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
 function install_akaunting {
302
 function install_akaunting {
303
         ONION_ONLY='no'
304
         ONION_ONLY='no'
304
     fi
305
     fi
305
 
306
 
306
-    if [ ! $AKAUNTING_DOMAIN_NAME ]; then
307
+    if [ ! "$AKAUNTING_DOMAIN_NAME" ]; then
307
         echo $'No domain name was given for akaunting'
308
         echo $'No domain name was given for akaunting'
308
         exit 89353
309
         exit 89353
309
     fi
310
     fi
317
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
318
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
318
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
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
     fi
323
     fi
323
-    if [ ! -d /var/www/$AKAUNTING_DOMAIN_NAME/htdocs ]; then
324
+    if [ ! -d "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" ]; then
324
         if [ -d /repos/akaunting ]; then
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
             git pull
329
             git pull
329
         else
330
         else
330
             function_check git_clone
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
         fi
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
             echo $'Unable to clone akaunting repo'
336
             echo $'Unable to clone akaunting repo'
336
             exit 2589389
337
             exit 2589389
337
         fi
338
         fi
338
     fi
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
     set_completion_param "akaunting commit" "$AKAUNTING_COMMIT"
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
     install_composer
349
     install_composer
349
 
350
 
350
     function_check akaunting_create_database
351
     function_check akaunting_create_database
351
     akaunting_create_database
352
     akaunting_create_database
352
 
353
 
353
     function_check add_ddns_domain
354
     function_check add_ddns_domain
354
-    add_ddns_domain $AKAUNTING_DOMAIN_NAME
355
+    add_ddns_domain "$AKAUNTING_DOMAIN_NAME"
355
 
356
 
356
     AKAUNTING_ONION_HOSTNAME=$(add_onion_service akaunting 80 ${AKAUNTING_ONION_PORT})
357
     AKAUNTING_ONION_HOSTNAME=$(add_onion_service akaunting 80 ${AKAUNTING_ONION_PORT})
357
 
358
 
358
     akaunting_nginx_site=/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME
359
     akaunting_nginx_site=/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME
359
     if [[ $ONION_ONLY == "no" ]]; then
360
     if [[ $ONION_ONLY == "no" ]]; then
360
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl
372
         function_check nginx_ssl
372
-        nginx_ssl $AKAUNTING_DOMAIN_NAME
373
+        nginx_ssl "$AKAUNTING_DOMAIN_NAME"
373
 
374
 
374
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
408
     else
408
-        echo -n '' > $akaunting_nginx_site
409
+        echo -n '' > "$akaunting_nginx_site"
409
     fi
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check configure_php
449
     function_check configure_php
449
     configure_php
450
     configure_php
450
 
451
 
451
     function_check create_site_certificate
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
     function_check nginx_ensite
455
     function_check nginx_ensite
455
-    nginx_ensite $AKAUNTING_DOMAIN_NAME
456
+    nginx_ensite "$AKAUNTING_DOMAIN_NAME"
456
 
457
 
457
     akaunting_remove_bad_links
458
     akaunting_remove_bad_links
458
 
459
 
460
     systemctl restart php7.0-fpm
461
     systemctl restart php7.0-fpm
461
     systemctl restart nginx
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
     set_completion_param "akaunting domain" "$AKAUNTING_DOMAIN_NAME"
466
     set_completion_param "akaunting domain" "$AKAUNTING_DOMAIN_NAME"
466
 
467
 

+ 28
- 29
src/freedombone-app-batman 查看文件

53
 }
53
 }
54
 
54
 
55
 function configure_firewall_for_batman {
55
 function configure_firewall_for_batman {
56
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
56
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
57
         return
57
         return
58
     fi
58
     fi
59
     if [[ $ENABLE_BATMAN != "yes" ]]; then
59
     if [[ $ENABLE_BATMAN != "yes" ]]; then
62
 
62
 
63
     function_check save_firewall_settings
63
     function_check save_firewall_settings
64
     save_firewall_settings
64
     save_firewall_settings
65
-    mark_completed $FUNCNAME
65
+    mark_completed "${FUNCNAME[0]}"
66
 }
66
 }
67
 
67
 
68
 function reconfigure_batman {
68
 function reconfigure_batman {
90
 }
90
 }
91
 
91
 
92
 function remove_batman {
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
         echo $'Failed to remove batman'
94
         echo $'Failed to remove batman'
96
         exit 79353
95
         exit 79353
97
     fi
96
     fi
100
 }
99
 }
101
 
100
 
102
 function mesh_install_batman {
101
 function mesh_install_batman {
102
+    # shellcheck disable=SC2154
103
     chroot "$rootdir" apt-get -yq install iproute bridge-utils libnetfilter-conntrack3 batctl
103
     chroot "$rootdir" apt-get -yq install iproute bridge-utils libnetfilter-conntrack3 batctl
104
     chroot "$rootdir" apt-get -yq install python-dev libevent-dev ebtables python-pip git
104
     chroot "$rootdir" apt-get -yq install python-dev libevent-dev ebtables python-pip git
105
     chroot "$rootdir" apt-get -yq install wireless-tools rfkill
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
     fi
109
     fi
110
 
110
 
111
     BATMAN_SCRIPT=$rootdir/var/lib/batman
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
     else
115
     else
116
-        cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
116
+        cp "/usr/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
117
     fi
117
     fi
118
 
118
 
119
     BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
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
     chroot "$rootdir" systemctl enable batman
137
     chroot "$rootdir" systemctl enable batman
138
 }
138
 }
139
 
139
 
140
 function install_batman {
140
 function install_batman {
141
-    if [ $INSTALLING_MESH ]; then
141
+    if [ "$INSTALLING_MESH" ]; then
142
         mesh_install_batman
142
         mesh_install_batman
143
         return
143
         return
144
     fi
144
     fi
146
         return
146
         return
147
     fi
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
         echo $'Failed to install batman'
150
         echo $'Failed to install batman'
152
         exit 72524
151
         exit 72524
153
     fi
152
     fi

+ 127
- 127
src/freedombone-app-bdsmail 查看文件

49
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
49
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
50
 
50
 
51
             # Add the user to the i2p group
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
                 # Create a mutt i2p folder
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
                 fi
59
                 fi
60
 
60
 
61
                 # Create a mutt folder hook to the i2p config
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
                 fi
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
                 fi
67
                 fi
68
             fi
68
             fi
69
 
69
 
70
             # Create a directory where i2p mail will be stored
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
             fi
75
             fi
76
         fi
76
         fi
77
     done
77
     done
93
     new_username="$1"
93
     new_username="$1"
94
     new_user_password="$2"
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
     fi
99
     fi
100
     read_config_param MY_USERNAME
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
     bdsmail_configure_users
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
     echo '0'
108
     echo '0'
109
 }
109
 }
110
 
110
 
117
     curr_username="$1"
117
     curr_username="$1"
118
     new_user_password="$2"
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
     for d in /home/*/ ; do
122
     for d in /home/*/ ; do
123
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
123
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
124
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
         fi
130
         fi
131
     done
131
     done
132
 }
132
 }
136
     for d in /home/*/ ; do
136
     for d in /home/*/ ; do
137
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
137
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
138
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
         fi
142
         fi
143
     done
143
     done
144
 }
144
 }
154
         sleep 30
154
         sleep 30
155
         bds_domain=$(bdsmail_domain)
155
         bds_domain=$(bdsmail_domain)
156
         sleep_ctr=$((sleep_ctr + 1))
156
         sleep_ctr=$((sleep_ctr + 1))
157
-        if [ $sleep_ctr -gt 100 ]; then
157
+        if [ "$sleep_ctr" -gt 100 ]; then
158
             break
158
             break
159
         fi
159
         fi
160
     done
160
     done
178
     fi
178
     fi
179
 
179
 
180
     # update to the next commit
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
     chown -R i2psvc:i2psvc $BDSMAIL_DIR
184
     chown -R i2psvc:i2psvc $BDSMAIL_DIR
185
     systemctl restart bdsmail
185
     systemctl restart bdsmail
186
 
186
 
210
     function_check restore_directory_from_usb
210
     function_check restore_directory_from_usb
211
     restore_directory_from_usb $temp_restore_dir bdsmail
211
     restore_directory_from_usb $temp_restore_dir bdsmail
212
     if [ -d $temp_restore_dir ]; then
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
             cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
214
             cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
215
         else
215
         else
216
             if [ ! -d $bdsmail_dir ]; then
216
             if [ ! -d $bdsmail_dir ]; then
246
     function_check restore_directory_from_friend
246
     function_check restore_directory_from_friend
247
     restore_directory_from_friend $temp_restore_dir bdsmail
247
     restore_directory_from_friend $temp_restore_dir bdsmail
248
     if [ -d $temp_restore_dir ]; then
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
             cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
250
             cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
251
         else
251
         else
252
             if [ ! -d $bdsmail_dir ]; then
252
             if [ ! -d $bdsmail_dir ]; then
272
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
272
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
273
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
273
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
274
             # remove the user from the i2p group
274
             # remove the user from the i2p group
275
-            deluser $USERNAME i2psvc
275
+            deluser "$USERNAME" i2psvc
276
 
276
 
277
             # Remove mutt folder hook to the i2p config
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
                 fi
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
                 fi
284
                 fi
285
             fi
285
             fi
286
 
286
 
287
             # Remove folder
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
             fi
290
             fi
291
 
291
 
292
             # NOTE: leave Maildir/i2p/cur. We might want to archive that
292
             # NOTE: leave Maildir/i2p/cur. We might want to archive that
293
             # or just be reinstalling the system without losing mail
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
         fi
295
         fi
296
     done
296
     done
297
 
297
 
298
     remove_i2p
298
     remove_i2p
299
     remove_app bdsmail
299
     remove_app bdsmail
300
     remove_completion_param install_bdsmail
300
     remove_completion_param install_bdsmail
301
-    sed -i '/bdsmail/d' $COMPLETION_FILE
301
+    sed -i '/bdsmail/d' "$COMPLETION_FILE"
302
     rm -rf /etc/skel/.mutt
302
     rm -rf /etc/skel/.mutt
303
     if [ -d $BDSMAIL_DIR ]; then
303
     if [ -d $BDSMAIL_DIR ]; then
304
         rm -rf $BDSMAIL_DIR
304
         rm -rf $BDSMAIL_DIR
319
     if [ -d /repos/bdsmail ]; then
319
     if [ -d /repos/bdsmail ]; then
320
         mkdir $BDSMAIL_DIR
320
         mkdir $BDSMAIL_DIR
321
         cp -r -p /repos/bdsmail/. $BDSMAIL_DIR
321
         cp -r -p /repos/bdsmail/. $BDSMAIL_DIR
322
-        cd $BDSMAIL_DIR
322
+        cd $BDSMAIL_DIR || exit 24687246
323
         git pull
323
         git pull
324
     else
324
     else
325
-        git_clone $BDSMAIL_REPO $BDSMAIL_DIR
325
+        git_clone "$BDSMAIL_REPO" "$BDSMAIL_DIR"
326
     fi
326
     fi
327
 
327
 
328
     if [ ! -d $BDSMAIL_DIR ]; then
328
     if [ ! -d $BDSMAIL_DIR ]; then
330
         exit 5735735
330
         exit 5735735
331
     fi
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
     set_completion_param "bdsmail commit" "$BDSMAIL_COMMIT"
335
     set_completion_param "bdsmail commit" "$BDSMAIL_COMMIT"
336
 
336
 
337
     mkdir -p $BDSMAIL_DIR/Maildir/i2p
337
     mkdir -p $BDSMAIL_DIR/Maildir/i2p
338
     chmod -R 700 $BDSMAIL_DIR/Maildir
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
     if [ ! -f $BDSMAIL_DIR/bin/bdsconfig ]; then
341
     if [ ! -f $BDSMAIL_DIR/bin/bdsconfig ]; then
342
         echo $'Unable to make bdsmail'
342
         echo $'Unable to make bdsmail'
343
         exit 87923567842
343
         exit 87923567842
347
     i2p_enable_sam
347
     i2p_enable_sam
348
 
348
 
349
     # create configuration file
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
     chmod +x $BDSMAIL_DIR/get_address
383
     chmod +x $BDSMAIL_DIR/get_address
384
 
384
 
385
     chown -R i2psvc:i2psvc $BDSMAIL_DIR
385
     chown -R i2psvc:i2psvc $BDSMAIL_DIR
386
     systemctl enable bdsmail
386
     systemctl enable bdsmail
387
     systemctl start bdsmail
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
     chmod +x /usr/bin/bdsmail_distribute
404
     chmod +x /usr/bin/bdsmail_distribute
405
 
405
 
406
     if ! grep -q 'bdsmail_distribute' /etc/crontab; then
406
     if ! grep -q 'bdsmail_distribute' /etc/crontab; then
407
         cron_add_mins 1 '/usr/bin/bdsmail_distribute 2> /dev/null'
407
         cron_add_mins 1 '/usr/bin/bdsmail_distribute 2> /dev/null'
408
     fi
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
     chmod +x /usr/bin/bdsmail_domain
416
     chmod +x /usr/bin/bdsmail_domain
417
 
417
 
418
     echo ''
418
     echo ''
422
 
422
 
423
     bdsmail_wait_for_key_generation
423
     bdsmail_wait_for_key_generation
424
 
424
 
425
-    if [ ! $bds_domain ]; then
425
+    if [ ! "$bds_domain" ]; then
426
         systemctl stop bdsmail
426
         systemctl stop bdsmail
427
         systemctl disable bdsmail
427
         systemctl disable bdsmail
428
         remove_i2p
428
         remove_i2p
430
         exit 8934638
430
         exit 8934638
431
     fi
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
     $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini admin $BDSMAIL_DIR/Maildir/i2p/admin "$BDSMAIL_PASSWORD"
436
     $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini admin $BDSMAIL_DIR/Maildir/i2p/admin "$BDSMAIL_PASSWORD"
437
 
437
 
438
     # Create mutt configuration
438
     # Create mutt configuration
439
     if [ ! -d /etc/skel/.mutt ]; then
439
     if [ ! -d /etc/skel/.mutt ]; then
440
         mkdir /etc/skel/.mutt
440
         mkdir /etc/skel/.mutt
441
     fi
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
     # mutt configuration for the admin user
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
     fi
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
     bdsmail_configure_users
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
     APP_INSTALLED=1
466
     APP_INSTALLED=1
467
 }
467
 }

+ 301
- 300
src/freedombone-app-cryptpad 查看文件

101
     function_check set_repo_commit
101
     function_check set_repo_commit
102
     set_repo_commit $CRYPTPAD_DIR "cryptpad commit" "$CRYPTPAD_COMMIT" $CRYPTPAD_REPO
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
     cryptpad_create_config
105
     cryptpad_create_config
106
     npm upgrade
106
     npm upgrade
107
     npm install
107
     npm install
156
 }
156
 }
157
 
157
 
158
 function backup_remote_cryptpad {
158
 function backup_remote_cryptpad {
159
-    if grep -q "cryptpad domain" $COMPLETION_FILE; then
159
+    if grep -q "cryptpad domain" "$COMPLETION_FILE"; then
160
         temp_backup_dir=$CRYPTPAD_DIR/datastore
160
         temp_backup_dir=$CRYPTPAD_DIR/datastore
161
         if [ -d $temp_backup_dir ]; then
161
         if [ -d $temp_backup_dir ]; then
162
             systemctl stop cryptpad
162
             systemctl stop cryptpad
226
     remove_onion_service cryptpad ${CRYPTPAD_ONION_PORT}
226
     remove_onion_service cryptpad ${CRYPTPAD_ONION_PORT}
227
     remove_app cryptpad
227
     remove_app cryptpad
228
     remove_completion_param install_cryptpad
228
     remove_completion_param install_cryptpad
229
-    sed -i '/cryptpad/d' $COMPLETION_FILE
229
+    sed -i '/cryptpad/d' "$COMPLETION_FILE"
230
 
230
 
231
     userdel -r cryptpad
231
     userdel -r cryptpad
232
 }
232
 }
236
 
236
 
237
     cryptpad_prefix=
237
     cryptpad_prefix=
238
     if [[ "$cryptpad_install_type" == "mesh" ]]; then
238
     if [[ "$cryptpad_install_type" == "mesh" ]]; then
239
-        cryptpad_prefix=$rootdir
239
+        # shellcheck disable=SC2154
240
+        cryptpad_prefix="$rootdir"
240
     fi
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
     if [[ "$cryptpad_install_type" == "mesh" ]]; then
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
     else
306
     else
306
         CRYPTPAD_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_cryptpad/hostname)
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
     fi
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
     if [[ "$cryptpad_install_type" != "mesh" ]]; then
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
     else
336
     else
337
         chroot "$rootdir" chown cryptpad:cryptpad $CRYPTPAD_DIR/config.js
337
         chroot "$rootdir" chown cryptpad:cryptpad $CRYPTPAD_DIR/config.js
338
     fi
338
     fi
339
 }
339
 }
340
 
340
 
341
 function mesh_install_cryptpad {
341
 function mesh_install_cryptpad {
342
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
342
+    # shellcheck disable=SC2153
343
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
343
         return
344
         return
344
     fi
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
     fi
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
     fi
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
         echo $'Unable to clone cryptpad repo'
357
         echo $'Unable to clone cryptpad repo'
357
         exit 783251
358
         exit 783251
358
     fi
359
     fi
360
     # an unprivileged user to run as
361
     # an unprivileged user to run as
361
     chroot "$rootdir" useradd -d $CRYPTPAD_DIR/ cryptpad
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
     chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
367
     chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
367
 
368
 
368
     cryptpad_nginx_site=$rootdir/etc/nginx/sites-available/cryptpad
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
     get_npm_arch
449
     get_npm_arch
449
 
450
 
450
-    cat <<EOF > $rootdir/usr/bin/install_cryptpad
451
+    cat <<EOF > "$rootdir/usr/bin/install_cryptpad"
451
 #!/bin/bash
452
 #!/bin/bash
452
 cd $CRYPTPAD_DIR
453
 cd $CRYPTPAD_DIR
453
 npm install --arch=$NPM_ARCH --build-from-source
454
 npm install --arch=$NPM_ARCH --build-from-source
456
 su -c 'bower install' - cryptpad
457
 su -c 'bower install' - cryptpad
457
 cp config.example.js config.js
458
 cp config.example.js config.js
458
 EOF
459
 EOF
459
-    chmod +x $rootdir/usr/bin/install_cryptpad
460
+    chmod +x "$rootdir/usr/bin/install_cryptpad"
460
     chroot "$rootdir" /usr/bin/install_cryptpad
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
         echo $'Cryptpad config file not found'
464
         echo $'Cryptpad config file not found'
464
         exit 628252
465
         exit 628252
465
     fi
466
     fi
466
 
467
 
467
-    rm $rootdir/usr/bin/install_cryptpad
468
+    rm "$rootdir/usr/bin/install_cryptpad"
468
 
469
 
469
     cryptpad_create_config mesh
470
     cryptpad_create_config mesh
470
 
471
 
471
     chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
472
     chroot "$rootdir" chown -R cryptpad:cryptpad $CRYPTPAD_DIR
472
 
473
 
473
     # daemon
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
     chroot "$rootdir" systemctl enable cryptpad.service
491
     chroot "$rootdir" systemctl enable cryptpad.service
491
 }
492
 }
492
 
493
 
505
     if [ -d /repos/cryptpad ]; then
506
     if [ -d /repos/cryptpad ]; then
506
         mkdir $CRYPTPAD_DIR
507
         mkdir $CRYPTPAD_DIR
507
         cp -r -p /repos/cryptpad/. $CRYPTPAD_DIR
508
         cp -r -p /repos/cryptpad/. $CRYPTPAD_DIR
508
-        cd $CRYPTPAD_DIR
509
+        cd $CRYPTPAD_DIR || exit 3468356385
509
         git pull
510
         git pull
510
     else
511
     else
511
         function_check git_clone
512
         function_check git_clone
520
     # an unprivileged user to run as
521
     # an unprivileged user to run as
521
     useradd -d $CRYPTPAD_DIR/ cryptpad
522
     useradd -d $CRYPTPAD_DIR/ cryptpad
522
 
523
 
523
-    cd $CRYPTPAD_DIR
524
+    cd $CRYPTPAD_DIR || exit 34683655
524
     git checkout $CRYPTPAD_COMMIT -b $CRYPTPAD_COMMIT
525
     git checkout $CRYPTPAD_COMMIT -b $CRYPTPAD_COMMIT
525
     set_completion_param "cryptpad commit" "$CRYPTPAD_COMMIT"
526
     set_completion_param "cryptpad commit" "$CRYPTPAD_COMMIT"
526
 
527
 
529
     CRYPTPAD_ONION_HOSTNAME=$(add_onion_service cryptpad 80 ${CRYPTPAD_ONION_PORT})
530
     CRYPTPAD_ONION_HOSTNAME=$(add_onion_service cryptpad 80 ${CRYPTPAD_ONION_PORT})
530
 
531
 
531
     cryptpad_nginx_site=/etc/nginx/sites-available/cryptpad
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
     function_check nginx_ensite
615
     function_check nginx_ensite
615
     nginx_ensite cryptpad
616
     nginx_ensite cryptpad
623
 
624
 
624
     install_cryptpad_main
625
     install_cryptpad_main
625
 
626
 
626
-    cd $CRYPTPAD_DIR
627
+    cd $CRYPTPAD_DIR || exit 35483548
627
 
628
 
628
     npm install
629
     npm install
629
     npm install -g bower@1.8.0
630
     npm install -g bower@1.8.0
639
     chown -R cryptpad:cryptpad $CRYPTPAD_DIR
640
     chown -R cryptpad:cryptpad $CRYPTPAD_DIR
640
 
641
 
641
     # daemon
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
     systemctl enable cryptpad.service
659
     systemctl enable cryptpad.service
659
     systemctl daemon-reload
660
     systemctl daemon-reload
660
     systemctl start cryptpad.service
661
     systemctl start cryptpad.service
664
     cryptpad_generate_api_config
665
     cryptpad_generate_api_config
665
 
666
 
666
     # install again
667
     # install again
667
-    cd $CRYPTPAD_DIR
668
+    cd $CRYPTPAD_DIR || exit 73537453
668
     su -c 'bower install' - cryptpad
669
     su -c 'bower install' - cryptpad
669
 
670
 
670
     systemctl restart nginx
671
     systemctl restart nginx

+ 62
- 57
src/freedombone-app-dlna 查看文件

49
 function configure_interactive_dlna {
49
 function configure_interactive_dlna {
50
     while true
50
     while true
51
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
53
         dialog --backtitle $"Freedombone Control Panel" \
55
                --title $"Media Menu" \
54
                --title $"Media Menu" \
56
                --radiolist $"Choose an operation:" 13 70 3 \
55
                --radiolist $"Choose an operation:" 13 70 3 \
57
                1 $"Attach a drive containing playable media" off \
56
                1 $"Attach a drive containing playable media" off \
58
                2 $"Remove a drive containing playable media" off \
57
                2 $"Remove a drive containing playable media" off \
59
-               3 $"Exit" on 2> $data
58
+               3 $"Exit" on 2> "$data"
60
         sel=$?
59
         sel=$?
61
         case $sel in
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
         esac
65
         esac
65
-        case $(cat $data) in
66
+        case $(cat "$data") in
66
             1) attach-music;;
67
             1) attach-music;;
67
             2) remove-music;;
68
             2) remove-music;;
68
-            3) break;;
69
+            3) rm -f "$data"
70
+               break;;
69
         esac
71
         esac
72
+        rm -f "$data"
70
     done
73
     done
71
 }
74
 }
72
 
75
 
84
 }
87
 }
85
 
88
 
86
 function configure_firewall_for_dlna {
89
 function configure_firewall_for_dlna {
87
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
90
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
88
         return
91
         return
89
     fi
92
     fi
90
     if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
93
     if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
95
     firewall_add DLNA 1900 udp
98
     firewall_add DLNA 1900 udp
96
     firewall_add DLNA 8200 tcp
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
     systemctl restart avahi-daemon
115
     systemctl restart avahi-daemon
113
 
116
 
114
-    mark_completed $FUNCNAME
117
+    mark_completed "${FUNCNAME[0]}"
115
 }
118
 }
116
 
119
 
117
 function backup_local_dlna {
120
 function backup_local_dlna {
125
 
128
 
126
 function restore_local_dlna {
129
 function restore_local_dlna {
127
     if [ -d /var/cache/minidlna ]; then
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
             echo $"Restoring DLNA cache"
132
             echo $"Restoring DLNA cache"
130
             temp_restore_dir=/root/tempdlna
133
             temp_restore_dir=/root/tempdlna
131
             function_check restore_directory_from_usb
134
             function_check restore_directory_from_usb
135
             else
138
             else
136
                 cp -r $temp_restore_dir/* /var/cache/minidlna/
139
                 cp -r $temp_restore_dir/* /var/cache/minidlna/
137
             fi
140
             fi
141
+            # shellcheck disable=SC2181
138
             if [ ! "$?" = "0" ]; then
142
             if [ ! "$?" = "0" ]; then
139
                 rm -rf $temp_restore_dir
143
                 rm -rf $temp_restore_dir
140
                 function_check set_user_permissions
144
                 function_check set_user_permissions
156
 
160
 
157
 function restore_remote_dlna {
161
 function restore_remote_dlna {
158
     if [ -d /var/cache/minidlna ]; then
162
     if [ -d /var/cache/minidlna ]; then
159
-        if [ -d $SERVER_DIRECTORY/backup/dlna ]; then
163
+        if [ -d "$SERVER_DIRECTORY/backup/dlna" ]; then
160
             temp_restore_dir=/root/tempdlna
164
             temp_restore_dir=/root/tempdlna
161
             function_check restore_directory_from_friend
165
             function_check restore_directory_from_friend
162
             restore_directory_from_friend $temp_restore_dir dlna
166
             restore_directory_from_friend $temp_restore_dir dlna
165
             else
169
             else
166
                 cp -r $temp_restore_dir/* /var/cache/minidlna/
170
                 cp -r $temp_restore_dir/* /var/cache/minidlna/
167
             fi
171
             fi
172
+            # shellcheck disable=SC2181
168
             if [ ! "$?" = "0" ]; then
173
             if [ ! "$?" = "0" ]; then
169
                 exit 982
174
                 exit 982
170
             fi
175
             fi
201
         exit 55
206
         exit 55
202
     fi
207
     fi
203
 
208
 
204
-    if [ ! $USB_MOUNT_DLNA ]; then
209
+    if [ ! "$USB_MOUNT_DLNA" ]; then
205
         USB_MOUNT_DLNA=/mnt/dlna
210
         USB_MOUNT_DLNA=/mnt/dlna
206
     fi
211
     fi
207
     if [ ${#USB_MOUNT_DLNA} -eq 0 ]; then
212
     if [ ${#USB_MOUNT_DLNA} -eq 0 ]; then
242
     systemctl reload minidlna
247
     systemctl reload minidlna
243
 
248
 
244
     sed -i 's/fs.inotify.max_user_watches*/fs.inotify.max_user_watches=65536/g' /etc/sysctl.conf
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
         echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
251
         echo 'fs.inotify.max_user_watches=65536' >> /etc/sysctl.conf
247
     fi
252
     fi
248
     /sbin/sysctl -p -q
253
     /sbin/sysctl -p -q
253
 }
258
 }
254
 
259
 
255
 function script_for_attaching_usb_drive {
260
 function script_for_attaching_usb_drive {
256
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
261
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
257
         return
262
         return
258
     fi
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
     chmod +x /usr/bin/attach-music
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
     chmod +x /usr/bin/remove-music
295
     chmod +x /usr/bin/remove-music
291
 
296
 
292
-    mark_completed $FUNCNAME
297
+    mark_completed "${FUNCNAME[0]}"
293
 }
298
 }
294
 
299
 
295
 function install_dlna {
300
 function install_dlna {

+ 256
- 252
src/freedombone-app-dokuwiki 查看文件

75
     new_user_password="$2"
75
     new_user_password="$2"
76
 
76
 
77
     DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
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
         HASHED_DOKUWIKI_PASSWORD=$(echo -n "$new_user_password" | md5sum | awk -F ' ' '{print $1}')
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
         if [[ "$existing_user" == *":admin,"* ]]; then
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
         else
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
         fi
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
     fi
90
     fi
91
 }
91
 }
92
 
92
 
96
 
96
 
97
     DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
97
     DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
98
     HASHED_DOKUWIKI_PASSWORD=$(echo -n "$new_user_password" | md5sum | awk -F ' ' '{print $1}')
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
 function remove_user_dokuwiki {
106
 function remove_user_dokuwiki {
107
     remove_username="$1"
107
     remove_username="$1"
108
 
108
 
109
     read_config_param "DOKUWIKI_DOMAIN_NAME"
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
     fi
114
     fi
115
 }
115
 }
116
 
116
 
120
 
120
 
121
 function upgrade_dokuwiki {
121
 function upgrade_dokuwiki {
122
     function_check set_repo_commit
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
 function backup_local_dokuwiki {
126
 function backup_local_dokuwiki {
129
     function_check backup_directory_to_usb
129
     function_check backup_directory_to_usb
130
 
130
 
131
     # backup the data
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
         dest_directory=dokuwikidat
134
         dest_directory=dokuwikidat
135
-        backup_directory_to_usb $source_directory $dest_directory
135
+        backup_directory_to_usb "$source_directory" "$dest_directory"
136
     fi
136
     fi
137
 
137
 
138
     # backup the users
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
         dest_directory=dokuwikiacl
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
     fi
144
     fi
145
 }
145
 }
146
 
146
 
153
     temp_restore_dir=/root/tempdokuwikidat
153
     temp_restore_dir=/root/tempdokuwikidat
154
     function_check restore_directory_from_usb
154
     function_check restore_directory_from_usb
155
     restore_directory_from_usb ${temp_restore_dir} dokuwikidat
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
     else
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
     fi
160
     fi
161
+    # shellcheck disable=SC2181
161
     if [ ! "$?" = "0" ]; then
162
     if [ ! "$?" = "0" ]; then
162
         function_check restore_directory_from_usb
163
         function_check restore_directory_from_usb
163
         set_user_permissions
164
         set_user_permissions
172
     temp_restore_dir=/root/tempdokuwikiacl
173
     temp_restore_dir=/root/tempdokuwikiacl
173
     function_check restore_directory_from_usb
174
     function_check restore_directory_from_usb
174
     restore_directory_from_usb ${temp_restore_dir} dokuwikiacl
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
     else
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
     fi
182
     fi
183
+    # shellcheck disable=SC2181
182
     if [ ! "$?" = "0" ]; then
184
     if [ ! "$?" = "0" ]; then
183
         function_check restore_directory_from_usb
185
         function_check restore_directory_from_usb
184
         set_user_permissions
186
         set_user_permissions
189
     fi
191
     fi
190
     rm -rf ${temp_restore_dir}
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
     echo $"Restore of Dokuwiki complete"
199
     echo $"Restore of Dokuwiki complete"
198
 }
200
 }
199
 
201
 
200
 function backup_remote_dokuwiki {
202
 function backup_remote_dokuwiki {
201
     DOKUWIKI_DOMAIN_NAME=$(get_completion_param "dokuwiki domain")
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
         echo $"Backing up dokuwiki"
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
     fi
209
     fi
208
 }
210
 }
209
 
211
 
212
     function_check get_completion_param
214
     function_check get_completion_param
213
     function_check restore_directory_from_friend
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
         echo $"Restoring Dokuwiki data for $DOKUWIKI_DOMAIN_NAME"
218
         echo $"Restoring Dokuwiki data for $DOKUWIKI_DOMAIN_NAME"
217
         temp_restore_dir=/root/tempdokuwikidat
219
         temp_restore_dir=/root/tempdokuwikidat
218
         restore_directory_from_friend $temp_restore_dir dokuwikidat
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
         else
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
         fi
225
         fi
226
+        # shellcheck disable=SC2181
224
         if [ ! "$?" = "0" ]; then
227
         if [ ! "$?" = "0" ]; then
225
             exit 92634
228
             exit 92634
226
         fi
229
         fi
229
         echo $"Restore of Dokuwiki data complete"
232
         echo $"Restore of Dokuwiki data complete"
230
     fi
233
     fi
231
 
234
 
232
-    if [ -d $SERVER_DIRECTORY/backup/dokuwikiacl ]; then
235
+    if [ -d "$SERVER_DIRECTORY/backup/dokuwikiacl" ]; then
233
         echo $"Restoring Dokuwiki users for $DOKUWIKI_DOMAIN_NAME"
236
         echo $"Restoring Dokuwiki users for $DOKUWIKI_DOMAIN_NAME"
234
         temp_restore_dir=/root/tempdokuwikiacl
237
         temp_restore_dir=/root/tempdokuwikiacl
235
         restore_directory_from_friend $temp_restore_dir dokuwikiacl
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
         else
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
         fi
243
         fi
244
+        # shellcheck disable=SC2181
241
         if [ ! "$?" = "0" ]; then
245
         if [ ! "$?" = "0" ]; then
242
             exit 735287
246
             exit 735287
243
         fi
247
         fi
246
         echo $"Restore of Dokuwiki users complete"
250
         echo $"Restore of Dokuwiki users complete"
247
     fi
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
 function remove_dokuwiki {
260
 function remove_dokuwiki {
259
     fi
263
     fi
260
     function_check remove_onion_service
264
     function_check remove_onion_service
261
     remove_onion_service dokuwiki ${DOKUWIKI_ONION_PORT}
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
     fi
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
     fi
273
     fi
270
     if [ -d /var/lib/dokuwiki ]; then
274
     if [ -d /var/lib/dokuwiki ]; then
271
         rm -rf /var/lib/dokuwiki
275
         rm -rf /var/lib/dokuwiki
278
     fi
282
     fi
279
     remove_completion_param "install_dokuwiki"
283
     remove_completion_param "install_dokuwiki"
280
     remove_completion_param "dokuwiki domain"
284
     remove_completion_param "dokuwiki domain"
281
-    sed -i '/dokuwiki/d' $COMPLETION_FILE
285
+    sed -i '/dokuwiki/d' "$COMPLETION_FILE"
282
 
286
 
283
     function_check remove_ddns_domain
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
 function install_dokuwiki {
291
 function install_dokuwiki {
288
-    if [ ! $DOKUWIKI_DOMAIN_NAME ]; then
292
+    if [ ! "$DOKUWIKI_DOMAIN_NAME" ]; then
289
         return
293
         return
290
     fi
294
     fi
291
 
295
 
293
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
297
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
294
     apt-get -yq install php-memcached memcached
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
     fi
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
         if [ -d /repos/dokuwiki ]; then
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
             git pull
311
             git pull
308
         else
312
         else
309
             function_check git_clone
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
         fi
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
         set_completion_param "dokuwiki commit" "$DOKUWIKI_COMMIT"
319
         set_completion_param "dokuwiki commit" "$DOKUWIKI_COMMIT"
316
 
320
 
317
     fi
321
     fi
322
         echo $'Removed Apache installation after Dokuwiki install'
326
         echo $'Removed Apache installation after Dokuwiki install'
323
     fi
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
     else
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
         fi
348
         fi
345
     fi
349
     fi
346
     HASHED_DOKUWIKI_PASSWORD=$(echo -n "$DOKUWIKI_ADMIN_PASSWORD" | md5sum | awk -F ' ' '{print $1}')
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
     fi
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
     fi
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
     fi
363
     fi
360
 
364
 
361
     DOKUWIKI_ONION_HOSTNAME=$(add_onion_service dokuwiki 80 ${DOKUWIKI_ONION_PORT})
365
     DOKUWIKI_ONION_HOSTNAME=$(add_onion_service dokuwiki 80 ${DOKUWIKI_ONION_PORT})
363
 
367
 
364
     if [[ $ONION_ONLY == "no" ]]; then
368
     if [[ $ONION_ONLY == "no" ]]; then
365
         function_check nginx_http_redirect
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
         function_check nginx_ssl
381
         function_check nginx_ssl
378
-        nginx_ssl $DOKUWIKI_DOMAIN_NAME
382
+        nginx_ssl "$DOKUWIKI_DOMAIN_NAME"
379
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
         function_check nginx_limits
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
     else
449
     else
446
-        echo -n '' > /etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME
450
+        echo -n '' > "/etc/nginx/sites-available/$DOKUWIKI_DOMAIN_NAME"
447
     fi
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check nginx_limits
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
     function_check create_site_certificate
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
     function_check configure_php
530
     function_check configure_php
527
     configure_php
531
     configure_php
528
 
532
 
529
-    nginx_ensite $DOKUWIKI_DOMAIN_NAME
533
+    nginx_ensite "$DOKUWIKI_DOMAIN_NAME"
530
 
534
 
531
     systemctl restart php7.0-fpm
535
     systemctl restart php7.0-fpm
532
     systemctl restart nginx
536
     systemctl restart nginx
533
 
537
 
534
     function_check add_ddns_domain
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
     APP_INSTALLED=1
543
     APP_INSTALLED=1
540
 }
544
 }

+ 135
- 134
src/freedombone-app-edith 查看文件

50
 function remove_bad_links_edith {
50
 function remove_bad_links_edith {
51
     read_config_param EDITH_DOMAIN_NAME
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
     # copy jquery locally
55
     # copy jquery locally
56
     jquery_version='1.12.4'
56
     jquery_version='1.12.4'
57
     if [ ! -f $edith_dir/jquery-${jquery_version}.js ]; then
57
     if [ ! -f $edith_dir/jquery-${jquery_version}.js ]; then
58
-        cd $edith_dir
58
+        cd $edith_dir || exit 246824628
59
         wget https://code.jquery.com/jquery-${jquery_version}.js
59
         wget https://code.jquery.com/jquery-${jquery_version}.js
60
         if [ -f $edith_dir/jquery-${jquery_version}.js ]; then
60
         if [ -f $edith_dir/jquery-${jquery_version}.js ]; then
61
             jquery_hash=$(sha256sum $edith_dir/jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
61
             jquery_hash=$(sha256sum $edith_dir/jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
79
     new_user_password="$2"
79
     new_user_password="$2"
80
 
80
 
81
     sed -i "/${curr_username}:/d" /etc/nginx/.edithpasswd
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
 function logging_on_edith {
87
 function logging_on_edith {
102
     dialog --title $"Enable Edith login" \
102
     dialog --title $"Enable Edith login" \
103
            --backtitle $"Freedombone Control Panel" \
103
            --backtitle $"Freedombone Control Panel" \
104
            --defaultno \
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
     sel=$?
106
     sel=$?
107
     case $sel in
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
                systemctl restart nginx
110
                systemctl restart nginx
111
            fi
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
            dialog --title $"Enable Edith login" \
114
            dialog --title $"Enable Edith login" \
115
                   --msgbox $"Edith logins are now enabled with the password $EDITH_PASSWORD" 6 65
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
                systemctl restart nginx
119
                systemctl restart nginx
121
            fi
120
            fi
122
            dialog --title $"Disable Edith login" \
121
            dialog --title $"Disable Edith login" \
127
 
126
 
128
 function edith_browse {
127
 function edith_browse {
129
     read_config_param EDITH_DOMAIN_NAME
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
 function configure_interactive_edith {
133
 function configure_interactive_edith {
135
     while true
134
     while true
136
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
137
         dialog --backtitle $"Freedombone Control Panel" \
140
                --title $"Edith" \
138
                --title $"Edith" \
141
                --radiolist $"Choose an operation:" 10 50 3 \
139
                --radiolist $"Choose an operation:" 10 50 3 \
142
                1 $"Enable login" off \
140
                1 $"Enable login" off \
143
                2 $"Browse notes" off \
141
                2 $"Browse notes" off \
144
-               3 $"Exit" on 2> $data
142
+               3 $"Exit" on 2> "$data"
145
         sel=$?
143
         sel=$?
146
         case $sel in
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
         esac
149
         esac
150
-        case $(cat $data) in
150
+        case $(cat "$data") in
151
             1) edith_enable_login;;
151
             1) edith_enable_login;;
152
             2) edith_browse;;
152
             2) edith_browse;;
153
-            3) break;;
153
+            3) rm -f "$data"
154
+               break;;
154
         esac
155
         esac
156
+        rm -f "$data"
155
     done
157
     done
156
 }
158
 }
157
 
159
 
165
 
167
 
166
     # update to the next commit
168
     # update to the next commit
167
     function_check set_repo_commit
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
     remove_bad_links_edith
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
 function backup_local_edith {
177
 function backup_local_edith {
176
     read_config_param EDITH_DOMAIN_NAME
178
     read_config_param EDITH_DOMAIN_NAME
177
 
179
 
178
     function_check suspend_site
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
     function_check backup_directory_to_usb
185
     function_check backup_directory_to_usb
184
     dest_directory=edith
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
     function_check restart_site
189
     function_check restart_site
188
     restart_site
190
     restart_site
192
     read_config_param EDITH_DOMAIN_NAME
194
     read_config_param EDITH_DOMAIN_NAME
193
 
195
 
194
     temp_restore_dir=/root/tempedith
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
     function_check restore_directory_from_usb
199
     function_check restore_directory_from_usb
198
     restore_directory_from_usb $temp_restore_dir edith
200
     restore_directory_from_usb $temp_restore_dir edith
199
     if [ -d $temp_restore_dir ]; then
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
             cp -rp $temp_restore_dir$edith_dir $edith_dir/
203
             cp -rp $temp_restore_dir$edith_dir $edith_dir/
202
         else
204
         else
203
             if [ ! -d $edith_dir ]; then
205
             if [ ! -d $edith_dir ]; then
215
     read_config_param EDITH_DOMAIN_NAME
217
     read_config_param EDITH_DOMAIN_NAME
216
 
218
 
217
     function_check suspend_site
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
     function_check backup_directory_to_friend
224
     function_check backup_directory_to_friend
223
     dest_directory=edith
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
     function_check restart_site
228
     function_check restart_site
227
     restart_site
229
     restart_site
231
     read_config_param EDITH_DOMAIN_NAME
233
     read_config_param EDITH_DOMAIN_NAME
232
 
234
 
233
     temp_restore_dir=/root/tempedith
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
     function_check restore_directory_from_friend
238
     function_check restore_directory_from_friend
237
     restore_directory_from_friend $temp_restore_dir edith
239
     restore_directory_from_friend $temp_restore_dir edith
238
     if [ -d $temp_restore_dir ]; then
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
             cp -rp $temp_restore_dir$edith_dir $edith_dir/
242
             cp -rp $temp_restore_dir$edith_dir $edith_dir/
241
         else
243
         else
242
             if [ ! -d $edith_dir ]; then
244
             if [ ! -d $edith_dir ]; then
253
 function remove_edith {
255
 function remove_edith {
254
     nginx_dissite $EDITH_DOMAIN_NAME
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
     fi
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
     fi
264
     fi
263
 
265
 
264
     function_check remove_onion_service
266
     function_check remove_onion_service
265
     remove_onion_service edith ${EDITH_ONION_PORT}
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
     if [ -f /etc/nginx/.edithpasswd ]; then
270
     if [ -f /etc/nginx/.edithpasswd ]; then
269
         rm /etc/nginx/.edithpasswd
271
         rm /etc/nginx/.edithpasswd
286
     function_check install_nodejs
288
     function_check install_nodejs
287
     install_nodejs edith
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
         else
294
         else
293
-            EDITH_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
295
+            EDITH_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
294
         fi
296
         fi
295
     fi
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
     fi
301
     fi
300
 
302
 
301
     if [ -d /repos/edith ]; then
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
         git pull
307
         git pull
306
     else
308
     else
307
         function_check git_clone
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
     fi
311
     fi
310
 
312
 
311
     if [ ! -d /var/www/$EDITH_DOMAIN_NAME/htdocs ]; then
313
     if [ ! -d /var/www/$EDITH_DOMAIN_NAME/htdocs ]; then
313
         exit 537593569
315
         exit 537593569
314
     fi
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
     set_completion_param "edith commit" "$EDITH_COMMIT"
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
     fi
324
     fi
323
 
325
 
324
     EDITH_ONION_HOSTNAME=$(add_onion_service edith 80 ${EDITH_ONION_PORT})
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
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl
341
         function_check nginx_ssl
340
-        nginx_ssl $EDITH_DOMAIN_NAME
342
+        nginx_ssl "$EDITH_DOMAIN_NAME"
341
 
343
 
342
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
372
     else
371
-        echo -n '' > $edith_nginx_site
373
+        echo -n '' > "$edith_nginx_site"
372
     fi
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
     function_check nginx_compress
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
401
     function_check nginx_limits
400
     nginx_limits $EDITH_DOMAIN_NAME '15m'
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
     function_check configure_php
409
     function_check configure_php
408
     configure_php
410
     configure_php
409
 
411
 
410
     function_check create_site_certificate
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
     # create a password for users
415
     # create a password for users
414
     if [ ! -f /etc/nginx/.edithpasswd ]; then
416
     if [ ! -f /etc/nginx/.edithpasswd ]; then
417
     if grep -q "$MY_USERNAME:" /etc/nginx/.edithpasswd; then
419
     if grep -q "$MY_USERNAME:" /etc/nginx/.edithpasswd; then
418
         sed -i "/$MY_USERNAME:/d" /etc/nginx/.edithpasswd
420
         sed -i "/$MY_USERNAME:/d" /etc/nginx/.edithpasswd
419
     fi
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
     if [ ! -f /etc/nginx/.edithpasswd ]; then
423
     if [ ! -f /etc/nginx/.edithpasswd ]; then
422
         echo $'/etc/nginx/.edithpasswd not found'
424
         echo $'/etc/nginx/.edithpasswd not found'
423
         exit 6537683563
425
         exit 6537683563
424
     fi
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
     npm install -g coffeescript uglify-js
432
     npm install -g coffeescript uglify-js
431
-    cake build
432
-    if [ ! "$?" = "0" ]; then
433
+    if ! cake build; then
433
         echo $'Unable to build Edith'
434
         echo $'Unable to build Edith'
434
         exit 7396483635
435
         exit 7396483635
435
     fi
436
     fi
436
     cp config.example.php config.php
437
     cp config.example.php config.php
437
-    if [[ $ONION_ONLY == "no" ]]; then
438
+    if [[ "$ONION_ONLY" == "no" ]]; then
438
         sed -i "s|define('EDITH_URI'.*|define('EDITH_URI', 'https://$EDITH_DOMAIN_NAME');|g" config.php
439
         sed -i "s|define('EDITH_URI'.*|define('EDITH_URI', 'https://$EDITH_DOMAIN_NAME');|g" config.php
439
     else
440
     else
440
         sed -i "s|define('EDITH_URI'.*|define('EDITH_URI', 'http://$EDITH_ONION_HOSTNAME');|g" config.php
441
         sed -i "s|define('EDITH_URI'.*|define('EDITH_URI', 'http://$EDITH_ONION_HOSTNAME');|g" config.php
445
 
446
 
446
     remove_bad_links_edith
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
     systemctl restart nginx
452
     systemctl restart nginx
452
 
453
 
453
     APP_INSTALLED=1
454
     APP_INSTALLED=1
454
 }
455
 }
455
 
456
 
456
 function install_interactive_edith {
457
 function install_interactive_edith {
457
-    if [ ! $ONION_ONLY ]; then
458
+    if [ ! "$ONION_ONLY" ]; then
458
         ONION_ONLY='no'
459
         ONION_ONLY='no'
459
     fi
460
     fi
460
 
461
 
461
-    if [[ $ONION_ONLY != "no" ]]; then
462
+    if [[ "$ONION_ONLY" != "no" ]]; then
462
         GHOST_DOMAIN_NAME='edith.local'
463
         GHOST_DOMAIN_NAME='edith.local'
463
         write_config_param "EDITH_DOMAIN_NAME" "$EDITH_DOMAIN_NAME"
464
         write_config_param "EDITH_DOMAIN_NAME" "$EDITH_DOMAIN_NAME"
464
     else
465
     else

+ 147
- 145
src/freedombone-app-emacs 查看文件

57
     for d in /home/*/ ; do
57
     for d in /home/*/ ; do
58
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
58
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
59
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 echo $"Backing up Emacs config for $USERNAME"
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
                 fi
64
                 fi
65
                 function_check backup_directory_to_usb
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
             fi
67
             fi
68
         fi
68
         fi
69
     done
69
     done
71
 
71
 
72
 function restore_local_emacs {
72
 function restore_local_emacs {
73
     temp_restore_dir=/root/tempemacs
73
     temp_restore_dir=/root/tempemacs
74
-    if [ -d $USB_MOUNT/backup/emacs ]; then
74
+    if [ -d "$USB_MOUNT/backup/emacs" ]; then
75
         for d in $USB_MOUNT/backup/emacs/*/ ; do
75
         for d in $USB_MOUNT/backup/emacs/*/ ; do
76
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
76
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
77
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
80
                 fi
81
                 echo $"Restoring Emacs config for $USERNAME"
81
                 echo $"Restoring Emacs config for $USERNAME"
82
                 function_check restore_directory_from_usb
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
                 else
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
                     fi
89
                     fi
90
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.emacs.d
90
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.emacs.d"
91
                 fi
91
                 fi
92
+                # shellcheck disable=SC2181
92
                 if [ ! "$?" = "0" ]; then
93
                 if [ ! "$?" = "0" ]; then
93
                     rm -rf $temp_restore_dir
94
                     rm -rf $temp_restore_dir
94
                     function_check set_user_permissions
95
                     function_check set_user_permissions
97
                     backup_unmount_drive
98
                     backup_unmount_drive
98
                     exit 664
99
                     exit 664
99
                 fi
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
                 else
103
                 else
103
-                    cp -f $temp_restore_dir/dotemacs /home/$USERNAME/.emacs
104
+                    cp -f "$temp_restore_dir/dotemacs" "/home/$USERNAME/.emacs"
104
                 fi
105
                 fi
105
                 rm -rf $temp_restore_dir
106
                 rm -rf $temp_restore_dir
106
             fi
107
             fi
112
     for d in /home/*/ ; do
113
     for d in /home/*/ ; do
113
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
114
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
114
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 echo $"Backing up Emacs config for $USERNAME"
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
                 fi
120
                 fi
120
                 function_check backup_directory_to_friend
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
             fi
123
             fi
123
         fi
124
         fi
124
     done
125
     done
126
 
127
 
127
 function restore_remote_emacs {
128
 function restore_remote_emacs {
128
     temp_restore_dir=/root/tempemacs
129
     temp_restore_dir=/root/tempemacs
129
-    if [ -d $USB_MOUNT/backup/emacs ]; then
130
+    if [ -d "$USB_MOUNT/backup/emacs" ]; then
130
         for d in $USB_MOUNT/backup/emacs/*/ ; do
131
         for d in $USB_MOUNT/backup/emacs/*/ ; do
131
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
132
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
132
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
136
                 fi
136
                 echo $"Restoring Emacs config for $USERNAME"
137
                 echo $"Restoring Emacs config for $USERNAME"
137
                 function_check restore_directory_from_friend
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
                 else
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
                     fi
145
                     fi
145
-                    cp -r $temp_restore_dir/* /home/$USERNAME/.emacs.d/*
146
+                    cp -r "$temp_restore_dir/*" "/home/$USERNAME/.emacs.d/*"
146
                 fi
147
                 fi
148
+                # shellcheck disable=SC2181
147
                 if [ ! "$?" = "0" ]; then
149
                 if [ ! "$?" = "0" ]; then
148
                     rm -rf $temp_restore_dir
150
                     rm -rf $temp_restore_dir
149
                     function_check set_user_permissions
151
                     function_check set_user_permissions
152
                     backup_unmount_drive
154
                     backup_unmount_drive
153
                     exit 664
155
                     exit 664
154
                 fi
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
                 else
159
                 else
158
-                    cp -f $temp_restore_dir/dotemacs /home/$USERNAME/.emacs
160
+                    cp -f "$temp_restore_dir/dotemacs" "/home/$USERNAME/.emacs"
159
                 fi
161
                 fi
160
                 rm -rf $temp_restore_dir
162
                 rm -rf $temp_restore_dir
161
             fi
163
             fi
166
 function remove_emacs {
168
 function remove_emacs {
167
     apt-get -yq remove --purge emacs
169
     apt-get -yq remove --purge emacs
168
     update-alternatives --set editor /usr/bin/nano
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
     # remove emacs as the mutt email editor
173
     # remove emacs as the mutt email editor
172
     if [ -f /etc/Muttrc ]; then
174
     if [ -f /etc/Muttrc ]; then
176
         for d in /home/*/ ; do
178
         for d in /home/*/ ; do
177
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
179
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
178
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                     fi
184
                     fi
183
                 fi
185
                 fi
184
             fi
186
             fi
194
     #echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
196
     #echo -n "(add-to-list 'load-path " > /home/$MY_USERNAME/.emacs
195
     #echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
197
     #echo '"~/.emacs.d/")' >> /home/$MY_USERNAME/.emacs
196
     #echo '' >> /home/$MY_USERNAME/.emacs
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
     # add a mutt entry to use emacs to compose emails
268
     # add a mutt entry to use emacs to compose emails
267
     if [ -f /etc/Muttrc ]; then
269
     if [ -f /etc/Muttrc ]; then
273
         for d in /home/*/ ; do
275
         for d in /home/*/ ; do
274
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
276
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
275
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                     else
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
                     fi
283
                     fi
282
                 fi
284
                 fi
283
 
285
 
284
                 # create an Emacs configuration specifically for use with Mutt, which
286
                 # create an Emacs configuration specifically for use with Mutt, which
285
                 # has word wrap and spell checking on by default
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
                     if [[ $DEFAULT_LANGUAGE == 'en_US'* ]]; then
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
                     fi
304
                     fi
303
                     if [[ $DEFAULT_LANGUAGE == 'en_GB'* ]]; then
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
                     fi
307
                     fi
306
                     if [[ $DEFAULT_LANGUAGE == 'fr_FR'* ]]; then
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
                     fi
310
                     fi
309
                     if [[ $DEFAULT_LANGUAGE == 'it_IT'* ]]; then
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
                     fi
313
                     fi
312
                     if [[ $DEFAULT_LANGUAGE == 'cs_CZ'* ]]; then
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
                     fi
316
                     fi
315
                     if [[ $DEFAULT_LANGUAGE == 'da_DK'* ]]; then
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
                     fi
319
                     fi
318
                     if [[ $DEFAULT_LANGUAGE == 'nl_NL'* ]]; then
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
                     fi
322
                     fi
321
                     if [[ $DEFAULT_LANGUAGE == 'ru_RU'* ]]; then
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
                     fi
325
                     fi
324
                     if [[ $DEFAULT_LANGUAGE == 'es_ES'* ]]; then
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
                     fi
328
                     fi
327
                     if [[ $DEFAULT_LANGUAGE == 'sv_SE'* ]]; then
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
                     fi
331
                     fi
330
                     if [[ $DEFAULT_LANGUAGE == 'no_NO'* ]]; then
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
                     fi
334
                     fi
333
                     if [[ $DEFAULT_LANGUAGE == 'de_DE'* ]]; then
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
                     fi
337
                     fi
336
                     if [[ $DEFAULT_LANGUAGE == 'bg_BG'* ]]; then
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
                     fi
340
                     fi
339
                     if [[ $DEFAULT_LANGUAGE == 'pl'* ]]; then
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
                     fi
343
                     fi
342
                     if [[ $DEFAULT_LANGUAGE == 'et_EE'* ]]; then
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
                     fi
346
                     fi
345
                     if [[ $DEFAULT_LANGUAGE == 'lt_LT'* ]]; then
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
                     fi
349
                     fi
348
                     if [[ $DEFAULT_LANGUAGE == 'uk_UA'* ]]; then
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
                     fi
352
                     fi
351
                     if [[ $DEFAULT_LANGUAGE == 'ca_ES'* ]]; then
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
                     fi
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
                     # add the emacs mutt configuration to the user profile skeleton
361
                     # add the emacs mutt configuration to the user profile skeleton
360
                     if [ ! -f /etc/skel/.emacs-mutt ]; then
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
                         chown root:root /etc/skel/.emacs-mutt
364
                         chown root:root /etc/skel/.emacs-mutt
363
                     fi
365
                     fi
364
                 fi
366
                 fi

+ 243
- 240
src/freedombone-app-etherpad 查看文件

41
 ETHERPAD_COMMIT='454f539561a8d9de51ed107a29d974eb79198bc6'
41
 ETHERPAD_COMMIT='454f539561a8d9de51ed107a29d974eb79198bc6'
42
 ETHERPAD_ADMIN_PASSWORD=
42
 ETHERPAD_ADMIN_PASSWORD=
43
 ETHERPAD_TITLE=$'Freedombone Docs'
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
 etherpad_variables=(ONION_ONLY
46
 etherpad_variables=(ONION_ONLY
47
                     DEFAULT_DOMAIN_NAME
47
                     DEFAULT_DOMAIN_NAME
67
     read_config_param ETHERPAD_DOMAIN_NAME
67
     read_config_param ETHERPAD_DOMAIN_NAME
68
 
68
 
69
     if grep -q "\"$change_username\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then
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
         if [[ "$user_line" == *"\"is_admin\": true"* ]]; then
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
         else
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
         fi
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
         systemctl restart etherpad
77
         systemctl restart etherpad
78
     fi
78
     fi
79
 }
79
 }
80
 
80
 
81
 function etherpad_create_database {
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
     else
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
         fi
87
         fi
88
     fi
88
     fi
89
-    if [ ! $ETHERPAD_ADMIN_PASSWORD ]; then
89
+    if [ ! "$ETHERPAD_ADMIN_PASSWORD" ]; then
90
         return
90
         return
91
     fi
91
     fi
92
 
92
 
93
     function_check create_database
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
 function create_etherpad_settings {
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
     chmod 600 $settings_file
173
     chmod 600 $settings_file
174
 }
174
 }
175
 
175
 
177
     remove_username="$1"
177
     remove_username="$1"
178
     settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
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
     if grep -q "\"$remove_username\": {" $settings_file; then
182
     if grep -q "\"$remove_username\": {" $settings_file; then
183
         sed -i "/\"$remove_username\": {/d" $settings_file
183
         sed -i "/\"$remove_username\": {/d" $settings_file
191
     settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
191
     settings_file=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json
192
 
192
 
193
     if ! grep -q "\"$new_username\": {" $settings_file; then
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
         sed -i "/\"users\": {/a    \"$new_username\": { \"password\": \"$new_user_password\", \"is_admin\": false }," $settings_file
195
         sed -i "/\"users\": {/a    \"$new_username\": { \"password\": \"$new_user_password\", \"is_admin\": false }," $settings_file
196
         if grep -q "\"$new_username\": {" $settings_file; then
196
         if grep -q "\"$new_username\": {" $settings_file; then
197
             systemctl restart etherpad
197
             systemctl restart etherpad
204
 }
204
 }
205
 
205
 
206
 function install_interactive_etherpad {
206
 function install_interactive_etherpad {
207
-    if [ ! $ONION_ONLY ]; then
207
+    if [ ! "$ONION_ONLY" ]; then
208
         ONION_ONLY='no'
208
         ONION_ONLY='no'
209
     fi
209
     fi
210
 
210
 
211
-    if [[ $ONION_ONLY != "no" ]]; then
211
+    if [[ "$ONION_ONLY" != "no" ]]; then
212
         ETHERPAD_DOMAIN_NAME='etherpad.local'
212
         ETHERPAD_DOMAIN_NAME='etherpad.local'
213
         write_config_param "ETHERPAD_DOMAIN_NAME" "$ETHERPAD_DOMAIN_NAME"
213
         write_config_param "ETHERPAD_DOMAIN_NAME" "$ETHERPAD_DOMAIN_NAME"
214
     else
214
     else
220
 
220
 
221
 function etherpad_set_title {
221
 function etherpad_set_title {
222
     read_config_param "ETHERPAD_TITLE"
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
     dialog --title $"Etherpad Title" \
224
     dialog --title $"Etherpad Title" \
226
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
227
     sel=$?
229
     case $sel in
228
     case $sel in
230
         0)
229
         0)
231
-            temp_title=$(<$data)
230
+            temp_title=$(<"$data")
232
             if [ ${#temp_title} -gt 0 ]; then
231
             if [ ${#temp_title} -gt 0 ]; then
233
                 ETHERPAD_TITLE="$temp_title"
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
                 write_config_param "ETHERPAD_TITLE" "$ETHERPAD_TITLE"
235
                 write_config_param "ETHERPAD_TITLE" "$ETHERPAD_TITLE"
237
                 sed -i "s|\"title\":.*|\"title\": \"${ETHERPAD_TITLE}\"|g" $settings_file
236
                 sed -i "s|\"title\":.*|\"title\": \"${ETHERPAD_TITLE}\"|g" $settings_file
241
             fi
240
             fi
242
            ;;
241
            ;;
243
     esac
242
     esac
243
+    rm -f "$data"
244
 }
244
 }
245
 
245
 
246
 function etherpad_set_welcome_message {
246
 function etherpad_set_welcome_message {
247
     read_config_param "ETHERPAD_WELCOME_MESSAGE"
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
     dialog --title $"Etherpad Welcome Message" \
249
     dialog --title $"Etherpad Welcome Message" \
251
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
252
     sel=$?
254
     case $sel in
253
     case $sel in
255
         0)
254
         0)
256
-            temp_welcome=$(<$data)
255
+            temp_welcome=$(<"$data")
257
             if [ ${#temp_welcome} -gt 0 ]; then
256
             if [ ${#temp_welcome} -gt 0 ]; then
258
                 ETHERPAD_WELCOME_MESSAGE="$temp_welcome"
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
                 write_config_param "ETHERPAD_WELCOME_MESSAGE" "$ETHERPAD_WELCOME_MESSAGE"
260
                 write_config_param "ETHERPAD_WELCOME_MESSAGE" "$ETHERPAD_WELCOME_MESSAGE"
262
                 sed -i "s|\"defaultPadText\" :.*|\"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"|g" $settings_file
261
                 sed -i "s|\"defaultPadText\" :.*|\"defaultPadText\" : \"${ETHERPAD_WELCOME_MESSAGE}\"|g" $settings_file
266
             fi
265
             fi
267
            ;;
266
            ;;
268
     esac
267
     esac
268
+    rm -f "$data"
269
 }
269
 }
270
 
270
 
271
 function configure_interactive_etherpad {
271
 function configure_interactive_etherpad {
272
     while true
272
     while true
273
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
275
         dialog --backtitle $"Freedombone Control Panel" \
277
                --title $"Etherpad Settings" \
276
                --title $"Etherpad Settings" \
278
                --radiolist $"Choose an operation:" 12 70 3 \
277
                --radiolist $"Choose an operation:" 12 70 3 \
279
                1 $"Set Title" off \
278
                1 $"Set Title" off \
280
                2 $"Set a welcome message" off \
279
                2 $"Set a welcome message" off \
281
-               3 $"Exit" on 2> $data
280
+               3 $"Exit" on 2> "$data"
282
         sel=$?
281
         sel=$?
283
         case $sel in
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
         esac
287
         esac
287
-        case $(cat $data) in
288
+        case $(cat "$data") in
288
             1) etherpad_set_title;;
289
             1) etherpad_set_title;;
289
             2) etherpad_set_welcome_message;;
290
             2) etherpad_set_welcome_message;;
290
-            3) break;;
291
+            3) rm -f "$data"
292
+               break;;
291
         esac
293
         esac
294
+        rm -f "$data"
292
     done
295
     done
293
 }
296
 }
294
 
297
 
311
 
314
 
312
 function backup_local_etherpad {
315
 function backup_local_etherpad {
313
     ETHERPAD_DOMAIN_NAME='etherpad'
316
     ETHERPAD_DOMAIN_NAME='etherpad'
314
-    if grep -q "etherpad domain" $COMPLETION_FILE; then
317
+    if grep -q "etherpad domain" "$COMPLETION_FILE"; then
315
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
318
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
316
     fi
319
     fi
317
 
320
 
318
     source_directory=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
321
     source_directory=/var/www/${ETHERPAD_DOMAIN_NAME}/htdocs
319
-    if [ -d $source_directory ]; then
322
+    if [ -d "$source_directory" ]; then
320
         dest_directory=etherpad
323
         dest_directory=etherpad
321
         function_check suspend_site
324
         function_check suspend_site
322
-        suspend_site ${ETHERPAD_DOMAIN_NAME}
325
+        suspend_site "${ETHERPAD_DOMAIN_NAME}"
323
 
326
 
324
         function_check backup_directory_to_usb
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
         function_check backup_database_to_usb
330
         function_check backup_database_to_usb
328
         backup_database_to_usb etherpad
331
         backup_database_to_usb etherpad
333
 }
336
 }
334
 
337
 
335
 function restore_local_etherpad {
338
 function restore_local_etherpad {
336
-    if ! grep -q "etherpad domain" $COMPLETION_FILE; then
339
+    if ! grep -q "etherpad domain" "$COMPLETION_FILE"; then
337
         return
340
         return
338
     fi
341
     fi
339
     ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
342
     ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
340
-    if [ $ETHERPAD_DOMAIN_NAME ]; then
343
+    if [ "$ETHERPAD_DOMAIN_NAME" ]; then
341
         temp_restore_dir=/root/tempetherpad
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
         function_check etherpad_create_database
347
         function_check etherpad_create_database
345
         etherpad_create_database
348
         etherpad_create_database
346
 
349
 
347
-        restore_database etherpad ${ETHERPAD_DOMAIN_NAME}
350
+        restore_database etherpad "${ETHERPAD_DOMAIN_NAME}"
348
         if [ -d $temp_restore_dir ]; then
351
         if [ -d $temp_restore_dir ]; then
349
             rm -rf $temp_restore_dir
352
             rm -rf $temp_restore_dir
350
         fi
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
         fi
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
         fi
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
         MARIADB_PASSWORD=
366
         MARIADB_PASSWORD=
364
     fi
367
     fi
365
 }
368
 }
366
 
369
 
367
 function backup_remote_etherpad {
370
 function backup_remote_etherpad {
368
-    if grep -q "etherpad domain" $COMPLETION_FILE; then
371
+    if grep -q "etherpad domain" "$COMPLETION_FILE"; then
369
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
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
             function_check suspend_site
375
             function_check suspend_site
373
-            suspend_site ${ETHERPAD_DOMAIN_NAME}
376
+            suspend_site "${ETHERPAD_DOMAIN_NAME}"
374
 
377
 
375
             function_check backup_database_to_friend
378
             function_check backup_database_to_friend
376
             backup_database_to_friend etherpad
379
             backup_database_to_friend etherpad
377
 
380
 
378
             function_check backup_directory_to_friend
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
             function_check restart_site
384
             function_check restart_site
382
             restart_site
385
             restart_site
387
 }
390
 }
388
 
391
 
389
 function restore_remote_etherpad {
392
 function restore_remote_etherpad {
390
-    if grep -q "etherpad domain" $COMPLETION_FILE; then
393
+    if grep -q "etherpad domain" "$COMPLETION_FILE"; then
391
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
394
         ETHERPAD_DOMAIN_NAME=$(get_completion_param "etherpad domain")
392
 
395
 
393
         function_check etherpad_create_database
396
         function_check etherpad_create_database
394
         etherpad_create_database
397
         etherpad_create_database
395
 
398
 
396
         function_check restore_database_from_friend
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
         if [ -d /root/tempetherpad ]; then
401
         if [ -d /root/tempetherpad ]; then
399
             rm -rf /root/tempetherpad
402
             rm -rf /root/tempetherpad
400
         fi
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
         fi
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
         fi
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
         MARIADB_PASSWORD=
416
         MARIADB_PASSWORD=
414
     fi
417
     fi
415
 }
418
 }
427
         rm /etc/systemd/system/etherpad.service
430
         rm /etc/systemd/system/etherpad.service
428
     fi
431
     fi
429
     systemctl daemon-reload
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
     fi
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
     fi
440
     fi
438
     function_check drop_database
441
     function_check drop_database
439
     drop_database etherpad
442
     drop_database etherpad
441
     remove_onion_service etherpad ${ETHERPAD_ONION_PORT}
444
     remove_onion_service etherpad ${ETHERPAD_ONION_PORT}
442
     remove_app etherpad
445
     remove_app etherpad
443
     remove_completion_param install_etherpad
446
     remove_completion_param install_etherpad
444
-    sed -i '/etherpad/d' $COMPLETION_FILE
447
+    sed -i '/etherpad/d' "$COMPLETION_FILE"
445
     remove_backup_database_local etherpad
448
     remove_backup_database_local etherpad
446
     remove_nodejs etherpad
449
     remove_nodejs etherpad
447
 
450
 
449
     userdel -r etherpad
452
     userdel -r etherpad
450
 
453
 
451
     function_check remove_ddns_domain
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
 function install_etherpad {
458
 function install_etherpad {
456
-    if [ ! $ETHERPAD_DOMAIN_NAME ]; then
459
+    if [ ! "$ETHERPAD_DOMAIN_NAME" ]; then
457
         echo $'No domain name was given for etherpad'
460
         echo $'No domain name was given for etherpad'
458
         exit 7359
461
         exit 7359
459
     fi
462
     fi
460
 
463
 
461
     check_ram_availability 2000
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
     else
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
         fi
471
         fi
469
     fi
472
     fi
470
 
473
 
484
     function_check install_nodejs
487
     function_check install_nodejs
485
     install_nodejs etherpad
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
     fi
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
         if [ -d /repos/etherpad ]; then
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
             git pull
499
             git pull
497
         else
500
         else
498
             function_check git_clone
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
         fi
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
             echo $'Unable to clone etherpad repo'
506
             echo $'Unable to clone etherpad repo'
504
             exit 56382
507
             exit 56382
505
         fi
508
         fi
506
     fi
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
     set_completion_param "etherpad commit" "$ETHERPAD_COMMIT"
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
     function_check etherpad_create_database
518
     function_check etherpad_create_database
516
     etherpad_create_database
519
     etherpad_create_database
517
 
520
 
518
     function_check add_ddns_domain
521
     function_check add_ddns_domain
519
-    add_ddns_domain $ETHERPAD_DOMAIN_NAME
522
+    add_ddns_domain "$ETHERPAD_DOMAIN_NAME"
520
 
523
 
521
     create_etherpad_settings
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
     chmod +x /etc/systemd/system/etherpad.service
545
     chmod +x /etc/systemd/system/etherpad.service
543
 
546
 
544
     etherpad_nginx_site=/etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
547
     etherpad_nginx_site=/etc/nginx/sites-available/$ETHERPAD_DOMAIN_NAME
545
     if [[ $ONION_ONLY == "no" ]]; then
548
     if [[ $ONION_ONLY == "no" ]]; then
546
         function_check nginx_http_redirect
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
         function_check nginx_ssl
557
         function_check nginx_ssl
555
-        nginx_ssl $ETHERPAD_DOMAIN_NAME
558
+        nginx_ssl "$ETHERPAD_DOMAIN_NAME"
556
 
559
 
557
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
580
     else
578
-        echo -n '' > $etherpad_nginx_site
581
+        echo -n '' > "$etherpad_nginx_site"
579
     fi
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check create_site_certificate
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
     fi
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
     fi
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
     fi
617
     fi
615
     usermod -a -G ssl-cert etherpad
618
     usermod -a -G ssl-cert etherpad
616
 
619
 
623
     backup_database_local etherpad
626
     backup_database_local etherpad
624
 
627
 
625
     function_check nginx_ensite
628
     function_check nginx_ensite
626
-    nginx_ensite $ETHERPAD_DOMAIN_NAME
629
+    nginx_ensite "$ETHERPAD_DOMAIN_NAME"
627
 
630
 
628
     ETHERPAD_ONION_HOSTNAME=$(add_onion_service etherpad 80 ${ETHERPAD_ONION_PORT})
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
     function_check add_ddns_domain
635
     function_check add_ddns_domain
633
-    add_ddns_domain $ETHERPAD_DOMAIN_NAME
636
+    add_ddns_domain "$ETHERPAD_DOMAIN_NAME"
634
 
637
 
635
     set_completion_param "etherpad domain" "$ETHERPAD_DOMAIN_NAME"
638
     set_completion_param "etherpad domain" "$ETHERPAD_DOMAIN_NAME"
636
 
639
 

+ 124
- 125
src/freedombone-app-fedwiki 查看文件

127
 }
127
 }
128
 
128
 
129
 function install_interactive_fedwiki {
129
 function install_interactive_fedwiki {
130
-    if [ ! $ONION_ONLY ]; then
130
+    if [ ! "$ONION_ONLY" ]; then
131
         ONION_ONLY='no'
131
         ONION_ONLY='no'
132
     fi
132
     fi
133
 
133
 
148
         echo $'Fedwiki password is too short'
148
         echo $'Fedwiki password is too short'
149
         return
149
         return
150
     fi
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
     sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
152
     sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
153
     sed -i "s|\"secret\":.*|\"secret\": \"${FEDWIKI_PASSWORD}\"|g" ${FEDWIKI_DATA}/status/owner.json
153
     sed -i "s|\"secret\":.*|\"secret\": \"${FEDWIKI_PASSWORD}\"|g" ${FEDWIKI_DATA}/status/owner.json
154
     systemctl daemon-reload
154
     systemctl daemon-reload
177
 
177
 
178
 function backup_local_fedwiki {
178
 function backup_local_fedwiki {
179
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
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
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
181
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
182
     fi
182
     fi
183
 
183
 
184
     systemctl stop fedwiki
184
     systemctl stop fedwiki
185
-    suspend_site ${FEDWIKI_DOMAIN_NAME}
185
+    suspend_site "${FEDWIKI_DOMAIN_NAME}"
186
 
186
 
187
     fedwiki_path=$FEDWIKI_DATA
187
     fedwiki_path=$FEDWIKI_DATA
188
     if [ -d $fedwiki_path ]; then
188
     if [ -d $fedwiki_path ]; then
195
 
195
 
196
 function restore_local_fedwiki {
196
 function restore_local_fedwiki {
197
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
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
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
199
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
200
     fi
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
         systemctl stop fedwiki
203
         systemctl stop fedwiki
204
 
204
 
205
         temp_restore_dir=/root/tempfedwiki
205
         temp_restore_dir=/root/tempfedwiki
215
             rm -rf $temp_restore_dir
215
             rm -rf $temp_restore_dir
216
         fi
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
         sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
220
         sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
221
         write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD"
221
         write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD"
222
         systemctl daemon-reload
222
         systemctl daemon-reload
227
 
227
 
228
 function backup_remote_fedwiki {
228
 function backup_remote_fedwiki {
229
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
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
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
231
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
232
     fi
232
     fi
233
 
233
 
234
     systemctl stop fedwiki
234
     systemctl stop fedwiki
235
-    suspend_site ${FEDWIKI_DOMAIN_NAME}
235
+    suspend_site "${FEDWIKI_DOMAIN_NAME}"
236
 
236
 
237
     temp_backup_dir=$FEDWIKI_DATA
237
     temp_backup_dir=$FEDWIKI_DATA
238
     if [ -d $temp_backup_dir ]; then
238
     if [ -d $temp_backup_dir ]; then
248
 
248
 
249
 function restore_remote_fedwiki {
249
 function restore_remote_fedwiki {
250
     FEDWIKI_DOMAIN_NAME='fedwiki.local'
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
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
252
         FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
253
     fi
253
     fi
254
 
254
 
255
     systemctl stop fedwiki
255
     systemctl stop fedwiki
256
-    suspend_site ${FEDWIKI_DOMAIN_NAME}
256
+    suspend_site "${FEDWIKI_DOMAIN_NAME}"
257
 
257
 
258
     temp_restore_dir=/root/tempfedwiki
258
     temp_restore_dir=/root/tempfedwiki
259
     function_check restore_directory_from_friend
259
     function_check restore_directory_from_friend
268
         rm -rf $temp_restore_dir
268
         rm -rf $temp_restore_dir
269
     fi
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
     sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
273
     sed -i "s|--cookieSecret .*|--cookieSecret '${FEDWIKI_PASSWORD}'|g" /etc/systemd/system/fedwiki.service
274
     write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD"
274
     write_config_param "FEDWIKI_COOKIE" "$FEDWIKI_PASSWORD"
275
     systemctl daemon-reload
275
     systemctl daemon-reload
294
     remove_nodejs fedwiki
294
     remove_nodejs fedwiki
295
 
295
 
296
     read_config_param "FEDWIKI_DOMAIN_NAME"
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
     fi
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
     fi
304
     fi
305
     remove_config_param FEDWIKI_DOMAIN_NAME
305
     remove_config_param FEDWIKI_DOMAIN_NAME
306
     remove_config_param FEDWIKI_CODE
306
     remove_config_param FEDWIKI_CODE
307
     function_check remove_onion_service
307
     function_check remove_onion_service
308
     remove_onion_service fedwiki ${FEDWIKI_ONION_PORT}
308
     remove_onion_service fedwiki ${FEDWIKI_ONION_PORT}
309
     remove_completion_param "install_fedwiki"
309
     remove_completion_param "install_fedwiki"
310
-    sed -i '/fedwiki/d' $COMPLETION_FILE
310
+    sed -i '/fedwiki/d' "$COMPLETION_FILE"
311
 
311
 
312
     groupdel -f fedwiki
312
     groupdel -f fedwiki
313
     userdel -r fedwiki
313
     userdel -r fedwiki
317
     fi
317
     fi
318
 
318
 
319
     function_check remove_ddns_domain
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
 function fedwiki_setup_web {
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
         function_check nginx_ssl
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
     else
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
     function_check create_site_certificate
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
     function_check nginx_ensite
395
     function_check nginx_ensite
396
-    nginx_ensite $FEDWIKI_DOMAIN_NAME
396
+    nginx_ensite "$FEDWIKI_DOMAIN_NAME"
397
 }
397
 }
398
 
398
 
399
 function install_fedwiki {
399
 function install_fedwiki {
400
-    if [[ $VARIANT == "mesh"* ]]; then
400
+    # shellcheck disable=SC2153
401
+    if [[ "$VARIANT" == "mesh"* ]]; then
401
         return
402
         return
402
     fi
403
     fi
403
 
404
 
404
-    if [ ! $ONION_ONLY ]; then
405
+    if [ ! "$ONION_ONLY" ]; then
405
         ONION_ONLY='no'
406
         ONION_ONLY='no'
406
     fi
407
     fi
407
 
408
 
408
-    if [ ! $FEDWIKI_DOMAIN_NAME ]; then
409
+    if [ ! "$FEDWIKI_DOMAIN_NAME" ]; then
409
         echo $'The fedwiki domain name was not specified'
410
         echo $'The fedwiki domain name was not specified'
410
         exit 893635
411
         exit 893635
411
     fi
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
     fi
416
     fi
416
 
417
 
417
     if [ ! -d $FEDWIKI_DATA ]; then
418
     if [ ! -d $FEDWIKI_DATA ]; then
429
 
430
 
430
     apt-get -yq install fonts-font-awesome
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
         echo $'Failed to install fedwiki'
434
         echo $'Failed to install fedwiki'
435
         exit 6293523
435
         exit 6293523
436
     fi
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
         echo $'Failed to install wiki-security-friends'
439
         echo $'Failed to install wiki-security-friends'
441
         exit 783533
440
         exit 783533
442
     fi
441
     fi
457
         FEDWIKI_COOKIE="$(create_password 20)"
456
         FEDWIKI_COOKIE="$(create_password 20)"
458
     fi
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
     if [ ! -d ${FEDWIKI_DATA}/status ]; then
478
     if [ ! -d ${FEDWIKI_DATA}/status ]; then
480
         mkdir -p ${FEDWIKI_DATA}/status
479
         mkdir -p ${FEDWIKI_DATA}/status
481
     fi
480
     fi
482
     fedwiki_auth_file=${FEDWIKI_DATA}/status/owner.json
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
     chown -R fedwiki:fedwiki $FEDWIKI_DATA
489
     chown -R fedwiki:fedwiki $FEDWIKI_DATA
491
 
490
 
492
     fedwiki_setup_web
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
     function_check add_ddns_domain
495
     function_check add_ddns_domain
497
-    add_ddns_domain $FEDWIKI_DOMAIN_NAME
496
+    add_ddns_domain "$FEDWIKI_DOMAIN_NAME"
498
 
497
 
499
     fedwiki_remove_bad_links
498
     fedwiki_remove_bad_links
500
 
499
 

+ 252
- 250
src/freedombone-app-friendica 查看文件

60
 
60
 
61
 function remove_user_friendica {
61
 function remove_user_friendica {
62
     remove_username="$1"
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
 function add_user_friendica {
66
 function add_user_friendica {
71
 
71
 
72
     new_username="$1"
72
     new_username="$1"
73
     new_user_password="$2"
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
     echo '0'
75
     echo '0'
76
 }
76
 }
77
 
77
 
78
 function friendica_renew_cert {
78
 function friendica_renew_cert {
79
     dialog --title $"Renew SSL certificate" \
79
     dialog --title $"Renew SSL certificate" \
80
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
82
     sel=$?
83
     case $sel in
83
     case $sel in
84
         1) return;;
84
         1) return;;
85
         255) return;;
85
         255) return;;
86
     esac
86
     esac
87
     FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain")
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
         dialog --title $"Renew SSL certificate" \
89
         dialog --title $"Renew SSL certificate" \
90
                --msgbox $"Friendica install directory not found" 6 40
90
                --msgbox $"Friendica install directory not found" 6 40
91
         return
91
         return
92
     fi
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
         any_key
94
         any_key
96
     else
95
     else
97
         dialog --title $"Renew SSL certificate" \
96
         dialog --title $"Renew SSL certificate" \
100
 }
99
 }
101
 
100
 
102
 function friendica_channel_directory_server {
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
         dialog --title $"Friendica channel directory server" \
103
         dialog --title $"Friendica channel directory server" \
105
                --msgbox $"Friendica is not installed on this system" 6 40
104
                --msgbox $"Friendica is not installed on this system" 6 40
106
         return
105
         return
107
     fi
106
     fi
108
     FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain")
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
         dialog --title $"Friendica channel directory server" \
109
         dialog --title $"Friendica channel directory server" \
111
                --msgbox $"Friendica install directory not found" 6 40
110
                --msgbox $"Friendica install directory not found" 6 40
112
         return
111
         return
113
     fi
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
     dialog --title $"Friendica channel directory server" \
117
     dialog --title $"Friendica channel directory server" \
120
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
120
     sel=$?
123
     case $sel in
121
     case $sel in
124
         0)
122
         0)
125
-            friendica_domain_server=$(<$data)
123
+            friendica_domain_server=$(<"$data")
126
             if [[ "$friendica_domain_server" != *"."* ]]; then
124
             if [[ "$friendica_domain_server" != *"."* ]]; then
125
+                rm -f "$data"
127
                 return
126
                 return
128
             fi
127
             fi
129
             if [[ "$friendica_domain_server" != "http"* ]]; then
128
             if [[ "$friendica_domain_server" != "http"* ]]; then
130
                 dialog --title $"Friendica channel directory server" \
129
                 dialog --title $"Friendica channel directory server" \
131
                        --msgbox $"Invalid domain - include the https://" 6 40
130
                        --msgbox $"Invalid domain - include the https://" 6 40
131
+                rm -f "$data"
132
                 return
132
                 return
133
             fi
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
             dialog --title $"Friendica channel directory server" \
135
             dialog --title $"Friendica channel directory server" \
136
                    --msgbox $"Domain channel directory server changed to $friendica_domain_server" 6 40
136
                    --msgbox $"Domain channel directory server changed to $friendica_domain_server" 6 40
137
             ;;
137
             ;;
138
     esac
138
     esac
139
+    rm -f "$data"
139
 }
140
 }
140
 
141
 
141
 function friendica_close_registrations {
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
     dialog --title $"Friendica Account Registrations" \
144
     dialog --title $"Friendica Account Registrations" \
144
            --msgbox $"New registrations are now closed" 6 40
145
            --msgbox $"New registrations are now closed" 6 40
145
 }
146
 }
146
 
147
 
147
 function friendica_allow_registrations {
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
     dialog --title $"Friendica Account Registrations" \
150
     dialog --title $"Friendica Account Registrations" \
150
            --msgbox $"New registrations are permitted" 6 40
151
            --msgbox $"New registrations are permitted" 6 40
151
 }
152
 }
153
 function configure_interactive_friendica {
154
 function configure_interactive_friendica {
154
     while true
155
     while true
155
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
158
         dialog --backtitle $"Freedombone Control Panel" \
159
                --title $"Friendica" \
159
                --title $"Friendica" \
160
                --radiolist $"Choose an operation:" 15 70 6 \
160
                --radiolist $"Choose an operation:" 15 70 6 \
162
                2 $"Renew SSL certificate" off \
162
                2 $"Renew SSL certificate" off \
163
                3 $"Close new account registrations" off \
163
                3 $"Close new account registrations" off \
164
                4 $"Allow new account registrations" off \
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
         sel=$?
166
         sel=$?
167
         case $sel in
167
         case $sel in
168
             1) break;;
168
             1) break;;
169
             255) break;;
169
             255) break;;
170
         esac
170
         esac
171
-        case $(cat $data) in
171
+        case $(cat "$data") in
172
             1) friendica_channel_directory_server;;
172
             1) friendica_channel_directory_server;;
173
             2) friendica_renew_cert;;
173
             2) friendica_renew_cert;;
174
             3) friendica_close_registrations;;
174
             3) friendica_close_registrations;;
175
             4) friendica_allow_registrations;;
175
             4) friendica_allow_registrations;;
176
-            5) break;;
176
+            5) rm -f "$data"
177
+               break;;
177
         esac
178
         esac
179
+        rm -f "$data"
178
     done
180
     done
179
 }
181
 }
180
 
182
 
190
 }
192
 }
191
 
193
 
192
 function change_password_friendica {
194
 function change_password_friendica {
193
-    FRIENDICA_USERNAME="$1"
195
+    #FRIENDICA_USERNAME="$1"
194
     FRIENDICA_PASSWORD="$2"
196
     FRIENDICA_PASSWORD="$2"
195
     if [ ${#FRIENDICA_PASSWORD} -lt 8 ]; then
197
     if [ ${#FRIENDICA_PASSWORD} -lt 8 ]; then
196
         echo $'Friendica password is too short'
198
         echo $'Friendica password is too short'
201
 }
203
 }
202
 
204
 
203
 function friendica_create_database {
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
     fi
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
     fi
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
         return
214
         return
213
     fi
215
     fi
214
 
216
 
229
     FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
231
     FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
230
 
232
 
231
     function_check set_repo_commit
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
 function backup_local_friendica {
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
         function_check backup_database_to_usb
241
         function_check backup_database_to_usb
240
         backup_database_to_usb friendica
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
     fi
245
     fi
244
 }
246
 }
245
 
247
 
250
     function_check friendica_create_database
252
     function_check friendica_create_database
251
     friendica_create_database
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
         fi
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
         if [ -d $temp_restore_dir ]; then
262
         if [ -d $temp_restore_dir ]; then
261
             rm -rf $temp_restore_dir
263
             rm -rf $temp_restore_dir
262
         fi
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
         FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
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
         MARIADB_PASSWORD=
269
         MARIADB_PASSWORD=
268
     fi
270
     fi
269
 }
271
 }
270
 
272
 
271
 function backup_remote_friendica {
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
         backup_database_to_friend friendica
277
         backup_database_to_friend friendica
276
         echo "Backing up Friendica installation"
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
         restart_site
280
         restart_site
279
         echo "Backup of Friendica complete"
281
         echo "Backup of Friendica complete"
280
     else
282
     else
289
     function_check friendica_create_database
291
     function_check friendica_create_database
290
     friendica_create_database
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
         fi
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
     fi
301
     fi
300
     if [ -d /root/tempfriendica ]; then
302
     if [ -d /root/tempfriendica ]; then
301
         rm -rf /root/tempfriendica
303
         rm -rf /root/tempfriendica
302
     fi
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
     MARIADB_PASSWORD=
309
     MARIADB_PASSWORD=
308
 }
310
 }
309
 
311
 
311
     if [ ${#FRIENDICA_DOMAIN_NAME} -eq 0 ]; then
313
     if [ ${#FRIENDICA_DOMAIN_NAME} -eq 0 ]; then
312
         return
314
         return
313
     fi
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
     fi
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
     fi
323
     fi
322
     function_check drop_database
324
     function_check drop_database
323
     drop_database friendica
325
     drop_database friendica
324
     function_check remove_onion_service
326
     function_check remove_onion_service
325
     remove_onion_service friendica ${FRIENDICA_ONION_PORT}
327
     remove_onion_service friendica ${FRIENDICA_ONION_PORT}
326
-    sed -i '/friendica/d' $COMPLETION_FILE
328
+    sed -i '/friendica/d' "$COMPLETION_FILE"
327
     sed -i '/poller.php/d' /etc/crontab
329
     sed -i '/poller.php/d' /etc/crontab
328
 
330
 
329
     function_check remove_ddns_domain
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
 function install_friendica {
335
 function install_friendica {
334
-    if [ ! $FRIENDICA_DOMAIN_NAME ]; then
336
+    if [ ! "$FRIENDICA_DOMAIN_NAME" ]; then
335
         return
337
         return
336
     fi
338
     fi
337
 
339
 
338
-    if [[ $ONION_ONLY != "no" ]]; then
340
+    if [[ "$ONION_ONLY" != "no" ]]; then
339
         return
341
         return
340
     fi
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
     function_check install_mariadb
346
     function_check install_mariadb
345
     install_mariadb
347
     install_mariadb
354
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
356
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
355
     apt-get -yq install php-memcached
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
     fi
361
     fi
360
-    if [ ! -d $FRIENDICA_PATH ]; then
361
-        mkdir $FRIENDICA_PATH
362
+    if [ ! -d "$FRIENDICA_PATH" ]; then
363
+        mkdir "$FRIENDICA_PATH"
362
     fi
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
         if [ -d /repos/friendica ]; then
369
         if [ -d /repos/friendica ]; then
368
             mkdir friendica
370
             mkdir friendica
369
             cp -r -p /repos/friendica/. friendica
371
             cp -r -p /repos/friendica/. friendica
370
-            cd friendica
372
+            cd friendica || exit 24682462
371
             git pull
373
             git pull
372
         else
374
         else
373
             function_check git_clone
375
             function_check git_clone
374
-            git_clone $FRIENDICA_REPO friendica
376
+            git_clone "$FRIENDICA_REPO" friendica
375
         fi
377
         fi
376
 
378
 
377
         git checkout $FRIENDICA_COMMIT -b $FRIENDICA_COMMIT
379
         git checkout $FRIENDICA_COMMIT -b $FRIENDICA_COMMIT
378
         set_completion_param "friendica commit" "$FRIENDICA_COMMIT"
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
         set_completion_param "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT"
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
     fi
391
     fi
390
 
392
 
391
     FRIENDICA_ONION_HOSTNAME=
393
     FRIENDICA_ONION_HOSTNAME=
400
     fi
402
     fi
401
 
403
 
402
     function_check add_ddns_domain
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
         function_check nginx_http_redirect
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
         function_check nginx_ssl
419
         function_check nginx_ssl
418
-        nginx_ssl $FRIENDICA_DOMAIN_NAME
420
+        nginx_ssl "$FRIENDICA_DOMAIN_NAME"
419
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
         function_check nginx_limits
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
     else
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
     fi
547
     fi
546
 
548
 
547
     function_check configure_php
549
     function_check configure_php
548
     configure_php
550
     configure_php
549
 
551
 
550
     function_check create_site_certificate
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
     fi
557
     fi
556
     if [ ! -d "$FRIENDICA_PATH/store" ]; then
558
     if [ ! -d "$FRIENDICA_PATH/store" ]; then
557
         mkdir "$FRIENDICA_PATH/store"
559
         mkdir "$FRIENDICA_PATH/store"
563
         mkdir "$FRIENDICA_PATH/store/[data]/smarty3"
565
         mkdir "$FRIENDICA_PATH/store/[data]/smarty3"
564
         chmod 1777 "$FRIENDICA_PATH/store/[data]/smarty3"
566
         chmod 1777 "$FRIENDICA_PATH/store/[data]/smarty3"
565
     fi
567
     fi
566
-    chmod 1777 $FRIENDICA_PATH/view/tpl
568
+    chmod 1777 "$FRIENDICA_PATH/view/tpl"
567
     chown -R www-data:www-data "$FRIENDICA_PATH/store"
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
     # Ensure that the database gets backed up locally, if remote
572
     # Ensure that the database gets backed up locally, if remote
571
     # backups are not being used
573
     # backups are not being used
575
     function_check backup_database_local
577
     function_check backup_database_local
576
     backup_database_local friendica
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
     function_check nginx_ensite
582
     function_check nginx_ensite
581
-    nginx_ensite $FRIENDICA_DOMAIN_NAME
583
+    nginx_ensite "$FRIENDICA_DOMAIN_NAME"
582
 
584
 
583
     # initialize the database
585
     # initialize the database
584
-    if [ ! -f $FRIENDICA_PATH/database.sql ]; then
586
+    if [ ! -f "$FRIENDICA_PATH/database.sql" ]; then
585
         echo $'No database schema found for friendica'
587
         echo $'No database schema found for friendica'
586
         exit 252782
588
         exit 252782
587
     fi
589
     fi
588
     function_check initialise_database
590
     function_check initialise_database
589
-    initialise_database friendica $FRIENDICA_PATH/database.sql
591
+    initialise_database friendica "$FRIENDICA_PATH/database.sql"
590
 
592
 
591
     # create the config file
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
     if [[ $ONION_ONLY == 'no' ]]; then
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
     else
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
     systemctl restart mariadb
623
     systemctl restart mariadb
622
     systemctl restart php7.0-fpm
624
     systemctl restart php7.0-fpm
623
     systemctl restart nginx
625
     systemctl restart nginx
624
     systemctl restart cron
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
     set_completion_param "friendica domain" "${FRIENDICA_DOMAIN_NAME}"
630
     set_completion_param "friendica domain" "${FRIENDICA_DOMAIN_NAME}"
629
     APP_INSTALLED=1
631
     APP_INSTALLED=1

+ 195
- 195
src/freedombone-app-ghost 查看文件

48
 
48
 
49
 function ghost_bust {
49
 function ghost_bust {
50
     # kill the started ghost process
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
 function logging_on_ghost {
61
 function logging_on_ghost {
77
     sed -i "s|http://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
77
     sed -i "s|http://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
78
     sed -i "s|https://code.jquery.com/jquery.js|$curr_domain/jquery-${jquery_version}.js|g" current/node_modules/jsdom/README.md
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
 function ghost_rss_button {
85
 function ghost_rss_button {
98
     ghost_rss_button
98
     ghost_rss_button
99
 
99
 
100
     # remove google font links
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
     # copy jquery locally
104
     # copy jquery locally
105
     previous_jquery_version='1.12.0'
105
     previous_jquery_version='1.12.0'
106
     jquery_version='1.12.4'
106
     jquery_version='1.12.4'
107
     if [ ! -f /var/www/$GHOST_DOMAIN_NAME/htdocs/jquery-${jquery_version}.js ]; then
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
         wget https://code.jquery.com/jquery-${jquery_version}.js
109
         wget https://code.jquery.com/jquery-${jquery_version}.js
110
         jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
110
         jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
111
         if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
111
         if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
119
 }
119
 }
120
 
120
 
121
 function ghost_replace_proprietary_services {
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
 function ghost_replace_services {
145
 function ghost_replace_services {
163
 }
163
 }
164
 
164
 
165
 function install_interactive_ghost {
165
 function install_interactive_ghost {
166
-    if [ ! $ONION_ONLY ]; then
166
+    if [ ! "$ONION_ONLY" ]; then
167
         ONION_ONLY='no'
167
         ONION_ONLY='no'
168
     fi
168
     fi
169
 
169
 
178
 }
178
 }
179
 
179
 
180
 function change_password_ghost {
180
 function change_password_ghost {
181
-    GHOST_USERNAME="$1"
181
+    #GHOST_USERNAME="$1"
182
     GHOST_PASSWORD="$2"
182
     GHOST_PASSWORD="$2"
183
     if [ ${#GHOST_PASSWORD} -lt 8 ]; then
183
     if [ ${#GHOST_PASSWORD} -lt 8 ]; then
184
         echo $'Ghost password is too short'
184
         echo $'Ghost password is too short'
185
         return
185
         return
186
     fi
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
 function reconfigure_ghost {
190
 function reconfigure_ghost {
206
     systemctl stop ghost
206
     systemctl stop ghost
207
     ghost_bust
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
     npm i -g ghost-cli
211
     npm i -g ghost-cli
212
     /usr/local/bin/ghost update &
212
     /usr/local/bin/ghost update &
220
     chown -R root:root /usr/local/lib
220
     chown -R root:root /usr/local/lib
221
     chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
221
     chown -R ghost: /var/www/${GHOST_DOMAIN_NAME}/htdocs
222
     systemctl restart ghost
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
 function backup_local_ghost {
226
 function backup_local_ghost {
227
     GHOST_DOMAIN_NAME='ghost.local'
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
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
229
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
230
     fi
230
     fi
231
 
231
 
232
-    suspend_site ${GHOST_DOMAIN_NAME}
232
+    suspend_site "${GHOST_DOMAIN_NAME}"
233
     systemctl stop ghost
233
     systemctl stop ghost
234
 
234
 
235
     ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
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
     fi
238
     fi
239
 
239
 
240
     ghost_path=/var/www/${GHOST_DOMAIN_NAME}/htdocs/current/content
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
     fi
243
     fi
244
 
244
 
245
     systemctl start ghost
245
     systemctl start ghost
248
 
248
 
249
 function restore_local_ghost {
249
 function restore_local_ghost {
250
     GHOST_DOMAIN_NAME='ghost.local'
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
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
252
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
253
     fi
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
         systemctl stop ghost
256
         systemctl stop ghost
257
 
257
 
258
         temp_restore_dir=/root/tempghostcontent
258
         temp_restore_dir=/root/tempghostcontent
259
         function_check restore_directory_from_usb
259
         function_check restore_directory_from_usb
260
         restore_directory_from_usb $temp_restore_dir ghostcontent
260
         restore_directory_from_usb $temp_restore_dir ghostcontent
261
         if [ -d $temp_restore_dir ]; then
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
             else
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
                 fi
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
             fi
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
             rm -rf $temp_restore_dir
271
             rm -rf $temp_restore_dir
272
         fi
272
         fi
273
 
273
 
275
         function_check restore_directory_from_usb
275
         function_check restore_directory_from_usb
276
         restore_directory_from_usb $temp_restore_dir ghostcurrent
276
         restore_directory_from_usb $temp_restore_dir ghostcurrent
277
         if [ -d $temp_restore_dir ]; then
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
             else
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
                 fi
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
             fi
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
             rm -rf $temp_restore_dir
287
             rm -rf $temp_restore_dir
288
         fi
288
         fi
289
 
289
 
294
 
294
 
295
 function backup_remote_ghost {
295
 function backup_remote_ghost {
296
     GHOST_DOMAIN_NAME='ghost.local'
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
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
298
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
299
     fi
299
     fi
300
 
300
 
301
-    suspend_site ${GHOST_DOMAIN_NAME}
301
+    suspend_site "${GHOST_DOMAIN_NAME}"
302
 
302
 
303
     temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/content
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
     else
306
     else
307
         restart_site
307
         restart_site
308
         echo $"Ghost domain specified but not found in /var/www/${GHOST_DOMAIN_NAME}"
308
         echo $"Ghost domain specified but not found in /var/www/${GHOST_DOMAIN_NAME}"
310
     fi
310
     fi
311
 
311
 
312
     temp_backup_dir=/var/www/${GHOST_DOMAIN_NAME}/htdocs/current/content
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
     else
315
     else
316
         restart_site
316
         restart_site
317
         echo $"Ghost domain specified but not found in $temp_backup_dir"
317
         echo $"Ghost domain specified but not found in $temp_backup_dir"
323
 
323
 
324
 function restore_remote_ghost {
324
 function restore_remote_ghost {
325
     GHOST_DOMAIN_NAME='ghost.local'
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
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
327
         GHOST_DOMAIN_NAME=$(get_completion_param "ghost domain")
328
     fi
328
     fi
329
-    suspend_site ${GHOST_DOMAIN_NAME}
329
+    suspend_site "${GHOST_DOMAIN_NAME}"
330
 
330
 
331
     systemctl stop ghost
331
     systemctl stop ghost
332
 
332
 
334
     function_check restore_directory_from_friend
334
     function_check restore_directory_from_friend
335
     restore_directory_from_friend $temp_restore_dir ghostcontent
335
     restore_directory_from_friend $temp_restore_dir ghostcontent
336
     if [ -d $temp_restore_dir ]; then
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
         else
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
             fi
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
         fi
344
         fi
345
-        chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs
345
+        chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
346
         rm -rf $temp_restore_dir
346
         rm -rf $temp_restore_dir
347
     fi
347
     fi
348
 
348
 
350
     function_check restore_directory_from_friend
350
     function_check restore_directory_from_friend
351
     restore_directory_from_friend $temp_restore_dir ghostcurrent
351
     restore_directory_from_friend $temp_restore_dir ghostcurrent
352
     if [ -d $temp_restore_dir ]; then
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
         else
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
             fi
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
         fi
360
         fi
361
-        chown -R ghost: /var/www/$GHOST_DOMAIN_NAME/htdocs
361
+        chown -R ghost: "/var/www/$GHOST_DOMAIN_NAME/htdocs"
362
         rm -rf $temp_restore_dir
362
         rm -rf $temp_restore_dir
363
     fi
363
     fi
364
 
364
 
382
     remove_nodejs ghost
382
     remove_nodejs ghost
383
 
383
 
384
     read_config_param "GHOST_DOMAIN_NAME"
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
     fi
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
     fi
392
     fi
393
     remove_config_param GHOST_DOMAIN_NAME
393
     remove_config_param GHOST_DOMAIN_NAME
394
     remove_config_param GHOST_CODE
394
     remove_config_param GHOST_CODE
395
     function_check remove_onion_service
395
     function_check remove_onion_service
396
     remove_onion_service ghost ${GHOST_ONION_PORT}
396
     remove_onion_service ghost ${GHOST_ONION_PORT}
397
     remove_completion_param "install_ghost"
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
     groupdel -f ghost
401
     groupdel -f ghost
402
     userdel -r ghost
402
     userdel -r ghost
403
 
403
 
404
     function_check remove_ddns_domain
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
 function install_ghost {
408
 function install_ghost {
412
         ONION_ONLY='no'
412
         ONION_ONLY='no'
413
     fi
413
     fi
414
 
414
 
415
-    if [ ! $GHOST_DOMAIN_NAME ]; then
415
+    if [ ! "$GHOST_DOMAIN_NAME" ]; then
416
         echo $'The ghost domain name was not specified'
416
         echo $'The ghost domain name was not specified'
417
         exit 5062
417
         exit 5062
418
     fi
418
     fi
420
     # for the avatar changing command
420
     # for the avatar changing command
421
     apt-get -yq install unzip wget
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
     fi
425
     fi
426
-    cd /var/www/$GHOST_DOMAIN_NAME/htdocs
426
+    cd "/var/www/$GHOST_DOMAIN_NAME/htdocs" || exit 26422842
427
 
427
 
428
     function_check install_nodejs
428
     function_check install_nodejs
429
     install_nodejs ghost
429
     install_nodejs ghost
440
     npm install -g yarn
440
     npm install -g yarn
441
     yarn install --no-emoji --no-progress
441
     yarn install --no-emoji --no-progress
442
     yarn cache clean
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
     printf 'y' | ghost install ${GHOST_VERSION} --user ghost --db=sqlite3 --port ${GHOST_PORT} --verbose
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
         echo $'versions directory was not found'
448
         echo $'versions directory was not found'
449
         exit 782523462
449
         exit 782523462
450
     fi
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
         echo $'content directory was not found'
452
         echo $'content directory was not found'
453
         exit 68352682
453
         exit 68352682
454
     fi
454
     fi
455
 
455
 
456
     npm install -g knex-migrator
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
         echo $'MigratorConfig.js was not found'
458
         echo $'MigratorConfig.js was not found'
459
         exit 62783538
459
         exit 62783538
460
     fi
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
     knex-migrator init
464
     knex-migrator init
465
 
465
 
466
     ghost_bust
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
     if [[ "$ONION_ONLY" == 'no' ]]; then
469
     if [[ "$ONION_ONLY" == 'no' ]]; then
470
         # NOTE: url must be http, not https
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
     else
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
     ghost_remove_offsite_links
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
     systemctl enable ghost
504
     systemctl enable ghost
505
     systemctl daemon-reload
505
     systemctl daemon-reload
507
 
507
 
508
     if [[ ${ONION_ONLY} == "no" ]]; then
508
     if [[ ${ONION_ONLY} == "no" ]]; then
509
         function_check nginx_http_redirect
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
         function_check nginx_ssl
519
         function_check nginx_ssl
520
-        nginx_ssl ${GHOST_DOMAIN_NAME}
520
+        nginx_ssl "${GHOST_DOMAIN_NAME}"
521
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check create_site_certificate
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
     ghost_replace_services
578
     ghost_replace_services
579
 
579
 
580
     function_check nginx_ensite
580
     function_check nginx_ensite
581
-    nginx_ensite $GHOST_DOMAIN_NAME
581
+    nginx_ensite "$GHOST_DOMAIN_NAME"
582
 
582
 
583
     systemctl restart nginx
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
     function_check add_ddns_domain
587
     function_check add_ddns_domain
588
-    add_ddns_domain $GHOST_DOMAIN_NAME
588
+    add_ddns_domain "$GHOST_DOMAIN_NAME"
589
 
589
 
590
     chown root:root /usr/local/bin/ghost
590
     chown root:root /usr/local/bin/ghost
591
     chown -R root:root /usr/local/lib
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
     set_completion_param "ghost domain" "$GHOST_DOMAIN_NAME"
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
     else
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
     fi
598
     fi
599
 
599
 
600
     APP_INSTALLED=1
600
     APP_INSTALLED=1

+ 286
- 280
src/freedombone-app-gnusocial
文件差异内容过多而无法显示
查看文件


+ 222
- 215
src/freedombone-app-gogs 查看文件

127
 }
127
 }
128
 
128
 
129
 function gogs_create_database {
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
     else
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
         fi
135
         fi
136
     fi
136
     fi
137
-    if [ ! $GIT_ADMIN_PASSWORD ]; then
137
+    if [ ! "$GIT_ADMIN_PASSWORD" ]; then
138
         return
138
         return
139
     fi
139
     fi
140
 
140
 
147
 }
147
 }
148
 
148
 
149
 function upgrade_gogs {
149
 function upgrade_gogs {
150
-    if ! grep -q 'gogs version:' $COMPLETION_FILE; then
150
+    if ! grep -q 'gogs version:' "$COMPLETION_FILE"; then
151
         return
151
         return
152
     fi
152
     fi
153
 
153
 
160
 
160
 
161
     GOGS_CONFIG_PATH=/home/${GOGS_USERNAME}/custom/conf
161
     GOGS_CONFIG_PATH=/home/${GOGS_USERNAME}/custom/conf
162
     GOGS_CONFIG_FILE=$GOGS_CONFIG_PATH/app.ini
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
     fi
167
     fi
168
     if [ -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
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
     fi
170
     fi
171
 
171
 
172
     gogs_parameters
172
     gogs_parameters
173
     echo "gogs binary upgrade: ${GOGS_BIN}"
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
     fi
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
     fi
181
     fi
182
     GOGS_FILE=linux_${CURR_ARCH}.tar.gz
182
     GOGS_FILE=linux_${CURR_ARCH}.tar.gz
183
     if [ ! -f ${GOGS_FILE} ]; then
183
     if [ ! -f ${GOGS_FILE} ]; then
196
             unzip -o ${GOGS_FILE}
196
             unzip -o ${GOGS_FILE}
197
         fi
197
         fi
198
     else
198
     else
199
-        tar -xzf ${INSTALL_DIR}/${GOGS_FILE}
199
+        tar -xzf "${INSTALL_DIR}/${GOGS_FILE}"
200
     fi
200
     fi
201
-    if [ ! -d ${INSTALL_DIR}/gogs ]; then
201
+    if [ ! -d "${INSTALL_DIR}/gogs" ]; then
202
         exit 37823
202
         exit 37823
203
     fi
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
     if [ -f ${GOGS_FILE} ]; then
206
     if [ -f ${GOGS_FILE} ]; then
207
         rm ${GOGS_FILE}
207
         rm ${GOGS_FILE}
208
     fi
208
     fi
211
         mkdir -p ${GOGS_CONFIG_PATH}
211
         mkdir -p ${GOGS_CONFIG_PATH}
212
     fi
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
     if [ ! -f $GOGS_CONFIG_FILE ]; then
215
     if [ ! -f $GOGS_CONFIG_FILE ]; then
216
         echo $'Gogs ini file not upgraded'
216
         echo $'Gogs ini file not upgraded'
217
         exit 873535
217
         exit 873535
218
     fi
218
     fi
219
-    rm $INSTALL_DIR/gogs_config.ini
219
+    rm "$INSTALL_DIR/gogs_config.ini"
220
     if [ -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
220
     if [ -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
221
         rm -rf /home/${GOGS_USERNAME}/gogs-repositories
221
         rm -rf /home/${GOGS_USERNAME}/gogs-repositories
222
     fi
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
     fi
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
     systemctl restart mariadb
229
     systemctl restart mariadb
230
     systemctl restart gogs
230
     systemctl restart gogs
231
 }
231
 }
232
 
232
 
233
 function backup_local_gogs {
233
 function backup_local_gogs {
234
-    if ! grep -q "gogs domain" ${COMPLETION_FILE}; then
234
+    if ! grep -q "gogs domain" "${COMPLETION_FILE}"; then
235
         return
235
         return
236
     fi
236
     fi
237
 
237
 
238
-    if [ ! -d /home/${GOGS_USERNAME}/gogs-repositories ]; then
238
+    if [ ! -d "/home/${GOGS_USERNAME}/gogs-repositories" ]; then
239
         return
239
         return
240
     fi
240
     fi
241
 
241
 
245
     backup_database_to_usb gogs
245
     backup_database_to_usb gogs
246
 
246
 
247
     function_check backup_directory_to_usb
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
     echo $"Gogs backup complete"
252
     echo $"Gogs backup complete"
253
 }
253
 }
254
 
254
 
255
 function restore_local_gogs {
255
 function restore_local_gogs {
256
-    if ! grep -q "gogs domain" ${COMPLETION_FILE}; then
256
+    if ! grep -q "gogs domain" "${COMPLETION_FILE}"; then
257
         return
257
         return
258
     fi
258
     fi
259
 
259
 
261
         function_check gogs_create_database
261
         function_check gogs_create_database
262
         gogs_create_database
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
         function_check restore_database
267
         function_check restore_database
268
-        restore_database gogs ${GIT_DOMAIN_NAME}
268
+        restore_database gogs "${GIT_DOMAIN_NAME}"
269
         temp_restore_dir=/root/tempgogs
269
         temp_restore_dir=/root/tempgogs
270
-        if [ -d ${USB_MOUNT}/backup/gogs ]; then
270
+        if [ -d "${USB_MOUNT}/backup/gogs" ]; then
271
             echo $"Restoring Gogs settings"
271
             echo $"Restoring Gogs settings"
272
             if [ ! -d $GOGS_CONFIG_PATH ]; then
272
             if [ ! -d $GOGS_CONFIG_PATH ]; then
273
                 mkdir -p $GOGS_CONFIG_PATH
273
                 mkdir -p $GOGS_CONFIG_PATH
274
             fi
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
             else
277
             else
278
-                cp -r /root/tempgogs/* /home/${GOGS_USERNAME}/custom/
278
+                cp -r "/root/tempgogs/*" "/home/${GOGS_USERNAME}/custom/"
279
             fi
279
             fi
280
+            # shellcheck disable=SC2181
280
             if [ ! "$?" = "0" ]; then
281
             if [ ! "$?" = "0" ]; then
281
                 function_check set_user_permissions
282
                 function_check set_user_permissions
282
                 set_user_permissions
283
                 set_user_permissions
286
             fi
287
             fi
287
             echo $"Restoring Gogs repos"
288
             echo $"Restoring Gogs repos"
288
             function_check restore_directory_from_usb
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
             fi
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
             else
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
             fi
298
             fi
299
+            # shellcheck disable=SC2181
298
             if [ ! "$?" = "0" ]; then
300
             if [ ! "$?" = "0" ]; then
299
                 function_check set_user_permissions
301
                 function_check set_user_permissions
300
                 set_user_permissions
302
                 set_user_permissions
313
             else
315
             else
314
                 cp -r ${temp_restore_dir}/* /home/${GOGS_USERNAME}/.ssh/
316
                 cp -r ${temp_restore_dir}/* /home/${GOGS_USERNAME}/.ssh/
315
             fi
317
             fi
318
+            # shellcheck disable=SC2181
316
             if [ ! "$?" = "0" ]; then
319
             if [ ! "$?" = "0" ]; then
317
                 function_check set_user_permissions
320
                 function_check set_user_permissions
318
                 set_user_permissions
321
                 set_user_permissions
326
             chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
329
             chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
327
         fi
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
         sed -i "s|PASSWD =.*|PASSWD = $MARIADB_PASSWORD|g" ${GOGS_CONFIG_FILE}
333
         sed -i "s|PASSWD =.*|PASSWD = $MARIADB_PASSWORD|g" ${GOGS_CONFIG_FILE}
331
         MARIADB_PASSWORD=
334
         MARIADB_PASSWORD=
332
         systemctl restart gogs
335
         systemctl restart gogs
363
 }
366
 }
364
 
367
 
365
 function restore_remote_gogs {
368
 function restore_remote_gogs {
366
-    if grep -q "gogs domain" $COMPLETION_FILE; then
369
+    if grep -q "gogs domain" "$COMPLETION_FILE"; then
367
         GIT_DOMAIN_NAME=$(get_completion_param "gogs domain")
370
         GIT_DOMAIN_NAME=$(get_completion_param "gogs domain")
368
 
371
 
369
         function_check gogs_create_database
372
         function_check gogs_create_database
373
         GOGS_CONFIG_FILE=${GOGS_CONFIG_PATH}/app.ini
376
         GOGS_CONFIG_FILE=${GOGS_CONFIG_PATH}/app.ini
374
 
377
 
375
         function_check restore_database_from_friend
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
             if [ ! -d $GOGS_CONFIG_PATH ]; then
381
             if [ ! -d $GOGS_CONFIG_PATH ]; then
379
                 mkdir -p $GOGS_CONFIG_PATH
382
                 mkdir -p $GOGS_CONFIG_PATH
380
             fi
383
             fi
383
             else
386
             else
384
                 cp -r /root/tempgogs/* /home/${GOGS_USERNAME}/custom/
387
                 cp -r /root/tempgogs/* /home/${GOGS_USERNAME}/custom/
385
             fi
388
             fi
389
+            # shellcheck disable=SC2181
386
             if [ ! "$?" = "0" ]; then
390
             if [ ! "$?" = "0" ]; then
387
                 exit 58852
391
                 exit 58852
388
             fi
392
             fi
396
             else
400
             else
397
                 cp -r /root/tempgogsrepos/* /home/${GOGS_USERNAME}/gogs-repositories/
401
                 cp -r /root/tempgogsrepos/* /home/${GOGS_USERNAME}/gogs-repositories/
398
             fi
402
             fi
403
+            # shellcheck disable=SC2181
399
             if [ ! "$?" = "0" ]; then
404
             if [ ! "$?" = "0" ]; then
400
                 exit 7649
405
                 exit 7649
401
             fi
406
             fi
409
             else
414
             else
410
                 cp -r /root/tempgogsssh/* /home/${GOGS_USERNAME}/.ssh/
415
                 cp -r /root/tempgogsssh/* /home/${GOGS_USERNAME}/.ssh/
411
             fi
416
             fi
417
+            # shellcheck disable=SC2181
412
             if [ ! "$?" = "0" ]; then
418
             if [ ! "$?" = "0" ]; then
413
                 exit 74239
419
                 exit 74239
414
             fi
420
             fi
419
             echo $"Restore of Gogs complete"
425
             echo $"Restore of Gogs complete"
420
         fi
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
         sed -i "s|PASSWD =.*|PASSWD = $MARIADB_PASSWORD|g" ${GOGS_CONFIG_FILE}
429
         sed -i "s|PASSWD =.*|PASSWD = $MARIADB_PASSWORD|g" ${GOGS_CONFIG_FILE}
424
         MARIADB_PASSWORD=
430
         MARIADB_PASSWORD=
425
         systemctl restart gogs
431
         systemctl restart gogs
433
     systemctl stop gogs
439
     systemctl stop gogs
434
     systemctl disable gogs
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
     fi
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
     fi
449
     fi
444
     function_check drop_database
450
     function_check drop_database
445
     drop_database gogs
451
     drop_database gogs
446
     rm /etc/systemd/system/gogs.service
452
     rm /etc/systemd/system/gogs.service
447
     systemctl daemon-reload
453
     systemctl daemon-reload
448
-    rm -rf /home/${GOGS_USERNAME}/*
454
+    rm -rf "/home/${GOGS_USERNAME:?}/"*
449
     remove_onion_service gogs ${GIT_ONION_PORT} 9418
455
     remove_onion_service gogs ${GIT_ONION_PORT} 9418
450
     remove_completion_param "install_gogs"
456
     remove_completion_param "install_gogs"
451
-    sed -i '/gogs /d' $COMPLETION_FILE
457
+    sed -i '/gogs /d' "$COMPLETION_FILE"
452
     remove_backup_database_local gogs
458
     remove_backup_database_local gogs
453
 
459
 
454
     groupdel -f gogs
460
     groupdel -f gogs
455
     userdel -r gogs
461
     userdel -r gogs
456
 
462
 
457
     function_check remove_ddns_domain
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
 function install_gogs {
467
 function install_gogs {
462
-    if [ ! $GIT_DOMAIN_NAME ]; then
468
+    if [ ! "$GIT_DOMAIN_NAME" ]; then
463
         return
469
         return
464
     fi
470
     fi
465
 
471
 
474
 
480
 
475
     gogs_parameters
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
     fi
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
     fi
489
     fi
484
-    GOGS_FILE=linux_${CURR_ARCH}.tar.gz
490
+    GOGS_FILE="linux_${CURR_ARCH}.tar.gz"
485
     if [ ! -f ${GOGS_FILE} ]; then
491
     if [ ! -f ${GOGS_FILE} ]; then
486
         wget ${GOGS_BIN}
492
         wget ${GOGS_BIN}
487
     fi
493
     fi
496
             unzip -o ${GOGS_FILE}
502
             unzip -o ${GOGS_FILE}
497
         fi
503
         fi
498
     else
504
     else
499
-        tar -xzf ${INSTALL_DIR}/${GOGS_FILE}
505
+        tar -xzf "${INSTALL_DIR}/${GOGS_FILE}"
500
     fi
506
     fi
501
-    if [ ! -d ${INSTALL_DIR}/gogs ]; then
507
+    if [ ! -d "${INSTALL_DIR}/gogs" ]; then
502
         exit 37823
508
         exit 37823
503
     fi
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
     if [ -f ${GOGS_FILE} ]; then
512
     if [ -f ${GOGS_FILE} ]; then
507
         rm ${GOGS_FILE}
513
         rm ${GOGS_FILE}
508
     fi
514
     fi
512
         exit 345562
518
         exit 345562
513
     fi
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
     chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
525
     chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
519
 
526
 
520
     function_check install_mariadb
527
     function_check install_mariadb
536
 
543
 
537
     chown -R ${GOGS_USERNAME}:${GOGS_USERNAME} /home/${GOGS_USERNAME}
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
     systemctl enable gogs
567
     systemctl enable gogs
561
     systemctl daemon-reload
568
     systemctl daemon-reload
562
     systemctl start gogs
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
     fi
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
     fi
576
     fi
570
 
577
 
571
-    if [[ ${ONION_ONLY} == "no" ]]; then
578
+    if [[ "${ONION_ONLY}" == "no" ]]; then
572
         function_check nginx_http_redirect
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
         function_check nginx_ssl
589
         function_check nginx_ssl
583
-        nginx_ssl ${GIT_DOMAIN_NAME}
590
+        nginx_ssl "${GIT_DOMAIN_NAME}"
584
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check configure_php
645
     function_check configure_php
639
     configure_php
646
     configure_php
640
 
647
 
641
     function_check create_site_certificate
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
     if [ ! -d /var/lib/tor ]; then
653
     if [ ! -d /var/lib/tor ]; then
647
         echo $'No Tor installation found. Gogs onion site cannot be configured.'
654
         echo $'No Tor installation found. Gogs onion site cannot be configured.'
648
         exit 877367
655
         exit 877367
649
     fi
656
     fi
650
     if ! grep -q "hidden_service_gogs" /etc/tor/torrc; then
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
         echo $'Added onion site for Gogs'
662
         echo $'Added onion site for Gogs'
656
     fi
663
     fi
657
 
664
 
670
     set_completion_param "gogs onion domain" "$GIT_ONION_HOSTNAME"
677
     set_completion_param "gogs onion domain" "$GIT_ONION_HOSTNAME"
671
 
678
 
672
     function_check add_ddns_domain
679
     function_check add_ddns_domain
673
-    add_ddns_domain ${GIT_DOMAIN_NAME}
680
+    add_ddns_domain "${GIT_DOMAIN_NAME}"
674
 
681
 
675
     # obtain the secret key
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
     # create the configuration
686
     # create the configuration
680
-    GOGS_CONFIG_PATH=/home/${GOGS_USERNAME}/custom/conf
687
+    GOGS_CONFIG_PATH="/home/${GOGS_USERNAME}/custom/conf"
681
     if [ ! -d ${GOGS_CONFIG_PATH} ]; then
688
     if [ ! -d ${GOGS_CONFIG_PATH} ]; then
682
         mkdir -p ${GOGS_CONFIG_PATH}
689
         mkdir -p ${GOGS_CONFIG_PATH}
683
     fi
690
     fi
684
     GOGS_CONFIG_FILE=${GOGS_CONFIG_PATH}/app.ini
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
     if [[ ${ONION_ONLY} == 'no' ]]; then
708
     if [[ ${ONION_ONLY} == 'no' ]]; then
702
         echo "DOMAIN = ${GIT_DOMAIN_NAME}" >> ${GOGS_CONFIG_FILE}
709
         echo "DOMAIN = ${GIT_DOMAIN_NAME}" >> ${GOGS_CONFIG_FILE}
703
         echo "ROOT_URL = https://$GIT_DOMAIN_NAME/" >> ${GOGS_CONFIG_FILE}
710
         echo "ROOT_URL = https://$GIT_DOMAIN_NAME/" >> ${GOGS_CONFIG_FILE}
705
         echo "DOMAIN = ${GIT_ONION_HOSTNAME}" >> ${GOGS_CONFIG_FILE}
712
         echo "DOMAIN = ${GIT_ONION_HOSTNAME}" >> ${GOGS_CONFIG_FILE}
706
         echo "ROOT_URL = http://$GIT_DOMAIN_NAME/" >> ${GOGS_CONFIG_FILE}
713
         echo "ROOT_URL = http://$GIT_DOMAIN_NAME/" >> ${GOGS_CONFIG_FILE}
707
     fi
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
     chmod 750 ${GOGS_CONFIG_FILE}
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
     systemctl restart gogs
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
     else
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
     fi
752
     fi
746
 
753
 
747
     function_check configure_firewall_for_git
754
     function_check configure_firewall_for_git
748
     configure_firewall_for_git
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
     else
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
     fi
760
     fi
754
     APP_INSTALLED=1
761
     APP_INSTALLED=1
755
 }
762
 }

+ 276
- 269
src/freedombone-app-htmly 查看文件

69
     fi
69
     fi
70
 
70
 
71
     # download the image
71
     # download the image
72
-    cd $BASE_DIR/customimages
72
+    cd "$BASE_DIR/customimages" || exit 2468246
73
     # convert to png
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
         mv avatar avatar.gif
76
         mv avatar avatar.gif
77
         mogrify -format png avatar.gif
77
         mogrify -format png avatar.gif
78
     fi
78
     fi
79
-    if [[ $AVATAR == *".jpg" ]]; then
79
+    if [[ "$AVATAR" == *".jpg" ]]; then
80
         mv avatar avatar.jpg
80
         mv avatar avatar.jpg
81
         mogrify -format png avatar.jpg
81
         mogrify -format png avatar.jpg
82
     fi
82
     fi
83
-    if [[ $AVATAR == *".jpeg" ]]; then
83
+    if [[ "$AVATAR" == *".jpeg" ]]; then
84
         mv avatar avatar.jpeg
84
         mv avatar avatar.jpeg
85
         mogrify -format png avatar.jpeg
85
         mogrify -format png avatar.jpeg
86
     fi
86
     fi
101
 function remove_user_htmly {
101
 function remove_user_htmly {
102
     remove_username="$1"
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
     fi
108
     fi
109
 }
109
 }
110
 
110
 
117
     new_username="$1"
117
     new_username="$1"
118
     new_user_password="$2"
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
     if [ ! -d /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users ]; then
122
     if [ ! -d /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users ]; then
123
         echo '2'
123
         echo '2'
124
         return
124
         return
125
     fi
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
     if [ ${#NEW_USER_PASSWORD_HASH} -lt 8 ]; then
127
     if [ ${#NEW_USER_PASSWORD_HASH} -lt 8 ]; then
128
         echo '3'
128
         echo '3'
129
         return
129
         return
130
     fi
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
     echo '0'
136
     echo '0'
137
 }
137
 }
138
 
138
 
139
 function configure_interactive_htmly {
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
     dialog --title $"Change htmly avatar" \
141
     dialog --title $"Change htmly avatar" \
143
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
144
     sel=$?
146
     case $sel in
145
     case $sel in
147
         0)
146
         0)
148
-            IMAGE_URL=$(<$data)
147
+            IMAGE_URL=$(<"$data")
149
             if [ ${#IMAGE_URL} -gt 5 ]; then
148
             if [ ${#IMAGE_URL} -gt 5 ]; then
150
                 clear
149
                 clear
151
                 AVATAR_SET=
150
                 AVATAR_SET=
152
-                set_avatar_from_url $IMAGE_URL
151
+                set_avatar_from_url "$IMAGE_URL"
153
                 if [ $AVATAR_SET ]; then
152
                 if [ $AVATAR_SET ]; then
154
                     dialog --title $"Change htmly avatar" \
153
                     dialog --title $"Change htmly avatar" \
155
                            --msgbox $"Your htmly avatar has been changed" 6 40
154
                            --msgbox $"Your htmly avatar has been changed" 6 40
157
             fi
156
             fi
158
             ;;
157
             ;;
159
     esac
158
     esac
159
+    rm -f "$data"
160
 }
160
 }
161
 
161
 
162
 function install_interactive_htmly {
162
 function install_interactive_htmly {
163
-    if [ ! $ONION_ONLY ]; then
163
+    if [ ! "$ONION_ONLY" ]; then
164
         ONION_ONLY='no'
164
         ONION_ONLY='no'
165
     fi
165
     fi
166
 
166
 
186
         echo $'Htmly password is too short'
186
         echo $'Htmly password is too short'
187
         return
187
         return
188
     fi
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
     if [ ${#HTMLY_PASSWORD_HASH} -lt 8 ]; then
191
     if [ ${#HTMLY_PASSWORD_HASH} -lt 8 ]; then
192
         echo $'Htmly admin password could not be hashed'
192
         echo $'Htmly admin password could not be hashed'
193
         exit 625728
193
         exit 625728
194
     fi
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
 function reconfigure_htmly {
198
 function reconfigure_htmly {
208
     read_config_param "HTMLY_DOMAIN_NAME"
208
     read_config_param "HTMLY_DOMAIN_NAME"
209
 
209
 
210
     function_check set_repo_commit
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
 function backup_local_htmly {
214
 function backup_local_htmly {
215
     HTMLY_DOMAIN_NAME='htmly.local'
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
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
217
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
218
     fi
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
         dest_directory=htmly
222
         dest_directory=htmly
223
         function_check suspend_site
223
         function_check suspend_site
224
-        suspend_site ${HTMLY_DOMAIN_NAME}
224
+        suspend_site "${HTMLY_DOMAIN_NAME}"
225
 
225
 
226
         function_check backup_directory_to_usb
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
         function_check restart_site
229
         function_check restart_site
230
         restart_site
230
         restart_site
233
 
233
 
234
 function restore_local_htmly {
234
 function restore_local_htmly {
235
     HTMLY_DOMAIN_NAME='htmly.local'
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
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
237
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
238
     fi
238
     fi
239
-    if [ $HTMLY_DOMAIN_NAME ]; then
239
+    if [ "$HTMLY_DOMAIN_NAME" ]; then
240
         temp_restore_dir=/root/temphtmly
240
         temp_restore_dir=/root/temphtmly
241
-        if [ -d $USB_MOUNT/backup/htmly ]; then
241
+        if [ -d "$USB_MOUNT/backup/htmly" ]; then
242
             restore_directory_from_usb $temp_restore_dir htmly
242
             restore_directory_from_usb $temp_restore_dir htmly
243
         else
243
         else
244
             restore_directory_from_usb $temp_restore_dir blog
244
             restore_directory_from_usb $temp_restore_dir blog
245
         fi
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
             fi
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
         fi
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
             temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
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
         else
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
             fi
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
         fi
260
         fi
261
+        # shellcheck disable=SC2181
261
         if [ ! "$?" = "0" ]; then
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
             fi
265
             fi
265
             set_user_permissions
266
             set_user_permissions
266
             backup_unmount_drive
267
             backup_unmount_drive
267
             exit 54675
268
             exit 54675
268
         fi
269
         fi
269
         rm -rf ${temp_restore_dir}
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
             echo $"No content directory found after restoring htmly"
272
             echo $"No content directory found after restoring htmly"
272
             set_user_permissions
273
             set_user_permissions
273
             backup_unmount_drive
274
             backup_unmount_drive
274
             exit 34578
275
             exit 34578
275
         fi
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
         # Ensure that the bundled SSL cert is being used
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
         fi
281
         fi
281
         for d in /home/*/ ; do
282
         for d in /home/*/ ; do
282
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
283
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
283
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
287
                 fi
287
             fi
288
             fi
288
         done
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
         fi
293
         fi
293
     fi
294
     fi
294
 }
295
 }
295
 
296
 
296
 function backup_remote_htmly {
297
 function backup_remote_htmly {
297
-    if grep -q "htmly domain" $COMPLETION_FILE; then
298
+    if grep -q "htmly domain" "$COMPLETION_FILE"; then
298
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
299
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
299
         temp_backup_dir=/var/www/${HTMLY_DOMAIN_NAME}/htdocs
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
             echo $"Backing up htmly"
302
             echo $"Backing up htmly"
302
-            backup_directory_to_friend $temp_backup_dir htmly
303
+            backup_directory_to_friend "$temp_backup_dir" htmly
303
             echo $"Backup of htmly complete"
304
             echo $"Backup of htmly complete"
304
         else
305
         else
305
             echo $"Htmly domain specified but not found in $temp_backup_dir"
306
             echo $"Htmly domain specified but not found in $temp_backup_dir"
309
 }
310
 }
310
 
311
 
311
 function restore_remote_htmly {
312
 function restore_remote_htmly {
312
-    if [ -d $SERVER_DIRECTORY/backup/htmly ]; then
313
+    if [ -d "$SERVER_DIRECTORY/backup/htmly" ]; then
313
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
314
         HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
314
         echo $"Restoring htmly installation $HTMLY_DOMAIN_NAME"
315
         echo $"Restoring htmly installation $HTMLY_DOMAIN_NAME"
315
         temp_restore_dir=/root/temphtmly
316
         temp_restore_dir=/root/temphtmly
316
         mkdir $temp_restore_dir
317
         mkdir $temp_restore_dir
317
         function_check restore_directory_from_friend
318
         function_check restore_directory_from_friend
318
         restore_directory_from_friend $temp_restore_dir htmly
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
             fi
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
         fi
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
             temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
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
         else
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
             fi
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
         fi
335
         fi
335
 
336
 
337
+        # shellcheck disable=SC2181
336
         if [ ! "$?" = "0" ]; then
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
             fi
341
             fi
340
             exit 593
342
             exit 593
341
         fi
343
         fi
342
         rm -rf ${temp_restore_dir}
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
             echo $"No content directory found after restoring htmly"
346
             echo $"No content directory found after restoring htmly"
345
             exit 287
347
             exit 287
346
         fi
348
         fi
347
         # Ensure that the bundled SSL cert is being used
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
         fi
352
         fi
351
         for d in /home/*/ ; do
353
         for d in /home/*/ ; do
352
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
354
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
353
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
358
                 fi
357
             fi
359
             fi
358
         done
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
         fi
364
         fi
363
         echo $"Restore of htmly complete"
365
         echo $"Restore of htmly complete"
364
     fi
366
     fi
370
     fi
372
     fi
371
 
373
 
372
     read_config_param "HTMLY_DOMAIN_NAME"
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
     fi
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
     fi
382
     fi
381
     remove_config_param HTMLY_DOMAIN_NAME
383
     remove_config_param HTMLY_DOMAIN_NAME
382
     remove_config_param HTMLY_CODE
384
     remove_config_param HTMLY_CODE
383
     function_check remove_onion_service
385
     function_check remove_onion_service
384
     remove_onion_service htmly ${HTMLY_ONION_PORT}
386
     remove_onion_service htmly ${HTMLY_ONION_PORT}
385
     remove_completion_param "install_htmly"
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
     function_check remove_ddns_domain
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
 function install_htmly_social_networks {
395
 function install_htmly_social_networks {
394
     # set social networks
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
     fi
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
     fi
404
     fi
403
 
405
 
404
     # clear proprietary social network strings
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
 function install_htmly_user {
412
 function install_htmly_user {
411
     # create a user password
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
     else
416
     else
415
-        HTMLY_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
417
+        HTMLY_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
416
     fi
418
     fi
417
 
419
 
418
     # create a user
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
     if [ ${#HTMLY_ADMIN_PASSWORD_HASH} -lt 8 ]; then
422
     if [ ${#HTMLY_ADMIN_PASSWORD_HASH} -lt 8 ]; then
421
         echo $'Htmly admin password could not be hashed'
423
         echo $'Htmly admin password could not be hashed'
422
         exit 625728
424
         exit 625728
423
     fi
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
 function install_htmly_settings {
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
 function install_htmly_website {
442
 function install_htmly_website {
441
     function_check nginx_http_redirect
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
     function_check nginx_ssl
455
     function_check nginx_ssl
454
-    nginx_ssl $HTMLY_DOMAIN_NAME
456
+    nginx_ssl "$HTMLY_DOMAIN_NAME"
455
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
 function install_htmly_website_onion {
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check nginx_limits
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
 function install_htmly_from_repo {
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
     fi
609
     fi
602
 
610
 
603
-    cd /var/www/$HTMLY_DOMAIN_NAME
611
+    cd "/var/www/$HTMLY_DOMAIN_NAME" || exit 34684682
604
 
612
 
605
     if [ -d /repos/htmly ]; then
613
     if [ -d /repos/htmly ]; then
606
         mkdir htdocs
614
         mkdir htdocs
607
         cp -r -p /repos/htmly/. htdocs
615
         cp -r -p /repos/htmly/. htdocs
608
-        cd htdocs
616
+        cd htdocs || exit 3468735
609
         git pull
617
         git pull
610
     else
618
     else
611
         git_clone $HTMLY_REPO htdocs
619
         git_clone $HTMLY_REPO htdocs
612
     fi
620
     fi
613
 
621
 
614
-    cd htdocs
622
+    cd htdocs || exit 3479835
615
     git checkout $HTMLY_COMMIT -b $HTMLY_COMMIT
623
     git checkout $HTMLY_COMMIT -b $HTMLY_COMMIT
616
     set_completion_param "htmly commit" "$HTMLY_COMMIT"
624
     set_completion_param "htmly commit" "$HTMLY_COMMIT"
617
 }
625
 }
618
 
626
 
619
 function install_htmly {
627
 function install_htmly {
620
-    if [ ! $ONION_ONLY ]; then
628
+    if [ ! "$ONION_ONLY" ]; then
621
         ONION_ONLY='no'
629
         ONION_ONLY='no'
622
     fi
630
     fi
623
 
631
 
624
-    if [ ! $HTMLY_DOMAIN_NAME ]; then
632
+    if [ ! "$HTMLY_DOMAIN_NAME" ]; then
625
         echo $'The htmly domain name was not specified'
633
         echo $'The htmly domain name was not specified'
626
         exit 5062
634
         exit 5062
627
     fi
635
     fi
636
         function_check install_htmly_website
644
         function_check install_htmly_website
637
         install_htmly_website
645
         install_htmly_website
638
     else
646
     else
639
-        echo -n '' > /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
647
+        echo -n '' > "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
640
     fi
648
     fi
649
+    HTMLY_ONION_HOSTNAME=$(add_onion_service htmly 80 ${HTMLY_ONION_PORT})
641
     function_check install_htmly_website_onion
650
     function_check install_htmly_website_onion
642
     install_htmly_website_onion
651
     install_htmly_website_onion
643
 
652
 
644
     function_check create_site_certificate
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
     function_check configure_php
656
     function_check configure_php
648
     configure_php
657
     configure_php
656
     function_check install_htmly_user
665
     function_check install_htmly_user
657
     install_htmly_user
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
     function_check nginx_ensite
670
     function_check nginx_ensite
664
-    nginx_ensite $HTMLY_DOMAIN_NAME
671
+    nginx_ensite "$HTMLY_DOMAIN_NAME"
665
 
672
 
666
     systemctl restart php7.0-fpm
673
     systemctl restart php7.0-fpm
667
     systemctl restart nginx
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
     function_check add_ddns_domain
678
     function_check add_ddns_domain
672
-    add_ddns_domain $HTMLY_DOMAIN_NAME
679
+    add_ddns_domain "$HTMLY_DOMAIN_NAME"
673
 
680
 
674
     set_completion_param "htmly domain" "$HTMLY_DOMAIN_NAME"
681
     set_completion_param "htmly domain" "$HTMLY_DOMAIN_NAME"
675
     APP_INSTALLED=1
682
     APP_INSTALLED=1

+ 256
- 254
src/freedombone-app-hubzilla 查看文件

60
 
60
 
61
 function remove_user_hubzilla {
61
 function remove_user_hubzilla {
62
     remove_username="$1"
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
 function add_user_hubzilla {
66
 function add_user_hubzilla {
71
 
71
 
72
     new_username="$1"
72
     new_username="$1"
73
     new_user_password="$2"
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
     echo '0'
75
     echo '0'
76
 }
76
 }
77
 
77
 
78
 function hubzilla_renew_cert {
78
 function hubzilla_renew_cert {
79
     dialog --title $"Renew SSL certificate" \
79
     dialog --title $"Renew SSL certificate" \
80
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
82
     sel=$?
83
     case $sel in
83
     case $sel in
84
         1) return;;
84
         1) return;;
85
         255) return;;
85
         255) return;;
86
     esac
86
     esac
87
     HUBZILLA_DOMAIN_NAME=$(get_completion_param "hubzilla domain")
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
         dialog --title $"Renew SSL certificate" \
89
         dialog --title $"Renew SSL certificate" \
90
                --msgbox $"Hubzilla install directory not found" 6 40
90
                --msgbox $"Hubzilla install directory not found" 6 40
91
         return
91
         return
92
     fi
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
         any_key
94
         any_key
96
     else
95
     else
97
         dialog --title $"Renew SSL certificate" \
96
         dialog --title $"Renew SSL certificate" \
100
 }
99
 }
101
 
100
 
102
 function hubzilla_channel_directory_server {
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
         dialog --title $"Hubzilla channel directory server" \
103
         dialog --title $"Hubzilla channel directory server" \
105
                --msgbox $"Hubzilla is not installed on this system" 6 40
104
                --msgbox $"Hubzilla is not installed on this system" 6 40
106
         return
105
         return
107
     fi
106
     fi
108
     HUBZILLA_DOMAIN_NAME=$(get_completion_param "hubzilla domain")
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
         dialog --title $"Hubzilla channel directory server" \
109
         dialog --title $"Hubzilla channel directory server" \
111
                --msgbox $"Hubzilla install directory not found" 6 40
110
                --msgbox $"Hubzilla install directory not found" 6 40
112
         return
111
         return
113
     fi
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
     dialog --title $"Hubzilla channel directory server" \
115
     dialog --title $"Hubzilla channel directory server" \
118
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
118
     sel=$?
121
     case $sel in
119
     case $sel in
122
         0)
120
         0)
123
-            hubzilla_domain_server=$(<$data)
121
+            hubzilla_domain_server=$(<"$data")
124
             if [[ $hubzilla_domain_server != *"."* ]]; then
122
             if [[ $hubzilla_domain_server != *"."* ]]; then
123
+                rm -f "$data"
125
                 return
124
                 return
126
             fi
125
             fi
127
             if [[ $hubzilla_domain_server != "https"* ]]; then
126
             if [[ $hubzilla_domain_server != "https"* ]]; then
128
                 dialog --title $"Hubzilla channel directory server" \
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
                 return
130
                 return
131
             fi
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
             dialog --title $"Hubzilla channel directory server" \
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
     esac
136
     esac
137
+    rm -f "$data"
137
 }
138
 }
138
 
139
 
139
 function configure_interactive_hubzilla {
140
 function configure_interactive_hubzilla {
140
     while true
141
     while true
141
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
144
         dialog --backtitle $"Freedombone Control Panel" \
145
                --title $"Hubzilla" \
145
                --title $"Hubzilla" \
146
                --radiolist $"Choose an operation:" 13 70 4 \
146
                --radiolist $"Choose an operation:" 13 70 4 \
147
                1 $"Set channel directory server" off \
147
                1 $"Set channel directory server" off \
148
                2 $"Renew SSL certificate" off \
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
         sel=$?
150
         sel=$?
151
         case $sel in
151
         case $sel in
152
             1) break;;
152
             1) break;;
153
             255) break;;
153
             255) break;;
154
         esac
154
         esac
155
-        case $(cat $data) in
155
+        case $(cat "$data") in
156
             1) hubzilla_channel_directory_server;;
156
             1) hubzilla_channel_directory_server;;
157
             2) hubzilla_renew_cert;;
157
             2) hubzilla_renew_cert;;
158
-            3) break;;
158
+            3) rm -f "$data"
159
+               break;;
159
         esac
160
         esac
161
+        rm -f "$data"
160
     done
162
     done
161
 }
163
 }
162
 
164
 
163
 function install_interactive_hubzilla {
165
 function install_interactive_hubzilla {
164
-    if [[ $ONION_ONLY != "no" ]]; then
166
+    if [[ "$ONION_ONLY" != "no" ]]; then
165
         return
167
         return
166
     fi
168
     fi
167
 
169
 
172
 }
174
 }
173
 
175
 
174
 function change_password_hubzilla {
176
 function change_password_hubzilla {
175
-    HUBZILLA_USERNAME="$1"
177
+#    HUBZILLA_USERNAME="$1"
176
     HUBZILLA_PASSWORD="$2"
178
     HUBZILLA_PASSWORD="$2"
177
     if [ ${#HUBZILLA_PASSWORD} -lt 8 ]; then
179
     if [ ${#HUBZILLA_PASSWORD} -lt 8 ]; then
178
         echo $'Hubzilla password is too short'
180
         echo $'Hubzilla password is too short'
183
 }
185
 }
184
 
186
 
185
 function hubzilla_create_database {
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
     fi
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
     fi
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
         return
196
         return
195
     fi
197
     fi
196
 
198
 
211
     HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
213
     HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
212
 
214
 
213
     function_check set_repo_commit
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
         git merge --abort
220
         git merge --abort
219
         git stash
221
         git stash
220
         git pull
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
     fi
225
     fi
224
 }
226
 }
225
 
227
 
226
 function backup_local_hubzilla {
228
 function backup_local_hubzilla {
227
     hubzilla_path=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
229
     hubzilla_path=/var/www/${HUBZILLA_DOMAIN_NAME}/htdocs
228
-    if [ -d $hubzilla_path ]; then
230
+    if [ -d "$hubzilla_path" ]; then
229
         function_check backup_database_to_usb
231
         function_check backup_database_to_usb
230
         backup_database_to_usb hubzilla
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
     fi
235
     fi
234
 }
236
 }
235
 
237
 
240
     function_check hubzilla_create_database
242
     function_check hubzilla_create_database
241
     hubzilla_create_database
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
         fi
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
         if [ -d $temp_restore_dir ]; then
252
         if [ -d $temp_restore_dir ]; then
251
             rm -rf $temp_restore_dir
253
             rm -rf $temp_restore_dir
252
         fi
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
         MARIADB_PASSWORD=
259
         MARIADB_PASSWORD=
258
     fi
260
     fi
259
 }
261
 }
260
 
262
 
261
 function backup_remote_hubzilla {
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
         backup_database_to_friend hubzilla
267
         backup_database_to_friend hubzilla
266
         echo "Backing up Hubzilla installation"
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
         restart_site
270
         restart_site
269
         echo "Backup of Hubzilla complete"
271
         echo "Backup of Hubzilla complete"
270
     else
272
     else
279
     function_check hubzilla_create_database
281
     function_check hubzilla_create_database
280
     hubzilla_create_database
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
         fi
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
     fi
291
     fi
290
     if [ -d /root/temphubzilla ]; then
292
     if [ -d /root/temphubzilla ]; then
291
         rm -rf /root/temphubzilla
293
         rm -rf /root/temphubzilla
292
     fi
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
     HUBZILLA_PATH=/var/www/$HUBZILLA_DOMAIN_NAME/htdocs
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
     MARIADB_PASSWORD=
299
     MARIADB_PASSWORD=
298
 }
300
 }
299
 
301
 
301
     if [ ${#HUBZILLA_DOMAIN_NAME} -eq 0 ]; then
303
     if [ ${#HUBZILLA_DOMAIN_NAME} -eq 0 ]; then
302
         return
304
         return
303
     fi
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
     fi
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
     fi
313
     fi
312
     function_check drop_database
314
     function_check drop_database
313
     drop_database hubzilla
315
     drop_database hubzilla
314
     function_check remove_onion_service
316
     function_check remove_onion_service
315
     remove_onion_service hubzilla ${HUBZILLA_ONION_PORT}
317
     remove_onion_service hubzilla ${HUBZILLA_ONION_PORT}
316
-    sed -i '/hubzilla/d' $COMPLETION_FILE
318
+    sed -i '/hubzilla/d' "$COMPLETION_FILE"
317
     sed -i '/poller.php/d' /etc/crontab
319
     sed -i '/poller.php/d' /etc/crontab
318
 
320
 
319
     function_check remove_ddns_domain
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
 function install_hubzilla {
325
 function install_hubzilla {
324
-    if [ ! $HUBZILLA_DOMAIN_NAME ]; then
326
+    if [ ! "$HUBZILLA_DOMAIN_NAME" ]; then
325
         return
327
         return
326
     fi
328
     fi
327
 
329
 
328
-    if [[ $ONION_ONLY != "no" ]]; then
330
+    if [[ "$ONION_ONLY" != "no" ]]; then
329
         echo $"Hubzilla won't work on an onion address"
331
         echo $"Hubzilla won't work on an onion address"
330
         exit 529925
332
         exit 529925
331
     fi
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
     function_check install_mariadb
337
     function_check install_mariadb
336
     install_mariadb
338
     install_mariadb
337
 
339
 
338
-    if [ -d /var/www/$HUBZILLA_DOMAIN_NAME ]; then
340
+    if [ -d "/var/www/$HUBZILLA_DOMAIN_NAME" ]; then
339
         remove_hubzilla
341
         remove_hubzilla
340
     fi
342
     fi
341
 
343
 
349
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
351
     apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
350
     apt-get -yq install php-memcached memcached
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
     fi
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
     fi
359
     fi
358
 
360
 
359
-    if [ ! -f $HUBZILLA_PATH/index.php ]; then
361
+    if [ ! -f "$HUBZILLA_PATH/index.php" ]; then
360
         if [ -d /repos/hubzilla ]; then
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
             git pull
366
             git pull
365
         else
367
         else
366
             function_check git_clone
368
             function_check git_clone
367
-            git_clone $HUBZILLA_REPO $HUBZILLA_PATH
369
+            git_clone "$HUBZILLA_REPO" "$HUBZILLA_PATH"
368
         fi
370
         fi
369
 
371
 
370
-        git checkout $HUBZILLA_COMMIT -b $HUBZILLA_COMMIT
372
+        git checkout "$HUBZILLA_COMMIT" -b "$HUBZILLA_COMMIT"
371
         set_completion_param "hubzilla commit" "$HUBZILLA_COMMIT"
373
         set_completion_param "hubzilla commit" "$HUBZILLA_COMMIT"
372
 
374
 
373
         if [ -d /repos/hubzilla-addons ]; then
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
             git pull
379
             git pull
378
         else
380
         else
379
-            git_clone $HUBZILLA_ADDONS_REPO $HUBZILLA_PATH/addon
381
+            git_clone "$HUBZILLA_ADDONS_REPO" "$HUBZILLA_PATH/addon"
380
         fi
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
         set_completion_param "hubzilla addons commit" "$HUBZILLA_ADDONS_COMMIT"
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
     fi
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
         echo $'No database schema found for hubzilla'
392
         echo $'No database schema found for hubzilla'
391
         exit 252782
393
         exit 252782
392
     fi
394
     fi
403
     fi
405
     fi
404
 
406
 
405
     function_check add_ddns_domain
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
         function_check nginx_http_redirect
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
         function_check nginx_ssl
422
         function_check nginx_ssl
421
-        nginx_ssl $HUBZILLA_DOMAIN_NAME
423
+        nginx_ssl "$HUBZILLA_DOMAIN_NAME"
422
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
         function_check nginx_limits
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
     else
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
     fi
548
     fi
547
 
549
 
548
     function_check configure_php
550
     function_check configure_php
549
     configure_php
551
     configure_php
550
 
552
 
551
     function_check create_site_certificate
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
     fi
558
     fi
557
     if [ ! -d "$HUBZILLA_PATH/store" ]; then
559
     if [ ! -d "$HUBZILLA_PATH/store" ]; then
558
         mkdir "$HUBZILLA_PATH/store"
560
         mkdir "$HUBZILLA_PATH/store"
564
         mkdir "$HUBZILLA_PATH/store/[data]/smarty3"
566
         mkdir "$HUBZILLA_PATH/store/[data]/smarty3"
565
         chmod 1777 "$HUBZILLA_PATH/store/[data]/smarty3"
567
         chmod 1777 "$HUBZILLA_PATH/store/[data]/smarty3"
566
     fi
568
     fi
567
-    chmod 1777 $HUBZILLA_PATH/view/tpl
569
+    chmod 1777 "$HUBZILLA_PATH/view/tpl"
568
     chown -R www-data:www-data "$HUBZILLA_PATH/store"
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
     # Ensure that the database gets backed up locally, if remote
573
     # Ensure that the database gets backed up locally, if remote
572
     # backups are not being used
574
     # backups are not being used
576
     function_check backup_database_local
578
     function_check backup_database_local
577
     backup_database_local hubzilla
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
     function_check nginx_ensite
583
     function_check nginx_ensite
582
-    nginx_ensite $HUBZILLA_DOMAIN_NAME
584
+    nginx_ensite "$HUBZILLA_DOMAIN_NAME"
583
 
585
 
584
     function_check initialise_database
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
     # create the config file
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
     else
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
     fi
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
     HUBZILLA_LOCATION_HASH="$(create_password 30)"
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
     systemctl restart mariadb
619
     systemctl restart mariadb
618
     systemctl restart php7.0-fpm
620
     systemctl restart php7.0-fpm
619
     systemctl restart nginx
621
     systemctl restart nginx
620
     systemctl restart cron
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
     set_completion_param "hubzilla domain" "${HUBZILLA_DOMAIN_NAME}"
626
     set_completion_param "hubzilla domain" "${HUBZILLA_DOMAIN_NAME}"
625
     APP_INSTALLED=1
627
     APP_INSTALLED=1

+ 220
- 216
src/freedombone-app-icecast 查看文件

68
         rm /etc/init.d/icecast2
68
         rm /etc/init.d/icecast2
69
     fi
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
     chmod +x /usr/bin/stop_icecast
74
     chmod +x /usr/bin/stop_icecast
75
 
75
 
76
     # Note that the sleep here actually is important
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
     chmod +x /usr/bin/start_icecast
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
     chown -R icecast2:icecast /etc/ices2
102
     chown -R icecast2:icecast /etc/ices2
103
     chown -R icecast2:icecast /etc/icecast2
103
     chown -R icecast2:icecast /etc/icecast2
121
         /etc/icecast2/icecast.xml
121
         /etc/icecast2/icecast.xml
122
     sed -i "s|<password>.*|<password>${new_user_password}</password>|g" /etc/ices2/ices-playlist.xml
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
     start_icecast
125
     start_icecast
126
 }
126
 }
127
 
127
 
139
 
139
 
140
 function icecast_convert_files {
140
 function icecast_convert_files {
141
     clear
141
     clear
142
-    cd ${1}
142
+    cd "${1}" || exit 2346824648
143
 
143
 
144
     echo $'Converting any mp3 files to ogg format'
144
     echo $'Converting any mp3 files to ogg format'
145
     find . -type f -name '*.mp3' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${0/%mp3/ogg}"' '{}' \;
145
     find . -type f -name '*.mp3' -exec bash -c 'ffmpeg -i "$0" -c:a libvorbis -q:a 4 "${0/%mp3/ogg}"' '{}' \;
153
 }
153
 }
154
 
154
 
155
 function icecast_add_file_to_playlist {
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
         return
158
         return
159
     fi
159
     fi
160
 
160
 
161
     echo $'Adding ogg files to playlist'
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
         if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
163
         if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
164
             echo "$file" >> $ICECAST_PLAYLIST_FILE
164
             echo "$file" >> $ICECAST_PLAYLIST_FILE
165
         fi
165
         fi
166
     done
166
     done
167
 
167
 
168
     echo $'Adding ogv files to playlist'
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
         if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
170
         if ! grep -q "$file" $ICECAST_PLAYLIST_FILE; then
171
             echo "$file" >> $ICECAST_PLAYLIST_FILE
171
             echo "$file" >> $ICECAST_PLAYLIST_FILE
172
         fi
172
         fi
178
 }
178
 }
179
 
179
 
180
 function icecast_import_from_directory {
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
     if [[ "$selected_dir" == "$ICECAST_DIR" ]]; then
185
     if [[ "$selected_dir" == "$ICECAST_DIR" ]]; then
186
         return
186
         return
187
     fi
187
     fi
188
-    if [ ! -d $selected_dir ]; then
188
+    if [ ! -d "$selected_dir" ]; then
189
         return
189
         return
190
     fi
190
     fi
191
     if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
191
     if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
201
     dialog --title $"Import stream files directory into Icecast" \
201
     dialog --title $"Import stream files directory into Icecast" \
202
            --backtitle $"Freedombone Control Panel" \
202
            --backtitle $"Freedombone Control Panel" \
203
            --defaultno \
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
     sel=$?
205
     sel=$?
206
     case $sel in
206
     case $sel in
207
         1) return;;
207
         1) return;;
215
     dest_dir=$(basename "$selected_dir")
215
     dest_dir=$(basename "$selected_dir")
216
     mv "$selected_dir" $ICECAST_DIR
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
     dialog --title $"Import stream files directory into Icecast" \
221
     dialog --title $"Import stream files directory into Icecast" \
222
            --msgbox $"Import success" 6 40
222
            --msgbox $"Import success" 6 40
226
     clear
226
     clear
227
     detect_usb_drive
227
     detect_usb_drive
228
 
228
 
229
-    if [ ! -b $USB_DRIVE ]; then
229
+    if [ ! -b "$USB_DRIVE" ]; then
230
         dialog --title $"Import stream files from USB drive" --msgbox $'No USB drive found' 6 50
230
         dialog --title $"Import stream files from USB drive" --msgbox $'No USB drive found' 6 50
231
         return
231
         return
232
     fi
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
         dialog --title $"Import stream files from USB drive" --msgbox $'No stream files directory found on USB drive' 6 50
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
     fi
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
     icecast_convert_files $ICECAST_DIR
241
     icecast_convert_files $ICECAST_DIR
242
     dialog --title $"Import stream files from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
242
     dialog --title $"Import stream files from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
243
 }
243
 }
246
     clear
246
     clear
247
     detect_usb_drive
247
     detect_usb_drive
248
 
248
 
249
-    if [ ! -b $USB_DRIVE ]; then
249
+    if [ ! -b "$USB_DRIVE" ]; then
250
         dialog --title $"Export stream files to USB drive" --msgbox $'No USB drive found' 6 50
250
         dialog --title $"Export stream files to USB drive" --msgbox $'No USB drive found' 6 50
251
         return
251
         return
252
     fi
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
     fi
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
     dialog --title $"Export stream files to USB drive" --msgbox $'Export complete. You may now remove the USB drive' 6 50
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
 function icecast_format_drive {
263
 function icecast_format_drive {
264
     detect_usb_drive
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
     dialog --title $"Format USB drive $USB_DRIVE for stream file storage" \
266
     dialog --title $"Format USB drive $USB_DRIVE for stream file storage" \
268
            --backtitle $"Freedombone Control Panel" \
267
            --backtitle $"Freedombone Control Panel" \
269
            --defaultno \
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
     sel=$?
270
     sel=$?
272
     case $sel in
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
     esac
276
     esac
276
-    rm $data
277
+    rm -f "$data"
277
 
278
 
278
     clear
279
     clear
279
     echo ''
280
     echo ''
280
     echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
281
     echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
281
     echo ''
282
     echo ''
282
-    ${PROJECT_NAME}-format $USB_DRIVE
283
+    "${PROJECT_NAME}-format" "$USB_DRIVE"
283
     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
     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
 }
291
 }
291
 
292
 
292
 function icecast_change_login {
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
     dialog --title $"Change Icecast stream visitor login" \
298
     dialog --title $"Change Icecast stream visitor login" \
299
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
301
     sel=$?
302
     case $sel in
302
     case $sel in
303
-        0)  ICECAST_USER_PASSWORD=$(<$data)
303
+        0)  ICECAST_USER_PASSWORD=$(<"$data")
304
             if [[ "$ICECAST_USER_PASSWORD" != *' '* ]]; then
304
             if [[ "$ICECAST_USER_PASSWORD" != *' '* ]]; then
305
                 if [ ${#ICECAST_USER_PASSWORD} -gt 8 ]; then
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
                     dialog --title $"Change Icecast stream visitor login" \
307
                     dialog --title $"Change Icecast stream visitor login" \
308
                            --msgbox $"Password changed to $ICECAST_USER_PASSWORD" 6 75
308
                            --msgbox $"Password changed to $ICECAST_USER_PASSWORD" 6 75
309
                 fi
309
                 fi
310
             fi
310
             fi
311
             ;;
311
             ;;
312
     esac
312
     esac
313
-    rm $data
313
+    rm -f "$data"
314
 }
314
 }
315
 
315
 
316
 function icecast_enable_login {
316
 function icecast_enable_login {
317
     dialog --title $"Enable Icecast login" \
317
     dialog --title $"Enable Icecast login" \
318
            --backtitle $"Freedombone Control Panel" \
318
            --backtitle $"Freedombone Control Panel" \
319
            --defaultno \
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
     sel=$?
321
     sel=$?
322
     case $sel in
322
     case $sel in
323
         0) if grep -q '#auth_basic' /etc/nginx/sites-available/icecast; then
323
         0) if grep -q '#auth_basic' /etc/nginx/sites-available/icecast; then
324
                sed -i 's|#auth_basic|auth_basic|g' /etc/nginx/sites-available/icecast
324
                sed -i 's|#auth_basic|auth_basic|g' /etc/nginx/sites-available/icecast
325
                systemctl restart nginx
325
                systemctl restart nginx
326
            fi
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
            dialog --title $"Enable Icecast login" \
329
            dialog --title $"Enable Icecast login" \
330
                   --msgbox $"Icecast logins are now enabled with the password $ICECAST_USER_PASSWORD" 6 65
330
                   --msgbox $"Icecast logins are now enabled with the password $ICECAST_USER_PASSWORD" 6 65
331
            ICECAST_USER_PASSWORD=
331
            ICECAST_USER_PASSWORD=
341
 }
341
 }
342
 
342
 
343
 function icecast_set_stream_name {
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
     dialog --backtitle $"Freedombone Control Panel" \
345
     dialog --backtitle $"Freedombone Control Panel" \
347
            --title $"Change Icecast stream details" \
346
            --title $"Change Icecast stream details" \
348
-           --form "\n" 8 60 4 \
347
+           --form "\\n" 8 60 4 \
349
            $"Stream name:" 1 1 "Example stream name" 1 18 40 1000 \
348
            $"Stream name:" 1 1 "Example stream name" 1 18 40 1000 \
350
            $"Description:" 2 1 "A short description of your stream" 2 18 40 1000 \
349
            $"Description:" 2 1 "A short description of your stream" 2 18 40 1000 \
351
            $"Genre:" 3 1 "Example genre" 3 18 40 1000 \
350
            $"Genre:" 3 1 "Example genre" 3 18 40 1000 \
352
-           2> $data
351
+           2> "$data"
353
     sel=$?
352
     sel=$?
354
     case $sel in
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
     esac
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
     if [ ${#stream_name} -gt 2 ]; then
362
     if [ ${#stream_name} -gt 2 ]; then
362
         sed -i "s|<name>.*|<name>${stream_name}</name>|g" /etc/ices2/ices-playlist.xml
363
         sed -i "s|<name>.*|<name>${stream_name}</name>|g" /etc/ices2/ices-playlist.xml
363
     fi
364
     fi
367
     if [ ${#stream_genre} -gt 2 ]; then
368
     if [ ${#stream_genre} -gt 2 ]; then
368
         sed -i "s|<genre>.*|<genre>${stream_genre}</genre>|g" /etc/ices2/ices-playlist.xml
369
         sed -i "s|<genre>.*|<genre>${stream_genre}</genre>|g" /etc/ices2/ices-playlist.xml
369
     fi
370
     fi
370
-    rm $data
371
+    rm -f "$data"
371
     stop_icecast
372
     stop_icecast
372
     start_icecast
373
     start_icecast
373
 }
374
 }
374
 
375
 
375
 function icecast_set_maximum_streams {
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
     dialog --title $"Set the maximum clients" \
378
     dialog --title $"Set the maximum clients" \
379
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
381
     sel=$?
382
     case $sel in
382
     case $sel in
383
         0)
383
         0)
384
-            max_clients=$(<$data)
384
+            max_clients=$(<"$data")
385
             if [ ${#max_clients} -gt 0 ]; then
385
             if [ ${#max_clients} -gt 0 ]; then
386
                 if [[ "$max_clients" != *' '* ]]; then
386
                 if [[ "$max_clients" != *' '* ]]; then
387
-                    if [[ $max_clients =~ '^[0-9]+$' ]] ; then
387
+                    # shellcheck disable=SC2076
388
+                    if [[ "$max_clients" =~ '^[0-9]+$' ]] ; then
388
                         sed -i "s|<clients>.*|<clients>${max_clients}</clients>|g" /etc/icecast2/icecast.xml
389
                         sed -i "s|<clients>.*|<clients>${max_clients}</clients>|g" /etc/icecast2/icecast.xml
389
                         stop_icecast
390
                         stop_icecast
390
                         start_icecast
391
                         start_icecast
391
                         dialog --title $"Set the maximum clients" \
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
                     fi
394
                     fi
394
                 fi
395
                 fi
395
             fi
396
             fi
396
             ;;
397
             ;;
397
     esac
398
     esac
398
-    rm $data
399
+    rm -f "$data"
399
 }
400
 }
400
 
401
 
401
 function configure_interactive_icecast {
402
 function configure_interactive_icecast {
402
     while true
403
     while true
403
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
406
         dialog --backtitle $"Freedombone Control Panel" \
407
                --title $"Icecast" \
407
                --title $"Icecast" \
408
                --radiolist $"Choose an operation:" 19 70 12 \
408
                --radiolist $"Choose an operation:" 19 70 12 \
417
                9 $"Restart stream" off \
417
                9 $"Restart stream" off \
418
                10 $"Set Stream Name/Description/Genre" off \
418
                10 $"Set Stream Name/Description/Genre" off \
419
                11 $"Set maximum number of clients/streams" off \
419
                11 $"Set maximum number of clients/streams" off \
420
-               12 $"Exit" on 2> $data
420
+               12 $"Exit" on 2> "$data"
421
         sel=$?
421
         sel=$?
422
         case $sel in
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
         esac
427
         esac
426
-        case $(cat $data) in
428
+        case $(cat "$data") in
427
             1) icecast_import_from_directory;;
429
             1) icecast_import_from_directory;;
428
             2) icecast_import_from_usb;;
430
             2) icecast_import_from_usb;;
429
             3) icecast_format_drive;;
431
             3) icecast_format_drive;;
440
                start_icecast;;
442
                start_icecast;;
441
             10) icecast_set_stream_name;;
443
             10) icecast_set_stream_name;;
442
             11) icecast_set_maximum_streams;;
444
             11) icecast_set_maximum_streams;;
443
-            12) break;;
445
+            12) rm -f "$data"
446
+                break;;
444
         esac
447
         esac
448
+        rm -f "$data"
445
     done
449
     done
446
 }
450
 }
447
 
451
 
556
     fi
560
     fi
557
     function_check remove_onion_service
561
     function_check remove_onion_service
558
     remove_onion_service icecast ${ICECAST_ONION_PORT}
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
 function install_icecast {
566
 function install_icecast {
572
         exit 7923528
576
         exit 7923528
573
     fi
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
         else
582
         else
579
-            ICECAST_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
583
+            ICECAST_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
580
         fi
584
         fi
581
     fi
585
     fi
582
 
586
 
600
     fi
604
     fi
601
 
605
 
602
     icecast_nginx_site=/etc/nginx/sites-available/icecast
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
     function_check nginx_limits
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
     if [ ! -d /var/log/ices ]; then
624
     if [ ! -d /var/log/ices ]; then
621
         mkdir -p /var/log/ices
625
         mkdir -p /var/log/ices
624
         mkdir -p /etc/ices2
628
         mkdir -p /etc/ices2
625
     fi
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
     sed -i 's|ENABLE=.*|ENABLE=true|g' /etc/default/icecast2
731
     sed -i 's|ENABLE=.*|ENABLE=true|g' /etc/default/icecast2
728
 
732
 
733
 
737
 
734
 
738
 
735
     # create a password for users
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
     if grep -q "$MY_USERNAME:" /etc/nginx/.icepasswd; then
741
     if grep -q "$MY_USERNAME:" /etc/nginx/.icepasswd; then
738
         sed -i "/$MY_USERNAME:/d" /etc/nginx/.icepasswd
742
         sed -i "/$MY_USERNAME:/d" /etc/nginx/.icepasswd
739
     fi
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
     if [ ! -f /etc/nginx/.icepasswd ]; then
745
     if [ ! -f /etc/nginx/.icepasswd ]; then
742
         echo $'/etc/nginx/.icepasswd not found'
746
         echo $'/etc/nginx/.icepasswd not found'
743
         exit 73528235
747
         exit 73528235
744
     fi
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
     groupadd icecast
753
     groupadd icecast
750
     useradd -c "Icecast system account" -d /etc/icecast2 -m -r -g icecast icecast2
754
     useradd -c "Icecast system account" -d /etc/icecast2 -m -r -g icecast icecast2

+ 153
- 153
src/freedombone-app-ipfs 查看文件

76
     fi
76
     fi
77
 
77
 
78
     function_check set_repo_commit
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
 function upgrade_ipfs_js {
82
 function upgrade_ipfs_js {
97
 }
97
 }
98
 
98
 
99
 function backup_local_ipfs {
99
 function backup_local_ipfs {
100
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
100
+    if ! grep -q "Admin user" "$COMPLETION_FILE"; then
101
         return
101
         return
102
     fi
102
     fi
103
     ADMIN_USERNAME=$(get_completion_param "Admin user")
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
         dest_directory=ipfs
106
         dest_directory=ipfs
107
         function_check backup_directory_to_usb
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
     fi
109
     fi
110
 }
110
 }
111
 
111
 
112
 function restore_local_ipfs {
112
 function restore_local_ipfs {
113
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
113
+    if ! grep -q "Admin user" "$COMPLETION_FILE"; then
114
         return
114
         return
115
     fi
115
     fi
116
-    if [ -d $USB_MOUNT/backup/ipfs ]; then
116
+    if [ -d "$USB_MOUNT/backup/ipfs" ]; then
117
         echo $"Restoring IPFS"
117
         echo $"Restoring IPFS"
118
         temp_restore_dir=/root/tempipfs
118
         temp_restore_dir=/root/tempipfs
119
         function_check restore_directory_from_usb
119
         function_check restore_directory_from_usb
120
         restore_directory_from_usb $temp_restore_dir ipfs
120
         restore_directory_from_usb $temp_restore_dir ipfs
121
         ADMIN_USERNAME=$(get_completion_param "Admin user")
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
         else
124
         else
125
-            cp -rf $temp_restore_dir/* /home/$ADMIN_USERNAME/.ipfs
125
+            cp -rf "$temp_restore_dir/*" "/home/$ADMIN_USERNAME/.ipfs"
126
         fi
126
         fi
127
+        # shellcheck disable=SC2181
127
         if [ ! "$?" = "0" ]; then
128
         if [ ! "$?" = "0" ]; then
128
             rm -rf $temp_restore_dir
129
             rm -rf $temp_restore_dir
129
             function_check set_user_permissions
130
             function_check set_user_permissions
138
 }
139
 }
139
 
140
 
140
 function backup_remote_ipfs {
141
 function backup_remote_ipfs {
141
-    if ! grep -q "Admin user" $COMPLETION_FILE; then
142
+    if ! grep -q "Admin user" "$COMPLETION_FILE"; then
142
         return
143
         return
143
     fi
144
     fi
144
     ADMIN_USERNAME=$(get_completion_param "Admin user")
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
         echo $"Backing up IPFS"
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
         echo $"Backup of IPFS complete"
149
         echo $"Backup of IPFS complete"
149
     fi
150
     fi
150
 }
151
 }
151
 
152
 
152
 function restore_remote_ipfs {
153
 function restore_remote_ipfs {
153
-    if [ -d $SERVER_DIRECTORY/backup/ipfs ]; then
154
+    if [ -d "$SERVER_DIRECTORY/backup/ipfs" ]; then
154
         echo $"Restoring IPFS"
155
         echo $"Restoring IPFS"
155
         temp_restore_dir=/root/tempipfs
156
         temp_restore_dir=/root/tempipfs
156
         function_check restore_directory_from_friend
157
         function_check restore_directory_from_friend
157
         restore_directory_from_friend $temp_restore_dir ipfs
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
         else
161
         else
161
-            cp -rf $temp_restore_dir/* /home/$ADMIN_USERNAME/.ipfs
162
+            cp -rf "$temp_restore_dir/*" "/home/$ADMIN_USERNAME/.ipfs"
162
         fi
163
         fi
164
+        # shellcheck disable=SC2181
163
         if [ ! "$?" = "0" ]; then
165
         if [ ! "$?" = "0" ]; then
164
             function_check set_user_permissions
166
             function_check set_user_permissions
165
             set_user_permissions
167
             set_user_permissions
177
     systemctl daemon-reload
179
     systemctl daemon-reload
178
     rm /etc/systemd/system/ipfs.service
180
     rm /etc/systemd/system/ipfs.service
179
     systemctl daemon-reload
181
     systemctl daemon-reload
180
-    rm -rf $GOPATH/src/github.com/ipfs
182
+    rm -rf "$GOPATH/src/github.com/ipfs"
181
     firewall_remove $IPFS_PORT tcp
183
     firewall_remove $IPFS_PORT tcp
182
     remove_completion_param install_ipfs
184
     remove_completion_param install_ipfs
183
     remove_completion_param configure_firewall_for_ipfs
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
 function remove_ipfs_js {
189
 function remove_ipfs_js {
194
     npm uninstall ronin --global
196
     npm uninstall ronin --global
195
 
197
 
196
     firewall_remove $IPFS_PORT tcp
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
 function remove_ipfs {
204
 function remove_ipfs {
205
 }
207
 }
206
 
208
 
207
 function configure_firewall_for_ipfs {
209
 function configure_firewall_for_ipfs {
208
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
210
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
209
         return
211
         return
210
     fi
212
     fi
211
     if [[ $ONION_ONLY != "no" ]]; then
213
     if [[ $ONION_ONLY != "no" ]]; then
213
     fi
215
     fi
214
 
216
 
215
     firewall_add IPFS $IPFS_PORT tcp
217
     firewall_add IPFS $IPFS_PORT tcp
216
-    mark_completed $FUNCNAME
218
+    mark_completed "${FUNCNAME[0]}"
217
 }
219
 }
218
 
220
 
219
 function mesh_install_ipfs_js {
221
 function mesh_install_ipfs_js {
220
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
222
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
221
         return
223
         return
222
     fi
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
         echo $'nodejs was not installed'
230
         echo $'nodejs was not installed'
228
         exit 63962
231
         exit 63962
229
     fi
232
     fi
230
 
233
 
231
-    cat <<EOF > ${rootdir}/root/install-ipfs.sh
234
+    cat <<EOF > "${rootdir}/root/install-ipfs.sh"
232
 #!/bin/bash
235
 #!/bin/bash
233
 PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
236
 PATH="/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/bin"
234
 NODE_PATH="/usr/lib/node_modules"
237
 NODE_PATH="/usr/lib/node_modules"
241
 npm install -g ipfs@${IPFS_JS_VERSION} --save
244
 npm install -g ipfs@${IPFS_JS_VERSION} --save
242
 exit 0
245
 exit 0
243
 EOF
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
     IPFS_PATH=/usr/bin
251
     IPFS_PATH=/usr/bin
249
 
252
 
250
-    if [ ! -f ${rootdir}$IPFS_PATH/jsipfs ]; then
253
+    if [ ! -f "${rootdir}$IPFS_PATH/jsipfs" ]; then
251
         exit 637292
254
         exit 637292
252
     fi
255
     fi
253
 
256
 
254
     # directories to mount to
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
     fi
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
     fi
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
     fi
270
     fi
268
 
271
 
269
     IPFS_DAEMON_NAME=ipfs
272
     IPFS_DAEMON_NAME=ipfs
270
     IPFS_DAEMON_FILE=${rootdir}/etc/systemd/system/${IPFS_DAEMON_NAME}.service
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
 function install_ipfs_js {
296
 function install_ipfs_js {
294
-    if [ $INSTALLING_MESH ]; then
297
+    if [ "$INSTALLING_MESH" ]; then
295
         mesh_install_ipfs_js
298
         mesh_install_ipfs_js
296
         return
299
         return
297
     fi
300
     fi
321
     fi
324
     fi
322
 
325
 
323
     # initialise
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
         echo "IPFS could not be initialised for user $MY_USERNAME"
329
         echo "IPFS could not be initialised for user $MY_USERNAME"
327
         exit 7358
330
         exit 7358
328
     fi
331
     fi
331
     if [ ! -d /ipfs ]; then
334
     if [ ! -d /ipfs ]; then
332
         mkdir /ipfs
335
         mkdir /ipfs
333
         mkdir /ipns
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
     fi
339
     fi
337
 
340
 
338
     if [ -f /etc/fuse.conf ]; then
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
     fi
343
     fi
341
     if [ -f /dev/fuse ]; then
344
     if [ -f /dev/fuse ]; then
342
-        chown $MY_USERNAME:$MY_USERNAME /dev/fuse
345
+        chown "$MY_USERNAME":"$MY_USERNAME" /dev/fuse
343
     fi
346
     fi
344
 
347
 
345
     IPFS_DAEMON_NAME=ipfs
348
     IPFS_DAEMON_NAME=ipfs
346
     IPFS_DAEMON_FILE=/etc/systemd/system/${IPFS_DAEMON_NAME}.service
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
     systemctl enable ${IPFS_DAEMON_NAME}
367
     systemctl enable ${IPFS_DAEMON_NAME}
365
     systemctl daemon-reload
368
     systemctl daemon-reload
366
     systemctl restart ${IPFS_DAEMON_NAME}
369
     systemctl restart ${IPFS_DAEMON_NAME}
367
 
370
 
368
     if [ -d /etc/avahi ]; then
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
         if [ ! -f /tmp/ipfsid ]; then
373
         if [ ! -f /tmp/ipfsid ]; then
371
             echo 'No IPFS identity was created'
374
             echo 'No IPFS identity was created'
372
             exit 37895
375
             exit 37895
387
 }
390
 }
388
 
391
 
389
 function mesh_install_ipfs_go {
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
     mesh_upgrade_golang
395
     mesh_upgrade_golang
393
 
396
 
394
     IPFS_ARCH=
397
     IPFS_ARCH=
395
     IPFS_PATH=/usr/bin
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
     fi
402
     fi
400
-    cd $rootdir$INSTALL_DIR/ipfs
403
+    cd "$rootdir$INSTALL_DIR/ipfs" || exit 23468264
401
 
404
 
402
     if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
405
     if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
403
         IPFS_ARCH=386
406
         IPFS_ARCH=386
431
 
434
 
432
     IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz
435
     IPFS_FILE=go-ipfs_v${IPFS_GO_VERSION}_linux-${IPFS_ARCH}.tar.gz
433
     wget https://ipfs.io/ipns/dist.ipfs.io/go-ipfs/v${IPFS_GO_VERSION}/${IPFS_FILE}
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
         echo $'IPFS package could not be downloaded'
438
         echo $'IPFS package could not be downloaded'
436
         exit 63725
439
         exit 63725
437
     fi
440
     fi
438
     tar -xzvf ${IPFS_FILE}
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
         echo $"ipfs was not found in downloaded package"
443
         echo $"ipfs was not found in downloaded package"
441
         exit 638235
444
         exit 638235
442
     fi
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
         echo $'IPFS was not installed'
448
         echo $'IPFS was not installed'
446
         exit 63722
449
         exit 63722
447
     fi
450
     fi
448
 
451
 
449
     IPFS_USER_DAEMON=${rootdir}/home/${MY_USERNAME}/.config/systemd/user/ipfs.service
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
 function install_ipfs_go {
471
 function install_ipfs_go {
469
-    if [ $INSTALLING_MESH ]; then
472
+    if [ "$INSTALLING_MESH" ]; then
470
         mesh_install_ipfs_go
473
         mesh_install_ipfs_go
471
         return
474
         return
472
     fi
475
     fi
490
         else
493
         else
491
             sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
494
             sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
492
         fi
495
         fi
493
-        systemctl set-environment GOPATH=$GOPATH
496
+        systemctl set-environment GOPATH="$GOPATH"
494
         if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
497
         if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
495
             echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
498
             echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
496
         else
499
         else
497
             sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
500
             sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
498
         fi
501
         fi
499
-        if [ ! -d $GOPATH ]; then
500
-            mkdir -p $GOPATH
502
+        if [ ! -d "$GOPATH" ]; then
503
+            mkdir -p "$GOPATH"
501
         fi
504
         fi
502
     fi
505
     fi
503
 
506
 
504
     IPFS_PATH=$GOPATH/bin
507
     IPFS_PATH=$GOPATH/bin
505
     export PATH="$GOPATH/bin:$PATH:"
508
     export PATH="$GOPATH/bin:$PATH:"
506
     if ! grep -q 'GOPATH/bin' ~/.bashrc; then
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
     else
511
     else
509
         sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
512
         sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
510
     fi
513
     fi
511
 
514
 
512
     # set gopath for the user
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
     else
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
     fi
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
         exit 8242
525
         exit 8242
524
     fi
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
         echo $'go get failed to get ipfs'
529
         echo $'go get failed to get ipfs'
528
         exit 63923
530
         exit 63923
529
     fi
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
         exit 735639
535
         exit 735639
535
     fi
536
     fi
536
 
537
 
537
     set_completion_param "ipfs commit" "$IPFS_COMMIT"
538
     set_completion_param "ipfs commit" "$IPFS_COMMIT"
538
 
539
 
539
-    make install
540
-    if [ ! "$?" = "0" ]; then
540
+    if ! make install; then
541
         exit 547242
541
         exit 547242
542
     fi
542
     fi
543
 
543
 
544
     # initialise
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
         echo "IPFS could not be initialised for user $MY_USERNAME"
548
         echo "IPFS could not be initialised for user $MY_USERNAME"
549
         exit 7358
549
         exit 7358
550
     fi
550
     fi
553
     if [ ! -d /ipfs ]; then
553
     if [ ! -d /ipfs ]; then
554
         mkdir /ipfs
554
         mkdir /ipfs
555
         mkdir /ipns
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
     fi
558
     fi
559
 
559
 
560
     if [ -f /etc/fuse.conf ]; then
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
     fi
562
     fi
563
     if [ -f /dev/fuse ]; then
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
     systemctl enable ipfs
584
     systemctl enable ipfs
585
     systemctl daemon-reload
585
     systemctl daemon-reload
586
     systemctl restart ipfs
586
     systemctl restart ipfs
587
 
587
 
588
     if [ -d /etc/avahi ]; then
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
         if [ ! -f /tmp/ipfsid ]; then
590
         if [ ! -f /tmp/ipfsid ]; then
591
             echo 'No IPFS identity was created'
591
             echo 'No IPFS identity was created'
592
             exit 37895
592
             exit 37895

+ 209
- 204
src/freedombone-app-irc 查看文件

63
 }
63
 }
64
 
64
 
65
 function irc_get_global_password {
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
 function start_irc_bouncer {
69
 function start_irc_bouncer {
93
         new_name="$new_username"
93
         new_name="$new_username"
94
     fi
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
     if [[ ${ONION_ONLY} == 'no' ]]; then
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
     else
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
 function remove_user_irc_bouncer {
162
 function remove_user_irc_bouncer {
172
 function remove_user_irc {
172
 function remove_user_irc {
173
     remove_username="$1"
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
     fi
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
     fi
183
     fi
184
 }
184
 }
185
 
185
 
192
     for d in /home/*/ ; do
192
     for d in /home/*/ ; do
193
         IRC_USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
193
         IRC_USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
194
         if [[ $(is_valid_user "$IRC_USERNAME") == "1" ]]; then
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
             fi
198
             fi
199
         fi
199
         fi
200
     done
200
     done
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
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
     # Update the password
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
     # matrix bridge to irc
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
         systemctl restart matrix_irc_bridge
225
         systemctl restart matrix_irc_bridge
226
     fi
226
     fi
227
 
227
 
244
     new_user_password=$(irc_get_global_password)
244
     new_user_password=$(irc_get_global_password)
245
     IRC_PASSWORD="$new_user_password"
245
     IRC_PASSWORD="$new_user_password"
246
     is_admin='true'
246
     is_admin='true'
247
-    if [ ! $3 ]; then
247
+    if [ ! "$3" ]; then
248
         is_admin='false'
248
         is_admin='false'
249
     fi
249
     fi
250
 
250
 
255
     read_config_param IRC_PORT
255
     read_config_param IRC_PORT
256
     read_config_param DEFAULT_DOMAIN_NAME
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
     stop_irc_bouncer
260
     stop_irc_bouncer
261
 
261
 
269
         return
269
         return
270
     fi
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
     mkdir -p /home/znc/.znc/moddata/webadmin
340
     mkdir -p /home/znc/.znc/moddata/webadmin
341
 
341
 
353
         IRC_PASSWORD=
353
         IRC_PASSWORD=
354
     fi
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
     fi
358
     fi
359
 
359
 
360
     create_irssi_config "${new_username}"
360
     create_irssi_config "${new_username}"
374
 
374
 
375
 function irc_set_global_password {
375
 function irc_set_global_password {
376
     EXISTING_IRC_PASSWORD=$(irc_get_global_password)
376
     EXISTING_IRC_PASSWORD=$(irc_get_global_password)
377
+    data=$(mktemp 2>/dev/null)
377
     dialog --title $"IRC Password" \
378
     dialog --title $"IRC Password" \
378
            --clear \
379
            --clear \
379
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
382
     sel=$?
382
     case $sel in
383
     case $sel in
383
         0)
384
         0)
384
-            NEW_IRC_PASSWORD=$(<$data)
385
+            NEW_IRC_PASSWORD=$(<"$data")
385
             irc_set_global_password_base "$NEW_IRC_PASSWORD"
386
             irc_set_global_password_base "$NEW_IRC_PASSWORD"
386
             dialog --title $"IRC Password" \
387
             dialog --title $"IRC Password" \
387
                    --msgbox $"The IRC password was changed" 6 40
388
                    --msgbox $"The IRC password was changed" 6 40
388
             ;;
389
             ;;
389
     esac
390
     esac
391
+    rm -f "$data"
390
 }
392
 }
391
 
393
 
392
 function configure_interactive_irc {
394
 function configure_interactive_irc {
398
 
400
 
399
     while true
401
     while true
400
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
404
         dialog --backtitle $"Freedombone Control Panel" \
404
                --title $"IRC Menu" \
405
                --title $"IRC Menu" \
405
                --radiolist $"Choose an operation:" 14 70 4 \
406
                --radiolist $"Choose an operation:" 14 70 4 \
406
                1 $"Set a password for all IRC users" off \
407
                1 $"Set a password for all IRC users" off \
407
                2 $"Show current IRC login password" off \
408
                2 $"Show current IRC login password" off \
408
-               3 $"Exit" on 2> $data
409
+               3 $"Exit" on 2> "$data"
409
         sel=$?
410
         sel=$?
410
         case $sel in
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
         esac
416
         esac
414
-        case $(cat $data) in
417
+        case $(cat "$data") in
415
             1) irc_set_global_password;;
418
             1) irc_set_global_password;;
416
             2) irc_show_password;;
419
             2) irc_show_password;;
417
             3) break;;
420
             3) break;;
418
         esac
421
         esac
422
+        rm -f "$data"
419
     done
423
     done
420
 }
424
 }
421
 
425
 
466
     remove_onion_service irc ${IRC_ONION_PORT}
470
     remove_onion_service irc ${IRC_ONION_PORT}
467
     remove_completion_param install_irc
471
     remove_completion_param install_irc
468
     remove_completion_param configure_firewall_for_irc
472
     remove_completion_param configure_firewall_for_irc
469
-    sed -i '/IRC /d' ${COMPLETION_FILE}
473
+    sed -i '/IRC /d' "${COMPLETION_FILE}"
470
     sed -i '/znc 2> /d' /etc/crontab
474
     sed -i '/znc 2> /d' /etc/crontab
471
     stop_irc_bouncer
475
     stop_irc_bouncer
472
     if [ -d /home/znc ]; then
476
     if [ -d /home/znc ]; then
481
     if [ ! -d /etc/ngircd ]; then
485
     if [ ! -d /etc/ngircd ]; then
482
         return
486
         return
483
     fi
487
     fi
484
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
488
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
485
         return
489
         return
486
     fi
490
     fi
487
     if [[ ${INSTALLED_WITHIN_DOCKER} == "yes" ]]; then
491
     if [[ ${INSTALLED_WITHIN_DOCKER} == "yes" ]]; then
496
     save_firewall_settings
500
     save_firewall_settings
497
 
501
 
498
     firewall_add IRC ${IRC_BOUNCER_PORT} tcp
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
 function install_irc_server {
506
 function install_irc_server {
511
     fi
515
     fi
512
 
516
 
513
     # obtain a cert for the default domain
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
         echo $'Obtaining certificate for the main domain'
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
     fi
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
         function_check check_certificates
525
         function_check check_certificates
522
         check_certificates ngircd
526
         check_certificates ngircd
523
     fi
527
     fi
524
 
528
 
525
     DEFAULTDOMAIN=${DEFAULT_DOMAIN_NAME}
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
     set_password_for_all_users irc "$IRC_PASSWORD"
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
     sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
541
     sed -i 's|MotdFile = /etc/ngircd/ngircd.motd|MotdFile = /etc/ngircd/motd|g' /etc/ngircd/ngircd.conf
538
     sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
542
     sed -i "s/irc@irc.example.com/$MY_EMAIL_ADDRESS/g" /etc/ngircd/ngircd.conf
539
     sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
543
     sed -i "s/irc.example.net/$DEFAULTDOMAIN/g" /etc/ngircd/ngircd.conf
541
     sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
545
     sed -i 's/;Password = wealllikedebian/Password =/g' /etc/ngircd/ngircd.conf
542
     sed -i "s/;Ports =.*/Ports = ${IRC_PORT}/g" /etc/ngircd/ngircd.conf
546
     sed -i "s/;Ports =.*/Ports = ${IRC_PORT}/g" /etc/ngircd/ngircd.conf
543
     if [[ $ONION_ONLY == 'no' ]]; then
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
             sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/ngircd/ngircd.conf
549
             sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/ngircd/ngircd.conf
546
         else
550
         else
547
             sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt|g" /etc/ngircd/ngircd.conf
551
             sed -i "s|;CertFile = /etc/ssl/certs/server.crt|CertFile = /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt|g" /etc/ngircd/ngircd.conf
562
     sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
566
     sed -i "s|;KeyFile = /etc/ngircd/#chan.key|KeyFile = /etc/ngircd/${PROJECT_NAME}.key|g" /etc/ngircd/ngircd.conf
563
     sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
567
     sed -i "s/;CloakHost = cloaked.host/CloakHost = ${PROJECT_NAME}/g" /etc/ngircd/ngircd.conf
564
     IRC_SALT="$(create_password 30)"
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
     else
571
     else
568
-        IRC_OPERATOR_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
572
+        IRC_OPERATOR_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
569
     fi
573
     fi
570
     sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
574
     sed -i "s|;CloakHostSalt = abcdefghijklmnopqrstuvwxyz|CloakHostSalt = $IRC_SALT|g" /etc/ngircd/ngircd.conf
571
     sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
575
     sed -i 's/;ConnectIPv4 = yes/ConnectIPv4 = yes/g' /etc/ngircd/ngircd.conf
574
     sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
578
     sed -i "s/;Name = TheOper/Name = $MY_USERNAME/g" /etc/ngircd/ngircd.conf
575
     sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
579
     sed -i "s/;Password = ThePwd/Password = $IRC_OPERATOR_PASSWORD/g" /etc/ngircd/ngircd.conf
576
     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
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
         sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
582
         sed -i "0,/RE/s/Password =.*/Password =$IRC_PASSWORD/" /etc/ngircd/ngircd.conf
579
     fi
583
     fi
580
     # upgrade a cypher
584
     # upgrade a cypher
585
     touch /var/run/ngircd/ngircd.pid
589
     touch /var/run/ngircd/ngircd.pid
586
     chown -R irc:irc /var/run/ngircd
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
     if [ ! -d /var/run/ircd ]; then
595
     if [ ! -d /var/run/ircd ]; then
591
         mkdir /var/run/ircd
596
         mkdir /var/run/ircd
608
     fi
613
     fi
609
     apt-get -yq install irssi
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
     fi
618
     fi
614
 
619
 
615
     create_irssi_config "${MY_USERNAME}" "$MY_NAME"
620
     create_irssi_config "${MY_USERNAME}" "$MY_NAME"
632
     mkdir -p /home/znc/.znc/configs
637
     mkdir -p /home/znc/.znc/configs
633
     mkdir -p /home/znc/.znc/users
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
         echo '  SSL = true' >> /home/znc/.znc/configs/znc.conf
656
         echo '  SSL = true' >> /home/znc/.znc/configs/znc.conf
652
     else
657
     else
653
         echo '  SSL = false' >> /home/znc/.znc/configs/znc.conf
658
         echo '  SSL = false' >> /home/znc/.znc/configs/znc.conf
654
     fi
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
     if [ $IRC_PORT -ne $IRC_ONION_PORT ]; then
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
     fi
675
     fi
671
 
676
 
672
     chown -R znc:znc /home/znc/.znc
677
     chown -R znc:znc /home/znc/.znc

+ 84
- 85
src/freedombone-app-jitsi 查看文件

105
 }
105
 }
106
 
106
 
107
 function install_interactive_jitsi {
107
 function install_interactive_jitsi {
108
-    if [ ! ${ONION_ONLY} ]; then
108
+    if [ ! "${ONION_ONLY}" ]; then
109
         ONION_ONLY='no'
109
         ONION_ONLY='no'
110
     fi
110
     fi
111
 
111
 
202
 
202
 
203
     remove_app jitsi
203
     remove_app jitsi
204
     remove_completion_param install_jitsi
204
     remove_completion_param install_jitsi
205
-    sed -i '/jitsi/d' ${COMPLETION_FILE}
205
+    sed -i '/jitsi/d' "${COMPLETION_FILE}"
206
 
206
 
207
     function_check remove_ddns_domain
207
     function_check remove_ddns_domain
208
     remove_ddns_domain $JITSI_DOMAIN_NAME
208
     remove_ddns_domain $JITSI_DOMAIN_NAME
233
     jitsi_deb_repo=unstable #binary
233
     jitsi_deb_repo=unstable #binary
234
     apt-get -yq install wget debconf-utils default-jre
234
     apt-get -yq install wget debconf-utils default-jre
235
     install_nodejs jitsi
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
         remove_nodejs jitsi
237
         remove_nodejs jitsi
239
         exit 638352
238
         exit 638352
240
     fi
239
     fi
272
 
271
 
273
     echo 'server_names_hash_bucket_size 64;' > $jitsi_nginx_site
272
     echo 'server_names_hash_bucket_size 64;' > $jitsi_nginx_site
274
     if [[ $ONION_ONLY == "no" ]]; then
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
         function_check nginx_ssl
286
         function_check nginx_ssl
288
         nginx_ssl ${JITSI_DOMAIN_NAME}
287
         nginx_ssl ${JITSI_DOMAIN_NAME}
290
         function_check nginx_disable_sniffing
289
         function_check nginx_disable_sniffing
291
         nginx_disable_sniffing ${JITSI_DOMAIN_NAME}
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
     if [[ $ONION_ONLY == 'no' ]]; then
329
     if [[ $ONION_ONLY == 'no' ]]; then
331
         echo "    server_name ${JITSI_DOMAIN_NAME};" >> $jitsi_nginx_site
330
         echo "    server_name ${JITSI_DOMAIN_NAME};" >> $jitsi_nginx_site
332
     else
331
     else
333
         echo "    server_name ${JITSI_ONION_HOSTNAME};" >> $jitsi_nginx_site
332
         echo "    server_name ${JITSI_ONION_HOSTNAME};" >> $jitsi_nginx_site
334
     fi
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
     sed -i "s|/var/www/${JITSI_DOMAIN_NAME}/htdocs|/usr/share/jitsi-meet|g" $jitsi_nginx_site
367
     sed -i "s|/var/www/${JITSI_DOMAIN_NAME}/htdocs|/usr/share/jitsi-meet|g" $jitsi_nginx_site
369
 
368
 
376
         fi
375
         fi
377
         function_check create_site_certificate
376
         function_check create_site_certificate
378
         create_site_certificate ${JITSI_DOMAIN_NAME} 'yes'
377
         create_site_certificate ${JITSI_DOMAIN_NAME} 'yes'
379
-        if [[ $ONION_ONLY == "no" ]]; then
378
+        if [[ "$ONION_ONLY" == "no" ]]; then
380
             if [ ! -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.pem ]; then
379
             if [ ! -f /etc/ssl/certs/${JITSI_DOMAIN_NAME}.pem ]; then
381
                 exit 678363
380
                 exit 678363
382
             fi
381
             fi

+ 195
- 198
src/freedombone-app-kanboard 查看文件

70
 function remove_user_kanboard {
70
 function remove_user_kanboard {
71
     remove_username="$1"
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
 function add_user_kanboard {
76
 function add_user_kanboard {
77
     new_username="$1"
77
     new_username="$1"
78
     new_user_password="$2"
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
     echo '0'
81
     echo '0'
82
 }
82
 }
83
 
83
 
84
 function install_interactive_kanboard {
84
 function install_interactive_kanboard {
85
-    if [ ! $ONION_ONLY ]; then
85
+    if [ ! "$ONION_ONLY" ]; then
86
         ONION_ONLY='no'
86
         ONION_ONLY='no'
87
     fi
87
     fi
88
 
88
 
92
         KANBOARD_DETAILS_COMPLETE=
92
         KANBOARD_DETAILS_COMPLETE=
93
         while [ ! $KANBOARD_DETAILS_COMPLETE ]
93
         while [ ! $KANBOARD_DETAILS_COMPLETE ]
94
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
96
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
98
                 dialog --backtitle $"Freedombone Configuration" \
97
                 dialog --backtitle $"Freedombone Configuration" \
99
                        --title $"KanBoard Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'KANBOARD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
100
                        $"Domain:" 1 1 "$(grep 'KANBOARD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
102
                        $"Code:" 2 1 "$(grep 'KANBOARD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
101
                        $"Code:" 2 1 "$(grep 'KANBOARD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
103
-                       2> $data
102
+                       2> "$data"
104
             else
103
             else
105
                 dialog --backtitle $"Freedombone Configuration" \
104
                 dialog --backtitle $"Freedombone Configuration" \
106
                        --title $"KanBoard Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'KANBOARD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
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
             fi
109
             fi
111
             sel=$?
110
             sel=$?
112
             case $sel in
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
             esac
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
                 if [[ $KANBOARD_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
119
                 if [[ $KANBOARD_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
119
                     KANBOARD_DOMAIN_NAME=""
120
                     KANBOARD_DOMAIN_NAME=""
120
                 fi
121
                 fi
121
                 TEST_DOMAIN_NAME=$KANBOARD_DOMAIN_NAME
122
                 TEST_DOMAIN_NAME=$KANBOARD_DOMAIN_NAME
122
                 validate_domain_name
123
                 validate_domain_name
123
-                if [[ $TEST_DOMAIN_NAME != $KANBOARD_DOMAIN_NAME ]]; then
124
+                if [[ "$TEST_DOMAIN_NAME" != "$KANBOARD_DOMAIN_NAME" ]]; then
124
                     KANBOARD_DOMAIN_NAME=
125
                     KANBOARD_DOMAIN_NAME=
125
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
126
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
126
                 else
127
                 else
127
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$KANBOARD_CODE"
130
                         validate_freedns_code "$KANBOARD_CODE"
130
-                        if [ ! $VALID_CODE ]; then
131
+                        if [ ! "$VALID_CODE" ]; then
131
                             KANBOARD_DOMAIN_NAME=
132
                             KANBOARD_DOMAIN_NAME=
132
                         fi
133
                         fi
133
                     fi
134
                     fi
136
             if [ $KANBOARD_DOMAIN_NAME ]; then
137
             if [ $KANBOARD_DOMAIN_NAME ]; then
137
                 KANBOARD_DETAILS_COMPLETE="yes"
138
                 KANBOARD_DETAILS_COMPLETE="yes"
138
             fi
139
             fi
140
+            rm -f "$data"
139
         done
141
         done
140
 
142
 
141
         # save the results in the config file
143
         # save the results in the config file
151
 
153
 
152
     read_config_param 'KANBOARD_DOMAIN_NAME'
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
 function kanboard_create_database {
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
     else
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
         fi
165
         fi
164
     fi
166
     fi
165
-    if [ ! $KANBOARD_ADMIN_PASSWORD ]; then
167
+    if [ ! "$KANBOARD_ADMIN_PASSWORD" ]; then
166
         return
168
         return
167
     fi
169
     fi
168
 
170
 
169
     function_check create_database
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
 function reconfigure_kanboard {
175
 function reconfigure_kanboard {
180
         return
182
         return
181
     fi
183
     fi
182
 
184
 
183
-    if grep -q "kanboard domain" $COMPLETION_FILE; then
185
+    if grep -q "kanboard domain" "$COMPLETION_FILE"; then
184
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
186
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
185
     fi
187
     fi
186
 
188
 
187
     # update to the next commit
189
     # update to the next commit
188
     function_check set_repo_commit
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
 function backup_local_kanboard {
197
 function backup_local_kanboard {
196
     KANBOARD_DOMAIN_NAME='kanboard'
198
     KANBOARD_DOMAIN_NAME='kanboard'
197
-    if grep -q "kanboard domain" $COMPLETION_FILE; then
199
+    if grep -q "kanboard domain" "$COMPLETION_FILE"; then
198
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
200
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
199
     fi
201
     fi
200
 
202
 
201
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/backup
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
     fi
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
     function_check suspend_site
209
     function_check suspend_site
208
-    suspend_site ${KANBOARD_DOMAIN_NAME}
210
+    suspend_site "${KANBOARD_DOMAIN_NAME}"
209
 
211
 
210
     function_check backup_directory_to_usb
212
     function_check backup_directory_to_usb
211
     dest_directory=kanboardconfig
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
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/data
216
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/data
215
     dest_directory=kanboardfile
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
     function_check backup_database_to_usb
220
     function_check backup_database_to_usb
219
     backup_database_to_usb kanboard
221
     backup_database_to_usb kanboard
223
 }
225
 }
224
 
226
 
225
 function restore_local_kanboard {
227
 function restore_local_kanboard {
226
-    if ! grep -q "kanboard domain" $COMPLETION_FILE; then
228
+    if ! grep -q "kanboard domain" "$COMPLETION_FILE"; then
227
         return
229
         return
228
     fi
230
     fi
229
     KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
231
     KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
230
-    if [ $KANBOARD_DOMAIN_NAME ]; then
232
+    if [ "$KANBOARD_DOMAIN_NAME" ]; then
231
         echo $"Restoring kanboard"
233
         echo $"Restoring kanboard"
232
         temp_restore_dir=/root/tempkanboard
234
         temp_restore_dir=/root/tempkanboard
233
         kanboard_dir=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs
235
         kanboard_dir=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs
243
         function_check restore_directory_from_usb
245
         function_check restore_directory_from_usb
244
         restore_directory_from_usb $temp_restore_dir kanboardconfig
246
         restore_directory_from_usb $temp_restore_dir kanboardconfig
245
         if [ -d $temp_restore_dir ]; then
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
             else
250
             else
249
-                cp $temp_restore_dir/config.php $kanboard_dir/
251
+                cp "$temp_restore_dir/config.php" "$kanboard_dir/"
250
             fi
252
             fi
251
-            chown www-data:www-data $kanboard_dir/config.php
253
+            chown www-data:www-data "$kanboard_dir/config.php"
252
             rm -rf $temp_restore_dir
254
             rm -rf $temp_restore_dir
253
         fi
255
         fi
254
 
256
 
255
         restore_directory_from_usb $temp_restore_dir kanboardfile
257
         restore_directory_from_usb $temp_restore_dir kanboardfile
256
         if [ -d $temp_restore_dir ]; then
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
             else
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
                 fi
264
                 fi
263
-                cp -rp $temp_restore_dir/* $kanboard_dir/data/
265
+                cp -rp "$temp_restore_dir/*" "$kanboard_dir/data/"
264
             fi
266
             fi
265
-            chown -R www-data:www-data $kanboard_dir/data
267
+            chown -R www-data:www-data "$kanboard_dir/data"
266
             rm -rf $temp_restore_dir
268
             rm -rf $temp_restore_dir
267
         fi
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
         echo $"Restore of kanboard complete"
273
         echo $"Restore of kanboard complete"
272
     fi
274
     fi
274
 
276
 
275
 function backup_remote_kanboard {
277
 function backup_remote_kanboard {
276
     KANBOARD_DOMAIN_NAME='kanboard'
278
     KANBOARD_DOMAIN_NAME='kanboard'
277
-    if grep -q "kanboard domain" $COMPLETION_FILE; then
279
+    if grep -q "kanboard domain" "$COMPLETION_FILE"; then
278
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
280
         KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
279
     fi
281
     fi
280
 
282
 
281
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/backup
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
     fi
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
     function_check suspend_site
289
     function_check suspend_site
288
-    suspend_site ${KANBOARD_DOMAIN_NAME}
290
+    suspend_site "${KANBOARD_DOMAIN_NAME}"
289
 
291
 
290
     function_check backup_directory_to_friend
292
     function_check backup_directory_to_friend
291
     dest_directory=kanboardconfig
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
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/data
296
     source_directory=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs/data
295
     dest_directory=kanboardfile
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
     function_check backup_database_to_friend
300
     function_check backup_database_to_friend
299
     backup_database_to_friend kanboard
301
     backup_database_to_friend kanboard
303
 }
305
 }
304
 
306
 
305
 function restore_remote_kanboard {
307
 function restore_remote_kanboard {
306
-    if ! grep -q "kanboard domain" $COMPLETION_FILE; then
308
+    if ! grep -q "kanboard domain" "$COMPLETION_FILE"; then
307
         return
309
         return
308
     fi
310
     fi
309
     KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
311
     KANBOARD_DOMAIN_NAME=$(get_completion_param "kanboard domain")
310
-    if [ $KANBOARD_DOMAIN_NAME ]; then
312
+    if [ "$KANBOARD_DOMAIN_NAME" ]; then
311
         echo $"Restoring kanboard"
313
         echo $"Restoring kanboard"
312
         temp_restore_dir=/root/tempkanboard
314
         temp_restore_dir=/root/tempkanboard
313
         kanboard_dir=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs
315
         kanboard_dir=/var/www/${KANBOARD_DOMAIN_NAME}/htdocs
324
         function_check restore_directory_from_friend
326
         function_check restore_directory_from_friend
325
         restore_directory_from_friend $temp_restore_dir kanboardconfig
327
         restore_directory_from_friend $temp_restore_dir kanboardconfig
326
         if [ -d $temp_restore_dir ]; then
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
             else
331
             else
330
-                cp $temp_restore_dir/config.php $kanboard_dir/
332
+                cp "$temp_restore_dir/config.php" "$kanboard_dir/"
331
             fi
333
             fi
332
-            chown www-data:www-data $kanboard_dir/config.php
334
+            chown www-data:www-data "$kanboard_dir/config.php"
333
             rm -rf $temp_restore_dir
335
             rm -rf $temp_restore_dir
334
         fi
336
         fi
335
 
337
 
336
         restore_directory_from_friend $temp_restore_dir kanboardfile
338
         restore_directory_from_friend $temp_restore_dir kanboardfile
337
         if [ -d $temp_restore_dir ]; then
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
             else
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
                 fi
345
                 fi
344
-                cp -rp $temp_restore_dir/* $kanboard_dir/data/
346
+                cp -rp "$temp_restore_dir/*" "$kanboard_dir/data/"
345
             fi
347
             fi
346
-            chown -R www-data:www-data $kanboard_dir/data
348
+            chown -R www-data:www-data "$kanboard_dir/data"
347
             rm -rf $temp_restore_dir
349
             rm -rf $temp_restore_dir
348
         fi
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
         echo $"Restore of kanboard complete"
354
         echo $"Restore of kanboard complete"
353
     fi
355
     fi
360
     read_config_param "KANBOARD_DOMAIN_NAME"
362
     read_config_param "KANBOARD_DOMAIN_NAME"
361
     read_config_param "MY_USERNAME"
363
     read_config_param "MY_USERNAME"
362
     echo "Removing $KANBOARD_DOMAIN_NAME"
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
     fi
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
     fi
373
     fi
372
     function_check drop_database
374
     function_check drop_database
373
     drop_database kanboard
375
     drop_database kanboard
375
     remove_onion_service kanboard ${KANBOARD_ONION_PORT}
377
     remove_onion_service kanboard ${KANBOARD_ONION_PORT}
376
     remove_app kanboard
378
     remove_app kanboard
377
     remove_completion_param install_kanboard
379
     remove_completion_param install_kanboard
378
-    sed -i '/kanboard/d' $COMPLETION_FILE
380
+    sed -i '/kanboard/d' "$COMPLETION_FILE"
379
     remove_backup_database_local kanboard
381
     remove_backup_database_local kanboard
380
 
382
 
381
     function_check remove_ddns_domain
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
 function install_kanboard {
387
 function install_kanboard {
387
         ONION_ONLY='no'
389
         ONION_ONLY='no'
388
     fi
390
     fi
389
 
391
 
390
-    if [ ! $KANBOARD_DOMAIN_NAME ]; then
392
+    if [ ! "$KANBOARD_DOMAIN_NAME" ]; then
391
         echo $'No domain name was given for kanboard'
393
         echo $'No domain name was given for kanboard'
392
         exit 73478
394
         exit 73478
393
     fi
395
     fi
394
 
396
 
395
-    kanboard_hourly_script kanboard $KANBOARD_DOMAIN_NAME
397
+    kanboard_hourly_script kanboard "$KANBOARD_DOMAIN_NAME"
396
 
398
 
397
     function_check install_mariadb
399
     function_check install_mariadb
398
     install_mariadb
400
     install_mariadb
406
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
408
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
407
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
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
     fi
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
         if [ -d /repos/kanboard ]; then
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
             git pull
420
             git pull
419
         else
421
         else
420
             function_check git_clone
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
         fi
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
             echo $'Unable to clone kanboard repo'
427
             echo $'Unable to clone kanboard repo'
426
             exit 89365
428
             exit 89365
427
         fi
429
         fi
428
     fi
430
     fi
429
 
431
 
430
-    cd /var/www/$KANBOARD_DOMAIN_NAME/htdocs
432
+    cd "/var/www/$KANBOARD_DOMAIN_NAME/htdocs" || exit 234682642
431
     git checkout $KANBOARD_COMMIT -b $KANBOARD_COMMIT
433
     git checkout $KANBOARD_COMMIT -b $KANBOARD_COMMIT
432
     set_completion_param "kanboard commit" "$KANBOARD_COMMIT"
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
     function_check kanboard_create_database
440
     function_check kanboard_create_database
439
     kanboard_create_database
441
     kanboard_create_database
446
     fi
448
     fi
447
 
449
 
448
     function_check add_ddns_domain
450
     function_check add_ddns_domain
449
-    add_ddns_domain $KANBOARD_DOMAIN_NAME
451
+    add_ddns_domain "$KANBOARD_DOMAIN_NAME"
450
 
452
 
451
     KANBOARD_ONION_HOSTNAME=$(add_onion_service kanboard 80 ${KANBOARD_ONION_PORT})
453
     KANBOARD_ONION_HOSTNAME=$(add_onion_service kanboard 80 ${KANBOARD_ONION_PORT})
452
 
454
 
453
     kanboard_nginx_site=/etc/nginx/sites-available/$KANBOARD_DOMAIN_NAME
455
     kanboard_nginx_site=/etc/nginx/sites-available/$KANBOARD_DOMAIN_NAME
454
     if [[ $ONION_ONLY == "no" ]]; then
456
     if [[ $ONION_ONLY == "no" ]]; then
455
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl
468
         function_check nginx_ssl
467
-        nginx_ssl $KANBOARD_DOMAIN_NAME
469
+        nginx_ssl "$KANBOARD_DOMAIN_NAME"
468
 
470
 
469
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
510
     else
509
-        echo -n '' > $kanboard_nginx_site
511
+        echo -n '' > "$kanboard_nginx_site"
510
     fi
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
     function_check nginx_compress
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check configure_php
558
     function_check configure_php
557
     configure_php
559
     configure_php
558
 
560
 
559
     function_check create_site_certificate
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
     # Ensure that the database gets backed up locally, if remote
564
     # Ensure that the database gets backed up locally, if remote
563
     # backups are not being used
565
     # backups are not being used
568
     backup_database_local kanboard
570
     backup_database_local kanboard
569
 
571
 
570
     function_check nginx_ensite
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
     # Create the configuration
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
     logging_off_kanboard
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
     install_composer
591
     install_composer
595
 
592
 
596
     systemctl restart mariadb
593
     systemctl restart mariadb
597
     systemctl restart php7.0-fpm
594
     systemctl restart php7.0-fpm
598
     systemctl restart nginx
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
     set_completion_param "kanboard domain" "$KANBOARD_DOMAIN_NAME"
599
     set_completion_param "kanboard domain" "$KANBOARD_DOMAIN_NAME"
603
 
600
 

+ 208
- 201
src/freedombone-app-keyserver 查看文件

49
 function check_keyserver_directory_size {
49
 function check_keyserver_directory_size {
50
     dirsize=$(du /var/lib/sks/DB | awk -F ' ' '{print $1}')
50
     dirsize=$(du /var/lib/sks/DB | awk -F ' ' '{print $1}')
51
     # 500M
51
     # 500M
52
-    if [ $dirsize -gt 500000 ]; then
52
+    if [ "$dirsize" -gt 500000 ]; then
53
         echo "1"
53
         echo "1"
54
         return
54
         return
55
     fi
55
     fi
57
 }
57
 }
58
 
58
 
59
 function keyserver_watchdog {
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
     ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
61
     ADMIN_EMAIL_ADDRESS=${ADMIN_USERNAME}@${HOSTNAME}
62
     keyserver_size_warning=$"The SKS keyserver database is getting large. Check that you aren't being spammed"
62
     keyserver_size_warning=$"The SKS keyserver database is getting large. Check that you aren't being spammed"
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."
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
 
67
 
68
     # check database size hourly
68
     # check database size hourly
69
     keyserver_watchdog_script=/tmp/keyserver-watchdog
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
     chmod +x $keyserver_watchdog_script
83
     chmod +x $keyserver_watchdog_script
84
 
84
 
85
     if [ ! -f /etc/cron.hourly/keyserver-watchdog ]; then
85
     if [ ! -f /etc/cron.hourly/keyserver-watchdog ]; then
102
     firewall_add keyserver 11370 tcp
102
     firewall_add keyserver 11370 tcp
103
     firewall_add keyserver 11371 tcp
103
     firewall_add keyserver 11371 tcp
104
     firewall_add keyserver 11372 tcp
104
     firewall_add keyserver 11372 tcp
105
-    mark_completed $FUNCNAME
105
+    mark_completed "${FUNCNAME[0]}"
106
 }
106
 }
107
 
107
 
108
 function keyserver_reset_database {
108
 function keyserver_reset_database {
134
         return
134
         return
135
     fi
135
     fi
136
 
136
 
137
-    if grep -q "keyserver domain" $COMPLETION_FILE; then
137
+    if grep -q "keyserver domain" "$COMPLETION_FILE"; then
138
         KEYSERVER_DOMAIN_NAME=$(get_completion_param "keyserver domain")
138
         KEYSERVER_DOMAIN_NAME=$(get_completion_param "keyserver domain")
139
     fi
139
     fi
140
 
140
 
141
     # update to the next commit
141
     # update to the next commit
142
     function_check set_repo_commit
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
     read_config_param MY_USERNAME
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
         echo $'No GPG ID for admin user'
149
         echo $'No GPG ID for admin user'
150
         exit 846336
150
         exit 846336
151
     fi
151
     fi
157
         echo $'GPG ID not retrieved for admin user due to error'
157
         echo $'GPG ID not retrieved for admin user due to error'
158
         exit 74825
158
         exit 74825
159
     fi
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
 function backup_local_keyserver {
168
 function backup_local_keyserver {
169
     # remove any unused log files
169
     # remove any unused log files
170
-    cd /var/lib/sks/DB
170
+    cd /var/lib/sks/DB || exit 2468245
171
     db_archive -d
171
     db_archive -d
172
 
172
 
173
     source_directory=/etc/sks
173
     source_directory=/etc/sks
223
         fi
223
         fi
224
         cp -r $temp_restore_dir/* /var/lib/sks/DB
224
         cp -r $temp_restore_dir/* /var/lib/sks/DB
225
     fi
225
     fi
226
+    # shellcheck disable=SC2181
226
     if [ ! "$?" = "0" ]; then
227
     if [ ! "$?" = "0" ]; then
227
         # restore the old database
228
         # restore the old database
228
         rm -rf /var/lib/sks/DB
229
         rm -rf /var/lib/sks/DB
243
 
244
 
244
     systemctl enable sks
245
     systemctl enable sks
245
     systemctl start sks
246
     systemctl start sks
246
-    nginx_ensite $KEYSERVER_DOMAIN_NAME
247
+    nginx_ensite "$KEYSERVER_DOMAIN_NAME"
247
 }
248
 }
248
 
249
 
249
 function backup_remote_keyserver {
250
 function backup_remote_keyserver {
250
     # remove any unused log files
251
     # remove any unused log files
251
-    cd /var/lib/sks/DB
252
+    cd /var/lib/sks/DB || exit 734624
252
     db_archive -d
253
     db_archive -d
253
 
254
 
254
     source_directory=/etc/sks
255
     source_directory=/etc/sks
304
         fi
305
         fi
305
         cp -r $temp_restore_dir/* /var/lib/sks/DB
306
         cp -r $temp_restore_dir/* /var/lib/sks/DB
306
     fi
307
     fi
308
+    # shellcheck disable=SC2181
307
     if [ ! "$?" = "0" ]; then
309
     if [ ! "$?" = "0" ]; then
308
         # restore the old database
310
         # restore the old database
309
         rm -rf /var/lib/sks/DB
311
         rm -rf /var/lib/sks/DB
322
 
324
 
323
     systemctl enable sks
325
     systemctl enable sks
324
     systemctl start sks
326
     systemctl start sks
325
-    nginx_ensite $KEYSERVER_DOMAIN_NAME
327
+    nginx_ensite "$KEYSERVER_DOMAIN_NAME"
326
 }
328
 }
327
 
329
 
328
 function remove_keyserver {
330
 function remove_keyserver {
333
     apt-get -qy remove sks dirmngr
335
     apt-get -qy remove sks dirmngr
334
 
336
 
335
     read_config_param "KEYSERVER_DOMAIN_NAME"
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
     fi
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
     fi
345
     fi
344
     function_check remove_ddns_domain
346
     function_check remove_ddns_domain
345
-    remove_ddns_domain $KEYSERVER_DOMAIN_NAME
347
+    remove_ddns_domain "$KEYSERVER_DOMAIN_NAME"
346
 
348
 
347
     remove_config_param KEYSERVER_DOMAIN_NAME
349
     remove_config_param KEYSERVER_DOMAIN_NAME
348
     remove_config_param KEYSERVER_CODE
350
     remove_config_param KEYSERVER_CODE
349
     function_check remove_onion_service
351
     function_check remove_onion_service
350
-    remove_onion_service keyserver ${KEYSERVER_ONION_PORT}
352
+    remove_onion_service keyserver "${KEYSERVER_ONION_PORT}"
351
     remove_onion_service sks 11370 11371 11372
353
     remove_onion_service sks 11370 11371 11372
352
     remove_completion_param "install_keyserver"
354
     remove_completion_param "install_keyserver"
353
 
355
 
355
     firewall_remove 11371 tcp
357
     firewall_remove 11371 tcp
356
     firewall_remove 11372 tcp
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
     if [ -d /var/lib/sks ]; then
362
     if [ -d /var/lib/sks ]; then
361
         rm -rf /var/lib/sks
363
         rm -rf /var/lib/sks
362
     fi
364
     fi
363
 }
365
 }
364
 
366
 
365
 function install_interactive_keyserver {
367
 function install_interactive_keyserver {
366
-    if [ ! $ONION_ONLY ]; then
368
+    if [ ! "$ONION_ONLY" ]; then
367
         ONION_ONLY='no'
369
         ONION_ONLY='no'
368
     fi
370
     fi
369
 
371
 
388
         return
390
         return
389
     fi
391
     fi
390
     systemctl stop sks
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
     chown -Rc debian-sks: /etc/sks/membership
399
     chown -Rc debian-sks: /etc/sks/membership
398
     systemctl start sks
400
     systemctl start sks
399
 }
401
 }
403
     dialog --title $"Import public keys database" \
405
     dialog --title $"Import public keys database" \
404
            --backtitle $"Freedombone Control Panel" \
406
            --backtitle $"Freedombone Control Panel" \
405
            --defaultno \
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
     sel=$?
409
     sel=$?
408
     case $sel in
410
     case $sel in
409
         1) return;;
411
         1) return;;
412
     if [ ! -d /var/lib/sks/dump ]; then
414
     if [ ! -d /var/lib/sks/dump ]; then
413
         mkdir -p /var/lib/sks/dump
415
         mkdir -p /var/lib/sks/dump
414
     fi
416
     fi
415
-    cd /var/lib/sks/dump
417
+    cd /var/lib/sks/dump || exit 59242684
416
     echo $'Getting keyserver dump. This may take a few days or longer, so be patient.'
418
     echo $'Getting keyserver dump. This may take a few days or longer, so be patient.'
417
     rm -rf /var/lib/sks/dump/*
419
     rm -rf /var/lib/sks/dump/*
418
     KEYSERVER_DUMP_URL="https://keyserver.mattrude.com/dump/$(date +%F)/"
420
     KEYSERVER_DUMP_URL="https://keyserver.mattrude.com/dump/$(date +%F)/"
419
     wget -crp -e robots=off --level=1 --cut-dirs=3 -nH \
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
     echo $'Building the keyserver database from the downloaded dump'
425
     echo $'Building the keyserver database from the downloaded dump'
424
     keyserver_reset_database
426
     keyserver_reset_database
425
 }
427
 }
426
 
428
 
427
 function keyserver_sync {
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
     dialog --backtitle $"Freedombone Control Panel" \
431
     dialog --backtitle $"Freedombone Control Panel" \
431
            --title $"Sync with other keyserver" \
432
            --title $"Sync with other keyserver" \
432
            --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
            --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
            $"Domain:" 1 1 "" 1 25 32 64 \
434
            $"Domain:" 1 1 "" 1 25 32 64 \
434
            $"Port:" 2 1 "11370" 2 25 6 6 \
435
            $"Port:" 2 1 "11370" 2 25 6 6 \
435
            $"Sync Email (optional):" 3 1 "pgp-public-keys@" 3 25 32 64 \
436
            $"Sync Email (optional):" 3 1 "pgp-public-keys@" 3 25 32 64 \
436
-           2> $data
437
+           2> "$data"
437
     sel=$?
438
     sel=$?
438
     case $sel in
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
     esac
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
     if [[ "$other_keyserver_domain" != *'.'* ]]; then
449
     if [[ "$other_keyserver_domain" != *'.'* ]]; then
446
         return
450
         return
447
     fi
451
     fi
464
     # Warn if trying to sync
468
     # Warn if trying to sync
465
     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
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
         dialog --title $"Sync with other keyserver" \
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
         return
472
         return
469
     fi
473
     fi
470
 
474
 
508
 }
512
 }
509
 
513
 
510
 function keyserver_remove_key {
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
     dialog --title $"Remove a key" \
516
     dialog --title $"Remove a key" \
514
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
519
     sel=$?
517
     case $sel in
520
     case $sel in
518
         0)
521
         0)
519
-            remove_key_id=$(<$data)
522
+            remove_key_id=$(<"$data")
520
             if [ ${#remove_key_id} -gt 8 ]; then
523
             if [ ${#remove_key_id} -gt 8 ]; then
521
-                sks drop $remove_key_id
524
+                sks drop "$remove_key_id"
522
                 dialog --title $"Remove a key" \
525
                 dialog --title $"Remove a key" \
523
                        --msgbox $"The key was removed" 6 40
526
                        --msgbox $"The key was removed" 6 40
524
             fi
527
             fi
525
             ;;
528
             ;;
526
     esac
529
     esac
530
+    rm -f "$data"
527
 }
531
 }
528
 
532
 
529
 function configure_interactive_keyserver {
533
 function configure_interactive_keyserver {
530
     while true
534
     while true
531
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
537
         dialog --backtitle $"Freedombone Control Panel" \
535
                --title $"SKS Keyserver" \
538
                --title $"SKS Keyserver" \
536
                --radiolist $"Choose an operation:" 12 70 4 \
539
                --radiolist $"Choose an operation:" 12 70 4 \
537
                1 $"Remove a key" off \
540
                1 $"Remove a key" off \
538
                2 $"Sync with other keyserver" off \
541
                2 $"Sync with other keyserver" off \
539
                3 $"Edit sync keyservers" off \
542
                3 $"Edit sync keyservers" off \
540
-               4 $"Exit" on 2> $data
543
+               4 $"Exit" on 2> "$data"
541
         sel=$?
544
         sel=$?
542
         case $sel in
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
         esac
550
         esac
546
-        case $(cat $data) in
551
+        case $(cat "$data") in
547
             1) keyserver_remove_key;;
552
             1) keyserver_remove_key;;
548
             2) keyserver_sync;;
553
             2) keyserver_sync;;
549
             3) keyserver_edit;;
554
             3) keyserver_edit;;
550
-            4) break;;
555
+            4) rm -f "$data"
556
+               break;;
551
         esac
557
         esac
558
+        rm -f "$data"
552
     done
559
     done
553
 }
560
 }
554
 
561
 
563
         mkdir /var/www/$KEYSERVER_DOMAIN_NAME
570
         mkdir /var/www/$KEYSERVER_DOMAIN_NAME
564
     fi
571
     fi
565
 
572
 
566
-    cd /var/www/$KEYSERVER_DOMAIN_NAME
573
+    cd "/var/www/$KEYSERVER_DOMAIN_NAME" || exit 25427642847
567
     if [ -d /var/www/$KEYSERVER_DOMAIN_NAME/htdocs ]; then
574
     if [ -d /var/www/$KEYSERVER_DOMAIN_NAME/htdocs ]; then
568
         rm -rf /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
575
         rm -rf /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
569
     fi
576
     fi
571
     if [ -d /repos/keyserverweb ]; then
578
     if [ -d /repos/keyserverweb ]; then
572
         mkdir htdocs
579
         mkdir htdocs
573
         cp -r -p /repos/keyserverweb/. htdocs
580
         cp -r -p /repos/keyserverweb/. htdocs
574
-        cd htdocs
581
+        cd htdocs || exit 379584659
575
         git pull
582
         git pull
576
     else
583
     else
577
         git_clone $KEYSERVER_WEB_REPO htdocs
584
         git_clone $KEYSERVER_WEB_REPO htdocs
581
         exit 6539230
588
         exit 6539230
582
     fi
589
     fi
583
 
590
 
584
-    cd /var/www/$KEYSERVER_DOMAIN_NAME/htdocs
591
+    cd "/var/www/$KEYSERVER_DOMAIN_NAME/htdocs" || exit 264824528
585
     git checkout $KEYSERVER_WEB_COMMIT -b $KEYSERVER_WEB_COMMIT
592
     git checkout $KEYSERVER_WEB_COMMIT -b $KEYSERVER_WEB_COMMIT
586
     set_completion_param "keyserver web commit" "$KEYSERVER_WEB_COMMIT"
593
     set_completion_param "keyserver web commit" "$KEYSERVER_WEB_COMMIT"
587
 
594
 
588
 
595
 
589
     USER_EMAIL_ADDRESS=$MY_USERNAME@$HOSTNAME
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
         echo $'No GPG ID for admin user'
599
         echo $'No GPG ID for admin user'
593
         exit 846336
600
         exit 846336
594
     fi
601
     fi
659
     chown debian-sks: $sksconf_file
666
     chown debian-sks: $sksconf_file
660
 
667
 
661
     if ! grep -q "hidden_service_sks" /etc/tor/torrc; then
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
         echo $'Added onion site for sks'
674
         echo $'Added onion site for sks'
668
     fi
675
     fi
669
 
676
 
682
     if [[ $ONION_ONLY == "no" ]]; then
689
     if [[ $ONION_ONLY == "no" ]]; then
683
         # NOTE: without http active on port 80 the keyserver doesn't work
690
         # NOTE: without http active on port 80 the keyserver doesn't work
684
         #       from the commandline
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
         function_check nginx_limits
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
         function_check nginx_ssl
742
         function_check nginx_ssl
736
         nginx_ssl $KEYSERVER_DOMAIN_NAME
743
         nginx_ssl $KEYSERVER_DOMAIN_NAME
737
 
744
 
738
         function_check nginx_disable_sniffing
745
         function_check nginx_disable_sniffing
739
         nginx_disable_sniffing $KEYSERVER_DOMAIN_NAME
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
         function_check nginx_limits
767
         function_check nginx_limits
761
         nginx_limits $KEYSERVER_DOMAIN_NAME '128k'
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
     else
781
     else
775
         echo -n '' > $keyserver_nginx_site
782
         echo -n '' > $keyserver_nginx_site
776
     fi
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
     function_check nginx_disable_sniffing
795
     function_check nginx_disable_sniffing
789
     nginx_disable_sniffing $KEYSERVER_DOMAIN_NAME
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
     function_check nginx_limits
814
     function_check nginx_limits
808
     nginx_limits $KEYSERVER_DOMAIN_NAME '128k'
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
     function_check create_site_certificate
828
     function_check create_site_certificate
822
     if [ ! -f /etc/ssl/certs/${KEYSERVER_DOMAIN_NAME}.pem ]; then
829
     if [ ! -f /etc/ssl/certs/${KEYSERVER_DOMAIN_NAME}.pem ]; then

+ 250
- 247
src/freedombone-app-koel 查看文件

58
 }
58
 }
59
 
59
 
60
 function koel_remove_gravatar {
60
 function koel_remove_gravatar {
61
-    cd /var/www/${KOEL_DOMAIN_NAME}/htdocs
61
+    cd "/var/www/${KOEL_DOMAIN_NAME}/htdocs" || exit 8345374534
62
     sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" node_modules/browser-sync-ui/public/js/app.js.map
62
     sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" node_modules/browser-sync-ui/public/js/app.js.map
63
     sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" public/js/app.*.js
63
     sed -i "s|www.gravatar.com|${KOEL_DOMAIN_NAME}|g" public/js/app.*.js
64
     if ! grep -q "//Vue.set(user, 'avatar'" resources/assets/js/stores/user.js; then
64
     if ! grep -q "//Vue.set(user, 'avatar'" resources/assets/js/stores/user.js; then
69
 function remove_user_koel {
69
 function remove_user_koel {
70
     remove_username="$1"
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
 function add_user_koel {
75
 function add_user_koel {
76
     new_username="$1"
76
     new_username="$1"
77
     new_user_password="$2"
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
     echo '0'
80
     echo '0'
81
 }
81
 }
82
 
82
 
83
 function install_interactive_koel {
83
 function install_interactive_koel {
84
-    if [ ! $ONION_ONLY ]; then
84
+    if [ ! "$ONION_ONLY" ]; then
85
         ONION_ONLY='no'
85
         ONION_ONLY='no'
86
     fi
86
     fi
87
 
87
 
91
         KOEL_DETAILS_COMPLETE=
91
         KOEL_DETAILS_COMPLETE=
92
         while [ ! $KOEL_DETAILS_COMPLETE ]
92
         while [ ! $KOEL_DETAILS_COMPLETE ]
93
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
95
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
97
                 dialog --backtitle $"Freedombone Configuration" \
96
                 dialog --backtitle $"Freedombone Configuration" \
98
                        --title $"Koel Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
99
                        $"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
101
                        $"Code:" 2 1 "$(grep 'KOEL_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
100
                        $"Code:" 2 1 "$(grep 'KOEL_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
102
-                       2> $data
101
+                       2> "$data"
103
             else
102
             else
104
                 dialog --backtitle $"Freedombone Configuration" \
103
                 dialog --backtitle $"Freedombone Configuration" \
105
                        --title $"Koel Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
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
             fi
108
             fi
110
             sel=$?
109
             sel=$?
111
             case $sel in
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
             esac
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
                     KOEL_DOMAIN_NAME=""
119
                     KOEL_DOMAIN_NAME=""
119
                 fi
120
                 fi
120
                 TEST_DOMAIN_NAME=$KOEL_DOMAIN_NAME
121
                 TEST_DOMAIN_NAME=$KOEL_DOMAIN_NAME
121
                 validate_domain_name
122
                 validate_domain_name
122
-                if [[ $TEST_DOMAIN_NAME != $KOEL_DOMAIN_NAME ]]; then
123
+                if [[ "$TEST_DOMAIN_NAME" != "$KOEL_DOMAIN_NAME" ]]; then
123
                     KOEL_DOMAIN_NAME=
124
                     KOEL_DOMAIN_NAME=
124
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
125
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
125
                 else
126
                 else
126
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$KOEL_CODE"
129
                         validate_freedns_code "$KOEL_CODE"
129
-                        if [ ! $VALID_CODE ]; then
130
+                        if [ ! "$VALID_CODE" ]; then
130
                             KOEL_DOMAIN_NAME=
131
                             KOEL_DOMAIN_NAME=
131
                         fi
132
                         fi
132
                     fi
133
                     fi
135
             if [ $KOEL_DOMAIN_NAME ]; then
136
             if [ $KOEL_DOMAIN_NAME ]; then
136
                 KOEL_DETAILS_COMPLETE="yes"
137
                 KOEL_DETAILS_COMPLETE="yes"
137
             fi
138
             fi
139
+            rm -f "$data"
138
         done
140
         done
139
 
141
 
140
         # save the results in the config file
142
         # save the results in the config file
150
 
152
 
151
     read_config_param 'KOEL_DOMAIN_NAME'
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
 function koel_create_database {
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
     else
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
         fi
164
         fi
163
     fi
165
     fi
164
-    if [ ! $KOEL_ADMIN_PASSWORD ]; then
166
+    if [ ! "$KOEL_ADMIN_PASSWORD" ]; then
165
         return
167
         return
166
     fi
168
     fi
167
 
169
 
168
     function_check create_database
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
 function reconfigure_koel {
174
 function reconfigure_koel {
174
 }
176
 }
175
 
177
 
176
 function koel_import_from_directory {
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
     if [[ "$selected_dir" == '/music' ]]; then
183
     if [[ "$selected_dir" == '/music' ]]; then
182
         return
184
         return
183
     fi
185
     fi
184
-    if [ ! -d $selected_dir ]; then
186
+    if [ ! -d "$selected_dir" ]; then
185
         return
187
         return
186
     fi
188
     fi
187
     if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
189
     if [[ "$selected_dir" == "/home/$MY_USERNAME/" ]]; then
197
     dialog --title $"Import music directory" \
199
     dialog --title $"Import music directory" \
198
            --backtitle $"Freedombone Control Panel" \
200
            --backtitle $"Freedombone Control Panel" \
199
            --defaultno \
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
     sel=$?
203
     sel=$?
202
     case $sel in
204
     case $sel in
203
         1) return;;
205
         1) return;;
214
     clear
216
     clear
215
     detect_usb_drive
217
     detect_usb_drive
216
 
218
 
217
-    if [ ! -b $USB_DRIVE ]; then
219
+    if [ ! -b "$USB_DRIVE" ]; then
218
         dialog --title $"Import music from USB drive" --msgbox $'No USB drive found' 6 50
220
         dialog --title $"Import music from USB drive" --msgbox $'No USB drive found' 6 50
219
         return
221
         return
220
     fi
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
         dialog --title $"Import music from USB drive" --msgbox $'No Music directory found on USB drive' 6 50
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
     fi
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
     dialog --title $"Import music from USB drive" --msgbox $'Import complete. You may now remove the USB drive' 6 50
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
     clear
235
     clear
234
     detect_usb_drive
236
     detect_usb_drive
235
 
237
 
236
-    if [ ! -b $USB_DRIVE ]; then
238
+    if [ ! -b "$USB_DRIVE" ]; then
237
         dialog --title $"Export music to USB drive" --msgbox $'No USB drive found' 6 50
239
         dialog --title $"Export music to USB drive" --msgbox $'No USB drive found' 6 50
238
         return
240
         return
239
     fi
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
     fi
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
     dialog --title $"Export music to USB drive" --msgbox $'Export complete. You may now remove the USB drive' 6 50
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
 function format_music_drive {
252
 function format_music_drive {
251
     detect_usb_drive
253
     detect_usb_drive
252
-    data=$(tempfile 2>/dev/null)
253
-    trap "rm -f $data" 0 1 2 5 15
254
     dialog --title $"Format USB drive $USB_DRIVE for music storage" \
254
     dialog --title $"Format USB drive $USB_DRIVE for music storage" \
255
            --backtitle $"Freedombone Control Panel" \
255
            --backtitle $"Freedombone Control Panel" \
256
            --defaultno \
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
     sel=$?
258
     sel=$?
259
     case $sel in
259
     case $sel in
260
         1) return;;
260
         1) return;;
265
     echo ''
265
     echo ''
266
     echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
266
     echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
267
     echo ''
267
     echo ''
268
-    ${PROJECT_NAME}-format $USB_DRIVE
268
+    "${PROJECT_NAME}-format" "$USB_DRIVE"
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
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
 function configure_interactive_koel {
273
 function configure_interactive_koel {
274
     while true
274
     while true
275
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
277
         dialog --backtitle $"Freedombone Control Panel" \
279
                --title $"Koel" \
278
                --title $"Koel" \
280
                --radiolist $"Choose an operation:" 12 70 5 \
279
                --radiolist $"Choose an operation:" 12 70 5 \
282
                2 $"Import music from USB drive" off \
281
                2 $"Import music from USB drive" off \
283
                3 $"Export music to USB drive" off \
282
                3 $"Export music to USB drive" off \
284
                4 $"Format a USB drive for music storage" off \
283
                4 $"Format a USB drive for music storage" off \
285
-               5 $"Exit" on 2> $data
284
+               5 $"Exit" on 2> "$data"
286
         sel=$?
285
         sel=$?
287
         case $sel in
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
         esac
291
         esac
291
-        case $(cat $data) in
292
+        case $(cat "$data") in
292
             1) koel_import_from_directory;;
293
             1) koel_import_from_directory;;
293
             2) koel_import_from_usb;;
294
             2) koel_import_from_usb;;
294
             3) koel_export_to_usb;;
295
             3) koel_export_to_usb;;
295
             4) format_music_drive;;
296
             4) format_music_drive;;
296
-            5) break;;
297
+            5) rm -f "$data"
298
+               break;;
297
         esac
299
         esac
300
+        rm -f "$data"
298
     done
301
     done
299
 }
302
 }
300
 
303
 
301
 function upgrade_koel {
304
 function upgrade_koel {
302
-    if grep -q "koel domain" $COMPLETION_FILE; then
305
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
303
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
306
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
304
     fi
307
     fi
305
 
308
 
312
 
315
 
313
     # update to the next commit
316
     # update to the next commit
314
     function_check set_repo_commit
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
     php artisan koel:init
321
     php artisan koel:init
319
     koel_remove_gravatar
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
     systemctl start koel
325
     systemctl start koel
323
 }
326
 }
325
 
328
 
326
 function backup_local_koel {
329
 function backup_local_koel {
327
     KOEL_DOMAIN_NAME='koel'
330
     KOEL_DOMAIN_NAME='koel'
328
-    if grep -q "koel domain" $COMPLETION_FILE; then
331
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
329
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
332
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
330
     fi
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
         systemctl stop koel
337
         systemctl stop koel
335
 
338
 
336
         dest_directory=koel
339
         dest_directory=koel
337
         function_check suspend_site
340
         function_check suspend_site
338
-        suspend_site ${KOEL_DOMAIN_NAME}
341
+        suspend_site "${KOEL_DOMAIN_NAME}"
339
 
342
 
340
         function_check backup_directory_to_usb
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
         function_check backup_database_to_usb
346
         function_check backup_database_to_usb
344
         backup_database_to_usb koel
347
         backup_database_to_usb koel
351
 }
354
 }
352
 
355
 
353
 function restore_local_koel {
356
 function restore_local_koel {
354
-    if ! grep -q "koel domain" $COMPLETION_FILE; then
357
+    if ! grep -q "koel domain" "$COMPLETION_FILE"; then
355
         return
358
         return
356
     fi
359
     fi
357
     KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
360
     KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
358
-    if [ $KOEL_DOMAIN_NAME ]; then
361
+    if [ "$KOEL_DOMAIN_NAME" ]; then
359
         echo $"Restoring koel"
362
         echo $"Restoring koel"
360
         systemctl stop koel
363
         systemctl stop koel
361
 
364
 
362
         temp_restore_dir=/root/tempkoel
365
         temp_restore_dir=/root/tempkoel
363
-        koel_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
364
 
366
 
365
         function_check koel_create_database
367
         function_check koel_create_database
366
         koel_create_database
368
         koel_create_database
367
 
369
 
368
-        restore_database koel ${KOEL_DOMAIN_NAME}
370
+        restore_database koel "${KOEL_DOMAIN_NAME}"
369
         if [ -d $temp_restore_dir ]; then
371
         if [ -d $temp_restore_dir ]; then
370
             rm -rf $temp_restore_dir
372
             rm -rf $temp_restore_dir
371
         fi
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
         sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
377
         sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
376
         MARIADB_PASSWORD=
378
         MARIADB_PASSWORD=
377
 
379
 
380
 }
382
 }
381
 
383
 
382
 function backup_remote_koel {
384
 function backup_remote_koel {
383
-    if grep -q "koel domain" $COMPLETION_FILE; then
385
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
384
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
386
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
385
         temp_backup_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
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
             systemctl stop koel
389
             systemctl stop koel
388
 
390
 
389
             function_check suspend_site
391
             function_check suspend_site
390
-            suspend_site ${KOEL_DOMAIN_NAME}
392
+            suspend_site "${KOEL_DOMAIN_NAME}"
391
 
393
 
392
             function_check backup_database_to_friend
394
             function_check backup_database_to_friend
393
             backup_database_to_friend koel
395
             backup_database_to_friend koel
395
             echo $"Backing up Koel installation"
397
             echo $"Backing up Koel installation"
396
 
398
 
397
             function_check backup_directory_to_friend
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
             function_check restart_site
402
             function_check restart_site
401
             restart_site
403
             restart_site
408
 }
410
 }
409
 
411
 
410
 function restore_remote_koel {
412
 function restore_remote_koel {
411
-    if grep -q "koel domain" $COMPLETION_FILE; then
413
+    if grep -q "koel domain" "$COMPLETION_FILE"; then
412
         echo $"Restoring koel"
414
         echo $"Restoring koel"
413
 
415
 
414
         systemctl stop koel
416
         systemctl stop koel
419
         koel_create_database
421
         koel_create_database
420
 
422
 
421
         function_check restore_database_from_friend
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
         if [ -d /root/tempkoel ]; then
425
         if [ -d /root/tempkoel ]; then
424
             rm -rf /root/tempkoel
426
             rm -rf /root/tempkoel
425
         fi
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
         sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
431
         sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$MARIADB_PASSWORD|g" .env
430
         MARIADB_PASSWORD=
432
         MARIADB_PASSWORD=
431
 
433
 
453
     read_config_param "KOEL_DOMAIN_NAME"
455
     read_config_param "KOEL_DOMAIN_NAME"
454
     read_config_param "MY_USERNAME"
456
     read_config_param "MY_USERNAME"
455
     echo "Removing $KOEL_DOMAIN_NAME"
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
     fi
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
     fi
466
     fi
465
     function_check drop_database
467
     function_check drop_database
466
     drop_database koel
468
     drop_database koel
468
     remove_onion_service koel ${KOEL_ONION_PORT}
470
     remove_onion_service koel ${KOEL_ONION_PORT}
469
     remove_app koel
471
     remove_app koel
470
     remove_completion_param install_koel
472
     remove_completion_param install_koel
471
-    sed -i '/koel/d' $COMPLETION_FILE
473
+    sed -i '/koel/d' "$COMPLETION_FILE"
472
     remove_backup_database_local koel
474
     remove_backup_database_local koel
473
 
475
 
474
     function_check remove_ddns_domain
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
 function install_koel_main {
480
 function install_koel_main {
479
-    if [ ! $KOEL_DOMAIN_NAME ]; then
481
+    if [ ! "$KOEL_DOMAIN_NAME" ]; then
480
         echo $'No domain name was given for koel'
482
         echo $'No domain name was given for koel'
481
         exit 7359
483
         exit 7359
482
     fi
484
     fi
498
     apt-get -yq install php-memcached php-intl exiftool libfcgi0ldbl
500
     apt-get -yq install php-memcached php-intl exiftool libfcgi0ldbl
499
     apt-get -yq install ffmpeg
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
     fi
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
         if [ -d /repos/koel ]; then
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
             git pull
512
             git pull
511
         else
513
         else
512
             function_check git_clone
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
         fi
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
             echo $'Unable to clone koel repo'
519
             echo $'Unable to clone koel repo'
518
             exit 365735
520
             exit 365735
519
         fi
521
         fi
520
     fi
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
     set_completion_param "koel commit" "$KOEL_COMMIT"
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
     function_check koel_create_database
530
     function_check koel_create_database
529
     koel_create_database
531
     koel_create_database
530
 
532
 
531
     function_check add_ddns_domain
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
     koel_nginx_site=/etc/nginx/sites-available/$KOEL_DOMAIN_NAME
538
     koel_nginx_site=/etc/nginx/sites-available/$KOEL_DOMAIN_NAME
535
     if [[ $ONION_ONLY == "no" ]]; then
539
     if [[ $ONION_ONLY == "no" ]]; then
536
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl mobile
552
         function_check nginx_ssl mobile
549
-        nginx_ssl $KOEL_DOMAIN_NAME
553
+        nginx_ssl "$KOEL_DOMAIN_NAME"
550
 
554
 
551
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
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
     fi
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
     function_check nginx_compress
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
     function_check nginx_limits
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
     function_check configure_php
678
     function_check configure_php
668
     configure_php
679
     configure_php
669
 
680
 
670
     function_check create_site_certificate
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
     # Ensure that the database gets backed up locally, if remote
684
     # Ensure that the database gets backed up locally, if remote
674
     # backups are not being used
685
     # backups are not being used
679
     backup_database_local koel
690
     backup_database_local koel
680
 
691
 
681
     function_check nginx_ensite
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
     systemctl restart mariadb
695
     systemctl restart mariadb
692
     systemctl restart php7.0-fpm
696
     systemctl restart php7.0-fpm
693
     systemctl restart nginx
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
     set_completion_param "koel domain" "$KOEL_DOMAIN_NAME"
701
     set_completion_param "koel domain" "$KOEL_DOMAIN_NAME"
698
 
702
 
709
 
713
 
710
     install_koel_main
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
     install_composer
717
     install_composer
714
 
718
 
715
     npm install -g yarn
719
     npm install -g yarn
731
     sed -i 's/MAIL_PORT=.*/MAIL_PORT=25/g' .env
735
     sed -i 's/MAIL_PORT=.*/MAIL_PORT=25/g' .env
732
     sed -i 's|FFMPEG_PATH=.*|FFMPEG_PATH=/usr/bin/ffmpeg|g' .env
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
         echo $"Can't install koel:init"
739
         echo $"Can't install koel:init"
737
         exit 78362
740
         exit 78362
738
     fi
741
     fi
739
     koel_remove_gravatar
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
     # daemon
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
     systemctl enable koel.service
761
     systemctl enable koel.service
759
     systemctl daemon-reload
762
     systemctl daemon-reload
760
     systemctl start koel.service
763
     systemctl start koel.service

+ 184
- 184
src/freedombone-app-lychee 查看文件

55
 }
55
 }
56
 
56
 
57
 function lychee_create_database {
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
     else
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
         fi
63
         fi
64
     fi
64
     fi
65
-    if [ ! $LYCHEE_ADMIN_PASSWORD ]; then
65
+    if [ ! "$LYCHEE_ADMIN_PASSWORD" ]; then
66
         return
66
         return
67
     fi
67
     fi
68
 
68
 
73
 function remove_user_lychee {
73
 function remove_user_lychee {
74
     remove_username="$1"
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
 function add_user_lychee {
79
 function add_user_lychee {
85
     new_username="$1"
85
     new_username="$1"
86
     new_user_password="$2"
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
     echo '0'
90
     echo '0'
91
 }
91
 }
92
 
92
 
93
 function install_interactive_lychee {
93
 function install_interactive_lychee {
94
-    if [ ! $ONION_ONLY ]; then
94
+    if [ ! "$ONION_ONLY" ]; then
95
         ONION_ONLY='no'
95
         ONION_ONLY='no'
96
     fi
96
     fi
97
 
97
 
110
     get_mariadb_password
110
     get_mariadb_password
111
 
111
 
112
     dialog --title $"Lychee Configuration" \
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
 function change_password_lychee {
117
 function change_password_lychee {
118
-    LYCHEE_USERNAME="$1"
118
+#    LYCHEE_USERNAME="$1"
119
     LYCHEE_PASSWORD="$2"
119
     LYCHEE_PASSWORD="$2"
120
     if [ ${#LYCHEE_PASSWORD} -lt 8 ]; then
120
     if [ ${#LYCHEE_PASSWORD} -lt 8 ]; then
121
         echo $'Lychee password is too short'
121
         echo $'Lychee password is too short'
143
 
143
 
144
 function backup_local_lychee {
144
 function backup_local_lychee {
145
     LYCHEE_DOMAIN_NAME='lychee.local'
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
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
147
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
148
     fi
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
         function_check backup_database_to_usb
152
         function_check backup_database_to_usb
153
         backup_database_to_usb lychee
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
         restart_site
156
         restart_site
157
     fi
157
     fi
158
 }
158
 }
159
 
159
 
160
 function restore_local_lychee {
160
 function restore_local_lychee {
161
     LYCHEE_DOMAIN_NAME='lychee.local'
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
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
163
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
164
     fi
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
         function_check lychee_create_database
168
         function_check lychee_create_database
169
         lychee_create_database
169
         lychee_create_database
170
 
170
 
171
         function_check restore_database
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
             MARIADB_PASSWORD=
177
             MARIADB_PASSWORD=
178
         fi
178
         fi
179
 
179
 
180
         restart_site
180
         restart_site
181
-        chown -R lychee: /var/www/$LYCHEE_DOMAIN_NAME/htdocs/
181
+        chown -R lychee: "/var/www/$LYCHEE_DOMAIN_NAME/htdocs/"
182
     fi
182
     fi
183
 }
183
 }
184
 
184
 
185
 function backup_remote_lychee {
185
 function backup_remote_lychee {
186
     LYCHEE_DOMAIN_NAME='lychee.local'
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
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
188
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
189
     fi
189
     fi
190
 
190
 
191
     temp_backup_dir=/var/www/${LYCHEE_DOMAIN_NAME}/htdocs
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
         backup_database_to_friend lychee
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
         restart_site
196
         restart_site
197
     else
197
     else
198
         echo $"Lychee domain specified but not found in /var/www/${LYCHEE_DOMAIN_NAME}"
198
         echo $"Lychee domain specified but not found in /var/www/${LYCHEE_DOMAIN_NAME}"
202
 
202
 
203
 function restore_remote_lychee {
203
 function restore_remote_lychee {
204
     LYCHEE_DOMAIN_NAME='lychee.local'
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
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
206
         LYCHEE_DOMAIN_NAME=$(get_completion_param "lychee domain")
207
     fi
207
     fi
208
 
208
 
209
-    suspend_site ${LYCHEE_DOMAIN_NAME}
209
+    suspend_site "${LYCHEE_DOMAIN_NAME}"
210
 
210
 
211
     function_check restore_database_from_friend
211
     function_check restore_database_from_friend
212
 
212
 
213
     function_check lychee_create_database
213
     function_check lychee_create_database
214
     lychee_create_database
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
         MARIADB_PASSWORD=
221
         MARIADB_PASSWORD=
222
     fi
222
     fi
223
 
223
 
224
     restart_site
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
 function remove_lychee {
228
 function remove_lychee {
231
     fi
231
     fi
232
 
232
 
233
     read_config_param "LYCHEE_DOMAIN_NAME"
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
     drop_database lychee
237
     drop_database lychee
238
     remove_backup_database_local lychee
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
     fi
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
     fi
245
     fi
246
     remove_config_param LYCHEE_DOMAIN_NAME
246
     remove_config_param LYCHEE_DOMAIN_NAME
247
     remove_config_param LYCHEE_CODE
247
     remove_config_param LYCHEE_CODE
248
     function_check remove_onion_service
248
     function_check remove_onion_service
249
-    remove_onion_service lychee ${LYCHEE_ONION_PORT}
249
+    remove_onion_service lychee "${LYCHEE_ONION_PORT}"
250
     remove_completion_param "install_lychee"
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
     function_check remove_ddns_domain
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
 function install_lychee_website {
258
 function install_lychee_website {
259
     function_check nginx_http_redirect
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
     function_check nginx_ssl
271
     function_check nginx_ssl
272
-    nginx_ssl $LYCHEE_DOMAIN_NAME
272
+    nginx_ssl "$LYCHEE_DOMAIN_NAME"
273
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
 function install_lychee_website_onion {
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check nginx_limits
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
 function install_lychee_from_repo {
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
     fi
394
     fi
395
 
395
 
396
-    cd /var/www/$LYCHEE_DOMAIN_NAME
396
+    cd "/var/www/$LYCHEE_DOMAIN_NAME" || exit 682468246
397
 
397
 
398
     if [ -d /repos/lychee ]; then
398
     if [ -d /repos/lychee ]; then
399
         mkdir htdocs
399
         mkdir htdocs
400
         cp -r -p /repos/lychee/. htdocs
400
         cp -r -p /repos/lychee/. htdocs
401
-        cd htdocs
401
+        cd htdocs || exit 963756345
402
         git pull
402
         git pull
403
     else
403
     else
404
-        git_clone $LYCHEE_REPO htdocs
404
+        git_clone "$LYCHEE_REPO" htdocs
405
     fi
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
     set_completion_param "lychee commit" "$LYCHEE_COMMIT"
409
     set_completion_param "lychee commit" "$LYCHEE_COMMIT"
410
 }
410
 }
411
 
411
 
414
         ONION_ONLY='no'
414
         ONION_ONLY='no'
415
     fi
415
     fi
416
 
416
 
417
-    if [ ! $LYCHEE_DOMAIN_NAME ]; then
417
+    if [ ! "$LYCHEE_DOMAIN_NAME" ]; then
418
         echo $'The lychee domain name was not specified'
418
         echo $'The lychee domain name was not specified'
419
         exit 543672
419
         exit 543672
420
     fi
420
     fi
429
         function_check install_lychee_website
429
         function_check install_lychee_website
430
         install_lychee_website
430
         install_lychee_website
431
     else
431
     else
432
-        echo -n '' > /etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME
432
+        echo -n '' > "/etc/nginx/sites-available/$LYCHEE_DOMAIN_NAME"
433
     fi
433
     fi
434
 
434
 
435
     LYCHEE_ONION_HOSTNAME=$(add_onion_service lychee 80 ${LYCHEE_ONION_PORT})
435
     LYCHEE_ONION_HOSTNAME=$(add_onion_service lychee 80 ${LYCHEE_ONION_PORT})
438
     install_lychee_website_onion
438
     install_lychee_website_onion
439
 
439
 
440
     function_check create_site_certificate
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
     function_check configure_php
443
     function_check configure_php
444
     configure_php
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
     function_check nginx_ensite
456
     function_check nginx_ensite
457
-    nginx_ensite $LYCHEE_DOMAIN_NAME
457
+    nginx_ensite "$LYCHEE_DOMAIN_NAME"
458
 
458
 
459
     function_check install_mariadb
459
     function_check install_mariadb
460
     install_mariadb
460
     install_mariadb
469
     systemctl restart php7.0-fpm
469
     systemctl restart php7.0-fpm
470
     systemctl restart nginx
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
     function_check add_ddns_domain
474
     function_check add_ddns_domain
475
-    add_ddns_domain $LYCHEE_DOMAIN_NAME
475
+    add_ddns_domain "$LYCHEE_DOMAIN_NAME"
476
 
476
 
477
     set_completion_param "lychee domain" "$LYCHEE_DOMAIN_NAME"
477
     set_completion_param "lychee domain" "$LYCHEE_DOMAIN_NAME"
478
     APP_INSTALLED=1
478
     APP_INSTALLED=1

+ 86
- 86
src/freedombone-app-mailpile 查看文件

58
 
58
 
59
 function remove_user_mailpile {
59
 function remove_user_mailpile {
60
     remove_username="$1"
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
 function add_user_mailpile {
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
 function install_interactive_mailpile {
68
 function install_interactive_mailpile {
69
-    if [ ! $ONION_ONLY ]; then
69
+    if [ ! "$ONION_ONLY" ]; then
70
         ONION_ONLY='no'
70
         ONION_ONLY='no'
71
     fi
71
     fi
72
 
72
 
93
     read_config_param "MAILPILE_DOMAIN_NAME"
93
     read_config_param "MAILPILE_DOMAIN_NAME"
94
 
94
 
95
     CURR_COMMIT=$MAILPILE_COMMIT
95
     CURR_COMMIT=$MAILPILE_COMMIT
96
-    if grep -q "mailpile commit" $COMPLETION_FILE; then
96
+    if grep -q "mailpile commit" "$COMPLETION_FILE"; then
97
         CURR_COMMIT=$(get_completion_param "mailpile commit")
97
         CURR_COMMIT=$(get_completion_param "mailpile commit")
98
     fi
98
     fi
99
     if [[ "$CURR_COMMIT" == "$MAILPILE_COMMIT" ]]; then
99
     if [[ "$CURR_COMMIT" == "$MAILPILE_COMMIT" ]]; then
103
     function_check set_repo_commit
103
     function_check set_repo_commit
104
     set_repo_commit /var/www/$MAILPILE_DOMAIN_NAME/mail "mailpile commit" "$MAILPILE_COMMIT" $MAILPILE_REPO
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
     pip install -r requirements.txt
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
 function backup_local_mailpile {
112
 function backup_local_mailpile {
136
     systemctl daemon-reload
136
     systemctl daemon-reload
137
 
137
 
138
     read_config_param "MAILPILE_DOMAIN_NAME"
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
     fi
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
     fi
146
     fi
147
     function_check remove_ddns_domain
147
     function_check remove_ddns_domain
148
-    remove_ddns_domain $MAILPILE_DOMAIN_NAME
148
+    remove_ddns_domain "$MAILPILE_DOMAIN_NAME"
149
 
149
 
150
     groupdel -f mailpile
150
     groupdel -f mailpile
151
     userdel -r mailpile
151
     userdel -r mailpile
158
 
158
 
159
     enable_email_encryption_at_rest
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
 function install_mailpile {
165
 function install_mailpile {
178
         mkdir /var/www/$MAILPILE_DOMAIN_NAME
178
         mkdir /var/www/$MAILPILE_DOMAIN_NAME
179
     fi
179
     fi
180
 
180
 
181
-    cd /var/www/$MAILPILE_DOMAIN_NAME
181
+    cd "/var/www/$MAILPILE_DOMAIN_NAME" || exit 264826484
182
     if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail ]; then
182
     if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail ]; then
183
         rm -rf /var/www/$MAILPILE_DOMAIN_NAME/mail
183
         rm -rf /var/www/$MAILPILE_DOMAIN_NAME/mail
184
     fi
184
     fi
186
     if [ -d /repos/mailpile ]; then
186
     if [ -d /repos/mailpile ]; then
187
         mkdir mail
187
         mkdir mail
188
         cp -r -p /repos/mailpile/. mail
188
         cp -r -p /repos/mailpile/. mail
189
-        cd mail
189
+        cd mail || exit 245728482
190
         git pull
190
         git pull
191
     else
191
     else
192
         git_clone $MAILPILE_REPO mail
192
         git_clone $MAILPILE_REPO mail
193
     fi
193
     fi
194
 
194
 
195
-    cd mail
195
+    cd mail || exit 246872468
196
     git checkout $MAILPILE_COMMIT -b $MAILPILE_COMMIT
196
     git checkout $MAILPILE_COMMIT -b $MAILPILE_COMMIT
197
     set_completion_param "mailpile commit" "$MAILPILE_COMMIT"
197
     set_completion_param "mailpile commit" "$MAILPILE_COMMIT"
198
 
198
 
206
     adduser mailpile debian-tor
206
     adduser mailpile debian-tor
207
     adduser mailpile www-data
207
     adduser mailpile www-data
208
     adduser mailpile mail
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
         chgrp -R ssl-cert /etc/letsencrypt
211
         chgrp -R ssl-cert /etc/letsencrypt
212
         chmod -R g=rX /etc/letsencrypt
212
         chmod -R g=rX /etc/letsencrypt
213
         usermod -a -G ssl-cert mailpile
213
         usermod -a -G ssl-cert mailpile
219
 
219
 
220
     MAILPILE_ONION_HOSTNAME=$(add_onion_service mailpile 80 ${MAILPILE_ONION_PORT})
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
     chmod +x /etc/systemd/system/mailpile.service
236
     chmod +x /etc/systemd/system/mailpile.service
237
 
237
 
238
     mailpile_nginx_site=/etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
238
     mailpile_nginx_site=/etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
239
     if [[ $ONION_ONLY == "no" ]]; then
239
     if [[ $ONION_ONLY == "no" ]]; then
240
         function_check nginx_http_redirect
240
         function_check nginx_http_redirect
241
         nginx_http_redirect $MAILPILE_DOMAIN_NAME
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
         function_check nginx_ssl
248
         function_check nginx_ssl
249
         nginx_ssl $MAILPILE_DOMAIN_NAME
249
         nginx_ssl $MAILPILE_DOMAIN_NAME
250
 
250
 
251
         function_check nginx_disable_sniffing
251
         function_check nginx_disable_sniffing
252
         nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
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
         function_check nginx_limits
264
         function_check nginx_limits
265
         nginx_limits $MAILPILE_DOMAIN_NAME '15m'
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
     else
276
     else
277
         echo -n '' > $mailpile_nginx_site
277
         echo -n '' > $mailpile_nginx_site
278
     fi
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
     function_check nginx_disable_sniffing
283
     function_check nginx_disable_sniffing
284
     nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
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
     function_check nginx_limits
294
     function_check nginx_limits
295
     nginx_limits $MAILPILE_DOMAIN_NAME '15m'
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
     function_check create_site_certificate
306
     function_check create_site_certificate
307
     if [ ! -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem ]; then
307
     if [ ! -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem ]; then
322
     function_check nginx_ensite
322
     function_check nginx_ensite
323
     nginx_ensite $MAILPILE_DOMAIN_NAME
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
     function_check add_ddns_domain
327
     function_check add_ddns_domain
328
     add_ddns_domain $MAILPILE_DOMAIN_NAME
328
     add_ddns_domain $MAILPILE_DOMAIN_NAME
336
     if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg ]; then
336
     if [ -d /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg ]; then
337
         mv /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg_orig
337
         mv /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg_orig
338
     fi
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
     chown -R mailpile:mailpile /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
340
     chown -R mailpile:mailpile /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
341
     chmod +x /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
341
     chmod +x /var/www/$MAILPILE_DOMAIN_NAME/mail/.gnupg
342
 
342
 
348
     sed -i 's|ssl =.*|ssl = no|g' /etc/dovecot/conf.d/10-ssl.conf
348
     sed -i 's|ssl =.*|ssl = no|g' /etc/dovecot/conf.d/10-ssl.conf
349
 
349
 
350
     # set ssl certs, just in case we want to use them later
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
             sed -i "s|#ssl_cert =.*|ssl_cert = </etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem|g" /etc/dovecot/conf.d/10-ssl.conf
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
             sed -i "s|ssl_cert =.*|ssl_cert = </etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem|g" /etc/dovecot/conf.d/10-ssl.conf
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
             sed -i "s|#ssl_key =.*|ssl_key = </etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/privkey.pem|g" /etc/dovecot/conf.d/10-ssl.conf
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
     read_config_param MATRIX_PORT
71
     read_config_param MATRIX_PORT
72
 
72
 
73
     matrix_remove_posts=/usr/bin/matrix-remove
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
     chmod +x $matrix_remove_posts
90
     chmod +x $matrix_remove_posts
91
 }
91
 }
127
 function matrix_nginx {
127
 function matrix_nginx {
128
     matrix_nginx_site=/etc/nginx/sites-available/$MATRIX_DOMAIN_NAME
128
     matrix_nginx_site=/etc/nginx/sites-available/$MATRIX_DOMAIN_NAME
129
     if [[ $ONION_ONLY == "no" ]]; then
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
         function_check nginx_ssl
135
         function_check nginx_ssl
136
         nginx_ssl ${MATRIX_DOMAIN_NAME}
136
         nginx_ssl ${MATRIX_DOMAIN_NAME}
137
 
137
 
138
         function_check nginx_disable_sniffing
138
         function_check nginx_disable_sniffing
139
         nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
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
         function_check nginx_limits
153
         function_check nginx_limits
154
         nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
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
         function_check nginx_ssl
164
         function_check nginx_ssl
165
         nginx_ssl ${MATRIX_DOMAIN_NAME}
165
         nginx_ssl ${MATRIX_DOMAIN_NAME}
166
 
166
 
167
         function_check nginx_disable_sniffing
167
         function_check nginx_disable_sniffing
168
         nginx_disable_sniffing ${MATRIX_DOMAIN_NAME}
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
         function_check nginx_limits
183
         function_check nginx_limits
184
         nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
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
     else
189
     else
190
         echo -n '' > $matrix_nginx_site
190
         echo -n '' > $matrix_nginx_site
191
     fi
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
     function_check nginx_disable_sniffing
196
     function_check nginx_disable_sniffing
197
     nginx_disable_sniffing $MATRIX_DOMAIN_NAME
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
     function_check nginx_limits
207
     function_check nginx_limits
208
     nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
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
     function_check nginx_disable_sniffing
217
     function_check nginx_disable_sniffing
218
     nginx_disable_sniffing $MATRIX_DOMAIN_NAME
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
     function_check nginx_limits
228
     function_check nginx_limits
229
     nginx_limits ${MATRIX_DOMAIN_NAME} '15m'
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
     if [ ! -d /var/www/$MATRIX_DOMAIN_NAME ]; then
234
     if [ ! -d /var/www/$MATRIX_DOMAIN_NAME ]; then
235
         mkdir -p /var/www/$MATRIX_DOMAIN_NAME/htdocs
235
         mkdir -p /var/www/$MATRIX_DOMAIN_NAME/htdocs
242
 function matrix_generate_homeserver_file {
242
 function matrix_generate_homeserver_file {
243
     local filepath="${1}"
243
     local filepath="${1}"
244
 
244
 
245
-    cd /etc/matrix
245
+    cd /etc/matrix || exit 468246824
246
     python -m synapse.app.homeserver \
246
     python -m synapse.app.homeserver \
247
            --config-path "${filepath}" \
247
            --config-path "${filepath}" \
248
            --generate-config \
248
            --generate-config \
251
 }
251
 }
252
 
252
 
253
 function matrix_configure_homeserver_yaml {
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
     awk -v TURNURIES="turn_uris: [\"turn:${MATRIX_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=udp\", \"turn:${DEFAULT_DOMAIN_NAME}:${TURN_HTTP_PORT}?transport=tcp\"]" \
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
         -v TURNSHAREDSECRET="turn_shared_secret: \"${turnkey}\"" \
260
         -v TURNSHAREDSECRET="turn_shared_secret: \"${turnkey}\"" \
272
         print;
272
         print;
273
         }' "${filepath}" > "${ymltemp}"
273
         }' "${filepath}" > "${ymltemp}"
274
 
274
 
275
-    mv ${ymltemp} "${filepath}"
275
+    mv "${ymltemp}" "${filepath}"
276
 
276
 
277
     if [[ $ONION_ONLY == "no" ]]; then
277
     if [[ $ONION_ONLY == "no" ]]; then
278
         sed -i "s|tls_certificate_path:.*|tls_certificate_path: \"/etc/ssl/certs/${MATRIX_DOMAIN_NAME}.pem\"|g" "${filepath}"
278
         sed -i "s|tls_certificate_path:.*|tls_certificate_path: \"/etc/ssl/certs/${MATRIX_DOMAIN_NAME}.pem\"|g" "${filepath}"
307
     REPORT_STATS="${REPORT_STATS:-no_or_yes}"
307
     REPORT_STATS="${REPORT_STATS:-no_or_yes}"
308
     export MATRIX_DOMAIN_NAME REPORT_STATS
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
 function matrix_generate {
316
 function matrix_generate {
334
     read_config_param MATRIX_DOMAIN_NAME
335
     read_config_param MATRIX_DOMAIN_NAME
335
 
336
 
336
     matrix_remove_user=/usr/bin/matrix-remove-user
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
     chmod +x $matrix_remove_user
348
     chmod +x $matrix_remove_user
348
 }
349
 }
351
     remove_username="$1"
352
     remove_username="$1"
352
 
353
 
353
     create_matrix_user_removal_script
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
     $matrix_remove_user "$remove_username"
356
     $matrix_remove_user "$remove_username"
356
 }
357
 }
357
 
358
 
362
     read_config_param MY_USERNAME
363
     read_config_param MY_USERNAME
363
     read_config_param MATRIX_DOMAIN_NAME
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
     if [[ "$new_username" != "$MY_USERNAME" ]]; then
368
     if [[ "$new_username" != "$MY_USERNAME" ]]; then
368
         echo 'no' | register_new_matrix_user -c ${MATRIX_DATA_DIR}/homeserver.yaml -u "${new_username}" -p "${new_user_password}" http://localhost:${MATRIX_PORT}
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
 }
374
 }
374
 
375
 
375
 function install_interactive_matrix {
376
 function install_interactive_matrix {
376
-    if [ ! $ONION_ONLY ]; then
377
+    if [ ! "$ONION_ONLY" ]; then
377
         ONION_ONLY='no'
378
         ONION_ONLY='no'
378
     fi
379
     fi
379
 
380
 
393
 }
394
 }
394
 
395
 
395
 function change_password_matrix {
396
 function change_password_matrix {
396
-    curr_username="$1"
397
+    #curr_username="$1"
397
     new_user_password="$2"
398
     new_user_password="$2"
398
 
399
 
399
     #${PROJECT_NAME}-pass -u "$curr_username" -a matrix -p "$new_user_password"
400
     #${PROJECT_NAME}-pass -u "$curr_username" -a matrix -p "$new_user_password"
418
 
419
 
419
     function_check set_repo_commit
420
     function_check set_repo_commit
420
     set_repo_commit /etc/matrix "matrix commit" "$MATRIX_COMMIT" $MATRIX_REPO
421
     set_repo_commit /etc/matrix "matrix commit" "$MATRIX_COMMIT" $MATRIX_REPO
421
-    cd /etc/matrix
422
+    cd /etc/matrix || exit 62476724
422
     pip install --upgrade --process-dependency-links .
423
     pip install --upgrade --process-dependency-links .
423
 
424
 
424
     sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
425
     sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
467
         else
468
         else
468
             cp -r $temp_restore_dir/* /etc/matrix/
469
             cp -r $temp_restore_dir/* /etc/matrix/
469
         fi
470
         fi
471
+        # shellcheck disable=SC2181
470
         if [ ! "$?" = "0" ]; then
472
         if [ ! "$?" = "0" ]; then
471
             function_check backup_unmount_drive
473
             function_check backup_unmount_drive
472
             backup_unmount_drive
474
             backup_unmount_drive
482
         else
484
         else
483
             cp -r $temp_restore_dir/* $MATRIX_DATA_DIR/
485
             cp -r $temp_restore_dir/* $MATRIX_DATA_DIR/
484
         fi
486
         fi
487
+        # shellcheck disable=SC2181
485
         if [ ! "$?" = "0" ]; then
488
         if [ ! "$?" = "0" ]; then
486
             function_check backup_unmount_drive
489
             function_check backup_unmount_drive
487
             backup_unmount_drive
490
             backup_unmount_drive
490
         rm -rf $temp_restore_dir
493
         rm -rf $temp_restore_dir
491
         chown -R matrix:matrix $MATRIX_DATA_DIR
494
         chown -R matrix:matrix $MATRIX_DATA_DIR
492
 
495
 
493
-        if [[ $ONION_ONLY == "no" ]]; then
496
+        if [[ "$ONION_ONLY" == "no" ]]; then
494
             if [ -f /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam ]; then
497
             if [ -f /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam ]; then
495
                 chmod 755 /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam
498
                 chmod 755 /etc/ssl/certs/${MATRIX_DOMAIN_NAME}.dhparam
496
             fi
499
             fi
532
         else
535
         else
533
             cp -r $temp_restore_dir/* /etc/matrix/
536
             cp -r $temp_restore_dir/* /etc/matrix/
534
         fi
537
         fi
538
+        # shellcheck disable=SC2181
535
         if [ ! "$?" = "0" ]; then
539
         if [ ! "$?" = "0" ]; then
536
             exit 38935
540
             exit 38935
537
         fi
541
         fi
545
         else
549
         else
546
             cp -r $temp_restore_dir/* $MATRIX_DATA_DIR/
550
             cp -r $temp_restore_dir/* $MATRIX_DATA_DIR/
547
         fi
551
         fi
552
+        # shellcheck disable=SC2181
548
         if [ ! "$?" = "0" ]; then
553
         if [ ! "$?" = "0" ]; then
549
             exit 60923
554
             exit 60923
550
         fi
555
         fi
581
     fi
586
     fi
582
     systemctl daemon-reload
587
     systemctl daemon-reload
583
     apt-get -y remove --purge coturn
588
     apt-get -y remove --purge coturn
584
-    cd /etc/matrix
589
+    cd /etc/matrix || exit 26472462
585
     pip uninstall .
590
     pip uninstall .
586
     rm -rf $MATRIX_DATA_DIR
591
     rm -rf $MATRIX_DATA_DIR
587
     rm -rf /etc/matrix
592
     rm -rf /etc/matrix
596
     systemctl restart nginx
601
     systemctl restart nginx
597
 
602
 
598
     remove_completion_param install_matrix
603
     remove_completion_param install_matrix
599
-    sed -i '/matrix/d' $COMPLETION_FILE
604
+    sed -i '/matrix/d' "$COMPLETION_FILE"
600
 
605
 
601
     rm /etc/avahi/services/matrix.service
606
     rm /etc/avahi/services/matrix.service
602
     systemctl restart avahi-daemon
607
     systemctl restart avahi-daemon
608
         if [ -d /repos/matrix ]; then
613
         if [ -d /repos/matrix ]; then
609
             mkdir /etc/matrix
614
             mkdir /etc/matrix
610
             cp -r -p /repos/matrix/. /etc/matrix
615
             cp -r -p /repos/matrix/. /etc/matrix
611
-            cd /etc/matrix
616
+            cd /etc/matrix || exit 2324962946
612
             git pull
617
             git pull
613
         else
618
         else
614
             function_check git_clone
619
             function_check git_clone
621
         fi
626
         fi
622
     fi
627
     fi
623
 
628
 
624
-    cd /etc/matrix
629
+    cd /etc/matrix || exit 7385452724
625
     git checkout $MATRIX_COMMIT -b $MATRIX_COMMIT
630
     git checkout $MATRIX_COMMIT -b $MATRIX_COMMIT
626
     set_completion_param "matrix commit" "$MATRIX_COMMIT"
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
     fi
634
     fi
630
     rm -rf /usr/local/lib/python2.7/dist-packages/ldap*
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
     fi
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
         echo $'Failed to install matrix home server'
640
         echo $'Failed to install matrix home server'
637
         exit 782542
641
         exit 782542
638
     fi
642
     fi
653
     function_check matrix_generate
657
     function_check matrix_generate
654
     matrix_generate
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
     # Disable the web client
660
     # Disable the web client
662
     sed -i 's|web_client:.*|web_client: False|g' $MATRIX_DATA_DIR/homeserver.yaml
661
     sed -i 's|web_client:.*|web_client: False|g' $MATRIX_DATA_DIR/homeserver.yaml
663
     sed -i 's|, webclient||g' $MATRIX_DATA_DIR/homeserver.yaml
662
     sed -i 's|, webclient||g' $MATRIX_DATA_DIR/homeserver.yaml
669
 
668
 
670
     sed -i 's/ssl.PROTOCOL_SSLv23/ssl.PROTOCOL_TLSv1/g' /usr/local/bin/register_new_matrix_user
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
     systemctl enable matrix
685
     systemctl enable matrix
687
     systemctl daemon-reload
686
     systemctl daemon-reload
688
     systemctl start matrix
687
     systemctl start matrix
701
     fi
700
     fi
702
     chmod -R 700 $MATRIX_DATA_DIR/homeserver.db
701
     chmod -R 700 $MATRIX_DATA_DIR/homeserver.db
703
 
702
 
704
-    cd $MATRIX_DATA_DIR
703
+    cd "$MATRIX_DATA_DIR" || exit 365856835
705
     sqlite3 homeserver.db "PRAGMA auto_vacuum = FULL;"
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
     echo "HiddenServicePort ${MATRIX_HTTP_PORT} 127.0.0.1:${MATRIX_FEDERATION_ONION_PORT}" >> /etc/tor/torrc
708
     echo "HiddenServicePort ${MATRIX_HTTP_PORT} 127.0.0.1:${MATRIX_FEDERATION_ONION_PORT}" >> /etc/tor/torrc
709
     systemctl restart tor
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
         else
714
         else
715
-            MATRIX_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
715
+            MATRIX_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
716
         fi
716
         fi
717
     fi
717
     fi
718
 
718
 
733
 
733
 
734
     check_ram_availability 1500
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
     fi
738
     fi
739
 
739
 
740
     if [[ ${ONION_ONLY} == 'no' ]]; then
740
     if [[ ${ONION_ONLY} == 'no' ]]; then
806
     set_completion_param "matrix domain" "$MATRIX_DOMAIN_NAME"
806
     set_completion_param "matrix domain" "$MATRIX_DOMAIN_NAME"
807
 
807
 
808
     # Add avahi services
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
     systemctl restart avahi-daemon
823
     systemctl restart avahi-daemon
824
 
824
 

+ 171
- 167
src/freedombone-app-mediagoblin 查看文件

71
     if ! grep -q 'import os' $mgfile; then
71
     if ! grep -q 'import os' $mgfile; then
72
         sed -i '/import sys/a import os' $mgfile
72
         sed -i '/import sys/a import os' $mgfile
73
     fi
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
 function install_interactive_mediagoblin {
77
 function install_interactive_mediagoblin {
92
     dialog --title $"Mediagoblin" \
92
     dialog --title $"Mediagoblin" \
93
            --backtitle $"Freedombone Control Panel" \
93
            --backtitle $"Freedombone Control Panel" \
94
            --defaultno \
94
            --defaultno \
95
-           --yesno $"\nAllow registration of new users?" 10 60
95
+           --yesno $"\\nAllow registration of new users?" 10 60
96
     sel=$?
96
     sel=$?
97
     case $sel in
97
     case $sel in
98
         0)
98
         0)
139
 }
139
 }
140
 
140
 
141
 function upgrade_mediagoblin {
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
     if [[ "$CURR_MEDIAGOBLIN_COMMIT" != "$MEDIAGOBLIN_COMMIT" ]]; then
143
     if [[ "$CURR_MEDIAGOBLIN_COMMIT" != "$MEDIAGOBLIN_COMMIT" ]]; then
144
         MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
144
         MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
145
         su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git stash && git pull" - mediagoblin
145
         su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && git stash && git pull" - mediagoblin
182
         else
182
         else
183
             cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
183
             cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
184
         fi
184
         fi
185
+        # shellcheck disable=SC2181
185
         if [ ! "$?" = "0" ]; then
186
         if [ ! "$?" = "0" ]; then
186
             function_check restore_directory_from_usb
187
             function_check restore_directory_from_usb
187
             set_user_permissions
188
             set_user_permissions
195
         else
196
         else
196
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
197
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
197
         fi
198
         fi
199
+        # shellcheck disable=SC2181
198
         if [ ! "$?" = "0" ]; then
200
         if [ ! "$?" = "0" ]; then
199
             function_check set_user_permissions
201
             function_check set_user_permissions
200
             set_user_permissions
202
             set_user_permissions
214
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
216
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
215
     if [ -d /etc/mediagoblin ]; then
217
     if [ -d /etc/mediagoblin ]; then
216
         echo $"Backing up mediagoblin"
218
         echo $"Backing up mediagoblin"
217
-        backup_directory_to_friend $MEDIAGOBLIN_BASE_DIR mediagoblin
219
+        backup_directory_to_friend "$MEDIAGOBLIN_BASE_DIR" mediagoblin
218
         backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
220
         backup_directory_to_friend /var/lib/mediagoblin mediagoblindata
219
     fi
221
     fi
220
 }
222
 }
221
 
223
 
222
 function restore_remote_mediagoblin {
224
 function restore_remote_mediagoblin {
223
     MEDIAGOBLIN_BASE_DIR=/var/www/$MEDIAGOBLIN_DOMAIN_NAME/htdocs
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
         temp_restore_dir=/root/tempmediagoblin
227
         temp_restore_dir=/root/tempmediagoblin
226
         function_check get_completion_param
228
         function_check get_completion_param
227
         MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
229
         MEDIAGOBLIN_DOMAIN_NAME=$(get_completion_param "mediagoblin domain")
228
         function_check restore_directory_from_friend
230
         function_check restore_directory_from_friend
229
         restore_directory_from_friend $temp_restore_dir mediagoblin
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
         else
234
         else
233
-            cp -r ${temp_restore_dir}/* $MEDIAGOBLIN_BASE_DIR/
235
+            cp -r "${temp_restore_dir}/*" "$MEDIAGOBLIN_BASE_DIR/"
234
         fi
236
         fi
237
+        # shellcheck disable=SC2181
235
         if [ ! "$?" = "0" ]; then
238
         if [ ! "$?" = "0" ]; then
236
             exit 264824
239
             exit 264824
237
         fi
240
         fi
241
         else
244
         else
242
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
245
             cp -r ${temp_restore_dir}2/* /var/lib/mediagoblin/
243
         fi
246
         fi
247
+        # shellcheck disable=SC2181
244
         if [ ! "$?" = "0" ]; then
248
         if [ ! "$?" = "0" ]; then
245
             exit 268492
249
             exit 268492
246
         fi
250
         fi
247
         rm -rf ${temp_restore_dir}
251
         rm -rf ${temp_restore_dir}
248
         rm -rf ${temp_restore_dir}2
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
         chown -hR mediagoblin:www-data /var/lib/mediagoblin
254
         chown -hR mediagoblin:www-data /var/lib/mediagoblin
251
         chmod -R g+wx /var/lib/mediagoblin
255
         chmod -R g+wx /var/lib/mediagoblin
252
     fi
256
     fi
264
 
268
 
265
     function_check remove_onion_service
269
     function_check remove_onion_service
266
     remove_onion_service mediagoblin ${MEDIAGOBLIN_ONION_PORT}
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
     if [ -d /var/lib/mediagoblin ]; then
273
     if [ -d /var/lib/mediagoblin ]; then
270
         rm -rf /var/lib/mediagoblin
274
         rm -rf /var/lib/mediagoblin
271
     fi
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
     fi
278
     fi
275
     remove_completion_param "install_mediagoblin"
279
     remove_completion_param "install_mediagoblin"
276
     remove_completion_param "mediagoblin domain"
280
     remove_completion_param "mediagoblin domain"
277
-    sed -i '/mediagoblin/d' $COMPLETION_FILE
281
+    sed -i '/mediagoblin/d' "$COMPLETION_FILE"
278
 
282
 
279
     remove_nodejs mediagoblin
283
     remove_nodejs mediagoblin
280
 
284
 
282
     userdel -r mediagoblin
286
     userdel -r mediagoblin
283
 
287
 
284
     function_check remove_ddns_domain
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
 function install_mediagoblin {
292
 function install_mediagoblin {
289
-    if [ ! $MEDIAGOBLIN_DOMAIN_NAME ]; then
293
+    if [ ! "$MEDIAGOBLIN_DOMAIN_NAME" ]; then
290
         return
294
         return
291
     fi
295
     fi
292
 
296
 
304
     useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
308
     useradd -c "GNU MediaGoblin system account" -d /var/lib/mediagoblin -m -r -g www-data mediagoblin
305
     usermod --append -G mediagoblin mediagoblin
309
     usermod --append -G mediagoblin mediagoblin
306
     mkdir -p /var/lib/mediagoblin
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
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
313
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
310
     chmod -R g+wx /var/lib/mediagoblin
314
     chmod -R g+wx /var/lib/mediagoblin
311
 
315
 
312
     if [ -d /repos/mediagoblin ]; then
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
         git pull
320
         git pull
317
-        chown -R mediagoblin:mediagoblin $MEDIAGOBLIN_BASE_DIR/mediagoblin
321
+        chown -R mediagoblin:mediagoblin "$MEDIAGOBLIN_BASE_DIR/mediagoblin"
318
     else
322
     else
319
         su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
323
         su -c "cd $MEDIAGOBLIN_BASE_DIR && git clone $MEDIAGOBLIN_REPO $MEDIAGOBLIN_BASE_DIR/mediagoblin" - mediagoblin
320
     fi
324
     fi
340
             gstreamer1.0-plugins-ugly \
344
             gstreamer1.0-plugins-ugly \
341
             gstreamer1.0-libav \
345
             gstreamer1.0-libav \
342
             python-gst-1.0 python3-gst-1.0
346
             python-gst-1.0 python3-gst-1.0
343
-    cd $MEDIAGOBLIN_BASE_DIR/mediagoblin
347
+    cd "$MEDIAGOBLIN_BASE_DIR/mediagoblin" || exit 76345672472
344
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
348
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.video]]' | tee -a mediagoblin_local.ini" - mediagoblin
345
 
349
 
346
     # Audio plugin
350
     # Audio plugin
349
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
353
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && echo '[[mediagoblin.media_types.audio]]' | tee -a mediagoblin_local.ini" - mediagoblin
350
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin && bin/pip install scikits.audiolab" - mediagoblin
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
     else
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
         fi
361
         fi
358
     fi
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
     MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
365
     MEDIAGOBLIN_ONION_HOSTNAME=$(add_onion_service mediagoblin 80 ${MEDIAGOBLIN_ONION_PORT})
362
     set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
366
     set_completion_param "mediagoblin domain" "${MEDIAGOBLIN_DOMAIN_NAME}"
365
 
369
 
366
     if [[ $ONION_ONLY == "no" ]]; then
370
     if [[ $ONION_ONLY == "no" ]]; then
367
         function_check nginx_http_redirect
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
         function_check nginx_ssl
382
         function_check nginx_ssl
379
-        nginx_ssl $MEDIAGOBLIN_DOMAIN_NAME
383
+        nginx_ssl "$MEDIAGOBLIN_DOMAIN_NAME"
380
         function_check nginx_disable_sniffing
384
         function_check nginx_disable_sniffing
381
-        nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
385
+        nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
382
         function_check nginx_limits
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
     else
430
     else
427
-        echo -n '' > /etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME
431
+        echo -n '' > "/etc/nginx/sites-available/$MEDIAGOBLIN_DOMAIN_NAME"
428
     fi
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
     function_check nginx_disable_sniffing
441
     function_check nginx_disable_sniffing
438
-    nginx_disable_sniffing $MEDIAGOBLIN_DOMAIN_NAME
442
+    nginx_disable_sniffing "$MEDIAGOBLIN_DOMAIN_NAME"
439
     function_check nginx_limits
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
     chmod +x /etc/systemd/system/mediagoblin.service
505
     chmod +x /etc/systemd/system/mediagoblin.service
502
 
506
 
503
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
507
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg dbupdate" - mediagoblin
504
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
508
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg adduser --username $MY_USERNAME --password $MY_USERNAME $MEDIAGOBLIN_ADMIN_PASSWORD" - mediagoblin
505
     su -c "cd $MEDIAGOBLIN_BASE_DIR/mediagoblin/ && bin/gmg makeadmin $MY_USERNAME" - mediagoblin
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
     fi
523
     fi
520
 
524
 
521
     systemctl enable mediagoblin
525
     systemctl enable mediagoblin
529
     fi
533
     fi
530
 
534
 
531
     function_check create_site_certificate
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
     function_check configure_php
538
     function_check configure_php
535
     configure_php
539
     configure_php
536
 
540
 
537
-    nginx_ensite $MEDIAGOBLIN_DOMAIN_NAME
541
+    nginx_ensite "$MEDIAGOBLIN_DOMAIN_NAME"
538
 
542
 
539
     systemctl restart php7.0-fpm
543
     systemctl restart php7.0-fpm
540
     systemctl restart nginx
544
     systemctl restart nginx
541
 
545
 
542
     function_check add_ddns_domain
546
     function_check add_ddns_domain
543
-    add_ddns_domain $MEDIAGOBLIN_DOMAIN_NAME
547
+    add_ddns_domain "$MEDIAGOBLIN_DOMAIN_NAME"
544
 
548
 
545
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
549
     chown -hR mediagoblin:www-data /var/lib/mediagoblin
546
     chmod -R g+wx /var/lib/mediagoblin
550
     chmod -R g+wx /var/lib/mediagoblin

+ 206
- 206
src/freedombone-app-movim 查看文件

58
 function remove_user_movim {
58
 function remove_user_movim {
59
     remove_username="$1"
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
 function add_user_movim {
64
 function add_user_movim {
65
     new_username="$1"
65
     new_username="$1"
66
     new_user_password="$2"
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
     echo '0'
69
     echo '0'
70
 }
70
 }
71
 
71
 
72
 function install_interactive_movim {
72
 function install_interactive_movim {
73
-    if [ ! $ONION_ONLY ]; then
73
+    if [ ! "$ONION_ONLY" ]; then
74
         ONION_ONLY='no'
74
         ONION_ONLY='no'
75
     fi
75
     fi
76
 
76
 
80
         MOVIM_DETAILS_COMPLETE=
80
         MOVIM_DETAILS_COMPLETE=
81
         while [ ! $MOVIM_DETAILS_COMPLETE ]
81
         while [ ! $MOVIM_DETAILS_COMPLETE ]
82
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
84
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
86
                 dialog --backtitle $"Freedombone Configuration" \
85
                 dialog --backtitle $"Freedombone Configuration" \
87
                        --title $"Movim Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
88
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
90
                        $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
89
                        $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
91
-                       2> $data
90
+                       2> "$data"
92
             else
91
             else
93
                 dialog --backtitle $"Freedombone Configuration" \
92
                 dialog --backtitle $"Freedombone Configuration" \
94
                        --title $"Movim Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
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
             fi
97
             fi
99
             sel=$?
98
             sel=$?
100
             case $sel in
99
             case $sel in
101
                 1) exit 1;;
100
                 1) exit 1;;
102
                 255) exit 1;;
101
                 255) exit 1;;
103
             esac
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
                 TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
105
                 TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
107
                 validate_domain_name
106
                 validate_domain_name
108
-                if [[ $TEST_DOMAIN_NAME != $MOVIM_DOMAIN_NAME ]]; then
107
+                if [[ "$TEST_DOMAIN_NAME" != "$MOVIM_DOMAIN_NAME" ]]; then
109
                     MOVIM_DOMAIN_NAME=
108
                     MOVIM_DOMAIN_NAME=
110
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
109
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
111
                 else
110
                 else
112
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$MOVIM_CODE"
113
                         validate_freedns_code "$MOVIM_CODE"
115
-                        if [ ! $VALID_CODE ]; then
114
+                        if [ ! "$VALID_CODE" ]; then
116
                             MOVIM_DOMAIN_NAME=
115
                             MOVIM_DOMAIN_NAME=
117
                         fi
116
                         fi
118
                     fi
117
                     fi
121
             if [ $MOVIM_DOMAIN_NAME ]; then
120
             if [ $MOVIM_DOMAIN_NAME ]; then
122
                 MOVIM_DETAILS_COMPLETE="yes"
121
                 MOVIM_DETAILS_COMPLETE="yes"
123
             fi
122
             fi
123
+            rm -f "$data"
124
         done
124
         done
125
 
125
 
126
         # save the results in the config file
126
         # save the results in the config file
136
 
136
 
137
     read_config_param 'MOVIM_DOMAIN_NAME'
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
 function movim_create_database {
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
     else
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
         fi
148
         fi
149
     fi
149
     fi
150
-    if [ ! $MOVIM_ADMIN_PASSWORD ]; then
150
+    if [ ! "$MOVIM_ADMIN_PASSWORD" ]; then
151
         return
151
         return
152
     fi
152
     fi
153
 
153
 
154
     function_check create_database
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
 function reconfigure_movim {
158
 function reconfigure_movim {
165
         return
165
         return
166
     fi
166
     fi
167
 
167
 
168
-    if grep -q "movim domain" $COMPLETION_FILE; then
168
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
169
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
169
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
170
     fi
170
     fi
171
 
171
 
172
     # update to the next commit
172
     # update to the next commit
173
     function_check set_repo_commit
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
     php composer.phar install
177
     php composer.phar install
178
     php mud.php db --set
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
 function backup_local_movim {
183
 function backup_local_movim {
184
     MOVIM_DOMAIN_NAME='movim'
184
     MOVIM_DOMAIN_NAME='movim'
185
-    if grep -q "movim domain" $COMPLETION_FILE; then
185
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
186
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
186
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
187
     fi
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
         dest_directory=movim
191
         dest_directory=movim
192
         function_check suspend_site
192
         function_check suspend_site
193
-        suspend_site ${MOVIM_DOMAIN_NAME}
193
+        suspend_site "${MOVIM_DOMAIN_NAME}"
194
 
194
 
195
         function_check backup_directory_to_usb
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
         function_check backup_database_to_usb
198
         function_check backup_database_to_usb
199
         backup_database_to_usb movim
199
         backup_database_to_usb movim
204
 }
204
 }
205
 
205
 
206
 function restore_local_movim {
206
 function restore_local_movim {
207
-    if ! grep -q "movim domain" $COMPLETION_FILE; then
207
+    if ! grep -q "movim domain" "$COMPLETION_FILE"; then
208
         return
208
         return
209
     fi
209
     fi
210
     MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
210
     MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
211
-    if [ $MOVIM_DOMAIN_NAME ]; then
211
+    if [ "$MOVIM_DOMAIN_NAME" ]; then
212
         echo $"Restoring movim"
212
         echo $"Restoring movim"
213
         temp_restore_dir=/root/tempmovim
213
         temp_restore_dir=/root/tempmovim
214
         movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
214
         movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
215
         # stop the daemons
215
         # stop the daemons
216
-        cd $movim_dir
216
+        cd "$movim_dir" || exit 7856724252
217
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
217
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
218
 
218
 
219
         function_check movim_create_database
219
         function_check movim_create_database
220
         movim_create_database
220
         movim_create_database
221
 
221
 
222
-        restore_database movim ${MOVIM_DOMAIN_NAME}
222
+        restore_database movim "${MOVIM_DOMAIN_NAME}"
223
         if [ -d $temp_restore_dir ]; then
223
         if [ -d $temp_restore_dir ]; then
224
             rm -rf $temp_restore_dir
224
             rm -rf $temp_restore_dir
225
         fi
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
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
229
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
230
         MARIADB_PASSWORD=
230
         MARIADB_PASSWORD=
231
 
231
 
234
 }
234
 }
235
 
235
 
236
 function backup_remote_movim {
236
 function backup_remote_movim {
237
-    if grep -q "movim domain" $COMPLETION_FILE; then
237
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
238
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
238
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
239
         temp_backup_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
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
             function_check suspend_site
241
             function_check suspend_site
242
-            suspend_site ${MOVIM_DOMAIN_NAME}
242
+            suspend_site "${MOVIM_DOMAIN_NAME}"
243
 
243
 
244
             function_check backup_database_to_friend
244
             function_check backup_database_to_friend
245
             backup_database_to_friend movim
245
             backup_database_to_friend movim
246
 
246
 
247
             function_check backup_directory_to_friend
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
             function_check restart_site
250
             function_check restart_site
251
             restart_site
251
             restart_site
256
 }
256
 }
257
 
257
 
258
 function restore_remote_movim {
258
 function restore_remote_movim {
259
-    if grep -q "movim domain" $COMPLETION_FILE; then
259
+    if grep -q "movim domain" "$COMPLETION_FILE"; then
260
         echo $"Restoring movim"
260
         echo $"Restoring movim"
261
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
261
         MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
262
 
262
 
263
         # stop the daemons
263
         # stop the daemons
264
-        cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
264
+        cd "/var/www/${MOVIM_DOMAIN_NAME}/htdocs" || exit 524792846827
265
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
265
         su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
266
 
266
 
267
         function_check movim_create_database
267
         function_check movim_create_database
268
         movim_create_database
268
         movim_create_database
269
 
269
 
270
         function_check restore_database_from_friend
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
         if [ -d /root/tempmovim ]; then
272
         if [ -d /root/tempmovim ]; then
273
             rm -rf /root/tempmovim
273
             rm -rf /root/tempmovim
274
         fi
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
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
278
         sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
279
         MARIADB_PASSWORD=
279
         MARIADB_PASSWORD=
280
 
280
 
298
 
298
 
299
     read_config_param "MY_USERNAME"
299
     read_config_param "MY_USERNAME"
300
     echo "Removing $MOVIM_DOMAIN_NAME"
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
     fi
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
     fi
309
     fi
310
     function_check drop_database
310
     function_check drop_database
311
     drop_database movim
311
     drop_database movim
316
     fi
316
     fi
317
     remove_app movim
317
     remove_app movim
318
     remove_completion_param install_movim
318
     remove_completion_param install_movim
319
-    sed -i '/movim/d' $COMPLETION_FILE
319
+    sed -i '/movim/d' "$COMPLETION_FILE"
320
     remove_backup_database_local movim
320
     remove_backup_database_local movim
321
 
321
 
322
     function_check remove_ddns_domain
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
 function install_movim {
326
 function install_movim {
327
-    if [ ! $MOVIM_DOMAIN_NAME ]; then
327
+    if [ ! "$MOVIM_DOMAIN_NAME" ]; then
328
         echo $'No domain name was given for movim'
328
         echo $'No domain name was given for movim'
329
         exit 72572
329
         exit 72572
330
     fi
330
     fi
333
         return
333
         return
334
     fi
334
     fi
335
 
335
 
336
-    movim_hourly_script movim $MOVIM_DOMAIN_NAME
336
+    movim_hourly_script movim "$MOVIM_DOMAIN_NAME"
337
 
337
 
338
     function_check install_mariadb
338
     function_check install_mariadb
339
     install_mariadb
339
     install_mariadb
347
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
347
     apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
348
     apt-get -yq install php-memcached php-intl exiftool php-imagick libfcgi0ldbl
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
     fi
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
         if [ -d /repos/movim ]; then
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
             git pull
359
             git pull
360
         else
360
         else
361
             function_check git_clone
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
         fi
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
             echo $'Unable to clone movim repo'
366
             echo $'Unable to clone movim repo'
367
             exit 76285
367
             exit 76285
368
         fi
368
         fi
369
     fi
369
     fi
370
 
370
 
371
-    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
371
+    cd "/var/www/$MOVIM_DOMAIN_NAME/htdocs" || exit 7345247242
372
     git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
372
     git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
373
     set_completion_param "movim commit" "$MOVIM_COMMIT"
373
     set_completion_param "movim commit" "$MOVIM_COMMIT"
374
 
374
 
375
     # default login
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
         echo $'Unable to find Config.php'
377
         echo $'Unable to find Config.php'
378
         exit 72352
378
         exit 72352
379
     fi
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
     # Fix typo
383
     # Fix typo
384
     sed -i 's|weksocket|websocket|g' app/widgets/AdminTest/admintest.js
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
     install_composer
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
     cp db.example.inc.php db.inc.php
390
     cp db.example.inc.php db.inc.php
391
     sed -i "s|'username'.*|'username'    => 'root',|g" db.inc.php
391
     sed -i "s|'username'.*|'username'    => 'root',|g" db.inc.php
392
     sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
392
     sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
393
     sed -i "s|'database'.*|'database'    => 'movim'|g" db.inc.php
393
     sed -i "s|'database'.*|'database'    => 'movim'|g" db.inc.php
394
     php mud.php db --set
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
     function_check movim_create_database
399
     function_check movim_create_database
400
     movim_create_database
400
     movim_create_database
401
 
401
 
402
     function_check add_ddns_domain
402
     function_check add_ddns_domain
403
-    add_ddns_domain $MOVIM_DOMAIN_NAME
403
+    add_ddns_domain "$MOVIM_DOMAIN_NAME"
404
 
404
 
405
     MOVIM_ONION_HOSTNAME=$(add_onion_service movim 80 ${MOVIM_ONION_PORT})
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
     if [[ $ONION_ONLY == 'no' ]]; then
415
     if [[ $ONION_ONLY == 'no' ]]; then
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
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
     else
417
     else
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
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
     fi
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
     systemctl enable movim
428
     systemctl enable movim
429
     systemctl daemon-reload
429
     systemctl daemon-reload
430
 
430
 
431
     movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
431
     movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
432
     if [[ $ONION_ONLY == "no" ]]; then
432
     if [[ $ONION_ONLY == "no" ]]; then
433
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl
444
         function_check nginx_ssl
445
-        nginx_ssl $MOVIM_DOMAIN_NAME
445
+        nginx_ssl "$MOVIM_DOMAIN_NAME"
446
 
446
 
447
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
499
     else
500
-        echo -n '' > $movim_nginx_site
500
+        echo -n '' > "$movim_nginx_site"
501
     fi
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
     function_check nginx_compress
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check configure_php
560
     function_check configure_php
561
     configure_php
561
     configure_php
562
 
562
 
563
     function_check create_site_certificate
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
     # Ensure that the database gets backed up locally, if remote
566
     # Ensure that the database gets backed up locally, if remote
567
     # backups are not being used
567
     # backups are not being used
572
     backup_database_local movim
572
     backup_database_local movim
573
 
573
 
574
     function_check nginx_ensite
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
     set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
579
     set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
580
 
580
 

+ 39
- 38
src/freedombone-app-mumble 查看文件

86
         usermod -a -G ssl-cert mumble-server
86
         usermod -a -G ssl-cert mumble-server
87
     fi
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
         if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
90
         if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
91
             sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
91
             sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
92
             sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
92
             sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
117
 }
117
 }
118
 
118
 
119
 function restore_local_mumble {
119
 function restore_local_mumble {
120
-    if [ -d $USB_MOUNT/backup/mumble ]; then
120
+    if [ -d "$USB_MOUNT/backup/mumble" ]; then
121
         echo $"Restoring mumble settings"
121
         echo $"Restoring mumble settings"
122
         temp_restore_dir=/root/tempmumble
122
         temp_restore_dir=/root/tempmumble
123
         function_check restore_directory_from_usb
123
         function_check restore_directory_from_usb
124
         restore_directory_from_usb $temp_restore_dir voip
124
         restore_directory_from_usb $temp_restore_dir voip
125
         restore_directory_from_usb $temp_restore_dir mumble
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
         else
128
         else
129
             cp -f $temp_restore_dir/mumble-server.ini /etc/
129
             cp -f $temp_restore_dir/mumble-server.ini /etc/
130
         fi
130
         fi
131
+        # shellcheck disable=SC2181
131
         if [ ! "$?" = "0" ]; then
132
         if [ ! "$?" = "0" ]; then
132
             rm -rf $temp_restore_dir
133
             rm -rf $temp_restore_dir
133
             function_check set_user_permissions
134
             function_check set_user_permissions
136
             backup_unmount_drive
137
             backup_unmount_drive
137
             exit 3679
138
             exit 3679
138
         fi
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
         else
142
         else
142
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
143
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
143
         fi
144
         fi
145
+        # shellcheck disable=SC2181
144
         if [ ! "$?" = "0" ]; then
146
         if [ ! "$?" = "0" ]; then
145
             rm -rf $temp_restore_dir
147
             rm -rf $temp_restore_dir
146
             function_check set_user_permissions
148
             function_check set_user_permissions
171
 }
173
 }
172
 
174
 
173
 function restore_remote_mumble {
175
 function restore_remote_mumble {
174
-    if [ -d $SERVER_DIRECTORY/backup/mumble ]; then
176
+    if [ -d "$SERVER_DIRECTORY/backup/mumble" ]; then
175
         echo $"Restoring Mumble settings"
177
         echo $"Restoring Mumble settings"
176
         temp_restore_dir=/root/tempmumble
178
         temp_restore_dir=/root/tempmumble
177
         function_check restore_directory_from_friend
179
         function_check restore_directory_from_friend
178
         restore_directory_from_friend $temp_restore_dir mumble
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
         else
183
         else
182
             cp -f $temp_restore_dir/mumble-server.ini /etc/
184
             cp -f $temp_restore_dir/mumble-server.ini /etc/
183
         fi
185
         fi
186
+        # shellcheck disable=SC2181
184
         if [ ! "$?" = "0" ]; then
187
         if [ ! "$?" = "0" ]; then
185
             rm -rf $temp_restore_dir
188
             rm -rf $temp_restore_dir
186
             exit 7823
189
             exit 7823
187
         fi
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
         else
193
         else
195
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
194
             cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
196
         fi
195
         fi
196
+        # shellcheck disable=SC2181
197
         if [ ! "$?" = "0" ]; then
197
         if [ ! "$?" = "0" ]; then
198
             rm -rf $temp_restore_dir
198
             rm -rf $temp_restore_dir
199
             exit 276
199
             exit 276
221
     fi
221
     fi
222
     function_check remove_onion_service
222
     function_check remove_onion_service
223
     remove_onion_service mumble ${MUMBLE_PORT}
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
 function configure_firewall_for_mumble {
227
 function configure_firewall_for_mumble {
228
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
228
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
229
         return
229
         return
230
     fi
230
     fi
231
     if [[ $ONION_ONLY != "no" ]]; then
231
     if [[ $ONION_ONLY != "no" ]]; then
232
         return
232
         return
233
     fi
233
     fi
234
     firewall_add Mumble ${MUMBLE_PORT}
234
     firewall_add Mumble ${MUMBLE_PORT}
235
-    mark_completed $FUNCNAME
235
+    mark_completed "${FUNCNAME[0]}"
236
 }
236
 }
237
 
237
 
238
 function install_mumble {
238
 function install_mumble {
239
     apt-get -yq install mumble-server
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
     else
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
             fi
248
             fi
249
         fi
249
         fi
250
     fi
250
     fi
251
 
251
 
252
     if [[ ${ONION_ONLY} == 'no' ]]; then
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
         fi
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
             fi
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
             fi
262
             fi
263
             echo $'Obtaining certificate for the main domain'
263
             echo $'Obtaining certificate for the main domain'
264
             function_check create_site_certificate
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
                 echo $'Incorrect certificate generated'
269
                 echo $'Incorrect certificate generated'
270
                 exit 78352
270
                 exit 78352
271
             fi
271
             fi
276
 
276
 
277
 
277
 
278
     # Make an ssl cert for the server
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
         if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
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
             function_check check_certificates
282
             function_check check_certificates
283
             check_certificates mumble
283
             check_certificates mumble
284
         fi
284
         fi
318
         echo 'allowping=False' >> /etc/mumble-server.ini
318
         echo 'allowping=False' >> /etc/mumble-server.ini
319
     fi
319
     fi
320
     sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
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
         sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
322
         sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
323
         sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
323
         sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
324
     else
324
     else
335
     sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
335
     sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
336
     sed -i "s|port=.*|port=${MUMBLE_PORT}|g" /etc/mumble-server.ini
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
     # turn off logs by default
341
     # turn off logs by default
341
     sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
342
     sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini

+ 229
- 242
src/freedombone-app-nextcloud 查看文件

60
 function remove_user_nextcloud {
60
 function remove_user_nextcloud {
61
     remove_username="$1"
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
 function add_user_nextcloud {
66
 function add_user_nextcloud {
67
     new_username="$1"
67
     new_username="$1"
68
     new_user_password="$2"
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
     echo '0'
71
     echo '0'
72
 }
72
 }
73
 
73
 
76
 
76
 
77
     export OC_PASS="$2"
77
     export OC_PASS="$2"
78
     su -s /bin/sh www-data -c "php occ user:resetpassword --password-from-env $curr_username"
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
     export OC_PASS=""
80
     export OC_PASS=""
81
 }
81
 }
82
 
82
 
83
 function install_interactive_nextcloud {
83
 function install_interactive_nextcloud {
84
-    if [ ! $ONION_ONLY ]; then
84
+    if [ ! "$ONION_ONLY" ]; then
85
         ONION_ONLY='no'
85
         ONION_ONLY='no'
86
     fi
86
     fi
87
 
87
 
91
         NEXTCLOUD_DETAILS_COMPLETE=
91
         NEXTCLOUD_DETAILS_COMPLETE=
92
         while [ ! $NEXTCLOUD_DETAILS_COMPLETE ]
92
         while [ ! $NEXTCLOUD_DETAILS_COMPLETE ]
93
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
95
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
97
                 dialog --backtitle $"Freedombone Configuration" \
96
                 dialog --backtitle $"Freedombone Configuration" \
98
                        --title $"NextCloud Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
99
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
101
                        $"Code:" 2 1 "$(grep 'NEXTCLOUD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
100
                        $"Code:" 2 1 "$(grep 'NEXTCLOUD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
102
-                       2> $data
101
+                       2> "$data"
103
             else
102
             else
104
                 dialog --backtitle $"Freedombone Configuration" \
103
                 dialog --backtitle $"Freedombone Configuration" \
105
                        --title $"NextCloud Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'NEXTCLOUD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
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
             fi
108
             fi
110
             sel=$?
109
             sel=$?
111
             case $sel in
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
             esac
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
                 TEST_DOMAIN_NAME=$NEXTCLOUD_DOMAIN_NAME
118
                 TEST_DOMAIN_NAME=$NEXTCLOUD_DOMAIN_NAME
121
                 validate_domain_name
119
                 validate_domain_name
122
-                if [[ $TEST_DOMAIN_NAME != $NEXTCLOUD_DOMAIN_NAME ]]; then
120
+                if [[ "$TEST_DOMAIN_NAME" != "$NEXTCLOUD_DOMAIN_NAME" ]]; then
123
                     NEXTCLOUD_DOMAIN_NAME=
121
                     NEXTCLOUD_DOMAIN_NAME=
124
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
122
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
125
                 else
123
                 else
126
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$NEXTCLOUD_CODE"
126
                         validate_freedns_code "$NEXTCLOUD_CODE"
129
-                        if [ ! $VALID_CODE ]; then
127
+                        if [ ! "$VALID_CODE" ]; then
130
                             NEXTCLOUD_DOMAIN_NAME=
128
                             NEXTCLOUD_DOMAIN_NAME=
131
                         fi
129
                         fi
132
                     fi
130
                     fi
135
             if [ $NEXTCLOUD_DOMAIN_NAME ]; then
133
             if [ $NEXTCLOUD_DOMAIN_NAME ]; then
136
                 NEXTCLOUD_DETAILS_COMPLETE="yes"
134
                 NEXTCLOUD_DETAILS_COMPLETE="yes"
137
             fi
135
             fi
136
+            rm -f "$data"
138
         done
137
         done
139
 
138
 
140
         # remove any invalid characters
139
         # remove any invalid characters
141
         if [ ${#NEXTCLOUD_TITLE} -gt 0 ]; then
140
         if [ ${#NEXTCLOUD_TITLE} -gt 0 ]; then
142
-            new_title=$(echo "$NEXTCLOUD_TITLE" | sed "s|'||g")
141
+            new_title=${"$NEXTCLOUD_TITLE"//\'//}
143
             NEXTCLOUD_TITLE="$new_title"
142
             NEXTCLOUD_TITLE="$new_title"
144
         fi
143
         fi
145
 
144
 
156
 
155
 
157
     read_config_param ${NEXTCLOUD_DOMAIN_NAME}
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
 function nextcloud_create_database {
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
     else
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
         fi
167
         fi
169
     fi
168
     fi
170
-    if [ ! $NEXTCLOUD_ADMIN_PASSWORD ]; then
169
+    if [ ! "$NEXTCLOUD_ADMIN_PASSWORD" ]; then
171
         return
170
         return
172
     fi
171
     fi
173
 
172
 
174
     function_check create_database
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
 function reconfigure_nextcloud {
177
 function reconfigure_nextcloud {
186
 function upgrade_nextcloud_base {
185
 function upgrade_nextcloud_base {
187
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
186
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
188
     chown -R www-data:www-data /var/www/$NEXTCLOUD_DOMAIN_NAME/data
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
     sudo -u www-data ./occ maintenance:repair
189
     sudo -u www-data ./occ maintenance:repair
191
     sudo -u www-data ./occ files:cleanup
190
     sudo -u www-data ./occ files:cleanup
192
     sudo -u www-data ./occ files:scan --all
191
     sudo -u www-data ./occ files:scan --all
200
         return
199
         return
201
     fi
200
     fi
202
 
201
 
203
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
202
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
204
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
203
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
205
     fi
204
     fi
206
 
205
 
207
     # update to the next commit
206
     # update to the next commit
208
     function_check set_repo_commit
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
     upgrade_nextcloud_base
210
     upgrade_nextcloud_base
212
     sudo -u www-data ./occ upgrade
211
     sudo -u www-data ./occ upgrade
215
 
214
 
216
 function backup_local_nextcloud {
215
 function backup_local_nextcloud {
217
     NEXTCLOUD_DOMAIN_NAME='nextcloud'
216
     NEXTCLOUD_DOMAIN_NAME='nextcloud'
218
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
217
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
219
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
218
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
220
     fi
219
     fi
221
 
220
 
222
     source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
221
     source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
223
-    if [ -d $source_directory ]; then
222
+    if [ -d "$source_directory" ]; then
224
         function_check suspend_site
223
         function_check suspend_site
225
-        suspend_site ${NEXTCLOUD_DOMAIN_NAME}
224
+        suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
226
 
225
 
227
         dest_directory=nextcloudfiles
226
         dest_directory=nextcloudfiles
228
         function_check backup_directory_to_usb
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
         source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
230
         source_directory=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
232
         dest_directory=nextcloudconfig
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
         function_check backup_database_to_usb
234
         function_check backup_database_to_usb
236
         backup_database_to_usb nextcloud
235
         backup_database_to_usb nextcloud
241
 }
240
 }
242
 
241
 
243
 function restore_local_nextcloud {
242
 function restore_local_nextcloud {
244
-    if ! grep -q "nextcloud domain" $COMPLETION_FILE; then
243
+    if ! grep -q "nextcloud domain" "$COMPLETION_FILE"; then
245
         return
244
         return
246
     fi
245
     fi
247
     NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
246
     NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
248
-    if [ $NEXTCLOUD_DOMAIN_NAME ]; then
247
+    if [ "$NEXTCLOUD_DOMAIN_NAME" ]; then
249
 
248
 
250
         temp_restore_dir=/root/tempnextcloud
249
         temp_restore_dir=/root/tempnextcloud
251
         function_check nextcloud_create_database
250
         function_check nextcloud_create_database
252
         nextcloud_create_database
251
         nextcloud_create_database
253
-        restore_database nextcloud ${NEXTCLOUD_DOMAIN_NAME}
252
+        restore_database nextcloud "${NEXTCLOUD_DOMAIN_NAME}"
254
 
253
 
255
         temp_restore_dir=/root/tempnextcloudfiles
254
         temp_restore_dir=/root/tempnextcloudfiles
256
         restore_directory_from_usb $temp_restore_dir nextcloudfiles
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
         else
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
         fi
261
         fi
263
-
262
+        # shellcheck disable=SC2181
264
         if [ ! "$?" = "0" ]; then
263
         if [ ! "$?" = "0" ]; then
265
             set_user_permissions
264
             set_user_permissions
266
             backup_unmount_drive
265
             backup_unmount_drive
271
         temp_restore_dir=/root/tempnextcloudconfig
270
         temp_restore_dir=/root/tempnextcloudconfig
272
         restore_directory_from_usb $temp_restore_dir nextcloudconfig
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
         else
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
         fi
277
         fi
279
 
278
 
279
+        # shellcheck disable=SC2181
280
         if [ ! "$?" = "0" ]; then
280
         if [ ! "$?" = "0" ]; then
281
             set_user_permissions
281
             set_user_permissions
282
             backup_unmount_drive
282
             backup_unmount_drive
284
         fi
284
         fi
285
         rm -rf ${temp_restore_dir}
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
         sudo -u www-data ./occ maintenance:repair
290
         sudo -u www-data ./occ maintenance:repair
291
         sudo -u www-data ./occ files:cleanup
291
         sudo -u www-data ./occ files:cleanup
292
         sudo -u www-data ./occ files:scan --all
292
         sudo -u www-data ./occ files:scan --all
294
 }
294
 }
295
 
295
 
296
 function backup_remote_nextcloud {
296
 function backup_remote_nextcloud {
297
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
297
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
298
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
298
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
299
         temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/data
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
             function_check suspend_site
301
             function_check suspend_site
302
-            suspend_site ${NEXTCLOUD_DOMAIN_NAME}
302
+            suspend_site "${NEXTCLOUD_DOMAIN_NAME}"
303
 
303
 
304
             function_check backup_database_to_friend
304
             function_check backup_database_to_friend
305
             backup_database_to_friend nextcloud
305
             backup_database_to_friend nextcloud
306
 
306
 
307
             function_check backup_directory_to_friend
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
             temp_backup_dir=/var/www/${NEXTCLOUD_DOMAIN_NAME}/htdocs/config
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
             function_check restart_site
313
             function_check restart_site
314
             restart_site
314
             restart_site
319
 }
319
 }
320
 
320
 
321
 function restore_remote_nextcloud {
321
 function restore_remote_nextcloud {
322
-    if grep -q "nextcloud domain" $COMPLETION_FILE; then
322
+    if grep -q "nextcloud domain" "$COMPLETION_FILE"; then
323
         echo $"Restoring nextcloud"
323
         echo $"Restoring nextcloud"
324
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
324
         NEXTCLOUD_DOMAIN_NAME=$(get_completion_param "nextcloud domain")
325
 
325
 
327
         nextcloud_create_database
327
         nextcloud_create_database
328
 
328
 
329
         function_check restore_database_from_friend
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
         if [ -d /root/tempnextcloud ]; then
331
         if [ -d /root/tempnextcloud ]; then
332
             rm -rf /root/tempnextcloud
332
             rm -rf /root/tempnextcloud
333
         fi
333
         fi
335
         temp_restore_dir=/root/tempnextcloudfiles
335
         temp_restore_dir=/root/tempnextcloudfiles
336
         restore_directory_from_friend $temp_restore_dir nextcloudfiles
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
         else
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
         fi
342
         fi
343
-
343
+        # shellcheck disable=SC2181
344
         if [ ! "$?" = "0" ]; then
344
         if [ ! "$?" = "0" ]; then
345
             exit 768254
345
             exit 768254
346
         fi
346
         fi
349
         temp_restore_dir=/root/tempnextcloudconfig
349
         temp_restore_dir=/root/tempnextcloudconfig
350
         restore_directory_from_friend $temp_restore_dir nextcloudconfig
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
         else
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
         fi
356
         fi
357
 
357
 
358
+        # shellcheck disable=SC2181
358
         if [ ! "$?" = "0" ]; then
359
         if [ ! "$?" = "0" ]; then
359
             exit 573427
360
             exit 573427
360
         fi
361
         fi
361
         rm -rf ${temp_restore_dir}
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
         sudo -u www-data ./occ maintenance:repair
367
         sudo -u www-data ./occ maintenance:repair
367
         sudo -u www-data ./occ files:cleanup
368
         sudo -u www-data ./occ files:cleanup
368
         sudo -u www-data ./occ files:scan --all
369
         sudo -u www-data ./occ files:scan --all
381
     read_config_param "NEXTCLOUD_DOMAIN_NAME"
382
     read_config_param "NEXTCLOUD_DOMAIN_NAME"
382
     read_config_param "MY_USERNAME"
383
     read_config_param "MY_USERNAME"
383
     echo "Removing $NEXTCLOUD_DOMAIN_NAME"
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
     fi
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
     fi
392
     fi
392
     function_check drop_database
393
     function_check drop_database
393
     drop_database nextcloud
394
     drop_database nextcloud
395
     remove_onion_service nextcloud ${NEXTCLOUD_ONION_PORT}
396
     remove_onion_service nextcloud ${NEXTCLOUD_ONION_PORT}
396
     remove_app nextcloud
397
     remove_app nextcloud
397
     remove_completion_param install_nextcloud
398
     remove_completion_param install_nextcloud
398
-    sed -i '/nextcloud/d' $COMPLETION_FILE
399
+    sed -i '/nextcloud/d' "$COMPLETION_FILE"
399
     remove_backup_database_local nextcloud
400
     remove_backup_database_local nextcloud
400
 
401
 
401
     function_check remove_ddns_domain
402
     function_check remove_ddns_domain
402
-    remove_ddns_domain $NEXTCLOUD_DOMAIN_NAME
403
+    remove_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
403
     systemctl restart nginx
404
     systemctl restart nginx
404
     systemctl restart php7.0-fpm
405
     systemctl restart php7.0-fpm
405
 }
406
 }
406
 
407
 
407
 function install_nextcloud_main {
408
 function install_nextcloud_main {
408
-    if [ ! $NEXTCLOUD_DOMAIN_NAME ]; then
409
+    if [ ! "$NEXTCLOUD_DOMAIN_NAME" ]; then
409
         echo $'No domain name was given for nextcloud'
410
         echo $'No domain name was given for nextcloud'
410
         exit 7359
411
         exit 7359
411
     fi
412
     fi
434
     fi
435
     fi
435
     sed -i 's|;env[PATH]|env[PATH]|g' /etc/php/7.0/fpm/pool.d/www.conf
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
     fi
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
         if [ -d /repos/nextcloud ]; then
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
             git pull
447
             git pull
447
         else
448
         else
448
             function_check git_clone
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
         fi
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
             echo $'Unable to clone nextcloud repo'
454
             echo $'Unable to clone nextcloud repo'
454
             exit 87525
455
             exit 87525
455
         fi
456
         fi
456
     fi
457
     fi
457
 
458
 
458
-    cd /var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs
459
+    cd "/var/www/$NEXTCLOUD_DOMAIN_NAME/htdocs" || exit 3468346834
459
     git submodule update --init
460
     git submodule update --init
460
     git checkout $NEXTCLOUD_COMMIT -b $NEXTCLOUD_COMMIT
461
     git checkout $NEXTCLOUD_COMMIT -b $NEXTCLOUD_COMMIT
461
     set_completion_param "nextcloud commit" "$NEXTCLOUD_COMMIT"
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
     function_check nextcloud_create_database
467
     function_check nextcloud_create_database
467
     nextcloud_create_database
468
     nextcloud_create_database
474
     fi
475
     fi
475
 
476
 
476
     function_check add_ddns_domain
477
     function_check add_ddns_domain
477
-    add_ddns_domain $NEXTCLOUD_DOMAIN_NAME
478
+    add_ddns_domain "$NEXTCLOUD_DOMAIN_NAME"
478
 
479
 
479
     nextcloud_nginx_site=/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
480
     nextcloud_nginx_site=/etc/nginx/sites-available/$NEXTCLOUD_DOMAIN_NAME
480
     if [[ $ONION_ONLY == "no" ]]; then
481
     if [[ $ONION_ONLY == "no" ]]; then
481
         function_check nginx_http_redirect
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
         function_check nginx_ssl
490
         function_check nginx_ssl
490
-        nginx_ssl $NEXTCLOUD_DOMAIN_NAME mobile
491
+        nginx_ssl "$NEXTCLOUD_DOMAIN_NAME" mobile
491
 
492
 
492
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
550
     else
550
-        echo -n '' > $nextcloud_nginx_site
551
+        echo -n '' > "$nextcloud_nginx_site"
551
     fi
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     # NextCloud doesn't like content-security-policy at all
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
     function_check configure_php
618
     function_check configure_php
618
     configure_php
619
     configure_php
619
 
620
 
620
     function_check create_site_certificate
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
             echo $'Certificate not generated for nextcloud'
626
             echo $'Certificate not generated for nextcloud'
626
             exit 725762
627
             exit 725762
627
         fi
628
         fi
636
     backup_database_local nextcloud
637
     backup_database_local nextcloud
637
 
638
 
638
     function_check nginx_ensite
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
     NEXTCLOUD_ONION_HOSTNAME=$(add_onion_service nextcloud 80 ${NEXTCLOUD_ONION_PORT})
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
     systemctl restart php7.0-fpm
644
     systemctl restart php7.0-fpm
657
     systemctl restart nginx
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
     if [ -d config ]; then
652
     if [ -d config ]; then
665
         chown -R www-data:www-data config
653
         chown -R www-data:www-data config
666
     fi
654
     fi
669
     fi
657
     fi
670
 
658
 
671
     chmod +x occ
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
     if [ ! -d data ]; then
661
     if [ ! -d data ]; then
674
         echo $'Nextcloud data directory was not found. This probably means that the installation failed.'
662
         echo $'Nextcloud data directory was not found. This probably means that the installation failed.'
675
         echo ''
663
         echo ''
683
     sudo -u www-data ./occ status
671
     sudo -u www-data ./occ status
684
     sudo -u www-data ./occ app:list
672
     sudo -u www-data ./occ app:list
685
     sudo -u www-data ./occ app:enable encryption
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
         echo $'Encryption not enabled'
675
         echo $'Encryption not enabled'
689
         exit 73527
676
         exit 73527
690
     fi
677
     fi
691
     sudo -u www-data ./occ encryption:status
678
     sudo -u www-data ./occ encryption:status
692
     sudo -u www-data ./occ config:system:set appstoreenabled --value=false
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
     chmod 0644 .htaccess
682
     chmod 0644 .htaccess
696
     chmod 0750 data
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
     sudo -u www-data ./occ files:cleanup
687
     sudo -u www-data ./occ files:cleanup
701
     sudo -u www-data ./occ files:scan --all
688
     sudo -u www-data ./occ files:scan --all
702
     sudo -u www-data ./occ maintenance:repair
689
     sudo -u www-data ./occ maintenance:repair
705
     systemctl restart mariadb
692
     systemctl restart mariadb
706
 
693
 
707
     # move the data directory
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
     set_completion_param "nextcloud domain" "$NEXTCLOUD_DOMAIN_NAME"
698
     set_completion_param "nextcloud domain" "$NEXTCLOUD_DOMAIN_NAME"
712
 
699
 
714
 }
701
 }
715
 
702
 
716
 function install_nextcloud {
703
 function install_nextcloud {
717
-    if [ ! $ONION_ONLY ]; then
704
+    if [ ! "$ONION_ONLY" ]; then
718
         ONION_ONLY='no'
705
         ONION_ONLY='no'
719
     fi
706
     fi
720
 
707
 

+ 332
- 334
src/freedombone-app-peertube 查看文件

55
                     MY_EMAIL_ADDRESS)
55
                     MY_EMAIL_ADDRESS)
56
 
56
 
57
 function peertube_create_database {
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
     else
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
         fi
63
         fi
64
     fi
64
     fi
65
-    if [ ! $PEERTUBE_ADMIN_PASSWORD ]; then
65
+    if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
66
         return
66
         return
67
     fi
67
     fi
68
 
68
 
82
 }
82
 }
83
 
83
 
84
 function remove_user_peertube {
84
 function remove_user_peertube {
85
-    remove_username="$1"
85
+    echo -n ''
86
+#    remove_username="$1"
86
 }
87
 }
87
 
88
 
88
 function add_user_peertube {
89
 function add_user_peertube {
91
         return
92
         return
92
     fi
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
     echo '0'
98
     echo '0'
98
 }
99
 }
99
 
100
 
100
 function install_interactive_peertube {
101
 function install_interactive_peertube {
101
-    if [ ! $ONION_ONLY ]; then
102
+    if [ ! "$ONION_ONLY" ]; then
102
         ONION_ONLY='no'
103
         ONION_ONLY='no'
103
     fi
104
     fi
104
 
105
 
113
 }
114
 }
114
 
115
 
115
 function peertube_set_admin_email {
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
     dialog --title $"Set PeerTube administrator email address" \
119
     dialog --title $"Set PeerTube administrator email address" \
120
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
122
     sel=$?
123
     case $sel in
123
     case $sel in
124
-        0)  peertube_email=$(<$data)
124
+        0)  peertube_email=$(<"$data")
125
             if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
125
             if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
126
                 if [ ${#peertube_email} -gt 8 ]; then
126
                 if [ ${#peertube_email} -gt 8 ]; then
127
                     sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
127
                     sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
132
             fi
132
             fi
133
             ;;
133
             ;;
134
     esac
134
     esac
135
-    rm $data
135
+    rm -f "$data"
136
 }
136
 }
137
 
137
 
138
 function peertube_disable_signups {
138
 function peertube_disable_signups {
139
     dialog --title $"Disable PeerTube signups" \
139
     dialog --title $"Disable PeerTube signups" \
140
            --backtitle $"Freedombone Control Panel" \
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
     sel=$?
142
     sel=$?
143
     case $sel in
143
     case $sel in
144
         0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
144
         0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
152
 function configure_interactive_peertube {
152
 function configure_interactive_peertube {
153
     while true
153
     while true
154
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
156
         dialog --backtitle $"Freedombone Control Panel" \
158
                --title $"PeerTube" \
157
                --title $"PeerTube" \
159
                --radiolist $"Choose an operation:" 10 70 4 \
158
                --radiolist $"Choose an operation:" 10 70 4 \
160
                1 $"Set administrator email address" off \
159
                1 $"Set administrator email address" off \
161
                2 $"Disable or enable signups" off \
160
                2 $"Disable or enable signups" off \
162
-               3 $"Exit" on 2> $data
161
+               3 $"Exit" on 2> "$data"
163
         sel=$?
162
         sel=$?
164
         case $sel in
163
         case $sel in
165
             1) break;;
164
             1) break;;
166
             255) break;;
165
             255) break;;
167
         esac
166
         esac
168
-        case $(cat $data) in
167
+        case $(cat "$data") in
169
             1) peertube_set_admin_email;;
168
             1) peertube_set_admin_email;;
170
             2) peertube_disable_signups;;
169
             2) peertube_disable_signups;;
171
-            3) break;;
170
+            3) rm -f "$data"
171
+               break;;
172
         esac
172
         esac
173
+        rm -f "$data"
173
     done
174
     done
174
 }
175
 }
175
 
176
 
176
 function change_password_peertube {
177
 function change_password_peertube {
177
-    PEERTUBE_USERNAME="$1"
178
+#    PEERTUBE_USERNAME="$1"
178
     PEERTUBE_PASSWORD="$2"
179
     PEERTUBE_PASSWORD="$2"
179
     if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
180
     if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
180
         echo $'Peertube password is too short'
181
         echo $'Peertube password is too short'
181
         return
182
         return
182
     fi
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
 function reconfigure_peertube {
187
 function reconfigure_peertube {
195
 
196
 
196
     read_config_param PEERTUBE_DOMAIN_NAME
197
     read_config_param PEERTUBE_DOMAIN_NAME
197
     systemctl stop peertube
198
     systemctl stop peertube
198
-    cd $PEERTUBE_DIR
199
+    cd "$PEERTUBE_DIR" || exit 7824552627
199
 
200
 
200
     function_check set_repo_commit
201
     function_check set_repo_commit
201
     set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
202
     set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
207
 
208
 
208
 function backup_local_peertube {
209
 function backup_local_peertube {
209
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
212
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
212
     fi
213
     fi
213
 
214
 
219
 
220
 
220
     peertube_path=$PEERTUBE_DIR/videos
221
     peertube_path=$PEERTUBE_DIR/videos
221
     if [ -d $peertube_path ]; then
222
     if [ -d $peertube_path ]; then
222
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
223
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
223
         systemctl stop peertube
224
         systemctl stop peertube
224
         backup_directory_to_usb $peertube_path peertubevideos
225
         backup_directory_to_usb $peertube_path peertubevideos
225
         systemctl start peertube
226
         systemctl start peertube
229
 
230
 
230
 function restore_local_peertube {
231
 function restore_local_peertube {
231
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
234
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
234
     fi
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
         systemctl stop peertube
238
         systemctl stop peertube
238
 
239
 
239
         USE_POSTGRESQL=1
240
         USE_POSTGRESQL=1
259
 
260
 
260
 function backup_remote_peertube {
261
 function backup_remote_peertube {
261
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
264
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
264
     fi
265
     fi
265
 
266
 
272
     temp_backup_dir=$PEERTUBE_DIR/videos
273
     temp_backup_dir=$PEERTUBE_DIR/videos
273
     if [ -d $temp_backup_dir ]; then
274
     if [ -d $temp_backup_dir ]; then
274
         systemctl stop peertube
275
         systemctl stop peertube
275
-        suspend_site ${PEERTUBE_DOMAIN_NAME}
276
+        suspend_site "${PEERTUBE_DOMAIN_NAME}"
276
         backup_directory_to_friend $temp_backup_dir peertubevideos
277
         backup_directory_to_friend $temp_backup_dir peertubevideos
277
         restart_site
278
         restart_site
278
         systemctl start peertube
279
         systemctl start peertube
284
 
285
 
285
 function restore_remote_peertube {
286
 function restore_remote_peertube {
286
     PEERTUBE_DOMAIN_NAME='peertube.local'
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
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
289
         PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
289
     fi
290
     fi
290
-    suspend_site ${PEERTUBE_DOMAIN_NAME}
291
+    suspend_site "${PEERTUBE_DOMAIN_NAME}"
291
 
292
 
292
     systemctl stop peertube
293
     systemctl stop peertube
293
 
294
 
295
+    # shellcheck disable=SC2034
294
     USE_POSTGRESQL=1
296
     USE_POSTGRESQL=1
295
     function_check restore_database_from_friend
297
     function_check restore_database_from_friend
296
     restore_database_from_friend peertube
298
     restore_database_from_friend peertube
326
     remove_nodejs peertube
328
     remove_nodejs peertube
327
 
329
 
328
     read_config_param "PEERTUBE_DOMAIN_NAME"
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
     fi
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
     fi
338
     fi
337
     remove_config_param PEERTUBE_DOMAIN_NAME
339
     remove_config_param PEERTUBE_DOMAIN_NAME
338
     remove_config_param PEERTUBE_CODE
340
     remove_config_param PEERTUBE_CODE
339
     function_check remove_onion_service
341
     function_check remove_onion_service
340
     remove_onion_service peertube ${PEERTUBE_ONION_PORT}
342
     remove_onion_service peertube ${PEERTUBE_ONION_PORT}
341
     remove_completion_param "install_peertube"
343
     remove_completion_param "install_peertube"
342
-    sed -i '/peertube/d' $COMPLETION_FILE
344
+    sed -i '/peertube/d' "$COMPLETION_FILE"
343
 
345
 
344
     function_check drop_database_postgresql
346
     function_check drop_database_postgresql
345
     drop_database_postgresql peertube peertube
347
     drop_database_postgresql peertube peertube
352
     fi
354
     fi
353
 
355
 
354
     function_check remove_ddns_domain
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
 function peertube_setup_web {
360
 function peertube_setup_web {
359
     peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
361
     peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
360
 
362
 
361
     if [[ $ONION_ONLY == "no" ]]; then
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
         function_check nginx_ssl
376
         function_check nginx_ssl
375
-        nginx_ssl $PEERTUBE_DOMAIN_NAME mobile
377
+        nginx_ssl "$PEERTUBE_DOMAIN_NAME" mobile
376
 
378
 
377
         function_check nginx_disable_sniffing
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
     else
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
     # CSP currently causes an error
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
     function_check create_site_certificate
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
     function_check nginx_ensite
484
     function_check nginx_ensite
483
-    nginx_ensite $PEERTUBE_DOMAIN_NAME
485
+    nginx_ensite "$PEERTUBE_DOMAIN_NAME"
484
 }
486
 }
485
 
487
 
486
 function mesh_peertube_setup_web {
488
 function mesh_peertube_setup_web {
489
+    # shellcheck disable=SC2154
487
     peertube_nginx_file=$rootdir/etc/nginx/sites-available/peertube
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
 function peertube_create_config {
542
 function peertube_create_config {
541
 
544
 
542
     peertube_config_file=$peertube_prefix$PEERTUBE_DIR/config/production.yaml
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
         else
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
         fi
561
         fi
559
     else
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
     else
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
 function mesh_install_peertube {
620
 function mesh_install_peertube {
618
-    if [[ $VARIANT != "meshclient" && $VARIANT != "meshusb" ]]; then
621
+    # shellcheck disable=SC2153
622
+    if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
619
         return
623
         return
620
     fi
624
     fi
621
-    if [[ $ARCHITECTURE != 'x86_64' && $ARCHITECTURE != 'amd64' ]]; then
625
+    if [[ "$ARCHITECTURE" != 'x86_64' && "$ARCHITECTURE" != 'amd64' ]]; then
622
         return
626
         return
623
     fi
627
     fi
624
 
628
 
627
     function_check install_postgresql
631
     function_check install_postgresql
628
     install_postgresql
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
     fi
636
     fi
633
 
637
 
634
-    git clone $PEERTUBE_REPO $rootdir$PEERTUBE_DIR
638
+    git clone "$PEERTUBE_REPO" "$rootdir$PEERTUBE_DIR"
635
 
639
 
636
     chroot "$rootdir" groupadd peertube
640
     chroot "$rootdir" groupadd peertube
637
     chroot "$rootdir" useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
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
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
644
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
641
 
645
 
642
-
643
     get_npm_arch
646
     get_npm_arch
644
 
647
 
645
-    cat <<EOF > $rootdir/usr/bin/install_peertube
648
+    cat <<EOF > "$rootdir/usr/bin/install_peertube"
646
 #!/bin/bash
649
 #!/bin/bash
647
 cd $PEERTUBE_DIR
650
 cd $PEERTUBE_DIR
648
 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
651
 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
683
     exit 5293593
686
     exit 5293593
684
 fi
687
 fi
685
 EOF
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
         echo $'PeerTube install failed'
691
         echo $'PeerTube install failed'
690
         exit 735638
692
         exit 735638
691
     fi
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
     chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
717
     chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
716
 
718
 
730
         ONION_ONLY='no'
732
         ONION_ONLY='no'
731
     fi
733
     fi
732
 
734
 
733
-    if [ ! $PEERTUBE_DOMAIN_NAME ]; then
735
+    if [ ! "$PEERTUBE_DOMAIN_NAME" ]; then
734
         echo $'The peertube domain name was not specified'
736
         echo $'The peertube domain name was not specified'
735
         exit 783523
737
         exit 783523
736
     fi
738
     fi
740
     function_check install_postgresql
742
     function_check install_postgresql
741
     install_postgresql
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
     fi
747
     fi
746
 
748
 
747
     if [ -d $PEERTUBE_DIR ]; then
749
     if [ -d $PEERTUBE_DIR ]; then
759
     if [ -d /repos/peertube ]; then
761
     if [ -d /repos/peertube ]; then
760
         mkdir -p $PEERTUBE_DIR
762
         mkdir -p $PEERTUBE_DIR
761
         cp -r -p /repos/peertube/. $PEERTUBE_DIR
763
         cp -r -p /repos/peertube/. $PEERTUBE_DIR
762
-        cd $PEERTUBE_DIR
764
+        cd "$PEERTUBE_DIR" || exit 642874682
763
         git pull
765
         git pull
764
     else
766
     else
765
         function_check git_clone
767
         function_check git_clone
766
         git_clone $PEERTUBE_REPO $PEERTUBE_DIR
768
         git_clone $PEERTUBE_REPO $PEERTUBE_DIR
767
     fi
769
     fi
768
 
770
 
769
-    cd $PEERTUBE_DIR
771
+    cd "$PEERTUBE_DIR" || exit 27492742
770
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
772
     git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
771
     set_completion_param "peertube commit" "$PEERTUBE_COMMIT"
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
         echo $'Failed to install yarn'
776
         echo $'Failed to install yarn'
776
         exit 79353234
777
         exit 79353234
777
     fi
778
     fi
778
     yarn add -D webpack --network-concurrency 1
779
     yarn add -D webpack --network-concurrency 1
779
-    yarn install
780
-    if [ ! "$?" = "0" ]; then
780
+    if ! yarn install; then
781
         echo $'Failed to run yarn install'
781
         echo $'Failed to run yarn install'
782
         exit 63754235
782
         exit 63754235
783
     fi
783
     fi
784
-    npm install
785
-    if [ ! "$?" = "0" ]; then
784
+    if ! npm install; then
786
         echo $'Failed to install peertube'
785
         echo $'Failed to install peertube'
787
         exit 7835243
786
         exit 7835243
788
     fi
787
     fi
789
-    npm run build
790
-    if [ ! "$?" = "0" ]; then
788
+    if ! npm run build; then
791
         echo $'Failed to build peertube'
789
         echo $'Failed to build peertube'
792
         exit 5293593
790
         exit 5293593
793
     fi
791
     fi
794
 
792
 
795
     PEERTUBE_ONION_HOSTNAME=$(add_onion_service peertube 80 ${PEERTUBE_ONION_PORT})
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
     peertube_create_config
815
     peertube_create_config
818
 
816
 
820
 
818
 
821
     peertube_setup_web
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
     function_check add_ddns_domain
823
     function_check add_ddns_domain
826
-    add_ddns_domain $PEERTUBE_DOMAIN_NAME
824
+    add_ddns_domain "$PEERTUBE_DOMAIN_NAME"
827
 
825
 
828
     systemctl enable peertube
826
     systemctl enable peertube
829
     systemctl daemon-reload
827
     systemctl daemon-reload

+ 283
- 272
src/freedombone-app-pelican 查看文件

50
                    PELICAN_BLOG_CODE)
50
                    PELICAN_BLOG_CODE)
51
 
51
 
52
 function pelican_remove_bad_blog_links {
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
 function logging_on_pelican {
61
 function logging_on_pelican {
73
     fi
73
     fi
74
     function_check nginx_http_redirect
74
     function_check nginx_http_redirect
75
     nginx_http_redirect $PELICAN_DOMAIN_NAME
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
     function_check nginx_ssl
85
     function_check nginx_ssl
86
-    nginx_ssl $PELICAN_DOMAIN_NAME
86
+    nginx_ssl "$PELICAN_DOMAIN_NAME"
87
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check create_site_certificate
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
 function install_pelican_website_onion {
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
 function pelican_editor_config {
156
 function pelican_editor_config {
157
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.emacs-pelican ]; then
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
     fi
174
     fi
175
 }
175
 }
176
 
176
 
179
     echo ''
179
     echo ''
180
     echo $'Regenerating blog...'
180
     echo $'Regenerating blog...'
181
 
181
 
182
-    cd $PELICAN_BLOG_INSTALL_DIR
182
+    cd "$PELICAN_BLOG_INSTALL_DIR" || exit 463856348
183
     make html
183
     make html
184
     cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
184
     cp -r $PELICAN_BLOG_INSTALL_DIR/output/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
185
     chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
185
     chown -R www-data:www-data /var/www/$PELICAN_DOMAIN_NAME/htdocs
189
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
189
     DATESTR=$(date "+%Y-%m-%d %H:%M:%S")
190
 
190
 
191
     if [ ! -f $PELICAN_BLOG_INSTALL_DIR/.new-blog-entry ]; then
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
     fi
205
     fi
206
 
206
 
207
     if [ -f /usr/bin/emacs ]; then
207
     if [ -f /usr/bin/emacs ]; then
222
 
222
 
223
     # move to the content directory
223
     # move to the content directory
224
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
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
     # increment the index
227
     # increment the index
228
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
228
     CURRENT_INDEX=$((CURRENT_INDEX + 1))
238
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
238
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
239
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
239
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
240
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
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
         return
242
         return
243
     fi
243
     fi
244
 
244
 
245
     if [ -f /usr/bin/emacs ]; then
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
     else
247
     else
248
-        editor $LAST_BLOG_ENTRY
248
+        editor "$LAST_BLOG_ENTRY"
249
     fi
249
     fi
250
 
250
 
251
     pelican_regenerate_blog
251
     pelican_regenerate_blog
258
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
258
     CURRENT_INDEX=$(cat $PELICAN_CURRENT_BLOG_INDEX)
259
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
259
     PREVIOUS_INDEX=$((CURRENT_INDEX - 1))
260
     LAST_BLOG_ENTRY=$BLOG_CONTENT_PATH/${PREVIOUS_INDEX}_post.md
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
         return
262
         return
263
     fi
263
     fi
264
 
264
 
265
     dialog --title $"Delete the previous blog entry" \
265
     dialog --title $"Delete the previous blog entry" \
266
            --backtitle $"Freedombone Mesh" \
266
            --backtitle $"Freedombone Mesh" \
267
            --defaultno \
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
     sel=$?
269
     sel=$?
270
     case $sel in
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
                CURRENT_INDEX=$PREVIOUS_INDEX
273
                CURRENT_INDEX=$PREVIOUS_INDEX
274
                echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
274
                echo "$CURRENT_INDEX" > $PELICAN_CURRENT_BLOG_INDEX
275
            else
275
            else
297
     for a in "${THEMES[@]}"
297
     for a in "${THEMES[@]}"
298
     do
298
     do
299
         is_selected='off'
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
                 is_selected='on'
302
                 is_selected='on'
303
             fi
303
             fi
304
         else
304
         else
308
         fi
308
         fi
309
 
309
 
310
         themelist="$themelist $n $a $is_selected"
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
     done
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
     dialog --backtitle $"Freedombone Mesh" \
316
     dialog --backtitle $"Freedombone Mesh" \
318
            --title $"Select Blog Theme" \
317
            --title $"Select Blog Theme" \
319
            --radiolist $'Choose:' \
318
            --radiolist $'Choose:' \
320
-           80 40 20 $themelist 2> $data
319
+           80 40 20 "$themelist" 2> "$data"
321
     sel=$?
320
     sel=$?
322
     case $sel in
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
     esac
326
     esac
326
-    CHOSEN_THEME_INDEX=$(cat $data)
327
+    CHOSEN_THEME_INDEX=$(cat "$data")
328
+    rm -f "$data"
327
     echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
329
     echo "$CHOSEN_THEME_INDEX" > $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index
328
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
330
     CHOSEN_THEME_INDEX=$((CHOSEN_THEME_INDEX - 1))
329
 
331
 
330
     CHOSEN_THEME=${THEMES[$CHOSEN_THEME_INDEX]}
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
     pelican_remove_bad_blog_links
335
     pelican_remove_bad_blog_links
334
 
336
 
335
     if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
337
     if grep -q "THEME=" $PELICAN_BLOG_INSTALL_DIR/pelicanconf.py; then
341
 }
343
 }
342
 
344
 
343
 function configure_interactive_pelican {
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
     dialog --backtitle $"Freedombone Configuration" \
347
     dialog --backtitle $"Freedombone Configuration" \
347
            --title $"Pelican Blogging" \
348
            --title $"Pelican Blogging" \
348
            --radiolist $"Choose an operation:" 18 50 11 \
349
            --radiolist $"Choose an operation:" 18 50 11 \
350
            2 $"Edit the previous blog entry" off \
351
            2 $"Edit the previous blog entry" off \
351
            3 $"Delete the previous blog entry" off \
352
            3 $"Delete the previous blog entry" off \
352
            4 $"Change theme" off \
353
            4 $"Change theme" off \
353
-           5 $"Exit" off 2> $data
354
+           5 $"Exit" off 2> "$data"
354
     sel=$?
355
     sel=$?
355
     case $sel in
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
     esac
361
     esac
359
-    case $(cat $data) in
362
+    case $(cat "$data") in
360
         1) pelican_new_blog;;
363
         1) pelican_new_blog;;
361
         2) pelican_edit_blog;;
364
         2) pelican_edit_blog;;
362
         3) pelican_delete_blog;;
365
         3) pelican_delete_blog;;
363
         4) pelican_change_theme;;
366
         4) pelican_change_theme;;
364
-        5) break;;
365
     esac
367
     esac
368
+    rm -f "$data"
366
 }
369
 }
367
 
370
 
368
 function install_interactive_pelican {
371
 function install_interactive_pelican {
369
-    if [ ! $ONION_ONLY ]; then
372
+    if [ ! "$ONION_ONLY" ]; then
370
         ONION_ONLY='no'
373
         ONION_ONLY='no'
371
     fi
374
     fi
372
 
375
 
376
         PELICAN_DETAILS_COMPLETE=
379
         PELICAN_DETAILS_COMPLETE=
377
         while [ ! $PELICAN_DETAILS_COMPLETE ]
380
         while [ ! $PELICAN_DETAILS_COMPLETE ]
378
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
383
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
382
                 dialog --backtitle $"Freedombone Configuration" \
384
                 dialog --backtitle $"Freedombone Configuration" \
383
                        --title $"Pelican Blog Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
387
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
386
                        $"Code:" 2 1 "$(grep 'PELICAN_BLOG_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
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
             else
390
             else
389
                 dialog --backtitle $"Freedombone Configuration" \
391
                 dialog --backtitle $"Freedombone Configuration" \
390
                        --title $"Pelican Blog Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PELICAN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
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
             fi
396
             fi
395
             sel=$?
397
             sel=$?
396
             case $sel in
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
             esac
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
                 if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
406
                 if [[ $PELICAN_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
403
                     PELICAN_DOMAIN_NAME=""
407
                     PELICAN_DOMAIN_NAME=""
404
                 fi
408
                 fi
405
                 TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
409
                 TEST_DOMAIN_NAME=$PELICAN_DOMAIN_NAME
406
                 validate_domain_name
410
                 validate_domain_name
407
-                if [[ $TEST_DOMAIN_NAME != $PELICAN_DOMAIN_NAME ]]; then
411
+                if [[ "$TEST_DOMAIN_NAME" != "$PELICAN_DOMAIN_NAME" ]]; then
408
                     PELICAN_DOMAIN_NAME=
412
                     PELICAN_DOMAIN_NAME=
409
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
413
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
410
                 else
414
                 else
411
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$PELICAN_BLOG_CODE"
417
                         validate_freedns_code "$PELICAN_BLOG_CODE"
414
-                        if [ ! $VALID_CODE ]; then
418
+                        if [ ! "$VALID_CODE" ]; then
415
                             PELICAN_DOMAIN_NAME=
419
                             PELICAN_DOMAIN_NAME=
416
                         fi
420
                         fi
417
                     fi
421
                     fi
420
             if [ $PELICAN_DOMAIN_NAME ]; then
424
             if [ $PELICAN_DOMAIN_NAME ]; then
421
                 PELICAN_DETAILS_COMPLETE="yes"
425
                 PELICAN_DETAILS_COMPLETE="yes"
422
             fi
426
             fi
427
+            rm -f "$data"
423
         done
428
         done
424
 
429
 
425
         # save the results in the config file
430
         # save the results in the config file
454
 
459
 
455
 function restore_local_pelican {
460
 function restore_local_pelican {
456
     if [ -d /etc/blog ]; then
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
             temp_restore_dir=/root/temppelican
463
             temp_restore_dir=/root/temppelican
459
             function_check restore_directory_from_usb
464
             function_check restore_directory_from_usb
460
             restore_directory_from_usb $temp_restore_dir pelican
465
             restore_directory_from_usb $temp_restore_dir pelican
463
             else
468
             else
464
                 cp -r $temp_restore_dir/* /etc/blog/
469
                 cp -r $temp_restore_dir/* /etc/blog/
465
             fi
470
             fi
471
+            # shellcheck disable=SC2181
466
             if [ ! "$?" = "0" ]; then
472
             if [ ! "$?" = "0" ]; then
467
                 rm -rf $temp_restore_dir
473
                 rm -rf $temp_restore_dir
468
                 function_check set_user_permissions
474
                 function_check set_user_permissions
475
         fi
481
         fi
476
     fi
482
     fi
477
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
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
             temp_restore_dir=/root/temppelican-site
485
             temp_restore_dir=/root/temppelican-site
480
             function_check restore_directory_from_usb
486
             function_check restore_directory_from_usb
481
             restore_directory_from_usb $temp_restore_dir pelican-site
487
             restore_directory_from_usb $temp_restore_dir pelican-site
484
             else
490
             else
485
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
491
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
486
             fi
492
             fi
493
+            # shellcheck disable=SC2181
487
             if [ ! "$?" = "0" ]; then
494
             if [ ! "$?" = "0" ]; then
488
                 rm -rf $temp_restore_dir
495
                 rm -rf $temp_restore_dir
489
                 function_check set_user_permissions
496
                 function_check set_user_permissions
508
 
515
 
509
 function restore_remote_pelican {
516
 function restore_remote_pelican {
510
     if [ -d /etc/blog ]; then
517
     if [ -d /etc/blog ]; then
511
-        if [ -d $SERVER_DIRECTORY/backup/pelican ]; then
518
+        if [ -d "$SERVER_DIRECTORY/backup/pelican" ]; then
512
             temp_restore_dir=/root/temppelican
519
             temp_restore_dir=/root/temppelican
513
             function_check restore_directory_from_friend
520
             function_check restore_directory_from_friend
514
             restore_directory_from_friend $temp_restore_dir pelican
521
             restore_directory_from_friend $temp_restore_dir pelican
517
             else
524
             else
518
                 cp -r $temp_restore_dir/* /etc/blog/
525
                 cp -r $temp_restore_dir/* /etc/blog/
519
             fi
526
             fi
527
+            # shellcheck disable=SC2181
520
             if [ ! "$?" = "0" ]; then
528
             if [ ! "$?" = "0" ]; then
521
                 exit 782352
529
                 exit 782352
522
             fi
530
             fi
524
         fi
532
         fi
525
     fi
533
     fi
526
     if [ -d /var/www/$PELICAN_DOMAIN_NAME/htdocs ]; then
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
             temp_restore_dir=/root/temppelican-site
536
             temp_restore_dir=/root/temppelican-site
529
             function_check restore_directory_from_friend
537
             function_check restore_directory_from_friend
530
             restore_directory_from_friend $temp_restore_dir pelican-site
538
             restore_directory_from_friend $temp_restore_dir pelican-site
533
             else
541
             else
534
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
542
                 cp -r $temp_restore_dir/* /var/www/$PELICAN_DOMAIN_NAME/htdocs/
535
             fi
543
             fi
544
+            # shellcheck disable=SC2181
536
             if [ ! "$?" = "0" ]; then
545
             if [ ! "$?" = "0" ]; then
537
                 exit 76382562
546
                 exit 76382562
538
             fi
547
             fi
561
 }
570
 }
562
 
571
 
563
 function create_pelican_conf {
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
 function create_pelican_makefile {
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
 function create_pelican_publish_conf {
660
 function create_pelican_publish_conf {
652
     STATIC_BLOG_FILE=$1
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
 function pelican_themes {
681
 function pelican_themes {
747
 }
756
 }
748
 
757
 
749
 function mesh_install_pelican {
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
         return
761
         return
752
     fi
762
     fi
753
 
763
 
764
+    # shellcheck disable=SC2154
754
     chroot "$rootdir" apt-get -yq install python-pip
765
     chroot "$rootdir" apt-get -yq install python-pip
755
     chroot "$rootdir" pip install ipython
766
     chroot "$rootdir" pip install ipython
756
     chroot "$rootdir" pip install Markdown
767
     chroot "$rootdir" pip install Markdown
760
     PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
771
     PELICAN_BLOG_INSTALL_DIR=/home/$MY_USERNAME/CreateBlog
761
     PELICAN_BLOG_PATH=/home/$MY_USERNAME/Public/Blog
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
     fi
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
     fi
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
     fi
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
     pelican_themes
792
     pelican_themes
782
 
793
 
783
     #git clone --recursive $PELICAN_PLUGINS_REPO $rootdir$PELICAN_BLOG_INSTALL_DIR/plugins
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
 function install_pelican {
800
 function install_pelican {
790
-    if [ $INSTALLING_MESH ]; then
801
+    if [ "$INSTALLING_MESH" ]; then
791
         mesh_install_pelican
802
         mesh_install_pelican
792
         return
803
         return
793
     fi
804
     fi
800
 
811
 
801
     PELICAN_BLOG_PATH=/var/www/$PELICAN_DOMAIN_NAME/htdocs
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
     fi
816
     fi
806
 
817
 
807
     if [ ! -d $PELICAN_BLOG_PATH ]; then
818
     if [ ! -d $PELICAN_BLOG_PATH ]; then
808
         mkdir -p $PELICAN_BLOG_PATH
819
         mkdir -p $PELICAN_BLOG_PATH
809
     fi
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
     fi
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
     pelican_themes
832
     pelican_themes
822
 
833
 
823
     #git clone --recursive $PELICAN_PLUGINS_REPO $PELICAN_BLOG_INSTALL_DIR/plugins
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
     chown -R www-data:www-data $PELICAN_BLOG_PATH
837
     chown -R www-data:www-data $PELICAN_BLOG_PATH
827
 
838
 
828
     pelican_editor_config
839
     pelican_editor_config
834
     install_pelican_website_onion
845
     install_pelican_website_onion
835
 
846
 
836
     pelican_regenerate_blog
847
     pelican_regenerate_blog
837
-    if [ ! -d $PELICAN_BLOG_INSTALL_DIR/output ]; then
848
+    if [ ! -d "$PELICAN_BLOG_INSTALL_DIR/output" ]; then
838
         echo $'Failed to generate pelican blog'
849
         echo $'Failed to generate pelican blog'
839
         exit 521892
850
         exit 521892
840
     fi
851
     fi

+ 54
- 48
src/freedombone-app-pihole 查看文件

66
     if [ ! -d /etc/.pihole ]; then
66
     if [ ! -d /etc/.pihole ]; then
67
         mkdir /etc/.pihole
67
         mkdir /etc/.pihole
68
     fi
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
     if [ ! -f $PIHOLE_CUSTOM_ADLIST ]; then
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
     fi
73
     fi
74
-    cp $INSTALL_DIR/pihole/advanced/Scripts/* /opt/$piholeBasename
74
+    cp "$INSTALL_DIR/pihole/advanced/Scripts/*" /opt/$piholeBasename
75
     if [ -f /etc/dnsmasq.d/01-pihole.conf ]; then
75
     if [ -f /etc/dnsmasq.d/01-pihole.conf ]; then
76
         rm /etc/dnsmasq.d/01-pihole.conf
76
         rm /etc/dnsmasq.d/01-pihole.conf
77
     fi
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
     chmod +x /opt/pihole/*.sh
80
     chmod +x /opt/pihole/*.sh
81
 }
81
 }
82
 
82
 
95
         return
95
         return
96
     fi
96
     fi
97
 
97
 
98
-    if [ ! -f $HOME/${PROJECT_NAME}-wifi.cfg ]; then
98
+    if [ ! -f "$HOME/${PROJECT_NAME}-wifi.cfg" ]; then
99
         PIHOLE_IFACE=eth0
99
         PIHOLE_IFACE=eth0
100
     else
100
     else
101
         read_config_param WIFI_INTERFACE
101
         read_config_param WIFI_INTERFACE
114
     echo "piholeDNS1=${PIHOLE_DNS1}" >> ${setupVars}
114
     echo "piholeDNS1=${PIHOLE_DNS1}" >> ${setupVars}
115
     echo "piholeDNS2=${PIHOLE_DNS1}" >> ${setupVars}
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
     pihole -g
125
     pihole -g
126
     systemctl restart dnsmasq
126
     systemctl restart dnsmasq
132
 }
132
 }
133
 
133
 
134
 function pihole_change_upstream_dns {
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
     dialog --backtitle $"Ad Blocker Upstream DNS" \
136
     dialog --backtitle $"Ad Blocker Upstream DNS" \
138
            --radiolist $"Pick a domain name service (DNS):" 28 50 19 \
137
            --radiolist $"Pick a domain name service (DNS):" 28 50 19 \
139
            1 $"Digital Courage" on \
138
            1 $"Digital Courage" on \
154
            16 $"DNS.Watch" off \
153
            16 $"DNS.Watch" off \
155
            17 $"uncensoreddns.org" off \
154
            17 $"uncensoreddns.org" off \
156
            18 $"Lorraine Data Network" off \
155
            18 $"Lorraine Data Network" off \
157
-           19 $"Google" off 2> $data
156
+           19 $"Google" off 2> "$data"
158
     sel=$?
157
     sel=$?
159
     case $sel in
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
     esac
163
     esac
163
-    case $(cat $data) in
164
+    case $(cat "$data") in
164
         1) PIHOLE_DNS1='85.214.73.63'
165
         1) PIHOLE_DNS1='85.214.73.63'
165
            PIHOLE_DNS2='213.73.91.35'
166
            PIHOLE_DNS2='213.73.91.35'
166
            ;;
167
            ;;
218
         19) PIHOLE_DNS1='8.8.8.8'
219
         19) PIHOLE_DNS1='8.8.8.8'
219
             PIHOLE_DNS2='4.4.4.4'
220
             PIHOLE_DNS2='4.4.4.4'
220
             dialog --title $"WARNING" \
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
     esac
226
     esac
227
+    rm -f "$data"
225
     write_config_param "PIHOLE_DNS1" "$PIHOLE_DNS1"
228
     write_config_param "PIHOLE_DNS1" "$PIHOLE_DNS1"
226
     write_config_param "PIHOLE_DNS2" "$PIHOLE_DNS2"
229
     write_config_param "PIHOLE_DNS2" "$PIHOLE_DNS2"
227
 }
230
 }
252
 function configure_interactive_pihole {
255
 function configure_interactive_pihole {
253
     while true
256
     while true
254
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
259
         dialog --backtitle $"Freedombone Control Panel" \
258
                --title $"Ad Blocker" \
260
                --title $"Ad Blocker" \
259
                --radiolist $"Choose an operation:" 16 70 7 \
261
                --radiolist $"Choose an operation:" 16 70 7 \
263
                4 $"Change upstream DNS servers" off \
265
                4 $"Change upstream DNS servers" off \
264
                5 $"Pause blocker" off \
266
                5 $"Pause blocker" off \
265
                6 $"Resume blocker" off \
267
                6 $"Resume blocker" off \
266
-               7 $"Exit" on 2> $data
268
+               7 $"Exit" on 2> "$data"
267
         sel=$?
269
         sel=$?
268
         case $sel in
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
         esac
275
         esac
272
-        case $(cat $data) in
276
+        case $(cat "$data") in
273
             1) editor $PIHOLE_CUSTOM_ADLIST
277
             1) editor $PIHOLE_CUSTOM_ADLIST
274
                update_pihole_interactive
278
                update_pihole_interactive
275
                ;;
279
                ;;
286
                ;;
290
                ;;
287
             6) pihole_resume
291
             6) pihole_resume
288
                ;;
292
                ;;
289
-            7) break;;
293
+            7) rm -f "$data"
294
+               break;;
290
         esac
295
         esac
296
+        rm -f "$data"
291
     done
297
     done
292
 }
298
 }
293
 
299
 
306
     fi
312
     fi
307
 
313
 
308
     function_check set_repo_commit
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
     pihole_copy_files
317
     pihole_copy_files
312
     pihole_update
318
     pihole_update
367
         rm /etc/cron.d/pihole
373
         rm /etc/cron.d/pihole
368
     fi
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
     fi
378
     fi
373
 
379
 
374
     firewall_remove 53
380
     firewall_remove 53
391
 
397
 
392
     systemctl enable dnsmasq
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
     fi
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
         if [ -d /repos/pihole ]; then
407
         if [ -d /repos/pihole ]; then
402
             mkdir pihole
408
             mkdir pihole
403
             cp -r -p /repos/pihole/. pihole
409
             cp -r -p /repos/pihole/. pihole
404
-            cd pihole
410
+            cd pihole || exit 24572424684
405
             git pull
411
             git pull
406
         else
412
         else
407
             git_clone $PIHOLE_REPO pihole
413
             git_clone $PIHOLE_REPO pihole
408
         fi
414
         fi
409
 
415
 
410
-        if [ ! -d $INSTALL_DIR/pihole ]; then
416
+        if [ ! -d "$INSTALL_DIR/pihole" ]; then
411
             exit 523925
417
             exit 523925
412
         fi
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
         set_completion_param "pihole commit" "$PIHOLE_COMMIT"
421
         set_completion_param "pihole commit" "$PIHOLE_COMMIT"
416
     fi
422
     fi
417
 
423
 
420
     fi
426
     fi
421
 
427
 
422
     # blank file which takes the place of ads
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
         exit 26738
435
         exit 26738
430
     fi
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
     chmod 755 /usr/local/bin/gravity.sh
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
         exit 52935
441
         exit 52935
436
     fi
442
     fi
437
-    cp $INSTALL_DIR/pihole/pihole /usr/local/bin/pihole
443
+    cp "$INSTALL_DIR/pihole/pihole" /usr/local/bin/pihole
438
     chmod 755 /usr/local/bin/pihole
444
     chmod 755 /usr/local/bin/pihole
439
 
445
 
440
     if [ ! -d $piholeDir ]; then
446
     if [ ! -d $piholeDir ]; then

+ 335
- 337
src/freedombone-app-pleroma
文件差异内容过多而无法显示
查看文件


+ 283
- 278
src/freedombone-app-postactiv
文件差异内容过多而无法显示
查看文件


+ 161
- 157
src/freedombone-app-privatebin 查看文件

56
     find "${pbpath}/" -type d -print0 | xargs -0 chmod 0550
56
     find "${pbpath}/" -type d -print0 | xargs -0 chmod 0550
57
 
57
 
58
     chown -R ${rootuser}:${htgroup} "${pbpath}/"
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
 function logging_on_privatebin {
62
 function logging_on_privatebin {
68
 }
68
 }
69
 
69
 
70
 function remove_user_privatebin {
70
 function remove_user_privatebin {
71
-    remove_username="$1"
71
+    echo -n ''
72
+#    remove_username="$1"
72
 }
73
 }
73
 
74
 
74
 function add_user_privatebin {
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
     echo '0'
79
     echo '0'
79
 }
80
 }
80
 
81
 
81
 function install_interactive_privatebin {
82
 function install_interactive_privatebin {
82
-    if [ ! $ONION_ONLY ]; then
83
+    if [ ! "$ONION_ONLY" ]; then
83
         ONION_ONLY='no'
84
         ONION_ONLY='no'
84
     fi
85
     fi
85
 
86
 
86
-    if [[ $ONION_ONLY != "no" ]]; then
87
+    if [[ "$ONION_ONLY" != "no" ]]; then
87
         PRIVATEBIN_DOMAIN_NAME='privatebin.local'
88
         PRIVATEBIN_DOMAIN_NAME='privatebin.local'
88
     else
89
     else
89
         PRIVATEBIN_DETAILS_COMPLETE=
90
         PRIVATEBIN_DETAILS_COMPLETE=
90
         while [ ! $PRIVATEBIN_DETAILS_COMPLETE ]
91
         while [ ! $PRIVATEBIN_DETAILS_COMPLETE ]
91
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
94
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
95
                 dialog --backtitle $"Freedombone Configuration" \
95
                 dialog --backtitle $"Freedombone Configuration" \
96
                        --title $"PrivateBin Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
98
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
99
                        $"Code:" 2 1 "$(grep 'PRIVATEBIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
99
                        $"Code:" 2 1 "$(grep 'PRIVATEBIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 33 255 \
100
-                       2> $data
100
+                       2> "$data"
101
             else
101
             else
102
                 dialog --backtitle $"Freedombone Configuration" \
102
                 dialog --backtitle $"Freedombone Configuration" \
103
                        --title $"PrivateBin Configuration" \
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
                        $"Domain:" 1 1 "$(grep 'PRIVATEBIN_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 33 40 \
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
             fi
107
             fi
108
             sel=$?
108
             sel=$?
109
             case $sel in
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
             esac
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
                     PRIVATEBIN_DOMAIN_NAME=""
118
                     PRIVATEBIN_DOMAIN_NAME=""
117
                 fi
119
                 fi
118
                 TEST_DOMAIN_NAME=$PRIVATEBIN_DOMAIN_NAME
120
                 TEST_DOMAIN_NAME=$PRIVATEBIN_DOMAIN_NAME
119
                 validate_domain_name
121
                 validate_domain_name
120
-                if [[ $TEST_DOMAIN_NAME != $PRIVATEBIN_DOMAIN_NAME ]]; then
122
+                if [[ "$TEST_DOMAIN_NAME" != "$PRIVATEBIN_DOMAIN_NAME" ]]; then
121
                     PRIVATEBIN_DOMAIN_NAME=
123
                     PRIVATEBIN_DOMAIN_NAME=
122
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
124
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
123
                 else
125
                 else
124
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$PRIVATEBIN_CODE"
128
                         validate_freedns_code "$PRIVATEBIN_CODE"
127
-                        if [ ! $VALID_CODE ]; then
129
+                        if [ ! "$VALID_CODE" ]; then
128
                             PRIVATEBIN_DOMAIN_NAME=
130
                             PRIVATEBIN_DOMAIN_NAME=
129
                         fi
131
                         fi
130
                     fi
132
                     fi
133
             if [ $PRIVATEBIN_DOMAIN_NAME ]; then
135
             if [ $PRIVATEBIN_DOMAIN_NAME ]; then
134
                 PRIVATEBIN_DETAILS_COMPLETE="yes"
136
                 PRIVATEBIN_DETAILS_COMPLETE="yes"
135
             fi
137
             fi
138
+            rm -f "$data"
136
         done
139
         done
137
 
140
 
138
         write_config_param "PRIVATEBIN_CODE" "$PRIVATEBIN_CODE"
141
         write_config_param "PRIVATEBIN_CODE" "$PRIVATEBIN_CODE"
142
 }
145
 }
143
 
146
 
144
 function change_password_privatebin {
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
 function reconfigure_privatebin {
153
 function reconfigure_privatebin {
156
         return
160
         return
157
     fi
161
     fi
158
 
162
 
159
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
163
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
160
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
164
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
161
     fi
165
     fi
162
 
166
 
163
     # update to the next commit
167
     # update to the next commit
164
     function_check set_repo_commit
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
     secure_privatebin
171
     secure_privatebin
168
 }
172
 }
170
 
174
 
171
 function backup_local_privatebin {
175
 function backup_local_privatebin {
172
     PRIVATEBIN_DOMAIN_NAME='privatebin'
176
     PRIVATEBIN_DOMAIN_NAME='privatebin'
173
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
177
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
174
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
178
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
175
     fi
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
     function_check suspend_site
183
     function_check suspend_site
180
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
184
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
181
 
185
 
182
     function_check backup_directory_to_usb
186
     function_check backup_directory_to_usb
183
     dest_directory=privatebin
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
     function_check restart_site
190
     function_check restart_site
187
     restart_site
191
     restart_site
188
 }
192
 }
189
 
193
 
190
 function restore_local_privatebin {
194
 function restore_local_privatebin {
191
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
195
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
192
         return
196
         return
193
     fi
197
     fi
194
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
198
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
195
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
199
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
196
         echo $"Restoring privatebin"
200
         echo $"Restoring privatebin"
197
         temp_restore_dir=/root/tempprivatebin
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
         function_check restore_directory_from_usb
204
         function_check restore_directory_from_usb
201
         restore_directory_from_usb $temp_restore_dir privatebin
205
         restore_directory_from_usb $temp_restore_dir privatebin
202
         if [ -d $temp_restore_dir ]; then
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
             else
209
             else
206
-                cp -rp $temp_restore_dir/* $privatebin_dir/
210
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
207
             fi
211
             fi
208
             secure_privatebin
212
             secure_privatebin
209
             rm -rf $temp_restore_dir
213
             rm -rf $temp_restore_dir
215
 
219
 
216
 function backup_remote_privatebin {
220
 function backup_remote_privatebin {
217
     PRIVATEBIN_DOMAIN_NAME='privatebin'
221
     PRIVATEBIN_DOMAIN_NAME='privatebin'
218
-    if grep -q "privatebin domain" $COMPLETION_FILE; then
222
+    if grep -q "privatebin domain" "$COMPLETION_FILE"; then
219
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
223
         PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
220
     fi
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
     function_check suspend_site
228
     function_check suspend_site
225
-    suspend_site ${PRIVATEBIN_DOMAIN_NAME}
229
+    suspend_site "${PRIVATEBIN_DOMAIN_NAME}"
226
 
230
 
227
     function_check backup_directory_to_friend
231
     function_check backup_directory_to_friend
228
     dest_directory=privatebin
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
     function_check restart_site
235
     function_check restart_site
232
     restart_site
236
     restart_site
233
 }
237
 }
234
 
238
 
235
 function restore_remote_privatebin {
239
 function restore_remote_privatebin {
236
-    if ! grep -q "privatebin domain" $COMPLETION_FILE; then
240
+    if ! grep -q "privatebin domain" "$COMPLETION_FILE"; then
237
         return
241
         return
238
     fi
242
     fi
239
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
243
     PRIVATEBIN_DOMAIN_NAME=$(get_completion_param "privatebin domain")
240
-    if [ $PRIVATEBIN_DOMAIN_NAME ]; then
244
+    if [ "$PRIVATEBIN_DOMAIN_NAME" ]; then
241
         temp_restore_dir=/root/tempprivatebin
245
         temp_restore_dir=/root/tempprivatebin
242
         privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
246
         privatebin_dir=/var/www/${PRIVATEBIN_DOMAIN_NAME}/htdocs/data
243
 
247
 
244
         function_check restore_directory_from_friend
248
         function_check restore_directory_from_friend
245
         restore_directory_from_friend $temp_restore_dir privatebin
249
         restore_directory_from_friend $temp_restore_dir privatebin
246
         if [ -d $temp_restore_dir ]; then
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
             else
253
             else
250
-                cp -rp $temp_restore_dir/* $privatebin_dir/
254
+                cp -rp "$temp_restore_dir/*" "$privatebin_dir/"
251
             fi
255
             fi
252
             secure_privatebin
256
             secure_privatebin
253
             rm -rf $temp_restore_dir
257
             rm -rf $temp_restore_dir
262
     read_config_param "PRIVATEBIN_DOMAIN_NAME"
266
     read_config_param "PRIVATEBIN_DOMAIN_NAME"
263
     read_config_param "MY_USERNAME"
267
     read_config_param "MY_USERNAME"
264
     echo "Removing $PRIVATEBIN_DOMAIN_NAME"
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
     fi
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
     fi
277
     fi
274
     function_check remove_onion_service
278
     function_check remove_onion_service
275
     remove_onion_service privatebin ${PRIVATEBIN_ONION_PORT}
279
     remove_onion_service privatebin ${PRIVATEBIN_ONION_PORT}
278
     fi
282
     fi
279
     remove_app privatebin
283
     remove_app privatebin
280
     remove_completion_param install_privatebin
284
     remove_completion_param install_privatebin
281
-    sed -i '/privatebin/d' $COMPLETION_FILE
285
+    sed -i '/privatebin/d' "$COMPLETION_FILE"
282
 
286
 
283
     function_check remove_ddns_domain
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
 function install_privatebin {
291
 function install_privatebin {
288
-    if [ ! $ONION_ONLY ]; then
292
+    if [ ! "$ONION_ONLY" ]; then
289
         ONION_ONLY='no'
293
         ONION_ONLY='no'
290
     fi
294
     fi
291
 
295
 
292
-    if [ ! $PRIVATEBIN_DOMAIN_NAME ]; then
296
+    if [ ! "$PRIVATEBIN_DOMAIN_NAME" ]; then
293
         echo $'No domain name was given for privatebin'
297
         echo $'No domain name was given for privatebin'
294
         exit 7359
298
         exit 7359
295
     fi
299
     fi
298
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
302
     apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
299
     apt-get -yq install php-libsodium libsodium18 php-mcrypt
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
     fi
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
         if [ -d /repos/privatebin ]; then
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
             git pull
314
             git pull
311
         else
315
         else
312
             function_check git_clone
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
         fi
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
             echo $'Unable to clone privatebin repo'
321
             echo $'Unable to clone privatebin repo'
318
             exit 63763873
322
             exit 63763873
319
         fi
323
         fi
320
     fi
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
     set_completion_param "privatebin commit" "$PRIVATEBIN_COMMIT"
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
     function_check add_ddns_domain
333
     function_check add_ddns_domain
330
-    add_ddns_domain $PRIVATEBIN_DOMAIN_NAME
334
+    add_ddns_domain "$PRIVATEBIN_DOMAIN_NAME"
331
 
335
 
332
     PRIVATEBIN_ONION_HOSTNAME=$(add_onion_service privatebin 80 ${PRIVATEBIN_ONION_PORT})
336
     PRIVATEBIN_ONION_HOSTNAME=$(add_onion_service privatebin 80 ${PRIVATEBIN_ONION_PORT})
333
 
337
 
334
     privatebin_nginx_site=/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
338
     privatebin_nginx_site=/etc/nginx/sites-available/$PRIVATEBIN_DOMAIN_NAME
335
     if [[ $ONION_ONLY == "no" ]]; then
339
     if [[ $ONION_ONLY == "no" ]]; then
336
         function_check nginx_http_redirect
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
         function_check nginx_compress
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
         function_check nginx_ssl
351
         function_check nginx_ssl
348
-        nginx_ssl $PRIVATEBIN_DOMAIN_NAME
352
+        nginx_ssl "$PRIVATEBIN_DOMAIN_NAME"
349
 
353
 
350
         function_check nginx_disable_sniffing
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
         function_check nginx_limits
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
     else
386
     else
383
-        echo -n '' > $privatebin_nginx_site
387
+        echo -n '' > "$privatebin_nginx_site"
384
     fi
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
     function_check nginx_compress
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
     function_check nginx_disable_sniffing
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
     function_check nginx_limits
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
     function_check configure_php
426
     function_check configure_php
423
     configure_php
427
     configure_php
424
 
428
 
425
     function_check create_site_certificate
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
     function_check nginx_ensite
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
     # Change some defaults
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
     secure_privatebin
453
     secure_privatebin
450
 
454
 

+ 114
- 113
src/freedombone-app-profanity 查看文件

57
 }
57
 }
58
 
58
 
59
 function remove_user_profanity {
59
 function remove_user_profanity {
60
-    remove_username="$1"
60
+    echo -n ''
61
+#    remove_username="$1"
61
 }
62
 }
62
 
63
 
63
 function add_user_profanity {
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
     echo '0'
68
     echo '0'
68
 }
69
 }
82
 
83
 
83
     read_config_param DEFAULT_DOMAIN_NAME
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
     # TODO: this is currently interactive. Really there needs to be a
88
     # TODO: this is currently interactive. Really there needs to be a
88
     # non-interactive password change option for prosodyctl
89
     # non-interactive password change option for prosodyctl
89
     clear
90
     clear
90
     echo ''
91
     echo ''
91
     echo $'Currently Prosody requires password changes to be done interactively'
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
     XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
95
     XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
95
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
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
     fi
99
     fi
99
 }
100
 }
100
 
101
 
110
 
111
 
111
     rm -rf /tmp/*
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
     if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
115
     if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
115
         function_check set_repo_commit
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
         ./bootstrap.sh
119
         ./bootstrap.sh
119
         ./configure
120
         ./configure
120
         make
121
         make
124
 
125
 
125
     rm -rf /tmp/*
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
     if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
129
     if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
129
         function_check set_repo_commit
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
         ./bootstrap.sh
133
         ./bootstrap.sh
133
         ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
134
         ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
134
         make
135
         make
135
         make install
136
         make install
136
     fi
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
     if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
140
     if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
140
         # upgrade omemo plugins for all users
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
         pip uninstall -y profanity-omemo-plugin
145
         pip uninstall -y profanity-omemo-plugin
145
         ./install.sh
146
         ./install.sh
146
         for d in /home/*/ ; do
147
         for d in /home/*/ ; do
147
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
148
             USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
148
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
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
                 fi
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
             fi
158
             fi
158
         done
159
         done
159
         if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
160
         if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
160
             rm /etc/skel/.local/share/profanity/plugins/omemo.*
161
             rm /etc/skel/.local/share/profanity/plugins/omemo.*
161
         fi
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
     fi
164
     fi
164
 
165
 
165
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
166
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
183
 
184
 
184
 function remove_profanity {
185
 function remove_profanity {
185
     if [ -f /usr/local/bin/profanity ]; then
186
     if [ -f /usr/local/bin/profanity ]; then
186
-        cd $INSTALL_DIR/profanity
187
+        cd "$INSTALL_DIR/profanity" || exit 4628462848
187
         make uninstall
188
         make uninstall
188
 
189
 
189
         remove_completion_param install_profanity
190
         remove_completion_param install_profanity
190
-        sed -i '/profanity/d' $COMPLETION_FILE
191
+        sed -i '/profanity/d' "$COMPLETION_FILE"
191
     fi
192
     fi
192
 }
193
 }
193
 
194
 
197
         return
198
         return
198
     fi
199
     fi
199
     # install profanity from source in order to get OMEMO support
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
     fi
203
     fi
203
 
204
 
204
     apt-get -yq install automake autoconf autoconf-archive libtool build-essential
205
     apt-get -yq install automake autoconf autoconf-archive libtool build-essential
207
 
208
 
208
     # dependency for profanity not available in debian
209
     # dependency for profanity not available in debian
209
     if [ -d /repos/libmesode ]; then
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
         git pull
214
         git pull
214
     else
215
     else
215
-        git_clone $LIBMESODE_REPO $INSTALL_DIR/libmesode
216
+        git_clone "$LIBMESODE_REPO" "$INSTALL_DIR/libmesode"
216
     fi
217
     fi
217
 
218
 
218
-    cd $INSTALL_DIR/libmesode
219
+    cd "$INSTALL_DIR/libmesode" || exit 2468246284
219
     git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
220
     git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
220
     ./bootstrap.sh
221
     ./bootstrap.sh
221
     ./configure
222
     ./configure
225
 
226
 
226
     # build profanity
227
     # build profanity
227
     if [ -d /repos/profanity ]; then
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
         git pull
232
         git pull
232
     else
233
     else
233
-        git_clone $PROFANITY_REPO $INSTALL_DIR/profanity
234
+        git_clone "$PROFANITY_REPO" "$INSTALL_DIR/profanity"
234
     fi
235
     fi
235
 
236
 
236
-    cd $INSTALL_DIR/profanity
237
+    cd "$INSTALL_DIR/profanity" || exit 54287452858
237
     git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
238
     git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
238
     ./bootstrap.sh
239
     ./bootstrap.sh
239
     ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
240
     ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
249
     apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev
250
     apt-get -yq install python-pip python-setuptools clang libffi-dev libssl-dev python-dev
250
 
251
 
251
     if [ -d /repos/profanity-omemo ]; then
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
         git pull
256
         git pull
256
     else
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
     fi
259
     fi
259
 
260
 
260
-    cd $INSTALL_DIR/profanity-omemo-plugin
261
+    cd "$INSTALL_DIR/profanity-omemo-plugin" || exit 6428468248
261
     git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT
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
         echo $'prof_omemo_plugin.py not found'
264
         echo $'prof_omemo_plugin.py not found'
264
         exit 389225
265
         exit 389225
265
     fi
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
     ./install.sh
268
     ./install.sh
268
 
269
 
269
     mkdir -p /etc/skel/.local/share/profanity/plugins
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
     XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
275
     XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
275
     XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
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
     fi
279
     fi
279
 
280
 
280
     XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
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
     if [[ $ONION_ONLY == 'no' ]]; then
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
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
304
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
304
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
305
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
305
         fi
306
         fi
306
     fi
307
     fi
307
 
308
 
308
     if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
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
         if [[ $ONION_ONLY == 'no' ]]; then
311
         if [[ $ONION_ONLY == 'no' ]]; then
311
-            echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
312
+            echo 'enabled=false' >> "$XMPP_CLIENT_ACCOUNTS"
312
         else
313
         else
313
-            echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
314
+            echo 'enabled=true' >> "$XMPP_CLIENT_ACCOUNTS"
314
         fi
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
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
333
         if [ ${#XMPP_PASSWORD} -gt 2 ]; then
333
-            echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
334
+            echo "password=$XMPP_PASSWORD" >> "$XMPP_CLIENT_ACCOUNTS"
334
         fi
335
         fi
335
     fi
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
     fi
340
     fi
340
-    echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
341
+    echo '[connection]' > "/home/$MY_USERNAME/.config/profanity/profrc"
341
     if [[ $ONION_ONLY == 'no' ]]; then
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
     else
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
     fi
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
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
364
     chmod -R 700 /root/.local/lib/python3.4/site-packages/python_axolotl_*
364
     APP_INSTALLED=1
365
     APP_INSTALLED=1

+ 157
- 153
src/freedombone-app-radicale 查看文件

61
 function remove_user_radicale {
61
 function remove_user_radicale {
62
     remove_username="$1"
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
     if grep -q "${remove_username}:" ${RADICALE_USERS}; then
66
     if grep -q "${remove_username}:" ${RADICALE_USERS}; then
67
         sed -i "/${remove_username}:/d" ${RADICALE_USERS}
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
         fi
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
         fi
73
         fi
74
         systemctl restart radicale
74
         systemctl restart radicale
75
     fi
75
     fi
79
     new_username="$1"
79
     new_username="$1"
80
     new_user_password="$2"
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
     if [ ! -f ${RADICALE_USERS} ]; then
84
     if [ ! -f ${RADICALE_USERS} ]; then
85
         touch ${RADICALE_USERS}
85
         touch ${RADICALE_USERS}
88
     if ! grep -q "$new_username:" ${RADICALE_USERS}; then
88
     if ! grep -q "$new_username:" ${RADICALE_USERS}; then
89
         htpasswd -bd ${RADICALE_USERS} "$new_username" "$new_user_password"
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
         chown -R www-data:www-data /var/www/radicale
99
         chown -R www-data:www-data /var/www/radicale
100
         chmod -R 755 /var/www/radicale/*
100
         chmod -R 755 /var/www/radicale/*
107
     existing_username="$1"
107
     existing_username="$1"
108
     new_user_password="$2"
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
     if grep -q "${existing_username}:" ${RADICALE_USERS}; then
112
     if grep -q "${existing_username}:" ${RADICALE_USERS}; then
113
         sed -i "/${existing_username}:/d" ${RADICALE_USERS}
113
         sed -i "/${existing_username}:/d" ${RADICALE_USERS}
127
     rm -rf /var/log/radicale/*
127
     rm -rf /var/log/radicale/*
128
 
128
 
129
     # create an admin password
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
     else
132
     else
133
-        RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
133
+        RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
134
     fi
134
     fi
135
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
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
     touch /var/log/radicale/radicale.log
139
     touch /var/log/radicale/radicale.log
140
     chown -R www-data:www-data /var/log/radicale
140
     chown -R www-data:www-data /var/log/radicale
145
         return
145
         return
146
     fi
146
     fi
147
 
147
 
148
-    if ! grep -q "radicale version:" $COMPLETION_FILE; then
148
+    if ! grep -q "radicale version:" "$COMPLETION_FILE"; then
149
         return
149
         return
150
     fi
150
     fi
151
 
151
 
155
     fi
155
     fi
156
 
156
 
157
     # get the source
157
     # get the source
158
-    cd /var/www/radicale
158
+    cd /var/www/radicale || exit 62784628468
159
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
159
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
160
 
160
 
161
     # check the hash
161
     # check the hash
170
         exit 73529
170
         exit 73529
171
     fi
171
     fi
172
     rm Radicale-${RADICALE_VERSION}.tar.gz
172
     rm Radicale-${RADICALE_VERSION}.tar.gz
173
-    cd Radicale-${RADICALE_VERSION}
173
+    cd "Radicale-${RADICALE_VERSION}" || exit 264824684
174
 
174
 
175
     # move the old command
175
     # move the old command
176
     mv /usr/local/bin/radicale /usr/local/bin/radicale_previous
176
     mv /usr/local/bin/radicale /usr/local/bin/radicale_previous
186
     fi
186
     fi
187
 
187
 
188
     # remove the old source
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
     chown -R www-data:www-data /var/www/radicale
192
     chown -R www-data:www-data /var/www/radicale
193
     systemctl restart radicale
193
     systemctl restart radicale
194
     systemctl restart nginx
194
     systemctl restart nginx
219
         else
219
         else
220
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
220
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
221
         fi
221
         fi
222
+        # shellcheck disable=SC2181
222
         if [ ! "$?" = "0" ]; then
223
         if [ ! "$?" = "0" ]; then
223
             function_check backup_unmount_drive
224
             function_check backup_unmount_drive
224
             backup_unmount_drive
225
             backup_unmount_drive
233
         else
234
         else
234
             cp -r $temp_restore_dir/* /var/www/radicale/*
235
             cp -r $temp_restore_dir/* /var/www/radicale/*
235
         fi
236
         fi
237
+        # shellcheck disable=SC2181
236
         if [ ! "$?" = "0" ]; then
238
         if [ ! "$?" = "0" ]; then
237
             function_check backup_unmount_drive
239
             function_check backup_unmount_drive
238
             backup_unmount_drive
240
             backup_unmount_drive
264
         else
266
         else
265
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
267
             cp -r $temp_restore_dir/* ${RADICALE_DIRECTORY}/
266
         fi
268
         fi
269
+        # shellcheck disable=SC2181
267
         if [ ! "$?" = "0" ]; then
270
         if [ ! "$?" = "0" ]; then
268
             exit 236746
271
             exit 236746
269
         fi
272
         fi
276
         else
279
         else
277
             cp -r $temp_restore_dir/* /var/www/radicale
280
             cp -r $temp_restore_dir/* /var/www/radicale
278
         fi
281
         fi
282
+        # shellcheck disable=SC2181
279
         if [ ! "$?" = "0" ]; then
283
         if [ ! "$?" = "0" ]; then
280
             exit 3674284
284
             exit 3674284
281
         fi
285
         fi
332
     fi
336
     fi
333
 
337
 
334
     remove_completion_param install_radicale
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
     systemctl restart nginx
341
     systemctl restart nginx
338
 }
342
 }
339
 
343
 
340
 function install_radicale {
344
 function install_radicale {
341
     if [[ $ONION_ONLY == 'no' ]]; then
345
     if [[ $ONION_ONLY == 'no' ]]; then
342
         # obtain a cert for the default domain
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
             echo $'Obtaining certificate for the main domain'
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
         fi
350
         fi
347
     fi
351
     fi
348
 
352
 
368
     fi
372
     fi
369
 
373
 
370
     # get the source
374
     # get the source
371
-    cd /var/www/radicale
375
+    cd /var/www/radicale || exit 462874628
372
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
376
     wget ${RADICALE_DOWNLOAD_URL}${RADICALE_VERSION}.tar.gz
373
 
377
 
374
     # check the hash
378
     # check the hash
383
         exit 623252
387
         exit 623252
384
     fi
388
     fi
385
     rm Radicale-${RADICALE_VERSION}.tar.gz
389
     rm Radicale-${RADICALE_VERSION}.tar.gz
386
-    cd Radicale-${RADICALE_VERSION}
390
+    cd "Radicale-${RADICALE_VERSION}" || exit 872462842
387
     python setup.py install
391
     python setup.py install
388
     if [ ! -f /usr/local/bin/radicale ]; then
392
     if [ ! -f /usr/local/bin/radicale ]; then
389
         echo $'Radicale did not install'
393
         echo $'Radicale did not install'
398
     fi
402
     fi
399
 
403
 
400
     # create the configuration
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
     # create an admin password
427
     # create an admin password
424
     if [ ${#RADICALE_PASSWORD} -lt 8 ]; then
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
         else
431
         else
428
-            RADICALE_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
432
+            RADICALE_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
429
         fi
433
         fi
430
     fi
434
     fi
431
     add_user_radicale "$MY_USERNAME" "$RADICALE_PASSWORD"
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
     addresses_str=$"Addresses"
452
     addresses_str=$"Addresses"
449
     echo "{\"tag\": \"VADDRESSBOOK\", \"D:displayname\": \"${addresses_str}\"}" > /var/www/radicale/collections/addresses.props
453
     echo "{\"tag\": \"VADDRESSBOOK\", \"D:displayname\": \"${addresses_str}\"}" > /var/www/radicale/collections/addresses.props
461
     systemctl enable radicale
465
     systemctl enable radicale
462
     systemctl start radicale
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
         # create a new site config
469
         # create a new site config
466
         RADICALE_ONION_HOSTNAME=$(add_onion_service radicale 80 ${RADICALE_ONION_PORT})
470
         RADICALE_ONION_HOSTNAME=$(add_onion_service radicale 80 ${RADICALE_ONION_PORT})
467
 
471
 
468
         if [[ $ONION_ONLY == 'no' ]]; then
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
             function_check nginx_ssl
477
             function_check nginx_ssl
474
-            nginx_ssl ${DEFAULT_DOMAIN_NAME} mobile
478
+            nginx_ssl "${DEFAULT_DOMAIN_NAME}" mobile
475
             function_check nginx_disable_sniffing
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
         else
514
         else
511
-            echo -n '' > /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
515
+            echo -n '' > "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
512
         fi
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
         set_completion_param "radicale onion domain" "${RADICALE_ONION_HOSTNAME}"
551
         set_completion_param "radicale onion domain" "${RADICALE_ONION_HOSTNAME}"
548
     else
552
     else
549
         # alter the existing site config
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
         fi
557
         fi
554
     fi
558
     fi
555
 
559
 
556
     # create a certificate
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
         fi
565
         fi
562
     fi
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
         sed -i "s|radicale.crt|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
569
         sed -i "s|radicale.crt|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
566
         sed -i "s|radicale.pem|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
570
         sed -i "s|radicale.pem|${DEFAULT_DOMAIN_NAME}.pem|g" /etc/nginx/sites-available/radicale
567
     fi
571
     fi
572
 
576
 
573
     systemctl restart nginx
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
     # keep track of the version so we can check for upgrades
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
     else
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
     fi
586
     fi
583
 
587
 
584
     APP_INSTALLED=1
588
     APP_INSTALLED=1

+ 89
- 87
src/freedombone-app-riot 查看文件

76
         RIOT_DETAILS_COMPLETE=
76
         RIOT_DETAILS_COMPLETE=
77
         while [ ! $RIOT_DETAILS_COMPLETE ]
77
         while [ ! $RIOT_DETAILS_COMPLETE ]
78
         do
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
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
80
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
82
                 dialog --backtitle $"Freedombone Configuration" \
81
                 dialog --backtitle $"Freedombone Configuration" \
83
                        --title $"Riot Web user interface for Matrix" \
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
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
84
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
86
                        $"Code:" 2 1 "$(grep 'RIOT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
85
                        $"Code:" 2 1 "$(grep 'RIOT_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 15 40 255 \
87
-                       2> $data
86
+                       2> "$data"
88
             else
87
             else
89
                 dialog --backtitle $"Freedombone Configuration" \
88
                 dialog --backtitle $"Freedombone Configuration" \
90
                        --title $"Riot Web user interface for Matrix" \
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
                        $"Domain:" 1 1 "$(grep 'RIOT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 15 40 40 \
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
             fi
93
             fi
95
             sel=$?
94
             sel=$?
96
             case $sel in
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
             esac
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
                 TEST_DOMAIN_NAME=$RIOT_DOMAIN_NAME
103
                 TEST_DOMAIN_NAME=$RIOT_DOMAIN_NAME
103
                 validate_domain_name
104
                 validate_domain_name
104
-                if [[ $TEST_DOMAIN_NAME != $RIOT_DOMAIN_NAME ]]; then
105
+                if [[ "$TEST_DOMAIN_NAME" != "$RIOT_DOMAIN_NAME" ]]; then
105
                     RIOT_DOMAIN_NAME=
106
                     RIOT_DOMAIN_NAME=
106
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
107
                     dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
107
                 else
108
                 else
108
                     if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
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
                         validate_freedns_code "$RIOT_CODE"
111
                         validate_freedns_code "$RIOT_CODE"
111
-                        if [ ! $VALID_CODE ]; then
112
+                        if [ ! "$VALID_CODE" ]; then
112
                             RIOT_DOMAIN_NAME=
113
                             RIOT_DOMAIN_NAME=
113
                         fi
114
                         fi
114
                     fi
115
                     fi
117
             if [ $RIOT_DOMAIN_NAME ]; then
118
             if [ $RIOT_DOMAIN_NAME ]; then
118
                 RIOT_DETAILS_COMPLETE="yes"
119
                 RIOT_DETAILS_COMPLETE="yes"
119
             fi
120
             fi
121
+            rm -f "$data"
120
         done
122
         done
121
 
123
 
122
         # save the results in the config file
124
         # save the results in the config file
132
 
134
 
133
 function riot_download {
135
 function riot_download {
134
     # download
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
     fi
139
     fi
138
-    if [ ! -f $INSTALL_DIR/${RIOT_FILENAME}.tar.gz ]; then
140
+    if [ ! -f "$INSTALL_DIR/${RIOT_FILENAME}.tar.gz" ]; then
139
         echo $'Unable to download Riot Web from releases'
141
         echo $'Unable to download Riot Web from releases'
140
         exit 62836
142
         exit 62836
141
     fi
143
     fi
142
-    cd $INSTALL_DIR
144
+    cd "$INSTALL_DIR" || exit 2468724628
143
 
145
 
144
     # check the hash
146
     # check the hash
145
     curr_hash=$(sha256sum ${RIOT_FILENAME}.tar.gz | awk -F ' ' '{print $1}')
147
     curr_hash=$(sha256sum ${RIOT_FILENAME}.tar.gz | awk -F ' ' '{print $1}')
149
     fi
151
     fi
150
 
152
 
151
     tar -xzvf ${RIOT_FILENAME}.tar.gz
153
     tar -xzvf ${RIOT_FILENAME}.tar.gz
152
-    if [ ! -d $INSTALL_DIR/${RIOT_FILENAME} ]; then
154
+    if [ ! -d "$INSTALL_DIR/${RIOT_FILENAME}" ]; then
153
         echo $'Unable to extract Riot Web tarball'
155
         echo $'Unable to extract Riot Web tarball'
154
         exit 542826
156
         exit 542826
155
     fi
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
 function upgrade_riot {
163
 function upgrade_riot {
162
-    if ! grep -q 'riot version:' $COMPLETION_FILE; then
164
+    if ! grep -q 'riot version:' "$COMPLETION_FILE"; then
163
         return
165
         return
164
     fi
166
     fi
165
 
167
 
171
     fi
173
     fi
172
 
174
 
173
     riot_download
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
     riot_remove_bad_links
177
     riot_remove_bad_links
176
 
178
 
177
     systemctl restart nginx
179
     systemctl restart nginx
207
     fi
209
     fi
208
 
210
 
209
     remove_completion_param install_riot
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
 function install_riot {
215
 function install_riot {
216
     fi
218
     fi
217
 
219
 
218
     # check that matrix has been installed
220
     # check that matrix has been installed
219
-    if [ ! $MATRIX_DOMAIN_NAME ]; then
221
+    if [ ! "$MATRIX_DOMAIN_NAME" ]; then
220
         exit 687292
222
         exit 687292
221
     fi
223
     fi
222
     if [[ "$MATRIX_DOMAIN_NAME" != *'.'* ]]; then
224
     if [[ "$MATRIX_DOMAIN_NAME" != *'.'* ]]; then
235
         mkdir -p /var/www/$RIOT_DOMAIN_NAME/htdocs
237
         mkdir -p /var/www/$RIOT_DOMAIN_NAME/htdocs
236
     fi
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
     fi
242
     fi
241
 
243
 
242
     riot_download
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
         riot_config_file="config.${RIOT_DOMAIN_NAME}.json"
249
         riot_config_file="config.${RIOT_DOMAIN_NAME}.json"
248
         cp config.sample.json $riot_config_file
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
     else
255
     else
254
         riot_config_file="config.${MATRIX_ONION_DOMAIN_NAME}.json"
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
     fi
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
     RIOT_ONION_HOSTNAME=$(add_onion_service riot 80 ${RIOT_ONION_PORT})
267
     RIOT_ONION_HOSTNAME=$(add_onion_service riot 80 ${RIOT_ONION_PORT})
266
 
268
 
268
     if [[ $ONION_ONLY == "no" ]]; then
270
     if [[ $ONION_ONLY == "no" ]]; then
269
         function_check nginx_http_redirect
271
         function_check nginx_http_redirect
270
         nginx_http_redirect $RIOT_DOMAIN_NAME
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
         function_check nginx_ssl
279
         function_check nginx_ssl
278
         nginx_ssl $RIOT_DOMAIN_NAME
280
         nginx_ssl $RIOT_DOMAIN_NAME
279
 
281
 
280
         function_check nginx_disable_sniffing
282
         function_check nginx_disable_sniffing
281
         nginx_disable_sniffing $RIOT_DOMAIN_NAME
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
         function_check nginx_limits
297
         function_check nginx_limits
296
         nginx_limits $RIOT_DOMAIN_NAME '15m'
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
     else
302
     else
301
         echo -n '' > $riot_nginx_site
303
         echo -n '' > $riot_nginx_site
302
     fi
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
     function_check nginx_disable_sniffing
309
     function_check nginx_disable_sniffing
308
     nginx_disable_sniffing $RIOT_DOMAIN_NAME
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
     function_check nginx_limits
322
     function_check nginx_limits
321
     nginx_limits $RIOT_DOMAIN_NAME '15m'
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
     function_check create_site_certificate
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
     fi
335
     fi
334
 
336
 
335
     function_check nginx_ensite
337
     function_check nginx_ensite
344
     systemctl restart nginx
346
     systemctl restart nginx
345
 
347
 
346
     set_completion_param "riot domain" "$RIOT_DOMAIN_NAME"
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
     else
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
     fi
353
     fi
352
     APP_INSTALLED=1
354
     APP_INSTALLED=1
353
 }
355
 }

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

62
 }
62
 }
63
 
63
 
64
 function remove_user_rss {
64
 function remove_user_rss {
65
-    remove_username="$1"
65
+    echo -n ''
66
+#    remove_username="$1"
66
 }
67
 }
67
 
68
 
68
 function add_user_rss {
69
 function add_user_rss {
69
-    new_username="$1"
70
-    new_user_password="$2"
70
+#    new_username="$1"
71
+#    new_user_password="$2"
71
     echo '0'
72
     echo '0'
72
 }
73
 }
73
 
74
 
77
 }
78
 }
78
 
79
 
79
 function change_password_rss {
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
     #${PROJECT_NAME}-pass -u "$curr_username" -a rss -p "$new_user_password"
85
     #${PROJECT_NAME}-pass -u "$curr_username" -a rss -p "$new_user_password"
84
 }
86
 }
85
 
87
 
86
 function rss_create_database {
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
     else
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
         fi
94
         fi
93
     fi
95
     fi
94
-    if [ ! $RSS_READER_ADMIN_PASSWORD ]; then
96
+    if [ ! "$RSS_READER_ADMIN_PASSWORD" ]; then
95
         return
97
         return
96
     fi
98
     fi
97
 
99
 
98
     function_check create_database
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
 function reconfigure_rss {
104
 function reconfigure_rss {
131
         # remove any previous install
133
         # remove any previous install
132
         if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
134
         if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
133
             if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
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
                 rm -rf $RSS_READER_PATH/g2ttree-mobile
138
                 rm -rf $RSS_READER_PATH/g2ttree-mobile
137
             fi
139
             fi
138
         fi
140
         fi
184
                 fi
186
                 fi
185
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
187
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
186
             fi
188
             fi
189
+            # shellcheck disable=SC2181
187
             if [ ! "$?" = "0" ]; then
190
             if [ ! "$?" = "0" ]; then
188
                 function_check set_user_permissions
191
                 function_check set_user_permissions
189
                 set_user_permissions
192
                 set_user_permissions
193
                 exit 528823
196
                 exit 528823
194
             fi
197
             fi
195
             if [ -d /etc/letsencrypt/live/${RSS_READER_DOMAIN_NAME} ]; then
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
             else
201
             else
199
                 # Ensure that the bundled SSL cert is being used
202
                 # Ensure that the bundled SSL cert is being used
200
                 if [ -f /etc/ssl/certs/${RSS_READER_DOMAIN_NAME}.bundle.crt ]; then
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
                 fi
205
                 fi
203
             fi
206
             fi
204
         fi
207
         fi
207
     function_check rss_modifications
210
     function_check rss_modifications
208
     rss_modifications
211
     rss_modifications
209
 
212
 
210
-    if [ -d $USB_MOUNT/backup/ttrss ]; then
213
+    if [ -d "$USB_MOUNT/backup/ttrss" ]; then
211
         chown -R www-data:www-data /etc/share/tt-rss
214
         chown -R www-data:www-data /etc/share/tt-rss
212
         if [ -d $temp_restore_dir ]; then
215
         if [ -d $temp_restore_dir ]; then
213
             rm -rf $temp_restore_dir
216
             rm -rf $temp_restore_dir
214
         fi
217
         fi
215
     fi
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
     sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
221
     sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
219
     MARIADB_PASSWORD=
222
     MARIADB_PASSWORD=
220
 }
223
 }
245
 
248
 
246
 function restore_remote_rss {
249
 function restore_remote_rss {
247
     temp_restore_dir=/root/tempttrss
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
         echo $"Restoring ttrss"
252
         echo $"Restoring ttrss"
250
         function_check get_mariadb_password
253
         function_check get_mariadb_password
251
         get_mariadb_password
254
         get_mariadb_password
263
                 fi
266
                 fi
264
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
267
                 cp -r $temp_restore_dir/* /etc/share/tt-rss/
265
             fi
268
             fi
269
+            # shellcheck disable=SC2181
266
             if [ ! "$?" = "0" ]; then
270
             if [ ! "$?" = "0" ]; then
267
                 exit 6391
271
                 exit 6391
268
             fi
272
             fi
280
         function_check rss_modifications
284
         function_check rss_modifications
281
         rss_modifications
285
         rss_modifications
282
 
286
 
283
-        if [ -d $SERVER_DIRECTORY/backup/ttrss ]; then
287
+        if [ -d "$SERVER_DIRECTORY/backup/ttrss" ]; then
284
             chown -R www-data:www-data /etc/share/tt-rss
288
             chown -R www-data:www-data /etc/share/tt-rss
285
         fi
289
         fi
286
         if [ -d /root/tempttrss ]; then
290
         if [ -d /root/tempttrss ]; then
287
             rm -rf /root/tempttrss
291
             rm -rf /root/tempttrss
288
         fi
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
         sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
295
         sed -i "s|define('DB_PASS'.*|define('DB_PASS', '${MARIADB_PASSWORD}');|g" $RSS_READER_PATH/config.php
292
         MARIADB_PASSWORD=
296
         MARIADB_PASSWORD=
293
 
297
 
313
     function_check drop_database
317
     function_check drop_database
314
     drop_database ttrss
318
     drop_database ttrss
315
     remove_completion_param install_rss
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
     remove_backup_database_local ttrss
323
     remove_backup_database_local ttrss
320
 }
324
 }
321
 
325
 
329
 
333
 
330
     # ensure that socks5 proxy is used
334
     # ensure that socks5 proxy is used
331
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/plugins/af_unburn/init.php; then
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
         rss_modified=1
337
         rss_modified=1
334
     fi
338
     fi
335
     if ! grep -q "CURLPROXY_SOCKS5" $RSS_READER_PATH/include/functions.php; then
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
         rss_modified=1
341
         rss_modified=1
338
     fi
342
     fi
339
     if [ $rss_modified ]; then
343
     if [ $rss_modified ]; then
340
-        cd $RSS_READER_PATH
344
+        cd $RSS_READER_PATH || exit 564286428
341
         git commit -a -m"Modify for Tor proxying"
345
         git commit -a -m"Modify for Tor proxying"
342
     fi
346
     fi
343
     chown -R www-data:www-data $RSS_READER_PATH
347
     chown -R www-data:www-data $RSS_READER_PATH
358
     if [ ! -d /etc/share ]; then
362
     if [ ! -d /etc/share ]; then
359
         mkdir /etc/share
363
         mkdir /etc/share
360
     fi
364
     fi
361
-    cd /etc/share
365
+    cd /etc/share || exit 46284628
362
 
366
 
363
     if [ -d /repos/rss ]; then
367
     if [ -d /repos/rss ]; then
364
         mkdir tt-rss
368
         mkdir tt-rss
365
         cp -r -p /repos/rss/. tt-rss
369
         cp -r -p /repos/rss/. tt-rss
366
-        cd tt-rss
370
+        cd tt-rss || exit 462846822
367
         git pull
371
         git pull
368
     else
372
     else
369
         function_check git_clone
373
         function_check git_clone
374
         echo $'Could not clone RSS reader repo'
378
         echo $'Could not clone RSS reader repo'
375
         exit 52925
379
         exit 52925
376
     fi
380
     fi
377
-    cd $RSS_READER_PATH
381
+    cd $RSS_READER_PATH || exit 42479825792593
378
     git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
382
     git checkout $RSS_READER_COMMIT -b $RSS_READER_COMMIT
379
     set_completion_param "rss reader commit" "$RSS_READER_COMMIT"
383
     set_completion_param "rss reader commit" "$RSS_READER_COMMIT"
380
 
384
 
397
     USE_V2_ONION_ADDRESS=1
401
     USE_V2_ONION_ADDRESS=1
398
     RSS_MOBILE_READER_ONION_HOSTNAME=$(add_onion_service mobilerss 80 ${RSS_MOBILE_READER_ONION_PORT})
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
     if [ ! -f $RSS_READER_PATH/config.php ]; then
505
     if [ ! -f $RSS_READER_PATH/config.php ]; then
502
         # generate a config file
506
         # generate a config file
503
         RSS_FEED_CRYPT_KEY="$(create_password 24)"
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
     fi
549
     fi
546
 
550
 
547
     # initialize the database
551
     # initialize the database
569
     systemctl restart nginx
573
     systemctl restart nginx
570
 
574
 
571
     # daemon to update feeds
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
     systemctl enable ttrss
587
     systemctl enable ttrss
584
     systemctl daemon-reload
588
     systemctl daemon-reload
585
     systemctl start ttrss
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
     install_completed rss_main
593
     install_completed rss_main
590
 }
594
 }
591
 
595
 
592
 function install_rss_gnusocial {
596
 function install_rss_gnusocial {
593
-    if [ ! $GNUSOCIAL_DOMAIN_NAME ]; then
597
+    if [ ! "$GNUSOCIAL_DOMAIN_NAME" ]; then
594
         return
598
         return
595
     fi
599
     fi
596
 
600
 
604
     set_repo_commit $RSS_READER_GNUSOCIAL_PATH "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT" $RSS_READER_GNUSOCIAL_REPO
608
     set_repo_commit $RSS_READER_GNUSOCIAL_PATH "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT" $RSS_READER_GNUSOCIAL_REPO
605
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
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
         return
612
         return
609
     fi
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
     fi
617
     fi
614
 
618
 
615
-    cd $INSTALL_DIR
619
+    cd "$INSTALL_DIR" || exit 7246284
616
     function_check git_clone
620
     function_check git_clone
617
     git_clone $RSS_READER_GNUSOCIAL_REPO ttrss-gnusocial
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
         echo $'Could not clone repo for RSS reader gnusocial plugin'
623
         echo $'Could not clone repo for RSS reader gnusocial plugin'
620
         exit 52838
624
         exit 52838
621
     fi
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
     git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
628
     git checkout $RSS_READER_GNUSOCIAL_COMMIT -b $RSS_READER_GNUSOCIAL_COMMIT
625
     set_completion_param "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT"
629
     set_completion_param "rss reader gnusocial commit" "$RSS_READER_GNUSOCIAL_COMMIT"
626
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
630
     chown -R www-data:www-data $RSS_READER_GNUSOCIAL_PATH
642
     # remove any previous install
646
     # remove any previous install
643
     if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
647
     if [ -d $RSS_READER_PATH/g2ttree-mobile ]; then
644
         if [[ $(is_completed "install_rss_mobile_reader") == "1" ]]; then
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
             rm -rf $RSS_READER_PATH/g2ttree-mobile
651
             rm -rf $RSS_READER_PATH/g2ttree-mobile
648
         fi
652
         fi
649
     fi
653
     fi
650
 
654
 
651
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
655
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
652
         return
656
         return
653
     fi
657
     fi
654
 
658
 
655
-    cd /etc/share
659
+    cd /etc/share || exit 7498264462
656
 
660
 
657
     if [ -d /repos/rss-mobile ]; then
661
     if [ -d /repos/rss-mobile ]; then
658
         mkdir ttrss-mobile
662
         mkdir ttrss-mobile
659
         cp -r -p /repos/rss-mobile/. ttrss-mobile
663
         cp -r -p /repos/rss-mobile/. ttrss-mobile
660
-        cd ttrss-mobile
664
+        cd ttrss-mobile || exit 462846284682
661
         git pull
665
         git pull
662
     else
666
     else
663
         function_check git_clone
667
         function_check git_clone
668
         echo $'Could not clone RSS mobile reader repo'
672
         echo $'Could not clone RSS mobile reader repo'
669
         exit 24816
673
         exit 24816
670
     fi
674
     fi
671
-    cd $RSS_MOBILE_READER_PATH
675
+    cd "$RSS_MOBILE_READER_PATH" || exit 462846246824
672
     git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
676
     git checkout $RSS_MOBILE_READER_COMMIT -b $RSS_MOBILE_READER_COMMIT
673
     set_completion_param "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT"
677
     set_completion_param "rss mobile reader commit" "$RSS_MOBILE_READER_COMMIT"
674
 
678
 

+ 173
- 168
src/freedombone-app-scuttlebot 查看文件

61
     invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
61
     invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
62
 
62
 
63
     clear
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
     read -n1 -r -p $"Press any key to continue..." key
66
     read -n1 -r -p $"Press any key to continue..." key
66
 }
67
 }
67
 
68
 
68
 function configure_interactive_scuttlebot {
69
 function configure_interactive_scuttlebot {
69
     while true
70
     while true
70
     do
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
         dialog --backtitle $"Freedombone Control Panel" \
73
         dialog --backtitle $"Freedombone Control Panel" \
74
                --title $"Scuttlebot" \
74
                --title $"Scuttlebot" \
75
                --radiolist $"Choose an operation:" 10 50 2 \
75
                --radiolist $"Choose an operation:" 10 50 2 \
76
                1 $"Create an invite" off \
76
                1 $"Create an invite" off \
77
-               2 $"Exit" on 2> $data
77
+               2 $"Exit" on 2> "$data"
78
         sel=$?
78
         sel=$?
79
         case $sel in
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
         esac
84
         esac
83
-        case $(cat $data) in
85
+        case $(cat "$data") in
84
             1) scuttlebot_create_invite;;
86
             1) scuttlebot_create_invite;;
85
-            2) break;;
87
+            2) rm -f "$data"
88
+               break;;
86
         esac
89
         esac
90
+        rm -f "$data"
87
     done
91
     done
88
 }
92
 }
89
 
93
 
90
 function remove_user_scuttlebot {
94
 function remove_user_scuttlebot {
91
-    remove_username="$1"
95
+    echo -n ''
96
+#    remove_username="$1"
92
 }
97
 }
93
 
98
 
94
 function add_user_scuttlebot {
99
 function add_user_scuttlebot {
95
-    new_username="$1"
96
-    new_user_password="$2"
100
+#    new_username="$1"
101
+#    new_user_password="$2"
97
     echo '0'
102
     echo '0'
98
 }
103
 }
99
 
104
 
109
 }
114
 }
110
 
115
 
111
 function change_password_scuttlebot {
116
 function change_password_scuttlebot {
112
-    new_username="$1"
113
-    new_user_password="$2"
117
+#    new_username="$1"
118
+#    new_user_password="$2"
114
     echo '0'
119
     echo '0'
115
 }
120
 }
116
 
121
 
123
 }
128
 }
124
 
129
 
125
 function upgrade_scuttlebot {
130
 function upgrade_scuttlebot {
126
-    if ! grep -q 'scuttlebot version:' $COMPLETION_FILE; then
131
+    if ! grep -q 'scuttlebot version:' $"COMPLETION_FILE"; then
127
         return
132
         return
128
     fi
133
     fi
129
 
134
 
134
         return
139
         return
135
     fi
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
         return
143
         return
140
     fi
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
 function backup_local_scuttlebot {
148
 function backup_local_scuttlebot {
218
     fi
222
     fi
219
 
223
 
220
     remove_completion_param install_scuttlebot
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
 function git_ssb_script {
228
 function git_ssb_script {
225
     if [[ "$1" == "mesh" ]]; then
229
     if [[ "$1" == "mesh" ]]; then
230
+        # shellcheck disable=SC2154
226
         git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
231
         git_ssb_script_name=$rootdir/usr/bin/git-ssb-create
227
         git_ssb_daemon_filename=$rootdir/etc/systemd/system/git_ssb.service
232
         git_ssb_daemon_filename=$rootdir/etc/systemd/system/git_ssb.service
228
     else
233
     else
229
         git_ssb_script_name=/usr/bin/git-ssb-create
234
         git_ssb_script_name=/usr/bin/git-ssb-create
230
         git_ssb_daemon_filename=/etc/systemd/system/git_ssb.service
235
         git_ssb_daemon_filename=/etc/systemd/system/git_ssb.service
231
     fi
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
     chmod +x $git_ssb_script_name
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
 function scuttlebot_git_setup {
269
 function scuttlebot_git_setup {
265
     if [[ "$1" == "mesh" ]]; then
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
         fi
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
             echo $'Could not find foundation.css'
275
             echo $'Could not find foundation.css'
271
             exit 347687245
276
             exit 347687245
272
         fi
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
         git_ssb_nginx_site=$rootdir/etc/nginx/sites-available/git_ssb
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
     else
291
     else
287
         if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
292
         if [ ! $SCUTTLEBOT_DOMAIN_NAME ]; then
288
             exit 7357225
293
             exit 7357225
300
         git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
305
         git_ssb_nginx_site=/etc/nginx/sites-available/${SCUTTLEBOT_DOMAIN_NAME}
301
         function_check nginx_http_redirect
306
         function_check nginx_http_redirect
302
         nginx_http_redirect $SCUTTLEBOT_DOMAIN_NAME "index index.html"
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
         function_check nginx_compress
313
         function_check nginx_compress
309
         nginx_compress $SCUTTLEBOT_DOMAIN_NAME
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
         function_check nginx_ssl
317
         function_check nginx_ssl
313
         nginx_ssl $SCUTTLEBOT_DOMAIN_NAME
318
         nginx_ssl $SCUTTLEBOT_DOMAIN_NAME
314
 
319
 
316
         nginx_disable_sniffing $SCUTTLEBOT_DOMAIN_NAME
321
         nginx_disable_sniffing $SCUTTLEBOT_DOMAIN_NAME
317
     fi
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
     fi
363
     fi
359
     if [[ "$1" != "mesh" ]]; then
364
     if [[ "$1" != "mesh" ]]; then
360
         nginx_ensite git_ssb
365
         nginx_ensite git_ssb
364
 function mesh_install_dat {
369
 function mesh_install_dat {
365
     get_npm_arch
370
     get_npm_arch
366
 
371
 
367
-    cat <<EOF > $rootdir/usr/bin/install_dat
372
+    cat <<EOF > "$rootdir/usr/bin/install_dat"
368
 #!/bin/bash
373
 #!/bin/bash
369
 npm install --arch=$NPM_ARCH -g dat
374
 npm install --arch=$NPM_ARCH -g dat
370
 npm install --arch=$NPM_ARCH -g @garbados/dat-boi
375
 npm install --arch=$NPM_ARCH -g @garbados/dat-boi
371
 npm install --arch=$NPM_ARCH -g add-to-systemd
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
 EOF
378
 EOF
374
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
379
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_dat
375
     chroot "$rootdir" /usr/bin/install_dat
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
 function install_dat {
384
 function install_dat {
380
     npm install -g dat
385
     npm install -g dat
381
     npm install -g @garbados/dat-boi
386
     npm install -g @garbados/dat-boi
382
     npm install -g add-to-systemd
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
 function mesh_install_scuttlebot {
391
 function mesh_install_scuttlebot {
390
 
395
 
391
     get_npm_arch
396
     get_npm_arch
392
 
397
 
393
-    cat <<EOF > $rootdir/usr/bin/install_scuttlebot
398
+    cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
394
 #!/bin/bash
399
 #!/bin/bash
395
 npm install --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}
400
 npm install --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}
396
 npm install --arch=$NPM_ARCH -g git-ssb
401
 npm install --arch=$NPM_ARCH -g git-ssb
398
 EOF
403
 EOF
399
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
404
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
400
     chroot "$rootdir" /usr/bin/install_scuttlebot
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
         echo $'Scuttlebot was not installed'
409
         echo $'Scuttlebot was not installed'
405
         exit 528253
410
         exit 528253
406
     fi
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
     fi
415
     fi
411
 
416
 
412
     # an unprivileged user to run as
417
     # an unprivileged user to run as
413
     chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
418
     chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
414
 
419
 
415
     # daemon
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
     scuttlebot_git_setup mesh
438
     scuttlebot_git_setup mesh
434
     git_ssb_script mesh
439
     git_ssb_script mesh
455
     useradd -d /etc/scuttlebot/ scuttlebot
460
     useradd -d /etc/scuttlebot/ scuttlebot
456
 
461
 
457
     # daemon
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
     chown -R scuttlebot:scuttlebot /etc/scuttlebot
480
     chown -R scuttlebot:scuttlebot /etc/scuttlebot
476
 
481
 
489
         exit 73528
494
         exit 73528
490
     fi
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
     chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
515
     chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
511
     systemctl restart scuttlebot.service
516
     systemctl restart scuttlebot.service
512
 
517
 
527
 
532
 
528
     systemctl restart nginx
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
     else
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
     fi
539
     fi
535
 
540
 
536
     APP_INSTALLED=1
541
     APP_INSTALLED=1

+ 607
- 611
src/freedombone-app-searx
文件差异内容过多而无法显示
查看文件


+ 115
- 108
src/freedombone-app-syncthing 查看文件

66
 
66
 
67
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
67
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
68
     if [ ! -f $SYNCTHING_CONFIG_FILE ]; then
68
     if [ ! -f $SYNCTHING_CONFIG_FILE ]; then
69
-        echo $'# Your syncthing configuration file' > $SYNCTHING_CONFIG_FILE
70
-        echo '#' >> $SYNCTHING_CONFIG_FILE
71
-        echo $"# The ${PROJECT_NAME} syncthing ID is: $SYNCTHING_ID" >> $SYNCTHING_CONFIG_FILE
72
-        echo '#' >> $SYNCTHING_CONFIG_FILE
73
-        echo '# Paste the IDs of your devices below' >> $SYNCTHING_CONFIG_FILE
74
-        echo '#' >> $SYNCTHING_CONFIG_FILE
69
+        { echo $'# Your syncthing configuration file';
70
+          echo '#';
71
+          echo $"# The ${PROJECT_NAME} syncthing ID is: $SYNCTHING_ID";
72
+          echo '#';
73
+          echo '# Paste the IDs of your devices below';
74
+          echo '#'; } > $SYNCTHING_CONFIG_FILE
75
     fi
75
     fi
76
 }
76
 }
77
 
77
 
94
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
94
     SYNCTHING_ID=$(cat ~/.syncthing-server-id)
95
     dialog --title $"Device ID for ${PROJECT_NAME}" \
95
     dialog --title $"Device ID for ${PROJECT_NAME}" \
96
            --backtitle $"Freedombone User Control Panel" \
96
            --backtitle $"Freedombone User Control Panel" \
97
-           --msgbox $"In a desktop terminal press shift and select the ID below,\nthen right click and copy.\n\nWithin Connectbot select Menu/Copy and then highlight the ID below\n\n$SYNCTHING_ID\n\nAlternatively press Enter to display a QR code which can be scanned." 13 78
97
+           --msgbox $"In a desktop terminal press shift and select the ID below,\\nthen right click and copy.\\n\\nWithin Connectbot select Menu/Copy and then highlight the ID below\\n\\n$SYNCTHING_ID\\n\\nAlternatively press Enter to display a QR code which can be scanned." 13 78
98
     clear
98
     clear
99
     echo $'Your Syncthing ID code'
99
     echo $'Your Syncthing ID code'
100
     echo ''
100
     echo ''
101
     echo -n "$SYNCTHING_ID" | qrencode -t UTF8
101
     echo -n "$SYNCTHING_ID" | qrencode -t UTF8
102
     echo ''
102
     echo ''
103
+    # shellcheck disable=SC2034
103
     read -n1 -rsp $"Press any key to continue..." key
104
     read -n1 -rsp $"Press any key to continue..." key
104
 }
105
 }
105
 
106
 
110
 
111
 
111
     syncthing_create_ids_file
112
     syncthing_create_ids_file
112
 
113
 
113
-    data=$(tempfile 2>/dev/null)
114
-    trap "rm -f $data" 0 1 2 5 15
114
+    data=$(mktemp 2>/dev/null)
115
     dialog --backtitle $"Freedombone User Control Panel" \
115
     dialog --backtitle $"Freedombone User Control Panel" \
116
            --title $"Add a Syncthing device ID" \
116
            --title $"Add a Syncthing device ID" \
117
            --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \
117
            --form $"Paste the device ID for your laptop/desktop/netbook/phone/tablet below" 9 80 2 \
118
            $"Device ID:" 1 1 "" 1 26 80 80 \
118
            $"Device ID:" 1 1 "" 1 26 80 80 \
119
            $"Description (optional):" 2 1 "" 2 26 80 80 \
119
            $"Description (optional):" 2 1 "" 2 26 80 80 \
120
-           2> $data
120
+           2> "$data"
121
     sel=$?
121
     sel=$?
122
     case $sel in
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
     esac
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
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
132
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
130
         return
133
         return
164
 
167
 
165
     syncthing_create_ids_file
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
     dialog --backtitle $"Freedombone User Control Panel" \
171
     dialog --backtitle $"Freedombone User Control Panel" \
170
            --title $"Remove a Syncthing device ID" \
172
            --title $"Remove a Syncthing device ID" \
171
            --form $"Paste the device ID which is to be removed below" 8 80 1 \
173
            --form $"Paste the device ID which is to be removed below" 8 80 1 \
172
            $"Device ID:" 1 1 "" 1 14 80 80 \
174
            $"Device ID:" 1 1 "" 1 14 80 80 \
173
-           2> $data
175
+           2> "$data"
174
     sel=$?
176
     sel=$?
175
     case $sel in
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
     esac
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
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
186
     if [ ${#SYNCTHING_DEVICE_ID} -lt 10 ]; then
182
         return
187
         return
212
 
217
 
213
     while true
218
     while true
214
     do
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
         dialog --backtitle $"Freedombone User Control Panel" \
221
         dialog --backtitle $"Freedombone User Control Panel" \
218
                --title $"File Synchronization" \
222
                --title $"File Synchronization" \
219
                --radiolist $"Choose an operation:" 12 70 6 \
223
                --radiolist $"Choose an operation:" 12 70 6 \
221
                2 $"Add an ID for another machine or device" off \
225
                2 $"Add an ID for another machine or device" off \
222
                3 $"Remove an ID for another machine or device" off \
226
                3 $"Remove an ID for another machine or device" off \
223
                4 $"Manually edit device IDs" off \
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
         sel=$?
229
         sel=$?
226
         case $sel in
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
         esac
235
         esac
230
-        case $(cat $data) in
236
+        case $(cat "$data") in
231
             1) syncthing_show_id;;
237
             1) syncthing_show_id;;
232
             2) syncthing_add_id;;
238
             2) syncthing_add_id;;
233
             3) syncthing_remove_id;;
239
             3) syncthing_remove_id;;
234
             4) syncthing_manual_edit;;
240
             4) syncthing_manual_edit;;
235
-            5) break;;
241
+            5) rm -f "$data"
242
+               break;;
236
         esac
243
         esac
244
+        rm -f "$data"
237
     done
245
     done
238
 }
246
 }
239
 
247
 
260
     for d in /home/*/ ; do
268
     for d in /home/*/ ; do
261
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
269
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
262
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
270
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
263
-            if [ -d /home/$USERNAME/Sync ]; then
271
+            if [ -d "/home/$USERNAME/Sync" ]; then
264
                 echo $"Backing up syncthing files for $USERNAME"
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
                 # ensure that device IDs will be backed up as part of user config settings
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
                 fi
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
                 fi
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
                 fi
286
                 fi
279
             fi
287
             fi
280
         fi
288
         fi
288
     fi
296
     fi
289
 
297
 
290
     temp_restore_dir=/root/tempsyncthing
298
     temp_restore_dir=/root/tempsyncthing
291
-    if [ -d $USB_MOUNT/backup/syncthingconfig ]; then
299
+    if [ -d "$USB_MOUNT/backup/syncthingconfig" ]; then
292
         echo $"Restoring syncthing configuration"
300
         echo $"Restoring syncthing configuration"
293
         function_check restore_directory_from_usb
301
         function_check restore_directory_from_usb
294
         restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
302
         restore_directory_from_usb ${temp_restore_dir}config syncthingconfig
297
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
305
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
298
             mkdir -p $SYNCTHING_CONFIG_PATH
306
             mkdir -p $SYNCTHING_CONFIG_PATH
299
         fi
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
             set_user_permissions
309
             set_user_permissions
304
             backup_unmount_drive
310
             backup_unmount_drive
305
             systemctl start syncthing
311
             systemctl start syncthing
309
         rm -rf ${temp_restore_dir}config
315
         rm -rf ${temp_restore_dir}config
310
     fi
316
     fi
311
 
317
 
312
-    if [ -d $USB_MOUNT/backup/syncthingshared ]; then
318
+    if [ -d "$USB_MOUNT/backup/syncthingshared" ]; then
313
         echo $"Restoring syncthing shared files"
319
         echo $"Restoring syncthing shared files"
314
         restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
320
         restore_directory_from_usb ${temp_restore_dir}shared syncthingshared
315
         #cp -r ${temp_restore_dir}shared/* /
321
         #cp -r ${temp_restore_dir}shared/* /
321
         rm -rf ${temp_restore_dir}shared
327
         rm -rf ${temp_restore_dir}shared
322
     fi
328
     fi
323
 
329
 
324
-    if [ -d $USB_MOUNT/backup/syncthing ]; then
330
+    if [ -d "$USB_MOUNT/backup/syncthing" ]; then
325
         for d in $USB_MOUNT/backup/syncthing/*/ ; do
331
         for d in $USB_MOUNT/backup/syncthing/*/ ; do
326
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
332
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
327
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
336
                 fi
331
                 echo $"Restoring syncthing files for $USERNAME"
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
                 else
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
                     fi
344
                     fi
339
                     if [ -d /root/Sync ]; then
345
                     if [ -d /root/Sync ]; then
340
-                        cp -r /root/Sync/* /home/$USERNAME/Sync/
346
+                        cp -r /root/Sync/* "/home/$USERNAME/Sync/"
341
                         rm -rf /root/Sync
347
                         rm -rf /root/Sync
342
                     else
348
                     else
343
-                        cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
349
+                        cp -r "${temp_restore_dir}/*" "/home/$USERNAME/Sync/"
344
                     fi
350
                     fi
345
                 fi
351
                 fi
352
+                # shellcheck disable=SC2181
346
                 if [ ! "$?" = "0" ]; then
353
                 if [ ! "$?" = "0" ]; then
347
                     rm -rf ${temp_restore_dir}
354
                     rm -rf ${temp_restore_dir}
348
                     set_user_permissions
355
                     set_user_permissions
354
                 rm -rf ${temp_restore_dir}
361
                 rm -rf ${temp_restore_dir}
355
 
362
 
356
                 # restore device IDs from config settings
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
                 fi
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
                 fi
371
                 fi
365
             fi
372
             fi
366
         done
373
         done
389
     for d in /home/*/ ; do
396
     for d in /home/*/ ; do
390
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
397
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
391
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
398
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
392
-            if [ -d /home/$USERNAME/Sync ]; then
399
+            if [ -d "/home/$USERNAME/Sync" ]; then
393
                 echo $"Backing up syncthing files for $USERNAME"
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
                 # ensure that device IDs will be backed up as part of user config settings
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
                 fi
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
                 fi
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
                 fi
414
                 fi
408
             fi
415
             fi
409
         fi
416
         fi
416
         systemctl stop cron
423
         systemctl stop cron
417
     fi
424
     fi
418
 
425
 
419
-    if [ -d $SERVER_DIRECTORY/backup/syncthingconfig ]; then
426
+    if [ -d "$SERVER_DIRECTORY/backup/syncthingconfig" ]; then
420
         echo $"Restoring syncthing configuration"
427
         echo $"Restoring syncthing configuration"
421
         temp_restore_dir=/root/tempsyncthingconfig
428
         temp_restore_dir=/root/tempsyncthingconfig
422
         function_check restore_directory_from_friend
429
         function_check restore_directory_from_friend
425
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
432
         if [ ! -d $SYNCTHING_CONFIG_PATH ]; then
426
             mkdir -p $SYNCTHING_CONFIG_PATH
433
             mkdir -p $SYNCTHING_CONFIG_PATH
427
         fi
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
             systemctl start syncthing
436
             systemctl start syncthing
431
             systemctl start cron
437
             systemctl start cron
432
             exit 6833
438
             exit 6833
434
         rm -rf $temp_restore_dir
440
         rm -rf $temp_restore_dir
435
     fi
441
     fi
436
 
442
 
437
-    if [ -d $SERVER_DIRECTORY/backup/syncthingshared ]; then
443
+    if [ -d "$SERVER_DIRECTORY/backup/syncthingshared" ]; then
438
         echo $"Restoring syncthing shared files"
444
         echo $"Restoring syncthing shared files"
439
         temp_restore_dir=/root/tempsyncthingshared
445
         temp_restore_dir=/root/tempsyncthingshared
440
         function_check restore_directory_from_friend
446
         function_check restore_directory_from_friend
446
         rm -rf ${temp_restore_dir}
452
         rm -rf ${temp_restore_dir}
447
     fi
453
     fi
448
 
454
 
449
-    if [ -d $SERVER_DIRECTORY/backup/syncthing ]; then
455
+    if [ -d "$SERVER_DIRECTORY/backup/syncthing" ]; then
450
         for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
456
         for d in $SERVER_DIRECTORY/backup/syncthing/*/ ; do
451
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
457
             USERNAME=$(echo "$d" | awk -F '/' '{print $6}')
452
             if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
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
                 fi
461
                 fi
456
                 echo $"Restoring syncthing files for $USERNAME"
462
                 echo $"Restoring syncthing files for $USERNAME"
457
                 temp_restore_dir=/root/tempsyncthing
463
                 temp_restore_dir=/root/tempsyncthing
458
                 function_check restore_directory_from_friend
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
                 else
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
                     fi
471
                     fi
466
                     if [ -d /root/Sync ]; then
472
                     if [ -d /root/Sync ]; then
467
-                        cp -r /root/Sync/* /home/$USERNAME/Sync/
473
+                        cp -r /root/Sync/* "/home/$USERNAME/Sync/"
468
                         rm -rf /root/Sync
474
                         rm -rf /root/Sync
469
                     else
475
                     else
470
-                        cp -r ${temp_restore_dir}/* /home/$USERNAME/Sync/
476
+                        cp -r "${temp_restore_dir}/*" "/home/$USERNAME/Sync/"
471
                     fi
477
                     fi
472
                 fi
478
                 fi
479
+                # shellcheck disable=SC2181
473
                 if [ ! "$?" = "0" ]; then
480
                 if [ ! "$?" = "0" ]; then
474
                     rm -rf $temp_restore_dir
481
                     rm -rf $temp_restore_dir
475
                     systemctl start syncthing
482
                     systemctl start syncthing
479
                 rm -rf $temp_restore_dir
486
                 rm -rf $temp_restore_dir
480
 
487
 
481
                 # restore device IDs from config settings
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
                 fi
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
                 fi
496
                 fi
490
                 echo $"Restore of syncthing files for $USERNAME complete"
497
                 echo $"Restore of syncthing files for $USERNAME complete"
491
             fi
498
             fi
512
 }
519
 }
513
 
520
 
514
 function configure_firewall_for_syncthing {
521
 function configure_firewall_for_syncthing {
515
-    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
522
+    if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
516
         return
523
         return
517
     fi
524
     fi
518
 
525
 
519
     firewall_add Syncthing ${SYNCTHING_PORT}
526
     firewall_add Syncthing ${SYNCTHING_PORT}
520
-    mark_completed $FUNCNAME
527
+    mark_completed "${FUNCNAME[0]}"
521
 }
528
 }
522
 
529
 
523
 function install_syncthing_repo {
530
 function install_syncthing_repo {
537
 
544
 
538
     # This probably does need to run as root so that it can access the Sync directories
545
     # This probably does need to run as root so that it can access the Sync directories
539
     # in each user's home directory
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
     systemctl enable syncthing
563
     systemctl enable syncthing
557
     systemctl daemon-reload
564
     systemctl daemon-reload
558
     systemctl start syncthing
565
     systemctl start syncthing

+ 164
- 157
src/freedombone-app-tahoelafs 查看文件

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

+ 202
- 206
src/freedombone-app-tox 查看文件

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

+ 95
- 87
src/freedombone-app-turtl 查看文件

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

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

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

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

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

+ 0
- 498
src/freedombone-app-wekan 查看文件

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

+ 8
- 8
src/freedombone-archive-mail 查看文件

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

+ 61
- 60
src/freedombone-backup-local 查看文件

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

+ 94
- 92
src/freedombone-backup-remote 查看文件

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

+ 594
- 654
src/freedombone-base-email
文件差异内容过多而无法显示
查看文件


+ 30
- 30
src/freedombone-base-tripwire 查看文件

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

+ 53
- 52
src/freedombone-client 查看文件

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

+ 51
- 55
src/freedombone-clientcert 查看文件

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

+ 170
- 135
src/freedombone-config 查看文件

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

+ 410
- 438
src/freedombone-controlpanel
文件差异内容过多而无法显示
查看文件


+ 207
- 220
src/freedombone-controlpanel-user
文件差异内容过多而无法显示
查看文件


+ 14
- 15
src/freedombone-dhparam 查看文件

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

+ 8
- 8
src/freedombone-encrypt-mail 查看文件

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

+ 5
- 8
src/freedombone-format 查看文件

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

+ 8
- 7
src/freedombone-freedns 查看文件

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

+ 21
- 21
src/freedombone-ignore 查看文件

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

+ 78
- 77
src/freedombone-image 查看文件

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

+ 695
- 661
src/freedombone-image-customise
文件差异内容过多而无法显示
查看文件


+ 19
- 25
src/freedombone-image-hardware-setup 查看文件

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

+ 52
- 52
src/freedombone-image-make 查看文件

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

+ 648
- 645
src/freedombone-image-mesh
文件差异内容过多而无法显示
查看文件


+ 2
- 2
src/freedombone-image-vmdebootstrap 查看文件

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

+ 41
- 43
src/freedombone-keydrive 查看文件

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

+ 16
- 16
src/freedombone-logging 查看文件

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

+ 78
- 73
src/freedombone-mesh-batman 查看文件

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

+ 48
- 47
src/freedombone-mesh-blog 查看文件

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

+ 5
- 4
src/freedombone-mesh-connect 查看文件

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

+ 107
- 107
src/freedombone-mesh-install 查看文件

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

+ 2
- 2
src/freedombone-mesh-invite 查看文件

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

+ 3
- 3
src/freedombone-mesh-reset 查看文件

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

+ 35
- 35
src/freedombone-mesh-routing 查看文件

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

+ 7
- 6
src/freedombone-mesh-visit-site 查看文件

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

+ 44
- 45
src/freedombone-pass 查看文件

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

+ 18
- 18
src/freedombone-pin-cert 查看文件

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

+ 8
- 8
src/freedombone-powerline 查看文件

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

+ 31
- 30
src/freedombone-recoverkey 查看文件

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

+ 33
- 33
src/freedombone-remote 查看文件

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

+ 4
- 5
src/freedombone-renew-cert 查看文件

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

+ 15
- 15
src/freedombone-repair-database 查看文件

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

+ 145
- 130
src/freedombone-restore-local 查看文件

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

+ 0
- 0
src/freedombone-restore-remote 查看文件


部分文件因为文件数量过多而无法显示