482b98f1f33330877da33a1074fd748ce7b5b72a
[gentoo.git] / app-backup / bareos / bareos-17.2.7-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 PYTHON_COMPAT=( python2_7 )
7 PYTHON_REQ_USE="threads"
8
9 inherit eutils multilib python-single-r1 systemd user
10
11 DESCRIPTION="Featureful client/server network backup suite"
12 HOMEPAGE="http://www.bareos.org/"
13 SRC_URI="https://github.com/${PN}/${PN}/archive/Release/${PV}.tar.gz -> ${P}.tar.gz"
14 RESTRICT="mirror"
15
16 LICENSE="AGPL-3"
17 SLOT="0"
18 KEYWORDS="~amd64 ~x86"
19 IUSE="X acl cephfs clientonly +director fastlz glusterfs gnutls ipv6 jansson lmdb libressl
20         logwatch mysql ndmp +postgres python rados rados-striper readline scsi-crypto
21         sql-pooling sqlite ssl static +storage-daemon tcpd vim-syntax"
22 REQUIRED_USE="!clientonly? ( || ( mysql postgres sqlite ) )"
23
24 DEPEND="
25         !app-backup/bacula
26         cephfs? ( sys-cluster/ceph )
27         rados? ( sys-cluster/ceph )
28         rados-striper? ( >=sys-cluster/ceph-0.94.2 )
29         glusterfs? ( sys-cluster/glusterfs )
30         lmdb? ( dev-db/lmdb )
31         dev-libs/gmp:0
32         !clientonly? (
33                 postgres? ( dev-db/postgresql:*[threads] )
34                 mysql? ( dev-db/mysql-connector-c:0= )
35                 sqlite? ( dev-db/sqlite:3 )
36                 director? (
37                         virtual/mta
38                         jansson? ( dev-libs/jansson )
39                 )
40         )
41         fastlz? ( dev-libs/bareos-fastlzlib )
42         logwatch? ( sys-apps/logwatch )
43         tcpd? ( sys-apps/tcp-wrappers )
44         readline? ( sys-libs/readline:0 )
45         static? (
46                 acl? ( virtual/acl[static-libs] )
47                 sys-libs/zlib[static-libs]
48                 dev-libs/lzo[static-libs]
49                 sys-libs/ncurses:=[static-libs]
50                 ssl? (
51                         !gnutls? (
52                                 !libressl? ( dev-libs/openssl:0=[static-libs] )
53                                 libressl? ( dev-libs/libressl:0=[static-libs] )
54                         )
55                         gnutls? ( net-libs/gnutls[static-libs] )
56                 )
57         )
58         !static? (
59                 acl? ( virtual/acl )
60                 dev-libs/lzo
61                 ssl? (
62                         !gnutls? (
63                                 !libressl? ( dev-libs/openssl:0= )
64                                 libressl? ( dev-libs/libressl:0= )
65                         )
66                         gnutls? ( net-libs/gnutls )
67                 )
68                 sys-libs/ncurses:=
69                 sys-libs/zlib
70         )
71         python? ( ${PYTHON_DEPS} )
72         "
73 RDEPEND="${DEPEND}
74         !clientonly? (
75                 storage-daemon? (
76                         sys-block/mtx
77                         app-arch/mt-st
78                 )
79         )
80         vim-syntax? ( || ( app-editors/vim app-editors/gvim ) )"
81
82 REQUIRED_USE="static? ( clientonly )
83         python? ( ${PYTHON_REQUIRED_USE} )"
84
85 S=${WORKDIR}/${PN}-Release-${PV}
86
87 pkg_setup() {
88         use mysql && export mydbtypes+="mysql"
89         use postgres && export mydbtypes+=" postgresql"
90         use sqlite && export mydbtypes+=" sqlite"
91
92         # create the daemon group and user
93         if [ -z "$(egetent group bareos 2>/dev/null)" ]; then
94                 enewgroup bareos
95                 einfo
96                 einfo "The group 'bareos' has been created. Any users you add to this"
97                 einfo "group have access to files created by the daemons."
98                 einfo
99         fi
100
101         if ! use clientonly; then
102                 if [ -z "$(egetent passwd bareos 2>/dev/null)" ]; then
103                         enewuser bareos -1 -1 /var/lib/bareos bareos,disk,tape,cdrom,cdrw
104                         einfo
105                         einfo "The user 'bareos' has been created.  Please see the bareos manual"
106                         einfo "for information about running bareos as a non-root user."
107                         einfo
108                 fi
109         fi
110
111         use python && python-single-r1_pkg_setup
112 }
113
114 src_prepare() {
115         # adjusts default configuration files for several binaries
116         # to /etc/bareos/<config> instead of ./<config>
117         pushd src >&/dev/null || die
118         for f in console/console.c dird/dird.c filed/filed.c \
119                 stored/bcopy.c stored/bextract.c stored/bls.c \
120                 stored/bscan.c stored/btape.c stored/stored.c; do
121                 sed -i -e 's|^\(#define CONFIG_FILE "\)|\1/etc/bareos/|g' "${f}" \
122                         || die "sed on ${f} failed"
123         done
124         popd >&/dev/null || die
125
126         # enables default database driver in catalog
127         pushd src/defaultconfigs/bareos-dir.d/catalog >&/dev/null || die
128                 sed -i -e 's/#dbdriver/dbdriver/' -e '/XXX_REPLACE/d' MyCatalog.conf.in \
129                         || die "sed on MyCatalog.conf.in failed"
130         popd >&/dev/null || die
131
132         # bug 466690 Use CXXFLAGS instead of CFLAGS
133         sed -i -e 's/@CFLAGS@/@CXXFLAGS@/' autoconf/Make.common.in || die
134
135         # do not strip binaries
136         for d in filed console dird stored; do
137                 sed -i -e "s/strip /# strip /" src/$d/Makefile.in || die
138         done
139
140         eapply_user
141 }
142
143 src_configure() {
144         local myconf=''
145
146         addpredict /var/lib/logrotate.status
147
148         if use clientonly; then
149                 myconf="${myconf} \
150                         $(use_enable clientonly client-only) \
151                         $(use_enable !static libtool) \
152                         $(use_enable static static-cons) \
153                         $(use_enable static static-fd)"
154         fi
155
156         myconf="${myconf} \
157                 $(use_with X x) \
158                 $(use_enable acl) \
159                 $(use_enable ipv6) \
160                 $(use_enable ndmp) \
161                 $(use_enable readline) \
162                 $(use_enable !readline conio) \
163                 $(use_enable scsi-crypto) \
164                 $(use_enable sql-pooling) \
165                 $(use_with fastlz) \
166                 $(use_with mysql) \
167                 $(use_with postgres postgresql) \
168                 $(use_with python) \
169                 $(use_with readline) \
170                 $(use_with sqlite sqlite3) \
171                 $(use sqlite || echo "--without-sqlite3") \
172                 $(use_with ssl openssl) \
173                 $(use_with tcpd tcp-wrappers) \
174                 $(use_enable lmdb) \
175                 $(use_with glusterfs) \
176                 $(use_with rados) \
177                 $(use_with rados-striper) \
178                 $(use_with cephfs) \
179                 $(use_with jansson) \
180                 "
181
182         econf \
183                 --libdir=/usr/$(get_libdir) \
184                 --docdir=/usr/share/doc/${PF} \
185                 --htmldir=/usr/share/doc/${PF}/html \
186                 --with-pid-dir=/run/bareos \
187                 --sysconfdir=/etc \
188                 --with-subsys-dir=/run/lock/subsys \
189                 --with-working-dir=/var/lib/bareos \
190                 --with-logdir=/var/log/bareos \
191                 --with-scriptdir=/usr/libexec/bareos \
192                 --with-plugindir=/usr/$(get_libdir)/${PN}/plugin \
193                 --with-backenddir=/usr/$(get_libdir)/${PN}/backend \
194                 --with-dir-user=bareos \
195                 --with-dir-group=bareos \
196                 --with-sd-user=root \
197                 --with-sd-group=bareos \
198                 --with-fd-user=root \
199                 --with-fd-group=bareos \
200                 --with-sbin-perm=0755 \
201                 --with-systemd \
202                 --with-db-password=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1` \
203                 --enable-dynamic-cats-backends \
204                 --enable-dynamic-storage-backends \
205                 --enable-batch-insert \
206                 --disable-afs \
207                 --host=${CHOST} \
208                 ${myconf}
209 }
210
211 src_compile() {
212         # Make build log verbose (bug #447806)
213         emake NO_ECHO=""
214 }
215
216 src_install() {
217         emake DESTDIR="${D}" install
218         newicon src/images/bareos_logo_shadow.png bareos.png
219
220         # remove some scripts we don't need at all
221         rm -f "${D}"/usr/libexec/bareos/{bareos,bareos-ctl-dir,bareos-ctl-fd,bareos-ctl-sd,startmysql,stopmysql}
222         rm -f "${D}"/usr/sbin/bareos
223
224         # remove upstream init scripts
225         rm -f "${D}"/etc/init.d/bareos-*
226
227         # rename statically linked apps
228         if use clientonly && use static ; then
229                 pushd "${D}"/usr/sbin || die
230                 mv static-bareos-fd bareos-fd || die
231                 mv static-bconsole bconsole || die
232                 popd || die
233         fi
234
235         # extra files which 'make install' doesn't cover
236         if ! use clientonly; then
237                 # the logrotate configuration
238                 # (now unconditional wrt bug #258187)
239                 diropts -m0755
240                 insinto /etc/logrotate.d
241                 insopts -m0644
242                 newins "${S}"/scripts/logrotate bareos
243
244                 # the logwatch scripts
245                 if use logwatch; then
246                         diropts -m0750
247                         dodir /etc/log.d/scripts/services
248                         dodir /etc/log.d/scripts/shared
249                         dodir /etc/log.d/conf/logfiles
250                         dodir /etc/log.d/conf/services
251                         pushd "${S}"/scripts/logwatch >&/dev/null || die
252                         emake DESTDIR="${D}" install
253                         popd >&/dev/null || die
254                 fi
255         fi
256
257         rm -vf "${D}"/usr/share/man/man1/bareos-bwxconsole.1*
258         if use clientonly || ! use director; then
259                 rm -vf "${D}"/usr/share/man/man8/bareos-dir.8*
260                 rm -vf "${D}"/usr/share/man/man8/bareos-dbcheck.8*
261                 rm -vf "${D}"/usr/share/man/man1/bsmtp.1*
262                 rm -vf "${D}"/usr/share/man/man8/bwild.8*
263                 rm -vf "${D}"/usr/share/man/man8/bregex.8*
264                 rm -vf "${D}"/usr/share/man/man8/bpluginfo.8*
265                 rm -vf "${D}"/usr/libexec/bareos/create_*_database
266                 rm -vf "${D}"/usr/libexec/bareos/drop_*_database
267                 rm -vf "${D}"/usr/libexec/bareos/make_*_tables
268                 rm -vf "${D}"/usr/libexec/bareos/update_*_tables
269                 rm -vf "${D}"/usr/libexec/bareos/drop_*_tables
270                 rm -vf "${D}"/usr/libexec/bareos/grant_*_privileges
271                 rm -vf "${D}"/usr/libexec/bareos/*_catalog_backup
272         fi
273         if use clientonly || ! use storage-daemon; then
274                 rm -vf "${D}"/usr/share/man/man8/bareos-sd.8*
275                 rm -vf "${D}"/usr/share/man/man8/bcopy.8*
276                 rm -vf "${D}"/usr/share/man/man8/bextract.8*
277                 rm -vf "${D}"/usr/share/man/man8/bls.8*
278                 rm -vf "${D}"/usr/share/man/man8/bscan.8*
279                 rm -vf "${D}"/usr/share/man/man8/btape.8*
280                 rm -vf "${D}"/usr/libexec/bareos/disk-changer
281                 rm -vf "${D}"/usr/libexec/bareos/mtx-changer
282                 rm -vf "${D}"/usr/libexec/bareos/dvd-handler
283                 rm -vf "${D}"/etc/bareos/mtx-changer.conf
284         fi
285         if ! use scsi-crypto; then
286                 rm -vf "${D}"/usr/share/man/man8/bscrypto.8*
287         fi
288
289         # documentation
290         dodoc README.md
291         use ndmp && dodoc README.NDMP
292         use scsi-crypto && dodoc README.scsicrypto
293
294         # vim-files
295         if use vim-syntax; then
296                 insinto /usr/share/vim/vimfiles/syntax
297                 doins scripts/bareos.vim
298                 insinto /usr/share/vim/vimfiles/ftdetect
299                 newins scripts/filetype.vim bareos_ft.vim
300         fi
301
302         # setup init scripts
303         myscripts="bareos-fd"
304         if ! use clientonly; then
305                 if use director; then
306                         myscripts="${myscripts} bareos-dir"
307                 fi
308                 if use storage-daemon; then
309                         myscripts="${myscripts} bareos-sd"
310                 fi
311         fi
312         for script in ${myscripts}; do
313                 # copy over init script and config to a temporary location
314                 # so we can modify them as needed
315                 cp "${FILESDIR}/${script}".confd-16 "${T}/${script}".confd || die "failed to copy ${script}.confd"
316                 cp "${FILESDIR}/${script}".initd "${T}/${script}".initd || die "failed to copy ${script}.initd"
317
318                 # now set the database dependency for the director init script
319                 case "${script}" in
320                         bareos-dir)
321                                 sed -i -e "s:%databasetypes%:${mydbtypes}:" "${T}/${script}".confd || die
322                                 ;;
323                         *)
324                                 ;;
325                 esac
326
327                 # install init script and config
328                 newinitd "${T}/${script}".initd "${script}"
329                 newconfd "${T}/${script}".confd "${script}"
330         done
331
332         # install systemd unit files
333         use director && systemd_dounit "${FILESDIR}"/bareos-dir.service
334         use storage-daemon && systemd_dounit "${FILESDIR}"/bareos-sd.service
335         systemd_dounit "${FILESDIR}"/bareos-fd.service
336
337         # make sure the working directory exists
338         diropts -m0750
339         keepdir /var/lib/bareos
340
341         # make sure bareos group can execute bareos libexec scripts
342         fowners -R root:bareos /usr/libexec/bareos
343 }
344
345 pkg_postinst() {
346         if use clientonly; then
347                 fowners root:bareos /var/lib/bareos
348         else
349                 fowners bareos:bareos /var/lib/bareos
350         fi
351
352         if ! use clientonly && use director; then
353                 einfo
354                 einfo "If this is a new install, you must create the database:"
355                 if use postgres; then
356                         einfo
357                         einfo "For postgresql:"
358                         einfo "  su postgres -c '/usr/libexec/bareos/create_bareos_database postgresql'"
359                         einfo "  su postgres -c '/usr/libexec/bareos/make_bareos_tables postgresql'"
360                         einfo "  su postgres -c '/usr/libexec/bareos/grant_bareos_privileges postgresql'"
361                 fi
362                 if use mysql; then
363                         einfo
364                         einfo "For mysql:"
365                         einfo
366                         einfo "  Make sure root has direct access to your mysql server. You may want to"
367                         einfo "  create a /root/.my.cnf file with"
368                         einfo "    [client]"
369                         einfo "    user=root"
370                         einfo "    password=YourPasswordForAccessingMysqlAsRoot"
371                         einfo "  before running:"
372                         einfo "  /usr/libexec/bareos/create_bareos_database mysql"
373                         einfo "  /usr/libexec/bareos/make_bareos_tables mysql"
374                         einfo "  /usr/libexec/bareos/grant_bareos_privileges mysql"
375                 fi
376                 einfo
377         fi
378
379         if use sqlite; then
380                 einfo
381                 einfo "Be aware that Bareos does not officially support SQLite database."
382                 einfo "Best use it only for a client-only installation. See Bug #445540."
383                 einfo
384                 einfo "It is strongly recommended to use either postgresql or mysql as"
385                 einfo "catalog database backend."
386                 einfo
387         fi
388 }