git2tarxz.sh 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # Create source tarball from git repo, with generated version
  3. # number.
  4. # Note that this script doesn't need to be run as root. It does
  5. # need to be able to write to the current directory it's run from.
  6. # Takes one optional argument, which is the commit or tag to create
  7. # a tarball of. With no arg, HEAD is used.
  8. PRGNAM=imgcurses
  9. CLONE_URL=https://github.com/orangeduck/imgcurses
  10. set -e
  11. GITDIR=$( mktemp -dt $PRGNAM.git.XXXXXX )
  12. rm -rf $GITDIR
  13. git clone $CLONE_URL $GITDIR
  14. CWD="$( pwd )"
  15. cd $GITDIR
  16. if [ "$1" != "" ]; then
  17. git reset --hard "$1" || exit 1
  18. fi
  19. GIT_SHA=$( git rev-parse --short HEAD )
  20. DATE=$( git log --date=format:%Y%m%d --format=%cd | head -1 )
  21. VERSION=${DATE}_${GIT_SHA}
  22. rm -rf .git
  23. find . -name .gitignore -print0 | xargs -0 rm -f
  24. cd "$CWD"
  25. rm -rf $PRGNAM-$VERSION $PRGNAM-$VERSION.tar.xz
  26. mv $GITDIR $PRGNAM-$VERSION
  27. tar cvfJ $PRGNAM-$VERSION.tar.xz $PRGNAM-$VERSION
  28. echo
  29. echo "Created tarball: $PRGNAM-$VERSION.tar.xz"
  30. echo "VERSION=$VERSION"