ソースを参照

Add federated wiki #69

Bob Mottram 7 年 前
コミット
0b8642e683
共有2 個のファイルを変更した409 個の追加0 個の削除を含む
  1. 408
    0
      src/freedombone-app-fedwiki
  2. 1
    0
      src/freedombone-image-customise

+ 408
- 0
src/freedombone-app-fedwiki ファイルの表示

@@ -0,0 +1,408 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Federated wiki
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+VARIANTS="full full-vim media"
32
+
33
+IN_DEFAULT_INSTALL=0
34
+SHOW_ON_ABOUT=1
35
+
36
+FEDWIKI_DOMAIN_NAME=
37
+FEDWIKI_CODE=
38
+FEDWIKI_REPO="https://github.com/fedwiki/wiki"
39
+FEDWIKI_COMMIT='8fba3bb5c18b53b0c07fd2f2af10058b0d1bd253'
40
+FEDWIKI_ONION_PORT=8131
41
+FEDWIKI_PORT=3053
42
+FEDWIKI_DIR=/etc/fedwiki
43
+FEDWIKI_DATA=/var/lib/fedwiki
44
+
45
+fedwiki_variables=(FEDWIKI_DOMAIN_NAME
46
+                   FEDWIKI_CODE
47
+                   FEDWIKI_ADMIN_PASSWORD
48
+                   ONION_ONLY
49
+                   DDNS_PROVIDER
50
+                   MY_USERNAME
51
+                   MY_EMAIL_ADDRESS)
52
+
53
+function logging_on_fedwiki {
54
+    echo -n ''
55
+}
56
+
57
+function logging_off_fedwiki {
58
+    echo -n ''
59
+}
60
+
61
+function remove_user_fedwiki {
62
+    remove_username="$1"
63
+}
64
+
65
+function add_user_fedwiki {
66
+    if [[ $(app_is_installed fedwiki) == "0" ]]; then
67
+        echo '0'
68
+        return
69
+    fi
70
+
71
+    new_username="$1"
72
+    new_user_password="$2"
73
+
74
+    echo '0'
75
+}
76
+
77
+function install_interactive_fedwiki {
78
+    if [ ! $ONION_ONLY ]; then
79
+        ONION_ONLY='no'
80
+    fi
81
+
82
+    if [[ $ONION_ONLY != "no" ]]; then
83
+        FEDWIKI_DOMAIN_NAME='fedwiki.local'
84
+        write_config_param "FEDWIKI_DOMAIN_NAME" "$FEDWIKI_DOMAIN_NAME"
85
+    else
86
+        function_check interactive_site_details
87
+        interactive_site_details "fedwiki" "FEDWIKI_DOMAIN_NAME" "FEDWIKI_CODE"
88
+    fi
89
+    APP_INSTALLED=1
90
+}
91
+
92
+function change_password_fedwiki {
93
+    FEDWIKI_USERNAME="$1"
94
+    FEDWIKI_PASSWORD="$2"
95
+    if [ ${#FEDWIKI_PASSWORD} -lt 8 ]; then
96
+        echo $'Fedwiki password is too short'
97
+        return
98
+    fi
99
+    #${PROJECT_NAME}-pass -u $FEDWIKI_USERNAME -a fedwiki -p "$FEDWIKI_PASSWORD"
100
+}
101
+
102
+function reconfigure_fedwiki {
103
+    echo -n ''
104
+}
105
+
106
+function upgrade_fedwiki {
107
+    CURR_FEDWIKI_COMMIT=$(get_completion_param "fedwiki commit")
108
+    if [[ "$CURR_FEDWIKI_COMMIT" == "$FEDWIKI_COMMIT" ]]; then
109
+        return
110
+    fi
111
+
112
+    read_config_param FEDWIKI_DOMAIN_NAME
113
+    systemctl stop fedwiki
114
+    cd $FEDWIKI_DIR
115
+
116
+    function_check set_repo_commit
117
+    set_repo_commit $FEDWIKI_DIR "fedwiki commit" "$FEDWIKI_COMMIT" $FEDWIKI_REPO
118
+
119
+    npm run upgrade-fedwiki
120
+    chown -R fedwiki:fedwiki $FEDWIKI_DIR
121
+    chown -R fedwiki:fedwiki $FEDWIKI_DATA
122
+    systemctl start fedwiki
123
+}
124
+
125
+function backup_local_fedwiki {
126
+    FEDWIKI_DOMAIN_NAME='fedwiki.local'
127
+    if grep -q "fedwiki domain" $COMPLETION_FILE; then
128
+        FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
129
+    fi
130
+
131
+    systemctl stop fedwiki
132
+    suspend_site ${FEDWIKI_DOMAIN_NAME}
133
+
134
+    fedwiki_path=$FEDWIKI_DATA
135
+    if [ -d $fedwiki_path ]; then
136
+        backup_directory_to_usb $fedwiki_path fedwiki
137
+    fi
138
+
139
+    restart_site
140
+    systemctl start fedwiki
141
+}
142
+
143
+function restore_local_fedwiki {
144
+    FEDWIKI_DOMAIN_NAME='fedwiki.local'
145
+    if grep -q "fedwiki domain" $COMPLETION_FILE; then
146
+        FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
147
+    fi
148
+    if [ $FEDWIKI_DOMAIN_NAME ]; then
149
+        suspend_site ${FEDWIKI_DOMAIN_NAME}
150
+        systemctl stop fedwiki
151
+
152
+        temp_restore_dir=/root/tempfedwiki
153
+        function_check restore_directory_from_usb
154
+        restore_directory_from_usb $temp_restore_dir fedwiki
155
+        if [ -d $temp_restore_dir ]; then
156
+            if [ -d $temp_restore_dir$FEDWIKI_DATA ]; then
157
+                cp -r $temp_restore_dir$FEDWIKI_DATA/* $FEDWIKI_DATA/
158
+            else
159
+                cp -r $temp_restore_dir/* $FEDWIKI_DATA/
160
+            fi
161
+            chown -R fedwiki:fedwiki $FEDWIKI_DATA
162
+            rm -rf $temp_restore_dir
163
+        fi
164
+
165
+        systemctl start fedwiki
166
+        restart_site
167
+    fi
168
+}
169
+
170
+function backup_remote_fedwiki {
171
+    FEDWIKI_DOMAIN_NAME='fedwiki.local'
172
+    if grep -q "fedwiki domain" $COMPLETION_FILE; then
173
+        FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
174
+    fi
175
+
176
+    systemctl stop fedwiki
177
+    suspend_site ${FEDWIKI_DOMAIN_NAME}
178
+
179
+    temp_backup_dir=$FEDWIKI_DATA
180
+    if [ -d $temp_backup_dir ]; then
181
+        backup_directory_to_friend $temp_backup_dir fedwiki
182
+    else
183
+        echo $"Fedwiki domain specified but not found in $temp_backup_dir"
184
+        exit 63542852
185
+    fi
186
+
187
+    restart_site
188
+    systemctl start fedwiki
189
+}
190
+
191
+function restore_remote_fedwiki {
192
+    FEDWIKI_DOMAIN_NAME='fedwiki.local'
193
+    if grep -q "fedwiki domain" $COMPLETION_FILE; then
194
+        FEDWIKI_DOMAIN_NAME=$(get_completion_param "fedwiki domain")
195
+    fi
196
+
197
+    systemctl stop fedwiki
198
+    suspend_site ${FEDWIKI_DOMAIN_NAME}
199
+
200
+    temp_restore_dir=/root/tempfedwiki
201
+    function_check restore_directory_from_friend
202
+    restore_directory_from_friend $temp_restore_dir fedwiki
203
+    if [ -d $temp_restore_dir ]; then
204
+        if [ -d $temp_restore_dir$FEDWIKI_DATA ]; then
205
+            cp -r $temp_restore_dir$FEDWIKI_DATA/* $FEDWIKI_DATA/
206
+        else
207
+            cp -r $temp_restore_dir/* $FEDWIKI_DATA/
208
+        fi
209
+        chown -R fedwiki: $FEDWIKI_DATA
210
+        rm -rf $temp_restore_dir
211
+    fi
212
+
213
+    systemctl start fedwiki
214
+    restart_site
215
+}
216
+
217
+function remove_fedwiki {
218
+    if [ ${#FEDWIKI_DOMAIN_NAME} -eq 0 ]; then
219
+        return
220
+    fi
221
+
222
+    systemctl stop fedwiki
223
+    systemctl disable fedwiki
224
+    rm /etc/systemd/system/fedwiki.service
225
+    systemctl daemon-reload
226
+
227
+    function_check remove_nodejs
228
+    remove_nodejs fedwiki
229
+
230
+    read_config_param "FEDWIKI_DOMAIN_NAME"
231
+    nginx_dissite $FEDWIKI_DOMAIN_NAME
232
+    remove_certs ${FEDWIKI_DOMAIN_NAME}
233
+    if [ -f /etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME ]; then
234
+        rm -f /etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME
235
+    fi
236
+    if [ -d /var/www/$FEDWIKI_DOMAIN_NAME ]; then
237
+        rm -rf /var/www/$FEDWIKI_DOMAIN_NAME
238
+    fi
239
+    remove_config_param FEDWIKI_DOMAIN_NAME
240
+    remove_config_param FEDWIKI_CODE
241
+    function_check remove_onion_service
242
+    remove_onion_service fedwiki ${FEDWIKI_ONION_PORT}
243
+    remove_completion_param "install_fedwiki"
244
+    sed -i '/fedwiki/d' $COMPLETION_FILE
245
+
246
+    groupdel -f fedwiki
247
+    userdel -r fedwiki
248
+
249
+    if [ -d $FEDWIKI_DIR ]; then
250
+        rm -rf $FEDWIKI_DIR
251
+    fi
252
+    if [ -d $FEDWIKI_DATA ]; then
253
+        rm -rf $FEDWIKI_DATA
254
+    fi
255
+
256
+    function_check remove_ddns_domain
257
+    remove_ddns_domain $FEDWIKI_DOMAIN_NAME
258
+}
259
+
260
+function fedwiki_setup_web {
261
+    fedwiki_nginx_file=/etc/nginx/sites-available/$FEDWIKI_DOMAIN_NAME
262
+
263
+    if [[ $ONION_ONLY == "no" ]]; then
264
+        echo 'server {' > $fedwiki_nginx_file
265
+        echo '  listen 80;' >> $fedwiki_nginx_file
266
+        echo '  listen [::]:80;' >> $fedwiki_nginx_file
267
+        echo "  server_name $FEDWIKI_DOMAIN_NAME;" >> $fedwiki_nginx_file
268
+        echo '  rewrite ^ https://$server_name$request_uri? permanent;' >> $fedwiki_nginx_file
269
+        echo '}' >> $fedwiki_nginx_file
270
+        echo '' >> $fedwiki_nginx_file
271
+        echo 'server {' >> $fedwiki_nginx_file
272
+        echo '  listen 443 ssl;' >> $fedwiki_nginx_file
273
+        echo '  listen [::]:443 ssl;' >> $fedwiki_nginx_file
274
+        echo "  server_name $FEDWIKI_DOMAIN_NAME;" >> $fedwiki_nginx_file
275
+        echo '' >> $fedwiki_nginx_file
276
+        function_check nginx_ssl
277
+        nginx_ssl $FEDWIKI_DOMAIN_NAME mobile
278
+
279
+        function_check nginx_disable_sniffing
280
+        nginx_disable_sniffing $FEDWIKI_DOMAIN_NAME
281
+
282
+        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $fedwiki_nginx_file
283
+        echo '' >> $fedwiki_nginx_file
284
+        echo '  location / {' >> $fedwiki_nginx_file
285
+        echo "    proxy_pass http://localhost:${FEDWIKI_PORT};" >> $fedwiki_nginx_file
286
+        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $fedwiki_nginx_file
287
+        echo '    proxy_set_header Host $host;' >> $fedwiki_nginx_file
288
+        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $fedwiki_nginx_file
289
+        echo '    client_max_body_size 1M;' >> $fedwiki_nginx_file
290
+        echo '  }' >> $fedwiki_nginx_file
291
+        echo '}' >> $fedwiki_nginx_file
292
+    else
293
+        echo -n '' > $fedwiki_nginx_file
294
+    fi
295
+    echo 'server {' >> $fedwiki_nginx_file
296
+    echo "  listen 127.0.0.1:$FEDWIKI_ONION_PORT default_server;" >> $fedwiki_nginx_file
297
+    echo "  server_name $FEDWIKI_ONION_HOSTNAME;" >> $fedwiki_nginx_file
298
+    echo '' >> $fedwiki_nginx_file
299
+    echo '  location / {' >> $fedwiki_nginx_file
300
+    echo "    proxy_pass http://localhost:${FEDWIKI_PORT};" >> $fedwiki_nginx_file
301
+    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $fedwiki_nginx_file
302
+    echo '    proxy_set_header Host $host;' >> $fedwiki_nginx_file
303
+    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $fedwiki_nginx_file
304
+    echo '    client_max_body_size 1M;' >> $fedwiki_nginx_file
305
+    echo '  }' >> $fedwiki_nginx_file
306
+    echo '}' >> $fedwiki_nginx_file
307
+
308
+    function_check create_site_certificate
309
+    create_site_certificate $FEDWIKI_DOMAIN_NAME 'yes'
310
+
311
+    function_check nginx_ensite
312
+    nginx_ensite $FEDWIKI_DOMAIN_NAME
313
+}
314
+
315
+function install_fedwiki {
316
+    if [[ $VARIANT == "mesh"* ]]; then
317
+        return
318
+    fi
319
+
320
+    if [ ! $ONION_ONLY ]; then
321
+        ONION_ONLY='no'
322
+    fi
323
+
324
+    if [ ! $FEDWIKI_DOMAIN_NAME ]; then
325
+        echo $'The fedwiki domain name was not specified'
326
+        exit 893635
327
+    fi
328
+
329
+    #apt-get -yq install ffmpeg
330
+
331
+    if [ ! -d /var/www/$FEDWIKI_DOMAIN_NAME/htdocs ]; then
332
+        mkdir -p /var/www/$FEDWIKI_DOMAIN_NAME/htdocs
333
+    fi
334
+
335
+    if [ -d $FEDWIKI_DIR ]; then
336
+        rm -rf $FEDWIKI_DIR
337
+    fi
338
+    if [ ! -d $FEDWIKI_DATA ]; then
339
+        mkdir -p $FEDWIKI_DATA
340
+    fi
341
+
342
+    groupadd fedwiki
343
+    useradd -c "Fedwiki system account" -d $FEDWIKI_DIR -m -r -g fedwiki fedwiki
344
+
345
+    function_check install_nodejs
346
+    install_nodejs fedwiki
347
+
348
+    if [ -d /repos/fedwiki ]; then
349
+        mkdir -p $FEDWIKI_DIR
350
+        cp -r -p /repos/fedwiki/. $FEDWIKI_DIR
351
+        cd $FEDWIKI_DIR
352
+        git pull
353
+    else
354
+        function_check git_clone
355
+        git_clone $FEDWIKI_REPO $FEDWIKI_DIR
356
+    fi
357
+
358
+    cd $FEDWIKI_DIR
359
+    git checkout $FEDWIKI_COMMIT -b $FEDWIKI_COMMIT
360
+    set_completion_param "fedwiki commit" "$FEDWIKI_COMMIT"
361
+
362
+    npm install
363
+    if [ ! "$?" = "0" ]; then
364
+        echo $'Failed to install fedwiki'
365
+        exit 8736254
366
+    fi
367
+
368
+    FEDWIKI_ONION_HOSTNAME=$(add_onion_service fedwiki 80 ${FEDWIKI_ONION_PORT})
369
+
370
+    echo '[Unit]' > /etc/systemd/system/fedwiki.service
371
+    echo 'Description=Fedwiki Decentralized video streaming platform' >> /etc/systemd/system/fedwiki.service
372
+    echo 'After=syslog.target' >> /etc/systemd/system/fedwiki.service
373
+    echo 'After=network.target' >> /etc/systemd/system/fedwiki.service
374
+    echo '' >> /etc/systemd/system/fedwiki.service
375
+    echo '[Service]' >> /etc/systemd/system/fedwiki.service
376
+    echo 'User=fedwiki' >> /etc/systemd/system/fedwiki.service
377
+    echo 'Group=fedwiki' >> /etc/systemd/system/fedwiki.service
378
+    echo "WorkingDirectory=$FEDWIKI_DIR" >> /etc/systemd/system/fedwiki.service
379
+    echo "ExecStart=$FEDWIKI_DIR/wiki --data $FEDWIKI_DATA -p $FEDWIKI_PORT" >> /etc/systemd/system/fedwiki.service
380
+    echo 'StandardOutput=syslog' >> /etc/systemd/system/fedwiki.service
381
+    echo 'StandardError=syslog' >> /etc/systemd/system/fedwiki.service
382
+    echo 'SyslogIdentifier=fedwiki' >> /etc/systemd/system/fedwiki.service
383
+    echo 'Restart=always' >> /etc/systemd/system/fedwiki.service
384
+    echo "Environment=NODE_ENV=production" >> /etc/systemd/system/fedwiki.service
385
+    echo '' >> /etc/systemd/system/fedwiki.service
386
+    echo '[Install]' >> /etc/systemd/system/fedwiki.service
387
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/fedwiki.service
388
+
389
+    chown -R fedwiki:fedwiki $FEDWIKI_DIR
390
+    chown -R fedwiki:fedwiki $FEDWIKI_DATA
391
+
392
+    fedwiki_setup_web
393
+
394
+    ${PROJECT_NAME}-pass -u $MY_USERNAME -a fedwiki -p "$FEDWIKI_ADMIN_PASSWORD"
395
+
396
+    function_check add_ddns_domain
397
+    add_ddns_domain $FEDWIKI_DOMAIN_NAME
398
+
399
+    systemctl enable fedwiki
400
+    systemctl daemon-reload
401
+    systemctl start fedwiki
402
+    systemctl restart nginx
403
+
404
+    set_completion_param "fedwiki domain" "$FEDWIKI_DOMAIN_NAME"
405
+    APP_INSTALLED=1
406
+}
407
+
408
+# NOTE: deliberately no exit 0

+ 1
- 0
src/freedombone-image-customise ファイルの表示

@@ -1667,6 +1667,7 @@ function image_preinstall_repos {
1667 1667
     git clone $KANBOARD_REPO $rootdir/repos/kanboard
1668 1668
     git clone $KEYSERVER_WEB_REPO $rootdir/repos/keyserverweb
1669 1669
     git clone $PEERTUBE_REPO $rootdir/repos/peertube
1670
+    git clone $FEDWIKI_REPO $rootdir/repos/fedwiki
1670 1671
     #git clone $WEKAN_REPO $rootdir/repos/wekan
1671 1672
     #git clone $FLOW_ROUTER_REPO $rootdir/repos/flowrouter
1672 1673
     #git clone $METEOR_USERACCOUNTS_REPO $rootdir/repos/meteoruseraccounts