#!/bin/sh set -ue VERBOSITY=0 BUILD="" debug() { if [ $VERBOSITY -gt 0 ] ; then echo "$@" fi } while getopts ":M:v" opt; do case $opt in M) BUILD="${OPTARG}" ;; v) VERBOSITY=$((VERBOSITY+1)) ;; \?) echo "Invalid option: -$OPTARG" exit 1 ;; :) echo "Option -$OPTARG requires an argument." exit 1 ;; esac done 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