From 3afbeeaf4e678628da01b2cf4624bc25f70084e6 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Thu, 10 Dec 2015 19:38:53 +0000 Subject: [PATCH] Add dib-python element Creating an element which we can use in #! lines to refer to either python2 or python3 depending on what it available. Change-Id: Ic47e18ad21c33ab9f0d11c04260a33725aeee814 --- elements/dib-python/README.rst | 9 +++++++++ elements/dib-python/pre-install.d/01-dib-python | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 elements/dib-python/README.rst create mode 100755 elements/dib-python/pre-install.d/01-dib-python diff --git a/elements/dib-python/README.rst b/elements/dib-python/README.rst new file mode 100644 index 000000000..996b519f8 --- /dev/null +++ b/elements/dib-python/README.rst @@ -0,0 +1,9 @@ +=========== +dib=-python +=========== + +Adds a symlink to /usr/local/bin/dib-python which points at either a python2 +or python3 executable. This is useful for creating #! lines for scripts that +are compatible with both python2 and python3. + +This does not install a python if one does not exist, and instead fails. diff --git a/elements/dib-python/pre-install.d/01-dib-python b/elements/dib-python/pre-install.d/01-dib-python new file mode 100755 index 000000000..57ae94ed8 --- /dev/null +++ b/elements/dib-python/pre-install.d/01-dib-python @@ -0,0 +1,17 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +which which || install-packages which + +python_path=$(which python2 || which python3) +if [ -z "$python_path" ]; then + echo "Could not find python2 or python3 executable." + exit 1 +fi + +ln -s $python_path /usr/local/bin/dib-python