#!/bin/sh # create versioned tarballs from git trees # by ponce # 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://sam.zoy.org/wtfpl/COPYING # This shell script uses the following binaries: # git, head, cut, awk, sed, xz, md5sum # 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 REMOTEGIT=$( git remote -v | grep fetch | cut -d\ -f1 | awk -F/ '{print $NF}' ) SRCNAM=${SRCNAM:-"$REMOTEGIT"} # form a string usable for versioning a tarball. # run it in a git tree and it 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 --format=format:%ci | awk '{print $1}' | sed 's/-//g' ) #TODAY=$( git log -1 --format=format:%ci | sed -e 's/-//g' -e 's/\ .*//' ) # the branch is extracted from git branch BRANCH=$( git branch | grep ^\* | cut -d\ -f2 ) # some output echo "creating tarball from $SRCNAM sources, with version ${TODAY}_${COMMIT}" echo "${OUTPUT}/${SRCNAM}-${TODAY}_${COMMIT}.tar.xz" # create the tarball xz compressed git archive --prefix=${SRCNAM}-${TODAY}_${COMMIT}/ $BRANCH | xz -c -z \ > ${OUTPUT}/${SRCNAM}-${TODAY}_${COMMIT}.tar.xz # calculate the md5 ( cd $OUTPUT md5sum ${SRCNAM}-${TODAY}_${COMMIT}.tar.xz \ > ${SRCNAM}-${TODAY}_${COMMIT}.tar.xz.md5 )