1#!/bin/bash 2 3TMPDIR=`pwd`/dist 4if [ ! -d $TMPDIR ]; then mkdir $TMPDIR; fi 5 6usage() { 7echo "$0 daily | release [ signed | <key-id> ]" 8echo 9echo " You must specify either release or daily in order for this script" 10echo "to make tarballs. If this is a daily release, the tarballs will" 11echo "be named <component>-git.tar.gz and will overwrite existing tarballs." 12echo "If this is a release build, then the tarball will be named" 13echo "<component>-<version>.tar.gz and must be a new file. In addition," 14echo "the script will add a new set of symbolic tags to the git repo" 15echo "that correspond to the <component>-<version> of each tarball." 16echo 17echo " If the TARGETS environment variable is not NULL, then it is taken" 18echo "as the list of components in the management tree that should be" 19echo "included in this release. If it's NULL, then do all the components." 20echo 21echo " If the script detects that the tag on any component already exists," 22echo "it will abort the release and prompt you to update the version on" 23echo "the already tagged component. This enforces the proper behavior of" 24echo "treating any released tarball as set in stone so that in the future" 25echo "you will always be able to get to any given release tarball by" 26echo "checking out the git tag and know with certainty that it is the same" 27echo "code as released before even if you no longer have the same tarball" 28echo "around." 29echo 30echo " As part of this process, the script will parse the <target>.spec.in" 31echo "file and output a <target>.spec file. Since this script isn't smart" 32echo "enough to deal with other random changes that should have their own" 33echo "checkin the script will refuse to run if the current repo state is not" 34echo "clean." 35echo 36echo " NOTE: the script has no clue if you are tagging on the right branch," 37echo "it will however show you the git branch output so you can confirm it" 38echo "is on the right branch before proceeding with the release." 39echo 40echo " In addition to just tagging the git repo, whenever creating a release" 41echo "there is an optional argument of either signed or a hex gpg key-id." 42echo "If you do not pass an argument to release, then the tag will be a" 43echo "simple git annotated tag. If you pass signed as the argument, the" 44echo "git tag operation will use your default signing key to sign the tag." 45echo "Or you can pass an actual gpg key id in hex format and git will sign" 46echo "the tag with that key." 47echo 48} 49 50if [ -z "$1" ]; then usage; exit 1; fi 51 52if [ "$1" != "daily" -a "$1" != "release" ]; then usage; exit 1; fi 53 54if [ -z "$TARGETS" ]; then 55 TARGETS="libibcommon libibumad libibmad opensm infiniband-diags" 56fi 57 58# Is the repo clean? 59git diff-index --quiet HEAD -- $package > /dev/null 2>&1 60if [ $? -ne 0 ]; then 61 echo "Git tree is dirty. Please commit or undo any changes before proceeding." 62 exit 4 63fi 64 65# make sure we are on the right branch 66git branch 67echo -n "Is the active branch the right one to tag this release on [y/N]? " 68read answer 69if [ "$answer" = y -o "$answer" = Y ]; then 70 echo "Proceeding..." 71else 72 echo "Please check out the right branch and run make.dist again" 73 exit 0 74fi 75 76for target in $TARGETS; do 77 VERSION=`grep "AC_INIT.*$target" $target/configure.in | cut -f 2 -d ',' | sed -e 's/ //g'` 78 if [ "$1" = "release" ]; then 79 # Check versions to make sure that we can proceed 80 if [ -f $TMPDIR/$target-$VERSION.tar.gz ]; then 81 echo "Target $target-$VERSION.tar.gz already exists, please update the version on" 82 echo "component $target" 83 exit 2 84 fi 85 if [ ! -z "`git tag -l $target-$VERSION`" ]; then 86 echo "A git tag already exists for $target-$VERSION. Please change the version" 87 echo "of $target so a tag replacement won't occur." 88 exit 3 89 fi 90# On a real release, this resets the daily release starting point, on the 91# assumption that any new daily builds will have a version number that is 92# incrementally higher than the last officially released tarball. 93 RELEASE=1 94 echo $RELEASE > $TMPDIR/$target.release 95 96 if [ ! -z "$2" ]; then 97 if [ $2 = "signed" ]; then 98 git tag -s -m "Auto tag by make.dist on release tarball creation" $target-$VERSION 99 else 100 git tag -u "$2" -m "Auto tag by make.dist on release tarball creation" $target-$VERSION 101 fi 102 elif [ $1 = "release" ]; then 103 git tag -a -m "Auto tag by make.dist on release tarball creation" $target-$VERSION 104 fi 105 elif [ "$1" = "daily" ]; then 106 DATE=`date +%Y%m%d` 107 git_rev=`./gen_ver.sh $target | sed -e 's/^'$VERSION'_//'` 108 if [ "$git_rev" = "$VERSION" ] ; then 109 VERSION=${VERSION}_${DATE} 110 else 111 VERSION=${VERSION}_${DATE}_${git_rev} 112 fi 113 if [ -f $TMPDIR/$target.gitrev ]; then 114 old_rev=`cat $TMPDIR/$target.gitrev` 115 fi 116 echo $git_rev > $TMPDIR/$target.gitrev 117 if [ "$old_rev" = "$git_rev" ] ; then 118 echo "No daily build is needed for '$target' ($git_rev)" 119 continue 120 fi 121 if [ -f $TMPDIR/$target.release ]; then 122 RELEASE=`cat $TMPDIR/$target.release` 123 RELEASE=`expr $RELEASE + 1` 124 else 125 RELEASE=1 126 fi 127 echo $RELEASE > $TMPDIR/$target.release 128 RELEASE=0.${RELEASE} 129 cat $target/configure.in \ 130 | sed -e '/AC_INIT/s/'$target', .*,/'$target', '$VERSION',/' \ 131 > configure.in.new 132 diff $target/configure.in configure.in.new > /dev/null \ 133 || cat configure.in.new > $target/configure.in 134 fi 135 136 TARBALL=$target-$VERSION.tar.gz 137 138 echo "Creating $TMPDIR/$TARBALL" 139 ( export RELEASE=$RELEASE && export TARBALL=$TARBALL && 140 cd $target && ./autogen.sh && ./configure && 141 make dist && mv $target-$VERSION.tar.gz $TMPDIR/$TARBALL ) || 142 exit $? 143 git checkout $target/configure.in 144done 145