|
@@ -1,536 +0,0 @@
|
1
|
|
-#!/bin/bash
|
2
|
|
-#
|
3
|
|
-# _____ _ _
|
4
|
|
-# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
|
5
|
|
-# | __| _| -_| -_| . | . | | . | . | | -_|
|
6
|
|
-# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
|
7
|
|
-#
|
8
|
|
-# Freedom in the Cloud
|
9
|
|
-#
|
10
|
|
-# License
|
11
|
|
-# =======
|
12
|
|
-#
|
13
|
|
-# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
|
14
|
|
-#
|
15
|
|
-# This program is free software: you can redistribute it and/or modify
|
16
|
|
-# it under the terms of the GNU Affero General Public License as published by
|
17
|
|
-# the Free Software Foundation, either version 3 of the License, or
|
18
|
|
-# (at your option) any later version.
|
19
|
|
-#
|
20
|
|
-# This program is distributed in the hope that it will be useful,
|
21
|
|
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22
|
|
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23
|
|
-# GNU Affero General Public License for more details.
|
24
|
|
-#
|
25
|
|
-# You should have received a copy of the GNU Affero General Public License
|
26
|
|
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
27
|
|
-
|
28
|
|
-VARIANTS='full full-vim'
|
29
|
|
-
|
30
|
|
-IN_DEFAULT_INSTALL=0
|
31
|
|
-SHOW_ON_ABOUT=1
|
32
|
|
-
|
33
|
|
-HACKMD_DOMAIN_NAME=
|
34
|
|
-HACKMD_CODE=
|
35
|
|
-HACKMD_ONION_PORT=9052
|
36
|
|
-HACKMD_REPO="https://github.com/hackmdio/hackmd"
|
37
|
|
-HACKMD_COMMIT='c71361467d6eee6519b050fb5c40fc32520a19a8'
|
38
|
|
-HACKMD_PORT_INTERNAL=3007
|
39
|
|
-
|
40
|
|
-hackmd_variables=(ONION_ONLY
|
41
|
|
- HACKMD_DOMAIN_NAME
|
42
|
|
- HACKMD_CODE
|
43
|
|
- DDNS_PROVIDER
|
44
|
|
- MY_USERNAME)
|
45
|
|
-
|
46
|
|
-function logging_on_hackmd {
|
47
|
|
- echo -n ''
|
48
|
|
-}
|
49
|
|
-
|
50
|
|
-function logging_off_hackmd {
|
51
|
|
- echo -n ''
|
52
|
|
-}
|
53
|
|
-
|
54
|
|
-function remove_user_hackmd {
|
55
|
|
- remove_username="$1"
|
56
|
|
-
|
57
|
|
- "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp hackmd
|
58
|
|
-}
|
59
|
|
-
|
60
|
|
-function add_user_hackmd {
|
61
|
|
- new_username="$1"
|
62
|
|
- new_user_password="$2"
|
63
|
|
-
|
64
|
|
- "${PROJECT_NAME}-pass" -u "$new_username" -a hackmd -p "$new_user_password"
|
65
|
|
- echo '0'
|
66
|
|
-}
|
67
|
|
-
|
68
|
|
-function install_interactive_hackmd {
|
69
|
|
- if [ ! "$ONION_ONLY" ]; then
|
70
|
|
- ONION_ONLY='no'
|
71
|
|
- fi
|
72
|
|
-
|
73
|
|
- if [[ "$ONION_ONLY" != "no" ]]; then
|
74
|
|
- HACKMD_DOMAIN_NAME='hackmd.local'
|
75
|
|
- write_config_param "HACKMD_DOMAIN_NAME" "$HACKMD_DOMAIN_NAME"
|
76
|
|
- else
|
77
|
|
- interactive_site_details "hackmd" "HACKMD_DOMAIN_NAME" "HACKMD_CODE"
|
78
|
|
- fi
|
79
|
|
- APP_INSTALLED=1
|
80
|
|
-}
|
81
|
|
-
|
82
|
|
-function change_password_hackmd {
|
83
|
|
- curr_username="$1"
|
84
|
|
- new_user_password="$2"
|
85
|
|
-
|
86
|
|
- read_config_param 'HACKMD_DOMAIN_NAME'
|
87
|
|
-
|
88
|
|
- "${PROJECT_NAME}-pass" -u "$curr_username" -a hackmd -p "$new_user_password"
|
89
|
|
-}
|
90
|
|
-
|
91
|
|
-function hackmd_create_database {
|
92
|
|
- if [ -f "$IMAGE_PASSWORD_FILE" ]; then
|
93
|
|
- HACKMD_ADMIN_PASSWORD="$(printf "%d" "$(cat "")")"
|
94
|
|
- else
|
95
|
|
- if [ ! "$HACKMD_ADMIN_PASSWORD" ]; then
|
96
|
|
- HACKMD_ADMIN_PASSWORD=$(create_password "${MINIMUM_PASSWORD_LENGTH}")
|
97
|
|
- fi
|
98
|
|
- fi
|
99
|
|
- if [ ! "$HACKMD_ADMIN_PASSWORD" ]; then
|
100
|
|
- return
|
101
|
|
- fi
|
102
|
|
-
|
103
|
|
- create_database hackmd "$HACKMD_ADMIN_PASSWORD" "$MY_USERNAME"
|
104
|
|
-}
|
105
|
|
-
|
106
|
|
-function reconfigure_hackmd {
|
107
|
|
- # This is used if you need to switch identity. Dump old keys and generate new ones
|
108
|
|
- echo -n ''
|
109
|
|
-}
|
110
|
|
-
|
111
|
|
-function configure_interactive_hackmd {
|
112
|
|
- W=(1 $"Option 1"
|
113
|
|
- 2 $"Option 2")
|
114
|
|
-
|
115
|
|
- while true
|
116
|
|
- do
|
117
|
|
- # shellcheck disable=SC2068
|
118
|
|
- selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"hackmd" --menu $"Choose an operation, or ESC for main menu:" 14 70 3 "${W[@]}" 3>&2 2>&1 1>&3)
|
119
|
|
-
|
120
|
|
- if [ ! "$selection" ]; then
|
121
|
|
- break
|
122
|
|
- fi
|
123
|
|
- case $selection in
|
124
|
|
- 1) # call some function for option 1
|
125
|
|
- ;;
|
126
|
|
- 2) # call some function for option 2
|
127
|
|
- ;;
|
128
|
|
- esac
|
129
|
|
- done
|
130
|
|
-}
|
131
|
|
-
|
132
|
|
-function upgrade_hackmd {
|
133
|
|
- CURR_HACKMD_COMMIT=$(get_completion_param "hackmd commit")
|
134
|
|
- if [[ "$CURR_HACKMD_COMMIT" == "$HACKMD_COMMIT" ]]; then
|
135
|
|
- return
|
136
|
|
- fi
|
137
|
|
-
|
138
|
|
- if grep -q "hackmd domain" "$COMPLETION_FILE"; then
|
139
|
|
- HACKMD_DOMAIN_NAME=$(get_completion_param "hackmd domain")
|
140
|
|
- fi
|
141
|
|
-
|
142
|
|
- # update to the next commit
|
143
|
|
- set_repo_commit "/etc/hackmd" "hackmd commit" "$HACKMD_COMMIT" "$HACKMD_REPO"
|
144
|
|
-
|
145
|
|
- # Remove references to markdown-pdf node package, because it doesn't install on arm
|
146
|
|
- cd /etc/hackmd || return
|
147
|
|
- sed -i '/markdown-pdf/d' lib/response.js
|
148
|
|
- sed -i '/markdownpdf/,/})/d' lib/response.js
|
149
|
|
- mv yarn.lock yarn.lock.old
|
150
|
|
- npm install
|
151
|
|
-
|
152
|
|
- chown -R hackmd:hackmd "/etc/hackmd"
|
153
|
|
- systemctl restart hackmd
|
154
|
|
-}
|
155
|
|
-
|
156
|
|
-function backup_local_hackmd {
|
157
|
|
- HACKMD_DOMAIN_NAME='hackmd'
|
158
|
|
- if grep -q "hackmd domain" "$COMPLETION_FILE"; then
|
159
|
|
- HACKMD_DOMAIN_NAME=$(get_completion_param "hackmd domain")
|
160
|
|
- fi
|
161
|
|
-
|
162
|
|
- source_directory=/etc/hackmd
|
163
|
|
-
|
164
|
|
- suspend_site "${HACKMD_DOMAIN_NAME}"
|
165
|
|
-
|
166
|
|
- systemctl stop hackmd
|
167
|
|
-
|
168
|
|
- dest_directory=hackmd
|
169
|
|
- backup_directory_to_usb "$source_directory" $dest_directory
|
170
|
|
-
|
171
|
|
- backup_database_to_usb hackmd
|
172
|
|
-
|
173
|
|
- restart_site
|
174
|
|
- systemctl start hackmd
|
175
|
|
-}
|
176
|
|
-
|
177
|
|
-function restore_local_hackmd {
|
178
|
|
- if ! grep -q "hackmd domain" "$COMPLETION_FILE"; then
|
179
|
|
- return
|
180
|
|
- fi
|
181
|
|
- HACKMD_DOMAIN_NAME=$(get_completion_param "hackmd domain")
|
182
|
|
- if [ ! "$HACKMD_DOMAIN_NAME" ]; then
|
183
|
|
- return
|
184
|
|
- fi
|
185
|
|
- suspend_site "${HACKMD_DOMAIN_NAME}"
|
186
|
|
- systemctl stop hackmd
|
187
|
|
-
|
188
|
|
- temp_restore_dir=/root/temphackmd
|
189
|
|
- hackmd_dir=/etc/hackmd
|
190
|
|
-
|
191
|
|
- hackmd_create_database
|
192
|
|
-
|
193
|
|
- restore_database hackmd
|
194
|
|
- if [ -d $temp_restore_dir ]; then
|
195
|
|
- rm -rf $temp_restore_dir
|
196
|
|
- fi
|
197
|
|
-
|
198
|
|
- restore_directory_from_usb $temp_restore_dir hackmd
|
199
|
|
- if [ -d $temp_restore_dir ]; then
|
200
|
|
- if [ -d "$temp_restore_dir$hackmd_dir" ]; then
|
201
|
|
- cp -rp "$temp_restore_dir$hackmd_dir"/* "$hackmd_dir"/
|
202
|
|
- else
|
203
|
|
- if [ ! -d "$hackmd_dir" ]; then
|
204
|
|
- mkdir "$hackmd_dir"
|
205
|
|
- fi
|
206
|
|
- cp -rp "$temp_restore_dir"/* "$hackmd_dir"/
|
207
|
|
- fi
|
208
|
|
- chown -R hackmd:hackmd "$hackmd_dir"
|
209
|
|
- rm -rf $temp_restore_dir
|
210
|
|
- fi
|
211
|
|
- systemctl start hackmd
|
212
|
|
-
|
213
|
|
- restart_site
|
214
|
|
-}
|
215
|
|
-
|
216
|
|
-function backup_remote_hackmd {
|
217
|
|
- HACKMD_DOMAIN_NAME='hackmd'
|
218
|
|
- if grep -q "hackmd domain" "$COMPLETION_FILE"; then
|
219
|
|
- HACKMD_DOMAIN_NAME=$(get_completion_param "hackmd domain")
|
220
|
|
- fi
|
221
|
|
-
|
222
|
|
- source_directory=/etc/hackmd
|
223
|
|
-
|
224
|
|
- suspend_site "${HACKMD_DOMAIN_NAME}"
|
225
|
|
- systemctl stop hackmd
|
226
|
|
-
|
227
|
|
- dest_directory=hackmd
|
228
|
|
- backup_directory_to_friend "$source_directory" $dest_directory
|
229
|
|
- backup_database_to_friend hackmd
|
230
|
|
-
|
231
|
|
-
|
232
|
|
- systemctl start hackmd
|
233
|
|
-
|
234
|
|
- restart_site
|
235
|
|
-}
|
236
|
|
-
|
237
|
|
-function restore_remote_hackmd {
|
238
|
|
- if ! grep -q "hackmd domain" "$COMPLETION_FILE"; then
|
239
|
|
- return
|
240
|
|
- fi
|
241
|
|
- HACKMD_DOMAIN_NAME=$(get_completion_param "hackmd domain")
|
242
|
|
- if [ ! "$HACKMD_DOMAIN_NAME" ]; then
|
243
|
|
- return
|
244
|
|
- fi
|
245
|
|
- suspend_site "${HACKMD_DOMAIN_NAME}"
|
246
|
|
- systemctl stop hackmd
|
247
|
|
-
|
248
|
|
- temp_restore_dir=/root/temphackmd
|
249
|
|
- hackmd_dir=/etc/hackmd
|
250
|
|
-
|
251
|
|
- hackmd_create_database
|
252
|
|
-
|
253
|
|
- restore_database_from_friend hackmd
|
254
|
|
- if [ -d "$temp_restore_dir" ]; then
|
255
|
|
- rm -rf $temp_restore_dir
|
256
|
|
- fi
|
257
|
|
-
|
258
|
|
- restore_directory_from_friend $temp_restore_dir hackmd
|
259
|
|
- if [ -d $temp_restore_dir ]; then
|
260
|
|
- if [ -d "$temp_restore_dir$hackmd_dir" ]; then
|
261
|
|
- cp -rp "$temp_restore_dir$hackmd_dir"/* "$hackmd_dir"/
|
262
|
|
- else
|
263
|
|
- if [ ! -d "$hackmd_dir" ]; then
|
264
|
|
- mkdir "$hackmd_dir"
|
265
|
|
- fi
|
266
|
|
- cp -rp $temp_restore_dir/* "$hackmd_dir"/
|
267
|
|
- fi
|
268
|
|
- chown -R hackmd:hackmd "$hackmd_dir"
|
269
|
|
- rm -rf $temp_restore_dir
|
270
|
|
- fi
|
271
|
|
- systemctl start hackmd
|
272
|
|
-
|
273
|
|
- restart_site
|
274
|
|
-}
|
275
|
|
-
|
276
|
|
-function remove_hackmd {
|
277
|
|
- nginx_dissite "$HACKMD_DOMAIN_NAME"
|
278
|
|
- remove_certs "$HACKMD_DOMAIN_NAME"
|
279
|
|
-
|
280
|
|
- if [ -f /etc/systemd/system/hackmd.service ]; then
|
281
|
|
- systemctl stop hackmd
|
282
|
|
- systemctl disable hackmd
|
283
|
|
- rm /etc/systemd/system/hackmd.service
|
284
|
|
- fi
|
285
|
|
- userdel -r hackmd
|
286
|
|
- remove_nodejs hackmd
|
287
|
|
-
|
288
|
|
-
|
289
|
|
- if [ -d "/var/www/$HACKMD_DOMAIN_NAME" ]; then
|
290
|
|
- rm -rf "/var/www/$HACKMD_DOMAIN_NAME"
|
291
|
|
- fi
|
292
|
|
- if [ -f "/etc/nginx/sites-available/$HACKMD_DOMAIN_NAME" ]; then
|
293
|
|
- rm "/etc/nginx/sites-available/$HACKMD_DOMAIN_NAME"
|
294
|
|
- fi
|
295
|
|
- drop_database hackmd
|
296
|
|
- remove_onion_service hackmd "${HACKMD_ONION_PORT}"
|
297
|
|
- if grep -q "hackmd" /etc/crontab; then
|
298
|
|
- sed -i "/hackmd/d" /etc/crontab
|
299
|
|
- fi
|
300
|
|
- remove_app hackmd
|
301
|
|
- remove_completion_param install_hackmd
|
302
|
|
- sed -i '/hackmd/d' "$COMPLETION_FILE"
|
303
|
|
-
|
304
|
|
- remove_ddns_domain "$HACKMD_DOMAIN_NAME"
|
305
|
|
- systemctl restart nginx
|
306
|
|
-}
|
307
|
|
-
|
308
|
|
-function hackmd_create_config {
|
309
|
|
- hackmd_secret=$(create_password "30")$(create_password "30")$(create_password "30")
|
310
|
|
-
|
311
|
|
- { echo '{';
|
312
|
|
- echo ' "production": {';
|
313
|
|
- echo " \"sessionSecret\": \"$hackmd_secret\",";
|
314
|
|
- echo ' "domain": "localhost",';
|
315
|
|
- echo ' "hsts": {';
|
316
|
|
- echo ' "enable": false,';
|
317
|
|
- echo ' "maxAgeSeconds": "31536000",';
|
318
|
|
- echo ' "includeSubdomains": true,';
|
319
|
|
- echo ' "preload": true';
|
320
|
|
- echo ' },';
|
321
|
|
- echo ' "csp": {';
|
322
|
|
- echo ' "enable": false,';
|
323
|
|
- echo ' "directives": {';
|
324
|
|
- echo ' },';
|
325
|
|
- echo ' "upgradeInsecureRequests": "false",';
|
326
|
|
- echo ' "addDefaults": true,';
|
327
|
|
- echo ' "addDisqus": false,';
|
328
|
|
- echo ' "addGoogleAnalytics": false';
|
329
|
|
- echo ' },';
|
330
|
|
- echo ' "db": {';
|
331
|
|
- echo " \"username\": \"root\",";
|
332
|
|
- echo " \"password\": \"$MARIADB_PASSWORD\",";
|
333
|
|
- echo ' "database": "hackmd",';
|
334
|
|
- echo ' "host": "localhost",';
|
335
|
|
- echo ' "port": "5432",';
|
336
|
|
- echo ' "dialect": "mysql"';
|
337
|
|
- echo ' },';
|
338
|
|
- echo ' "github": {';
|
339
|
|
- echo ' "clientID": "change this",';
|
340
|
|
- echo ' "clientSecret": "change this"';
|
341
|
|
- echo ' },';
|
342
|
|
- echo ' "gitlab": {';
|
343
|
|
- echo ' "baseURL": "change this",';
|
344
|
|
- echo ' "clientID": "change this",';
|
345
|
|
- echo ' "clientSecret": "change this",';
|
346
|
|
- echo ' "scope": "use read_user scope for auth user only or remove this property if you need gitlab snippet import/export support (will result to be default scope api)"';
|
347
|
|
- echo ' }';
|
348
|
|
- echo ' }';
|
349
|
|
- echo '}'; } > config.json
|
350
|
|
-}
|
351
|
|
-
|
352
|
|
-function install_hackmd {
|
353
|
|
- apt-get -yq install phantomjs
|
354
|
|
-
|
355
|
|
- install_mariadb
|
356
|
|
-
|
357
|
|
- get_mariadb_password
|
358
|
|
-
|
359
|
|
- install_nodejs hackmd
|
360
|
|
- if [ ! "$HACKMD_DOMAIN_NAME" ]; then
|
361
|
|
- echo $'No domain name was given'
|
362
|
|
- exit 3568356
|
363
|
|
- fi
|
364
|
|
-
|
365
|
|
- if [ -d "/var/www/$HACKMD_DOMAIN_NAME/htdocs" ]; then
|
366
|
|
- rm -rf "/var/www/$HACKMD_DOMAIN_NAME/htdocs"
|
367
|
|
- fi
|
368
|
|
- if [ -d /repos/hackmd ]; then
|
369
|
|
- mkdir "/var/www/$HACKMD_DOMAIN_NAME/htdocs"
|
370
|
|
- cp -r -p /repos/hackmd/. "/etc/hackmd"
|
371
|
|
- cd "/etc/hackmd" || exit 36487365
|
372
|
|
- git pull
|
373
|
|
- else
|
374
|
|
- git_clone "$HACKMD_REPO" "/etc/hackmd"
|
375
|
|
- fi
|
376
|
|
-
|
377
|
|
- if [ ! -d "/etc/hackmd" ]; then
|
378
|
|
- echo $'Unable to clone hackmd repo'
|
379
|
|
- exit 87525
|
380
|
|
- fi
|
381
|
|
-
|
382
|
|
- cd "/etc/hackmd" || exit 3463754637
|
383
|
|
- git checkout "$HACKMD_COMMIT" -b "$HACKMD_COMMIT"
|
384
|
|
- set_completion_param "hackmd commit" "$HACKMD_COMMIT"
|
385
|
|
-
|
386
|
|
- if [ ! -f bin/setup ]; then
|
387
|
|
- echo $'No setup file found'
|
388
|
|
- exit 36587356
|
389
|
|
- fi
|
390
|
|
- chmod +x bin/setup
|
391
|
|
- ./bin/setup
|
392
|
|
- hackmd_create_config
|
393
|
|
- npm install
|
394
|
|
- npm install ejs
|
395
|
|
- npm install passport
|
396
|
|
- npm install method-override
|
397
|
|
- npm install cookie-parser
|
398
|
|
- npm install compression
|
399
|
|
- npm install express-session
|
400
|
|
- npm install connect-session-sequelize
|
401
|
|
- npm install morgan
|
402
|
|
- npm install passport.socketio
|
403
|
|
- npm install helmet
|
404
|
|
- npm install i18n
|
405
|
|
- npm install connect-flash
|
406
|
|
- npm install lodash
|
407
|
|
- npm install deep-freeze
|
408
|
|
- npm install winston
|
409
|
|
- npm install graceful-fs
|
410
|
|
- npm install webpack
|
411
|
|
- npm install extract-text-webpack-plugin
|
412
|
|
- npm install html-webpack-plugin
|
413
|
|
- npm install copy-webpack-plugin
|
414
|
|
- npm install eve
|
415
|
|
- npm install js-sequence-diagrams
|
416
|
|
- #npm install markdown-pdf
|
417
|
|
-
|
418
|
|
- sed -i '/markdown-pdf/d' lib/response.js
|
419
|
|
- sed -i '/markdownpdf/,/})/d' lib/response.js
|
420
|
|
-
|
421
|
|
- mv yarn.lock yarn.lock.old
|
422
|
|
- npm run build
|
423
|
|
-
|
424
|
|
- chmod g+w "/var/www/$HACKMD_DOMAIN_NAME/htdocs"
|
425
|
|
- chown -R www-data:www-data "/var/www/$HACKMD_DOMAIN_NAME/htdocs"
|
426
|
|
-
|
427
|
|
- hackmd_create_database
|
428
|
|
-
|
429
|
|
- add_ddns_domain "$HACKMD_DOMAIN_NAME"
|
430
|
|
-
|
431
|
|
- HACKMD_ONION_HOSTNAME=$(add_onion_service hackmd 80 "${HACKMD_ONION_PORT}")
|
432
|
|
-
|
433
|
|
- hackmd_nginx_site=/etc/nginx/sites-available/$HACKMD_DOMAIN_NAME
|
434
|
|
- if [[ "$ONION_ONLY" == "no" ]]; then
|
435
|
|
- nginx_http_redirect "$HACKMD_DOMAIN_NAME" "index index.html"
|
436
|
|
- { echo 'server {';
|
437
|
|
- echo ' listen 443 ssl;';
|
438
|
|
- echo ' #listen [::]:443 ssl;';
|
439
|
|
- echo " server_name $HACKMD_DOMAIN_NAME;";
|
440
|
|
- echo ''; } >> "$hackmd_nginx_site"
|
441
|
|
- nginx_compress "$HACKMD_DOMAIN_NAME"
|
442
|
|
- echo '' >> "$hackmd_nginx_site"
|
443
|
|
- echo ' # Security' >> "$hackmd_nginx_site"
|
444
|
|
- nginx_ssl "$HACKMD_DOMAIN_NAME"
|
445
|
|
-
|
446
|
|
- nginx_security_options "$HACKMD_DOMAIN_NAME"
|
447
|
|
-
|
448
|
|
- { echo ' add_header Strict-Transport-Security max-age=15768000;';
|
449
|
|
- echo '';
|
450
|
|
- echo ' access_log /dev/null;';
|
451
|
|
- echo ' error_log /dev/null;';
|
452
|
|
- echo '';
|
453
|
|
- echo " root /var/www/$HACKMD_DOMAIN_NAME/htdocs;";
|
454
|
|
- echo '';
|
455
|
|
- echo ' index index.html;';
|
456
|
|
- echo ' # Location';
|
457
|
|
- echo ' location / {'; } >> "$hackmd_nginx_site"
|
458
|
|
- nginx_limits "$HACKMD_DOMAIN_NAME" '15m'
|
459
|
|
- { echo " proxy_pass http://localhost:$HACKMD_PORT_INTERNAL;";
|
460
|
|
- echo ' }';
|
461
|
|
- echo '}'; } >> "$hackmd_nginx_site"
|
462
|
|
- else
|
463
|
|
- echo -n '' > "$hackmd_nginx_site"
|
464
|
|
- fi
|
465
|
|
- { echo 'server {';
|
466
|
|
- echo " listen 127.0.0.1:$HACKMD_ONION_PORT default_server;";
|
467
|
|
- echo " server_name $HACKMD_ONION_HOSTNAME;";
|
468
|
|
- echo ''; } >> "$hackmd_nginx_site"
|
469
|
|
- nginx_compress "$HACKMD_DOMAIN_NAME"
|
470
|
|
- echo '' >> "$hackmd_nginx_site"
|
471
|
|
- nginx_security_options "$HACKMD_DOMAIN_NAME"
|
472
|
|
- { echo '';
|
473
|
|
- echo ' access_log /dev/null;';
|
474
|
|
- echo ' error_log /dev/null;';
|
475
|
|
- echo '';
|
476
|
|
- echo " root /var/www/$HACKMD_DOMAIN_NAME/htdocs;";
|
477
|
|
- echo '';
|
478
|
|
- echo ' index index.html;';
|
479
|
|
- echo ' # Location';
|
480
|
|
- echo ' location / {'; } >> "$hackmd_nginx_site"
|
481
|
|
- nginx_limits "$HACKMD_DOMAIN_NAME" '15m'
|
482
|
|
- { echo " proxy_pass http://localhost:$HACKMD_PORT_INTERNAL;";
|
483
|
|
- echo ' }';
|
484
|
|
- echo '}'; } >> "$hackmd_nginx_site"
|
485
|
|
-
|
486
|
|
- adduser --system --home="/etc/hackmd" --group hackmd
|
487
|
|
-
|
488
|
|
- hmd_domain="$HACKMD_DOMAIN_NAME"
|
489
|
|
- if [[ "$ONION_ONLY" != 'no' ]]; then
|
490
|
|
- hmd_domain="$HACKMD_ONION_HOSTNAME"
|
491
|
|
- fi
|
492
|
|
-
|
493
|
|
- { echo '[Unit]';
|
494
|
|
- echo 'Description=hackmd';
|
495
|
|
- echo 'After=syslog.target';
|
496
|
|
- echo 'After=network.target';
|
497
|
|
- echo "Documentation=$HACKMD_REPO";
|
498
|
|
- echo '';
|
499
|
|
- echo '[Service]';
|
500
|
|
- echo 'Type=simple';
|
501
|
|
- echo 'User=hackmd';
|
502
|
|
- echo 'Group=hackmd';
|
503
|
|
- echo 'WorkingDirectory=/etc/hackmd';
|
504
|
|
- echo 'ExecStart=/usr/local/bin/npm start';
|
505
|
|
- echo 'ExecStop=/usr/local/bin/npm stop';
|
506
|
|
- echo 'Environment=USER=hackmd';
|
507
|
|
- echo 'Environment=NODE_ENV=production';
|
508
|
|
- echo "Environment=HMD_DOMAIN=$hmd_domain";
|
509
|
|
- echo "Environment=HMD_PORT=$HACKMD_PORT_INTERNAL";
|
510
|
|
- echo 'Environment=HMD_PROTOCOL_USESSL=false';
|
511
|
|
- echo 'Environment=HMD_ALLOW_ANONYMOUS=false';
|
512
|
|
- echo 'Environment=HMD_ALLOW_FREEURL=true';
|
513
|
|
- echo 'Restart=always';
|
514
|
|
- echo 'StandardError=syslog';
|
515
|
|
- echo '';
|
516
|
|
- echo '[Install]';
|
517
|
|
- echo 'WantedBy=multi-user.target'; } >> "/etc/systemd/system/hackmd.service"
|
518
|
|
- systemctl enable hackmd
|
519
|
|
- chown -R hackmd:hackmd "/etc/hackmd"
|
520
|
|
- systemctl start hackmd
|
521
|
|
-
|
522
|
|
- create_site_certificate "$HACKMD_DOMAIN_NAME" 'yes'
|
523
|
|
-
|
524
|
|
- nginx_ensite "$HACKMD_DOMAIN_NAME"
|
525
|
|
-
|
526
|
|
- systemctl restart mariadb
|
527
|
|
-
|
528
|
|
- systemctl restart nginx
|
529
|
|
-
|
530
|
|
- "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a hackmd -p "$HACKMD_ADMIN_PASSWORD"
|
531
|
|
- set_completion_param "hackmd domain" "$HACKMD_DOMAIN_NAME"
|
532
|
|
-
|
533
|
|
- APP_INSTALLED=1
|
534
|
|
-}
|
535
|
|
-
|
536
|
|
-# NOTE: deliberately there is no "exit 0"
|