Make dib-python use the default python for distro

Right now dib-python works by trying to find any python on a system in
an order of precedence. A much better way is if we are explicit about
the python we intend to be there which will allow us to make better
decisions in other elements (such as allowing for package-installs to
take into account DIB_PYTHON_VERSION) as well as allow for users to
specify a preferred python version.

Co-Authored-By: Adam Harwell <flux.adam@gmail.com>
Change-Id: Ie609de51cc5fcde701296c9474e315981d9778a2
This commit is contained in:
Gregory Haynes 2016-12-07 12:26:43 -08:00
parent 8c74c8e409
commit 6278371eaa
6 changed files with 50 additions and 4 deletions

View File

@ -1,2 +1,3 @@
debootstrap
dib-python
pkg-map

View File

@ -54,4 +54,13 @@ $apt_get update
$apt_get clean
$apt_get dist-upgrade -y
$apt_get install -y busybox python sudo
$apt_get install -y busybox sudo
if [ "$DIB_PYTHON_VERSION" == "2" ]; then
$apt_get install -y python
elif [ "$DIB_PYTHON_VERSION" == "3" ]; then
$apt_get install -y python3
else
echo "ERROR: DIB_PYTHON_VERSION is '$DIB_PYTHON_VERSION' but needs to be 2 or 3"
exit 1
fi

View File

@ -7,3 +7,6 @@ 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.
This also exports a variable DIB_PYTHON_VERSION which will either be '2' or
'3' depending on the python version which dib-python points to.

View File

@ -0,0 +1,24 @@
# Pick which distros we need to force python2
if [ -z "${DIB_PYTHON_VERSION:-}" ]; then
if [ "$DISTRO_NAME" == "ubuntu" ]; then
if [ "$DIB_RELEASE" == "trusty" ]; then
DIB_PYTHON_VERSION=2
fi
elif [ "$DISTRO_NAME" == "debian" ]; then
DIB_PYTHON_VERSION=2
elif [ "$DISTRO_NAME" == "fedora" ]; then
if [ "$DIB_RELEASE" -le 22 ]; then
DIB_PYTHON_VERSION=2
fi
elif [ "$DISTRO_NAME" == "centos" ]; then
DIB_PYTHON_VERSION=2
elif [ "$DISTRO_NAME" == "centos7" ]; then
DIB_PYTHON_VERSION=2
fi
fi
if [ -z "${DIB_PYTHON_VERSION:-}" ]; then
DIB_PYTHON_VERSION=3
fi
export DIB_PYTHON_VERSION

View File

@ -6,9 +6,9 @@ fi
set -eu
set -o pipefail
python_path=$(command -v python2 || command -v python3)
python_path=$(command -v python${DIB_PYTHON_VERSION})
if [ -z "$python_path" ]; then
echo "Could not find python2 or python3 executable."
echo "Could not find python${DIB_PYTHON_VERSION} executable."
exit 1
fi

View File

@ -43,4 +43,13 @@ $apt_get update
$apt_get clean
$apt_get dist-upgrade -y
$apt_get install -y busybox python sudo
$apt_get install -y busybox sudo
if [ "$DIB_PYTHON_VERSION" == "2" ]; then
$apt_get install -y python
elif [ "$DIB_PYTHON_VERSION" == "3" ]; then
$apt_get install -y python3
else
echo "ERROR: DIB_PYTHON_VERSION is '$DIB_PYTHON_VERSION' but needs to be 2 or 3"
exit 1
fi