|
@@ -0,0 +1,447 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# .---. . .
|
|
4
|
+# | | |
|
|
5
|
+# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
+# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
+# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
+#
|
|
9
|
+# Freedom in the Cloud
|
|
10
|
+#
|
|
11
|
+# Brain Dead Simple Mail Server for i2p
|
|
12
|
+#
|
|
13
|
+# License
|
|
14
|
+# =======
|
|
15
|
+#
|
|
16
|
+# Copyright (C) 2018 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'
|
|
32
|
+
|
|
33
|
+IN_DEFAULT_INSTALL=0
|
|
34
|
+SHOW_ON_ABOUT=1
|
|
35
|
+
|
|
36
|
+BDSMAIL_REPO="https://github.com/majestrate/bdsmail"
|
|
37
|
+BDSMAIL_COMMIT='8fb00a725edea59b31b8d23eb32e0c21972bb723'
|
|
38
|
+BDSMAIL_DIR=/etc/bdsmail
|
|
39
|
+I2P_SAM_PORT=7656
|
|
40
|
+I2P_SMTP_PORT=2525
|
|
41
|
+
|
|
42
|
+bdsmail=(MY_USERNAME)
|
|
43
|
+
|
|
44
|
+function bdsmail_configure_users {
|
|
45
|
+ for d in /home/*/ ; do
|
|
46
|
+ USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
|
47
|
+ if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
|
48
|
+
|
|
49
|
+ # Add the user to the i2p group
|
|
50
|
+ usermod -a -G i2psvc $USERNAME
|
|
51
|
+
|
|
52
|
+ if [ -f /home/$USERNAME/.muttrc ]; then
|
|
53
|
+ # Create a mutt i2p folder
|
|
54
|
+ if ! grep -q ' =i2p' /home/$USERNAME/.muttrc; then
|
|
55
|
+ MUTT_MAILBOXES=$(grep "mailboxes =" /home/$USERNAME/.muttrc)
|
|
56
|
+ sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =i2p|g" /home/$USERNAME/.muttrc
|
|
57
|
+ fi
|
|
58
|
+
|
|
59
|
+ # Create a mutt folder hook to the i2p config
|
|
60
|
+ if ! grep -q 'folder-hook !i2p' /home/$USERNAME/.muttrc; then
|
|
61
|
+ echo 'folder-hook !i2p/* source ~/.muttrc' >> /home/$USERNAME/.muttrc
|
|
62
|
+ fi
|
|
63
|
+ if ! grep -q 'folder-hook i2p' /home/$USERNAME/.muttrc; then
|
|
64
|
+ echo 'folder-hook i2p/* source ~/.mutt/bdsmail' >> /home/$USERNAME/.muttrc
|
|
65
|
+ fi
|
|
66
|
+ fi
|
|
67
|
+
|
|
68
|
+ # Create a directory where i2p mail will be stored
|
|
69
|
+ if [ ! -d /home/$USERNAME/Maildir/i2p/new ]; then
|
|
70
|
+ mkdir -p /home/$USERNAME/Maildir/i2p/cur
|
|
71
|
+ mkdir -p /home/$USERNAME/Maildir/i2p/new
|
|
72
|
+ chown -R $USERNAME:$USERNAME /home/$USERNAME/Maildir/i2p
|
|
73
|
+ fi
|
|
74
|
+ fi
|
|
75
|
+ done
|
|
76
|
+}
|
|
77
|
+
|
|
78
|
+function logging_on_bdsmail {
|
|
79
|
+ echo -n ''
|
|
80
|
+}
|
|
81
|
+
|
|
82
|
+function logging_off_bdsmail {
|
|
83
|
+ echo -n ''
|
|
84
|
+}
|
|
85
|
+
|
|
86
|
+function remove_user_bdsmail {
|
|
87
|
+ remove_username="$1"
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+function add_user_bdsmail {
|
|
91
|
+ new_username="$1"
|
|
92
|
+ new_user_password="$2"
|
|
93
|
+
|
|
94
|
+ if [ ! -d /home/$new_username/.mutt ]; then
|
|
95
|
+ mkdir /home/$new_username/.mutt
|
|
96
|
+ cp /etc/skel/.mutt/bdsmail /home/$new_username/.mutt
|
|
97
|
+ fi
|
|
98
|
+ sed -i "s|username|$new_username|g" /home/$new_username/.mutt/bdsmail
|
|
99
|
+ bdsmail_configure_users
|
|
100
|
+ $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini $new_username /home/$new_username/Maildir/i2p
|
|
101
|
+ chown -R $new_username:$new_username /home/$new_username/.mutt
|
|
102
|
+ echo '0'
|
|
103
|
+}
|
|
104
|
+
|
|
105
|
+function install_interactive_bdsmail {
|
|
106
|
+ echo -n ''
|
|
107
|
+ APP_INSTALLED=1
|
|
108
|
+}
|
|
109
|
+
|
|
110
|
+function change_password_bdsmail {
|
|
111
|
+ curr_username="$1"
|
|
112
|
+ new_user_password="$2"
|
|
113
|
+}
|
|
114
|
+
|
|
115
|
+function bdsmail_update_domain {
|
|
116
|
+ sed -i "s|set from=.*|set from=username@$(bdsmail_domain)|g" /etc/skel/.mutt/bdsmail
|
|
117
|
+ for d in /home/*/ ; do
|
|
118
|
+ USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
|
119
|
+ if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
|
120
|
+ cp /etc/skel/.mutt/bdsmail /home/${USERNAME}/.mutt/bdsmail
|
|
121
|
+ sed -i "s|set from=.*|set from=${USERNAME}@$(bdsmail_domain)|g" /home/${USERNAME}/.mutt/bdsmail
|
|
122
|
+ chown ${USERNAME}:${USERNAME} /home/${USERNAME}/.mutt/bdsmail
|
|
123
|
+ fi
|
|
124
|
+ done
|
|
125
|
+}
|
|
126
|
+
|
|
127
|
+function bdsmail_wait_for_key_generation {
|
|
128
|
+ # wait for domain to be generated by the daemon
|
|
129
|
+ # This can take a while, probably because i2p is connecting
|
|
130
|
+ bds_domain=
|
|
131
|
+ sleep_ctr=0
|
|
132
|
+ while [ ! $bds_domain ]; do
|
|
133
|
+ echo $"Waiting for i2p domain to be generated ${sleep_ctr}/100"
|
|
134
|
+ systemctl restart bdsmail
|
|
135
|
+ sleep 30
|
|
136
|
+ bds_domain=$(bdsmail_domain)
|
|
137
|
+ sleep_ctr=$((sleep_ctr + 1))
|
|
138
|
+ if [ $sleep_ctr -gt 100 ]; then
|
|
139
|
+ break
|
|
140
|
+ fi
|
|
141
|
+ done
|
|
142
|
+}
|
|
143
|
+
|
|
144
|
+function reconfigure_bdsmail {
|
|
145
|
+ systemctl stop bdsmail
|
|
146
|
+ rm $BDSMAIL_DIR/*.dat
|
|
147
|
+ rm $BDSMAIL_DIR/*.pem
|
|
148
|
+ bdsmail_wait_for_key_generation
|
|
149
|
+ if [ ! -f $BDSMAIL_DIR/bdsmail-privkey.dat ]; then
|
|
150
|
+ return
|
|
151
|
+ fi
|
|
152
|
+ bdsmail_update_domain
|
|
153
|
+}
|
|
154
|
+
|
|
155
|
+function upgrade_bdsmail {
|
|
156
|
+ CURR_BDSMAIL_COMMIT=$(get_completion_param "bdsmail commit")
|
|
157
|
+ if [[ "$CURR_BDSMAIL_COMMIT" == "$BDSMAIL_COMMIT" ]]; then
|
|
158
|
+ return
|
|
159
|
+ fi
|
|
160
|
+
|
|
161
|
+ # update to the next commit
|
|
162
|
+ set_repo_commit $BDSMAIL_DIR "bdsmail commit" "$BDSMAIL_COMMIT" $BDSMAIL_REPO
|
|
163
|
+ cd $BDSMAIL_DIR
|
|
164
|
+ make GOROOT=/home/go/go${GO_VERSION}
|
|
165
|
+ chown -R i2psvc:i2psvc $BDSMAIL_DIR
|
|
166
|
+ systemctl restart bdsmail
|
|
167
|
+
|
|
168
|
+ if ! grep -q "$(bdsmail_domain)" /etc/skel/.mutt/bdsmail; then
|
|
169
|
+ bdsmail_update_domain
|
|
170
|
+ fi
|
|
171
|
+}
|
|
172
|
+
|
|
173
|
+function backup_local_bdsmail {
|
|
174
|
+ systemctl stop bdsmail
|
|
175
|
+
|
|
176
|
+ source_directory=$BDSMAIL_DIR
|
|
177
|
+
|
|
178
|
+ function_check backup_directory_to_usb
|
|
179
|
+ dest_directory=bdsmail
|
|
180
|
+ backup_directory_to_usb $source_directory $dest_directory
|
|
181
|
+
|
|
182
|
+ systemctl start bdsmail
|
|
183
|
+}
|
|
184
|
+
|
|
185
|
+function restore_local_bdsmail {
|
|
186
|
+ systemctl stop bdsmail
|
|
187
|
+
|
|
188
|
+ temp_restore_dir=/root/tempbdsmail
|
|
189
|
+ bdsmail_dir=$BDSMAIL_DIR
|
|
190
|
+
|
|
191
|
+ function_check restore_directory_from_usb
|
|
192
|
+ restore_directory_from_usb $temp_restore_dir bdsmail
|
|
193
|
+ if [ -d $temp_restore_dir ]; then
|
|
194
|
+ if [ -d cp $temp_restore_dir$bdsmail_dir ]; then
|
|
195
|
+ cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
|
|
196
|
+ else
|
|
197
|
+ if [ ! -d $bdsmail_dir ]; then
|
|
198
|
+ mkdir $bdsmail_dir
|
|
199
|
+ fi
|
|
200
|
+ cp -rp $temp_restore_dir/* $bdsmail_dir
|
|
201
|
+ fi
|
|
202
|
+ chown -R i2psvc:i2psvc $bdsmail_dir
|
|
203
|
+ rm -rf $temp_restore_dir
|
|
204
|
+ fi
|
|
205
|
+
|
|
206
|
+ systemctl start bdsmail
|
|
207
|
+}
|
|
208
|
+
|
|
209
|
+function backup_remote_bdsmail {
|
|
210
|
+ systemctl stop bdsmail
|
|
211
|
+
|
|
212
|
+ source_directory=$BDSMAIL_DIR
|
|
213
|
+
|
|
214
|
+ function_check backup_directory_to_friend
|
|
215
|
+ dest_directory=bdsmail
|
|
216
|
+ backup_directory_to_friend $source_directory $dest_directory
|
|
217
|
+
|
|
218
|
+ systemctl start bdsmail
|
|
219
|
+}
|
|
220
|
+
|
|
221
|
+function restore_remote_bdsmail {
|
|
222
|
+ systemctl stop bdsmail
|
|
223
|
+
|
|
224
|
+ temp_restore_dir=/root/tempbdsmail
|
|
225
|
+ bdsmail_dir=$BDSMAIL_DIR
|
|
226
|
+
|
|
227
|
+ function_check restore_directory_from_friend
|
|
228
|
+ restore_directory_from_friend $temp_restore_dir bdsmail
|
|
229
|
+ if [ -d $temp_restore_dir ]; then
|
|
230
|
+ if [ -d cp $temp_restore_dir$bdsmail_dir ]; then
|
|
231
|
+ cp -rp $temp_restore_dir$bdsmail_dir $bdsmail_dir/
|
|
232
|
+ else
|
|
233
|
+ if [ ! -d $bdsmail_dir ]; then
|
|
234
|
+ mkdir $bdsmail_dir
|
|
235
|
+ fi
|
|
236
|
+ cp -rp $temp_restore_dir/* $bdsmail_dir
|
|
237
|
+ fi
|
|
238
|
+ chown -R i2psvc:i2psvc $bdsmail_dir
|
|
239
|
+ rm -rf $temp_restore_dir
|
|
240
|
+ fi
|
|
241
|
+
|
|
242
|
+ systemctl start bdsmail
|
|
243
|
+}
|
|
244
|
+
|
|
245
|
+function remove_bdsmail {
|
|
246
|
+ if [ -f /etc/systemd/system/bdsmail.service ]; then
|
|
247
|
+ systemctl stop bdsmail
|
|
248
|
+ systemctl disable bdsmail
|
|
249
|
+ rm /etc/systemd/system/bdsmail.service
|
|
250
|
+ fi
|
|
251
|
+
|
|
252
|
+ for d in /home/*/ ; do
|
|
253
|
+ USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
|
254
|
+ if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
|
|
255
|
+ # remove the user from the i2p group
|
|
256
|
+ deluser $USERNAME i2psvc
|
|
257
|
+
|
|
258
|
+ # Remove mutt folder hook to the i2p config
|
|
259
|
+ if [ -f /home/$USERNAME/.muttrc ]; then
|
|
260
|
+ if grep -q 'folder-hook !i2p' /home/$USERNAME/.muttrc; then
|
|
261
|
+ sed -i '/folder-hook !i2p/d' /home/$USERNAME/.muttrc
|
|
262
|
+ fi
|
|
263
|
+ if grep -q 'folder-hook i2p' /home/$USERNAME/.muttrc; then
|
|
264
|
+ sed -i '/folder-hook i2p/d' /home/$USERNAME/.muttrc
|
|
265
|
+ fi
|
|
266
|
+ fi
|
|
267
|
+
|
|
268
|
+ # Remove folder
|
|
269
|
+ if grep -q ' =i2p' /home/$USERNAME/.muttrc; then
|
|
270
|
+ sed -i 's| =i2p||g' /home/$USERNAME/.muttrc
|
|
271
|
+ fi
|
|
272
|
+
|
|
273
|
+ # NOTE: leave Maildir/i2p/cur. We might want to archive that
|
|
274
|
+ # or just be reinstalling the system without losing mail
|
|
275
|
+ rm -rf /home/$USERNAME/Maildir/i2p/new
|
|
276
|
+ fi
|
|
277
|
+ done
|
|
278
|
+
|
|
279
|
+ remove_i2p
|
|
280
|
+ remove_app bdsmail
|
|
281
|
+ remove_completion_param install_bdsmail
|
|
282
|
+ sed -i '/bdsmail/d' $COMPLETION_FILE
|
|
283
|
+ rm -rf /etc/skel/.mutt
|
|
284
|
+ if [ -d $BDSMAIL_DIR ]; then
|
|
285
|
+ rm -rf $BDSMAIL_DIR
|
|
286
|
+ fi
|
|
287
|
+ rm /usr/bin/bdsmail_domain
|
|
288
|
+ sed -i '/bdsmail_distribute/d' /etc/crontab
|
|
289
|
+ rm /usr/bin/bdsmail_distribute
|
|
290
|
+ if [ -f /etc/skel/.mutt/bdsmail ]; then
|
|
291
|
+ rm /etc/skel/.mutt/bdsmail
|
|
292
|
+ fi
|
|
293
|
+}
|
|
294
|
+
|
|
295
|
+function install_bdsmail {
|
|
296
|
+ if [ -d $BDSMAIL_DIR ]; then
|
|
297
|
+ remove_bdsmail
|
|
298
|
+ fi
|
|
299
|
+
|
|
300
|
+ if [ -d /repos/bdsmail ]; then
|
|
301
|
+ mkdir $BDSMAIL_DIR
|
|
302
|
+ cp -r -p /repos/bdsmail/. $BDSMAIL_DIR
|
|
303
|
+ cd $BDSMAIL_DIR
|
|
304
|
+ git pull
|
|
305
|
+ else
|
|
306
|
+ git_clone $BDSMAIL_REPO $BDSMAIL_DIR
|
|
307
|
+ fi
|
|
308
|
+
|
|
309
|
+ if [ ! -d $BDSMAIL_DIR ]; then
|
|
310
|
+ echo $'Unable to clone bdsmail repo'
|
|
311
|
+ exit 5735735
|
|
312
|
+ fi
|
|
313
|
+
|
|
314
|
+ cd $BDSMAIL_DIR
|
|
315
|
+ git checkout $BDSMAIL_COMMIT -b $BDSMAIL_COMMIT
|
|
316
|
+ set_completion_param "bdsmail commit" "$BDSMAIL_COMMIT"
|
|
317
|
+
|
|
318
|
+ mkdir -p $BDSMAIL_DIR/Maildir/i2p
|
|
319
|
+ chmod -R 700 $BDSMAIL_DIR/Maildir
|
|
320
|
+
|
|
321
|
+ make GOROOT=/home/go/go${GO_VERSION}
|
|
322
|
+ if [ ! -f $BDSMAIL_DIR/bin/bdsconfig ]; then
|
|
323
|
+ echo $'Unable to make bdsmail'
|
|
324
|
+ exit 87923567842
|
|
325
|
+ fi
|
|
326
|
+
|
|
327
|
+ install_i2p
|
|
328
|
+ i2p_enable_sam
|
|
329
|
+
|
|
330
|
+ # create configuration file
|
|
331
|
+ $BDSMAIL_DIR/bin/bdsconfig > $BDSMAIL_DIR/config.ini
|
|
332
|
+ echo '[maild]' > $BDSMAIL_DIR/config.ini
|
|
333
|
+ echo "i2paddr = 127.0.0.1:$I2P_SAM_PORT" >> $BDSMAIL_DIR/config.ini
|
|
334
|
+ echo 'i2pkeyfile = bdsmail-privkey.dat' >> $BDSMAIL_DIR/config.ini
|
|
335
|
+ echo "bindmail = 127.0.0.1:$I2P_SMTP_PORT" >> $BDSMAIL_DIR/config.ini
|
|
336
|
+ echo 'bindweb = 127.0.0.1:8489' >> $BDSMAIL_DIR/config.ini
|
|
337
|
+ echo 'bindpop3 = 127.0.0.1:1110' >> $BDSMAIL_DIR/config.ini
|
|
338
|
+ echo 'domain = localhost' >> $BDSMAIL_DIR/config.ini
|
|
339
|
+ echo 'maildir = Maildir/i2p' >> $BDSMAIL_DIR/config.ini
|
|
340
|
+ echo 'database = localhost.sqlite' >> $BDSMAIL_DIR/config.ini
|
|
341
|
+ echo 'assets = contrib/assets/web' >> $BDSMAIL_DIR/config.ini
|
|
342
|
+
|
|
343
|
+ echo '[Unit]' > /etc/systemd/system/bdsmail.service
|
|
344
|
+ echo 'Description=bdsmail' >> /etc/systemd/system/bdsmail.service
|
|
345
|
+ echo 'After=syslog.target' >> /etc/systemd/system/bdsmail.service
|
|
346
|
+ echo 'After=network.target' >> /etc/systemd/system/bdsmail.service
|
|
347
|
+ echo '' >> /etc/systemd/system/bdsmail.service
|
|
348
|
+ echo '[Service]' >> /etc/systemd/system/bdsmail.service
|
|
349
|
+ echo 'Type=simple' >> /etc/systemd/system/bdsmail.service
|
|
350
|
+ echo 'User=i2psvc' >> /etc/systemd/system/bdsmail.service
|
|
351
|
+ echo 'Group=i2psvc' >> /etc/systemd/system/bdsmail.service
|
|
352
|
+ echo "WorkingDirectory=$BDSMAIL_DIR" >> /etc/systemd/system/bdsmail.service
|
|
353
|
+ echo "ExecStart=$BDSMAIL_DIR/bin/maild $BDSMAIL_DIR/config.ini" >> /etc/systemd/system/bdsmail.service
|
|
354
|
+ echo 'Restart=always' >> /etc/systemd/system/bdsmail.service
|
|
355
|
+ echo 'Environment="USER=i2psvc"' >> /etc/systemd/system/bdsmail.service
|
|
356
|
+ echo '' >> /etc/systemd/system/bdsmail.service
|
|
357
|
+ echo '[Install]' >> /etc/systemd/system/bdsmail.service
|
|
358
|
+ echo 'WantedBy=multi-user.target' >> /etc/systemd/system/bdsmail.service
|
|
359
|
+
|
|
360
|
+ echo '#!/usr/bin/env python2' > $BDSMAIL_DIR/get_address
|
|
361
|
+ echo 'import base64, hashlib, sys' >> $BDSMAIL_DIR/get_address
|
|
362
|
+ echo 'with open(sys.argv[1]) as f:' >> $BDSMAIL_DIR/get_address
|
|
363
|
+ echo " print(base64.b32encode(hashlib.sha256(base64.b64decode(f.read(516), '-~')).digest()).strip('=')+\".b32.i2p\")" >> $BDSMAIL_DIR/get_address
|
|
364
|
+ chmod +x $BDSMAIL_DIR/get_address
|
|
365
|
+
|
|
366
|
+ chown -R i2psvc:i2psvc $BDSMAIL_DIR
|
|
367
|
+ systemctl enable bdsmail
|
|
368
|
+ systemctl start bdsmail
|
|
369
|
+
|
|
370
|
+ echo '#!/bin/bash' > /usr/bin/bdsmail_distribute
|
|
371
|
+ echo "BDSMAIL_DIR=$BDSMAIL_DIR" >> /usr/bin/bdsmail_distribute
|
|
372
|
+ echo "MAIL_DIR=\$BDSMAIL_DIR/\$(cat \$BDSMAIL_DIR/config.ini | grep 'maildir =' | awk -F ' ' '{print \$3}')" >> /usr/bin/bdsmail_distribute
|
|
373
|
+ echo 'if [ ! -d $MAIL_DIR/postmaster/new ]; then' >> /usr/bin/bdsmail_distribute
|
|
374
|
+ echo ' exit 0' >> /usr/bin/bdsmail_distribute
|
|
375
|
+ echo 'fi' >> /usr/bin/bdsmail_distribute
|
|
376
|
+ echo 'for filename in $MAIL_DIR/postmaster/new/*; do' >> /usr/bin/bdsmail_distribute
|
|
377
|
+ echo ' to_line=$(cat $filename | grep "To: " | head -n 1)' >> /usr/bin/bdsmail_distribute
|
|
378
|
+ echo " to_username=\$(echo \"\$to_line\" | awk -F ' ' '{print \$2}' | awk -F '@' '{print \$1}')" >> /usr/bin/bdsmail_distribute
|
|
379
|
+ echo ' if [ -d /home/$to_username/Maildir/i2p/new ]; then' >> /usr/bin/bdsmail_distribute
|
|
380
|
+ echo ' chown $to_username:$to_username $filename' >> /usr/bin/bdsmail_distribute
|
|
381
|
+ echo ' chmod 600 $filename' >> /usr/bin/bdsmail_distribute
|
|
382
|
+ echo ' mv $filename /home/$to_username/Maildir/i2p/new' >> /usr/bin/bdsmail_distribute
|
|
383
|
+ echo ' fi' >> /usr/bin/bdsmail_distribute
|
|
384
|
+ echo 'done' >> /usr/bin/bdsmail_distribute
|
|
385
|
+ chmod +x /usr/bin/bdsmail_distribute
|
|
386
|
+
|
|
387
|
+ if ! grep -q 'bdsmail_distribute' /etc/crontab; then
|
|
388
|
+ echo '*/1 * * * * root /usr/bin/bdsmail_distribute 2> /dev/null' >> /etc/crontab
|
|
389
|
+ fi
|
|
390
|
+
|
|
391
|
+ echo '#!/bin/bash' > /usr/bin/bdsmail_domain
|
|
392
|
+ echo "cd $BDSMAIL_DIR" >> /usr/bin/bdsmail_domain
|
|
393
|
+ echo 'if [ ! -f bdsmail-privkey.dat ]; then' >> /usr/bin/bdsmail_domain
|
|
394
|
+ echo ' exit 1' >> /usr/bin/bdsmail_domain
|
|
395
|
+ echo 'fi' >> /usr/bin/bdsmail_domain
|
|
396
|
+ echo "python2 get_address bdsmail-privkey.dat | tr '[:upper:]' '[:lower:]'" >> /usr/bin/bdsmail_domain
|
|
397
|
+ chmod +x /usr/bin/bdsmail_domain
|
|
398
|
+
|
|
399
|
+ echo ''
|
|
400
|
+ echo $'Now we will wait for i2p to connect and a private key to be generated'
|
|
401
|
+ echo $'This may take a while.'
|
|
402
|
+ echo ''
|
|
403
|
+
|
|
404
|
+ bdsmail_wait_for_key_generation
|
|
405
|
+
|
|
406
|
+ if [ ! $bds_domain ]; then
|
|
407
|
+ systemctl stop bdsmail
|
|
408
|
+ systemctl disable bdsmail
|
|
409
|
+ remove_i2p
|
|
410
|
+ echo $'Failed to get the bdsmail domain'
|
|
411
|
+ exit 8934638
|
|
412
|
+ fi
|
|
413
|
+
|
|
414
|
+ bdsmail_admin_password="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
|
|
415
|
+ ${PROJECT_NAME}-pass -u $MY_USERNAME -a bdsmail -p "$bdsmail_admin_password"
|
|
416
|
+ $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini admin $BDSMAIL_DIR/Maildir/i2p/admin "$bdsmail_admin_password"
|
|
417
|
+
|
|
418
|
+ # Create mutt configuration
|
|
419
|
+ if [ ! -d /etc/skel/.mutt ]; then
|
|
420
|
+ mkdir /etc/skel/.mutt
|
|
421
|
+ fi
|
|
422
|
+ echo 'set mbox_type=Maildir' > /etc/skel/.mutt/bdsmail
|
|
423
|
+ echo "set smtp_url=smtp://admin:${bdsmail_admin_password}@127.0.0.1:$I2P_SMTP_PORT/" >> /etc/skel/.mutt/bdsmail
|
|
424
|
+ echo 'set use_from=yes' >> /etc/skel/.mutt/bdsmail
|
|
425
|
+ echo "set from=username@${bds_domain}" >> /etc/skel/.mutt/bdsmail
|
|
426
|
+ echo "set spoolfile=~/Maildir/i2p" >> /etc/skel/.mutt/bdsmail
|
|
427
|
+ echo 'set pgp_autoencrypt=no' >> /etc/skel/.mutt/bdsmail
|
|
428
|
+ echo 'set pgp_replyencrypt=no' >> /etc/skel/.mutt/bdsmail
|
|
429
|
+ echo 'set pgp_autosign=no' >> /etc/skel/.mutt/bdsmail
|
|
430
|
+ echo 'set pgp_replysign=no' >> /etc/skel/.mutt/bdsmail
|
|
431
|
+
|
|
432
|
+ # mutt configuration for the admin user
|
|
433
|
+ if [ ! -d /home/$MY_USERNAME/.mutt ]; then
|
|
434
|
+ mkdir /home/$MY_USERNAME/.mutt
|
|
435
|
+ fi
|
|
436
|
+ cp /etc/skel/.mutt/bdsmail /home/$MY_USERNAME/.mutt
|
|
437
|
+ sed -i "s|username|$MY_USERNAME|g" /home/$MY_USERNAME/.mutt/bdsmail
|
|
438
|
+ chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt
|
|
439
|
+
|
|
440
|
+ bdsmail_configure_users
|
|
441
|
+
|
|
442
|
+ $BDSMAIL_DIR/bin/mailtool $BDSMAIL_DIR/config.ini $MY_USERNAME /home/$MY_USERNAME/Maildir/i2p
|
|
443
|
+
|
|
444
|
+ APP_INSTALLED=1
|
|
445
|
+}
|
|
446
|
+
|
|
447
|
+# NOTE: deliberately there is no "exit 0"
|