Merge branch 'master' of ctdb into 'master' of samba
[sfrench/samba-autobuild/.git] / ctdb / packaging / maketarball.sh
1 #!/bin/sh
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 TARGETDIR="${1:-${PWD}}"  # Default target directory is .
28
29 DIRNAME=$(dirname "$0")
30 cd -P "${DIRNAME}/.."
31 TOPDIR="$PWD"
32
33 tmpd=$(mktemp -d) || {
34     echo "Failed to create temporary directory"
35     exit 1
36 }
37
38 TAR_PREFIX_TMP="ctdb-tmp"
39 SPECFILE="${tmpd}/${TAR_PREFIX_TMP}/packaging/RPM/ctdb.spec"
40 SPECFILE_IN="${SPECFILE}.in"
41 VERSION_H="${tmpd}/${TAR_PREFIX_TMP}/include/ctdb_version.h"
42
43 if echo | gzip -c --rsyncable - > /dev/null 2>&1 ; then
44         GZIP="gzip -9 --rsyncable"
45 else
46         GZIP="gzip -9"
47 fi
48
49 echo "Creating tarball ... "
50 git archive --prefix="${TAR_PREFIX_TMP}/" HEAD | ( cd "$tmpd" ; tar xf - )
51 if [ $? -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 cd "${tmpd}/${TAR_PREFIX_TMP}"
72 ./autogen.sh || {
73         echo "Error calling autogen.sh."
74         exit 1
75 }
76
77 make -C doc || {
78     echo "Error building docs."
79     exit 1
80 }
81
82 if [ "$DEBIAN_MODE" = "yes" ] ; then
83         TAR_PREFIX="ctdb-${VERSION}.orig"
84         TAR_BASE="ctdb_${VERSION}.orig"
85         rm -rf "${tmpd}/${TAR_PREFIX_TMP}/lib/popt"
86 fi
87
88 TAR_BALL="${TAR_BASE}.tar"
89 TAR_GZ_BALL="${TAR_BALL}.gz"
90
91 mv "${tmpd}/${TAR_PREFIX_TMP}" "${tmpd}/${TAR_PREFIX}"
92
93 cd "$tmpd"
94 tar cf "$TAR_BALL" "$TAR_PREFIX" || {
95         echo "Creation of tarball failed."
96         exit 1
97 }
98
99 $GZIP "$TAR_BALL" || {
100         echo "Zipping tarball failed."
101         exit 1
102 }
103
104 rm -rf "$TAR_PREFIX"
105
106 mv "${tmpd}/${TAR_GZ_BALL}" "${TARGETDIR}/"
107
108 rmdir "$tmpd"
109
110 echo "Done."
111 exit 0