Jared K. Smith 8e6fff7
#!/bin/bash
Jared K. Smith 8e6fff7
Jared K. Smith 8e6fff7
tag=$(sed -n 's/^Version:\s\(.*\)$/\1/p' ./*.spec | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
Jared K. Smith 8e6fff7
url=$(sed -n 's/^URL:\s\(.*\)$/\1/p' ./*.spec | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
Jared K. Smith 8e6fff7
pkgdir=$(basename $url | sed -s 's/\.git$//')
Jared K. Smith 8e6fff7
Jared K. Smith 8e6fff7
echo "tag: $tag"
Jared K. Smith 8e6fff7
echo "URL: $url"
Jared K. Smith 8e6fff7
echo "pkgdir: $pkgdir"
Jared K. Smith 8e6fff7
Jared K. Smith 8e6fff7
set -e
Jared K. Smith 8e6fff7
Jared K. Smith 8e6fff7
tmp=$(mktemp -d)
Jared K. Smith 8e6fff7
Jared K. Smith 8e6fff7
trap cleanup EXIT
Jared K. Smith 8e6fff7
cleanup() {
Jared K. Smith 8e6fff7
    echo Cleaning up...
Jared K. Smith 8e6fff7
    set +e
Jared K. Smith 8e6fff7
    [ -z "$tmp" -o ! -d "$tmp" ] || rm -rf "$tmp"
Jared K. Smith 8e6fff7
}
Jared K. Smith 8e6fff7
Jared K. Smith 8e6fff7
unset CDPATH
Jared K. Smith 8e6fff7
pwd=$(pwd)
Jared K. Smith 8e6fff7
Jared K. Smith 8e6fff7
pushd "$tmp"
Jared K. Smith 8e6fff7
git clone $url
Jared K. Smith 8e6fff7
cd $pkgdir
Jared K. Smith 8e6fff7
echo Finding git tag
Jared K. Smith 8e6fff7
gittag=$(git show-ref --tags | cut -d' ' -f2 | grep "${tag}$" || git show-ref --tags | cut -d' ' -f2 | sort -Vr | head -n1)
Jared K. Smith 8e6fff7
if [ -z $gittag ]; then
Jared K. Smith 8e6fff7
	gittag=tags/$tag
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
echo "Git Tag: $gittag"
Jared K. Smith 8e6fff7
if [ -d "test" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='test/' --format=tar ${gittag}:test/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/tests-${tag}.tar.bz2
Jared K. Smith 8e6fff7
elif [ -d "tests" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='tests/' --format=tar ${gittag}:tests/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/tests-${tag}.tar.bz2
Jared K. Smith 8e6fff7
elif [ -d "spec" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='spec/' --format=tar ${gittag}:spec/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/tests-${tag}.tar.bz2
Jared K. Smith 8e6fff7
else
Jared K. Smith 8e6fff7
  echo "No test directory found for tag ${gittag}"
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
if [ -d "support" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='support/' --format=tar ${gittag}:support/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/support-${tag}.tar.bz2
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
if [ -d "fixture" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='fixture/' --format=tar ${gittag}:fixture/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/fixture-${tag}.tar.bz2
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
if [ -d "examples" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='examples/' --format=tar ${gittag}:examples/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/examples-${tag}.tar.bz2
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
if [ -d "tasks" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='tasks/' --format=tar ${gittag}:tasks/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/tasks-${tag}.tar.bz2
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
if [ -d "docs" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='docs/' --format=tar ${gittag}:docs/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/docs-${tag}.tar.bz2
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
if [ -d "src" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='src/' --format=tar ${gittag}:src/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/src-${tag}.tar.bz2
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
if [ -d "tools" ]; then
Jared K. Smith 8e6fff7
  git archive --prefix='tools/' --format=tar ${gittag}:tools/ \
Jared K. Smith 8e6fff7
      | bzip2 > "$pwd"/tools-${tag}.tar.bz2
Jared K. Smith 8e6fff7
fi
Jared K. Smith 8e6fff7
popd