diskimage-builder/diskimage_builder/elements/python-stow-versions/install.d/70-python-build
Dmitriy Rabotyagov 1de6fe4ba7 Add python-stow-versions element
This element is designed to install latest minor versions of different
python releases, like py27, py35, py36, py37, py38
into stow directory, and later easily enable them with stow.

Change-Id: Iab6d20e7643e549b53c629fb430e58b1c5e72991
2020-03-19 21:21:01 +02:00

39 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 1 ]; then
set -x
fi
set -eu
set -o pipefail
#Install python-build
/pyenv/plugins/python-build/install.sh
DIB_PYTHON_VERSIONS=${DIB_PYTHON_VERSIONS:-"2.7,3.5,3.6,3.7,3.8,3.9"}
DIB_VERSIONS_TO_INSTALL=${1:-$DIB_PYTHON_VERSIONS}
# Get pyenv versions
DIB_PYENV_VERSIONS=$(python-build --definitions \
| egrep "^\s*[2,3]\.[0-9]{1,2}\.[0-9]{1,2}$")
declare -A DIB_PYTHON_VERSIONS_ARRAY
for version in ${DIB_PYENV_VERSIONS}; do
DIB_PYTHON_VERSIONS_ARRAY[${version%.*}]+="${version##*.} "
done
if [ -n $DIB_VERSIONS_TO_INSTALL ]; then
readarray -t DIB_VERSIONS_ARRAY <<<\
"$(echo "$DIB_VERSIONS_TO_INSTALL" | tr ',' '\n')"
fi
for key in ${!DIB_PYTHON_VERSIONS_ARRAY[@]}; do
if ([ -n $DIB_VERSIONS_ARRAY ] && \
[[ " ${DIB_VERSIONS_ARRAY[@]} " =~ " ${key} " ]]) || \
[ -z ${DIB_VERSIONS_ARRAY} ]; then
DIB_LAST_VERSION=${key}.$(echo "${DIB_PYTHON_VERSIONS_ARRAY[${key}]}" \
| sed "s/ /\n/g" | sort -nr | head -n1)
python-build ${DIB_LAST_VERSION} /usr/local/stow/python-${DIB_LAST_VERSION}
fi
done