|
@@ -0,0 +1,470 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# .---. . .
|
|
4
|
+# | | |
|
|
5
|
+# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
+# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
+# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
+#
|
|
9
|
+# Freedom in the Cloud
|
|
10
|
+#
|
|
11
|
+# turtl app
|
|
12
|
+#
|
|
13
|
+# http://portallinux.es/instalacion-servidor-turtl-debian-8
|
|
14
|
+# http://framacloud.org/cultiver-son-jardin/installation-de-turtl/
|
|
15
|
+#
|
|
16
|
+# License
|
|
17
|
+# =======
|
|
18
|
+#
|
|
19
|
+# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
|
|
20
|
+#
|
|
21
|
+# This program is free software: you can redistribute it and/or modify
|
|
22
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
23
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
24
|
+# (at your option) any later version.
|
|
25
|
+#
|
|
26
|
+# This program is distributed in the hope that it will be useful,
|
|
27
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
28
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
29
|
+# GNU Affero General Public License for more details.
|
|
30
|
+#
|
|
31
|
+# You should have received a copy of the GNU Affero General Public License
|
|
32
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
33
|
+
|
|
34
|
+VARIANTS="full full-vim writer"
|
|
35
|
+
|
|
36
|
+IN_DEFAULT_INSTALL=0
|
|
37
|
+SHOW_ON_ABOUT=1
|
|
38
|
+
|
|
39
|
+TURTL_DOMAIN_NAME=
|
|
40
|
+TURTL_CODE=
|
|
41
|
+TURTL_ONION_PORT=8107
|
|
42
|
+TURTL_PORT=8181
|
|
43
|
+TURTL_REPO="https://github.com/turtl/api.git"
|
|
44
|
+TURTL_COMMIT='53e00a5583f52de8f86ef380fe11c176b5738dcf'
|
|
45
|
+TURTL_ADMIN_PASSWORD=
|
|
46
|
+TURTL_STORAGE_LIMIT_MB=100
|
|
47
|
+
|
|
48
|
+LIBUV_VERSION='1.9.1'
|
|
49
|
+LIBUV_HASH='e83953782c916d7822ef0b94e8115ce5756fab5300cca173f0de5f5b0e0ae928'
|
|
50
|
+
|
|
51
|
+turtl_variables=(ONION_ONLY
|
|
52
|
+ DEFAULT_DOMAIN_NAME
|
|
53
|
+ TURTL_DOMAIN_NAME
|
|
54
|
+ TURTL_CODE
|
|
55
|
+ TURTL_STORAGE_LIMIT_MB
|
|
56
|
+ DDNS_PROVIDER
|
|
57
|
+ MY_EMAIL_ADDRESS
|
|
58
|
+ MY_USERNAME)
|
|
59
|
+
|
|
60
|
+function change_password_turtl {
|
|
61
|
+ change_username="$1"
|
|
62
|
+ new_user_password="$2"
|
|
63
|
+}
|
|
64
|
+
|
|
65
|
+function remove_user_turtl {
|
|
66
|
+ remove_username="$1"
|
|
67
|
+}
|
|
68
|
+
|
|
69
|
+function add_user_turtl {
|
|
70
|
+ new_username="$1"
|
|
71
|
+ new_user_password="$2"
|
|
72
|
+ echo '0'
|
|
73
|
+}
|
|
74
|
+
|
|
75
|
+function install_interactive_turtl {
|
|
76
|
+ if [ ! $ONION_ONLY ]; then
|
|
77
|
+ ONION_ONLY='no'
|
|
78
|
+ fi
|
|
79
|
+
|
|
80
|
+ if [[ $ONION_ONLY != "no" ]]; then
|
|
81
|
+ TURTL_DOMAIN_NAME='notes.local'
|
|
82
|
+ write_config_param "TURTL_DOMAIN_NAME" "$TURTL_DOMAIN_NAME"
|
|
83
|
+ else
|
|
84
|
+ function_check interactive_site_details
|
|
85
|
+ interactive_site_details "turtl" "TURTL_DOMAIN_NAME" "TURTL_CODE"
|
|
86
|
+ fi
|
|
87
|
+ APP_INSTALLED=1
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+function configure_interactive_turtl {
|
|
91
|
+ data=$(tempfile 2>/dev/null)
|
|
92
|
+ trap "rm -f $data" 0 1 2 5 15
|
|
93
|
+ dialog --title $"Change storage limit" \
|
|
94
|
+ --backtitle $"Freedombone Control Panel" \
|
|
95
|
+ --inputbox $"Enter a storage limit in megabytes." 8 75 "$TURTL_STORAGE_LIMIT_MB" 2>$data
|
|
96
|
+ sel=$?
|
|
97
|
+ case $sel in
|
|
98
|
+ 0)
|
|
99
|
+ STORAGE=$(<$data)
|
|
100
|
+ if [ ${#STORAGE} -gt 0 ]; then
|
|
101
|
+ TURTL_STORAGE_LIMIT_MB=$STORAGE
|
|
102
|
+ sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* $TURTL_STORAGE_LIMIT_MB|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
103
|
+ systemctl restart turtl
|
|
104
|
+ dialog --title $"Change storage limit" \
|
|
105
|
+ --msgbox $"Storage limit changed to ${TURTL_STORAGE_LIMIT_MB}M" 6 50
|
|
106
|
+ fi
|
|
107
|
+ ;;
|
|
108
|
+ esac
|
|
109
|
+}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+function reconfigure_turtl {
|
|
113
|
+ if [ -d /var/www/${TURTL_DOMAIN_NAME}/htdocs/data ]; then
|
|
114
|
+ rm -rf /var/www/${TURTL_DOMAIN_NAME}/htdocs/data/*
|
|
115
|
+ fi
|
|
116
|
+}
|
|
117
|
+
|
|
118
|
+function upgrade_turtl {
|
|
119
|
+ read_config_param "TURTL_DOMAIN_NAME"
|
|
120
|
+
|
|
121
|
+ install_libuv
|
|
122
|
+
|
|
123
|
+ function_check set_repo_commit
|
|
124
|
+ set_repo_commit /var/www/$TURTL_DOMAIN_NAME/htdocs "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+function backup_local_turtl {
|
|
128
|
+ read_config_param "TURTL_DOMAIN_NAME"
|
|
129
|
+ source_directory=/var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
130
|
+ if [ -d $source_directory ]; then
|
|
131
|
+ dest_directory=turtl
|
|
132
|
+ function_check suspend_site
|
|
133
|
+ suspend_site ${TURTL_DOMAIN_NAME}
|
|
134
|
+
|
|
135
|
+ function_check backup_directory_to_usb
|
|
136
|
+ backup_directory_to_usb $source_directory $dest_directory
|
|
137
|
+
|
|
138
|
+ function_check restart_site
|
|
139
|
+ restart_site
|
|
140
|
+ fi
|
|
141
|
+}
|
|
142
|
+
|
|
143
|
+function restore_local_turtl {
|
|
144
|
+ read_config_param "TURTL_DOMAIN_NAME"
|
|
145
|
+ if [ $TURTL_DOMAIN_NAME ]; then
|
|
146
|
+ temp_restore_dir=/root/tempturtl
|
|
147
|
+ restore_directory_from_usb $temp_restore_dir turtl
|
|
148
|
+ if [ -d /var/www/${TURTL_DOMAIN_NAME}/htdocs ]; then
|
|
149
|
+ if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
150
|
+ rm -rf /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
151
|
+ fi
|
|
152
|
+ mv /var/www/${TURTL_DOMAIN_NAME}/htdocs /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
153
|
+ fi
|
|
154
|
+ temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
|
|
155
|
+ cp -r ${temp_source_dir} /var/www/${TURTL_DOMAIN_NAME}/
|
|
156
|
+ if [ ! "$?" = "0" ]; then
|
|
157
|
+ if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
158
|
+ mv /var/www/${TURTL_DOMAIN_NAME}/previous /var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
159
|
+ fi
|
|
160
|
+ set_user_permissions
|
|
161
|
+ backup_unmount_drive
|
|
162
|
+ exit 36723
|
|
163
|
+ fi
|
|
164
|
+ rm -rf ${temp_restore_dir}
|
|
165
|
+ chown -R turtl:turtl /var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
166
|
+ fi
|
|
167
|
+}
|
|
168
|
+
|
|
169
|
+function backup_remote_turtl {
|
|
170
|
+ read_config_param "TURTL_DOMAIN_NAME"
|
|
171
|
+ if [ $TURTL_DOMAIN_NAME ]; then
|
|
172
|
+ temp_backup_dir=/var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
173
|
+ if [ -d $temp_backup_dir ]; then
|
|
174
|
+ echo $"Backing up turtl"
|
|
175
|
+ backup_directory_to_friend $temp_backup_dir turtl
|
|
176
|
+ echo $"Backup of turtl complete"
|
|
177
|
+ else
|
|
178
|
+ echo $"turtl domain specified but not found in $temp_backup_dir"
|
|
179
|
+ exit 68725
|
|
180
|
+ fi
|
|
181
|
+ fi
|
|
182
|
+}
|
|
183
|
+
|
|
184
|
+function restore_remote_turtl {
|
|
185
|
+ read_config_param "TURTL_DOMAIN_NAME"
|
|
186
|
+ if [ $TURTL_DOMAIN_NAME ]; then
|
|
187
|
+ temp_restore_dir=/root/tempturtl
|
|
188
|
+ mkdir $temp_restore_dir
|
|
189
|
+ function_check restore_directory_from_friend
|
|
190
|
+ restore_directory_from_friend $temp_restore_dir turtl
|
|
191
|
+ if [ -d /var/www/${TURTL_DOMAIN_NAME}/htdocs ]; then
|
|
192
|
+ if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
193
|
+ rm -rf /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
194
|
+ fi
|
|
195
|
+ mv /var/www/${TURTL_DOMAIN_NAME}/htdocs /var/www/${TURTL_DOMAIN_NAME}/previous
|
|
196
|
+ fi
|
|
197
|
+ temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
|
|
198
|
+ cp -r ${temp_source_dir} /var/www/${TURTL_DOMAIN_NAME}/
|
|
199
|
+ if [ ! "$?" = "0" ]; then
|
|
200
|
+ if [ -d /var/www/${TURTL_DOMAIN_NAME}/previous ]; then
|
|
201
|
+ mv /var/www/${TURTL_DOMAIN_NAME}/previous /var/www/${TURTL_DOMAIN_NAME}/htdocs
|
|
202
|
+ fi
|
|
203
|
+ exit 37823
|
|
204
|
+ fi
|
|
205
|
+ rm -rf ${temp_restore_dir}
|
|
206
|
+ fi
|
|
207
|
+}
|
|
208
|
+
|
|
209
|
+function remove_turtl {
|
|
210
|
+ if [ ${#TURTL_DOMAIN_NAME} -eq 0 ]; then
|
|
211
|
+ return
|
|
212
|
+ fi
|
|
213
|
+ read_config_param "TURTL_DOMAIN_NAME"
|
|
214
|
+ read_config_param "MY_USERNAME"
|
|
215
|
+ echo "Removing $TURTL_DOMAIN_NAME"
|
|
216
|
+ if [ -f /etc/systemd/system/turtl.service ]; then
|
|
217
|
+ systemctl stop turtl
|
|
218
|
+ systemctl disable turtl
|
|
219
|
+ rm /etc/systemd/system/turtl.service
|
|
220
|
+ fi
|
|
221
|
+ nginx_dissite $TURTL_DOMAIN_NAME
|
|
222
|
+ remove_certs $TURTL_DOMAIN_NAME
|
|
223
|
+ if [ -d /var/www/$TURTL_DOMAIN_NAME ]; then
|
|
224
|
+ rm -rf /var/www/$TURTL_DOMAIN_NAME
|
|
225
|
+ fi
|
|
226
|
+ if [ -f /etc/nginx/sites-available/$TURTL_DOMAIN_NAME ]; then
|
|
227
|
+ rm /etc/nginx/sites-available/$TURTL_DOMAIN_NAME
|
|
228
|
+ fi
|
|
229
|
+ function_check remove_onion_service
|
|
230
|
+ remove_onion_service turtl ${TURTL_ONION_PORT}
|
|
231
|
+ remove_app turtl
|
|
232
|
+ remove_completion_param install_turtl
|
|
233
|
+ sed -i '/turtl/d' $COMPLETION_FILE
|
|
234
|
+ deluser --remove-all-files turtl
|
|
235
|
+ remove_nodejs turtl
|
|
236
|
+
|
|
237
|
+ remove_rethinkdb
|
|
238
|
+
|
|
239
|
+ function_check remove_ddns_domain
|
|
240
|
+ remove_ddns_domain $TURTL_DOMAIN_NAME
|
|
241
|
+}
|
|
242
|
+
|
|
243
|
+function install_libuv {
|
|
244
|
+ if [ ! -d $INSTALL_DIR ]; then
|
|
245
|
+ mkdir -p $INSTALL_DIR
|
|
246
|
+ fi
|
|
247
|
+
|
|
248
|
+ cd $INSTALL_DIR
|
|
249
|
+ if [ ! -f libuv-v${LIBUV_VERSION}.tar.gz ]; then
|
|
250
|
+ wget http://dist.libuv.org/dist/v${LIBUV_VERSION}/libuv-v${LIBUV_VERSION}.tar.gz
|
|
251
|
+ fi
|
|
252
|
+ if [ ! -f libuv-v${LIBUV_VERSION}.tar.gz ]; then
|
|
253
|
+ echo $"Couldn't download libuv ${LIBUV_VERSION}"
|
|
254
|
+ exit 728235
|
|
255
|
+ fi
|
|
256
|
+ hashstr=$(sha256sum libuv-v${LIBUV_VERSION}.tar.gz | awk -F ' ' '{print $1}')
|
|
257
|
+ if [[ "$hashstr" != "$LIBUV_HASH" ]]; then
|
|
258
|
+ rm libuv-v${LIBUV_VERSION}.tar.gz
|
|
259
|
+ echo $"libuv hash does not match. Expected $LIBUV_HASH but found $hashstr"
|
|
260
|
+ exit 27685
|
|
261
|
+ fi
|
|
262
|
+ if [ ! -d $INSTALL_DIR/libuv-v${LIBUV_VERSION} ]; then
|
|
263
|
+ tar -xf libuv-v${LIBUV_VERSION}.tar.gz
|
|
264
|
+ fi
|
|
265
|
+ if [ ! -d $INSTALL_DIR/libuv-v${LIBUV_VERSION} ]; then
|
|
266
|
+ rm libuv-v${LIBUV_VERSION}.tar.gz
|
|
267
|
+ echo $'libuv could not be extracted'
|
|
268
|
+ exit 72754
|
|
269
|
+ fi
|
|
270
|
+ cd $INSTALL_DIR/libuv-v${LIBUV_VERSION}
|
|
271
|
+ sh autogen.sh
|
|
272
|
+ ./configure
|
|
273
|
+ make
|
|
274
|
+ make install
|
|
275
|
+}
|
|
276
|
+
|
|
277
|
+function install_turtl {
|
|
278
|
+ if [ ! $TURTL_DOMAIN_NAME ]; then
|
|
279
|
+ echo $'No domain name was given for turtl'
|
|
280
|
+ exit 47823
|
|
281
|
+ fi
|
|
282
|
+
|
|
283
|
+ if [ -f $IMAGE_PASSWORD_FILE ]; then
|
|
284
|
+ TURTL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
|
|
285
|
+ else
|
|
286
|
+ if [ ! $TURTL_ADMIN_PASSWORD ]; then
|
|
287
|
+ TURTL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
|
288
|
+ fi
|
|
289
|
+ fi
|
|
290
|
+
|
|
291
|
+ apt-get -yq install git wget curl libtool subversion gcc make automake
|
|
292
|
+ apt-get -yq install cl-cffi cl-quicklisp libuv1-dev build-essential
|
|
293
|
+
|
|
294
|
+ if [ ! -d $INSTALL_DIR ]; then
|
|
295
|
+ mkdir -p $INSTALL_DIR
|
|
296
|
+ fi
|
|
297
|
+
|
|
298
|
+ if [ ! -d /var/www/$TURTL_DOMAIN_NAME ]; then
|
|
299
|
+ mkdir /var/www/$TURTL_DOMAIN_NAME
|
|
300
|
+ fi
|
|
301
|
+ if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs ]; then
|
|
302
|
+ function_check git_clone
|
|
303
|
+ git_clone $TURTL_REPO /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
304
|
+ if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs ]; then
|
|
305
|
+ echo $'Unable to clone turtl repo'
|
|
306
|
+ exit 367292
|
|
307
|
+ fi
|
|
308
|
+ fi
|
|
309
|
+
|
|
310
|
+ if [ ! -f /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.default.lisp ]; then
|
|
311
|
+ echo $'No default turtl config found'
|
|
312
|
+ exit 825328
|
|
313
|
+ fi
|
|
314
|
+ if [ ! -d /var/www/$TURTL_DOMAIN_NAME/htdocs/data ]; then
|
|
315
|
+ mkdir -p /var/www/$TURTL_DOMAIN_NAME/htdocs/data
|
|
316
|
+ fi
|
|
317
|
+ cp /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.default.lisp /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
318
|
+ sed -i "s|defvar *admin-email* \".*|defvar *admin-email* \"$MY_EMAIL_ADDRESS\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
319
|
+ sed -i "s|defvar *email-from* \".*|defvar *email-from* \"noreply@$DEFAULT_DOMAIN_NAME\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
320
|
+ sed -i "s|defvar *site-url* \".*|defvar *site-url* \"https://$TURTL_DOMAIN_NAME\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
321
|
+ sed -i "s|defvar *analytics* '(:enabled.*|defvar *analytics* '(:enabled f|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
322
|
+ sed -i 's|http://turtl.dev:8181|https://$TURTL_DOMAIN_NAME|g' /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
323
|
+ sed -i "s|defvar *local-upload*.*|defvar *local-upload* \"/var/www/$TURTL_DOMAIN_NAME/htdocs/data\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
324
|
+ sed -i "s|defvar *local-upload-url*.*|defvar *local-upload-url* \"https://$TURTL_DOMAIN_NAME\"|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
325
|
+ sed -i 's|defparameter *storage-invite-credit*.*|defparameter *storage-invite-credit* 0|g' /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
326
|
+ sed -i "s|defparameter *default-storage-limit*.*|defparameter *default-storage-limit* $TURTL_STORAGE_LIMIT_MB|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
327
|
+
|
|
328
|
+ cd /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
329
|
+ git checkout $TURTL_COMMIT -b $TURTL_COMMIT
|
|
330
|
+ set_completion_param "turtl commit" "$TURTL_COMMIT"
|
|
331
|
+
|
|
332
|
+ chmod a+w /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
333
|
+ chown www-data:www-data /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
334
|
+
|
|
335
|
+ install_libuv
|
|
336
|
+ install_rethinkdb
|
|
337
|
+ install_common_lisp
|
|
338
|
+ install_quicklisp
|
|
339
|
+
|
|
340
|
+ function_check install_nodejs
|
|
341
|
+ install_nodejs turtl
|
|
342
|
+
|
|
343
|
+ function_check add_ddns_domain
|
|
344
|
+ add_ddns_domain $TURTL_DOMAIN_NAME
|
|
345
|
+
|
|
346
|
+ adduser --system --home=/var/www/$TURTL_DOMAIN_NAME/htdocs/ --group turtl
|
|
347
|
+ chown -R turtl:turtl /var/www/$TURTL_DOMAIN_NAME/htdocs
|
|
348
|
+
|
|
349
|
+ echo '[Unit]' > /etc/systemd/system/turtl.service
|
|
350
|
+ echo 'Description=Note taking service' >> /etc/systemd/system/turtl.service
|
|
351
|
+ echo 'Documentation=http://turtl.it' >> /etc/systemd/system/turtl.service
|
|
352
|
+ echo 'Requires=network.target' >> /etc/systemd/system/turtl.service
|
|
353
|
+ echo 'Requires=rethinkdb.service' >> /etc/systemd/system/turtl.service
|
|
354
|
+ echo 'After=network.target' >> /etc/systemd/system/turtl.service
|
|
355
|
+ echo 'After=rethinkdb.service' >> /etc/systemd/system/turtl.service
|
|
356
|
+ echo '' >> /etc/systemd/system/turtl.service
|
|
357
|
+ echo '[Service]' >> /etc/systemd/system/turtl.service
|
|
358
|
+ echo 'Type=simple' >> /etc/systemd/system/turtl.service
|
|
359
|
+ echo 'User=turtl' >> /etc/systemd/system/turtl.service
|
|
360
|
+ echo "WorkingDirectory=/var/www/$TURTL_DOMAIN_NAME/htdocs/" >> /etc/systemd/system/turtl.service
|
|
361
|
+ check_architecture=$(uname -a)
|
|
362
|
+ if [[ "$check_architecture" == *"64"* && "$check_architecture" != *"arm"* ]]; then
|
|
363
|
+ echo 'ExecStart=/usr/bin/ccl64 -Q -b --load start.lisp' >> /etc/systemd/system/turtl.service
|
|
364
|
+ else
|
|
365
|
+ echo 'ExecStart=/usr/bin/ccl -Q -b --load start.lisp' >> /etc/systemd/system/turtl.service
|
|
366
|
+ fi
|
|
367
|
+ echo '' >> /etc/systemd/system/turtl.service
|
|
368
|
+ echo '[Install]' >> /etc/systemd/system/turtl.service
|
|
369
|
+ echo 'WantedBy=multi-user.target' >> /etc/systemd/system/turtl.service
|
|
370
|
+ chmod +x /etc/systemd/system/turtl.service
|
|
371
|
+
|
|
372
|
+ turtl_nginx_site=/etc/nginx/sites-available/$TURTL_DOMAIN_NAME
|
|
373
|
+ if [[ $ONION_ONLY == "no" ]]; then
|
|
374
|
+ function_check nginx_http_redirect
|
|
375
|
+ nginx_http_redirect $TURTL_DOMAIN_NAME
|
|
376
|
+ echo 'server {' >> $turtl_nginx_site
|
|
377
|
+ echo ' listen 443 ssl;' >> $turtl_nginx_site
|
|
378
|
+ echo ' listen [::]:443 ssl;' >> $turtl_nginx_site
|
|
379
|
+ echo " server_name $TURTL_DOMAIN_NAME;" >> $turtl_nginx_site
|
|
380
|
+ echo '' >> $turtl_nginx_site
|
|
381
|
+ echo ' # Security' >> $turtl_nginx_site
|
|
382
|
+ function_check nginx_ssl
|
|
383
|
+ nginx_ssl $TURTL_DOMAIN_NAME
|
|
384
|
+
|
|
385
|
+ function_check nginx_disable_sniffing
|
|
386
|
+ nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
|
387
|
+
|
|
388
|
+ echo ' add_header Strict-Transport-Security max-age=15768000;' >> $turtl_nginx_site
|
|
389
|
+ echo '' >> $turtl_nginx_site
|
|
390
|
+ echo ' # Logs' >> $turtl_nginx_site
|
|
391
|
+ echo ' access_log /dev/null;' >> $turtl_nginx_site
|
|
392
|
+ echo ' error_log /dev/null;' >> $turtl_nginx_site
|
|
393
|
+ echo '' >> $turtl_nginx_site
|
|
394
|
+ echo ' # Root' >> $turtl_nginx_site
|
|
395
|
+ echo " root /var/www/$TURTL_DOMAIN_NAME/htdocs;" >> $turtl_nginx_site
|
|
396
|
+ echo '' >> $turtl_nginx_site
|
|
397
|
+ echo ' location / {' >> $turtl_nginx_site
|
|
398
|
+ function_check nginx_limits
|
|
399
|
+ nginx_limits $TURTL_DOMAIN_NAME '15m'
|
|
400
|
+ echo " proxy_pass http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
|
|
401
|
+ echo ' proxy_set_header Host $host;' >> $turtl_nginx_site
|
|
402
|
+ echo ' proxy_buffering off;' >> $turtl_nginx_site
|
|
403
|
+ echo ' }' >> $turtl_nginx_site
|
|
404
|
+ echo '' >> $turtl_nginx_site
|
|
405
|
+ nginx_keybase $TURTL_DOMAIN_NAME
|
|
406
|
+ echo '}' >> $turtl_nginx_site
|
|
407
|
+ else
|
|
408
|
+ echo -n '' > $turtl_nginx_site
|
|
409
|
+ fi
|
|
410
|
+ echo 'server {' >> $turtl_nginx_site
|
|
411
|
+ echo " listen 127.0.0.1:$TURTL_ONION_PORT default_server;" >> $turtl_nginx_site
|
|
412
|
+ echo " server_name $TURTL_DOMAIN_NAME;" >> $turtl_nginx_site
|
|
413
|
+ echo '' >> $turtl_nginx_site
|
|
414
|
+ function_check nginx_disable_sniffing
|
|
415
|
+ nginx_disable_sniffing $TURTL_DOMAIN_NAME
|
|
416
|
+ echo '' >> $turtl_nginx_site
|
|
417
|
+ echo ' # Logs' >> $turtl_nginx_site
|
|
418
|
+ echo ' access_log /dev/null;' >> $turtl_nginx_site
|
|
419
|
+ echo ' error_log /dev/null;' >> $turtl_nginx_site
|
|
420
|
+ echo '' >> $turtl_nginx_site
|
|
421
|
+ echo ' # Root' >> $turtl_nginx_site
|
|
422
|
+ echo " root /var/www/$TURTL_DOMAIN_NAME/htdocs;" >> $turtl_nginx_site
|
|
423
|
+ echo '' >> $turtl_nginx_site
|
|
424
|
+ echo ' location / {' >> $turtl_nginx_site
|
|
425
|
+ function_check nginx_limits
|
|
426
|
+ nginx_limits $TURTL_DOMAIN_NAME '15m'
|
|
427
|
+ echo " proxy_pass http://localhost:${TURTL_PORT}/;" >> $turtl_nginx_site
|
|
428
|
+ echo ' proxy_set_header Host $host;' >> $turtl_nginx_site
|
|
429
|
+ echo ' proxy_buffering off;' >> $turtl_nginx_site
|
|
430
|
+ echo ' }' >> $turtl_nginx_site
|
|
431
|
+ echo '' >> $turtl_nginx_site
|
|
432
|
+ nginx_keybase $TURTL_DOMAIN_NAME
|
|
433
|
+ echo '}' >> $turtl_nginx_site
|
|
434
|
+
|
|
435
|
+ function_check create_site_certificate
|
|
436
|
+ create_site_certificate $TURTL_DOMAIN_NAME 'yes'
|
|
437
|
+
|
|
438
|
+ if [ -f /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt ]; then
|
|
439
|
+ mv /etc/ssl/certs/${TURTL_DOMAIN_NAME}.crt /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem
|
|
440
|
+ fi
|
|
441
|
+ if [ -f /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem ]; then
|
|
442
|
+ chown turtl:turtl /etc/ssl/certs/${TURTL_DOMAIN_NAME}.pem
|
|
443
|
+ fi
|
|
444
|
+ if [ -f /etc/ssl/private/${TURTL_DOMAIN_NAME}.key ]; then
|
|
445
|
+ chown turtl:turtl /etc/ssl/private/${TURTL_DOMAIN_NAME}.key
|
|
446
|
+ fi
|
|
447
|
+
|
|
448
|
+ function_check nginx_ensite
|
|
449
|
+ nginx_ensite $TURTL_DOMAIN_NAME
|
|
450
|
+
|
|
451
|
+ TURTL_ONION_HOSTNAME=$(add_onion_service turtl 80 ${TURTL_ONION_PORT})
|
|
452
|
+
|
|
453
|
+ if [[ $ONION_ONLY != 'no' ]]; then
|
|
454
|
+ sed -i "s|https://$TURTL_DOMAIN_NAME|http://$TURTL_ONION_HOSTNAME|g" /var/www/$TURTL_DOMAIN_NAME/htdocs/config/config.lisp
|
|
455
|
+ fi
|
|
456
|
+
|
|
457
|
+ ${PROJECT_NAME}-pass -u $MY_USERNAME -a turtl -p "$TURTL_ADMIN_PASSWORD"
|
|
458
|
+
|
|
459
|
+ function_check add_ddns_domain
|
|
460
|
+ add_ddns_domain $TURTL_DOMAIN_NAME
|
|
461
|
+
|
|
462
|
+ set_completion_param "turtl domain" "$TURTL_DOMAIN_NAME"
|
|
463
|
+
|
|
464
|
+ systemctl enable turtl
|
|
465
|
+ systemctl daemon-reload
|
|
466
|
+ systemctl start turtl
|
|
467
|
+ systemctl restart nginx
|
|
468
|
+
|
|
469
|
+ APP_INSTALLED=1
|
|
470
|
+}
|