/[gentoo-x86]/eclass/qmail.eclass
Gentoo

Contents of /eclass/qmail.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Wed Jul 28 12:37:32 2010 UTC (4 years ago) by jer
Branch: MAIN
Changes since 1.1: +2 -2 lines
Fix e-mail address.

1 # Copyright 1999-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/qmail.eclass,v 1.1 2008/04/06 17:05:27 hollow Exp $
4
5 # @ECLASS: qmail.eclass
6 # @MAINTAINER: qmail-bugs@gentoo.org
7 # @BLURB: common qmail functions
8
9 inherit flag-o-matic toolchain-funcs fixheadtails
10 DESCRIPTION="Based on the ${ECLASS} eclass"
11
12 # hardcoded paths
13 QMAIL_HOME="/var/qmail"
14 TCPRULES_DIR="/etc/tcprules.d"
15 SUPERVISE_DIR="/var/qmail/supervise"
16
17 # source files and directories
18 GENQMAIL_F=genqmail-${GENQMAIL_PV}.tar.bz2
19 GENQMAIL_S="${WORKDIR}"/genqmail-${GENQMAIL_PV}
20
21 QMAIL_SPP_F=qmail-spp-${QMAIL_SPP_PV}.tar.gz
22 QMAIL_SPP_S="${WORKDIR}"/qmail-spp-${QMAIL_SPP_PV}
23
24 # @FUNCTION: primes
25 # @USAGE: <min> <max>
26 # @DESCRIPTION:
27 # Prints a list of primes between min and max inclusive
28 # Note: this functions gets very slow when used with large numbers.
29 primes() {
30 local min=${1} max=${2}
31 local result= primelist=2 i p
32
33 [[ ${min} -le 2 ]] && result="${result} 2"
34
35 for ((i = 3; i <= max; i += 2))
36 do
37 for p in ${primelist}
38 do
39 [[ $[i % p] == 0 || $[p * p] -gt ${i} ]] && \
40 break
41 done
42 if [[ $[i % p] != 0 ]]
43 then
44 primelist="${primelist} ${i}"
45 [[ ${i} -ge ${min} ]] && \
46 result="${result} ${i}"
47 fi
48 done
49
50 echo ${result}
51 }
52
53 # @FUNCTION: is_prima
54 # @USAGE: <number>
55 # @DESCRIPTION:
56 # Checks wether a number is a prime number
57 is_prime() {
58 local number=${1} i
59 for i in $(primes ${number} ${number})
60 do
61 [[ ${i} == ${number} ]] && return 0
62 done
63 return 1
64 }
65
66 dospp() {
67 insinto "${QMAIL_HOME}"/plugins/
68 insopts -o root -g root -m 0755
69 newins $1 ${2:-$(basename $1)}
70 }
71
72 # @FUNCTION: dosupervise
73 # @USAGE: dosupervise <service> [<runfile> <logfile>]
74 # @DESCRIPTION:
75 # Install runfiles for services and logging to supervise directory
76 dosupervise() {
77 local service=$1
78 local runfile=${2:-${service}} logfile=${3:-${service}-log}
79 [[ -z "${service}" ]] && die "no service given"
80
81 insopts -o root -g root -m 0755
82 diropts -o root -g root -m 0755
83
84 dodir ${SUPERVISE_DIR}/${service}{,/log}
85 fperms +t ${SUPERVISE_DIR}/${service}{,/log}
86
87 insinto ${SUPERVISE_DIR}/${service}
88 newins ${runfile} run
89
90 insinto ${SUPERVISE_DIR}/${service}/log
91 newins ${logfile} run
92 }
93
94 # @FUNCTION: qmail_set_cc
95 # @DESCRIPTION:
96 # The following commands patch the conf-{cc,ld} files to use the user's
97 # specified CFLAGS and LDFLAGS. These rather complex commands are needed
98 # because a user supplied patch might apply changes to these files, too.
99 # See bug #165981.
100 qmail_set_cc() {
101 cc=$(head -n 1 ./conf-cc | sed -e "s#^g\?cc\s\+\(-O2\)\?#$(tc-getCC) #")
102 ld=$(head -n 1 ./conf-ld | sed -e "s#^g\?cc\s\+\(-s\)\?#$(tc-getCC) #")
103
104 echo "${cc} ${CFLAGS}" > ./conf-cc || die 'Patching conf-cc failed.'
105 echo "${ld} ${LDFLAGS}" > ./conf-ld || die 'Patching conf-ld failed.'
106 }
107
108 # @FUNCTION: qmail_create_users
109 # @DESCRIPTION:
110 # Keep qmail groups in sync across ebuilds
111 qmail_create_groups() {
112 einfo "Creating qmail groups"
113 enewgroup nofiles 200
114 enewgroup qmail 201
115 }
116
117 # @FUNCTION: qmail_create_users
118 # @DESCRIPTION:
119 # Keep qmail users in sync across ebuilds
120 qmail_create_users() {
121 qmail_create_groups
122
123 einfo "Creating qmail users"
124 enewuser alias 200 -1 "${QMAIL_HOME}"/alias 200
125 enewuser qmaild 201 -1 "${QMAIL_HOME}" 200
126 enewuser qmaill 202 -1 "${QMAIL_HOME}" 200
127 enewuser qmailp 203 -1 "${QMAIL_HOME}" 200
128 enewuser qmailq 204 -1 "${QMAIL_HOME}" 201
129 enewuser qmailr 205 -1 "${QMAIL_HOME}" 201
130 enewuser qmails 206 -1 "${QMAIL_HOME}" 201
131 }
132
133 genqmail_src_unpack() {
134 cd "${WORKDIR}"
135 [[ -n ${GENQMAIL_PV} ]] && unpack "${GENQMAIL_F}"
136 }
137
138 qmail_spp_src_unpack() {
139 cd "${WORKDIR}"
140 [[ -n ${QMAIL_SPP_PV} ]] && unpack "${QMAIL_SPP_F}"
141 }
142
143 # @FUNCTION: qmail_src_postunpack
144 # @DESCRIPTION:
145 # Unpack common config files, apply custom patches if supplied and
146 # set built configuration (CFLAGS, LDFLAGS, etc)
147 qmail_src_postunpack() {
148 cd "${S}"
149
150 qmail_set_cc
151
152 mysplit=${QMAIL_CONF_SPLIT:-23}
153 is_prime ${mysplit} || die "QMAIL_CONF_SPLIT is not a prime number."
154 einfo "Using conf-split value of ${mysplit}."
155 echo -n ${mysplit} > "${S}"/conf-split
156 }
157
158 qmail_src_compile() {
159 cd "${S}"
160 emake it man "$@" || die "make failed"
161 }
162
163 qmail_spp_src_compile() {
164 cd "${GENQMAIL_S}"/spp/
165 emake || die "make spp failed"
166 }
167
168 qmail_base_install() {
169 einfo "Setting up basic directory hierarchy"
170 diropts -o root -g qmail -m 755
171 keepdir "${QMAIL_HOME}"/{,bin,control}
172
173 einfo "Installing basic qmail software"
174 insinto "${QMAIL_HOME}"/bin
175
176 insopts -o root -g qmail -m 755
177 doins datemail elq forward maildir2mbox maildirmake \
178 maildirwatch mailsubj pinq predate qail \
179 qmail-{inject,qmqpc,showctl} sendmail
180
181 einfo "Adding env.d entry for qmail"
182 doenvd "${GENQMAIL_S}"/conf/99qmail
183
184 declare -F qmail_base_install_hook >/dev/null && \
185 qmail_base_install_hook
186 }
187
188 qmail_full_install() {
189 einfo "Setting up full directory hierarchy"
190 keepdir "${QMAIL_HOME}"/users
191 diropts -o alias -g qmail -m 755
192 keepdir "${QMAIL_HOME}"/alias
193
194 einfo "Installing all qmail software"
195 insopts -o root -g qmail -m 755
196 doins bouncesaying condredirect config-fast except preline qbiff \
197 qmail-{pop3d,qmqpd,qmtpd,qread,qstat,smtpd,tcpok,tcpto} \
198 qreceipt qsmhook tcp-env
199
200 insopts -o root -g qmail -m 711
201 doins qmail-{clean,getpw,local,popup,pw2u,remote,rspawn,send} splogger
202
203 insopts -o root -g qmail -m 700
204 doins qmail-{lspawn,newmrh,newu,start}
205
206 insopts -o qmailq -g qmail -m 4711
207 doins qmail-queue
208
209 declare -F qmail_full_install_hook >/dev/null && \
210 qmail_full_install_hook
211 }
212
213 qmail_config_install() {
214 einfo "Installing stock configuration files"
215 insinto "${QMAIL_HOME}"/control
216 insopts -o root -g root -m 644
217 doins "${GENQMAIL_S}"/control/{conf-*,defaultdelivery}
218
219 einfo "Installing configuration sanity checker and launcher"
220 insinto "${QMAIL_HOME}"/bin
221 insopts -o root -g root -m 644
222 doins "${GENQMAIL_S}"/control/qmail-config-system
223
224 declare -F qmail_config_install_hook >/dev/null && \
225 qmail_config_install_hook
226 }
227
228 qmail_man_install() {
229 einfo "Installing manpages and documentation"
230
231 # those are tagged for section 8 but named for
232 # section 9 (which does not exist anyway)
233 for i in *.9; do
234 mv ${i} ${i/.9/.8}
235 done
236
237 into /usr
238 doman *.[1578]
239 dodoc BLURB* CHANGES FAQ INSTALL* PIC* README* REMOVE* SECURITY \
240 SENDMAIL SYSDEPS TEST* THANKS* THOUGHTS TODO* \
241 UPGRADE VERSION*
242
243 declare -F qmail_man_install_hook >/dev/null && \
244 qmail_man_install_hook
245 }
246
247 qmail_sendmail_install() {
248 einfo "Installing sendmail replacement"
249 diropts -m 755
250 dodir /usr/sbin /usr/lib
251
252 if use mailwrapper; then
253 insinto /etc/mail
254 doins "${GENQMAIL_S}"/conf/mailer.conf
255 else
256 dosym "${QMAIL_HOME}"/bin/sendmail /usr/sbin/sendmail
257 dosym "${QMAIL_HOME}"/bin/sendmail /usr/lib/sendmail
258 fi
259
260 declare -F qmail_sendmail_install_hook >/dev/null && \
261 qmail_sendmail_install_hook
262 }
263
264 qmail_maildir_install() {
265 # use the correct maildirmake
266 # the courier-imap one has some extensions that are nicer
267 MAILDIRMAKE="${D}${QMAIL_HOME}/bin/maildirmake"
268 [[ -e /usr/bin/maildirmake ]] && \
269 MAILDIRMAKE="/usr/bin/maildirmake"
270
271 einfo "Setting up the default aliases"
272 diropts -o alias -g qmail -m 700
273 "${MAILDIRMAKE}" "${D}${QMAIL_HOME}"/alias/.maildir
274 keepdir "${QMAIL_HOME}"/alias/.maildir/{cur,new,tmp}
275
276 for i in "${QMAIL_HOME}"/alias/.qmail-{mailer-daemon,postmaster,root}; do
277 if [[ ! -f "${ROOT}${i}" ]]; then
278 touch "${D}${i}"
279 fowners alias:qmail "${i}"
280 fi
281 done
282
283 einfo "Setting up default maildirs in the account skeleton"
284 diropts -o root -g root -m 755
285 insinto /etc/skel
286 insopts -o root -g root -m 644
287 newins "${GENQMAIL_S}"/control/defaultdelivery .qmail.sample
288 "${MAILDIRMAKE}" "${D}"/etc/skel/.maildir
289 keepdir /etc/skel/.maildir/{cur,new,tmp}
290
291 declare -F qmail_maildir_install_hook >/dev/null && \
292 qmail_maildir_install_hook
293 }
294
295 qmail_tcprules_install() {
296 dodir "${TCPRULES_DIR}"
297 insinto "${TCPRULES_DIR}"
298 insopts -o root -g root -m 0644
299 doins "${GENQMAIL_S}"/tcprules/Makefile.qmail
300 doins "${GENQMAIL_S}"/tcprules/tcp.qmail-*
301 use ssl || rm -f "${D}${TCPRULES_DIR}"/tcp.qmail-pop3sd
302 }
303
304 qmail_supervise_install() {
305 einfo "Installing supervise scripts"
306
307 cd "${GENQMAIL_S}"/supervise
308
309 for i in qmail-{send,smtpd,qmtpd,qmqpd,pop3d}; do
310 dosupervise ${i}
311 diropts -o qmaill -g root -m 755
312 keepdir /var/log/qmail/${i}
313 done
314
315 if use ssl; then
316 dosupervise qmail-pop3sd
317 diropts -o qmaill -g root -m 755
318 keepdir /var/log/qmail/qmail-pop3sd
319 fi
320
321 declare -F qmail_supervise_install_hook >/dev/null && \
322 qmail_supervise_install_hook
323 }
324
325 qmail_spp_install() {
326 einfo "Installing qmail-spp configuration files"
327 insinto "${QMAIL_HOME}"/control/
328 insopts -o root -g root -m 0644
329 doins "${GENQMAIL_S}"/spp/smtpplugins
330
331 einfo "Installing qmail-spp plugins"
332 keepdir "${QMAIL_HOME}"/plugins/
333 for i in authlog mfdnscheck ifauthnext tarpit; do
334 dospp "${GENQMAIL_S}"/spp/${i}
335 done
336
337 declare -F qmail_spp_install_hook >/dev/null && \
338 qmail_spp_install_hook
339 }
340
341 qmail_ssl_install() {
342 use gencertdaily && \
343 CRON_FOLDER=cron.daily || \
344 CRON_FOLDER=cron.hourly
345
346 einfo "Installing SSL Certificate creation script"
347 insinto "${QMAIL_HOME}"/control
348 insopts -o root -g root -m 0644
349 doins "${GENQMAIL_S}"/ssl/servercert.cnf
350
351 insinto "${QMAIL_HOME}"/bin
352 insopts -o root -g root -m 0755
353 doins "${GENQMAIL_S}"/ssl/mkservercert
354
355 einfo "Installing RSA key generation cronjob"
356 insinto /etc/${CRON_FOLDER}
357 insopts -o root -g root -m 0755
358 doins "${GENQMAIL_S}"/ssl/qmail-genrsacert.sh
359
360 keepdir "${QMAIL_HOME}"/control/tlshosts
361
362 declare -F qmail_ssl_install_hook >/dev/null && \
363 qmail_ssl_install_hook
364 }
365
366 qmail_src_install() {
367 qmail_base_install
368 qmail_full_install
369 qmail_config_install
370 qmail_man_install
371 qmail_sendmail_install
372 qmail_maildir_install
373 qmail_tcprules_install
374 qmail_supervise_install
375
376 use qmail-spp && qmail_spp_install
377 use ssl && qmail_ssl_install
378 }
379
380 qmail_queue_setup() {
381 if use highvolume; then
382 myconf="--bigtodo"
383 else
384 myconf="--no-bigtodo"
385 fi
386
387 mysplit=${QMAIL_CONF_SPLIT:-23}
388 is_prime ${mysplit} || die "QMAIL_CONF_SPLIT is not a prime number."
389
390 einfo "Setting up the message queue hierarchy"
391 /usr/bin/queue-repair.py --create ${myconf} \
392 --split ${mysplit} \
393 "${ROOT}${QMAIL_HOME}" >/dev/null || \
394 die 'queue-repair failed'
395 }
396
397 qmail_rootmail_fixup() {
398 local TMPCMD="ln -sf ${QMAIL_HOME}/alias/.maildir/ ${ROOT}/root/.maildir"
399
400 if [[ -d "${ROOT}"/root/.maildir && ! -L "${ROOT}"/root/.maildir ]] ; then
401 elog "Previously the qmail ebuilds created /root/.maildir/ but not"
402 elog "every mail was delivered there. If the directory does not"
403 elog "contain any mail, please delete it and run:"
404 elog "${TMPCMD}"
405 else
406 ${TMPCMD}
407 fi
408
409 chown -R alias:qmail "${ROOT}${QMAIL_HOME}"/alias/.maildir 2>/dev/null
410 }
411
412 qmail_tcprules_fixup() {
413 mkdir -p "${TCPRULES_DIR}"
414 for f in {smtp,qmtp,qmqp,pop3}{,.cdb}; do
415 old="/etc/tcp.${f}"
416 new="${TCPRULES_DIR}/tcp.qmail-${f}"
417 fail=0
418 if [[ -f "${old}" && ! -f "${new}" ]]; then
419 einfo "Moving ${old} to ${new}"
420 cp "${old}" "${new}" || fail=1
421 else
422 fail=1
423 fi
424 if [[ "${fail}" = 1 && -f "${old}" ]]; then
425 eerror "Error moving ${old} to ${new}, be sure to check the"
426 eerror "configuration! You may have already moved the files,"
427 eerror "in which case you can delete ${old}"
428 fi
429 done
430 }
431
432 qmail_tcprules_build() {
433 for f in tcp.qmail-{smtp,qmtp,qmqp,pop3,pop3s}; do
434 # please note that we don't check if it exists
435 # as we want it to make the cdb files anyway!
436 src="${ROOT}${TCPRULES_DIR}/${f}"
437 cdb="${ROOT}${TCPRULES_DIR}/${f}.cdb"
438 tmp="${ROOT}${TCPRULES_DIR}/.${f}.tmp"
439 [[ -e "${src}" ]] && tcprules "${cdb}" "${tmp}" < "${src}"
440 done
441 }
442
443 qmail_config_notice() {
444 elog
445 elog "To setup ${PN} to run out-of-the-box on your system, run:"
446 elog "emerge --config =${CATEGORY}/${PF}"
447 }
448
449 qmail_supervise_config_notice() {
450 elog
451 elog "To start qmail at boot you have to add svscan to your startup"
452 elog "and create the following links:"
453 elog "ln -s ${SUPERVISE_DIR}/qmail-send /service/qmail-send"
454 elog "ln -s ${SUPERVISE_DIR}/qmail-smtpd /service/qmail-smtpd"
455 elog
456 elog "To start the pop3 server as well, create the following link:"
457 elog "ln -s ${SUPERVISE_DIR}/qmail-pop3d /service/qmail-pop3d"
458 elog
459 if use ssl; then
460 elog "To start the pop3s server as well, create the following link:"
461 elog "ln -s ${SUPERVISE_DIR}/qmail-pop3sd /service/qmail-pop3sd"
462 elog
463 fi
464 elog "Additionally, the QMTP and QMQP protocols are supported, "
465 elog "and can be started as:"
466 elog "ln -s ${SUPERVISE_DIR}/qmail-qmtpd /service/qmail-qmtpd"
467 elog "ln -s ${SUPERVISE_DIR}/qmail-qmqpd /service/qmail-qmqpd"
468 elog
469 elog "Additionally, if you wish to run qmail right now, you should "
470 elog "run this before anything else:"
471 elog "source /etc/profile"
472 }
473
474 qmail_config_fast() {
475 if [[ ${ROOT} = / ]]; then
476 local host=$(hostname --fqdn)
477
478 if [[ -z "${host}" ]]; then
479 eerror
480 eerror "Cannot determine your fully-qualified hostname"
481 eerror "Please setup your /etc/hosts as described in"
482 eerror "http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=8#doc_chap2_sect4"
483 eerror
484 die "cannot determine FQDN"
485 fi
486
487 if [[ ! -f "${ROOT}${QMAIL_HOME}"/control/me ]]; then
488 "${ROOT}${QMAIL_HOME}"/bin/config-fast ${host}
489 fi
490 else
491 ewarn "Skipping some configuration as it MUST be run on the final host"
492 fi
493 }
494
495 qmail_tcprules_config() {
496 einfo "Accepting relaying by default from all ips configured on this machine."
497 LOCALIPS=$(/sbin/ifconfig | grep inet | cut -d' ' -f 12 -s | cut -b 6-20)
498 TCPSTRING=":allow,RELAYCLIENT=\"\",RBLSMTPD=\"\""
499 for ip in $LOCALIPS; do
500 myline="${ip}${TCPSTRING}"
501 for proto in smtp qmtp qmqp; do
502 f="${ROOT}${TCPRULES_DIR}/tcp.qmail-${proto}"
503 egrep -q "${myline}" "${f}" || echo "${myline}" >> "${f}"
504 done
505 done
506 }
507
508 qmail_ssl_generate() {
509 CRON_FOLDER=cron.hourly
510 use gencertdaily && CRON_FOLDER=cron.daily
511
512 ebegin "Generating RSA keys for SSL/TLS, this can take some time"
513 "${ROOT}"/etc/${CRON_FOLDER}/qmail-genrsacert.sh
514 eend $?
515
516 einfo "Creating a self-signed ssl-certificate:"
517 "${ROOT}${QMAIL_HOME}"/bin/mkservercert
518
519 einfo "If you want to have a properly signed certificate "
520 einfo "instead, do the following:"
521 # space at the end of the string because of the current implementation
522 # of einfo
523 einfo "openssl req -new -nodes -out req.pem \\ "
524 einfo " -config ${QMAIL_HOME}/control/servercert.cnf \\ "
525 einfo " -keyout ${QMAIL_HOME}/control/servercert.pem"
526 einfo "Send req.pem to your CA to obtain signed_req.pem, and do:"
527 einfo "cat signed_req.pem >> ${QMAIL_HOME}/control/servercert.pem"
528 }

  ViewVC Help
Powered by ViewVC 1.1.20