aboutsummaryrefslogtreecommitdiffstats
path: root/qst.sh
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-10-03 19:13:32 +0200
committerMatěj Cepl <mcepl@cepl.eu>2024-10-03 19:21:43 +0200
commit55baf66e48cb7723a61918f4ae0ded2964b97270 (patch)
treeb989e4cf635fb9e597fa64f97eeddba10f3e4286 /qst.sh
parent734f1d01af0d4cc8df074f7673e420f53ddd29d3 (diff)
downloadquilt_utils-55baf66e48cb7723a61918f4ae0ded2964b97270.tar.gz
fix: first hopefully working versionHEADmaster
Diffstat (limited to 'qst.sh')
-rwxr-xr-xqst.sh64
1 files changed, 52 insertions, 12 deletions
diff --git a/qst.sh b/qst.sh
index eadb6a4..be7e8ed 100755
--- a/qst.sh
+++ b/qst.sh
@@ -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