1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit desktop libtool qmake-utils systemd user
11 DESCRIPTION="Featureful client/server network backup suite"
12 HOMEPAGE="https://www.bacula.org/"
13 SRC_URI="mirror://sourceforge/bacula/${MY_P}.tar.gz"
17 KEYWORDS="~amd64 ~ppc ~sparc ~x86"
18 IUSE="acl bacula-clientonly bacula-nodir bacula-nosd examples ipv6 libressl logwatch mysql postgres qt5 readline +sqlite ssl static tcpd vim-syntax X"
22 !bacula-nodir? ( virtual/mta )
23 postgres? ( dev-db/postgresql:=[threads] )
24 mysql? ( || ( dev-db/mysql-connector-c dev-db/mariadb-connector-c ) )
25 sqlite? ( dev-db/sqlite:3 )
32 logwatch? ( sys-apps/logwatch )
33 readline? ( sys-libs/readline:0 )
35 dev-libs/lzo[static-libs]
36 sys-libs/ncurses:=[static-libs]
37 sys-libs/zlib[static-libs]
38 acl? ( virtual/acl[static-libs] )
40 !libressl? ( dev-libs/openssl:0=[static-libs] )
41 libressl? ( dev-libs/libressl:0=[static-libs] )
50 !libressl? ( dev-libs/openssl:0= )
51 libressl? ( dev-libs/libressl:0= )
54 tcpd? ( >=sys-apps/tcp-wrappers-7.6 )
63 vim-syntax? ( || ( app-editors/vim app-editors/gvim ) )
67 !bacula-clientonly? ( ^^ ( mysql postgres sqlite ) )
68 static? ( bacula-clientonly )
74 #XOR and !bacula-clientonly controlled by REQUIRED_USE
75 use mysql && export mydbtype="mysql"
76 use postgres && export mydbtype="postgresql"
77 use sqlite && export mydbtype="sqlite3"
79 # create the daemon group and user
80 if [ -z "$(egetent group bacula 2>/dev/null)" ]; then
83 einfo "The group 'bacula' has been created. Any users you add to this"
84 einfo "group have access to files created by the daemons."
88 if use bacula-clientonly && use static && use qt5; then
90 ewarn "Building statically linked 'bat' is not supported. Ignorig 'qt5' useflag."
94 if ! use bacula-clientonly; then
95 if [ -z "$(egetent passwd bacula 2>/dev/null)" ]; then
96 enewuser bacula -1 -1 /var/lib/bacula bacula,disk,tape,cdrom,cdrw
98 einfo "The user 'bacula' has been created. Please see the bacula manual"
99 einfo "for information about running bacula as a non-root user."
106 # adjusts default configuration files for several binaries
107 # to /etc/bacula/<config> instead of ./<config>
108 pushd src >&/dev/null || die
109 for f in console/console.c dird/dird.c filed/filed.c \
110 stored/bcopy.c stored/bextract.c stored/bls.c \
111 stored/bscan.c stored/btape.c stored/stored.c \
112 qt-console/main.cpp; do
113 sed -i -e 's|^\(#define CONFIG_FILE "\)|\1/etc/bacula/|g' "${f}" \
114 || die "sed on ${f} failed"
116 popd >&/dev/null || die
118 # bug 466688 drop deprecated categories from Desktop file
119 sed -i -e 's/Application;//' scripts/bat.desktop.in || die
121 # bug 466690 Use CXXFLAGS instead of CFLAGS
122 sed -i -e 's/@CFLAGS@/@CXXFLAGS@/' autoconf/Make.common.in || die
124 # drop automatic install of unneeded documentation (for bug 356499)
125 eapply -p0 "${FILESDIR}"/7.2.0/${PN}-7.2.0-doc.patch
128 eapply "${FILESDIR}"/5.2.3/${PN}-5.2.3-as-needed.patch
131 eapply -p0 "${FILESDIR}"/9.0.2/${PN}-9.0.2-lib-search-path.patch
133 # bat needs to respect LDFLAGS and CFLAGS
134 eapply -p0 "${FILESDIR}"/9.0.6/${PN}-9.0.6-bat-pro.patch
137 eapply -p0 "${FILESDIR}"/5.2.3/${PN}-5.2.3-openssl-1.patch
139 eapply -p0 "${FILESDIR}"/9.0.8/${PN}-9.0.8-fix-static.patch
141 # fix soname in libbaccat.so bug #602952
142 eapply -p0 "${FILESDIR}/bacula-fix-sonames.patch"
144 # do not strip binaries
145 sed -i -e "s/strip /# strip /" src/filed/Makefile.in || die
146 sed -i -e "s/strip /# strip /" src/console/Makefile.in || die
148 # fix file not found error during make depend
149 eapply -p0 "${FILESDIR}"/7.0.2/${PN}-7.0.2-depend.patch
153 # Fix systemd unit files:
155 sed -i -e '/Requires/d' platforms/systemd/*.service.in || die
156 sed -i -e '/StandardOutput/d' platforms/systemd/*.service.in || die
158 sed -i -e '/Alias=bacula-dir/d' platforms/systemd/bacula-dir.service.in || die
159 # bug 584442 and 504368
160 sed -i -e 's/@dir_user@/root/g' platforms/systemd/bacula-dir.service.in || die
162 # build 'bat' for Qt5
163 export QMAKE="$(qt5_get_bindir)"/qmake
165 # adapt to >=Qt-5.9 (see bug #644566)
166 # qmake needs an existing target file to generate install instructions
167 sed -i -e 's#bins.files = bat#bins.files = .libs/bat#g' \
168 src/qt-console/bat.pro.in || die
169 mkdir src/qt-console/.libs || die
170 touch src/qt-console/.libs/bat || die
171 chmod 755 src/qt-console/.libs/bat || die
173 # fix wrong handling of libressl version
174 # needs separate handling for <libressl-2.7 and >=libressl2.7
176 if has_version "<dev-libs/libressl-2.7"; then
177 eapply -p0 "${FILESDIR}"/9.0.6/${PN}-9.0.6-libressl26.patch
179 eapply -p0 "${FILESDIR}"/9.0.6/${PN}-9.0.6-libressl27.patch
182 # Don't let program instal man pages directly
183 rm "${S}"/manpages/Makefile.in || die "Unable to remove man pages Makefile.in"
184 eapply -p1 "${FILESDIR}/bacula-fix-manpages.patch"
186 # fix bundled libtool (bug 466696)
187 # But first move directory with M4 macros out of the way.
188 # It is only needed by autoconf and gives errors during elibtoolize.
189 mv autoconf/libtool autoconf/libtool1 || die
196 if use bacula-clientonly; then
198 $(use_enable bacula-clientonly client-only) \
199 $(use_enable !static libtool) \
200 $(use_enable static static-cons) \
201 $(use_enable static static-fd)"
204 $(use_enable !bacula-nodir build-dird) \
205 $(use_enable !bacula-nosd build-stored)"
207 # database support needed by dir-only *and* sd-only
208 # build as well (for building bscan, btape, etc.)
213 --disable-batch-insert"
216 --enable-batch-insert"
220 # do not build bat if 'static' clientonly
221 if ! use bacula-clientonly || ! use static; then
223 $(use_enable qt5 bat)"
228 $(use_enable !readline conio) \
229 $(use_enable readline) \
230 $(use_with readline readline /usr) \
231 $(use_with ssl openssl) \
234 $(use_with tcpd tcp-wrappers)"
237 --libdir=/usr/$(get_libdir) \
238 --docdir=/usr/share/doc/${PF} \
239 --htmldir=/usr/share/doc/${PF}/html \
240 --with-pid-dir=/var/run \
241 --sysconfdir=/etc/bacula \
242 --with-archivedir=/var/lib/bacula/tmp \
243 --with-subsys-dir=/var/lock/subsys \
244 --with-working-dir=/var/lib/bacula \
245 --with-logdir=/var/lib/bacula \
246 --with-scriptdir=/usr/libexec/bacula \
247 --with-systemd=$(systemd_get_systemunitdir) \
248 --with-dir-user=bacula \
249 --with-dir-group=bacula \
250 --with-sd-user=root \
251 --with-sd-group=bacula \
252 --with-fd-user=root \
253 --with-fd-group=bacula \
254 --enable-smartalloc \
261 # Make build log verbose (bug #447806)
266 emake DESTDIR="${D}" install
267 doicon scripts/bacula.png
269 # install bat icon and desktop file when enabled
270 # (for some reason ./configure doesn't pick this up)
271 if use qt5 && ! use static ; then
272 doicon src/qt-console/images/bat_icon.png
273 domenu scripts/bat.desktop
276 # remove some scripts we don't need at all
277 rm -f "${D}"/usr/libexec/bacula/{bacula,bacula-ctl-dir,bacula-ctl-fd,bacula-ctl-sd,startmysql,stopmysql}
279 # rename statically linked apps
280 if use bacula-clientonly && use static ; then
281 pushd "${D}"/usr/sbin || die
282 mv static-bacula-fd bacula-fd || die
283 mv static-bconsole bconsole || die
287 # extra files which 'make install' doesn't cover
288 if ! use bacula-clientonly; then
289 # the database update scripts
291 insinto /usr/libexec/bacula/updatedb
293 doins "${S}"/updatedb/*
294 fperms 0640 /usr/libexec/bacula/updatedb/README
296 # the logrotate configuration
297 # (now unconditional wrt bug #258187)
299 insinto /etc/logrotate.d
301 newins "${S}"/scripts/logrotate bacula
303 # the logwatch scripts
304 if use logwatch; then
306 dodir /usr/share/logwatch/scripts/services
307 dodir /usr/share/logwatch/scripts/shared
308 dodir /etc/logwatch/conf/logfiles
309 dodir /etc/logwatch/conf/services
310 pushd "${S}"/scripts/logwatch >&/dev/null || die
311 emake DESTDIR="${D}" install
312 popd >&/dev/null || die
317 rm -vf "${D}"/usr/share/man/man1/bat.1*
319 rm -vf "${D}"/usr/share/man/man1/bacula-tray-monitor.1*
321 if use bacula-clientonly || use bacula-nodir ; then
322 rm -vf "${D}"/usr/libexec/bacula/create_*_database
323 rm -vf "${D}"/usr/libexec/bacula/drop_*_database
324 rm -vf "${D}"/usr/libexec/bacula/make_*_tables
325 rm -vf "${D}"/usr/libexec/bacula/update_*_tables
326 rm -vf "${D}"/usr/libexec/bacula/drop_*_tables
327 rm -vf "${D}"/usr/libexec/bacula/grant_*_privileges
328 rm -vf "${D}"/usr/libexec/bacula/*_catalog_backup
330 if use bacula-clientonly || use bacula-nosd; then
331 rm -vf "${D}"/usr/libexec/bacula/disk-changer
332 rm -vf "${D}"/usr/libexec/bacula/mtx-changer
333 rm -vf "${D}"/usr/libexec/bacula/dvd-handler
337 dodoc ChangeLog ReleaseNotes SUPPORT
339 # Install all man pages
340 doman "${S}"/manpages/*
342 # install examples (bug #457504)
343 if use examples; then
349 if use vim-syntax; then
350 insinto /usr/share/vim/vimfiles/syntax
351 doins scripts/bacula.vim
352 insinto /usr/share/vim/vimfiles/ftdetect
353 newins scripts/filetype.vim bacula_ft.vim
357 myscripts="bacula-fd"
358 if ! use bacula-clientonly; then
359 if ! use bacula-nodir; then
360 myscripts="${myscripts} bacula-dir"
362 if ! use bacula-nosd; then
363 myscripts="${myscripts} bacula-sd"
366 for script in ${myscripts}; do
367 # copy over init script and config to a temporary location
368 # so we can modify them as needed
369 cp "${FILESDIR}/${script}".confd "${T}/${script}".confd || die "failed to copy ${script}.confd"
370 cp "${FILESDIR}/newscripts/${script}".initd "${T}/${script}".initd || die "failed to copy ${script}.initd"
372 # now set the database dependancy for the director init script
375 case "${mydbtype}" in
377 # sqlite databases don't have a daemon
378 sed -i -e 's/need "%database%"/:/g' "${T}/${script}".initd || die
381 # all other databases have daemons
382 sed -i -e "s:%database%:${mydbtype}:" "${T}/${script}".initd || die
390 # install init script and config
391 newinitd "${T}/${script}".initd "${script}"
392 newconfd "${T}/${script}".confd "${script}"
395 systemd_dounit "${S}"/platforms/systemd/bacula-{dir,fd,sd}.service
397 # make sure the working directory exists
399 keepdir /var/lib/bacula
401 # make sure bacula group can execute bacula libexec scripts
402 fowners -R root:bacula /usr/libexec/bacula
406 if use bacula-clientonly; then
407 fowners root:bacula /var/lib/bacula
409 fowners bacula:bacula /var/lib/bacula
412 if ! use bacula-clientonly && ! use bacula-nodir; then
414 einfo "If this is a new install, you must create the ${mydbtype} databases with:"
415 einfo " /usr/libexec/bacula/create_${mydbtype}_database"
416 einfo " /usr/libexec/bacula/make_${mydbtype}_tables"
417 einfo " /usr/libexec/bacula/grant_${mydbtype}_privileges"
421 ewarn "The format of the database may have changed."
422 ewarn "If you just upgraded from a version below 9.0.0 you must run"
423 ewarn "'update_bacula_tables' now."
424 ewarn "Make sure to have a backup of your catalog before."
430 einfo "Be aware that Bacula does not officially support SQLite database anymore."
431 einfo "Best use it only for a client-only installation. See Bug #445540."
435 einfo "Please note that 'bconsole' will always be installed. To compile 'bat'"
436 einfo "you have to enable 'USE=qt5'."
438 einfo "/var/lib/bacula/tmp was configured for archivedir. This dir will be used during"
439 einfo "restores, so be sure to set it to an appropriate in dir in the bacula config."