From f47d85dfb0ab39d749050ad5c688b26716c82edf Mon Sep 17 00:00:00 2001 From: Michael Wild Date: Tue, 21 Sep 2010 07:55:25 +0200 Subject: [PATCH] ENH: Improve foamPackSource script Signed-off-by: Michael Wild --- data/utilities/foamPackSource | 148 +++++++++++++++++------------------------- 1 file changed, 58 insertions(+), 90 deletions(-) diff --git a/data/utilities/foamPackSource b/data/utilities/foamPackSource index 070fb03c3..1793fc8da 100755 --- a/data/utilities/foamPackSource +++ b/data/utilities/foamPackSource @@ -69,60 +69,35 @@ # #------------------------------------------------------------------------------ -usage() { - cat >&2 << _EOF_ - - Usage: $0 [-h|--help] - [-c|--create-tag [-t|--tag-key ] [-m|--tag-msg ]] - [-s|--sign-key ] - - Creates a source tar-ball for a given in . - - The argument requires that a git tree-ish object with the name - v exists (i.e. a tag named e.g. v0.1.0). If no such tag exists, you - can specify -c and the current HEAD will be tagged as v. The output - is named /freefoam-.tar.bz2 and a detached signature is - created using the users default GPG-key in - /freefoam-.tar.bz2.sig (can be overriden using -s). - Further the md5 and sha1 digests are computed and placed in - /freefoam-.tar.bz2.md5 and - /freefoam-.tar.bz2.sha1, respectively. - - -h - --help Print a help message - -c - --create-tag Create a tag named v. By default it is signed - by the default e-mail address's GPG-key. - -t - --tag-key If -c is used, specify a different GPG-key ID to sign. - -m - --tag-msg Instead of prompting, use the given tag-message when - -c is specified. - -s - --sign-key Sign the created tar-ball using the GPG-key - instead of using the default key. - -u - --upload Upload to sourceforge.net. - Specify the version for which to create the source - tar-ball. This expects a git object with the name - v to exist, which should be a tag. - The directory in which to place the tar-ball. - -_EOF_ -if [ $# -gt 0 ]; then - exit $1 -else - exit 0 -fi -} +SUBDIRECTORY_OK=Yes + +OPTIONS_SPEC="\ +foamPackSource [options] + +Creates a source tar-ball for a given in . + +The argument requires that a git tree-ish object with the name +v exists (i.e. a tag named e.g. v0.1.0). If no such tag exists, you +can specify -c and the current HEAD will be tagged as v. The output +is named /freefoam-.tar.bz2 and a detached signature is +created using the users default GPG-key in +/freefoam-.tar.bz2.sig (can be overriden using -s). +Further the md5 and sha1 digests are computed and placed in +/freefoam-.tar.bz2.md5 and +/freefoam-.tar.bz2.sha1, respectively. +-- +c,create-tag Create a tag named v and sign it with the default GPG-key. +t,tag-key= If -c is used, specify a different GPG-key ID to sign. +m,tag-msg= Use the given tag-message if -c is specified instead of prompting. +s,sign-key= Sign the tar-ball with the specified, non-default GPG-key. +u,upload Upload the created tar-ball to sourceforge.net." -abort() { - echo "$1" >&2 - exit 1 -} +. "$(git --exec-path)/git-sh-setup" + +cd_to_toplevel if [ $# -lt 2 ]; then - usage 1 + die "Require version number and output directory arguments." fi CREATE_TAG=no @@ -134,72 +109,54 @@ VERSION= OUTPUT_DIR= while [ $# -gt 0 ]; do - case "x$1" in - x-h|x--help) - usage - ;; - x-c|x--create-tag) + case "$1" in + -c|--create-tag) CREATE_TAG=yes shift ;; - x-t|x--tag-key) - if [ $# -lt 4 ]; then - usage 1 - fi + -t|--tag-key) CUSTOM_TAG_KEY="$2" shift 2 ;; - x-m|x--tag-msg) - if [ $# -lt 4 ]; then - usage 1 - fi + -m|--tag-msg) TAG_MSG="$2" shift 2 ;; - x-s|x--sign-key) - if [ $# -lt 4 ]; then - usage 1 - fi + -s|--sign-key) SIGN_KEY="--default-key $2" shift 2 ;; - x-u|x--upload) + -u|--upload) DO_UPLOAD=yes shift ;; - *) - if [ $# -lt 2 ]; then - usage 1 - fi - VERSION="$1" - OUTPUT_DIR="$2" - shift 2 + --) + VERSION="$2" + OUTPUT_DIR="$3" + shift 3 break ;; esac done if [ -z "$VERSION" -o -z "$OUTPUT_DIR" ]; then - usage 1 + die "Version and output directory arguments are required" fi if ! [ -d "$OUTPUT_DIR" -a -w "$OUTPUT_DIR" ]; then - echo "Error: The output directory '$OUTPUT_DIR' does not exist or is not writeable" >&2 - usage 1 + die "The output directory '$OUTPUT_DIR' does not exist or is not writeable" fi for ext in "" .sig .md5 .sha1; do if [ -e "$OUTPUT_DIR/freefoam-$VERSION.tar.bz2$ext" ]; then - echo "Error: The output file $OUTPUT_DIR/freefoam-$VERSION.tar.bz2$ext already exists" >&2 - usage 1 + die "The output file $OUTPUT_DIR/freefoam-$VERSION.tar.bz2$ext already exists" >&2 fi done # create the tag if requested if [ "$CREATE_TAG" = "yes" ]; then if git rev-list --max-count=1 --quiet --tags "v$VERSION" > /dev/null 2>&1; then - echo "Error: Cannot create tag v$VERSION, it already exists" - usage 1 + die "Cannot create tag v$VERSION, it already exists" fi GIT_TAG_OPTS= if [ -n "$CUSTOM_TAG_KEY" ]; then @@ -216,21 +173,31 @@ fi # create the tar-ball echo "Creating the tar ball" -TMP=`mktemp -d` || abort "Failed to create temporary directory" +TMP=`mktemp -d -t freefoam` || die "Failed to create temporary directory" git archive --format=tar --prefix=freefoam-$VERSION/ v$VERSION > \ - $TMP/freefoam-$VERSION.tar || abort "Failed to create tar file" + $TMP/freefoam-$VERSION.tar || die "Failed to create tar file" + +# create HTML docs and add to tar-ball +echo "Creating HTML docs and adding them to the tar-ball" +mkdir $TMP/freefoam-$VERSION +for f in ChangeLog INSTALL README ReleaseNotes; do + git show v$VERSION -- $f | \ + asciidoc -a toc -f data/asciidoc.conf - > \ + $TMP/freefoam-$VERSION/$f.html +done +tar -C $TMP -rf $TMP/freefoam-$VERSION.tar freefoam-$VERSION echo "Compressing the tar ball" -bzip2 --best $TMP/freefoam-$VERSION.tar || abort "Failed to compress the tar ball" +bzip2 --best $TMP/freefoam-$VERSION.tar || die "Failed to compress the tar ball" mv $TMP/freefoam-$VERSION.tar.bz2 $OUTPUT_DIR/freefoam-$VERSION.tar.bz2 || \ - abort "Failed to place the compressed tar ball in '$OUTPUT_DIR'" -rm -rf $TMP || abort "Failed to remove the temporary directory '$TMP'" + die "Failed to place the compressed tar ball in '$OUTPUT_DIR'" +rm -rf $TMP || die "Failed to remove the temporary directory '$TMP'" # sign the tar-ball echo "Signing the tar ball" gpg --armor -o $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.sig $SIGN_KEY \ --sign --detach-sign $OUTPUT_DIR/freefoam-$VERSION.tar.bz2 || \ - abort "Failed to sign the tar ball" + die "Failed to sign the tar ball" # create md5 and sha1 sums echo "Computing checksums of the tar ball" @@ -244,7 +211,8 @@ if [ "$DO_UPLOAD" = "yes" ]; then $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.sig \ $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.md5 \ $OUTPUT_DIR/freefoam-$VERSION.tar.bz2.sha1 \ - web.sf.net:uploads/ || abort "Failed to upload the files to sourceforge.net" + web.sourceforge.net:uploads/ || \ + die "Failed to upload the files to sourceforge.net" echo "Finished upload. Remember to create a release on SF.net." echo "You can do so on https://sourceforge.net/project/admin/editpackages.php?group_id=215833" fi -- 2.11.4.GIT