.travis/preinstall: Add python3-selinux

Add python3-selinux to the packages-to-be-installed list if
venv python matches system python.
This commit is contained in:
Jiri Kucera 2020-01-09 08:53:28 +01:00 committed by Till Maas
parent c94fea7617
commit b563a09cb4
3 changed files with 38 additions and 10 deletions

View file

@ -1,4 +1,11 @@
# SPDX-License-Identifier: MIT
export LSR_MOLECULE_DEPS='-rmolecule_requirements.txt'
#
# Use this file to specify custom configuration for a project. Generally, this
# involves the modification of the content of LSR_* environment variables, see
#
# * .travis/preinstall:
#
# - LSR_EXTRA_PACKAGES
#
LSR_EXTRA_PACKAGES='python3-selinux'
export LSR_MOLECULE_DEPS='-rmolecule_requirements.txt'

View file

@ -1,18 +1,30 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
set -ex
# Install package specified by user in LSR_EXTRA_PACKAGES. Executed by Travis
# during before_install phase.
#
# LSR_EXTRA_PACKAGES, set by user in .travis/config.sh, is a space separated
# list of packages to be installed on the Travis build environment (Ubuntu).
SCRIPTDIR=$(dirname $0)
CONFIG=${SCRIPTDIR}/config.sh
set -e
if [[ -f ${CONFIG} ]]; then
. ${CONFIG}
SCRIPTDIR=$(readlink -f $(dirname $0))
. ${SCRIPTDIR}/utils.sh
# Add python3-selinux package (needed by Molecule on selinux enabled systems,
# because Molecule is using `copy` and `file` Ansible modules to setup the
# container).
if lsr_venv_python_matches_system_python; then
LSR_EXTRA_PACKAGES='python3-selinux'
fi
. ${SCRIPTDIR}/config.sh
# Install extra dependencies.
if [[ "${LSR_EXTRA_PACKAGES}" ]]; then
set -x
sudo apt-get update
for P in ${LSR_EXTRA_PACKAGES}; do
sudo apt-get install -y ${P} || :
done
sudo apt-get install -y ${LSR_EXTRA_PACKAGES}
fi

View file

@ -134,3 +134,12 @@ function lsr_compare_pythons() {
lsr_compare_versions \
$(lsr_get_python_version $1) $2 $(lsr_get_python_version $3)
}
##
# lsr_venv_python_matches_system_python
#
# Exit with 0 if virtual environment Python version matches the system Python
# version.
function lsr_venv_python_matches_system_python() {
lsr_compare_pythons python -eq /usr/bin/python3
}