forked from msimerson/Mail-Toaster-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-sqwebmail.sh
executable file
·153 lines (121 loc) · 3.42 KB
/
provision-sqwebmail.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/sh
# shellcheck disable=1091
. mail-toaster.sh || exit
export JAIL_START_EXTRA=""
export JAIL_CONF_EXTRA="
mount += \"$ZFS_DATA_MNT/sqwebmail \$path/data nullfs rw 0 0\";
mount += \"$ZFS_DATA_MNT/vpopmail \$path/usr/local/vpopmail nullfs rw 0 0\";"
mt6-include vpopmail
install_authdaemond()
{
tell_status "building courier-authlib with vpopmail support"
stage_make_conf security_courier-authlib "
security_courier-authlib_SET=AUTH_VCHKPW
"
export BATCH=${BATCH:="1"}
# sunset after 2017-08 (when courier-unicode 2.0 is installed by pkg)
stage_port_install devel/courier-unicode || exit
stage_port_install security/courier-authlib || exit
}
install_sqwebmail_src()
{
stage_make_conf mail_sqwebmail "
mail_sqwebmail_SET=AUTH_VCHKPW
mail_sqwebmail_UNSET=SENTRENAME
"
export BATCH=${BATCH:="1"}
stage_port_install mail/sqwebmail || exit
}
install_sqwebmail()
{
if [ "$TOASTER_MYSQL" = "1" ]; then
tell_status "installing mysql client libs (for vpopmail)"
stage_pkg_install mysql57-client dialog4ports
fi
install_qmail
install_vpopmail_port
tell_status "installing sqwebmail"
stage_pkg_install sqwebmail courier-authlib lighttpd maildrop gnupg || exit
install_authdaemond
install_sqwebmail_src
}
configure_lighttpd()
{
stage_sysrc lighttpd_enable=YES
local _lighttpd="$STAGE_MNT/usr/local/etc/lighttpd/lighttpd.conf"
if grep -qs data-dist "$_lighttpd"; then
tell_status "sqwebmail already configured"
return
fi
tell_status "enabling sqwebmail in lighttpd.conf"
# shellcheck disable=2016
sed -i .bak \
-e '/^var.server_root/ s/data/data-dist/' \
-e '/^server.document-root/ s/data/data-dist/' \
"$_lighttpd"
tee -a "$_lighttpd" <<EO_LIGHTTPD
server.modules += ( "mod_cgi", "mod_alias", "mod_extforward" )
alias.url += (
"/cgi-bin" => "/usr/local/www/cgi-bin-dist/sqwebmail/",
"/sqwebmail/" => "/usr/local/www/data-dist/sqwebmail/",
)
\$HTTP["url"] =~ "^/cgi-bin" {
cgi.assign = ( "" => "" )
}
extforward.forwarder = (
"$(get_jail_ip haproxy)" => "trust",
)
EO_LIGHTTPD
}
configure_authdaemon()
{
stage_sysrc courier_authdaemond_enable=YES
tell_status "configuring authdaemond"
sed -i .bak \
-e '/^authmodulelist/ s/authuserdb authvchkpw authpam authldap authmysql authpgsql/authvchkpw/' \
"$STAGE_MNT/usr/local/etc/authlib/authdaemonrc"
}
configure_sqwebmail()
{
tell_status "configuring sqwebmail"
stage_sysrc sqwebmaild_enable=YES
configure_authdaemon
tee -a "$STAGE_MNT/usr/local/etc/sqwebmail/maildirfilterconfig" <<EO_MFC
MAILDIRFILTER=../.mailfilter
MAILDIR=./Maildir
EO_MFC
}
start_sqwebmail()
{
tell_status "starting sqwebmaild"
stage_exec service sqwebmail-sqwebmaild start || exit
tell_status "starting courier-authdaemond"
stage_exec service courier-authdaemond start || exit
tell_status "starting lighttpd"
stage_exec service lighttpd start || exit
}
test_sqwebmail()
{
tell_status "testing sqwebmaild"
if [ ! -S "$STAGE_MNT/var/sqwebmail/sqwebmail.sock" ]; then
tell_status "sqwebmail socket missing"
exit
fi
tell_status "testing courier-authdaemond"
if [ ! -S "$STAGE_MNT/var/run/authdaemond/socket" ]; then
tell_status "courier-authdaemond socket missing"
exit
fi
tell_status "testing lighttpd on port 80"
stage_listening 80
echo "it worked"
}
base_snapshot_exists || exit
create_staged_fs sqwebmail
start_staged_jail sqwebmail
install_sqwebmail
configure_sqwebmail
configure_lighttpd
start_sqwebmail
test_sqwebmail
promote_staged_jail sqwebmail