Imported Upstream version 3.3.2
[debian/amanda] / packaging / rpm / buildpkg
1 #!/bin/bash
2
3 # Buildpkg script for producing RPM packages. (Does not require root access.)
4 # Buildpkg is designed to be used by both buildbot (to automate rpm production)
5 # and by J Random User (to build an rpm for kicks).  The odd way of handling
6 # all optioins through environment variables is a product of buildbot.
7 #
8 # AMVER: the version of amanda we're working on.  This will become part of the
9 #     rpm name.  AMVER must line up with the version number mentioned in the
10 #     .spec file.
11 # PKG_DIR: Rpmbuild expects absolute paths, so we provide this var.  It also
12 #     allows you to build somewhere other than `pwd`.  You probably don't want
13 #     to use the system-wide location, as the script tries to blow these
14 #     directories away.
15
16 # Other Hints:
17 # Not everyone will want to use the ./configure options we provide.  The
18 # easiest way to change them is by editing the .spec file.  This isn't so
19 # easy, unfortunately.  Look at the %build section, and the %define xxxx 
20 # statements immediately above it. good luck.
21
22 # This is useful for debugging
23  set -x
24 # Check for $AMVER, or pull it from configure.in
25 if [ -z $AMVER ]; then
26     VER=`cat FULL_VERSION`
27     AMVER=amanda-${VER}
28 fi
29
30 # Until we get package revisioning in community.
31 [ -f "PKG_REV" ] || echo "1" > PKG_REV
32
33 [ -f "./configure" ] || \
34     { echo "./configure does not exist, please run ./autogen"; exit 1; }
35
36 # Substitute amanda.spec.src
37 /usr/bin/perl packaging/common/substitute.pl \
38     packaging/rpm/amanda.spec.src packaging/rpm/amanda.spec || exit 1
39
40 PKG_TARBALL=${AMVER}.tar.gz
41 if [ ! -f "${PKG_TARBALL}" ]; then
42     mkdir ${AMVER} || exit 1
43     cp -Rfp * ${AMVER}/
44     tar -cf ${PKG_TARBALL} -z ${AMVER} || exit 1
45     rm -rf ${AMVER} || exit 1
46 fi
47
48 # Check for the packaging dirs.
49 if [ -z "$PKG_DIR" ]; then
50     PKG_DIR=${PWD}
51 fi
52 if [ ! -d ${PKG_DIR} ]; then
53     mkdir ${PKG_DIR} || exit 1
54 fi
55 cd ${PKG_DIR}
56
57 if [ -d rpm ]; then
58     rm -rf rpm || exit 1
59 fi
60 mkdir rpm
61 mkdir rpm/SOURCES
62 mkdir rpm/SRPMS
63 mkdir rpm/SPECS
64 mkdir rpm/BUILD
65 mkdir rpm/RPMS || exit 1
66
67 # Make a copy of the tarball in the rpmbuild location
68 cp ${PKG_TARBALL} rpm/SOURCES/${PKG_TARBALL} || exit 1
69 cp packaging/rpm/amanda.spec rpm/SPECS || exit 1
70 # Rpmbuild requires absolute paths.  annoying.  If you need to change the 
71 # default value of some rpm.spec variable, just pass extra --define options.
72 # this is useful for changing %amanda_release or %amanda_version
73 rpmbuild -ba --define "_topdir ${PKG_DIR}/rpm" \
74              ${PKG_DIR}/rpm/SPECS/amanda.spec || exit 1
75 cp rpm/RPMS/*/*.rpm . || exit 1
76 cp rpm/SRPMS/*.rpm . || exit 1