summaryrefslogtreecommitdiff
blob: 2f11b3a483933a6e504c5149cda91b03465a67ca (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

MY_P=kolabd-2.1-gentoo-20070510

DESCRIPTION="The kolab server"
HOMEPAGE="http://www.kolab.org"
SRC_URI="http://build.pardus.de/downloads/${MY_P}.tar.bz2"

SLOT="0"

LICENSE="GPL-2"
KEYWORDS="x86 amd64"
IUSE="horde spam webdav legacy"

DEPEND=""

RDEPEND="
>=net-libs/c-client-2004g-r1
>=dev-lang/php-5.2.6

>net-mail/cyrus-imapd-2.3.12
>net-mail/cyrus-imap-admin-2.3.12

>=app-antivirus/clamav-0.90
>=mail-mta/postfix-2.4.0
>=www-servers/apache-2.2.0
>=net-nds/openldap-2.3.35-r1

dev-perl/URI
dev-perl/perl-ldap
dev-perl/Net-Netmask
dev-perl/TermReadKey

mail-filter/spamassassin
mail-filter/amavisd-new
dev-libs/cyrus-sasl

legacy? (
net-ftp/proftpd
)

spam? (
mail-filter/dcc
mail-filter/razor
dev-python/pyzor
)

>=dev-perl/perl-kolab-2.1

net-mail/kolab-resource-handlers
net-mail/kolab-webadmin
"

S=${WORKDIR}/${MY_P}

detect_skiplist_db() {

	IMAPD_DB_FORMAT="none"

	if [ -f /var/imap/mailboxes.db ]; then
		if [ "`head -c 17 /var/imap/mailboxes.db | tail -c 13`" == "skiplist file" ]; then
			IMAPD_DB_FORMAT="skiplist"
		else
			IMAPD_DB_FORMAT="other"
		fi
	fi

	if [ "${IMAPD_DB_FORMAT}" == "skiplist" ]; then

		ewarn "Your cyrus-imapd databases are in the older \"skiplist\" format."
		ewarn "kolabd-20070216 changes to \"berkeley\" format and your databases"
		ewarn "must be converted! This ebuild will fail until you manually"
		ewarn "converted the files."
		ewarn
		ewarn "These are the necessary commands for the conversion:"
		ewarn
		ewarn "# Ensure that cyrus-imap is not running"
		ewarn "/etc/init.d/cyrus stop"
		ewarn "# Move the old databases away"
		ewarn "mv /var/imap/mailboxes.db /var/imap/mailboxes.db-skiplist"
		ewarn "mv /var/imap/annotations.db /var/imap/annotations.db-skiplist"
		ewarn "# Convert the databases"
		ewarn "/usr/lib/cyrus/cvt_cyrusdb /var/imap/mailboxes.db-skiplist skiplist /var/imap/mailboxes.db berkeley"
		ewarn "/usr/lib/cyrus/cvt_cyrusdb /var/imap/annotations.db-skiplist skiplist /var/imap/annotations.db berkeley"
		ewarn "chown -R cyrus:mail /var/imap/annotations.db /var/imap/mailboxes.db /var/imap/db"
		ewarn "# Emerge the new kolabd ebuild again"
		ewarn "emerge kolabd"
		ewarn "# Update the configuration"
		ewarn "kolabconf"
		ewarn "# Restart the cyrus-imapd server"
		ewarn "/etc/init.d/cyrus start"

		die

	elif [ "${IMAPD_DB_FORMAT}" == "other" ]; then

		einfo "Your cyrus-imapd databases do not seem to have the \"skiplist\""
		einfo "format. This ebuild will now assume they are in berkeley format"
		einfo "which is necessary for kolabd-20070216."

	fi
}

detect_apache_modules() {

	APACHE_MODULES="mod_authn_alias"

	APACHE_BUILTINS="/etc/apache2/apache2-builtin-mods"

	if [ -f "${APACHE_BUILTINS}" ]; then
		for MOD in ${APACHE_MODULES}
		do
			if [ "`grep $MOD ${APACHE_BUILTINS}`" == "" -o "`grep $MOD ${APACHE_BUILTINS} | grep disabled`" != "" ]; then

				ewarn "The module $MOD in your apache configuration file"
				ewarn "${APACHE_BUILTINS} has been set to \"disabled\"."
				ewarn "Please set it to \"shared\" and re-emerge apache."

				die
			else
				einfo "Apache module ${MOD} seems to be activated."
			fi
		done
	else
		einfo "There exists no /etc/apache2/apache2-builtin-mods. The"
		einfo "ebuild is unable to determine the modules build for your"
		einfo "Aapche. Assuming that everyting is okay."
	fi
}

detect_bad_clamav_log() {

	owner=`stat --printf="%U" /var/log/clamav/clamd.log`
	if [ "$owner" != "amavis" ]; then
		ewarn "/var/log/clamav/clamd.log is not owned by amavis!"
		ewarn "Restarting clamav may fail."
		ewarn "Please run"
		ewarn "chown amavis\\: /var/log/clamav/clamd.log"
	fi
}

add_user_to_group() {

	#############################################################
	# HACK:
	# I did not see any other ebuild that adds existing users
	# to new groups. So I'm not certain it is ok to handle it
	# like this since I need to disable the sandbox to access
	# the /etc/group file.
	# The given users need access to the ssl certificates which
	# is possible if they belong to kolab-r

	local oldsandbox=${SANDBOX_ON}
	export SANDBOX_ON="0"
	gpasswd -a $1 $2
	export SANDBOX_ON=${oldsandbox}
}

pkg_setup() {

	if ! built_with_use net-nds/openldap berkdb crypt overlays perl ssl ; then
	eerror "You MUST re-emerge openldap with berkdb, crypt,"
	eerror "overlays, perl and ssl enabled. Please add these use flags"
	eerror "to your USE variable and re-emerge openldap!"
	die "Current openldap installation does not support Kolabd!"
	fi

	if built_with_use net-nds/openldap minimal ; then
	eerror "You MUST re-emerge openldap without the"
	eerror "minimal use flag enabled. Please remove this use flags"
	eerror "from your USE variable and re-emerge openldap!"
	die "Current openldap installation does not support Kolabd!"
	fi

	if ! built_with_use dev-lang/php kolab ; then
	eerror "You MUST re-emerge php with the"
	eerror "kolab use flag enabled. Please add this use flags"
	eerror "to your USE variable and re-emerge php!"
	die "Current php installation does not support Kolabd!"
	fi

	if ! built_with_use dev-libs/cyrus-sasl ldap ssl; then
	eerror "You MUST re-emerge cyrus-sasl with ldap and ssl support."
	eerror "Please add the these use flags"
	eerror "to your USE variable and re-emerge cyrus-sasl!"
	die "Current cyrus-sasl installation does not support Kolabd!"
	fi

	if ! built_with_use mail-mta/postfix sasl ssl ldap ; then
	eerror "You MUST re-emerge postfix with ldap, sasl,"
	eerror "and ssl enabled. Please add these use flags"
	eerror "to your USE variable and re-emerge postfix!"
	die "Current postfix installation does not support Kolabd!"
	fi

	if ! built_with_use net-mail/cyrus-imapd kolab ssl ; then
	eerror "You MUST re-emerge cyrus-imapd with kolab"
	eerror "and ssl enabled. Please add both use flags"
	eerror "to your USE variable and re-emerge cyrus-imapd!"
	die "Current cyrus-imapd installation does not support Kolabd!"
	fi

	if ! built_with_use net-libs/c-client kolab; then
	eerror "You MUST re-emerge c-client with kolab"
	eerror "enabled. Please add the use flag"
	eerror "to your USE variable and re-emerge c-client!"
	die "Current cyrus-imapd installation does not support Kolabd!"
	fi

	if ! built_with_use www-servers/apache ssl ; then
	eerror "You MUST re-emerge apache with ssl support."
	eerror "Please add the ssl use flag"
	eerror "to your USE variable and re-emerge apache!"
	die "Current apache installation does not support Kolabd!"
	fi

	if use legacy ; then
		if ! built_with_use net-ftp/proftpd ssl ldap ; then
			eerror "You MUST re-emerge proftpd with ldap"
			eerror "and ssl enabled. Please add both use flags"
			eerror "to your USE variable and re-emerge proftpd!"
			die "Current proftpd installation does not support Kolabd!"
		fi
	fi

	# Perform some important sanity checks.
	detect_apache_modules
	detect_skiplist_db
	detect_bad_clamav_log

	# This needs to be in pkg_setup so that it will also be done
	# when using binary packages.

	add_user_to_group ldap kolab-r
	add_user_to_group cyrus kolab-r
	add_user_to_group postfix kolab-r
	add_user_to_group apache kolab-r
}

src_unpack() {

	unpack ${A} && cd "${S}"

	for PATCH in ${FILESDIR}/*-${PV}.patch
	do
		for USEFLAG in webdav horde spam
		do
			if [ -z "${PATCH/*-use-${USEFLAG}-${PV}.patch/}" ]; then
				use ${USEFLAG} && epatch ${PATCH} && PATCHED="${PATCHED} ${PATCH/-use-${USEFLAG}/}"
			fi
		done
	done

	for PATCH in ${FILESDIR}/*-${PV}.patch
	do
		patch=1
		for NP in ${PATCHED}
		do
			if [ "${NP}" == "${PATCH}" ]; then
				patch=0
			fi
		done
		if [ -n "${PATCH/*-use-*-${PV}.patch/}" ]; then
			if [ ${patch} -gt 0 ]; then
				epatch ${PATCH}
			fi
		fi
	done

}

src_compile() {

	local myconf
	myconf="${myconf} --with-dist=gentoo"
	myconf="${myconf} --libexecdir=/usr/lib"
	myconf="${myconf} --localstatedir=/var"

	econf ${myconf} || die
	emake || die
}

src_install() {
	make DESTDIR="${D}" install || die "Install failed"

	#############################################################
	# Remove httpd templates
	rm ${D}/etc/kolab/templates/httpd.*

	#############################################################
	# Add additional templates

	cd "${FILESDIR}"

	for TEMPLATE in *-${PV}.template
	do
		for USEFLAG in webdav horde spam
		do
			if [ -z "${TEMPLATE/*.use-${USEFLAG}-${PV}.template/}" ]; then
				if use ${USEFLAG}; then
					cp ${TEMPLATE} ${D}/etc/kolab/templates/${TEMPLATE/.use-${USEFLAG}-${PV}/} \
					&& TEMPLATED="${TEMPLATED} ${TEMPLATE/use-${USEFLAG}-/}"
				fi
			fi
		done
	done

	for TEMPLATE in *.${PV}.template
	do
		template=1
		for NP in ${TEMPLATED}
		do
			if [ "${NP}" == "${TEMPLATE}" ]; then
				template=0
			fi
		done
		if [ -n "${TEMPLATE/*.use-*-${PV}.template/}" ]; then
			if [ ${template} -gt 0 ]; then
				cp ${TEMPLATE} ${D}/etc/kolab/templates/${TEMPLATE/.${PV}/}
			fi
		fi
	done

	for POSTFIX in *.${PV}.postfix
	do
		mkdir -p ${D}/etc/postfix
		cp ${POSTFIX} ${D}/etc/postfix/${POSTFIX/.${PV}.postfix/}
	done

	cd "${S}"

	# Create original dist templates
	for TMPL in	${D}/etc/kolab/templates/*
	do
		cp $TMPL $TMPL.dist
	done

	#############################################################
	# Keep necessary directories

	VARDIRS=$(find ${D}/var -type d)
	for DIR in ${VARDIRS}
	do
		keepdir ${DIR/${D}/}
	done

	#############################################################
	# Provide basic web root

	mkdir -p ${D}/var/www/kolab/htdocs/server/services
	insinto /var/www/kolab/htdocs/server/
	insopts --mode=0644 --owner=root --group=root
	doins ${FILESDIR}/favicon.ico
	doins ${FILESDIR}/kolab_logo.small.png
	doins ${FILESDIR}/powered-by-gentoo.jpg
	doins ${FILESDIR}/index.php

	# now add the services to the service directory
	insinto /var/www/kolab/htdocs/server/services
	insopts --mode=0644 --owner=root --group=root
	doins ${FILESDIR}/admin.service

	if use horde ; then
		doins ${FILESDIR}/horde.service
	fi

	#############################################################
	# Fix permissions

	fowners apache:apache /var/cache/httpd_sessions

	fowners kolab:kolab /etc/kolab/kolab.globals

	insinto /etc/init.d
	insopts --mode=0755 --owner=root --group=root
	if use legacy ; then
		cp ${FILESDIR}/kolabd.legacy ${S}/kolabd
		doins ${S}/kolabd
	else
		doins ${FILESDIR}/kolabd
		rm ${D}/etc/kolab/templates/proftpd.conf.template*
	fi

	# FIXME
	# This is kolab-resource-handlers stuff. But I don't want to fix the
	# dependancies right now.
	keepdir /var/cache/freebusy/
	fowners apache:apache /var/cache/freebusy/

	keepdir /var/log/kolab/freebusy
	fowners apache:apache /var/log/kolab/freebusy

	keepdir /var/log/kolab/resmgr
	fowners kolab-n:kolab-n /var/log/kolab/resmgr

	keepdir /var/amavis/clamav
	fowners amavis:amavis /var/amavis/clamav
}


pkg_postinst() {

	echo
	ewarn "This new version changes the format of some central cyrus-imapd databases."
	ewarn "The ebuild tries to automatically detect any problems but please be aware"
	ewarn "that this may fail and you need to debug your cyrus-admin configuration!"
	echo
	ewarn "You need to execute "
	ewarn ""
	ewarn "/usr/share/${PN}/scripts/kolab_bootstrap -b"
	ewarn ""
	ewarn "to complete the kolab installation"
	echo

	if use horde; then
		echo
		ewarn "*** USE FLAG HORDE ***"
		ewarn
		ewarn "This use flag will install horde for use with kolab and"
		ewarn "in addition pathes the server for the horde installation."
		ewarn
		ewarn "Please note that the horde packages are NOT AT ALL in a "
		ewarn "stable state. Do not expect horde to work on your machine."
		echo
	fi

	if use spam; then
		echo
		ewarn "*** USE FLAG SPAM ***"
		ewarn
		ewarn "If you wish to register with razor so that you can also report spam,"
		ewarn "you can run"
		ewarn "mkdir -p /etc/mail/razor && chown amavis:amavis /etc/mail/razor"
		ewarn "su -s /bin/bash - amavis razor-admin -home=/etc/mail/razor -register my@mail.com"
		ewarn "su -s /bin/bash - amavis razor-admin -home=/etc/mail/razor -create"
		ewarn "Edit /etc/mail/razor/razor-agent.conf afterwards and link to the newly created identity"
		echo
	fi

}