0d8fb9502665f5e2aadb3cb83fafee757a4bd3c4
[gentoo.git] / app-backup / bacula / bacula-9.4.3-r1.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit desktop libtool qmake-utils systemd user
7
8 MY_PV=${PV/_beta/-b}
9 MY_P=${PN}-${MY_PV}
10
11 DESCRIPTION="Featureful client/server network backup suite"
12 HOMEPAGE="https://www.bacula.org/"
13 SRC_URI="mirror://sourceforge/bacula/${MY_P}.tar.gz"
14
15 LICENSE="AGPL-3"
16 SLOT="0"
17 KEYWORDS="~amd64 ~ppc ~sparc ~x86"
18 IUSE="acl bacula-clientonly bacula-nodir bacula-nosd +batch-insert examples ipv6 libressl logwatch mysql postgres qt5 readline +sqlite ssl static tcpd vim-syntax X"
19
20 DEPEND="
21         !bacula-clientonly? (
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 )
26         )
27         dev-libs/gmp:0
28         qt5? (
29                 dev-qt/qtcore:5
30                 dev-qt/qtgui:5
31                 dev-qt/qtwidgets:5
32                 dev-qt/qtsvg:5
33                 x11-libs/qwt:6
34         )
35         logwatch? ( sys-apps/logwatch )
36         readline? ( sys-libs/readline:0 )
37         static? (
38                 dev-libs/lzo[static-libs]
39                 sys-libs/ncurses:=[static-libs]
40                 sys-libs/zlib[static-libs]
41                 acl? ( virtual/acl[static-libs] )
42                 ssl? (
43                         !libressl? ( dev-libs/openssl:0=[static-libs] )
44                         libressl? ( dev-libs/libressl:0=[static-libs] )
45                 )
46         )
47         !static? (
48                 dev-libs/lzo
49                 sys-libs/ncurses:=
50                 sys-libs/zlib
51                 acl? ( virtual/acl )
52                 ssl? (
53                         !libressl? ( dev-libs/openssl:0= )
54                         libressl? ( dev-libs/libressl:0= )
55                 )
56         )
57         tcpd? ( >=sys-apps/tcp-wrappers-7.6 )
58 "
59 RDEPEND="${DEPEND}
60         !bacula-clientonly? (
61                 !bacula-nosd? (
62                         app-arch/mt-st
63                         sys-block/mtx
64                 )
65         )
66         vim-syntax? ( || ( app-editors/vim app-editors/gvim ) )
67 "
68
69 REQUIRED_USE="
70         !bacula-clientonly? ( ^^ ( mysql postgres sqlite ) )
71         static? ( bacula-clientonly )
72 "
73
74 S=${WORKDIR}/${MY_P}
75
76 pkg_setup() {
77         #XOR and !bacula-clientonly controlled by REQUIRED_USE
78         use mysql && export mydbtype="mysql"
79         use postgres && export mydbtype="postgresql"
80         use sqlite && export mydbtype="sqlite3"
81
82         # create the daemon group and user
83         if [ -z "$(egetent group bacula 2>/dev/null)" ]; then
84                 enewgroup bacula
85                 einfo
86                 einfo "The group 'bacula' has been created. Any users you add to this"
87                 einfo "group have access to files created by the daemons."
88                 einfo
89         fi
90
91         if use bacula-clientonly && use static && use qt5; then
92                 ewarn
93                 ewarn "Building statically linked 'bat' is not supported. Ignorig 'qt5' useflag."
94                 ewarn
95         fi
96
97         if ! use bacula-clientonly; then
98                 if [ -z "$(egetent passwd bacula 2>/dev/null)" ]; then
99                         enewuser bacula -1 -1 /var/lib/bacula bacula,disk,tape,cdrom,cdrw
100                         einfo
101                         einfo "The user 'bacula' has been created.  Please see the bacula manual"
102                         einfo "for information about running bacula as a non-root user."
103                         einfo
104                 fi
105         fi
106 }
107
108 src_prepare() {
109         # adjusts default configuration files for several binaries
110         # to /etc/bacula/<config> instead of ./<config>
111         pushd src >&/dev/null || die
112         for f in console/console.c dird/dird.c filed/filed.c \
113                 stored/bcopy.c stored/bextract.c stored/bls.c \
114                 stored/bscan.c stored/btape.c stored/stored.c \
115                 qt-console/main.cpp; do
116                 sed -i -e 's|^\(#define CONFIG_FILE "\)|\1/etc/bacula/|g' "${f}" \
117                         || die "sed on ${f} failed"
118         done
119         popd >&/dev/null || die
120
121         # bug 466688 drop deprecated categories from Desktop file
122         sed -i -e 's/Application;//' scripts/bat.desktop.in || die
123
124         # bug 466690 Use CXXFLAGS instead of CFLAGS
125         sed -i -e 's/@CFLAGS@/@CXXFLAGS@/' autoconf/Make.common.in || die
126
127         # drop automatic install of unneeded documentation (for bug 356499)
128         eapply -p0 "${FILESDIR}"/7.2.0/${PN}-7.2.0-doc.patch
129
130         # bug #310087
131         eapply "${FILESDIR}"/5.2.3/${PN}-5.2.3-as-needed.patch
132
133         # bug #311161
134         eapply -p0 "${FILESDIR}"/9.0.2/${PN}-9.0.2-lib-search-path.patch
135
136         # bat needs to respect LDFLAGS and CFLAGS
137         eapply -p0 "${FILESDIR}"/9.0.6/${PN}-9.0.6-bat-pro.patch
138
139         # bug #328701
140         eapply -p0 "${FILESDIR}"/5.2.3/${PN}-5.2.3-openssl-1.patch
141
142         eapply -p0 "${FILESDIR}"/9.0.8/${PN}-9.0.8-fix-static.patch
143
144         # fix soname in libbaccat.so bug #602952
145         eapply -p0 "${FILESDIR}/bacula-fix-sonames.patch"
146
147         # do not strip binaries
148         sed -i -e "s/strip /# strip /" src/filed/Makefile.in || die
149         sed -i -e "s/strip /# strip /" src/console/Makefile.in || die
150
151         # fix file not found error during make depend
152         eapply -p0 "${FILESDIR}"/7.0.2/${PN}-7.0.2-depend.patch
153
154         eapply_user
155
156         # Fix systemd unit files:
157         # bug 497748
158         sed -i -e '/Requires/d' platforms/systemd/*.service.in || die
159         sed -i -e '/StandardOutput/d' platforms/systemd/*.service.in || die
160         # bug 504370
161         sed -i -e '/Alias=bacula-dir/d' platforms/systemd/bacula-dir.service.in || die
162         # bug 584442 and 504368
163         sed -i -e 's/@dir_user@/root/g' platforms/systemd/bacula-dir.service.in || die
164
165         # build 'bat' for Qt5
166         export QMAKE="$(qt5_get_bindir)"/qmake
167
168         # adapt to >=Qt-5.9 (see bug #644566)
169         # qmake needs an existing target file to generate install instructions
170         sed -i -e 's#bins.files = bat#bins.files = .libs/bat#g' \
171                 src/qt-console/bat.pro.in || die
172         mkdir src/qt-console/.libs || die
173         touch src/qt-console/.libs/bat || die
174         chmod 755 src/qt-console/.libs/bat || die
175
176         # fix handling of libressl version
177         # needs separate handling for <libressl-2.7 and >=libressl2.7
178         # (see bug #655520)
179         if has_version "<dev-libs/libressl-2.7"; then
180                 eapply -p0 "${FILESDIR}"/9.4.0/${PN}-9.4.0-libressl26.patch
181         else
182                 eapply -p0 "${FILESDIR}"/9.4.0/${PN}-9.4.0-libressl27.patch
183         fi
184
185         # Don't let program install man pages directly
186         rm "${S}"/manpages/Makefile.in || die "Unable to remove man pages Makefile.in"
187         eapply -p1 "${FILESDIR}/bacula-fix-manpages.patch"
188
189         # fix bundled libtool (bug 466696)
190         # But first move directory with M4 macros out of the way.
191         # It is only needed by autoconf and gives errors during elibtoolize.
192         mv autoconf/libtool autoconf/libtool1 || die
193         elibtoolize
194 }
195
196 src_configure() {
197         local myconf=''
198
199         if use bacula-clientonly; then
200                 myconf="${myconf} \
201                         $(use_enable bacula-clientonly client-only) \
202                         $(use_enable !static libtool) \
203                         $(use_enable static static-cons) \
204                         $(use_enable static static-fd)"
205         else
206                 myconf="${myconf} \
207                         $(use_enable !bacula-nodir build-dird) \
208                         $(use_enable !bacula-nosd build-stored)"
209                 # bug #311099
210                 # database support needed by dir-only *and* sd-only
211                 # build as well (for building bscan, btape, etc.)
212                 myconf="${myconf}
213                         --with-${mydbtype}"
214         fi
215
216         # do not build bat if 'static' clientonly
217         if ! use bacula-clientonly || ! use static; then
218                 myconf="${myconf} \
219                         $(use_enable qt5 bat)"
220         fi
221
222         myconf="${myconf} \
223                 $(use_with X x) \
224                 $(use_enable batch-insert) \
225                 $(use_enable !readline conio) \
226                 $(use_enable readline) \
227                 $(use_with readline readline /usr) \
228                 $(use_with ssl openssl) \
229                 $(use_enable ipv6) \
230                 $(use_enable acl) \
231                 $(use_with tcpd tcp-wrappers)"
232
233         econf \
234                 --libdir=/usr/$(get_libdir) \
235                 --docdir=/usr/share/doc/${PF} \
236                 --htmldir=/usr/share/doc/${PF}/html \
237                 --with-pid-dir=/var/run \
238                 --sysconfdir=/etc/bacula \
239                 --with-archivedir=/var/lib/bacula/tmp \
240                 --with-subsys-dir=/var/lock/subsys \
241                 --with-working-dir=/var/lib/bacula \
242                 --with-logdir=/var/lib/bacula \
243                 --with-scriptdir=/usr/libexec/bacula \
244                 --with-systemd=$(systemd_get_systemunitdir) \
245                 --with-dir-user=bacula \
246                 --with-dir-group=bacula \
247                 --with-sd-user=root \
248                 --with-sd-group=bacula \
249                 --with-fd-user=root \
250                 --with-fd-group=bacula \
251                 --enable-smartalloc \
252                 --disable-afs \
253                 --without-s3 \
254                 --host=${CHOST} \
255                 ${myconf}
256 }
257
258 src_compile() {
259         # Make build log verbose (bug #447806)
260         emake NO_ECHO=""
261 }
262
263 src_install() {
264         emake DESTDIR="${D}" install
265         doicon scripts/bacula.png
266
267         # install bat icon and desktop file when enabled
268         # (for some reason ./configure doesn't pick this up)
269         if use qt5 && ! use static ; then
270                 doicon src/qt-console/images/bat_icon.png
271                 domenu scripts/bat.desktop
272         fi
273
274         # remove some scripts we don't need at all
275         rm -f "${D}"/usr/libexec/bacula/{bacula,bacula-ctl-dir,bacula-ctl-fd,bacula-ctl-sd,startmysql,stopmysql}
276
277         # rename statically linked apps
278         if use bacula-clientonly && use static ; then
279                 pushd "${D}"/usr/sbin || die
280                 mv static-bacula-fd bacula-fd || die
281                 mv static-bconsole bconsole || die
282                 popd || die
283         fi
284
285         # extra files which 'make install' doesn't cover
286         if ! use bacula-clientonly; then
287             # the database update scripts
288                 diropts -m0750
289                 insinto /usr/libexec/bacula/updatedb
290                 insopts -m0754
291                 doins "${S}"/updatedb/*
292                 fperms 0640 /usr/libexec/bacula/updatedb/README
293
294                 # the logrotate configuration
295                 # (now unconditional wrt bug #258187)
296                 diropts -m0755
297                 insinto /etc/logrotate.d
298                 insopts -m0644
299                 newins "${S}"/scripts/logrotate bacula
300
301                 # the logwatch scripts
302                 if use logwatch; then
303                         diropts -m0750
304                         dodir /usr/share/logwatch/scripts/services
305                         dodir /usr/share/logwatch/scripts/shared
306                         dodir /etc/logwatch/conf/logfiles
307                         dodir /etc/logwatch/conf/services
308                         pushd "${S}"/scripts/logwatch >&/dev/null || die
309                         emake DESTDIR="${D}" install
310                         popd >&/dev/null || die
311                 fi
312         fi
313
314         # Install all man pages
315         doman "${S}"/manpages/*
316
317         if ! use qt5; then
318                 rm -vf "${D}"/usr/share/man/man1/bat.1*
319         fi
320         rm -vf "${D}"/usr/share/man/man1/bacula-tray-monitor.1*
321
322         if use bacula-clientonly || use bacula-nodir ; then
323                 rm -vf "${D}"/usr/libexec/bacula/create_*_database
324                 rm -vf "${D}"/usr/libexec/bacula/drop_*_database
325                 rm -vf "${D}"/usr/libexec/bacula/make_*_tables
326                 rm -vf "${D}"/usr/libexec/bacula/update_*_tables
327                 rm -vf "${D}"/usr/libexec/bacula/drop_*_tables
328                 rm -vf "${D}"/usr/libexec/bacula/grant_*_privileges
329                 rm -vf "${D}"/usr/libexec/bacula/*_catalog_backup
330         fi
331         if use bacula-clientonly || use bacula-nosd; then
332                 rm -vf "${D}"/usr/libexec/bacula/disk-changer
333                 rm -vf "${D}"/usr/libexec/bacula/mtx-changer
334                 rm -vf "${D}"/usr/libexec/bacula/dvd-handler
335         fi
336
337         # documentation
338         dodoc ChangeLog ReleaseNotes SUPPORT
339
340         # install examples (bug #457504)
341         if use examples; then
342                 docinto examples/
343                 dodoc -r examples/*
344         fi
345
346         # vim-files
347         if use vim-syntax; then
348                 insinto /usr/share/vim/vimfiles/syntax
349                 doins scripts/bacula.vim
350                 insinto /usr/share/vim/vimfiles/ftdetect
351                 newins scripts/filetype.vim bacula_ft.vim
352         fi
353
354         # setup init scripts
355         myscripts="bacula-fd"
356         if ! use bacula-clientonly; then
357                 if ! use bacula-nodir; then
358                         myscripts="${myscripts} bacula-dir"
359                 fi
360                 if ! use bacula-nosd; then
361                         myscripts="${myscripts} bacula-sd"
362                 fi
363         fi
364         for script in ${myscripts}; do
365                 # copy over init script and config to a temporary location
366                 # so we can modify them as needed
367                 cp "${FILESDIR}/${script}".confd "${T}/${script}".confd || die "failed to copy ${script}.confd"
368                 cp "${FILESDIR}/newscripts/${script}".initd "${T}/${script}".initd || die "failed to copy ${script}.initd"
369
370                 # now set the database dependancy for the director init script
371                 case "${script}" in
372                         bacula-dir)
373                                 case "${mydbtype}" in
374                                         sqlite3)
375                                                 # sqlite databases don't have a daemon
376                                                 sed -i -e 's/need "%database%"/:/g' "${T}/${script}".initd || die
377                                                 ;;
378                                         *)
379                                                 # all other databases have daemons
380                                                 sed -i -e "s:%database%:${mydbtype}:" "${T}/${script}".initd || die
381                                                 ;;
382                                 esac
383                                 ;;
384                         *)
385                                 ;;
386                 esac
387
388                 # install init script and config
389                 newinitd "${T}/${script}".initd "${script}"
390                 newconfd "${T}/${script}".confd "${script}"
391         done
392
393         systemd_dounit "${S}"/platforms/systemd/bacula-{dir,fd,sd}.service
394
395         # make sure the working directory exists
396         diropts -m0750
397         keepdir /var/lib/bacula
398
399         # make sure bacula group can execute bacula libexec scripts
400         fowners -R root:bacula /usr/libexec/bacula
401 }
402
403 pkg_postinst() {
404         if use bacula-clientonly; then
405                 fowners root:bacula /var/lib/bacula
406         else
407                 fowners bacula:bacula /var/lib/bacula
408         fi
409
410         if ! use bacula-clientonly && ! use bacula-nodir; then
411                 einfo
412                 einfo "If this is a new install, you must create the ${mydbtype} databases with:"
413                 einfo "  /usr/libexec/bacula/create_${mydbtype}_database"
414                 einfo "  /usr/libexec/bacula/make_${mydbtype}_tables"
415                 einfo "  /usr/libexec/bacula/grant_${mydbtype}_privileges"
416                 einfo
417
418                 ewarn "ATTENTION!"
419                 ewarn "The format of the database may have changed."
420                 ewarn "If you just upgraded from a version below 9.0.0 you must run"
421                 ewarn "'update_bacula_tables' now."
422                 ewarn "Make sure to have a backup of your catalog before."
423                 ewarn
424         fi
425
426         if use sqlite; then
427                 einfo
428                 einfo "Be aware that Bacula does not officially support SQLite database anymore."
429                 einfo "Best use it only for a client-only installation. See Bug #445540."
430                 einfo
431         fi
432
433         einfo "Please note that 'bconsole' will always be installed. To compile 'bat'"
434         einfo "you have to enable 'USE=qt5'."
435         einfo
436         einfo "/var/lib/bacula/tmp was configured for archivedir. This dir will be used during"
437         einfo "restores, so be sure to set it to an appropriate in dir in the bacula config."
438 }