Bob Mottram 8 лет назад
Родитель
Сommit
9ad3422761

+ 6
- 0
src/freedombone-app-etherpad Просмотреть файл

@@ -424,6 +424,9 @@ function remove_etherpad {
424 424
     remove_backup_database_local etherpad
425 425
     deluser --remove-all-files etherpad
426 426
     remove_nodejs etherpad
427
+
428
+    function_check remove_ddns_domain
429
+    remove_ddns_domain $ETHERPAD_DOMAIN_NAME
427 430
 }
428 431
 
429 432
 function install_etherpad {
@@ -612,6 +615,9 @@ function install_etherpad {
612 615
         fi
613 616
     fi
614 617
 
618
+    function_check add_ddns_domain
619
+    add_ddns_domain $ETHERPAD_DOMAIN_NAME
620
+
615 621
     set_completion_param "etherpad domain" "$ETHERPAD_DOMAIN_NAME"
616 622
 
617 623
     systemctl enable etherpad

+ 307
- 0
src/freedombone-app-mailpile Просмотреть файл

@@ -0,0 +1,307 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# mailpile app
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2016 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 writer"
32
+
33
+IN_DEFAULT_INSTALL=0
34
+SHOW_ON_ABOUT=1
35
+
36
+MAILPILE_DOMAIN_NAME=
37
+MAILPILE_CODE=
38
+MAILPILE_ONION_PORT=8103
39
+MAILPILE_REPO="https://github.com/mailpile/Mailpile"
40
+MAILPILE_COMMIT='352ca27a29f7d9525298264c04bc5c7d55887276'
41
+MAILPILE_PORT=33411
42
+
43
+mailpile_variables=(MAILPILE_REPO
44
+                    MAILPILE_COMMIT
45
+                    MAILPILE_DOMAIN_NAME
46
+                    MAILPILE_CODE
47
+                    ONION_ONLY
48
+                    DDNS_PROVIDER
49
+                    MY_USERNAME)
50
+
51
+function remove_user_mailpile {
52
+    remove_username="$1"
53
+}
54
+
55
+function add_user_mailpile {
56
+    echo '0'
57
+}
58
+
59
+function install_interactive_mailpile {
60
+    if [ ! $ONION_ONLY ]; then
61
+        ONION_ONLY='no'
62
+    fi
63
+
64
+    if [[ $ONION_ONLY != "no" ]]; then
65
+        MAILPILE_DOMAIN_NAME='mailpile.local'
66
+        write_config_param "MAILPILE_DOMAIN_NAME" "$MAILPILE_DOMAIN_NAME"
67
+    else
68
+        function_check interactive_site_details
69
+        interactive_site_details "mailpile" "MAILPILE_DOMAIN_NAME" "MAILPILE_CODE"
70
+    fi
71
+    APP_INSTALLED=1
72
+}
73
+
74
+function change_password_mailpile {
75
+    echo -n ''
76
+}
77
+
78
+function reconfigure_mailpile {
79
+    echo -n ''
80
+}
81
+
82
+function upgrade_mailpile {
83
+    read_config_param "MAILPILE_DOMAIN_NAME"
84
+
85
+    function_check set_repo_commit
86
+    set_repo_commit /var/www/$MAILPILE_DOMAIN_NAME/htdocs "mailpile commit" "$MAILPILE_COMMIT" $MAILPILE_REPO
87
+}
88
+
89
+function backup_local_mailpile {
90
+    echo -n ''
91
+}
92
+
93
+function restore_local_mailpile {
94
+    echo -n ''
95
+}
96
+
97
+function backup_remote_mailpile {
98
+    echo -n ''
99
+}
100
+
101
+function restore_remote_mailpile {
102
+    echo -n ''
103
+}
104
+
105
+function remove_mailpile {
106
+    if [ ${#MAILPILE_DOMAIN_NAME} -eq 0 ]; then
107
+        return
108
+    fi
109
+
110
+    systemctl stop mailpile
111
+    systemctl disable mailpile
112
+    rm /etc/systemd/system/mailpile.service
113
+
114
+    read_config_param "MAILPILE_DOMAIN_NAME"
115
+    if [[ "$MAILPILE_DOMAIN_NAME" != "$DEFAULT_DOMAIN_NAME" ]]; then
116
+        nginx_dissite $MAILPILE_DOMAIN_NAME
117
+        remove_certs ${MAILPILE_DOMAIN_NAME}
118
+        if [ -f /etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME ]; then
119
+            rm -f /etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
120
+        fi
121
+        if [ -d /var/www/$MAILPILE_DOMAIN_NAME ]; then
122
+            rm -rf /var/www/$MAILPILE_DOMAIN_NAME
123
+        fi
124
+        function_check remove_ddns_domain
125
+        remove_ddns_domain $MAILPILE_DOMAIN_NAME
126
+    fi
127
+
128
+    remove_config_param MAILPILE_DOMAIN_NAME
129
+    remove_config_param MAILPILE_CODE
130
+    function_check remove_onion_service
131
+    remove_onion_service mailpile ${MAILPILE_ONION_PORT}
132
+    remove_completion_param "install_mailpile"
133
+
134
+    enable_email_encryption_at_rest
135
+
136
+    sed -i '/Mailpile/d' $COMPLETION_FILE
137
+    sed -i '/mailpile/d' $COMPLETION_FILE
138
+    sed -i '/mailpile/d' /home/$MY_USERNAME/README
139
+    sed -i '/Mailpile/d' /home/$MY_USERNAME/README
140
+}
141
+
142
+function install_mailpile {
143
+    if [ ! $ONION_ONLY ]; then
144
+        ONION_ONLY='no'
145
+    fi
146
+
147
+    if [ ! $MAILPILE_DOMAIN_NAME ]; then
148
+        echo $'The mailpile domain name was not specified'
149
+        exit 63824
150
+    fi
151
+
152
+    apt-get -yq install python-pip python-lxml python-dev libjpeg-dev
153
+
154
+    if [ ! -d /var/www/$MAILPILE_DOMAIN_NAME ]; then
155
+        mkdir /var/www/$MAILPILE_DOMAIN_NAME
156
+    fi
157
+
158
+    cd /var/www/$MAILPILE_DOMAIN_NAME
159
+    git_clone $MAILPILE_REPO htdocs
160
+    cd htdocs
161
+    git checkout $MAILPILE_COMMIT -b $MAILPILE_COMMIT
162
+    set_completion_param "mailpile commit" "$MAILPILE_COMMIT"
163
+
164
+    if [ ! -f requirements-dev.txt ]; then
165
+        echo $'No python requirements file found'
166
+        exit 62382
167
+    fi
168
+    pip install -r requirements.txt
169
+
170
+    adduser --system --home=/var/www/$MAILPILE_DOMAIN_NAME/htdocs/ --group mailpile
171
+    chown -R mailpile: /var/www/$MAILPILE_DOMAIN_NAME/htdocs/
172
+
173
+    # create folders and tags
174
+    su -c "cd /var/www/$MAILPILE_DOMAIN_NAME/htdocs && ./mp --setup" - mailpile
175
+
176
+    if [[ $ONION_ONLY == 'no' ]]; then
177
+        if [[ "$MAILPILE_DOMAIN_NAME" == "$DEFAULT_DOMAIN_NAME" ]]; then
178
+            su -c "cd /var/www/$MAILPILE_DOMAIN_NAME/htdocs && ./mp set sys.http_path /mail" - mailpile
179
+        fi
180
+    fi
181
+
182
+    echo '[Unit]' > /etc/systemd/system/mailpile.service
183
+    echo 'Description=Mailpile Email Client' >> /etc/systemd/system/mailpile.service
184
+    echo 'After=syslog.target network.target nginx.target' >> /etc/systemd/system/mailpile.service
185
+    echo '' >> /etc/systemd/system/mailpile.service
186
+    echo '[Service]' >> /etc/systemd/system/mailpile.service
187
+    echo 'User=mailpile' >> /etc/systemd/system/etherpad.service
188
+    echo 'Group=mailpile' >> /etc/systemd/system/etherpad.service
189
+    echo "WorkingDirectory=/var/www/$MAILPILE_DOMAIN_NAME/htdocs" >> /etc/systemd/system/mailpile.service
190
+    echo "ExecStart=./mp --www=0.0.0.0:${MAILPILE_PORT} --wait" >> /etc/systemd/system/mailpile.service
191
+    echo 'Restart=always' >> /etc/systemd/system/mailpile.service
192
+    echo 'RestartSec=10' >> /etc/systemd/system/mailpile.service
193
+    echo '' >> /etc/systemd/system/mailpile.service
194
+    echo '[Install]' >> /etc/systemd/system/mailpile.service
195
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/mailpile.service
196
+    chmod +x /etc/systemd/system/mailpile.service
197
+
198
+    mailpile_nginx_site=/etc/nginx/sites-available/$MAILPILE_DOMAIN_NAME
199
+    if [ ! -f $mailpile_nginx_site ]; then
200
+        if [[ $ONION_ONLY == "no" ]]; then
201
+            function_check nginx_http_redirect
202
+            nginx_http_redirect $MAILPILE_DOMAIN_NAME
203
+            echo 'server {' >> $mailpile_nginx_site
204
+            echo '  listen 443 ssl;' >> $mailpile_nginx_site
205
+            echo "  server_name $MAILPILE_DOMAIN_NAME;" >> $mailpile_nginx_site
206
+            echo '' >> $mailpile_nginx_site
207
+            echo '  # Security' >> $mailpile_nginx_site
208
+            function_check nginx_ssl
209
+            nginx_ssl $MAILPILE_DOMAIN_NAME
210
+
211
+            function_check nginx_disable_sniffing
212
+            nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
213
+
214
+            echo '  add_header Strict-Transport-Security max-age=15768000;' >> $mailpile_nginx_site
215
+            echo '' >> $mailpile_nginx_site
216
+            echo '  # Logs' >> $mailpile_nginx_site
217
+            echo '  access_log off;' >> $mailpile_nginx_site
218
+            echo '  error_log off;' >> $mailpile_nginx_site
219
+            echo '' >> $mailpile_nginx_site
220
+            echo '  # Root' >> $mailpile_nginx_site
221
+            echo "  root /var/www/$MAILPILE_DOMAIN_NAME/htdocs;" >> $mailpile_nginx_site
222
+            echo '' >> $mailpile_nginx_site
223
+            echo '  location / {' >> $mailpile_nginx_site
224
+            function_check nginx_limits
225
+            nginx_limits $MAILPILE_DOMAIN_NAME '15m'
226
+            echo "    proxy_pass        http://localhost:${MAILPILE_PORT}/;" >> $mailpile_nginx_site
227
+            echo '    proxy_set_header  Host $host;' >> $mailpile_nginx_site
228
+            echo '    proxy_buffering   off;' >> $mailpile_nginx_site
229
+            echo '  }' >> $mailpile_nginx_site
230
+            echo '}' >> $mailpile_nginx_site
231
+        else
232
+            echo -n '' > $mailpile_nginx_site
233
+        fi
234
+        echo 'server {' >> $mailpile_nginx_site
235
+        echo "    listen 127.0.0.1:$MAILPILE_ONION_PORT default_server;" >> $mailpile_nginx_site
236
+        echo "    server_name $MAILPILE_DOMAIN_NAME;" >> $mailpile_nginx_site
237
+        echo '' >> $mailpile_nginx_site
238
+        function_check nginx_disable_sniffing
239
+        nginx_disable_sniffing $MAILPILE_DOMAIN_NAME
240
+        echo '' >> $mailpile_nginx_site
241
+        echo '  # Logs' >> $mailpile_nginx_site
242
+        echo '  access_log off;' >> $mailpile_nginx_site
243
+        echo '  error_log off;' >> $mailpile_nginx_site
244
+        echo '' >> $mailpile_nginx_site
245
+        echo '  # Root' >> $mailpile_nginx_site
246
+        echo "  root /var/www/$MAILPILE_DOMAIN_NAME/htdocs;" >> $mailpile_nginx_site
247
+        echo '' >> $mailpile_nginx_site
248
+        echo '  location / {' >> $mailpile_nginx_site
249
+        function_check nginx_limits
250
+        nginx_limits $MAILPILE_DOMAIN_NAME '15m'
251
+        echo "    proxy_pass        http://localhost:${MAILPILE_PORT}/;" >> $mailpile_nginx_site
252
+        echo '    proxy_set_header  Host $host;' >> $mailpile_nginx_site
253
+        echo '    proxy_buffering   off;' >> $mailpile_nginx_site
254
+        echo '  }' >> $mailpile_nginx_site
255
+        echo '}' >> $mailpile_nginx_site
256
+    fi
257
+
258
+    function_check create_site_certificate
259
+    if [[ "$MAILPILE_DOMAIN_NAME" == "$DEFAULT_DOMAIN_NAME" ]]; then
260
+        if [ ! -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem ]; then
261
+            create_site_certificate $MAILPILE_DOMAIN_NAME 'yes'
262
+        fi
263
+    else
264
+        create_site_certificate $MAILPILE_DOMAIN_NAME 'yes'
265
+    fi
266
+
267
+    if [ -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.crt ]; then
268
+        mv /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.crt /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem
269
+    fi
270
+    if [ -f /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem ]; then
271
+        chown mailpile: /etc/ssl/certs/${MAILPILE_DOMAIN_NAME}.pem
272
+    fi
273
+    if [ -f /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key ]; then
274
+        chown mailpile: /etc/ssl/private/${MAILPILE_DOMAIN_NAME}.key
275
+    fi
276
+
277
+    function_check nginx_ensite
278
+    nginx_ensite $MAILPILE_DOMAIN_NAME
279
+
280
+    MAILPILE_ONION_HOSTNAME=$(add_onion_service mailpile 80 ${MAILPILE_ONION_PORT})
281
+
282
+    if ! grep -q "Mailpile onion domain" /home/$MY_USERNAME/README; then
283
+        echo $"Mailpile onion domain: ${MAILPILE_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
284
+        echo '' >> /home/$MY_USERNAME/README
285
+        chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
286
+        chmod 600 /home/$MY_USERNAME/README
287
+    else
288
+        if [ -f /home/$MY_USERNAME/README ]; then
289
+            sed -i "s|Mailpile onion domain.*|Mailpile onion domain: ${MAILPILE_ONION_HOSTNAME}|g" /home/$MY_USERNAME/README
290
+        fi
291
+    fi
292
+
293
+    function_check add_ddns_domain
294
+    add_ddns_domain $MAILPILE_DOMAIN_NAME
295
+
296
+    disable_email_encryption_at_rest
297
+
298
+    systemctl enable mailpile
299
+    systemctl daemon-reload
300
+    systemctl start mailpile
301
+    systemctl restart nginx
302
+
303
+    set_completion_param "mailpile domain" "$MAILPILE_DOMAIN_NAME"
304
+    APP_INSTALLED=1
305
+}
306
+
307
+# NOTE: deliberately no exit 0

+ 21
- 0
src/freedombone-utils-dns Просмотреть файл

@@ -160,6 +160,27 @@ function add_ddns_domain {
160 160
     systemctl daemon-reload
161 161
 }
162 162
 
163
+function remove_ddns_domain {
164
+    if [ ! $1 ]; then
165
+        echo $'ddns domain not specified'
166
+        exit 5638
167
+    fi
168
+    CURRENT_DDNS_DOMAIN="$1"
169
+    if [[ $ONION_ONLY != "no" ]]; then
170
+        return
171
+    fi
172
+    if [ ! -f /etc/inadyn.conf ]; then
173
+        echo $'Unable to find inadyn configuration file /etc/inadyn.conf'
174
+        exit 5745
175
+    fi
176
+    if grep -q "$CURRENT_DDNS_DOMAIN" /etc/inadyn.conf; then
177
+        systemctl stop inadyn
178
+        sed -i "/alias $CURRENT_DDNS_DOMAIN/d" /etc/inadyn.conf
179
+        systemctl start inadyn
180
+        systemctl daemon-reload
181
+    fi
182
+}
183
+
163 184
 function configure_dns {
164 185
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
165 186
         return

+ 1
- 1
src/freedombone-utils-git Просмотреть файл

@@ -46,7 +46,7 @@ function git_clone {
46 46
         fi
47 47
     fi
48 48
     echo "git clone $repo_url $destination_dir"
49
-    git clone "$repo_url" "$destination_dir"
49
+    git clone --recursive "$repo_url" "$destination_dir"
50 50
 }
51 51
 
52 52
 function git_pull {

+ 61
- 0
src/freedombone-utils-gpg Просмотреть файл

@@ -0,0 +1,61 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# gpg functions
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2016 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
+function enable_email_encryption_at_rest {
32
+    for d in /home/*/ ; do
33
+        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
34
+        if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "0" ]]; then
35
+            if grep '#/usr/bin/gpgit.pl' /home/$USERNAME/.procmailrc; then
36
+                sed -i 's|#/usr/bin/gpgit.pl|/usr/bin/gpgit.pl|g' /home/$USERNAME/.procmailrc
37
+            fi
38
+        fi
39
+    done
40
+
41
+    if grep '#/usr/bin/gpgit.pl' /etc/skel/.procmailrc; then
42
+        sed -i 's|#/usr/bin/gpgit.pl|/usr/bin/gpgit.pl|g' /etc/skel/.procmailrc
43
+    fi
44
+}
45
+
46
+function disable_email_encryption_at_rest {
47
+    for d in /home/*/ ; do
48
+        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
49
+        if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "0" ]]; then
50
+            if ! grep '#/usr/bin/gpgit.pl' /home/$USERNAME/.procmailrc; then
51
+                sed -i 's|/usr/bin/gpgit.pl|#/usr/bin/gpgit.pl|g' /home/$USERNAME/.procmailrc
52
+            fi
53
+        fi
54
+    done
55
+
56
+    if ! grep '#/usr/bin/gpgit.pl' /etc/skel/.procmailrc; then
57
+        sed -i 's|/usr/bin/gpgit.pl|#/usr/bin/gpgit.pl|g' /etc/skel/.procmailrc
58
+    fi
59
+}
60
+
61
+# NOTE: deliberately no exit 0