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

Contents of /eclass/qmail.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations) (download)
Sun Jan 8 03:38:03 2012 UTC (2 years, 6 months ago) by vapier
Branch: MAIN
Changes since 1.5: +4 -4 lines
respect CPPFLAGS, and mark cc/ld as local

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

  ViewVC Help
Powered by ViewVC 1.1.20