Imported Upstream version 3.3.2
[debian/amanda] / packaging / rpm / amanda.spec.src
1 #
2 #                  Copyright (C) 2005-2012 Zmanda Incorporated.
3 #                            All Rights Reserved.
4 #
5 #  This program is free software; you can redistribute it and/or modify it
6 #  under the terms of the GNU General Public License version 2 as published
7 #  by the Free Software Foundation.
8
9 #  This program is distributed in the hope that it will be useful, but
10 #  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 #  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 #  for more details.
13
14 #  You should have received a copy of the GNU General Public License along
15 #  with this program; if not, write to the Free Software Foundation, Inc.,
16 #  59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17
18 #  Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
19 #  Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 #
21
22
23 %define build_srpm 0
24 %{?srpm_only: %define build_srpm 1}
25
26 # Pkg-config sometimes needs its own path set, and we need to allow users to
27 # override our guess during detection.  This macro takes care of that.
28 # If no --define PKG_CONFIG_PATH was passed and env var $PKG_CONFIG_PATH is 
29 # set then use the env var.
30 %{!?PKG_CONFIG_PATH: %{expand:%(echo ${PKG_CONFIG_PATH:+"%%define PKG_CONFIG_PATH $PKG_CONFIG_PATH"})}}
31
32 %{?PKG_CONFIG_PATH:%{echo:PKG_CONFIG_PATH = %{PKG_CONFIG_PATH}}}
33
34 # LDFLAGS: newer gnu linkers can use "-Wl,--as-needed", while older ones,
35 # like rhel3 and sles9 can't.
36 %define enable_as_needed --enable-as-needed
37
38 # Define which Distribution we are building:
39 # Try to detect the distribution we are building:
40 %if %{_vendor} == redhat 
41     # Fedora symlinks /etc/fedora-release to /etc/redhat-release for at least
42     # fc3-8.  So RHEL and Fedora look at the same file.  Different versions have
43     # different numbers of spaces; hence the use if $3 vs. $4..
44     %if %(awk '$1 == "Fedora" && $4 ~ /3.*/ { exit 1; }' /etc/redhat-release; echo $?)
45         %define dist fedora
46         %define disttag fc
47         %define distver 3
48         %define requires_libtermcap Requires: libtermcap.so.2
49         %define curl curl
50     %endif
51     %if %(awk '$1 == "Fedora" && $4 ~ /4.*/ { exit 1; }' /etc/redhat-release; echo $?)
52         %define dist fedora
53         %define disttag fc
54         %define distver 4
55         %define requires_libtermcap Requires: libtermcap.so.2
56         %define curl curl
57     %endif
58     %if %(awk '$1 == "Fedora" && $4 ~ /5.*/ { exit 1; }' /etc/redhat-release; echo $?)
59         %define dist fedora
60         %define disttag fc
61         %define distver 5
62         %define requires_libtermcap Requires: libtermcap.so.2
63         %define curl curl
64     %endif
65     %if %(awk '$1 == "Fedora" && $4 ~ /6.*/ { exit 1; }' /etc/redhat-release; echo $?)
66         %define dist fedora
67         %define disttag fc
68         %define distver 6
69         %define requires_libtermcap Requires: libtermcap.so.2
70         %define curl curl
71     %endif
72     %if %(awk '$1 == "Fedora" && $3 ~ /7.*/ { exit 1; }' /etc/redhat-release; echo $?)
73         %define dist fedora
74         %define disttag fc
75         %define distver 7
76         %define requires_libtermcap Requires: libtermcap.so.2
77         %define curl curl
78     %endif
79     # if macro cannot have an empty test and we're just testing the existance
80     %if %{?fedora:yes}%{!?fedora:no} == yes
81         %define dist fedora
82         %define disttag fc
83         %define distver %{fedora}
84         %if %{distver} <= 8
85             %define requires_libtermcap Requires: libtermcap.so.2
86             %define curl curl
87         %endif
88         %if %{distver} >= 9
89             %define curl libcurl
90         %endif
91         %if %{_host_cpu} == x86_64 && %{_target_cpu} == i686
92                 # Do nothing if PKG_CONFIG_PATH was set by the user above.
93                 %{!?PKG_CONFIG_PATH: %define PKG_CONFIG_PATH /usr/lib/pkgconfig}
94         %endif
95     %endif
96     %if %(awk '$1 == "Red" && $7 ~ /3.*/ { exit 1; }' /etc/redhat-release; echo $?)
97         %define dist redhat
98         %define disttag rhel
99         %define distver 3
100         %define tarver 1.14
101         %define requires_libtermcap Requires: libtermcap.so.2
102         %define curl curl
103         %define without_ipv6 --without-ipv6
104     %endif
105     %if %(awk '$1 == "Red" && $7 ~ /4.*/ { exit 1; }' /etc/redhat-release; echo $?)
106         %define dist redhat
107         %define disttag rhel
108         %define distver 4
109         %define tarver 1.14
110         %define requires_libtermcap Requires: libtermcap.so.2
111         %define curl curl
112     %endif
113     %if %(awk '$1 == "CentOS" && $3 ~ /4.*/ { exit 1; }' /etc/redhat-release; echo $?)
114         %define dist redhat
115         %define disttag rhel
116         %define distver 4
117         %define tarver 1.14
118         %define requires_libtermcap Requires: libtermcap.so.2
119         %define curl curl
120     %endif
121     %if %(awk '$1 == "Red" && $7 ~ /5.*/ { exit 1; }' /etc/redhat-release; echo $?)
122         %define dist redhat
123         %define disttag rhel
124         %define distver 5
125         %define curl curl
126     %endif
127     %if %(awk '$1 == "CentOS" && $3 ~ /5.*/ { exit 1; }' /etc/redhat-release; echo $?)
128         %define dist redhat
129         %define disttag rhel
130         %define distver 5
131         %define curl curl
132     %endif
133     %if %(awk '$1 == "Red" && $7 ~ /6.*/ { exit 1; }' /etc/redhat-release; echo $?)
134         %define dist redhat
135         %define disttag rhel
136         %define distver 6
137         %define curl libcurl
138     %endif
139     
140     # If dist is undefined, we didn't detect.
141     %{!?dist:%define dist unknown}
142 %endif
143 # Detect Suse variants. 
144 %if %{_vendor} == "suse"
145     %define dist SuSE
146     %if %(awk '$1 == "openSUSE" { exit 1; }' /etc/SuSE-release; echo $?)
147         %define disttag suse
148         %define distver %(awk '$1=="openSUSE" {print $2}' /etc/SuSE-release)
149     %endif
150     %if %(awk '$1 == "SUSE" { exit 1; }' /etc/SuSE-release; echo $?)
151         %define disttag %(awk '$1=="SUSE" {$3=="Enterprise" ? TAG="sles" : TAG="suse" ; print TAG}' /etc/SuSE-release)
152         %define distver %(awk '$1=="SUSE" {$3=="Enterprise" ? VER=$5 : VER=$3 ; print VER}' /etc/SuSE-release)
153         # Always use quotes in rpm comparisons if values could be interpreted
154         # as integers.
155         %define curl curl
156         %if "%{distver}" == "9"
157             %undefine enable_as_needed
158         %endif
159     %endif
160 %endif
161
162 # Set options per distribution
163 %if %{dist} == redhat || %{dist} == fedora
164     %define rpm_group Applications/Archiving
165     %define xinetd_reload restart
166     %define requires_initscripts Requires: initscripts
167 %endif
168 %if %{dist} == SuSE
169     %define rpm_group Productivity/Archiving/Backup
170     %define xinetd_reload restart
171 %endif
172
173 # Let's die if we haven't detected the distro. This might save some frustration.
174 # RPM does not provide a way to  exit gracefully, hence the tag_to_cause_exit. 
175 %{!?distver: %{error:"Your distribution and its version were not detected."}; %tag_to_cause_exit }
176 # Set minimum tar version if it wasn't set in the per-distro section
177 %{!?tarver: %define tarver 1.15}
178
179 %define packer %(%{__id_u} -n)
180
181 # --- Definitions ---
182
183 # Define amanda_version using the value determined by
184 # packaging/common/substitute.pl.
185 %{!?amanda_version: %define amanda_version %%VERSION%% }
186 %{!?amanda_release: %define amanda_release 1}
187 %define amanda_version_info "Amanda Community Edition - version %{amanda_version}"
188 %define amanda_user amandabackup
189 %define amanda_group disk
190
191 Summary: The Amanda Backup and Archiving System
192 Name: amanda
193 Version: %{amanda_version}
194 %define rpm_release %{amanda_release}.%{disttag}%{distver}
195 %if %{build_srpm}
196 %define rpm_release %{amanda_release}
197 %endif
198 Release: %{rpm_release}
199 Source: %{name}-%{version}.tar.gz
200 License: http://wiki.zmanda.com/index.php/Amanda_Copyright
201 Vendor: Zmanda, Inc.
202 Packager: www.zmanda.com
203 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%{packer}-buildroot
204 Group: %{rpm_group}
205 # TODO - Need required versions for these:
206 BuildRequires: autoconf
207 BuildRequires: automake
208 BuildRequires: binutils
209 BuildRequires: bison
210 BuildRequires: flex
211 BuildRequires: gcc
212 BuildRequires: glib2 >= 2.2.0
213 BuildRequires: glib2-devel
214 BuildRequires: readline
215 # Note: newer distros have changed most *-devel to lib*-devel, and added a
216 # provides tag for backwards compat.
217 BuildRequires: readline-devel
218 BuildRequires: %{curl} >= 7.10.0
219 BuildRequires: %{curl}-devel >= 7.10.0
220 BuildRequires: openssl
221 BuildRequires: openssl-devel
222 BuildRequires: perl(ExtUtils::Embed)
223 Requires: /bin/awk
224 Requires: /bin/date
225 Requires: /usr/bin/id
226 Requires: /sbin/ldconfig
227 Requires: /bin/sh
228 Requires: /usr/sbin/useradd
229 Requires: /usr/sbin/usermod
230 Requires: fileutils
231 Requires: grep
232 Requires: gnuplot
233 Requires: %{curl} >= 7.10.0
234 Requires: openssl
235 Requires: xinetd
236 Requires: perl >= 5.6.0
237 Requires: tar >= %{tarver}
238 Requires: readline
239 %{?requires_libtermcap}
240 %{?requires_initscripts}
241
242 %package backup_client
243 Summary: The Amanda Backup and Archiving Client
244 Group: %{rpm_group}
245 Requires: /bin/awk
246 Requires: fileutils
247 Requires: grep
248 %{?requires_libtermcap}
249 %{?requires_initscripts}
250 Requires: xinetd
251 Requires: perl >= 5.6.0
252 Requires: tar >= %{tarver}
253 Requires: readline
254 Provides: amanda-backup_client = %{amanda_version}
255 Provides: libamclient-%{version}.so = %{amanda_version}
256 Provides: libamanda-%{version}.so = %{amanda_version}
257 Conflicts: amanda-backup_server
258 # Native package names
259 Obsoletes: amanda, amanda-client, amanda-server
260
261 %package backup_server
262 Summary: The Amanda Backup and Archiving Server
263 Group: %{rpm_group}
264 Requires: /bin/awk
265 Requires: fileutils
266 Requires: grep
267 %{?requires_libtermcap}
268 %{?requires_initscripts}
269 Requires: xinetd
270 Requires: perl >= 5.6.0
271 Requires: tar >= %{tarver}
272 Provides: amanda-backup_server = %{amanda_version}
273 Provides: libamclient-%{version}.so = %{amanda_version}
274 Provides: libamanda-%{version}.so = %{amanda_version}
275 Provides: libamserver-%{version}.so = %{amanda_version}
276 Provides: libamtape-%{version}.so = %{amanda_version}
277 Provides: libamdevice-%{version}.so = %{amanda_version}
278 Conflicts: amanda-backup_client
279 # Native package names
280 Obsoletes: amanda, amanda-client, amanda-server
281 # --- Package descriptions ---
282
283 %description
284 Amanda is the leading Open-Source Backup and Archiving software.
285
286 The amanda-backup_server package should be installed on the Amanda server, i.e. 
287 the machine attached to backup media (such as a tape drive or disk 
288 drives) where backups will be written. The amanda-backup_server package
289 includes Amanda client.  The amanda-backup_client package needs 
290 to be installed on every system that is being backed up.
291
292 Amanda Forums is located at: http://forums.zmanda.com/
293 Amanda Documentation is available at: http://wiki.zmanda.com/
294
295
296
297 %description backup_server
298 Amanda is the leading Open-Source Backup and Archiving software.
299
300 This package contains the Amanda server.  The amanda-backup_server package 
301 should be installed on the Amanda server, i.e. the machine attached 
302 to backup media (such as a tape drive or disk drives) where backups 
303 will be written.  The amanda-backup_server package includes Amanda client.
304
305 Amanda Forums is located at: http://forums.zmanda.com/
306 Amanda Documentation is available at: http://wiki.zmanda.com/
307
308
309
310 %description backup_client
311 Amanda is the leading Open-Source Backup and Archiving software.
312
313 This package contains the Amanda client.  The amanda-backup_client package  
314 needs to be installed on every system that is being backed up.
315
316 Amanda Forums is located at: http://forums.zmanda.com/
317 Amanda Documentation is available at: http://wiki.zmanda.com/
318
319 # --- Directory setup ---
320
321 # Configure directories:
322 %define PREFIX          /usr
323 %define EPREFIX         %{PREFIX}
324 %define BINDIR          %{EPREFIX}/bin
325 %define SBINDIR         %{EPREFIX}/sbin
326 %define LIBEXECDIR      %{EPREFIX}/libexec
327 %define AMLIBEXECDIR    %{LIBEXECDIR}/amanda
328 %define DATADIR         %{PREFIX}/share
329 %define SYSCONFDIR      /etc
330 %define LOCALSTATEDIR   /var
331 %define AMANDATES       %{AMANDAHOMEDIR}/amandates
332 %define AMANDAHOMEDIR   %{LOCALSTATEDIR}/lib/amanda
333 %ifarch x86_64
334 %define LIBDIR          %{EPREFIX}/lib64
335 %else
336 %define LIBDIR          %{EPREFIX}/lib
337 %endif
338 %define AMLIBDIR        %{LIBDIR}/amanda
339 %define INCLUDEDIR      %{PREFIX}/include
340 %define MANDIR          %{DATADIR}/man
341 %define LOGDIR          /var/log/amanda
342 %define PERLSITELIB     %(eval "`perl -V:installsitelib`"; echo $installsitelib)
343 %define AMDATADIR       /var/lib/amanda
344
345 # Installation directories:
346 %define ROOT_SBINDIR            %{buildroot}/%{SBINDIR}
347 %define ROOT_LIBEXECDIR         %{buildroot}/%{LIBEXECDIR}
348 %define ROOT_DATADIR            %{buildroot}/%{DATADIR}
349 %define ROOT_LOCALSTATEDIR      %{buildroot}/%{LOCALSTATEDIR}
350 %define ROOT_SYSCONFDIR         %{buildroot}/%{SYSCONFDIR}
351 %define ROOT_AMANDAHOMEDIR      %{buildroot}/%{AMANDAHOMEDIR}
352 %define ROOT_LIBDIR             %{buildroot}/%{LIBDIR}
353 %define ROOT_MANDIR             %{buildroot}/%{MANDIR}
354 %define ROOT_LOGDIR             %{buildroot}/%{LOGDIR}
355 %define ROOT_AMDATADIR          %{buildroot}/%{AMDATADIR}
356
357 # --- Unpack ---
358
359 %prep
360 %setup -q
361 # --- Configure and compile ---
362
363 %build
364 %define config_user %{amanda_user}
365 %define config_group %{amanda_group}
366
367 # Set PKG_CONFIG_PATH=some/path if some/path was set on the command line, or by 
368 # the platform detection bits.
369 # without_ipv6 should only be defined on rhel3.
370 # LDFLAGS macro is defined except on rhel3.
371 # --enable-as-needed must be conditional until configure tests whether
372 # ld can accept --as-needed.
373 ./configure \
374         %{?PKG_CONFIG_PATH: PKG_CONFIG_PATH=%PKG_CONFIG_PATH} \
375         CFLAGS="%{optflags} -g -pipe" CXXFLAGS="%{optflags}" \
376         %{?LDFLAGS:LDFLAGS="${LDFLAGS} %{?LDFLAGS:%LDFLAGS}"} \
377         %{?enable_as_needed:%{enable_as_needed}} \
378         --quiet \
379         --prefix=%{PREFIX} \
380         --sysconfdir=%{SYSCONFDIR} \
381         --sharedstatedir=%{LOCALSTATEDIR} \
382         --localstatedir=%{LOCALSTATEDIR} \
383         --libdir=%{LIBDIR} \
384         --includedir=%{INCLUDEDIR} \
385         --mandir=%{MANDIR} \
386         --with-amdatadir=%{AMDATADIR} \
387         --with-gnuplot=/usr/bin/gnuplot \
388         --with-gnutar=/bin/tar \
389         --with-gnutar-listdir=%{AMANDAHOMEDIR}/gnutar-lists \
390         --with-index-server=localhost \
391         --with-tape-server=localhost \
392         --with-user=%{config_user} \
393         --with-group=%{config_group} \
394         --with-owner=%{packer} \
395         --with-fqdn \
396         --with-bsd-security \
397         --with-bsdtcp-security \
398         --with-bsdudp-security \
399         --with-ssh-security \
400         --with-debugging=%{LOGDIR} \
401         --with-assertions \
402         --disable-installperms \
403         %{?without_ipv6}
404
405 make -s LIBTOOLFLAGS=--silent
406
407 # --- Install to buildroot ---
408
409 %install
410 if [ "%{buildroot}" != "/" ]; then
411         if [ -d "%{buildroot}" ] ; then
412                 rm -rf %{buildroot}
413         fi
414 else
415         echo "BuildRoot was somehow set to / !"
416         exit -1
417 fi
418
419 make -s -j1 LIBTOOLFLAGS=--silent DESTDIR=%{buildroot} install
420
421 rm -f %{ROOT_AMANDAHOMEDIR}/example/inetd.conf.amandaclient
422 mkdir %{buildroot}/{etc,var/log}
423 mkdir %{ROOT_LOCALSTATEDIR}/amanda 
424 mkdir %{ROOT_SYSCONFDIR}/amanda
425 mkdir %{ROOT_AMANDAHOMEDIR}/gnutar-lists
426 mkdir %{ROOT_LOGDIR}
427
428 echo "%{amanda_version_info}" >%{ROOT_AMANDAHOMEDIR}/amanda-release
429
430 # --- Clean up buildroot ---
431
432 %clean
433 if [ "%{buildroot}" != "/" ]; then
434         if [ -d "%{buildroot}" ] ; then
435                 rm -rf %{buildroot}
436         fi
437 else
438         echo "BuildRoot was somehow set to / !"
439         exit -1
440 fi
441
442 # --- Pre/post (un)installation scripts ---
443
444 # Define script variables
445 # Some versions of rpmbuild do not like multi-line macros in spec files. ugly.
446 %define script_vars amanda_user=%{amanda_user}; amanda_group=%{amanda_group}; AMANDAHOMEDIR=%{AMANDAHOMEDIR}; os=Linux; wanted_shell=/bin/bash; dist=%{dist}; LOGDIR=%{LOGDIR}; INSTALL_LOG=$LOGDIR/install.log; SYSCONFDIR=%{SYSCONFDIR}; SBINDIR=%{SBINDIR};
447 # --- Pre/post (un)installation scripts ---
448
449 %pre backup_server
450 ##########################################
451 LOGFILE=`mktemp /tmp/amanda_server-preinst.log.XXXXXXXXXXX`
452 if [ $? -ne 0 ]; then
453         echo "Unable to create log file!"
454         exit 1
455 fi
456 %{script_vars}
457
458
459 # See packaging/common/ for shell function libraries.
460 # ---------- Common functions ------------
461 %%COMMON_FUNCTIONS%%
462 %%PRE_INST_FUNCTIONS%%
463
464 # -------- End Common functions ----------
465 logger "Preparing to install: Amanda Server %%VERSION%%"
466 create_user
467 check_user_group "${amanda_group}" || add_group "${amanda_group}"
468 check_user_supplemental_group "tape" || add_group "tape"
469 check_user_shell "${wanted_shell}"
470 check_user_homedir "${AMANDAHOMEDIR}"
471 check_homedir || create_homedir
472 create_logdir
473
474 logger "Preinstall done."
475 cat $LOGFILE > $INSTALL_LOG && rm $LOGFILE || \
476     echo "Amanda preinstall logs can be found in '$LOGFILE'."
477
478 %post backup_server
479 ##########################################
480 LOGFILE=`mktemp /tmp/amanda_server-postinst.log.XXXXXXXXXXX`
481 if [ $? -ne 0 ]; then
482         echo "Unable to create log file!"
483         exit 1
484 fi
485 %{script_vars}
486 AMANDATES=%{AMANDATES}
487
488 # ---------- Common functions ------------
489 %%COMMON_FUNCTIONS%%
490 %%POST_INST_FUNCTIONS%%
491
492 # -------- End Common functions ----------
493 /sbin/ldconfig
494
495 check_xinetd "amandaserver"
496 case $? in
497         0) backup_xinetd "amandaserver"
498            install_xinetd "amandaserver"
499         ;;
500         1) install_xinetd "amandaserver" ;;
501         2) logger "Xinetd config not installed: either xinetd config is not present or xinetd.d is a file." ;;
502         *) logger "bad return from check_xinetd"; exit 1 ;;
503 esac
504
505 # Amanda servers should not have the client xinetd installed.
506 check_xinetd "amandaclient"
507 case $? in
508         0) backup_xinetd "amandaclient" ;;
509 esac
510
511 reload_xinetd
512 create_amandates
513 check_amandates
514 create_gnupg
515 check_gnupg
516 create_amandahosts
517 check_amandahosts_entry root amindexd amidxtaped
518 check_amandahosts_entry ${amanda_user} amdump
519 check_amandahosts_perms
520 create_ssh_key server
521 create_ssh_key client
522 create_profile
523 check_profile
524 install_client_conf
525 create_ampassphrase
526
527 logger "Amanda installation complete."
528 cat $LOGFILE >> $INSTALL_LOG && {
529     rm $LOGFILE;
530     echo "Amanda installation log can be found in '${INSTALL_LOG}'.";
531 } || \
532     echo "Amanda postinstall logs can be found in '$LOGFILE'."
533
534 %postun backup_server
535 ##########################################
536 LOGFILE=`mktemp /tmp/amanda_server-remove.log.XXXXXXXXXXX`
537 if [ $? -ne 0 ]; then
538         echo "Unable to create log file!"
539         exit 1
540 fi
541 %{script_vars}
542
543 # ---------- Common functions ------------
544 %%COMMON_FUNCTIONS%%
545 %%POST_RM_FUNCTIONS%%
546
547 # -------- End Common functions ----------
548 /sbin/ldconfig
549 # Check for parameter to script (are we upgrading?)
550 if [ $1 -gt 0 ]; then
551     # We're upgrading
552     action="upgrade"
553 else
554     # We're uninstalling
555     action="uninstall"
556 fi
557
558 # See http://fedoraproject.org/wiki/Packaging/ScriptletSnippets for the reason
559 # we only remove xinetd on uninstall.
560 if [ "$action" = "uninstall" ]; then
561     # Check for and remove existing xinetd configs
562     check_xinetd "amandaserver"
563     if [ $? -eq 0 ] ; then
564         rm_xinetd "amandaserver"
565         reload_xinetd
566     fi
567     check_inetd "amandaserver"
568     if [ $? -eq 0 ] ; then
569         rm_inetd "amandaserver"
570         reload_inetd
571     fi
572     if [ -d ${SYSCONFDIR}/amanda ]; then
573         logger "Removing ${SYSCONFDIR}/amanda if empty..."
574         rmdir ${SYSCONFDIR}/amanda 2> /dev/null || true
575     fi
576     if [ -d ${AMANDAHOMEDIR} ]; then
577         logger "Removing ${AMANDAHOMEDIR}..."
578         rm -rf ${AMANDAHOMEDIR}
579     fi
580     if [ -f ${SYSCONFDIR}/amandates ]; then
581         logger "Removing ${SYSCONFDIR}/amandates..."
582         rm -rf ${SYSCONFDIR}/amandates
583     fi
584     # Remove ${amanda_user} from sensitive groups.
585     if which deluser >/dev/null 2>&1 ; then
586         for group in tape; do
587             # only call deluser when amandabackup is in $group
588             if getent group "$group" |
589                 awk -F: '{ print $4 }' |
590                 awk -F, '{ for (i=1; i <= NF; i++ ) print $i }' |
591                 grep "^${amanda_user}$" > /dev/null; then
592                     deluser ${amanda_user} $group || true
593             fi
594         done
595     fi
596
597 fi
598
599 echo "Amanda removal log can be found in '$LOGFILE'."
600
601 %pre backup_client
602 ##########################################
603 LOGFILE=`mktemp /tmp/amanda_client-preinst.log.XXXXXXXXXXX`
604 if [ $? -ne 0 ]; then
605         echo "Unable to create log file!"
606         exit 1
607 fi
608 %{script_vars}
609
610 # ---------- Common functions ------------
611 %%COMMON_FUNCTIONS%%
612 %%PRE_INST_FUNCTIONS%%
613
614 # -------- End Common functions ----------
615 logger "Preparing to install: %{amanda_version_info}" 
616 create_user
617 check_user_group "${amanda_group}" || add_group "${amanda_group}"
618 check_user_shell "${wanted_shell}"
619 check_user_homedir "${AMANDAHOMEDIR}"
620 check_homedir || create_homedir
621 create_logdir
622
623 logger "Preinstall done."
624 cat $LOGFILE >> $INSTALL_LOG && rm $LOGFILE || \
625     echo "Amanda preinstall logs can be found in '$LOGFILE'."
626
627 %post backup_client
628 ##########################################
629 LOGFILE=`mktemp /tmp/amanda_client-postinst.log.XXXXXXXXXXX`
630 if [ $? -ne 0 ]; then
631         echo "Unable to create log file!"
632         exit 1
633 fi
634 %{script_vars}
635 AMANDATES=%{AMANDATES}
636
637 # ---------- Common functions ------------
638 %%COMMON_FUNCTIONS%%
639 %%POST_INST_FUNCTIONS%%
640
641 # -------- End Common functions ----------
642 /sbin/ldconfig
643
644 check_xinetd "amandaclient"
645 case $? in
646         0) backup_xinetd "amandaclient"
647            install_xinetd "amandaclient"
648         ;;
649         1) install_xinetd "amandaclient" ;;
650         2) logger "Xinetd config not installed: either xinetd config is not present or xinetd.d is a file." ;;
651         *) logger "bad return from check_xinetd"; exit 1 ;;
652 esac
653
654 # Amanda clients should not have the server xinetd installed.
655 check_xinetd "amandaserver"
656 case $? in
657         0) backup_xinetd "amandaserver" ;;
658 esac
659
660 reload_xinetd
661 create_amandates
662 check_amandates
663 create_gnupg
664 check_gnupg
665 create_amandahosts
666 check_amandahosts_entry ${amanda_user} amdump
667 check_amandahosts_perms
668 create_ssh_key server
669 create_ssh_key client
670 create_profile
671 check_profile
672 install_client_conf
673
674 logger "Amanda installation complete."
675 cat $LOGFILE >> $INSTALL_LOG && {
676     rm $LOGFILE;
677     echo "Amanda installation log can be found in '${INSTALL_LOG}'.";
678 } || \
679     echo "Amanda postinstall logs can be found in '$LOGFILE'."
680
681 echo "`date +'%b %e %Y %T'`: Sending anonymous distribution and version information to Zmanda" >> ${INSTALL_LOG}
682 if [ -x /usr/bin/wget ]; then 
683         /usr/bin/wget -q -o /dev/null -O - --timeout=5 http://www.zmanda.com/amanda-tips.php\?version=%{amanda_version}\&os=%{disttag}%{distver}\&type=client 
684 fi
685
686 %postun backup_client
687 ##########################################
688 LOGFILE=`mktemp /tmp/amanda_client-remove.log.XXXXXXXXXXX`
689 if [ $? -ne 0 ]; then
690         echo "Unable to create log file!"
691         exit 1
692 fi
693 %{script_vars}
694
695 # ---------- Common functions ------------
696 %%COMMON_FUNCTIONS%%
697 %%POST_RM_FUNCTIONS%%
698
699 # -------- End Common functions ----------
700 /sbin/ldconfig
701
702 # Check for parameter to script (are we upgrading?)
703 if [ $1 -gt 0 ]; then
704     # We're upgrading
705     action="upgrade"
706 else
707     # We're uninstalling
708     action="uninstall"
709 fi
710
711 # See http://fedoraproject.org/wiki/Packaging/ScriptletSnippets for the reason
712 # we only remove xinetd on uninstall.
713 if [ "$action" = "uninstall" ]; then
714     # Check for and remove existing xinetd configs
715     check_xinetd "amandaclient"
716     if [ $? -eq 0 ] ; then
717         rm_xinetd "amandaclient"
718         reload_xinetd
719     fi
720     check_inetd "amandaclient"
721     if [ $? -eq 0 ] ; then
722         rm_inetd "amandaclient"
723         reload_inetd
724     fi
725     if [ -d ${SYSCONFDIR}/amanda ]; then
726         logger "Removing ${SYSCONFDIR}/amanda if empty..."
727         rmdir ${SYSCONFDIR}/amanda 2> /dev/null || true
728     fi
729     if [ -d ${AMANDAHOMEDIR} ]; then
730         logger "Removing ${AMANDAHOMEDIR}..."
731         rm -rf ${AMANDAHOMEDIR}
732     fi
733     if [ -f ${SYSCONFDIR}/amandates ]; then
734         logger "Removing ${SYSCONFDIR}/amandates..."
735         rm -rf ${SYSCONFDIR}/amandates
736     fi
737     # Remove ${amanda_user} from sensitive groups.
738     if which deluser >/dev/null 2>&1 ; then
739         for group in tape; do
740             # only call deluser when amandabackup is in $group
741             if getent group "$group" |
742                 awk -F: '{ print $4 }' |
743                 awk -F, '{ for (i=1; i <= NF; i++ ) print $i }' |
744                 grep "^${amanda_user}$" > /dev/null; then
745                     deluser ${amanda_user} $group || true
746             fi
747         done
748     fi
749 fi
750
751 echo "Amanda removal log can be found in '$LOGFILE'."
752
753 %files backup_client
754 # --- Files to install ---
755 # Notes:  Do not use wildcards on directories not wholly owned by amanda.  An
756 # uninstall of the software will attempt to delete whatever matches here.
757 %defattr(0755,%{amanda_user},%{amanda_group},0755)
758 %{AMLIBEXECDIR}
759 %{AMLIBDIR}
760 %{PERLSITELIB}/auto/Amanda
761 %defattr(4750,root,disk)
762 %{AMLIBEXECDIR}/application/amgtar
763 %{AMLIBEXECDIR}/application/amstar
764 %{AMLIBEXECDIR}/calcsize
765 %{AMLIBEXECDIR}/killpgrp
766 %{AMLIBEXECDIR}/rundump
767 %{AMLIBEXECDIR}/runtar
768 %defattr(0750,%{amanda_user},%{amanda_group},0750)
769 %{LOGDIR}
770 %{SBINDIR}/amaespipe
771 %{SBINDIR}/amcryp*
772 %{SBINDIR}/amgpgcrypt
773 %{SBINDIR}/amoldrecover
774 %{SBINDIR}/amrecover
775 %{SYSCONFDIR}/amanda
776 %defattr(0644,%{amanda_user},%{amanda_group},0755)
777 %{LOCALSTATEDIR}/amanda
778 %{PERLSITELIB}/Amanda
779 %{AMLIBEXECDIR}/amcat.awk
780 %{AMANDAHOMEDIR}/gnutar-lists
781 %doc %{AMANDAHOMEDIR}/amanda-release
782 %doc %{AMANDAHOMEDIR}/example/xinetd.amandaclient
783 %doc %{AMANDAHOMEDIR}/example/xinetd.amandaserver
784 %doc %{AMANDAHOMEDIR}/example/amanda-client.conf
785 %doc %{AMANDAHOMEDIR}/template.d/README
786 %doc %{AMANDAHOMEDIR}/template.d/dumptypes
787 %defattr(0644,root,root,0755)
788 %docdir %{MANDIR}
789 %{MANDIR}/man5/amanda.conf.5.gz
790 %{MANDIR}/man5/amanda-client.conf.5.gz
791 %{MANDIR}/man7/amanda-devices.7.gz
792 %{MANDIR}/man7/amanda-applications.7.gz
793 %{MANDIR}/man7/amanda-scripts.7.gz
794 %{MANDIR}/man8/amaespipe.8.gz
795 %{MANDIR}/man8/amanda.8.gz
796 %{MANDIR}/man8/amcheckdump.8.gz
797 %{MANDIR}/man8/amcrypt*
798 %{MANDIR}/man8/amgpgcrypt.8.gz
799 %{MANDIR}/man8/amrecover.8.gz
800 %doc %{DATADIR}/amanda
801
802 %files backup_server
803 %defattr(0755,%{amanda_user},%{amanda_group})
804 %{AMLIBEXECDIR}
805 %{AMLIBDIR}
806 %{PERLSITELIB}/Amanda
807 %{PERLSITELIB}/auto/Amanda
808 %{AMANDAHOMEDIR}
809 %{LOCALSTATEDIR}/amanda
810 %{SBINDIR}/am*
811 %defattr(4750,root,disk)
812 %{AMLIBEXECDIR}/application/amgtar
813 %{AMLIBEXECDIR}/application/amstar
814 %{AMLIBEXECDIR}/calcsize
815 %{AMLIBEXECDIR}/killpgrp
816 %{AMLIBEXECDIR}/rundump
817 %{AMLIBEXECDIR}/runtar
818 %{AMLIBEXECDIR}/dumper
819 %{AMLIBEXECDIR}/planner
820 %{SBINDIR}/amcheck
821 %{SBINDIR}/amservice
822 %defattr(0750,%{amanda_user},%{amanda_group},0750)
823 %{LOGDIR}
824 %{SYSCONFDIR}/amanda
825 # Files in standard dirs must be listed explicitly
826 %{SBINDIR}/activate-devpay
827 %{SBINDIR}/amaespipe
828 %{SBINDIR}/amcrypt
829 %{SBINDIR}/amcrypt-ossl
830 %{SBINDIR}/amcrypt-ossl-asym
831 %{SBINDIR}/amcryptsimple
832 %{SBINDIR}/amgpgcrypt
833 %{SBINDIR}/amoldrecover
834 %{SBINDIR}/amrecover
835 %defattr(0644,%{amanda_user},%{amanda_group})
836 %{AMLIBEXECDIR}/amcat.awk
837 %{AMLIBEXECDIR}/amplot.awk
838 %{AMLIBEXECDIR}/amplot.g
839 %{AMLIBEXECDIR}/amplot.gp
840 %doc %{AMANDAHOMEDIR}/amanda-release
841 %docdir %{AMANDAHOMEDIR}/example
842 %docdir %{AMANDAHOMEDIR}/template.d
843 %defattr(0644,root,root,0755)
844 %docdir %{MANDIR}
845 %{MANDIR}/man5/am*
846 %{MANDIR}/man5/disklist.5.gz
847 %{MANDIR}/man5/tapelist.5.gz
848 %{MANDIR}/man7/am*
849 %{MANDIR}/man8/am*
850 %{MANDIR}/man8/script-email.8.gz
851 %doc %{DATADIR}/amanda
852
853 # --- ChangeLog
854
855 %changelog
856 * Fri Aug 20 2010 Dan Locks <dwlocks at zmanda dot com> 3.2.0alpha
857 - use %%VERSION%% macro instead of reading a file.  error reported by ssgelm
858 * Thu Aug 19 2010 Dan Locks <dwlocks at zmanda dot com> 3.2.0alpha
859 - Added detection of openSuSE 11 as suggested by ssgelm