From: Ladislav Michl <[email protected]>

Provide a helpful message instead of 'bad interpreter' and check
bash version.

Signed-off-by: Ladislav Michl <[email protected]>
---
 bin/ptxdist              | 24 +++++++++++++++++++++++-
 bin/ptxdist-auto-version |  4 ++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/bin/ptxdist b/bin/ptxdist
index 7b20026bb..3c86aa225 100755
--- a/bin/ptxdist
+++ b/bin/ptxdist
@@ -1,4 +1,26 @@
-#!/bin/bash
+#!/bin/sh
+
+#
+# Everything up to the bash version check must be plain POSIX sh: PTXdist
+# may be started by any shell and re-executes itself with bash.
+#
+if [ -z "${BASH_VERSION}" ]; then
+       bash="$(command -v bash)" || {
+               echo "ptxdist: error: bash >= 4.2 is required, please install 
it" >&2
+               exit 1
+       }
+       exec "${bash}" "${0}" "${@}"
+fi
+
+case "${BASH_VERSION}" in
+[0-3].*|4.[01].*)
+       echo "ptxdist: error: bash >= 4.2 is required, found ${BASH_VERSION} as 
'${BASH}'" >&2
+       exit 1
+       ;;
+esac
+
+# e.g. when started as 'sh' with /bin/sh -> bash
+set +o posix
 
 LANG=C
 LC_ALL=POSIX
diff --git a/bin/ptxdist-auto-version b/bin/ptxdist-auto-version
index 2f6414ae0..92c50fc3d 100755
--- a/bin/ptxdist-auto-version
+++ b/bin/ptxdist-auto-version
@@ -1,7 +1,7 @@
-#!/bin/bash
+#!/bin/sh
 
 #
-# bash implementation of realpath / readlink -f
+# shell implementation of realpath / readlink -f
 #   arg1 - filename
 realpath()
 {
-- 
2.47.3


Reply via email to