]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
If python3 version is too old, use python3.9 if it exists
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 7 Sep 2023 10:54:44 +0000 (12:54 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Sep 2023 11:59:50 +0000 (13:59 +0200)
bin/mkosi

index 7d9cad88c9bc491b90136492c77616a676987bfb..8a9c3a954e4458af3e06a2a1ff1cf954f41f9a06 100755 (executable)
--- 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 "$@"