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