app-backup/amanda: [QA] inherit toolchain-funcs.eclass directly
[gentoo.git] / app-backup / amanda / amanda-3.4.4.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5 inherit autotools perl-module user systemd toolchain-funcs
6
7 DESCRIPTION="The Advanced Maryland Automatic Network Disk Archiver"
8 HOMEPAGE="http://www.amanda.org/"
9 SRC_URI="mirror://sourceforge/amanda/${P}.tar.gz"
10
11 LICENSE="HPND BSD BSD-2 GPL-2+ GPL-3+"
12 SLOT="0"
13 IUSE="curl gnuplot ipv6 kerberos minimal nls readline s3 samba systemd xfs"
14
15 KEYWORDS="~amd64 ~ppc ~ppc64 ~sparc ~x86"
16 RDEPEND="sys-libs/readline:=
17         virtual/awk
18         app-arch/tar
19         dev-lang/perl:=
20         app-arch/dump
21         net-misc/openssh
22         >=dev-libs/glib-2.26.0
23         dev-perl/JSON
24         dev-perl/Encode-Locale
25         nls? ( virtual/libintl )
26         s3? ( >=net-misc/curl-7.10.0 )
27         !s3? ( curl? ( >=net-misc/curl-7.10.0 ) )
28         samba? ( net-fs/samba:= )
29         kerberos? ( app-crypt/mit-krb5 )
30         xfs? ( sys-fs/xfsdump )
31         !minimal? (
32                 dev-perl/XML-Simple
33                 virtual/mailx
34                 app-arch/mt-st:=
35                 sys-block/mtx
36                 gnuplot? ( sci-visualization/gnuplot )
37                 app-crypt/aespipe
38                 app-crypt/gnupg
39         )"
40
41 DEPEND="${RDEPEND}
42         virtual/pkgconfig
43         nls? ( sys-devel/gettext )
44         >=app-text/docbook-xsl-stylesheets-1.72.0
45         app-text/docbook-xml-dtd
46         dev-libs/libxslt
47         dev-lang/swig
48         "
49
50 MYFILESDIR="${T}/files"
51 ENVDIR="/etc/env.d"
52 ENVDFILE="97amanda"
53 TMPENVFILE="${T}/${ENVDFILE}"
54
55 # This is a complete list of Amanda settings that the ebuild takes from the
56 # build environment. This allows users to alter the behavior of the package as
57 # upstream intended, but keeping with Gentoo style. We store a copy of them in
58 # /etc/env.d/97amanda during the install, so that they are preserved for future
59 # installed. This variable name must not start with AMANDA_, as we do not want
60 # it captured into the env file.
61 ENV_SETTINGS_AMANDA="
62 AMANDA_GROUP_GID AMANDA_GROUP_NAME
63 AMANDA_USER_NAME AMANDA_USER_UID AMANDA_USER_SH AMANDA_USER_HOMEDIR AMANDA_USER_GROUPS
64 AMANDA_SERVER AMANDA_SERVER_TAPE AMANDA_SERVER_TAPE_DEVICE AMANDA_SERVER_INDEX
65 AMANDA_TAR_LISTDIR AMANDA_TAR
66 AMANDA_PORTS_UDP AMANDA_PORTS_TCP AMANDA_PORTS_BOTH AMANDA_PORTS
67 AMANDA_CONFIG_NAME AMANDA_TMPDIR"
68
69 amanda_variable_setup() {
70
71         # Setting vars
72         local currentamanda
73
74         # Grab the current settings
75         currentamanda="$(set | egrep "^AMANDA_" | grep -v '^AMANDA_ENV_SETTINGS' | xargs)"
76
77         # First we set the defaults
78         [[ -z "${AMANDA_GROUP_GID}" ]] && AMANDA_GROUP_GID=87
79         [[ -z "${AMANDA_GROUP_NAME}" ]] && AMANDA_GROUP_NAME=amanda
80         [[ -z "${AMANDA_USER_NAME}" ]] && AMANDA_USER_NAME=amanda
81         [[ -z "${AMANDA_USER_UID}" ]] && AMANDA_USER_UID=87
82         [[ -z "${AMANDA_USER_SH}" ]] && AMANDA_USER_SH=/bin/bash
83         [[ -z "${AMANDA_USER_HOMEDIR}" ]] && AMANDA_USER_HOMEDIR=/var/spool/amanda
84         [[ -z "${AMANDA_USER_GROUPS}" ]] && AMANDA_USER_GROUPS="${AMANDA_GROUP_NAME}"
85
86         # This installs Amanda, with the server. However, it could be a client,
87         # just specify an alternate server name in AMANDA_SERVER.
88         [[ -z "${AMANDA_SERVER}" ]] && AMANDA_SERVER="${HOSTNAME}"
89         [[ -z "${AMANDA_SERVER_TAPE}" ]] && AMANDA_SERVER_TAPE="${AMANDA_SERVER}"
90         [[ -z "${AMANDA_SERVER_TAPE_DEVICE}" ]] && AMANDA_SERVER_TAPE_DEVICE="/dev/nst0"
91         [[ -z "${AMANDA_SERVER_INDEX}" ]] && AMANDA_SERVER_INDEX="${AMANDA_SERVER}"
92         [[ -z "${AMANDA_TAR_LISTDIR}" ]] && AMANDA_TAR_LISTDIR=${AMANDA_USER_HOMEDIR}/tar-lists
93         [[ -z "${AMANDA_CONFIG_NAME}" ]] && AMANDA_CONFIG_NAME=DailySet1
94         [[ -z "${AMANDA_TMPDIR}" ]] && AMANDA_TMPDIR=/var/tmp/amanda
95         [[ -z "${AMANDA_DBGDIR}" ]] && AMANDA_DBGDIR="$AMANDA_TMPDIR"
96         # These are left empty by default
97         [[ -z "${AMANDA_PORTS_UDP}" ]] && AMANDA_PORTS_UDP=
98         [[ -z "${AMANDA_PORTS_TCP}" ]] && AMANDA_PORTS_TCP=
99         [[ -z "${AMANDA_PORTS_BOTH}" ]] && AMANDA_PORTS_BOTH=
100         [[ -z "${AMANDA_PORTS}" ]] && AMANDA_PORTS=
101
102         # What tar to use
103         [[ -z "${AMANDA_TAR}" ]] && AMANDA_TAR=/bin/tar
104
105         # Now pull in the old stuff
106         if [[ -f "${EROOT}${ENVDIR}/${ENVDFILE}" ]]; then
107                 # We don't just source it as we don't want everything in there.
108                 eval $(egrep "^AMANDA_" "${EROOT}${ENVDIR}/${ENVDFILE}" | grep -v '^AMANDA_ENV_SETTINGS')
109         fi
110
111         # Re-apply the new settings if any
112         [ -n "${currentamanda}" ] && eval $(echo "${currentamanda}")
113
114 }
115
116 pkg_setup() {
117         amanda_variable_setup
118
119         # If USE=minimal, give out a warning, if AMANDA_SERVER is not set to
120         # another host than HOSTNAME.
121         if use minimal && [ "${AMANDA_SERVER}" = "${HOSTNAME}" ] ; then
122                 elog "You are installing a client-only version of Amanda."
123                 elog "You should set the variable \$AMANDA_SERVER to point at your"
124                 elog "Amanda-tape-server, otherwise you will have to specify its name"
125                 elog "when using amrecover on the client."
126                 elog "For example: Use something like"
127                 elog "AMANDA_SERVER=\"myserver\" emerge amanda"
128                 elog
129         fi
130
131         enewgroup "${AMANDA_GROUP_NAME}" "${AMANDA_GROUP_GID}"
132         enewuser "${AMANDA_USER_NAME}" "${AMANDA_USER_UID}" "${AMANDA_USER_SH}" "${AMANDA_USER_HOMEDIR}" "${AMANDA_USER_GROUPS}"
133 }
134
135 src_unpack() {
136         # we do not want the perl src_unpack
137         default_src_unpack
138 }
139
140 src_prepare() {
141         # gentoo bug #331111
142         sed -i '/^check-local: check-perl$/d' "${S}"/config/automake/scripts.am || die
143         sed -i '/^check-local:/s,syntax-check,,g' "${S}"/perl/Makefile.am || die
144
145         # bug with glibc-2.16.0
146         sed -i -e '/gets is a security/d' "${S}"/gnulib/stdio.in.h || die
147
148         eautoreconf
149
150         # places for us to work in
151         mkdir -p "${MYFILESDIR}" || die
152         # Now we store the settings we just created
153         set | egrep "^AMANDA_" | grep -v '^AMANDA_ENV_SETTINGS' > "${TMPENVFILE}" || die
154
155         # Prepare our custom files
156         einfo "Building custom configuration files"
157         local i # our iterator
158         local sedexpr # var for sed expr
159         sedexpr=''
160         for i in ${ENV_SETTINGS_AMANDA} ; do
161                 local val
162                 eval "val=\"\${${i}}\""
163                 sedexpr="${sedexpr}s|__${i}__|${val}|g;"
164         done
165
166         # now apply the sed expr
167         for i in "${FILESDIR}"/amanda-* ; do
168                 sed -re "${sedexpr}" <"${i}" >"${MYFILESDIR}/`basename ${i}`" || die
169         done
170
171         if use minimal; then
172                 cat "${MYFILESDIR}"/amanda-amandahosts-server-2.5.1_p3-r1 > "${T}"/amandahosts || die
173         else
174                 sed -i -e 's:^\(my $amandahomedir\)=.*:\1 = $localstatedir;:' \
175                         server-src/am{addclient,serverconfig}.pl || die
176                 cat "${MYFILESDIR}"/amanda-amandahosts-client-2.5.1_p3-r1 > "${T}"/amandahosts || die
177         fi
178
179         eapply_user
180 }
181
182 src_configure() {
183         # fix bug #36316
184         addpredict /var/cache/samba/gencache.tdb
185         # fix bug #376169
186         addpredict /run/blkid
187         addpredict /etc/blkid.tab
188
189         [ ! -f "${TMPENVFILE}" ] && die "Variable setting file (${TMPENVFILE}) should exist!"
190         source "${TMPENVFILE}"
191         local myconf
192
193         einfo "Using ${AMANDA_SERVER_TAPE} for tape server."
194         myconf="${myconf} --with-tape-server=${AMANDA_SERVER_TAPE}"
195         einfo "Using ${AMANDA_SERVER_TAPE_DEVICE} for tape server."
196         myconf="${myconf} --with-tape-device=${AMANDA_SERVER_TAPE_DEVICE}"
197         einfo "Using ${AMANDA_SERVER_INDEX} for index server."
198         myconf="${myconf} --with-index-server=${AMANDA_SERVER_INDEX}"
199         einfo "Using ${AMANDA_USER_NAME} for amanda user."
200         myconf="${myconf} --with-user=${AMANDA_USER_NAME}"
201         einfo "Using ${AMANDA_GROUP_NAME} for amanda group."
202         myconf="${myconf} --with-group=${AMANDA_GROUP_NAME}"
203         einfo "Using ${AMANDA_TAR} as Tar implementation."
204         myconf="${myconf} --with-gnutar=${AMANDA_TAR}"
205         einfo "Using ${AMANDA_TAR_LISTDIR} as tar listdir."
206         myconf="${myconf} --with-gnutar-listdir=${AMANDA_TAR_LISTDIR}"
207         einfo "Using ${AMANDA_CONFIG_NAME} as default config name."
208         myconf="${myconf} --with-config=${AMANDA_CONFIG_NAME}"
209         einfo "Using ${AMANDA_TMPDIR} as Amanda temporary directory."
210         myconf="${myconf} --with-tmpdir=${AMANDA_TMPDIR}"
211
212         if [ -n "${AMANDA_PORTS_UDP}" ] && [ -n "${AMANDA_PORTS_TCP}" ] && [ -z "${AMANDA_PORTS_BOTH}" ] ; then
213                 eerror "If you want _both_ UDP and TCP ports, please use only the"
214                 eerror "AMANDA_PORTS environment variable for identical ports, or set"
215                 eerror "AMANDA_PORTS_BOTH."
216                 die "Bad port setup!"
217         fi
218         if [ -n "${AMANDA_PORTS_UDP}" ]; then
219                 einfo "Using UDP ports ${AMANDA_PORTS_UDP/,/-}"
220                 myconf="${myconf} --with-udpportrange=${AMANDA_PORTS_UDP}"
221         fi
222         if [ -n "${AMANDA_PORTS_TCP}" ]; then
223                 einfo "Using TCP ports ${AMANDA_PORTS_TCP/,/-}"
224                 myconf="${myconf} --with-tcpportrange=${AMANDA_PORTS_TCP}"
225         fi
226         if [ -n "${AMANDA_PORTS}" ]; then
227                 einfo "Using ports ${AMANDA_PORTS/,/-}"
228                 myconf="${myconf} --with-portrange=${AMANDA_PORTS}"
229         fi
230
231         # Extras
232         # Speed option
233         myconf="${myconf} --with-buffered-dump"
234         # "debugging" in the configuration is NOT debug in the conventional sense.
235         # It is actually just useful output in the application, and should remain
236         # enabled. There are some cases of breakage with MTX tape changers as of
237         # 2.5.1p2 that it exposes when turned off as well.
238         myconf="${myconf} --with-debugging"
239         # Where to put our files
240         myconf="${myconf} --localstatedir=${AMANDA_USER_HOMEDIR}"
241
242         # Samba support
243         myconf="${myconf} $(use_with samba smbclient /usr/bin/smbclient)"
244
245         # Support for BSD, SSH, BSDUDP, BSDTCP security methods all compiled in by
246         # default
247         myconf="${myconf} --with-bsd-security"
248         myconf="${myconf} --with-ssh-security"
249         myconf="${myconf} --with-bsdudp-security"
250         myconf="${myconf} --with-bsdtcp-security"
251
252         # kerberos-security mechanism version 5
253         myconf="${myconf} $(use_with kerberos krb5-security)"
254
255         # Amazon S3 support
256         myconf="${myconf} `use_enable s3 s3-device`"
257
258         # libcurl is required for S3 but otherwise optional
259         if ! use s3; then
260                 myconf="${myconf} $(use_with curl libcurl)"
261         fi
262
263         # Client only, as requested in bug #127725
264         if use minimal ; then
265                 myconf="${myconf} --without-server"
266         else
267                 # amplot
268                 myconf="${myconf} $(use_with gnuplot)"
269         fi
270
271         # IPv6 fun.
272         myconf="${myconf} `use_with ipv6`"
273         # This is to prevent the IPv6-is-working test
274         # As the test fails on binpkg build hosts with no IPv6.
275         use ipv6 && export amanda_cv_working_ipv6=yes
276
277         # I18N
278         myconf="${myconf} `use_enable nls`"
279
280         # Bug #296634: Perl location
281         perl_set_version
282         myconf="${myconf} --with-amperldir=${VENDOR_LIB}"
283
284         # Bug 296633: --disable-syntax-checks
285         # Some tests are not safe for production systems
286         myconf="${myconf} --disable-syntax-checks"
287
288         # build manpages
289         myconf="${myconf} --enable-manpage-build"
290
291         # bug #483120
292         tc-export AR
293
294         econf \
295                 $(use_with readline) \
296                 ${myconf}
297 }
298
299 src_compile() {
300         # Again, do not want the perl-module src_compile
301         default_src_compile
302 }
303
304 src_install() {
305         [ ! -f "${TMPENVFILE}" ] && die "Variable setting file (${TMPENVFILE}) should exist!"
306         source ${TMPENVFILE}
307
308         einfo "Doing stock install"
309         emake DESTDIR="${D}" install
310
311         # Build the envdir file
312         # Don't forget this..
313         einfo "Building environment file"
314         (
315                 echo "# These settings are what was present in the environment when this"
316                 echo "# Amanda was compiled.  Changing anything below this comment will"
317                 echo "# have no effect on your application, but it merely exists to"
318                 echo "# preserve them for your next emerge of Amanda"
319                 cat "${TMPENVFILE}" | sed "s,=\$,='',g"
320         ) >> "${MYFILESDIR}/${ENVDFILE}"
321
322         # Env.d
323         einfo "Installing environment config file"
324         doenvd "${MYFILESDIR}/${ENVDFILE}"
325
326         # Lock down next section (up until docs).
327         insopts -m0640
328         # Installing Amanda Xinetd Services Definition
329         einfo "Installing xinetd service file"
330         insinto /etc/xinetd.d
331         if use minimal ; then
332                 newins "${MYFILESDIR}"/amanda-xinetd-2.6.1_p1-client amanda
333         else
334                 newins "${MYFILESDIR}"/amanda-xinetd-2.6.1_p1-server amanda
335         fi
336
337         if ! use minimal; then
338                 einfo "Installing Sample Daily Cron Job for Amanda"
339                 insinto /etc/cron.daily
340                 newins "${MYFILESDIR}/amanda-cron" amanda
341         fi
342
343         einfo "Installing systemd service and socket files for Amanda"
344         systemd_dounit "${FILESDIR}"/amanda.socket || die
345         systemd_newunit "${FILESDIR}"/amanda.service 'amanda@.service' || die
346
347         insinto /etc/amanda
348         einfo "Installing .amandahosts File for ${AMANDA_USER_NAME} user"
349         doins "${T}/amandahosts"
350         fperms 600 /etc/amanda/amandahosts
351
352         dosym /etc/amanda/amandahosts "${AMANDA_USER_HOMEDIR}/.amandahosts"
353         insinto "${AMANDA_USER_HOMEDIR}"
354         einfo "Installing .profile for ${AMANDA_USER_NAME} user"
355         newins "${MYFILESDIR}/amanda-profile" .profile
356
357         insinto /etc/amanda
358         doins "${S}/example/amanda-client.conf"
359         if ! use minimal ; then
360                 insinto "/etc/amanda/${AMANDA_CONFIG_NAME}"
361                 doins "${S}/example/amanda.conf"
362                 doins "${S}/example/disklist"
363                 keepdir "${AMANDA_USER_HOMEDIR}/${AMANDA_CONFIG_NAME}/index"
364         fi
365
366         keepdir "${AMANDA_TAR_LISTDIR}"
367         keepdir "${AMANDA_USER_HOMEDIR}/amanda"
368         keepdir "${AMANDA_TMPDIR}/dumps"
369         # Just make sure it exists for XFS to work...
370         use xfs && keepdir /var/xfsdump/inventory
371
372         local i
373         for i in "${AMANDA_USER_HOMEDIR}" "${AMANDA_TAR_LISTDIR}" \
374                 "${AMANDA_TMPDIR}" /etc/amanda; do
375                 einfo "Securing directory (${i})"
376                 fowners -R ${AMANDA_USER_NAME}:${AMANDA_GROUP_NAME} ${i}
377         done
378         # Do NOT use -R
379         fperms 0700 \
380                 "${AMANDA_USER_HOMEDIR}" "${AMANDA_TAR_LISTDIR}" \
381                 "${AMANDA_TMPDIR}" "${AMANDA_TMPDIR}/dumps" \
382                  "${AMANDA_USER_HOMEDIR}/amanda" \
383                  /etc/amanda
384
385         if ! use minimal ; then
386                 fperms 0700 \
387                          "${AMANDA_USER_HOMEDIR}/${AMANDA_CONFIG_NAME}" \
388                  /etc/amanda/${AMANDA_CONFIG_NAME}
389         fi
390
391         einfo "Setting setuid permissions"
392         amanda_permissions_fix "${D}"
393
394         # Relax permissions again
395         insopts -m0644
396
397         # docs
398         einfo "Installing documentation"
399         dodoc AUTHORS ChangeLog DEVELOPING NEWS README ReleaseNotes UPGRADING
400         # our inetd sample
401         einfo "Installing standard inetd sample"
402         newdoc "${MYFILESDIR}/amanda-inetd.amanda.sample-2.6.0_p2-r2" amanda-inetd.amanda.sample
403         # Amanda example configs
404         einfo "Installing example configurations"
405         rm "${D}"/usr/share/amanda/{COPYRIGHT,ChangeLog,NEWS,ReleaseNotes}
406         mv "${D}/usr/share/amanda/example" "${D}/usr/share/doc/${PF}/"
407         docinto example1
408         newdoc "${FILESDIR}/example_amanda.conf" amanda.conf
409         newdoc "${FILESDIR}/example_disklist-2.5.1_p3-r1" disklist
410         newdoc "${FILESDIR}/example_global.conf" global.conf
411
412         einfo "Cleaning up dud .la files"
413         perl_set_version
414         find "${D}"/"${VENDOR_LIB}" -name '*.la' -print0 |xargs -0 rm -f
415 }
416
417 pkg_postinst() {
418         [ ! -f "${TMPENVFILE}" -a "$MERGE_TYPE" == "binary" ] && \
419                 TMPENVFILE="${ROOT}${ENVDIR}/${ENVDFILE}"
420         [ ! -f "${TMPENVFILE}" ] && die "Variable setting file (${TMPENVFILE}) should exist!"
421         source "${TMPENVFILE}"
422
423         # Migration of amandates from /etc to $localstatedir/amanda
424         if [ -f "${ROOT}/etc/amandates" -a \
425                 ! -f "${ROOT}/${AMANDA_USER_HOMEDIR}/amanda/amandates" ]; then
426                 einfo "Migrating amandates from /etc/ to ${AMANDA_USER_HOMEDIR}/amanda"
427                 einfo "A backup is also placed at /etc/amandates.orig"
428                 cp -dp "${ROOT}/etc/amandates" "${ROOT}/etc/amandates.orig"
429                 mkdir -p "${ROOT}/${AMANDA_USER_HOMEDIR}/amanda/"
430                 cp -dp "${ROOT}/etc/amandates" "${ROOT}/${AMANDA_USER_HOMEDIR}/amanda/amandates"
431         fi
432         if [ -f "${ROOT}/etc/amandates" ]; then
433                 einfo "If you have migrated safely, please delete /etc/amandates"
434         fi
435
436         einfo "Checking setuid permissions"
437         amanda_permissions_fix "${ROOT}"
438
439         elog "You should configure Amanda in /etc/amanda now."
440         elog
441         elog "If you use xinetd, Don't forget to check /etc/xinetd.d/amanda"
442         elog "and restart xinetd afterwards!"
443         elog
444         elog "Otherwise, please look at /usr/share/doc/${PF}/inetd.amanda.sample"
445         elog "as an example of how to configure your inetd."
446         elog
447         elog "systemd-users: enable and start amanda.socket or the relevant services"
448         elog "regarding what auth method you use."
449         elog
450         elog "NOTICE: If you need raw access to partitions you need to add the"
451         elog "amanda user to the 'disk' group."
452         elog
453         elog "NOTICE: If you have a tape changer, you need to add the amanda user"
454         elog "to the 'tape' group."
455         elog
456         elog "If you use localhost in your disklist your restores may break."
457         elog "You should replace it with the actual hostname!"
458         elog "Please also see the syntax changes to amandahosts."
459         elog "The only exception is when you use the authentication method 'local'."
460         elog
461         elog "Please note that this package no longer explicitly depends on"
462         elog "virtual/inetd, as it supports modes where an inetd is not needed"
463         elog "(see bug #506028 for details)."
464 }
465
466 # We have had reports of amanda file permissions getting screwed up.
467 # Losing setuid, becoming too lax etc.
468 # ONLY root and users in the amanda group should be able to run these binaries!
469 amanda_permissions_fix() {
470         local root="$1"
471         [ -z "${root}" ] && die "Failed to pass root argument to amanda_permissions_fix!"
472         local le="/usr/libexec/amanda"
473         for i in /usr/sbin/amcheck "${le}"/calcsize "${le}"/killpgrp \
474                 "${le}"/rundump "${le}"/runtar "${le}"/dumper \
475                 "${le}"/planner ; do
476                 chown root:${AMANDA_GROUP_NAME} "${root}"/${i}
477                 chmod u=srwx,g=rx,o= "${root}"/${i}
478         done
479 }
480
481 # We do not want the perl-module tests.
482 src_test() {
483         default_src_test
484 }