1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 inherit autotools perl-module user systemd toolchain-funcs
7 DESCRIPTION="The Advanced Maryland Automatic Network Disk Archiver"
8 HOMEPAGE="http://www.amanda.org/"
9 SRC_URI="mirror://sourceforge/amanda/${P}.tar.gz"
11 LICENSE="HPND BSD BSD-2 GPL-2+ GPL-3+"
13 IUSE="curl gnuplot ipv6 kerberos minimal ndmp nls readline s3 samba systemd xfs"
15 KEYWORDS="~amd64 ~ppc ~ppc64 ~sparc ~x86"
16 RDEPEND="sys-libs/readline:=
22 >=dev-libs/glib-2.26.0
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 )
36 gnuplot? ( sci-visualization/gnuplot )
43 nls? ( sys-devel/gettext )
44 >=app-text/docbook-xsl-stylesheets-1.72.0
45 app-text/docbook-xml-dtd
50 MYFILESDIR="${T}/files"
53 TMPENVFILE="${T}/${ENVDFILE}"
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.
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"
69 amanda_variable_setup() {
74 # Grab the current settings
75 currentamanda="$(set | egrep "^AMANDA_" | grep -v '^AMANDA_ENV_SETTINGS' | xargs)"
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}"
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=
103 [[ -z "${AMANDA_TAR}" ]] && AMANDA_TAR=/bin/tar
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')
111 # Re-apply the new settings if any
112 [ -n "${currentamanda}" ] && eval $(echo "${currentamanda}")
117 amanda_variable_setup
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"
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}"
136 # we do not want the perl src_unpack
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
145 # bug with glibc-2.16.0
146 sed -i -e '/gets is a security/d' "${S}"/gnulib/stdio.in.h || die
148 # https://bugs.gentoo.org/701416 sandbox violation
149 sed -i -e 's/case `"$SAMBA_CLIENT.*/case "Connection to nosuchhost.amanda.org failed" in/' "${S}"/config/amanda/dumpers.m4 || die
153 # places for us to work in
154 mkdir -p "${MYFILESDIR}" || die
155 # Now we store the settings we just created
156 set | egrep "^AMANDA_" | grep -v '^AMANDA_ENV_SETTINGS' > "${TMPENVFILE}" || die
158 # Prepare our custom files
159 einfo "Building custom configuration files"
160 local i # our iterator
161 local sedexpr # var for sed expr
163 for i in ${ENV_SETTINGS_AMANDA} ; do
165 eval "val=\"\${${i}}\""
166 sedexpr="${sedexpr}s|__${i}__|${val}|g;"
169 # now apply the sed expr
170 for i in "${FILESDIR}"/amanda-* ; do
171 sed -re "${sedexpr}" <"${i}" >"${MYFILESDIR}/`basename ${i}`" || die
175 cat "${MYFILESDIR}"/amanda-amandahosts-server-2.5.1_p3-r1 > "${T}"/amandahosts || die
177 sed -i -e 's:^\(my $amandahomedir\)=.*:\1 = $localstatedir;:' \
178 server-src/am{addclient,serverconfig}.pl || die
179 cat "${MYFILESDIR}"/amanda-amandahosts-client-2.5.1_p3-r1 > "${T}"/amandahosts || die
187 addpredict /var/cache/samba/gencache.tdb
189 addpredict /run/blkid
190 addpredict /etc/blkid.tab
192 [ ! -f "${TMPENVFILE}" ] && die "Variable setting file (${TMPENVFILE}) should exist!"
193 source "${TMPENVFILE}"
196 einfo "Using ${AMANDA_SERVER_TAPE} for tape server."
197 myconf="${myconf} --with-tape-server=${AMANDA_SERVER_TAPE}"
198 einfo "Using ${AMANDA_SERVER_TAPE_DEVICE} for tape server."
199 myconf="${myconf} --with-tape-device=${AMANDA_SERVER_TAPE_DEVICE}"
200 einfo "Using ${AMANDA_SERVER_INDEX} for index server."
201 myconf="${myconf} --with-index-server=${AMANDA_SERVER_INDEX}"
202 einfo "Using ${AMANDA_USER_NAME} for amanda user."
203 myconf="${myconf} --with-user=${AMANDA_USER_NAME}"
204 einfo "Using ${AMANDA_GROUP_NAME} for amanda group."
205 myconf="${myconf} --with-group=${AMANDA_GROUP_NAME}"
206 einfo "Using ${AMANDA_TAR} as Tar implementation."
207 myconf="${myconf} --with-gnutar=${AMANDA_TAR}"
208 einfo "Using ${AMANDA_TAR_LISTDIR} as tar listdir."
209 myconf="${myconf} --with-gnutar-listdir=${AMANDA_TAR_LISTDIR}"
210 einfo "Using ${AMANDA_CONFIG_NAME} as default config name."
211 myconf="${myconf} --with-config=${AMANDA_CONFIG_NAME}"
212 einfo "Using ${AMANDA_TMPDIR} as Amanda temporary directory."
213 myconf="${myconf} --with-tmpdir=${AMANDA_TMPDIR}"
215 if [ -n "${AMANDA_PORTS_UDP}" ] && [ -n "${AMANDA_PORTS_TCP}" ] && [ -z "${AMANDA_PORTS_BOTH}" ] ; then
216 eerror "If you want _both_ UDP and TCP ports, please use only the"
217 eerror "AMANDA_PORTS environment variable for identical ports, or set"
218 eerror "AMANDA_PORTS_BOTH."
219 die "Bad port setup!"
221 if [ -n "${AMANDA_PORTS_UDP}" ]; then
222 einfo "Using UDP ports ${AMANDA_PORTS_UDP/,/-}"
223 myconf="${myconf} --with-udpportrange=${AMANDA_PORTS_UDP}"
225 if [ -n "${AMANDA_PORTS_TCP}" ]; then
226 einfo "Using TCP ports ${AMANDA_PORTS_TCP/,/-}"
227 myconf="${myconf} --with-tcpportrange=${AMANDA_PORTS_TCP}"
229 if [ -n "${AMANDA_PORTS}" ]; then
230 einfo "Using ports ${AMANDA_PORTS/,/-}"
231 myconf="${myconf} --with-portrange=${AMANDA_PORTS}"
236 myconf="${myconf} --with-buffered-dump"
237 # "debugging" in the configuration is NOT debug in the conventional sense.
238 # It is actually just useful output in the application, and should remain
239 # enabled. There are some cases of breakage with MTX tape changers as of
240 # 2.5.1p2 that it exposes when turned off as well.
241 myconf="${myconf} --with-debugging"
242 # Where to put our files
243 myconf="${myconf} --localstatedir=${AMANDA_USER_HOMEDIR}"
246 myconf="${myconf} $(use_with samba smbclient /usr/bin/smbclient)"
248 # Support for BSD, SSH, BSDUDP, BSDTCP security methods all compiled in by
250 myconf="${myconf} --with-bsd-security"
251 myconf="${myconf} --with-ssh-security"
252 myconf="${myconf} --with-bsdudp-security"
253 myconf="${myconf} --with-bsdtcp-security"
255 # kerberos-security mechanism version 5
256 myconf="${myconf} $(use_with kerberos krb5-security)"
259 myconf="${myconf} `use_enable s3 s3-device`"
261 # libcurl is required for S3 but otherwise optional
263 myconf="${myconf} $(use_with curl libcurl)"
266 # Client only, as requested in bug #127725
267 if use minimal ; then
268 myconf="${myconf} --without-server"
271 myconf="${myconf} $(use_with gnuplot)"
275 myconf="${myconf} `use_with ipv6`"
276 # This is to prevent the IPv6-is-working test
277 # As the test fails on binpkg build hosts with no IPv6.
278 use ipv6 && export amanda_cv_working_ipv6=yes
281 myconf="${myconf} `use_enable nls`"
283 # Bug #296634: Perl location
285 myconf="${myconf} --with-amperldir=${VENDOR_LIB}"
287 # Bug 296633: --disable-syntax-checks
288 # Some tests are not safe for production systems
289 myconf="${myconf} --disable-syntax-checks"
292 myconf="${myconf} --enable-manpage-build"
295 myconf="${myconf} $(use_with ndmp ndmp)"
301 $(use_with readline) \
306 # Again, do not want the perl-module src_compile
311 [ ! -f "${TMPENVFILE}" ] && die "Variable setting file (${TMPENVFILE}) should exist!"
314 einfo "Doing stock install"
315 emake DESTDIR="${D}" install
317 # Build the envdir file
318 # Don't forget this..
319 einfo "Building environment file"
321 echo "# These settings are what was present in the environment when this"
322 echo "# Amanda was compiled. Changing anything below this comment will"
323 echo "# have no effect on your application, but it merely exists to"
324 echo "# preserve them for your next emerge of Amanda"
325 cat "${TMPENVFILE}" | sed "s,=\$,='',g"
326 ) >> "${MYFILESDIR}/${ENVDFILE}"
329 einfo "Installing environment config file"
330 doenvd "${MYFILESDIR}/${ENVDFILE}"
332 einfo "Installing systemd service and socket files for Amanda"
333 systemd_dounit "${FILESDIR}"/amanda.socket
334 systemd_newunit "${FILESDIR}"/amanda.service 'amanda@.service'
336 # Lock down next section (up until docs).
338 # Installing Amanda Xinetd Services Definition
339 einfo "Installing xinetd service file"
340 insinto /etc/xinetd.d
341 if use minimal ; then
342 newins "${MYFILESDIR}"/amanda-xinetd-2.6.1_p1-client amanda
344 newins "${MYFILESDIR}"/amanda-xinetd-2.6.1_p1-server amanda
347 if ! use minimal; then
348 einfo "Installing Sample Daily Cron Job for Amanda"
349 insinto /etc/cron.daily
350 newins "${MYFILESDIR}/amanda-cron" amanda
354 einfo "Installing .amandahosts File for ${AMANDA_USER_NAME} user"
355 doins "${T}/amandahosts"
356 fperms 600 /etc/amanda/amandahosts
358 dosym /etc/amanda/amandahosts "${AMANDA_USER_HOMEDIR}/.amandahosts"
359 insinto "${AMANDA_USER_HOMEDIR}"
360 einfo "Installing .profile for ${AMANDA_USER_NAME} user"
361 newins "${MYFILESDIR}/amanda-profile" .profile
364 doins "${S}/example/amanda-client.conf"
365 if ! use minimal ; then
366 insinto "/etc/amanda/${AMANDA_CONFIG_NAME}"
367 doins "${S}/example/amanda.conf"
368 doins "${S}/example/disklist"
369 keepdir "${AMANDA_USER_HOMEDIR}/${AMANDA_CONFIG_NAME}/index"
372 keepdir "${AMANDA_TAR_LISTDIR}"
373 keepdir "${AMANDA_USER_HOMEDIR}/amanda"
374 keepdir "${AMANDA_TMPDIR}/dumps"
375 # Just make sure it exists for XFS to work...
376 use xfs && keepdir /var/xfsdump/inventory
379 for i in "${AMANDA_USER_HOMEDIR}" "${AMANDA_TAR_LISTDIR}" \
380 "${AMANDA_TMPDIR}" /etc/amanda; do
381 einfo "Securing directory (${i})"
382 fowners -R ${AMANDA_USER_NAME}:${AMANDA_GROUP_NAME} ${i}
386 "${AMANDA_USER_HOMEDIR}" "${AMANDA_TAR_LISTDIR}" \
387 "${AMANDA_TMPDIR}" "${AMANDA_TMPDIR}/dumps" \
388 "${AMANDA_USER_HOMEDIR}/amanda" \
391 if ! use minimal ; then
393 "${AMANDA_USER_HOMEDIR}/${AMANDA_CONFIG_NAME}" \
394 /etc/amanda/${AMANDA_CONFIG_NAME}
397 einfo "Setting setuid permissions"
398 amanda_permissions_fix "${D}"
400 # Relax permissions again
404 einfo "Installing documentation"
405 dodoc AUTHORS ChangeLog DEVELOPING NEWS README ReleaseNotes UPGRADING
407 einfo "Installing standard inetd sample"
408 newdoc "${MYFILESDIR}/amanda-inetd.amanda.sample-2.6.0_p2-r2" amanda-inetd.amanda.sample
409 # Amanda example configs
410 einfo "Installing example configurations"
411 rm "${D}"/usr/share/amanda/{COPYRIGHT,ChangeLog,NEWS,ReleaseNotes} || die
412 mv "${D}/usr/share/amanda/example" "${D}/usr/share/doc/${PF}/" || die
414 newdoc "${FILESDIR}/example_amanda.conf" amanda.conf
415 newdoc "${FILESDIR}/example_disklist-2.5.1_p3-r1" disklist
416 newdoc "${FILESDIR}/example_global.conf" global.conf
418 einfo "Cleaning up dud .la files"
420 find "${D}"/"${VENDOR_LIB}" -name '*.la' -delete || die
424 [ ! -f "${TMPENVFILE}" -a "$MERGE_TYPE" == "binary" ] && \
425 TMPENVFILE="${ROOT}${ENVDIR}/${ENVDFILE}"
426 [ ! -f "${TMPENVFILE}" ] && die "Variable setting file (${TMPENVFILE}) should exist!"
427 source "${TMPENVFILE}"
429 # Migration of amandates from /etc to $localstatedir/amanda
430 if [ -f "${ROOT}/etc/amandates" -a \
431 ! -f "${ROOT}/${AMANDA_USER_HOMEDIR}/amanda/amandates" ]; then
432 einfo "Migrating amandates from /etc/ to ${AMANDA_USER_HOMEDIR}/amanda"
433 einfo "A backup is also placed at /etc/amandates.orig"
434 cp -dp "${ROOT}/etc/amandates" "${ROOT}/etc/amandates.orig" || die
435 mkdir -p "${ROOT}/${AMANDA_USER_HOMEDIR}/amanda/" || die
436 cp -dp "${ROOT}/etc/amandates" "${ROOT}/${AMANDA_USER_HOMEDIR}/amanda/amandates" || die
438 if [ -f "${ROOT}/etc/amandates" ]; then
439 einfo "If you have migrated safely, please delete /etc/amandates"
442 einfo "Checking setuid permissions"
443 amanda_permissions_fix "${ROOT}"
445 elog "You should configure Amanda in /etc/amanda now."
447 elog "If you use xinetd, Don't forget to check /etc/xinetd.d/amanda"
448 elog "and restart xinetd afterwards!"
450 elog "Otherwise, please look at /usr/share/doc/${PF}/inetd.amanda.sample"
451 elog "as an example of how to configure your inetd."
453 elog "systemd-users: enable and start amanda.socket or the relevant services"
454 elog "regarding what auth method you use."
456 elog "NOTICE: If you need raw access to partitions you need to add the"
457 elog "amanda user to the 'disk' group."
459 elog "NOTICE: If you have a tape changer, you need to add the amanda user"
460 elog "to the 'tape' group."
462 elog "If you use localhost in your disklist your restores may break."
463 elog "You should replace it with the actual hostname!"
464 elog "Please also see the syntax changes to amandahosts."
465 elog "The only exception is when you use the authentication method 'local'."
467 elog "Please note that this package no longer explicitly depends on"
468 elog "virtual/inetd, as it supports modes where an inetd is not needed"
469 elog "(see bug #506028 for details)."
472 # We have had reports of amanda file permissions getting screwed up.
473 # Losing setuid, becoming too lax etc.
474 # ONLY root and users in the amanda group should be able to run these binaries!
475 amanda_permissions_fix() {
477 [ -z "${root}" ] && die "Failed to pass root argument to amanda_permissions_fix!"
478 local le="/usr/libexec/amanda"
480 for i in "${le}"/calcsize "${le}"/killpgrp \
481 "${le}"/rundump "${le}"/runtar ; do
482 [ -e "${root}"/${i} ] || continue
483 chown root:${AMANDA_GROUP_NAME} "${root}"/${i} || die
484 chmod u=srwx,g=rx,o= "${root}"/${i} || die
487 # amanda-security.conf is a config file with similar requirements:
488 # writable only by root
490 # 3.3.9: introduced in /etc/amanda-security.conf
491 # 3.4.2: moved to /etc/amanda/amanda-security.conf
492 f=/etc/amanda/amanda-security.conf
493 chown root:root "${root}""${f}" || die
494 chmod u=rw,go=r "${root}""${f}" || die
497 # We do not want the perl-module tests.