]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/infrastructure/cat-if-error.sh
update scripts from hagger
[xonotic/xonotic.git] / misc / infrastructure / cat-if-error.sh
diff --git a/misc/infrastructure/cat-if-error.sh b/misc/infrastructure/cat-if-error.sh
new file mode 100755 (executable)
index 0000000..1789af5
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+logfile=$1
+shift
+
+if ! lockfile-create "$logfile.lock" >/dev/null 2>&1; then
+       exit 1
+fi
+lockfile-touch "$logfile.lock" & lockpid=$!
+
+if "$@" >"$logfile" 2>&1; then
+       : # all is well
+else
+       cat "$logfile"
+fi
+
+kill $lockpid
+lockfile-remove "$logfile.lock"