afdc05c14a6e05a44dc654c4c109fb9852c841de
[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 # AMTARBALL: the name of the tarball which contains the source code.  it must
12 #     unpack into a directory named AMVER.  It's easiest and safest to just 
13 #     let the script create a new one for you, even if it's a bit more overhead
14 # AMPKGDIR: Rpmbuild expects absolute paths, so we provide this var.  It also
15 #     allows you to build somewhere other than `pwd`.  You probably don't want
16 #     to use the system-wide location, as the script tries to blow these
17 #     directories away.
18
19 # Other Hints:
20 # Not everyone will want to use the ./configure options we provide.  The
21 # easiest way to change them is by editing the .spec file.  This isn't so
22 # easy, unfortunately.  Look at the %build section, and the %define xxxx 
23 # statements immediately above it. good luck.
24
25 # This is useful for debugging
26 set -x
27 # Buildbot exports some useful env variables.
28 # Check for $AMVER.  I couldn't come up with a good way to detect it.
29 if [ -z $AMVER ]; then
30     AMVER=amanda-2.6.1p2
31 fi
32
33 # Check for AMTARBALL variable.
34 if [ -z $AMTARBALL ]; then 
35     AMTARBALL=$AMVER.tar.gz
36 fi
37
38 # Check for AMTARBALL file, if it's not there, create it.
39 if [ ! -f ${AMTARBALL} ]; then
40     mkdir ${AMVER}
41     cp -Rfp * ${AMVER}/
42     tar -cf ${AMTARBALL} -z ${AMVER} || exit 1
43     rm -rf ${AMVER}
44 fi
45
46 # Check for the packaging dirs.
47 if [ -z $AMPKGDIR ]; then
48     AMPKGDIR=${PWD}
49 fi
50 if [ ! -d ${AMPKGDIR} ]; then
51     mkdir ${AMPKGDIR} || exit 1
52 fi
53 cd ${AMPKGDIR}
54
55 if [ -d rpm ]; then
56     rm -rf rpm || exit 1
57 fi
58 mkdir rpm
59 mkdir rpm/SOURCES
60 mkdir rpm/SRPMS
61 mkdir rpm/SPECS
62 mkdir rpm/BUILD
63 mkdir rpm/RPMS || exit 1
64
65 # Make a copy of the tarball with the name that rpmbuild expects
66 cp ${AMTARBALL} rpm/SOURCES/${AMVER}.tar.gz || exit 1
67 cp packaging/rpm/amanda.spec rpm/SPECS || exit 1
68 # Rpmbuild requires absolute paths.  annoying.  If you need to change the 
69 # default value of some rpm.spec variable, just pass extra --define options.
70 # this is useful for changing %amanda_release or %amanda_version
71 rpmbuild -ba --define "_topdir ${AMPKGDIR}/rpm" \
72              ${AMPKGDIR}/rpm/SPECS/amanda.spec || exit 1
73 cp rpm/RPMS/*/*.rpm . || exit 1
74 cp rpm/SRPMS/*.rpm . || exit 1