Browse Source

More tidying

Bob Mottram 7 years ago
parent
commit
5479d49dc9

+ 243
- 240
src/freedombone-app-etherpad View File

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 View File

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
 

+ 251
- 249
src/freedombone-app-friendica View File

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 View File

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
File diff suppressed because it is too large
View File


+ 222
- 215
src/freedombone-app-gogs View File

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 View File

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 View File

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 View File

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

+ 146
- 146
src/freedombone-app-ipfs View File

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 {
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}
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}
289
 
292
 
290
     mark_completed "${FUNCNAME[0]}"
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
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

+ 208
- 203
src/freedombone-app-irc View File

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
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 View File

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 View File

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
 

+ 207
- 200
src/freedombone-app-keyserver View File

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
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 View File

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 View File

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 View File

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 View File

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