diff --git a/.tools/make-tar.sh b/.tools/make-tar.sh index 4bb0c8a3a..3d676e109 100755 --- a/.tools/make-tar.sh +++ b/.tools/make-tar.sh @@ -1,22 +1,26 @@ -#!/bin/sh +#!/bin/bash # # Make tar for git repo w/ one level of sub modules. # -set -e +set -e -u die() { echo "$1" >&2 exit 1 } -TOPREV="$1" -FINALTAR="$2" -PREFIX="$3" +maybedie() { + if [ "$DEVMODE" ]; then + echo "Warning: $1" >&2 + else + echo "Error: $1" >&2 + exit 1 + fi +} -if ! [ "$TOPREV" ] -then +usage() { cat <&2 -usage: $0 [ []] +usage: $0 [-v] [-s] [ []] may be any git revision spec. (tag, branch, or commit id). @@ -24,9 +28,33 @@ usage: $0 [ []] If is omitted, "base-.tar.gz" will be used. If provided, must end with "/". If is omitted, the default is "base-/". + + Options: + + -v Enable verbose prints + -d Enable permissive developer mode EOF exit 1 -fi +} + +export DEVMODE= + +while getopts "vd" OPT +do + case "$OPT" in + v) set -x;; + d) DEVMODE=1;; + ?) echo "Unknown option" + usage;; + esac +done +shift $(($OPTIND - 1)) + +TOPREV="$1" +FINALTAR="$2" +PREFIX="${3:-}" + +[ "$TOPREV" ] || usage case "$FINALTAR" in "") @@ -59,16 +87,13 @@ case "$PREFIX" in esac # Check for both and R -if [ "$TOPREV" = "HEAD" ] -then - true -elif ! [ `git tag -l $TOPREV` ] +if ! [ `git tag -l $TOPREV` ] then if [ `git tag -l R$TOPREV` ] then TOPREV="R$TOPREV" else - die "No tags exist '$TOPREV' or 'R$TOPREV'" + maybedie "No tags exist '$TOPREV' or 'R$TOPREV'" fi fi @@ -94,7 +119,12 @@ git ls-tree -r $TOPREV | \ while read HASH MODDIR do echo "Visiting $HASH $MODDIR" - git -C $MODDIR archive --prefix=${PREFIX}${MODDIR}/ $HASH | tar -C "$TDIR"/tar -x + if [ -e $MODDIR/.git ] + then + git -C $MODDIR archive --prefix=${PREFIX}${MODDIR}/ $HASH | tar -C "$TDIR"/tar -x + else + maybedie " Submodule not checked out." + fi done # make a list of files copied and filter out undesirables @@ -134,5 +164,5 @@ tar -t $TAROPT -f "$FINALTAR" > "$TDIR"/list.3 # make sure we haven't picked up anything extra if ! diff -u "$TDIR"/list.2 "$TDIR"/list.3 then - echo "Oops! Tarfile diff against plan shown above" + die "Oops! Tarfile diff against plan shown above" fi