1 |
mrness 07/09/30 11:30:48 |
2 |
|
3 |
Modified: ChangeLog |
4 |
Added: dspam-3.8.0-r7.ebuild |
5 |
Log: |
6 |
Major dspam.cron and pkg_config redesign (#193081). Drop sqlite-2 support. Install prefs.h needed by dovecot-dspam. |
7 |
(Portage version: 2.1.3.9) |
8 |
|
9 |
Revision Changes Path |
10 |
1.97 mail-filter/dspam/ChangeLog |
11 |
|
12 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/mail-filter/dspam/ChangeLog?rev=1.97&view=markup |
13 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/mail-filter/dspam/ChangeLog?rev=1.97&content-type=text/plain |
14 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/mail-filter/dspam/ChangeLog?r1=1.96&r2=1.97 |
15 |
|
16 |
Index: ChangeLog |
17 |
=================================================================== |
18 |
RCS file: /var/cvsroot/gentoo-x86/mail-filter/dspam/ChangeLog,v |
19 |
retrieving revision 1.96 |
20 |
retrieving revision 1.97 |
21 |
diff -u -r1.96 -r1.97 |
22 |
--- ChangeLog 10 Sep 2007 04:06:01 -0000 1.96 |
23 |
+++ ChangeLog 30 Sep 2007 11:30:47 -0000 1.97 |
24 |
@@ -1,6 +1,13 @@ |
25 |
# ChangeLog for mail-filter/dspam |
26 |
# Copyright 1999-2007 Gentoo Foundation; Distributed under the GPL v2 |
27 |
-# $Header: /var/cvsroot/gentoo-x86/mail-filter/dspam/ChangeLog,v 1.96 2007/09/10 04:06:01 mrness Exp $ |
28 |
+# $Header: /var/cvsroot/gentoo-x86/mail-filter/dspam/ChangeLog,v 1.97 2007/09/30 11:30:47 mrness Exp $ |
29 |
+ |
30 |
+*dspam-3.8.0-r7 (30 Sep 2007) |
31 |
+ |
32 |
+ 30 Sep 2007; Alin Năstac <mrness@g.o> +files/dspam.cron-r1, |
33 |
+ +files/pgsql_createdb.py, +files/pgsql_purge.py, +dspam-3.8.0-r7.ebuild: |
34 |
+ Major dspam.cron and pkg_config redesign (#193081). Drop sqlite-2 support. |
35 |
+ Install prefs.h needed by dovecot-dspam. |
36 |
|
37 |
*dspam-3.8.0-r6 (10 Sep 2007) |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
1.1 mail-filter/dspam/dspam-3.8.0-r7.ebuild |
43 |
|
44 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/mail-filter/dspam/dspam-3.8.0-r7.ebuild?rev=1.1&view=markup |
45 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/mail-filter/dspam/dspam-3.8.0-r7.ebuild?rev=1.1&content-type=text/plain |
46 |
|
47 |
Index: dspam-3.8.0-r7.ebuild |
48 |
=================================================================== |
49 |
# Copyright 1999-2007 Gentoo Foundation |
50 |
# Distributed under the terms of the GNU General Public License v2 |
51 |
# $Header: /var/cvsroot/gentoo-x86/mail-filter/dspam/dspam-3.8.0-r7.ebuild,v 1.1 2007/09/30 11:30:47 mrness Exp $ |
52 |
|
53 |
WANT_AUTOCONF="latest" |
54 |
WANT_AUTOMAKE="latest" |
55 |
|
56 |
inherit eutils autotools flag-o-matic multilib |
57 |
|
58 |
DESCRIPTION="A statistical-algorithmic hybrid anti-spam filter" |
59 |
HOMEPAGE="http://dspam.nuclearelephant.com/" |
60 |
SRC_URI="http://dspam.nuclearelephant.com/sources/${P}.tar.gz |
61 |
mirror://gentoo/${P}-patches-20070930.tar.gz |
62 |
http://dspam.nuclearelephant.com/sources/extras/dspam_sa_trainer.tar.gz" |
63 |
|
64 |
LICENSE="GPL-2" |
65 |
SLOT="0" |
66 |
KEYWORDS="~alpha ~amd64 ~ppc ~sparc ~x86" |
67 |
IUSE="clamav daemon debug ldap mysql postgres sqlite \ |
68 |
large-domain virtual-users user-homedirs" |
69 |
|
70 |
COMMON_DEPEND="clamav? ( >=app-antivirus/clamav-0.90.2 ) |
71 |
ldap? ( >=net-nds/openldap-2.2 ) |
72 |
mysql? ( virtual/mysql ) |
73 |
sqlite? ( =dev-db/sqlite-3* )" |
74 |
DEPEND="${COMMON_DEPEND} |
75 |
postgres? ( >=dev-db/libpq-8 )" |
76 |
RDEPEND="${COMMON_DEPEND} |
77 |
postgres? ( || ( dev-python/psycopg >=dev-db/postgresql-8 ) ) |
78 |
sys-process/cronbase |
79 |
virtual/logger" |
80 |
|
81 |
# some FHS-like structure |
82 |
DSPAM_HOMEDIR="/var/spool/dspam" |
83 |
DSPAM_CONFDIR="/etc/mail/dspam" |
84 |
DSPAM_LOGDIR="/var/log/dspam" |
85 |
DSPAM_MODE=2511 |
86 |
|
87 |
create_dspam_usergroup() { |
88 |
local egid euid |
89 |
#Need a UID and GID >= 1000, for being able to use suexec in apache |
90 |
for euid in $(seq 1000 5000 ) ; do |
91 |
[[ -z $(egetent passwd ${euid}) ]] && break |
92 |
done |
93 |
for egid in $(seq 1000 5000 ) ; do |
94 |
[[ -z $(egetent group ${egid}) ]] && break |
95 |
done |
96 |
|
97 |
enewgroup dspam ${egid} |
98 |
enewuser dspam ${euid} -1 "${DSPAM_HOMEDIR}" dspam,mail |
99 |
} |
100 |
|
101 |
pkg_setup() { |
102 |
if use virtual-users && use user-homedirs ; then |
103 |
eerror "If the users are virtual, then they probably should not have home directories." |
104 |
die "Incompatible USE flag selection" |
105 |
fi |
106 |
|
107 |
# Delete these lines some time after -r6 removal |
108 |
if has_version "<=mail-filter/dspam-3.8.0-r6" && |
109 |
built_with_use "<=mail-filter/dspam-3.8.0-r6" sqlite && |
110 |
grep -q "^StorageDriver.*libsqlite_drv.so" "${ROOT}${DSPAM_CONFDIR}"/dspam.conf; then |
111 |
eerror "Sqlite2 support has been removed. Please upgrade your database to sqlite3" |
112 |
eerror "and select libsqlite3_drv.so in dspam.conf before proceeding with update." |
113 |
die "sqlite-2 no longer supported" |
114 |
fi |
115 |
|
116 |
create_dspam_usergroup |
117 |
} |
118 |
|
119 |
src_unpack() { |
120 |
unpack ${A} |
121 |
cd "${S}" |
122 |
|
123 |
EPATCH_SUFFIX="patch" |
124 |
epatch "${WORKDIR}"/patches |
125 |
|
126 |
# Fix Lazy bindings |
127 |
append-flags $(bindnow-flags) |
128 |
|
129 |
AT_M4DIR="${S}/m4" |
130 |
eautoreconf |
131 |
} |
132 |
|
133 |
src_compile() { |
134 |
local myconf="--enable-long-usernames --enable-syslog" |
135 |
|
136 |
use large-domain && myconf="${myconf} --enable-large-scale" || \ |
137 |
myconf="${myconf} --enable-domain-scale" |
138 |
|
139 |
use user-homedirs && myconf="${myconf} --enable-homedir" |
140 |
|
141 |
use debug && myconf="${myconf} --enable-debug --enable-bnr-debug" |
142 |
|
143 |
if use virtual-users ; then |
144 |
if use mysql || use postgres ; then |
145 |
myconf="${myconf} --enable-virtual-users" |
146 |
fi |
147 |
fi |
148 |
|
149 |
if use mysql || use postgres ; then |
150 |
myconf="${myconf} --enable-preferences-extension" |
151 |
fi |
152 |
|
153 |
local STORAGE="hash_drv" |
154 |
# select storage driver |
155 |
if use sqlite ; then |
156 |
STORAGE="${STORAGE},sqlite3_drv" |
157 |
fi |
158 |
if use mysql; then |
159 |
STORAGE="${STORAGE},mysql_drv" |
160 |
myconf="${myconf} --with-mysql-includes=/usr/include/mysql" |
161 |
myconf="${myconf} --with-mysql-libraries=/usr/$(get_libdir)/mysql" |
162 |
fi |
163 |
if use postgres ; then |
164 |
STORAGE="${STORAGE},pgsql_drv" |
165 |
myconf="${myconf} --with-pgsql-includes=/usr/include/postgresql" |
166 |
myconf="${myconf} --with-pgsql-libraries=/usr/$(get_libdir)/postgresql" |
167 |
fi |
168 |
|
169 |
econf ${myconf} --with-storage-driver=${STORAGE} \ |
170 |
--with-dspam-home="${DSPAM_HOMEDIR}" \ |
171 |
--sysconfdir="${DSPAM_CONFDIR}" \ |
172 |
$(use_enable daemon) \ |
173 |
$(use_enable ldap) \ |
174 |
$(use_enable clamav) \ |
175 |
--with-dspam-group=dspam \ |
176 |
--with-dspam-home-group=dspam \ |
177 |
--with-dspam-mode=${DSPAM_MODE} \ |
178 |
--with-logdir="${DSPAM_LOGDIR}" || die "econf failed" |
179 |
emake || die "emake failed" |
180 |
} |
181 |
|
182 |
src_install () { |
183 |
diropts -m0770 -o dspam -g dspam |
184 |
dodir "${DSPAM_CONFDIR}" |
185 |
insinto "${DSPAM_CONFDIR}" |
186 |
insopts -m640 -o dspam -g dspam |
187 |
doins src/dspam.conf |
188 |
dosym /etc/mail/dspam /etc/dspam |
189 |
|
190 |
# make install |
191 |
emake DESTDIR="${D}" install || die "emake install failed" |
192 |
|
193 |
# necessary for dovecot-dspam |
194 |
insopts -m644 |
195 |
insinto /usr/include/dspam && doins src/pref.h |
196 |
|
197 |
diropts -m0755 -o dspam -g dspam |
198 |
dodir /var/run/dspam |
199 |
|
200 |
# create logdir (used only when build with debug useflag) |
201 |
if use debug ; then |
202 |
diropts -m0770 -o dspam -g dspam |
203 |
dodir "${DSPAM_LOGDIR}" |
204 |
diropts -m0755 |
205 |
insinto /etc/logrotate.d |
206 |
newins "${FILESDIR}/logrotate.dspam" dspam || die "failed to install logrotate.d file" |
207 |
fi |
208 |
|
209 |
if use daemon; then |
210 |
# We use sockets for the daemon instead of tcp port 24 |
211 |
sed -e 's:^#*\(ServerDomainSocketPath[\t ]\{1,\}\).*:\1\"/var/run/dspam/dspam.sock\":gI' \ |
212 |
-e 's:^#*\(ServerPID[\t ]\{1,\}\).*:\1/var/run/dspam/dspam.pid:gI' \ |
213 |
-e 's:^#*\(ClientHost[\t ]\{1,\}\)/.*:\1\"/var/run/dspam/dspam.sock\":gI' \ |
214 |
-i "${D}/${DSPAM_CONFDIR}/dspam.conf" |
215 |
|
216 |
newinitd "${FILESDIR}/dspam.rc" dspam || die "failed to install init script" |
217 |
|
218 |
fowners root:dspam /usr/bin/dspamc && |
219 |
fperms u=rx,g=xs,o=x /usr/bin/dspamc || |
220 |
die "failed to alter dspamc owner:group or mode" |
221 |
fi |
222 |
|
223 |
# database related configuration and scripts |
224 |
local PASSWORD="${RANDOM}${RANDOM}${RANDOM}${RANDOM}" DSPAM_DB_DATA=() |
225 |
if use sqlite; then |
226 |
insinto "${DSPAM_CONFDIR}" |
227 |
newins src/tools.sqlite_drv/purge-3.sql sqlite3_purge.sql || die "failed to install sqlite3_purge.sql script" |
228 |
fi |
229 |
if use mysql; then |
230 |
DSPAM_DB_DATA[0]="/var/run/mysqld/mysqld.sock" |
231 |
DSPAM_DB_DATA[1]="" |
232 |
DSPAM_DB_DATA[2]="dspam" |
233 |
DSPAM_DB_DATA[3]="${PASSWORD}" |
234 |
DSPAM_DB_DATA[4]="dspam" |
235 |
DSPAM_DB_DATA[5]="false" |
236 |
|
237 |
# Activate mysql database configuration |
238 |
sed -e "s:^#*\(MySQLServer[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[0]}:gI" \ |
239 |
-e "s:^#*\(MySQLPort[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[1]}:gI" \ |
240 |
-e "s:^#*\(MySQLUser[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[2]}:gI" \ |
241 |
-e "s:^#*\(MySQLPass[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[3]}:gI" \ |
242 |
-e "s:^#*\(MySQLDb[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[4]}:gI" \ |
243 |
-e "s:^#*\(MySQLCompress[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[5]}:gI" \ |
244 |
-i "${D}/${DSPAM_CONFDIR}/dspam.conf" |
245 |
|
246 |
insinto "${DSPAM_CONFDIR}" |
247 |
newins src/tools.mysql_drv/mysql_objects-space.sql mysql_objects-space.sql && |
248 |
newins src/tools.mysql_drv/mysql_objects-speed.sql mysql_objects-speed.sql && |
249 |
newins src/tools.mysql_drv/mysql_objects-4.1.sql mysql_objects-4.1.sql && |
250 |
newins src/tools.mysql_drv/purge.sql mysql_purge.sql && |
251 |
newins src/tools.mysql_drv/purge-4.1.sql mysql_purge-4.1.sql || |
252 |
die "failed to install mysql*.sql scripts" |
253 |
if use virtual-users ; then |
254 |
newins src/tools.mysql_drv/virtual_users.sql mysql_virtual_users.sql && |
255 |
newins src/tools.mysql_drv/virtual_user_aliases.sql mysql_virtual_user_aliases.sql || |
256 |
die "failed to install mysql_virtual_user*.sql scripts" |
257 |
fi |
258 |
fi |
259 |
if use postgres ; then |
260 |
DSPAM_DB_DATA[0]="127.0.0.1" |
261 |
DSPAM_DB_DATA[1]="5432" |
262 |
DSPAM_DB_DATA[2]="dspam" |
263 |
DSPAM_DB_DATA[3]="${PASSWORD}" |
264 |
DSPAM_DB_DATA[4]="dspam" |
265 |
|
266 |
# Activate pgsql database configuration |
267 |
sed -e "s:^#*\(PgSQLServer[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[0]}:gI" \ |
268 |
-e "s:^#*\(PgSQLPort[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[1]}:gI" \ |
269 |
-e "s:^#*\(PgSQLUser[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[2]}:gI" \ |
270 |
-e "s:^#*\(PgSQLPass[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[3]}:gI" \ |
271 |
-e "s:^#*\(PgSQLDb[\t ]\{1,\}\).*:\1${DSPAM_DB_DATA[4]}:gI" \ |
272 |
-e "s:^#*\(PgSQLConnectionCache[\t ]*.\):\1:gI" \ |
273 |
-i "${D}/${DSPAM_CONFDIR}"/dspam.conf |
274 |
|
275 |
insinto "${DSPAM_CONFDIR}" |
276 |
newins src/tools.pgsql_drv/pgsql_objects.sql pgsql_objects.sql && |
277 |
newins src/tools.pgsql_drv/purge.sql pgsql_purge.sql || |
278 |
die "failed to install pgsql*.sql scripts" |
279 |
if use virtual-users ; then |
280 |
newins src/tools.pgsql_drv/virtual_users.sql pgsql_virtual_users.sql || |
281 |
die "failed to install pgsql_virtual_users.sql scripts" |
282 |
fi |
283 |
|
284 |
# Install psycopg scripts needed when postgresql is not installed |
285 |
exeinto "${DSPAM_CONFDIR}" |
286 |
doexe "${FILESDIR}"/pgsql_{createdb,purge}.py || die "failed to install psycopg scripts" |
287 |
fi |
288 |
|
289 |
# Set default storage |
290 |
local DEFAULT_STORAGE |
291 |
if use sqlite ; then |
292 |
DEFAULT_STORAGE=sqlite3 |
293 |
elif use mysql ; then |
294 |
DEFAULT_STORAGE=mysql |
295 |
elif use postgres ; then |
296 |
DEFAULT_STORAGE=pgsql |
297 |
fi |
298 |
if [[ -z "${DEFAULT_STORAGE}" ]]; then |
299 |
# When only one storage driver is compiled, it is linked statically with dspam |
300 |
# thus you should not set the StorageDriver at all |
301 |
# Also, hash_drv requires certain tokenizer and PValue (see bug #185718) |
302 |
sed -e "s:^\(StorageDriver[\t ].*\)$:#\1:" \ |
303 |
-e "s:^Tokenizer .*$:Tokenizer sbph:" \ |
304 |
-e "/^#PValue/d" \ |
305 |
-e "s:^PValue .*$:PValue markov:" \ |
306 |
-i "${D}/${DSPAM_CONFDIR}"/dspam.conf |
307 |
else |
308 |
# Set the storage driver and use purge configuration for SQL-based installations |
309 |
sed -e "s:^\(Purge.*\):###\1:g" \ |
310 |
-e "s:^#\(Purge.*\):\1:g" \ |
311 |
-e "s:^###\(Purge.*\):#\1:g" \ |
312 |
-e "s:^\(StorageDriver[\t ].*\)libhash_drv.so:\1lib${DEFAULT_STORAGE}_drv.so:" \ |
313 |
-i "${D}/${DSPAM_CONFDIR}"/dspam.conf |
314 |
fi |
315 |
|
316 |
# installs the notification messages |
317 |
# -> The documentation is wrong! The files need to be in ./txt |
318 |
echo "Scanned and tagged as SPAM with DSPAM ${PV} by Your ISP.com">"${T}"/msgtag.spam |
319 |
echo "Scanned and tagged as non-SPAM with DSPAM ${PV} by Your ISP.com">"${T}"/msgtag.nonspam |
320 |
insinto "${DSPAM_CONFDIR}"/txt |
321 |
doins "${S}"/txt/*.txt |
322 |
doins "${T}"/msgtag.* |
323 |
|
324 |
# Create the opt-in / opt-out directories |
325 |
diropts -m0770 -o dspam -g dspam |
326 |
dodir "${DSPAM_HOMEDIR}" |
327 |
keepdir "${DSPAM_HOMEDIR}"/opt-in |
328 |
keepdir "${DSPAM_HOMEDIR}"/opt-out |
329 |
diropts -m0755 |
330 |
|
331 |
# dspam cron job |
332 |
exeinto /etc/cron.daily |
333 |
newexe "${FILESDIR}/dspam.cron-r1" dspam.cron || die "failed to install cron script" |
334 |
|
335 |
# documentation |
336 |
dodoc CHANGELOG README* RELEASE.NOTES UPGRADING |
337 |
docinto doc |
338 |
dodoc doc/*.txt |
339 |
docinto gentoo |
340 |
dodoc "${FILESDIR}"/README.{postfix,qmail} |
341 |
docinto sa_train |
342 |
dodoc "${WORKDIR}"/dspam_sa_trainer/* |
343 |
doman man/dspam* |
344 |
} |
345 |
|
346 |
pkg_preinst() { |
347 |
# Delete these lines some time after -r6 removal |
348 |
if has_version "<=mail-filter/dspam-3.8.0-r6" ; then |
349 |
# Remove obsolete *.data files |
350 |
local f |
351 |
for f in "${ROOT}${DSPAM_CONFDIR}"/{mysql,pgsql}.data ; do |
352 |
f=${f/\/\//\/} |
353 |
if [[ -f "${f}" ]]; then |
354 |
rm "${f}" && |
355 |
elog "Obsolete ${f} has been removed" || |
356 |
eerror "Failed to remove ${f}" |
357 |
fi |
358 |
done |
359 |
fi |
360 |
} |
361 |
|
362 |
pkg_postinst() { |
363 |
# need enewgroup/enewuser in this function for binary install. |
364 |
create_dspam_usergroup |
365 |
|
366 |
ewarn "The hash_drv storage backend has the following requirements:" |
367 |
ewarn " - PValue must be set to 'markov'; Do not use this pvalue with any other storage backend!" |
368 |
ewarn " - Tokenizer must be either 'sbph' or 'osb'" |
369 |
ewarn "See markov.txt for more info." |
370 |
|
371 |
if use mysql || use postgres; then |
372 |
elog |
373 |
elog "To setup DSPAM to run out-of-the-box on your system with a MySQL" |
374 |
elog "or PostgreSQL database, run:" |
375 |
elog "emerge --config =${PF}" |
376 |
fi |
377 |
|
378 |
if use daemon; then |
379 |
elog |
380 |
elog "If you want to run DSPAM in the new daemon mode remember" |
381 |
elog "to make the DSPAM daemon start during boot:" |
382 |
elog " rc-update add dspam default" |
383 |
elog |
384 |
elog "To use the DSPAM daemon mode, the used storage driver must be thread-safe." |
385 |
fi |
386 |
|
387 |
elog |
388 |
elog "See http://dspamwiki.expass.de/Installation for more info" |
389 |
} |
390 |
|
391 |
# Edits interactively one or more parameters from "${ROOT}${DSPAM_CONFDIR}/dspam.conf" |
392 |
# Usage: edit_dspam_params param_name1 [param_name2 ..] |
393 |
edit_dspam_params() { |
394 |
local PARAMETER OLD_VALUE VALUE |
395 |
for PARAMETER in $@ ; do |
396 |
OLD_VALUE=$(awk "BEGIN { IGNORECASE=1; } \$1==\"${PARAMETER}\" { print \$2; exit; }" "${ROOT}${DSPAM_CONFDIR}/dspam.conf") |
397 |
[[ $? == 0 ]] || return 1 |
398 |
read -r -p "${PARAMETER} (default ${OLD_VALUE:-none}): " VALUE |
399 |
|
400 |
if [[ -z "${VALUE}" ]] ; then |
401 |
VALUE=${OLD_VALUE} |
402 |
else |
403 |
sed -e "s:^#*${PARAMETER}\([\t ].*\)\?\$:${PARAMETER} ${VALUE}:gI" \ |
404 |
-i "${ROOT}${DSPAM_CONFDIR}/dspam.conf" |
405 |
[[ $? == 0 ]] || return 2 |
406 |
fi |
407 |
eval $PARAMETER=\"${VALUE}\" |
408 |
done |
409 |
return 0 |
410 |
} |
411 |
|
412 |
# Selects the storage driver in "${ROOT}${DSPAM_CONFDIR}/dspam.conf" |
413 |
# usage: set_storage_driver { hash | sqlite3 | mysql | pgsql } |
414 |
set_storage_driver() { |
415 |
sed -e "s:^[#\t ]*\(StorageDriver[\t ].*\)lib[a-z1-9]\+_drv.so:\1lib${1}_drv.so:" \ |
416 |
-i "${ROOT}${DSPAM_CONFDIR}"/dspam.conf && |
417 |
einfo "Storage driver lib${1}_drv.so has been selected" |
418 |
} |
419 |
|
420 |
pkg_config () { |
421 |
local AVAIL_BACKENDS=( hash ) |
422 |
use sqlite && AVAIL_BACKENDS=( ${AVAIL_BACKENDS[*]} sqlite ) |
423 |
use mysql && AVAIL_BACKENDS=( ${AVAIL_BACKENDS[*]} mysql ) |
424 |
use postgres && AVAIL_BACKENDS=( ${AVAIL_BACKENDS[*]} postgres ) |
425 |
local USE_BACKEND |
426 |
read -p "Which backend do you want to configure? (available backends are ${AVAIL_BACKENDS[*]}): " USE_BACKEND |
427 |
if [[ " ${AVAIL_BACKENDS[*]} " != *" ${USE_BACKEND} "* ]]; then |
428 |
eerror "The '${USE_BACKEND}' backend is not available." |
429 |
return 1 |
430 |
fi |
431 |
|
432 |
case "${USE_BACKEND}" in |
433 |
|
434 |
hash) |
435 |
einfo "hash driver will automatically create the necessary databases" |
436 |
set_storage_driver hash |
437 |
;; |
438 |
|
439 |
sqlite) |
440 |
einfo "sqlite driver will automatically create the necessary databases" |
441 |
set_storage_driver sqlite3 |
442 |
;; |
443 |
|
444 |
mysql) |
445 |
local MySQLServer MySQLPort MySQLUser MySQLPass MySQLDb MySQLCompress |
446 |
edit_dspam_params MySQLServer MySQLPort MySQLUser MySQLPass MySQLDb MySQLCompress || return $? |
447 |
if [[ -z "${MySQLServer}" || -z "${MySQLUser}" || -z "${MySQLPass}" || -z "${MySQLDb}" ]]; then |
448 |
eerror "Following parameters are required: MySQLServer MySQLUser MySQLPass MySQLDb" |
449 |
return 1 |
450 |
fi |
451 |
|
452 |
local MySQL_DB_Type MySQL_Virtuser_Type |
453 |
einfo " Please select what kind of database you like to create:" |
454 |
einfo " [0] Don't create the database, I will do it myself" |
455 |
einfo " [1] Database will be hosted on a mysql-4.1 server or above" |
456 |
einfo " [2] Space optimized database on a mysql-4.0 server or below" |
457 |
einfo " [3] Speed optimized database on a mysql-4.0 server or below" |
458 |
einfo |
459 |
while read -n 1 -s -p " Press 0, 1, 2 or 3 on the keyboard to select database " MySQL_DB_Type; do |
460 |
if [[ "${MySQL_DB_Type}" == "0" ]] ; then |
461 |
echo |
462 |
set_storage_driver mysql |
463 |
return 0 |
464 |
fi |
465 |
[[ "${MySQL_DB_Type}" == "1" || "${MySQL_DB_Type}" == "2" || "${MySQL_DB_Type}" == "3" ]] && echo && break |
466 |
done |
467 |
if use virtual-users ; then |
468 |
einfo " Please select what kind of virtual_uids table you like to use:" |
469 |
einfo " [1] Virtual users added automatically (use it if this server is the primary MX)" |
470 |
einfo " [2] Virtual users added manually (use it if this server is a secondary MX)" |
471 |
einfo |
472 |
while read -n 1 -s -p " Press 1 or 2 on the keyboard to select table type " MySQL_Virtuser_Type; do |
473 |
[[ "${MySQL_Virtuser_Type}" == "1" || "${MySQL_Virtuser_Type}" == "2" ]] && echo && break |
474 |
done |
475 |
fi |
476 |
|
477 |
local MYSQL_ROOT_USER |
478 |
read -r -p "Your administrative MySQL account (default root): " MYSQL_ROOT_USER |
479 |
if [[ -z "${MYSQL_ROOT_USER}" ]]; then |
480 |
MYSQL_ROOT_USER="root" |
481 |
fi |
482 |
einfo "When prompted for a password, please enter your MySQL ${MYSQL_ROOT_USER} password" |
483 |
|
484 |
local MYSQL_CMD_LINE="/usr/bin/mysql -u ${MYSQL_ROOT_USER} -p" |
485 |
[[ "${MySQLServer}" != "/"* ]] && MYSQL_CMD_LINE="${MYSQL_CMD_LINE} -h ${MySQLServer}" |
486 |
[[ -n "${MySQLPort}" ]] && MYSQL_CMD_LINE="${MYSQL_CMD_LINE} -P ${MySQLPort}" |
487 |
{ |
488 |
echo "CREATE DATABASE ${MySQLDb};" |
489 |
echo "USE ${MySQLDb};" |
490 |
case ${MySQL_DB_Type} in |
491 |
1) cat "${ROOT}${DSPAM_CONFDIR}"/mysql_objects-4.1.sql ;; |
492 |
2) cat "${ROOT}${DSPAM_CONFDIR}"/mysql_objects-space.sql ;; |
493 |
3) cat "${ROOT}${DSPAM_CONFDIR}"/mysql_objects-speed.sql ;; |
494 |
esac |
495 |
if use virtual-users ; then |
496 |
case ${MySQL_Virtuser_Type} in |
497 |
1) cat "${ROOT}${DSPAM_CONFDIR}"/mysql_virtual_users.sql ;; |
498 |
2) cat "${ROOT}${DSPAM_CONFDIR}"/mysql_virtual_user_aliases.sql ;; |
499 |
esac |
500 |
fi |
501 |
echo "GRANT SELECT,INSERT,UPDATE,DELETE ON ${MySQLDb}.* TO '${MySQLUser}'@'%' IDENTIFIED BY '${MySQLPass}';" |
502 |
echo "FLUSH PRIVILEGES;" |
503 |
} | ${MYSQL_CMD_LINE} |
504 |
[[ ${PIPESTATUS[1]} == 0 ]] || return ${PIPESTATUS[1]} |
505 |
|
506 |
einfo "MySQL database created successfully" |
507 |
set_storage_driver mysql |
508 |
;; |
509 |
|
510 |
postgres) |
511 |
local PgSQLServer PgSQLPort PgSQLUser PgSQLPass PgSQLDb |
512 |
edit_dspam_params PgSQLServer PgSQLPort PgSQLUser PgSQLPass PgSQLDb || return $? |
513 |
if [[ -z "${PgSQLServer}" || -z "${PgSQLUser}" || -z "${PgSQLPass}" || -z "${PgSQLDb}" ]]; then |
514 |
eerror "Following parameters are required: PgSQLServer PgSQLUser PgSQLPass PgSQLDb" |
515 |
return 1 |
516 |
fi |
517 |
|
518 |
local PgSQL_DB_Create |
519 |
einfo " Do you want PgSQL database be automatically created for you?" |
520 |
while read -n 1 -s -p " Press y or n " PgSQL_DB_Create; do |
521 |
if [[ "${PgSQL_DB_Create}" == "n" || "${PgSQL_DB_Create}" == "N" ]] ; then |
522 |
echo |
523 |
set_storage_driver pgsql |
524 |
return 0 |
525 |
fi |
526 |
[[ "${PgSQL_DB_Create}" == "y" || "${PgSQL_DB_Create}" == "Y" ]] && echo && break |
527 |
done |
528 |
|
529 |
local PGSQL_ROOT_USER |
530 |
read -r -p "Your administrative PgSQL account (default postgres): " PGSQL_ROOT_USER |
531 |
if [[ -z "${PGSQL_ROOT_USER}" ]]; then |
532 |
PGSQL_ROOT_USER="postgres" |
533 |
fi |
534 |
einfo "When prompted for a password, please enter your PgSQL ${PGSQL_ROOT_USER} password" |
535 |
|
536 |
if [[ -x /usr/bin/psql ]]; then |
537 |
# Create database using psql |
538 |
local PGSQL_CMD_LINE="/usr/bin/psql -h ${PgSQLServer}" |
539 |
[[ -n "${PgSQLPort}" ]] && PGSQL_CMD_LINE="${PGSQL_CMD_LINE} -p ${PgSQLPort}" |
540 |
|
541 |
{ |
542 |
echo "\\set ON_ERROR_STOP = on;" |
543 |
echo "CREATE USER ${PgSQLUser} WITH PASSWORD '${PgSQLPass}' NOCREATEDB NOCREATEUSER;" |
544 |
echo "CREATE DATABASE ${PgSQLDb};" |
545 |
echo "GRANT ALL PRIVILEGES ON DATABASE ${PgSQLDb} TO ${PgSQLUser};" |
546 |
echo "GRANT ALL PRIVILEGES ON SCHEMA public TO ${PgSQLUser};" |
547 |
echo "UPDATE pg_database SET datdba=(SELECT usesysid FROM pg_shadow WHERE usename='${PgSQLUser}') WHERE datname='${PgSQLDb}';" |
548 |
echo "\\c ${PgSQLDb};" |
549 |
echo "CREATE FUNCTION plpgsql_call_handler() RETURNS language_handler AS '\$libdir/plpgsql', 'plpgsql_call_handler' LANGUAGE c;" |
550 |
echo "CREATE FUNCTION plpgsql_validator(oid) RETURNS void AS '\$libdir/plpgsql', 'plpgsql_validator' LANGUAGE c;" |
551 |
echo "CREATE TRUSTED PROCEDURAL LANGUAGE plpgsql HANDLER plpgsql_call_handler VALIDATOR plpgsql_validator;" |
552 |
} | ${PGSQL_CMD_LINE} -d template1 -U ${PGSQL_ROOT_USER} |
553 |
[[ ${PIPESTATUS[1]} == 0 ]] || return ${PIPESTATUS[1]} |
554 |
|
555 |
{ |
556 |
echo "\\set ON_ERROR_STOP = on;" |
557 |
cat "${ROOT}${DSPAM_CONFDIR}"/pgsql_objects.sql |
558 |
use virtual-users && cat "${ROOT}${DSPAM_CONFDIR}"/pgsql_virtual_users.sql |
559 |
} | PGUSER="${PgSQLUser}" PGPASSWORD="${PgSQLPass}" ${PGSQL_CMD_LINE} -d "${PgSQLDb}" -U ${PgSQLUser} |
560 |
[[ ${PIPESTATUS[1]} == 0 ]] || return ${PIPESTATUS[1]} |
561 |
else |
562 |
# Create database using psycopg script |
563 |
if use virtual-users ; then |
564 |
DSPAM_PgSQLPass="${PgSQLPass}" "${ROOT}${DSPAM_CONFDIR}"/pgsql_createdb.py "${PgSQLServer}" "${PgSQLPort}" "${PGSQL_ROOT_USER}" \ |
565 |
"${PgSQLUser}" "${PgSQLDb}" "${ROOT}${DSPAM_CONFDIR}"/pgsql_objects.sql "${ROOT}${DSPAM_CONFDIR}"/pgsql_virtual_users.sql |
566 |
else |
567 |
DSPAM_PgSQLPass="${PgSQLPass}" "${ROOT}${DSPAM_CONFDIR}"/pgsql_createdb.py "${PgSQLServer}" "${PgSQLPort}" "${PGSQL_ROOT_USER}" \ |
568 |
"${PgSQLUser}" "${PgSQLDb}" "${ROOT}${DSPAM_CONFDIR}"/pgsql_objects.sql |
569 |
fi |
570 |
[[ $? == 0 ]] || return $? |
571 |
fi |
572 |
|
573 |
einfo "PgSQL database created successfully" |
574 |
set_storage_driver pgsql |
575 |
;; |
576 |
|
577 |
esac |
578 |
} |
579 |
|
580 |
|
581 |
|
582 |
-- |
583 |
gentoo-commits@g.o mailing list |