forked from msimerson/Mail-Toaster-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision-vpopmail.sh
executable file
·210 lines (169 loc) · 5.74 KB
/
provision-vpopmail.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/sh
# shellcheck disable=1091
. mail-toaster.sh || exit
export VPOPMAIL_OPTIONS_SET="CLEAR_PASSWD"
export VPOPMAIL_OPTIONS_UNSET="ROAMING"
export JAIL_CONF_EXTRA="
mount += \"$ZFS_DATA_MNT/vpopmail \$path/usr/local/vpopmail nullfs rw 0 0\";"
install_qmail()
{
tell_status "setting up data fs for qmail control files"
mkdir -p "$STAGE_MNT/var/qmail" \
"$ZFS_DATA_MNT/vpopmail/qmail-control" \
"$ZFS_DATA_MNT/vpopmail/qmail-users"
stage_exec ln -s /usr/local/vpopmail/qmail-control /var/qmail/control
stage_exec ln -s /usr/local/vpopmail/qmail-users /var/qmail/users
tell_status "installing qmail"
mkdir -p "$STAGE_MNT/usr/local/etc/rc.d"
echo "$TOASTER_HOSTNAME" > "$ZFS_DATA_MNT/vpopmail/qmail-control/me"
stage_pkg_install netqmail daemontools ucspi-tcp || exit
tell_status "enabling qmail"
stage_exec /var/qmail/scripts/enable-qmail
local _alias="$STAGE_MNT/var/qmail/alias"
echo "postmaster@$TOASTER_MAIL_DOMAIN" | tee "$_alias/.qmail-root"
echo "postmaster@$TOASTER_MAIL_DOMAIN" | tee "$_alias/.qmail-postmaster"
echo "postmaster@$TOASTER_MAIL_DOMAIN" | tee "$_alias/.qmail-mailer-daemon"
stage_make_conf mail_qmail_ 'mail_qmail_SET=DNS_CNAME DOCS MAILDIRQUOTA_PATCH
mail_qmail_UNSET=RCDLINK
'
# stage_exec make -C /usr/ports/mail/qmail deinstall install clean
}
install_maildrop()
{
tell_status "installing maildrop"
stage_pkg_install maildrop
tell_status "installing maildrop filter file"
fetch -o "$STAGE_MNT/etc/mailfilter" http://mail-toaster.com/install/mt6-mailfilter.txt
chown 89:89 "$STAGE_MNT/etc/mailfilter"
chmod 600 "$STAGE_MNT/etc/mailfilter"
tell_status "adding legacy mailfilter for MT5 compatibility"
mkdir -p "$STAGE_MNT/usr/local/etc/mail"
cp "$STAGE_MNT/etc/mailfilter" "$STAGE_MNT/usr/local/etc/mail/"
chown 89:89 "$STAGE_MNT/usr/local/etc/mailfilter"
chmod 600 "$STAGE_MNT/usr/local/etc/mailfilter"
}
install_lighttpd()
{
tell_status "installing lighttpd"
stage_pkg_install lighttpd
local _conf; _conf="$STAGE_MNT/usr/local/etc/lighttpd/lighttpd.conf"
sed -i .bak \
-e '/^server.use-ipv6/ s/enable/disable/' \
-e 's/^\$SERVER\["socket"\]/#\$SERVER\["socket"\]/' \
"$_conf"
cat <<EO_LIGHTTPD >> "$_conf"
server.modules += ( "mod_alias" )
alias.url = ( "/cgi-bin/" => "/usr/local/www/cgi-bin/",
"/qmailadmin/" => "/usr/local/www/data/qmailadmin/",
)
server.modules += ( "mod_cgi" )
\$HTTP["url"] =~ "^/cgi-bin" {
cgi.assign = ( "" => "" )
}
EO_LIGHTTPD
stage_sysrc lighttpd_enable=YES
stage_exec service lighttpd start
}
install_qmailadmin()
{
tell_status "installing qmailadmin"
stage_pkg_install autorespond cracklib ezmlm-idx autoconf automake
stage_make_conf mail_qmailadmin_ '
mail_qmailadmin_SET=CRACKLIB HELP IDX MODIFY_QUOTA SPAM_DETECTION TRIVIAL_PASSWORD USER_INDEX
mail_qmailadmin_UNSET=CATCHALL IDX_SQL
'
export WEBDATADIR=www/data CGIBINDIR=www/cgi-bin CGIBINSUBDIR=qmailadmin
stage_exec make -C /usr/ports/mail/qmailadmin install clean
install_lighttpd
}
install_vpopmail_mysql_grants()
{
tell_status "enabling vpopmail MySQL access"
local _vpe; _vpe="$STAGE_MNT/usr/local/vpopmail/etc/vpopmail.mysql"
if [ ! -f "$_vpe" ]; then
echo "ERR: where is $_vpe?"
exit
fi
if ! mysql_db_exists vpopmail; then
tell_status "creating vpopmail database"
echo "CREATE DATABASE vpopmail;" | jexec mysql /usr/local/bin/mysql || exit
fi
local _last; _last=$(grep -v ^# "$_vpe" | head -n1 | cut -f4 -d'|')
if [ "$_last" != "secret" ]; then
echo "preserving password $_last"
return
fi
local _vpass; _vpass=$(openssl rand -hex 18)
sed -i .bak \
-e "s/localhost/$(get_jail_ip mysql)/" \
-e 's/root/vpopmail/' \
-e "s/secret/$_vpass/" \
"$_vpe" || exit
local _vpopmail_ip; _vpopmail_ip=$(get_jail_ip vpopmail)
echo "GRANT ALL PRIVILEGES ON vpopmail.* to 'vpopmail'@'${_vpopmail_ip}' IDENTIFIED BY '${_vpass}';" \
| jexec mysql /usr/local/bin/mysql || exit
local _stage_ip; _stage_ip=$(get_jail_ip)
echo "GRANT ALL PRIVILEGES ON vpopmail.* to 'vpopmail'@'${_stage_ip}' IDENTIFIED BY '${_vpass}';" \
| jexec mysql /usr/local/bin/mysql || exit
}
install_vpopmail_port()
{
if [ "$TOASTER_MYSQL" = "1" ]; then
tell_status "installing vpopmail mysql dependency"
stage_pkg_install mysql56-client
VPOPMAIL_OPTIONS_SET="$VPOPMAIL_OPTIONS_SET MYSQL VALIAS"
VPOPMAIL_OPTIONS_UNSET="$VPOPMAIL_OPTIONS_UNSET CDB"
fi
tell_status "installing vpopmail port with custom options"
stage_make_conf mail_vpopmail_ "
mail_vpopmail_SET=$VPOPMAIL_OPTIONS_SET
mail_vpopmail_UNSET=$VPOPMAIL_OPTIONS_UNSET
"
stage_pkg_install gmake gettext dialog4ports fakeroot
stage_exec make -C /usr/ports/mail/vpopmail deinstall install clean
if [ "$TOASTER_MYSQL" = "1" ]; then
install_vpopmail_mysql_grants
fi
}
install_vpopmail()
{
install_qmail
install_maildrop
# stage_exec pw groupadd -n vpopmail -g 89
# stage_exec pw useradd -n vpopmail -s /nonexistent -d /usr/local/vpopmail -u 89 -g 89 -m -h-
tell_status "installing vpopmail package"
stage_pkg_install vpopmail || exit
install_vpopmail_port
install_qmailadmin
if [ -n "$TOASTER_NRPE" ]; then
stage_pkg_install nrpe
fi
}
configure_vpopmail()
{
tell_status "setting up daemon supervision"
fetch -o - http://mail-toaster.com/install/mt6-qmail-run.txt | stage_exec sh
if [ ! -d "$ZFS_DATA_MNT/vpopmail/domains/$TOASTER_MAIL_DOMAIN" ]; then
tell_status "ATTN: Your postmaster password is..."
stage_exec /usr/local/vpopmail/bin/vadddomain -r14 "$TOASTER_MAIL_DOMAIN"
fi
}
start_vpopmail()
{
true
}
test_vpopmail()
{
echo "testing vpopmail"
sleep 1 # give the daemons a second to start listening
stage_exec sockstat -l -4 | grep :89 || exit
echo "it worked"
}
base_snapshot_exists || exit
create_staged_fs vpopmail
start_staged_jail
install_vpopmail
configure_vpopmail
start_vpopmail
test_vpopmail
promote_staged_jail vpopmail