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