app-backup/bacula: use HTTPS
[gentoo.git] / app-backup / bacula / bacula-9.2.2.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 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/qtsvg:5
30                 x11-libs/qwt:6
31         )
32         logwatch? ( sys-apps/logwatch )
33         readline? ( sys-libs/readline:0 )
34         static? (
35                 dev-libs/lzo[static-libs]
36                 sys-libs/ncurses:=[static-libs]
37                 sys-libs/zlib[static-libs]
38                 acl? ( virtual/acl[static-libs] )
39                 ssl? (
40                         !libressl? ( dev-libs/openssl:0=[static-libs] )
41                         libressl? ( dev-libs/libressl:0=[static-libs] )
42                 )
43         )
44         !static? (
45                 dev-libs/lzo
46                 sys-libs/ncurses:=
47                 sys-libs/zlib
48                 acl? ( virtual/acl )
49                 ssl? (
50                         !libressl? ( dev-libs/openssl:0= )
51                         libressl? ( dev-libs/libressl:0= )
52                 )
53         )
54         tcpd? ( >=sys-apps/tcp-wrappers-7.6 )
55 "
56 RDEPEND="${DEPEND}
57         !bacula-clientonly? (
58                 !bacula-nosd? (
59                         app-arch/mt-st
60                         sys-block/mtx
61                 )
62         )
63         vim-syntax? ( || ( app-editors/vim app-editors/gvim ) )
64 "
65
66 REQUIRED_USE="
67         !bacula-clientonly? ( ^^ ( mysql postgres sqlite ) )
68         static? ( bacula-clientonly )
69 "
70
71 S=${WORKDIR}/${MY_P}
72
73 pkg_setup() {
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"
78
79         # create the daemon group and user
80         if [ -z "$(egetent group bacula 2>/dev/null)" ]; then
81                 enewgroup bacula
82                 einfo
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."
85                 einfo
86         fi
87
88         if use bacula-clientonly && use static && use qt5; then
89                 ewarn
90                 ewarn "Building statically linked 'bat' is not supported. Ignorig 'qt5' useflag."
91                 ewarn
92         fi
93
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
97                         einfo
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."
100                         einfo
101                 fi
102         fi
103 }
104
105 src_prepare() {
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"
115         done
116         popd >&/dev/null || die
117
118         # bug 466688 drop deprecated categories from Desktop file
119         sed -i -e 's/Application;//' scripts/bat.desktop.in || die
120
121         # bug 466690 Use CXXFLAGS instead of CFLAGS
122         sed -i -e 's/@CFLAGS@/@CXXFLAGS@/' autoconf/Make.common.in || die
123
124         # drop automatic install of unneeded documentation (for bug 356499)
125         eapply -p0 "${FILESDIR}"/7.2.0/${PN}-7.2.0-doc.patch
126
127         # bug #310087
128         eapply "${FILESDIR}"/5.2.3/${PN}-5.2.3-as-needed.patch
129
130         # bug #311161
131         eapply -p0 "${FILESDIR}"/9.0.2/${PN}-9.0.2-lib-search-path.patch
132
133         # bat needs to respect LDFLAGS and CFLAGS
134         eapply -p0 "${FILESDIR}"/9.0.6/${PN}-9.0.6-bat-pro.patch
135
136         # bug #328701
137         eapply -p0 "${FILESDIR}"/5.2.3/${PN}-5.2.3-openssl-1.patch
138
139         eapply -p0 "${FILESDIR}"/9.0.8/${PN}-9.0.8-fix-static.patch
140
141         # fix soname in libbaccat.so bug #602952
142         eapply -p0 "${FILESDIR}/bacula-fix-sonames.patch"
143
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
147
148         # fix file not found error during make depend
149         eapply -p0 "${FILESDIR}"/7.0.2/${PN}-7.0.2-depend.patch
150
151         eapply_user
152
153         # Fix systemd unit files:
154         # bug 497748
155         sed -i -e '/Requires/d' platforms/systemd/*.service.in || die
156         sed -i -e '/StandardOutput/d' platforms/systemd/*.service.in || die
157         # bug 504370
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
161
162         # build 'bat' for Qt5
163         export QMAKE="$(qt5_get_bindir)"/qmake
164
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
172
173         # fix wrong handling of libressl version
174         # needs separate handling for <libressl-2.7 and >=libressl2.7
175         # (see bug #655520)
176         if has_version "<dev-libs/libressl-2.7"; then
177                 eapply -p0 "${FILESDIR}"/9.0.6/${PN}-9.0.6-libressl26.patch
178         else
179                 eapply -p0 "${FILESDIR}"/9.0.6/${PN}-9.0.6-libressl27.patch
180         fi
181
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"
185
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
190         elibtoolize
191 }
192
193 src_configure() {
194         local myconf=''
195
196         if use bacula-clientonly; then
197                 myconf="${myconf} \
198                         $(use_enable bacula-clientonly client-only) \
199                         $(use_enable !static libtool) \
200                         $(use_enable static static-cons) \
201                         $(use_enable static static-fd)"
202         else
203                 myconf="${myconf} \
204                         $(use_enable !bacula-nodir build-dird) \
205                         $(use_enable !bacula-nosd build-stored)"
206                 # bug #311099
207                 # database support needed by dir-only *and* sd-only
208                 # build as well (for building bscan, btape, etc.)
209                 myconf="${myconf}
210                         --with-${mydbtype}"
211                 if use mysql; then
212                     myconf="${myconf} \
213                         --disable-batch-insert"
214                 else
215                     myconf="${myconf} \
216                         --enable-batch-insert"
217                 fi
218         fi
219
220         # do not build bat if 'static' clientonly
221         if ! use bacula-clientonly || ! use static; then
222                 myconf="${myconf} \
223                         $(use_enable qt5 bat)"
224         fi
225
226         myconf="${myconf} \
227                 $(use_with X x) \
228                 $(use_enable !readline conio) \
229                 $(use_enable readline) \
230                 $(use_with readline readline /usr) \
231                 $(use_with ssl openssl) \
232                 $(use_enable ipv6) \
233                 $(use_enable acl) \
234                 $(use_with tcpd tcp-wrappers)"
235
236         econf \
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 \
255                 --disable-afs \
256                 --host=${CHOST} \
257                 ${myconf}
258 }
259
260 src_compile() {
261         # Make build log verbose (bug #447806)
262         emake NO_ECHO=""
263 }
264
265 src_install() {
266         emake DESTDIR="${D}" install
267         doicon scripts/bacula.png
268
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
274         fi
275
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}
278
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
284                 popd || die
285         fi
286
287         # extra files which 'make install' doesn't cover
288         if ! use bacula-clientonly; then
289             # the database update scripts
290                 diropts -m0750
291                 insinto /usr/libexec/bacula/updatedb
292                 insopts -m0754
293                 doins "${S}"/updatedb/*
294                 fperms 0640 /usr/libexec/bacula/updatedb/README
295
296                 # the logrotate configuration
297                 # (now unconditional wrt bug #258187)
298                 diropts -m0755
299                 insinto /etc/logrotate.d
300                 insopts -m0644
301                 newins "${S}"/scripts/logrotate bacula
302
303                 # the logwatch scripts
304                 if use logwatch; then
305                         diropts -m0750
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
313                 fi
314         fi
315
316         if ! use qt5; then
317                 rm -vf "${D}"/usr/share/man/man1/bat.1*
318         fi
319         rm -vf "${D}"/usr/share/man/man1/bacula-tray-monitor.1*
320
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
329         fi
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
334         fi
335
336         # documentation
337         dodoc ChangeLog ReleaseNotes SUPPORT
338
339         # Install all man pages
340         doman "${S}"/manpages/*
341
342         # install examples (bug #457504)
343         if use examples; then
344                 docinto examples/
345                 dodoc -r examples/*
346         fi
347
348         # vim-files
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
354         fi
355
356         # setup init scripts
357         myscripts="bacula-fd"
358         if ! use bacula-clientonly; then
359                 if ! use bacula-nodir; then
360                         myscripts="${myscripts} bacula-dir"
361                 fi
362                 if ! use bacula-nosd; then
363                         myscripts="${myscripts} bacula-sd"
364                 fi
365         fi
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"
371
372                 # now set the database dependancy for the director init script
373                 case "${script}" in
374                         bacula-dir)
375                                 case "${mydbtype}" in
376                                         sqlite3)
377                                                 # sqlite databases don't have a daemon
378                                                 sed -i -e 's/need "%database%"/:/g' "${T}/${script}".initd || die
379                                                 ;;
380                                         *)
381                                                 # all other databases have daemons
382                                                 sed -i -e "s:%database%:${mydbtype}:" "${T}/${script}".initd || die
383                                                 ;;
384                                 esac
385                                 ;;
386                         *)
387                                 ;;
388                 esac
389
390                 # install init script and config
391                 newinitd "${T}/${script}".initd "${script}"
392                 newconfd "${T}/${script}".confd "${script}"
393         done
394
395         systemd_dounit "${S}"/platforms/systemd/bacula-{dir,fd,sd}.service
396
397         # make sure the working directory exists
398         diropts -m0750
399         keepdir /var/lib/bacula
400
401         # make sure bacula group can execute bacula libexec scripts
402         fowners -R root:bacula /usr/libexec/bacula
403 }
404
405 pkg_postinst() {
406         if use bacula-clientonly; then
407                 fowners root:bacula /var/lib/bacula
408         else
409                 fowners bacula:bacula /var/lib/bacula
410         fi
411
412         if ! use bacula-clientonly && ! use bacula-nodir; then
413                 einfo
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"
418                 einfo
419
420                 ewarn "ATTENTION!"
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."
425                 ewarn
426         fi
427
428         if use sqlite; then
429                 einfo
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."
432                 einfo
433         fi
434
435         einfo "Please note that 'bconsole' will always be installed. To compile 'bat'"
436         einfo "you have to enable 'USE=qt5'."
437         einfo
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."
440 }