Advertisement
ponce

giver_tarball

Jan 5th, 2013
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.00 KB | None | 0 0
  1. #!/bin/sh
  2. # giver_tarball (create versioned tarballs from git trees)
  3. # by ponce <matteo.bernardini@gmail.com>
  4.  
  5. # This program is free software. It comes without any warranty, to
  6. # the extent permitted by applicable law. You can redistribute it
  7. # and/or modify it under the terms of the WTFPL, Version 2, as
  8. # published by Sam Hocevar. For more details, see
  9. # http://www.wtfpl.net/txt/copying/
  10.  
  11. # This shell script uses the following binaries:
  12. # git, head, cut, awk, sed, xz, md5sum
  13.  
  14. # Example use:
  15. # Clone your git tree and move in the cloned folder. Launch
  16. #   SRCNAM=name_of_the_sources /path/to/giver_tarball
  17. # a tarball with of the tree of the latest version of the branch
  18. # you're in will be created in /tmp
  19.  
  20. # Are we in a git tree?
  21. if [ "$( git log 2>&1 | head -1 | cut -d: -f1 )" = "fatal" ]; then
  22.   echo "this is not a git repository."
  23.   exit 1
  24. fi
  25.  
  26. # OUTPUT is set to /tmp if not else specified
  27. OUTPUT=${OUTPUT:-/tmp}
  28.  
  29. # The name of the tarball is desumed by the remote repository name.
  30. # You can override also this specifying SRCNAM (better).
  31. REMOTEGIT=$( git remote -v | grep fetch | cut -d\  -f1 | awk -F/ '{print $NF}' )
  32. SRCNAM=${SRCNAM:-"$REMOTEGIT"}
  33.  
  34. # Form a string usable for versioning a tarball.
  35. # Running this in a git tree will output a string
  36. # composed by the date, an underscore and the first
  37. # 7 digit of the commit id of the active branch.
  38. COMMIT=$( git log -1 | head -1 | cut -c 8-14 )
  39. TODAY=$( git log -1 --date=short | grep ^Date | awk '{print $2}' | sed 's/-//g' )
  40.  
  41. # The branch is extracted from git status
  42. BRANCH=$( git status | head -1 | cut -d\  -f4 )
  43.  
  44. # Some output
  45. echo "creating tarball from $SRCNAM sources, with version ${TODAY}_${COMMIT}"
  46. echo "$OUTPUT/$SRCNAM-${TODAY}_${COMMIT}.tar.xz"
  47.  
  48. # Actually create the tarball
  49. git archive --prefix=$SRCNAM-${TODAY}_${COMMIT}/ $BRANCH | xz -c -z \
  50.   > $OUTPUT/$SRCNAM-${TODAY}_${COMMIT}.tar.xz
  51.  
  52. # Calculate the md5sum
  53. ( cd $OUTPUT
  54. md5sum $SRCNAM-${TODAY}_${COMMIT}.tar.xz > $SRCNAM-${TODAY}_${COMMIT}.tar.xz.md5 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement