From: Daan De Meyer Date: Thu, 7 Sep 2023 10:54:44 +0000 (+0200) Subject: If python3 version is too old, use python3.9 if it exists X-Git-Tag: v16~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a352b59352bc861a0fddfee934021162d250d227;p=thirdparty%2Fmkosi.git If python3 version is too old, use python3.9 if it exists --- diff --git a/bin/mkosi b/bin/mkosi index 7d9cad88c..8a9c3a954 100755 --- a/bin/mkosi +++ b/bin/mkosi @@ -3,4 +3,18 @@ set -e PYTHONPATH="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")" export PYTHONPATH -exec ${MKOSI_INTERPRETER:-python3} -B -m mkosi "$@" + +if [ -z "$MKOSI_INTERPRETER" ]; then + # Note the check seems to be inverted here because the if branch is executed when the exit status is 0 + # which is equal to "False" in python. + if python3 -c "import sys; sys.exit(sys.version_info < (3, 9))"; then + MKOSI_INTERPRETER=python3 + elif command -v python3.9 >/dev/null; then + MKOSI_INTERPRETER=python3.9 + else + echo "mkosi needs python 3.9 or newer (found $(python3 --version))" + exit 1 + fi +fi + +exec "$MKOSI_INTERPRETER" -B -m mkosi "$@"