Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # giver_tarball (create versioned tarballs from git trees)
- # by ponce <matteo.bernardini@gmail.com>
- # This program is free software. It comes without any warranty, to
- # the extent permitted by applicable law. You can redistribute it
- # and/or modify it under the terms of the WTFPL, Version 2, as
- # published by Sam Hocevar. For more details, see
- # http://www.wtfpl.net/txt/copying/
- # This shell script uses the following binaries:
- # git, head, cut, awk, sed, xz, md5sum
- # Example use:
- # Clone your git tree and move in the cloned folder. Launch
- # SRCNAM=name_of_the_sources /path/to/giver_tarball
- # a tarball with of the tree of the latest version of the branch
- # you're in will be created in /tmp
- # Are we in a git tree?
- if [ "$( git log 2>&1 | head -1 | cut -d: -f1 )" = "fatal" ]; then
- echo "this is not a git repository."
- exit 1
- fi
- # OUTPUT is set to /tmp if not else specified
- OUTPUT=${OUTPUT:-/tmp}
- # The name of the tarball is desumed by the remote repository name.
- # You can override also this specifying SRCNAM (better).
- REMOTEGIT=$( git remote -v | grep fetch | cut -d\ -f1 | awk -F/ '{print $NF}' )
- SRCNAM=${SRCNAM:-"$REMOTEGIT"}
- # Form a string usable for versioning a tarball.
- # Running this in a git tree will output a string
- # composed by the date, an underscore and the first
- # 7 digit of the commit id of the active branch.
- COMMIT=$( git log -1 | head -1 | cut -c 8-14 )
- TODAY=$( git log -1 --date=short | grep ^Date | awk '{print $2}' | sed 's/-//g' )
- # The branch is extracted from git status
- BRANCH=$( git status | head -1 | cut -d\ -f4 )
- # Some output
- echo "creating tarball from $SRCNAM sources, with version ${TODAY}_${COMMIT}"
- echo "$OUTPUT/$SRCNAM-${TODAY}_${COMMIT}.tar.xz"
- # Actually create the tarball
- git archive --prefix=$SRCNAM-${TODAY}_${COMMIT}/ $BRANCH | xz -c -z \
- > $OUTPUT/$SRCNAM-${TODAY}_${COMMIT}.tar.xz
- # Calculate the md5sum
- ( cd $OUTPUT
- md5sum $SRCNAM-${TODAY}_${COMMIT}.tar.xz > $SRCNAM-${TODAY}_${COMMIT}.tar.xz.md5 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement