summaryrefslogtreecommitdiff
blob: 8086a730393e41a12ac15ac9d27e462d7a448b24 (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
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/app-backup/bacula/bacula-1.36.3.ebuild,v 1.1 2005/07/04 01:52:06 robbat2 Exp $

inherit eutils

DESCRIPTION="featureful client/server network backup suite"
HOMEPAGE="http://www.bacula.org/"
SRC_URI="mirror://sourceforge/bacula/${P}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~ppc ~sparc ~x86"
IUSE="bacula-clientonly bacula-console bacula-split doc gnome logrotate logwatch mysql postgres readline sqlite static tcpd wxwindows X"

#theres a local sqlite use flag. use it -OR- mysql, not both.
#mysql is the reccomended choice ...
#may need sys-libs/libtermcap-compat but try without first
DEPEND="
	>=sys-libs/zlib-1.1.4
	dev-libs/gmp
	!bacula-clientonly? (
		mysql? ( >=dev-db/mysql-3.23 )
		postgres? ( >=dev-db/postgresql-7.4.0 )
		sqlite? ( =dev-db/sqlite-2* )
		!mysql? ( !postgres? ( !sqlite? ( >=dev-db/mysql-3.23 ) ) )
		virtual/mta
	)
	bacula-console? (
		X? ( virtual/x11 )
		wxwindows? ( >=x11-libs/wxGTK-2.4.2 )
		gnome? ( gnome-base/libgnome )
		gnome? ( app-admin/gnomesu )
	)
	doc? (
		app-text/tetex
		dev-tex/latex2html
	)
	logrotate? ( app-admin/logrotate )
	logwatch? ( sys-apps/logwatch )
	tcpd? ( >=sys-apps/tcp-wrappers-7.6 )
	readline? ( >=sys-libs/readline-4.1 )"
RDEPEND="${DEPEND}
	!bacula-clientonly? (
		sys-block/mtx
		app-arch/mt-st
	)"

pkg_setup() {
	if ( use mysql || use postgres ) && [ -z ${BACULA_DB_USER} ] && [ -z ${BACULA_DB_PASSWORD} ] && [ -z ${BACULA_DB_HOST} ]; then
		# Display warning about DB query environment variables
		einfo
		einfo "If you are upgrading or rebuilding your bacula installation and"
		einfo "your database requires you to specify user, password, or host"
		einfo "you may do so with the environment variables BACULA_DB_USER,"
		einfo "BACULA_DB_PASSWORD, and BACULA_DB_HOST respectively."
		einfo
		einfo "For example:"
		einfo "# export BACULA_DB_USER=\"bacula\""
		einfo "# export BACULA_DB_PASSWORD=\"mydbpassword\""
		einfo "# export BACULA_DB_HOST=\"mydbhost.mydomain.net\""
		einfo "# emerge bacula"
		einfo
		einfo "If you require these variables and have not set them yet, you"
		einfo "may wish to abort now and do so.  If this is a new installation"
		einfo "of bacula, this should not affect you."
		einfo

		ebeep 3
		ewarn "Press Ctrl-C to abort.  Merge will resume in 10 seconds."
		epause 10
	fi
}

src_unpack() {
	unpack ${P}.tar.gz
	cd ${S}
	# this resolves bacula bug #181
	epatch ${FILESDIR}/${PN}-1.36.2-cdrecord-configure.patch
	# fixes lack of depend() in split init scripts
	epatch ${FILESDIR}/${PN}-1.36.3-init-depends.patch
	# adds build/install capability to ${S}/rescue/linux/Makefile.in
	epatch ${FILESDIR}/${PN}-1.36.3-rescue-makefile.patch
	cd ${S}
}

src_compile() {
	local myconf=""
	if use bacula-clientonly ; then
		myconf="${myconf}
			`use_enable bacula-clientonly client-only`
			`use_enable static static-fd`"
	fi
	if use bacula-console ; then
		myconf="${myconf}
			`use_enable X x`
			`use_enable gnome tray-monitor`
			`use_enable wxwindows wx-console`
			`use_enable static static-cons`"
	fi
	myconf="${myconf}
		`use_enable readline`
		`use_enable tcpd tcp-wrappers`"

	# select database support
	if ! use bacula-clientonly; then
		if ! use mysql && ! use postgres && ! use sqlite ; then
			ewarn "No database enabled in USE."
			ewarn "Using mysql database support by default."
			myconf="${myconf}
				`use_with mysql`"
		elif use mysql ; then
			if use postgres ; then
				ewarn "Multiple databases enabled in USE."
				ewarn "Using mysql database support by default."
			elif use sqlite ; then
				ewarn "Multiple databases enabled in USE."
				ewarn "Using mysql database support by default."
			fi
			myconf="${myconf}
				`use_with mysql`"
		elif use postgres ; then
			if use sqlite ; then
				ewarn "Multiple databases enabled in USE."
				ewarn "Using postgresql database support by default."
			fi
			myconf="${myconf}
				`use_with postgres postgresql`"
		else
			myconf="${myconf}
				`use_with sqlite`"
		fi
	fi
	if ! use bacula-clientonly; then
		if use static ; then
			myconf="${myconf}
				`use_enable static static-tools`
				`use_enable static static-fd`
				`use_enable static static-sd`
				`use_enable static static-dir`"
		fi
	fi

	./configure \
		--prefix=/usr \
		--enable-smartalloc \
		--mandir=/usr/share/man \
		--with-pid-dir=/var/run \
		--sysconfdir=/etc/bacula \
		--infodir=/usr/share/info \
		--with-subsys-dir=/var/lock/subsys \
		--with-working-dir=/var/bacula \
		--with-scriptdir=/etc/bacula \
		--with-dir-user=root \
		--with-dir-group=bacula \
		--with-sd-user=root \
		--with-sd-group=bacula \
		--with-fd-user=root \
		--with-fd-group=bacula \
		--host=${CHOST} ${myconf} || die "Configure failed!"

	emake || die "Failed primary build!"

	if use doc ; then
		# make the docs
		cd ${S}/doc/latex && emake || die "Failed to build tetx docs!" && cd ${S}
	fi
}

src_install() {
	emake DESTDIR=${D} install || die "Failed install to ${D} !"

	if use gnome ; then
		dodir /usr/bin
		emake DESTDIR=${D} \
			install-menu \
			install-menu-xsu \
			install-menu-consolehelper || die "Failed to install gnome menu files to ${D} !"

		#chmod 755 ${D}/usr/sbin/bacula-tray-monitor
		#chmod 644 ${D}/etc/bacula/tray-monitor.conf
	fi
	if ! use bacula-clientonly ; then
		# the database update scripts
		mkdir -p ${D}/etc/bacula/updatedb
		cp ${S}/updatedb/* ${D}/etc/bacula/updatedb/
		chmod 754 ${D}/etc/bacula/updatedb/*

		# the logrotate configuration
		if use logrotate ; then
			mkdir -p ${D}/etc/logrotate.d
			cp ${S}/scripts/logrotate ${D}/etc/logrotate.d/bacula
			chmod 644 ${D}/etc/logrotate.d/bacula
		fi

		# the logwatch scripts
		if use logwatch ; then
			cd ${S}/scripts/logwatch
			emake DESTDIR=${D} install || die "Failed to install logwatch scripts to ${D} !"
			cd ${S}
		fi
	fi
	# documentation
	for a in ${S}/{Changelog,LICENSE,README,ReleaseNotes,kernstodo,doc/BaculaRoadMap_*.pdf}
	do
		dodoc ${a}
	done
	# clean up permissions left broken by install
	chown -R root:root ${D}/usr/share/doc/${PF}
	chmod -R 644 ${D}/usr/share/doc/${PF}/*
	chmod o-r ${D}/etc/bacula/query.sql
	# remove the working dir so we can add it postinst with group
	rmdir ${D}/var/bacula

	exeinto ${S}/etc/init.d
	if use bacula-clientonly ; then
		newexe ${S}/platforms/gentoo/bacula-fd bacula-fd
	else
		if use bacula-split ; then
			newexe ${S}/platforms/gentoo/bacula-fd bacula-fd
			newexe ${S}/platforms/gentoo/bacula-sd bacula-sd
			newexe ${S}/platforms/gentoo/bacula-dir bacula-dir
		else
			newexe ${S}/platforms/gentoo/bacula-init bacula
		fi
	fi
}

pkg_postinst() {
	# create the daemon group
	HAVE_BACULA=`cat /etc/group | grep bacula 2>/dev/null`
	if [ -z ${HAVE_BACULA} ]; then
		enewgroup bacula
		einfo "The group bacula has been created. Any users you add to"
		einfo "this group have access to files created by the daemons."
		# the working directory
		install -m0750 -o root -g bacula -d ${ROOT}/var/bacula
	fi

	einfo
	einfo "The CD-ROM rescue disk package has been installed into the"
	einfo "/etc/bacula/rescue/cdrom/ directory. Please examine the manual"
	einfo "for information on creating a rescue CD."
	einfo

	if ! use bacula-clientonly ; then
		# test for an existing database
		if use mysql ; then
			mydb="mysql"
		elif use postgres ; then
			mydb="postgresql"
		elif use sqlite ; then
			mydb="sqlite"
		else
			mydb="mysql"
		fi

		if [ ${mydb} == "sqlite" ]; then
			DB_VER=`echo "select * from Version;" | sqlite /var/bacula/bacula.db | tail -n 1 2>/dev/null`
		else
			if [ -z ${BACULA_DB_USER} ] && [ -z ${BACULA_DB_PASSWORD} ] && [ -z ${BACULA_DB_HOST} ]; then
				if [ ${mydb} == "mysql" ]; then
					DB_VER=`mysql bacula -e 'select * from Version;' | tail -n 1 2>/dev/null`
				elif [ ${mydb} == "postgresql" ]; then
					DB_VER=`echo 'select * from Version;' | psql bacula | tail -3 | head -n 1 2>/dev/null`
				fi
			else
				BACULA_DB_OPTS=""
				if [ ${mydb} == "mysql" ]; then
					if [ ! -z ${BACULA_DB_HOST} ]; then
						BACULA_DB_OPTS="${BACULA_DB_OPTS} --host=${BACULA_DB_HOST}"
					fi
					if [ ! -z ${BACULA_DB_USER} ]; then
						BACULA_DB_OPTS="${BACULA_DB_OPTS} --user=${BACULA_DB_USER}"
					fi
					if [ ! -z ${BACULA_DB_PASSWORD} ]; then
						BACULA_DB_OPTS="${BACULA_DB_OPTS} --password=${BACULA_DB_PASSWORD}"
					fi
					DB_VER=`mysql ${BACULA_DB_OPTS} -e 'select * from Version' bacula | tail -n 1 2>/dev/null`
				elif [ ${mydb} == "postgresql" ]; then
					if [ ! -z ${BACULA_DB_HOST} ]; then
						BACULA_DB_OPTS="${BACULA_DB_OPTS} --host ${BACULA_DB_HOST}"
					fi
					if [ ! -z ${BACULA_DB_USER} ]; then
						BACULA_DB_OPTS="${BACULA_DB_OPTS} --username ${BACULA_DB_USER}"
					fi
					# psql prompts for password by default but we can force it.
					# psql(1) does not seem to support --password=somepass
					# NOTE: this is untested
					if [ ! -z ${BACULA_DB_PASSWORD} ]; then
						BACULA_DB_OPTS="${BACULA_DB_OPTS} --password"
					fi
					DB_VER=`echo 'select * from Version;' | psql ${BACULA_DB_OPTS} bacula | tail -3 | head -n 1 2>/dev/null`
				fi
			fi
		fi
		if [ -z "${DB_VER}" ]; then
			einfo "This appears to be a new install and you plan to use ${mydb}"
			einfo "for your catalog database. You should now create it with the"
			einfo "following commands:"
			einfo " sh /etc/bacula/grant_${mydb}_privileges"
			einfo " sh /etc/bacula/create_${mydb}_database"
			einfo " sh /etc/bacula/make_${mydb}_tables"
		elif [ "${DB_VER}" -lt "8" ]; then
			einfo "This release requires an upgrade to your bacula database"
			einfo "as the database format has changed.  Please read the"
			einfo "manual chapter for upgrading your database!"
		fi
	fi

	einfo
	einfo "Configuration files are installed in /etc/bacula and"
	einfo "init script(s) are:"
	if use bacula-clientonly ; then
		einfo " /etc/init.d/bacula-fd"
	else
		if use bacula-split ; then
			einfo " /etc/init.d/bacula-sd"
			einfo " /etc/init.d/bacula-dir"
			einfo " /etc/init.d/bacula-fd"
			einfo " or /etc/bacula/bacula will start all three."
		else
			einfo " /etc/init.d/bacula"
		fi
	fi
	einfo
}