summaryrefslogtreecommitdiff
blob: 787a7074b9fc9e921b90648318f30ecf32dcf8e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

PYTHON_COMPAT=( python3_{8..10} )
CMAKE_WARN_UNUSED_CLI=no
#CMAKE_REMOVE_MODULES=yes

inherit python-any-r1 systemd cmake tmpfiles

DESCRIPTION="Featureful client/server network backup suite"
HOMEPAGE="https://www.bareos.org/"
SRC_URI="https://github.com/${PN}/${PN}/archive/Release/${PV}.tar.gz -> ${P}.tar.gz"

# some tests still fail propably due to missing bits in src_test -> TODO
RESTRICT="mirror test"
#RESTRICT="
#	mirror
#	!test? ( test )
#"

LICENSE="AGPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="X acl ceph clientonly +director glusterfs ipv6 lmdb
	logwatch ndmp readline scsi-crypto
	static +storage-daemon systemd tcpd test vim-syntax vmware xattr"

# get cmake variables from core/cmake/BareosSetVariableDefaults.cmake
DEPEND="
	!app-backup/bacula
	acct-group/${PN}
	!x86? (
		ceph? ( sys-cluster/ceph )
	)
	glusterfs? ( sys-cluster/glusterfs )
	lmdb? ( dev-db/lmdb )
	dev-libs/gmp:0
	!clientonly? (
		acct-user/${PN}
		dev-db/postgresql:*[threads]
		director? (
			virtual/mta
		)
	)
	logwatch? ( sys-apps/logwatch )
	ndmp? ( net-libs/rpcsvc-proto )
	tcpd? ( sys-apps/tcp-wrappers )
	readline? ( sys-libs/readline:0 )
	static? (
		acl? ( virtual/acl[static-libs] )
		dev-libs/jansson:=[static-libs]
		dev-libs/lzo[static-libs]
		dev-libs/openssl:0=[static-libs]
		sys-libs/ncurses:=[static-libs]
		sys-libs/zlib[static-libs]
	)
	!static? (
		acl? ( virtual/acl )
		dev-libs/jansson:=
		dev-libs/lzo
		dev-libs/openssl:0=
		sys-libs/ncurses:=
		sys-libs/zlib
	)
	"
RDEPEND="${DEPEND}
	!clientonly? (
		storage-daemon? (
			sys-block/mtx
			app-arch/mt-st
		)
	)
	vim-syntax? ( || ( app-editors/vim app-editors/gvim ) )
	"

BDEPEND="
	${PYTHON_DEPS}
	test? (
		dev-cpp/gtest
		dev-db/postgresql:*[server,threads]
		dev-db/mariadb:*[server]
	)
"

REQUIRED_USE="
	static? ( clientonly )
	x86? ( !ceph )
"

S=${WORKDIR}/${PN}-Release-${PV}

pkg_pretend() {
	local active_removed_backend=""
	if has_version "<app-backup/bareos-21[director,mysql]"; then
		if grep -qhriE "dbdriver.*=.*mysql" /etc/bareos/; then
			active_removed_backend=MySQL
		fi
	elif has_version "<app-backup/bareos-21[director,sqlite]"; then
		if grep -qhriE "dbdriver.*=.*sqlite" /etc/bareos/; then
			active_removed_backend=SQLite
		fi
	fi
	if [[ -n $active_removed_backend ]]; then
		ewarn
		ewarn "You are currently using bareos with the $active_removed_backend"
		ewarn "catalog backend."
		ewarn
		ewarn "THIS IS NOT SUPPORTED ANYMORE"
		ewarn
		ewarn "Beginning with version 21.0.0 bareos has dropped support for"
		ewarn "MySQL and SQLite catalog backends."
		ewarn
		ewarn "To upgrade to bareos >=21.0.0 you need to migrate to PostgreSQL"
		ewarn "catalog backend using the 'bareos-dbcopy' tool of your current"
		ewarn "installation first."
		ewarn
		die "current catalog backend not supported anymore"
	fi
}

src_test() {
	# initialze catalog test database
	initdb -D "${T}"/pgsql || die
	pg_ctl -w -D "${T}"/pgsql start \
		-o "-h '' -k '${T}'" || die
	createuser -h "${T}" bareos || die
	createdb -h "${T}" --owner bareos bareos || die
	export PGHOST="${T}"

	# initiale mariadb database for backup tests
	# $USER must be set and != root
	export USER=portage

	default
	cmake_src_test

	pg_ctl -w -D "${T}"/pgsql stop || die
	rm -rvf "${T}"/pgsql
}

src_prepare() {
	# fix gentoo platform support
	eapply -p1 "${FILESDIR}/${PN}-21-cmake-gentoo.patch"

	# fix missing DESTDIR in symlink creation
	sed -i '/bareos-symlink-default-db-backend.cmake/d' "${S}/core/src/cats/CMakeLists.txt"

	cmake_src_prepare
}

src_configure() {
	local mycmakeargs=()

	cmake_comment_add_subdirectory webui

	if use clientonly; then
		mycmakeargs+=(
			-Dclient-only=ON
			-Dstatic-cons=$(usex static)
			-Dstatic-fd=$(usex static)
		)
	fi

	for useflag in acl ipv6 ndmp scsi-crypto \
		systemd lmdb; do
		mycmakeargs+=( -D$useflag=$(usex $useflag) )
	done

	mycmakeargs+=(
		-DHAVE_PYTHON=0
		-Darchivedir=/var/lib/bareos/storage
		-Dbackenddir=/usr/$(get_libdir)/${PN}/backend
		-Dbasename="`hostname -s`"
		-Dbatch-insert=yes
		-Dbsrdir=/var/lib/bareos/bsr
		-Dconfdir=/etc/bareos
		-Dcoverage=no
		-Ddb_password=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1`
		-Ddir-group=bareos
		-Ddir-password="`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`"
		-Ddir-user=bareos
		-Ddocdir=/usr/share/doc/${PF}
		-Ddynamic-cats-backends=yes
		-Ddynamic-storage-backends=yes
		-Dfd-group=bareos
		-Dfd-password="`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`"
		-Dfd-user=root
		-Dhost=${CHOST}
		-Dhostname="`hostname -s`"
		-Dhtmldir=/usr/share/doc/${PF}/html
		-Dlibdir=/usr/$(get_libdir)
		-Dlogdir=/var/log/bareos
		-Dmandir=/usr/share/man
		-Dmon-dir-password="`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`"
		-Dmon-fd-password="`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`"
		-Dmon-sd-password="`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`"
		-Dopenssl=yes
		-Dpiddir=/run/bareos
		-Dplugindir=/usr/$(get_libdir)/${PN}/plugin
		-Dsbin-perm=0755
		-Dsbindir=/usr/sbin
		-Dscriptdir=/usr/libexec/bareos
		-Dsd-group=bareos
		-Dsd-password="`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`"
		-Dsd-user=root
		-Dsubsysdir=/run/lock/subsys
		-Dsysconfdir=/etc
		-Dworkingdir=/var/lib/bareos
		-Dx=$(usex X)
		)

		# disable droplet support for now as it does not build with gcc 10
		# ... and this is a bundled lib, which should have its own package
		cd core && cmake_comment_add_subdirectory "src/droplet"

		cmake_src_configure
}

src_install() {
	cmake_src_install

	# remove some scripts we don't need at all
	rm -f "${D}"/usr/libexec/bareos/{bareos,bareos-ctl-dir,bareos-ctl-fd,bareos-ctl-sd}
	rm -f "${D}"/usr/sbin/bareos

	# remove upstream init scripts and systemd units
	rm -f "${D}"/etc/init.d/bareos-* "${D}"/lib/systemd/system/bareos-*.service

	# remove misc stuff we do not need in production
	rm -f "${D}"/etc/bareos/bareos-regress.conf
	rm -f "${D}"/etc/logrotate.d/bareos-dir

	# get rid of py2 stuff
	rm -rf "$D"/usr/lib64/python2.7 || die
	rm -f "$D"/usr/lib64/bareos/plugin/python-fd.so || die
	if ! use vmware; then
		rm -f "$D"/usr/lib64/bareos/plugin/{BareosFdPluginVMware.py,bareos-fd-vmware.py}
	fi

	# rename statically linked apps
	if use clientonly && use static ; then
		pushd "${D}"/usr/sbin || die
		mv static-bareos-fd bareos-fd || die
		mv static-bconsole bconsole || die
		popd || die
	fi

	# extra files which 'make install' doesn't cover
	if ! use clientonly; then
		# the logrotate configuration
		# (now unconditional wrt bug #258187)
		diropts -m0755
		insinto /etc/logrotate.d
		insopts -m0644
		newins "${S}"/core/scripts/logrotate bareos

		# the logwatch scripts
		if use logwatch; then
			diropts -m0750
			dodir /etc/log.d/scripts/services
			dodir /etc/log.d/scripts/shared
			dodir /etc/log.d/conf/logfiles
			dodir /etc/log.d/conf/services
			pushd "${S}"/core/scripts/logwatch >&/dev/null || die

			into /etc/log.d/scripts/services
			dobin bareos

			into /etc/log.d/scripts/shared
			dobin applybareosdate

			insinto /etc/log.d/conf/logfiles
			newins logfile.bareos.conf bareos.conf

			insinto /etc/log.d/conf/services
			newins services.bareos.conf bareos.conf

			popd >&/dev/null || die
		fi
	fi

	rm -vf "${D}"/usr/share/man/man1/bareos-bwxconsole.1*
	if use clientonly || ! use director; then
		rm -vf "${D}"/usr/share/man/man8/bareos-dir.8*
		rm -vf "${D}"/usr/share/man/man8/bareos-dbcheck.8*
		rm -vf "${D}"/usr/share/man/man1/bsmtp.1*
		rm -vf "${D}"/usr/share/man/man8/bwild.8*
		rm -vf "${D}"/usr/share/man/man8/bregex.8*
		rm -vf "${D}"/usr/share/man/man8/bpluginfo.8*
		rm -vf "${D}"/usr/libexec/bareos/create_*_database
		rm -vf "${D}"/usr/libexec/bareos/drop_*_database
		rm -vf "${D}"/usr/libexec/bareos/make_*_tables
		rm -vf "${D}"/usr/libexec/bareos/update_*_tables
		rm -vf "${D}"/usr/libexec/bareos/drop_*_tables
		rm -vf "${D}"/usr/libexec/bareos/grant_*_privileges
		rm -vf "${D}"/usr/libexec/bareos/*_catalog_backup
	fi
	if use clientonly || ! use storage-daemon; then
		rm -vf "${D}"/usr/share/man/man8/bareos-sd.8*
		rm -vf "${D}"/usr/share/man/man8/bcopy.8*
		rm -vf "${D}"/usr/share/man/man8/bextract.8*
		rm -vf "${D}"/usr/share/man/man8/bls.8*
		rm -vf "${D}"/usr/share/man/man8/bscan.8*
		rm -vf "${D}"/usr/share/man/man8/btape.8*
		rm -vf "${D}"/usr/libexec/bareos/disk-changer
		rm -vf "${D}"/usr/libexec/bareos/mtx-changer
		rm -vf "${D}"/usr/libexec/bareos/dvd-handler
		rm -vf "${D}"/etc/bareos/mtx-changer.conf
	fi
	if ! use scsi-crypto; then
		rm -vf "${D}"/usr/share/man/man8/bscrypto.8*
	fi

	# documentation
	dodoc README.md
	dodoc core/README.configsubdirectories
	use glusterfs dodoc core/README.glusterfs
	use ndmp && dodoc core/README.NDMP
	use scsi-crypto && dodoc core/README.scsicrypto

	# vim-files
	if use vim-syntax; then
		insinto /usr/share/vim/vimfiles/syntax
		doins core/scripts/bareos.vim
		insinto /usr/share/vim/vimfiles/ftdetect
		newins core/scripts/filetype.vim bareos_ft.vim
	fi

	# setup init scripts
	myscripts="bareos-fd"
	if ! use clientonly; then
		if use director; then
			myscripts+=" bareos-dir-21"
		fi
		if use storage-daemon; then
			myscripts+=" bareos-sd"
		fi
	fi
	for script in ${myscripts}; do
		# copy over init script and config to a temporary location
		# so we can modify them as needed
		cp "${FILESDIR}/${script}".confd "${T}/${script}".confd || die "failed to copy ${script}.confd"
		cp "${FILESDIR}/${script}".initd "${T}/${script}".initd || die "failed to copy ${script}.initd"

		# install init script and config
		newinitd "${T}/${script}".initd "${script/-21/}"
		newconfd "${T}/${script}".confd "${script/-21/}"
	done

	# install systemd unit files
	if use systemd; then
		if ! use clientonly; then
			use director && systemd_dounit "${FILESDIR}"/bareos-dir.service
			use storage-daemon && systemd_dounit "${FILESDIR}"/bareos-sd.service
		fi
		systemd_dounit "${FILESDIR}"/bareos-fd.service
	fi

	# make sure the working directory exists
	diropts -m0750
	keepdir /var/lib/bareos
	keepdir /var/lib/bareos/storage

	diropts -m0755
	keepdir /var/log/bareos

	newtmpfiles "${FILESDIR}"/tmpfiles.d-bareos.conf bareos.conf

	# make sure bareos group can execute bareos libexec scripts
	fowners -R root:bareos /usr/libexec/bareos
}

pkg_postinst() {
	tmpfiles_process bareos.conf

	if use clientonly; then
		fowners root:bareos /var/lib/bareos
	else
		fowners bareos:bareos /var/lib/bareos
	fi

	if ! use clientonly && use director; then
		einfo
		einfo "If this is a new install, you must create the database:"
		einfo
		einfo "  su postgres -c '/usr/libexec/bareos/create_bareos_database postgresql'"
		einfo "  su postgres -c '/usr/libexec/bareos/make_bareos_tables postgresql'"
		einfo "  su postgres -c '/usr/libexec/bareos/grant_bareos_privileges postgresql'"
		einfo
	fi
}