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

Contents of /eclass/qmail.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Sat Sep 15 16:16:53 2012 UTC (2 years, 3 months ago) by zmedico
Branch: MAIN
Changes since 1.6: +2 -3 lines
Remove redundant DESCRIPTION variable settings.

1 # Copyright 1999-2012 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.6 2012/01/08 03:38:03 vapier Exp $
4
5 # @ECLASS: qmail.eclass
6 # @MAINTAINER:
7 # qmail-bugs@gentoo.org
8 # @BLURB: common qmail functions
9
10 inherit flag-o-matic toolchain-funcs fixheadtails
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 local cc=$(head -n 1 ./conf-cc | sed -e "s#^g\?cc\s\+\(-O2\)\?#$(tc-getCC) #")
102 local ld=$(head -n 1 ./conf-ld | sed -e "s#^g\?cc\s\+\(-s\)\?#$(tc-getCC) #")
103
104 echo "${cc} ${CFLAGS} ${CPPFLAGS}" > ./conf-cc || die 'Patching conf-cc failed.'
105 echo "${ld} ${LDFLAGS}" > ./conf-ld || die 'Patching conf-ld failed.'
106 }
107
108 # @FUNCTION: qmail_create_groups
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 dosym "${QMAIL_HOME}"/bin/sendmail /usr/sbin/sendmail
253 dosym "${QMAIL_HOME}"/bin/sendmail /usr/lib/sendmail
254
255 declare -F qmail_sendmail_install_hook >/dev/null && \
256 qmail_sendmail_install_hook
257 }
258
259 qmail_maildir_install() {
260 # use the correct maildirmake
261 # the courier-imap one has some extensions that are nicer
262 MAILDIRMAKE="${D}${QMAIL_HOME}/bin/maildirmake"
263 [[ -e /usr/bin/maildirmake ]] && \
264 MAILDIRMAKE="/usr/bin/maildirmake"
265
266 einfo "Setting up the default aliases"
267 diropts -o alias -g qmail -m 700
268 "${MAILDIRMAKE}" "${D}${QMAIL_HOME}"/alias/.maildir
269 keepdir "${QMAIL_HOME}"/alias/.maildir/{cur,new,tmp}
270
271 for i in "${QMAIL_HOME}"/alias/.qmail-{mailer-daemon,postmaster,root}; do
272 if [[ ! -f "${ROOT}${i}" ]]; then
273 touch "${D}${i}"
274 fowners alias:qmail "${i}"
275 fi
276 done
277
278 einfo "Setting up default maildirs in the account skeleton"
279 diropts -o root -g root -m 755
280 insinto /etc/skel
281 insopts -o root -g root -m 644
282 newins "${GENQMAIL_S}"/control/defaultdelivery .qmail.sample
283 "${MAILDIRMAKE}" "${D}"/etc/skel/.maildir
284 keepdir /etc/skel/.maildir/{cur,new,tmp}
285
286 declare -F qmail_maildir_install_hook >/dev/null && \
287 qmail_maildir_install_hook
288 }
289
290 qmail_tcprules_install() {
291 dodir "${TCPRULES_DIR}"
292 insinto "${TCPRULES_DIR}"
293 insopts -o root -g root -m 0644
294 doins "${GENQMAIL_S}"/tcprules/Makefile.qmail
295 doins "${GENQMAIL_S}"/tcprules/tcp.qmail-*
296 use ssl || rm -f "${D}${TCPRULES_DIR}"/tcp.qmail-pop3sd
297 }
298
299 qmail_supervise_install() {
300 einfo "Installing supervise scripts"
301
302 cd "${GENQMAIL_S}"/supervise
303
304 for i in qmail-{send,smtpd,qmtpd,qmqpd,pop3d}; do
305 dosupervise ${i}
306 diropts -o qmaill -g root -m 755
307 keepdir /var/log/qmail/${i}
308 done
309
310 if use ssl; then
311 dosupervise qmail-pop3sd
312 diropts -o qmaill -g root -m 755
313 keepdir /var/log/qmail/qmail-pop3sd
314 fi
315
316 declare -F qmail_supervise_install_hook >/dev/null && \
317 qmail_supervise_install_hook
318 }
319
320 qmail_spp_install() {
321 einfo "Installing qmail-spp configuration files"
322 insinto "${QMAIL_HOME}"/control/
323 insopts -o root -g root -m 0644
324 doins "${GENQMAIL_S}"/spp/smtpplugins
325
326 einfo "Installing qmail-spp plugins"
327 keepdir "${QMAIL_HOME}"/plugins/
328 for i in authlog mfdnscheck ifauthnext tarpit; do
329 dospp "${GENQMAIL_S}"/spp/${i}
330 done
331
332 declare -F qmail_spp_install_hook >/dev/null && \
333 qmail_spp_install_hook
334 }
335
336 qmail_ssl_install() {
337 use gencertdaily && \
338 CRON_FOLDER=cron.daily || \
339 CRON_FOLDER=cron.hourly
340
341 einfo "Installing SSL Certificate creation script"
342 insinto "${QMAIL_HOME}"/control
343 insopts -o root -g root -m 0644
344 doins "${GENQMAIL_S}"/ssl/servercert.cnf
345
346 insinto "${QMAIL_HOME}"/bin
347 insopts -o root -g root -m 0755
348 doins "${GENQMAIL_S}"/ssl/mkservercert
349
350 einfo "Installing RSA key generation cronjob"
351 insinto /etc/${CRON_FOLDER}
352 insopts -o root -g root -m 0755
353 doins "${GENQMAIL_S}"/ssl/qmail-genrsacert.sh
354
355 keepdir "${QMAIL_HOME}"/control/tlshosts
356
357 declare -F qmail_ssl_install_hook >/dev/null && \
358 qmail_ssl_install_hook
359 }
360
361 qmail_src_install() {
362 qmail_base_install
363 qmail_full_install
364 qmail_config_install
365 qmail_man_install
366 qmail_sendmail_install
367 qmail_maildir_install
368 qmail_tcprules_install
369 qmail_supervise_install
370
371 use qmail-spp && qmail_spp_install
372 use ssl && qmail_ssl_install
373 }
374
375 qmail_queue_setup() {
376 if use highvolume; then
377 myconf="--bigtodo"
378 else
379 myconf="--no-bigtodo"
380 fi
381
382 mysplit=${QMAIL_CONF_SPLIT:-23}
383 is_prime ${mysplit} || die "QMAIL_CONF_SPLIT is not a prime number."
384
385 einfo "Setting up the message queue hierarchy"
386 /usr/bin/queue-repair.py --create ${myconf} \
387 --split ${mysplit} \
388 "${ROOT}${QMAIL_HOME}" >/dev/null || \
389 die 'queue-repair failed'
390 }
391
392 qmail_rootmail_fixup() {
393 local TMPCMD="ln -sf ${QMAIL_HOME}/alias/.maildir/ ${ROOT}/root/.maildir"
394
395 if [[ -d "${ROOT}"/root/.maildir && ! -L "${ROOT}"/root/.maildir ]] ; then
396 elog "Previously the qmail ebuilds created /root/.maildir/ but not"
397 elog "every mail was delivered there. If the directory does not"
398 elog "contain any mail, please delete it and run:"
399 elog "${TMPCMD}"
400 else
401 ${TMPCMD}
402 fi
403
404 chown -R alias:qmail "${ROOT}${QMAIL_HOME}"/alias/.maildir 2>/dev/null
405 }
406
407 qmail_tcprules_fixup() {
408 mkdir -p "${TCPRULES_DIR}"
409 for f in {smtp,qmtp,qmqp,pop3}{,.cdb}; do
410 old="/etc/tcp.${f}"
411 new="${TCPRULES_DIR}/tcp.qmail-${f}"
412 fail=0
413 if [[ -f "${old}" && ! -f "${new}" ]]; then
414 einfo "Moving ${old} to ${new}"
415 cp "${old}" "${new}" || fail=1
416 else
417 fail=1
418 fi
419 if [[ "${fail}" = 1 && -f "${old}" ]]; then
420 eerror "Error moving ${old} to ${new}, be sure to check the"
421 eerror "configuration! You may have already moved the files,"
422 eerror "in which case you can delete ${old}"
423 fi
424 done
425 }
426
427 qmail_tcprules_build() {
428 for f in tcp.qmail-{smtp,qmtp,qmqp,pop3,pop3s}; do
429 # please note that we don't check if it exists
430 # as we want it to make the cdb files anyway!
431 src="${ROOT}${TCPRULES_DIR}/${f}"
432 cdb="${ROOT}${TCPRULES_DIR}/${f}.cdb"
433 tmp="${ROOT}${TCPRULES_DIR}/.${f}.tmp"
434 [[ -e "${src}" ]] && tcprules "${cdb}" "${tmp}" < "${src}"
435 done
436 }
437
438 qmail_config_notice() {
439 elog
440 elog "To setup ${PN} to run out-of-the-box on your system, run:"
441 elog "emerge --config =${CATEGORY}/${PF}"
442 }
443
444 qmail_supervise_config_notice() {
445 elog
446 elog "To start qmail at boot you have to add svscan to your startup"
447 elog "and create the following links:"
448 elog "ln -s ${SUPERVISE_DIR}/qmail-send /service/qmail-send"
449 elog "ln -s ${SUPERVISE_DIR}/qmail-smtpd /service/qmail-smtpd"
450 elog
451 elog "To start the pop3 server as well, create the following link:"
452 elog "ln -s ${SUPERVISE_DIR}/qmail-pop3d /service/qmail-pop3d"
453 elog
454 if use ssl; then
455 elog "To start the pop3s server as well, create the following link:"
456 elog "ln -s ${SUPERVISE_DIR}/qmail-pop3sd /service/qmail-pop3sd"
457 elog
458 fi
459 elog "Additionally, the QMTP and QMQP protocols are supported, "
460 elog "and can be started as:"
461 elog "ln -s ${SUPERVISE_DIR}/qmail-qmtpd /service/qmail-qmtpd"
462 elog "ln -s ${SUPERVISE_DIR}/qmail-qmqpd /service/qmail-qmqpd"
463 elog
464 elog "Additionally, if you wish to run qmail right now, you should "
465 elog "run this before anything else:"
466 elog "source /etc/profile"
467 }
468
469 qmail_config_fast() {
470 if [[ ${ROOT} = / ]]; then
471 local host=$(hostname --fqdn)
472
473 if [[ -z "${host}" ]]; then
474 eerror
475 eerror "Cannot determine your fully-qualified hostname"
476 eerror "Please setup your /etc/hosts as described in"
477 eerror "http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=8#doc_chap2_sect4"
478 eerror
479 die "cannot determine FQDN"
480 fi
481
482 if [[ ! -f "${ROOT}${QMAIL_HOME}"/control/me ]]; then
483 "${ROOT}${QMAIL_HOME}"/bin/config-fast ${host}
484 fi
485 else
486 ewarn "Skipping some configuration as it MUST be run on the final host"
487 fi
488 }
489
490 qmail_tcprules_config() {
491 einfo "Accepting relaying by default from all ips configured on this machine."
492 LOCALIPS=$(/sbin/ifconfig | grep inet | cut -d' ' -f 12 -s | cut -b 6-20)
493 TCPSTRING=":allow,RELAYCLIENT=\"\",RBLSMTPD=\"\""
494 for ip in $LOCALIPS; do
495 myline="${ip}${TCPSTRING}"
496 for proto in smtp qmtp qmqp; do
497 f="${ROOT}${TCPRULES_DIR}/tcp.qmail-${proto}"
498 egrep -q "${myline}" "${f}" || echo "${myline}" >> "${f}"
499 done
500 done
501 }
502
503 qmail_ssl_generate() {
504 CRON_FOLDER=cron.hourly
505 use gencertdaily && CRON_FOLDER=cron.daily
506
507 ebegin "Generating RSA keys for SSL/TLS, this can take some time"
508 "${ROOT}"/etc/${CRON_FOLDER}/qmail-genrsacert.sh
509 eend $?
510
511 einfo "Creating a self-signed ssl-certificate:"
512 "${ROOT}${QMAIL_HOME}"/bin/mkservercert
513
514 einfo "If you want to have a properly signed certificate "
515 einfo "instead, do the following:"
516 # space at the end of the string because of the current implementation
517 # of einfo
518 einfo "openssl req -new -nodes -out req.pem \\ "
519 einfo " -config ${QMAIL_HOME}/control/servercert.cnf \\ "
520 einfo " -keyout ${QMAIL_HOME}/control/servercert.pem"
521 einfo "Send req.pem to your CA to obtain signed_req.pem, and do:"
522 einfo "cat signed_req.pem >> ${QMAIL_HOME}/control/servercert.pem"
523 }

  ViewVC Help
Powered by ViewVC 1.1.20