#!/bin/bash
# mk_git_tar
# Generic tool for making tarballs from git
# Run this script in SOURCES
# $ ./mk_git_tar <projectname> <url> <tar_compression>
# Examples :-
# $ ./mk_git_tar LogbookKonni_pi git://github.com/konnibe/LogbookKonni-1.2.git tar.gz

name=$1
url=$2
tartype=$3

git clone $url $name

cd $name
rev=$(git rev-list HEAD | wc -l)
cd ..

# Create tarball
case $tartype in
tar.gz)
opt=z
;;
tar.bz2)
opt=j
;;
tar.xz)
opt=J
;;
tar)
opt=
;;
*)
echo "Unsupported compression type"
exit 1
esac

echo "Please wait creating tarball..."
[[ -f $name.$tartype ]] && rm $name.$tartype
#tar -c"$opt"f $name.$rev.$tartype $name/ --exclude-vcs
tar -c"$opt"f $name.$rev.$tartype $name/
[[ $? = 0 ]] && chmod 644 $name.$rev.$tartype && \
echo "Written $name.$rev.$tartype"

 
