forked from msimerson/Mail-Toaster-6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision-dspam.sh
executable file
·90 lines (73 loc) · 1.93 KB
/
provision-dspam.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
#!/bin/sh
# shellcheck disable=1091
. mail-toaster.sh || exit
install_dspam()
{
tell_status "installing dspam"
stage_pkg_install dspam || exit
}
configure_dspam_mysql()
{
tell_status "enabling dspam MySQL"
local _dconf="$STAGE_MNT/usr/local/etc/dspam.conf"
if [ ! -f "$_dconf" ]; then
fatal_err "where is $_dconf?"
fi
local _last
if ! mysql_db_exists dspam; then
tell_status "creating dspam database"
echo "CREATE DATABASE dspam;" | jexec mysql /usr/local/bin/mysql || exit
fi
local _curcfg="$ZFS_JAIL_MNT/dspam/usr/local/etc/dspam.conf"
if [ -f "$_curcfg" ]; then
_last=$(grep ^MySQLPass "$_curcfg" | awk '{ print $2 }' | head -n1)
fi
if [ -n "$_last" ] && [ "$_last" != "changeme" ]; then
echo "preserving password"
_dpass="$_last"
return
fi
_dpass=$(openssl rand -hex 18)
echo "GRANT ALL PRIVILEGES ON dspam.* to 'dspam'@'$(get_jail_ip dspam)' IDENTIFIED BY '${_dpass}';" \
| jexec mysql /usr/local/bin/mysql || exit
echo "GRANT ALL PRIVILEGES ON dspam.* to 'dspam'@'$(get_jail_ip stage)' IDENTIFIED BY '${_dpass}';" \
| jexec mysql /usr/local/bin/mysql || exit
}
configure_dspam()
{
tell_status "configuring dspam"
local _etc="$STAGE_MNT/usr/local/etc"
cp "$_etc/dspam.conf.sample" "$_etc/dspam.conf"
sed -i .bak \
-e 's/^#ServerPID/ServerPID/' \
-e '/^StorageDriver/ s/libpgsql/libmysql/' \
"$_etc/dspam.conf"
configure_dspam_mysql
tee -a "$_etc/dspam.conf" <<EO_DSPAM_MYSQL
MySQLServer $(get_jail_ip mysql)
MySQLUser dspam
MySQLPass $_dpass
MySQLDb dspam
EO_DSPAM_MYSQL
}
start_dspam()
{
tell_status "starting dspam"
stage_sysrc dspam_enable=YES
stage_exec service dspam start
}
test_dspam()
{
tell_status "testing dspam"
sleep 2
stage_exec sockstat -l -4 | grep :24 || exit
echo "it worked"
}
base_snapshot_exists || exit
create_staged_fs dspam
start_staged_jail
install_dspam
configure_dspam
start_dspam
test_dspam
promote_staged_jail dspam