Remove empty tmp.tar if nominated git tag doesn't exist.
[git-tools-moved-to-github.git] / id-deb-build / mkdist.sh
1 die () {
2   echo >&2 "$@"
3   exit 1
4 }
5
6 if test -f IDMETA; then
7   . ./IDMETA
8 else
9   echo "Warning: no IDMETA file.  Limping along anyway" >&2
10 fi
11
12 #we will keep this to get the project name
13 DEBCHANGELOG=debian/changelog
14
15 if [ "x$NAME" != x ]; then
16   echo "Got name $NAME from IDMETA file"
17 else
18   NAME=`head -1 $DEBCHANGELOG|sed 's/ .*//g'`
19   echo "Warning: assuming name $NAME from $DEBCHANGELOG"
20 fi
21
22 if [ "x$2" != x ]; then
23   echo "Overriding name $NAME with $2"
24   NAME=$2
25 fi
26
27 if [ "x$VERSION" != x ]; then
28   echo "Got version $VERSION from IDMETA file"
29 else
30   FULLVERSION=`head -1 $DEBCHANGELOG|sed 's/.*(//g'|sed 's/).*//g'`
31   VERSION=`echo $FULLVERSION|sed 's/-.*//g'`
32   echo "Warning: assuming version $VERSION from $DEBCHANGELOG"
33 fi
34
35 if [ "x$1" != x ]; then
36   echo "Overriding version $VERSION with $1"
37   VERSION=$1
38 fi
39
40 trap 'rm -f tmp.tar' 0
41 git archive --format=tar --prefix=$NAME-$VERSION/ v${VERSION} > tmp.tar || die "This version is not tagged in Git";
42 tar xf tmp.tar
43 rm tmp.tar
44 for file in debian $OMIT_FROM_DIST; do
45   echo "Omitting $file from distribution"
46   rm -r $NAME-$VERSION/$file
47 done
48 tar cfz $NAME-$VERSION.tar.gz $NAME-$VERSION
49 rm -r $NAME-$VERSION