diff options
-rwxr-xr-x | qst.sh | 64 |
1 files changed, 52 insertions, 12 deletions
@@ -1,22 +1,22 @@ #!/bin/sh -set -uex - -SUBDIR="" -PRIVATE=0 +set -ue VERBOSITY=0 +BUILD="" + +debug() { + if [ $VERBOSITY -gt 0 ] ; then + echo "$@" + fi +} -# apars.add_argument('-M', '--multibuild', -# help='Build the specified multibuild package') -# apars.add_argument('-v', '--verbose', action='count', -# help="Print quilt's stdout.") while getopts ":M:v" opt; do case $opt in M) BUILD="${OPTARG}" ;; v) - ((VERBOSITY++)) + VERBOSITY=$((VERBOSITY+1)) ;; \?) echo "Invalid option: -$OPTARG" @@ -29,6 +29,46 @@ while getopts ":M:v" opt; do esac done -shift $(($OPTIND - 1)) -REMAINDER=($@) -echo "Length of the remainder is ${#REMAINDER}" +debug "VERBOSITY is ${VERBOSITY}" +debug "BUILD is ${BUILD}" + +shift $((OPTIND - 1)) + +debug "Length of the remainder is $#" +debug "The remainder is $*" + +if [ $# -gt 0 ] ; then + for LAST in "$@" ; do : ; done + SPEC_FILE_NAME="$LAST" +else + SPEC_FILE_NAME="$(/bin/ls -- *.spec|sort -r|head -n1)" +fi + +if [ ! -f "$SPEC_FILE_NAME" ] ; then + echo "File $SPEC_FILE_NAME doesn't exist!" + exit 1 +fi + +debug "SPEC_FILE_NAME = $SPEC_FILE_NAME" + +if [ -n "$BUILD" ] ; then + TMP_SPEC="$(mktemp /tmp/qstXXXXXX.spec)" + trap 'rm -f "${TMP_SPEC}"' EXIT + + sed -E -e 's/@BUILD_FLAVOR@/'$BUILD'/' "$SPEC_FILE_NAME" >"$TMP_SPEC" +else + TMP_SPEC="$SPEC_FILE_NAME" +fi + +# TODO between '-v' and $TMP_SPEC there should be remainder of $@ without the last element +FAILF="$(mktemp /tmp/qstXXXXXX)" +trap 'rm -f "${FAILF}"' EXIT +RES="$(quilt setup -v "$TMP_SPEC" || echo >"$FAILF")" +if [ -s "$FAILF" ] ; then + echo "$RES" 2>&1 + exit 1 +fi +REPOCD="$(echo "$RES"|awk '/^+ rm -rf / {print $4}'|head -n1)" +if [ -n "$REPOCD" ] ; then + echo "$REPOCD" +fi |