From b563a09cb430d30eea2edb49734ec230f158a2f7 Mon Sep 17 00:00:00 2001 From: Jiri Kucera Date: Thu, 9 Jan 2020 08:53:28 +0100 Subject: [PATCH] .travis/preinstall: Add python3-selinux Add python3-selinux to the packages-to-be-installed list if venv python matches system python. --- .travis/config.sh | 11 +++++++++-- .travis/preinstall | 28 ++++++++++++++++++++-------- .travis/utils.sh | 9 +++++++++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/.travis/config.sh b/.travis/config.sh index b7aea8eb..0c1b4b5b 100644 --- a/.travis/config.sh +++ b/.travis/config.sh @@ -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' diff --git a/.travis/preinstall b/.travis/preinstall index 70cf1390..4e4f53ae 100755 --- a/.travis/preinstall +++ b/.travis/preinstall @@ -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 diff --git a/.travis/utils.sh b/.travis/utils.sh index 3da971b0..fd179888 100644 --- a/.travis/utils.sh +++ b/.travis/utils.sh @@ -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 +}