c99bb7075935699c0db3996d9644c6c29c356366
[amitay/ctdb.git] / packaging / maketarball.sh
1 #!/bin/bash
2 #
3 # maketarball.sh - create a tarball from the git branch HEAD
4 #
5 # Copyright (C) Michael Adam 2009
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3 of the License, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15 # more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # this program; if not, see <http://www.gnu.org/licenses/>.
19 #
20
21 #
22 # Create CTDB source tarball of the current git branch HEAD.
23 # The version is calculated from git tag in mkversion.sh.
24 # Optional argument is the directory to which tarball is copied.
25 #
26
27 DIRNAME=$(dirname $0)
28 TOPDIR=${DIRNAME}/..
29
30 TARGETDIR="$1"
31 if [ -z "${TARGETDIR}" ]; then
32     TARGETDIR="."
33 fi
34
35 TAR_PREFIX_TMP="ctdb-tmp"
36 SPECFILE=/tmp/${TAR_PREFIX_TMP}/packaging/RPM/ctdb.spec
37 SPECFILE_IN=${SPECFILE}.in
38 VERSION_H=/tmp/${TAR_PREFIX_TMP}/include/ctdb_version.h
39
40 if echo | gzip -c --rsyncable - > /dev/null 2>&1 ; then
41         GZIP="gzip -9 --rsyncable"
42 else
43         GZIP="gzip -9"
44 fi
45
46 pushd ${TOPDIR}
47 echo "Creating tarball ... "
48 git archive --prefix=${TAR_PREFIX_TMP}/ HEAD | ( cd /tmp ; tar xf - )
49 RC=$?
50 popd
51 if [ $RC -ne 0 ]; then
52         echo "Error calling git archive."
53         exit 1
54 fi
55
56 set -- $(${TOPDIR}/packaging/mkversion.sh ${VERSION_H})
57 VERSION=$1
58 RELEASE=$2
59 if [ -z "$VERSION" -o -z "$RELEASE" ]; then
60     exit 1
61 fi
62
63 sed -e "s/@VERSION@/${VERSION}/g" \
64     -e "s/@RELEASE@/$RELEASE/g" \
65         < ${SPECFILE_IN} \
66         > ${SPECFILE}
67
68 TAR_PREFIX="ctdb-${VERSION}"
69 TAR_BASE="ctdb-${VERSION}"
70
71 pushd /tmp/${TAR_PREFIX_TMP}
72 ./autogen.sh
73 RC=$?
74 if [ $RC -ne 0 ]; then
75         echo "Error calling autogen.sh."
76         exit 1
77 fi
78
79 make -C doc
80 RC=$?
81 if [ $RC -ne 0 ]; then
82     echo "Error building docs."
83     exit 1
84 fi
85 popd
86
87 if test "x${DEBIAN_MODE}" = "xyes" ; then
88         TAR_PREFIX="ctdb-${VERSION}.orig"
89         TAR_BASE="ctdb_${VERSION}.orig"
90         rm -rf /tmp/${TAR_PREFIX_TMP}/lib/popt
91 fi
92
93 TAR_BALL=${TAR_BASE}.tar
94 TAR_GZ_BALL=${TAR_BALL}.gz
95
96 mv /tmp/${TAR_PREFIX_TMP} /tmp/${TAR_PREFIX}
97
98 pushd /tmp
99 tar cf ${TAR_BALL} ${TAR_PREFIX}
100 RC=$?
101 if [ $RC -ne 0 ]; then
102         popd
103         echo "Creation of tarball failed."
104         exit 1
105 fi
106
107 ${GZIP} ${TAR_BALL}
108 RC=$?
109 if [ $RC -ne 0 ]; then
110         popd
111         echo "Zipping tarball failed."
112         exit 1
113 fi
114
115 rm -rf ${TAR_PREFIX}
116
117 popd
118
119 mv /tmp/${TAR_GZ_BALL} ${TARGETDIR}/
120
121 echo "Done."
122 exit 0