#!/usr/bin/env bash # Copyright Red Hat, Inc. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. ## Shell Opts ---------------------------------------------------------------- set -o pipefail set -xeuo ## Vars ---------------------------------------------------------------------- export PROJECT_DIR="$(dirname $(dirname $(readlink -f ${BASH_SOURCE[0]})))" # NOTE(cloudnull): Disable ansible compat check, caters to the case where # system ansible may be installed. export ANSIBLE_SKIP_CONFLICT_CHECK=1 USE_VENV=${USE_VENV:-'yes'} ## Main ---------------------------------------------------------------------- # Source distribution information source /etc/os-release || source /usr/lib/os-release RHT_PKG_MGR=$(command -v dnf) PYTHON_EXEC=$(command -v python3) SYSTEM_PIP=$(dirname "$PYTHON_EXEC")/pip3 # Install the requirements we need to run local tests command -v gcc || sudo dnf -y install gcc PIP_INSTALL_ARGUMENTS="-U -r ${PROJECT_DIR}/common-requirements.txt" case ${USE_VENV} in y|yes|true) PIP="${HOME}/test-python/bin/pip3" USE_VENV='yes' echo echo ### USING VIRTUALENV echo ;; *) PIP="pip3" USE_VENV='no' # Gate jobs don't have /root/.local/bin in PATH, so install globally if [ "$(whoami)" != "root" ]; then PIP_INSTALL_ARGUMENTS="--user ${PIP_INSTALL_ARGUMENTS}" fi echo echo ### NO VENV - may break your system! echo ;; esac # Kill all sudo in the current shell sudo -k # Ensure the required ci file is presnet mkdir -p ${HOME}/ci/yum.repos.d cp /etc/ci/mirror_info.sh ${HOME}/ci || touch ${HOME}/ci/mirror_info.sh cp -r /opt/yum.repos.d/* ${HOME}/ci/yum.repos.d || cp -r /etc/yum.repos.d/* ${HOME}/ci/yum.repos.d case ${USE_VENV} in y|yes|true): # Create a virtual env "${PYTHON_EXEC}" -m venv --upgrade-deps "${HOME}/test-python" if [[ -d "${HOME}/.cache/pip/wheels" ]]; then rm -rf "${HOME}/.cache/pip/wheels" fi ;; esac # Run bindep "${PIP}" install pip setuptools bindep --upgrade "${PROJECT_DIR}/scripts/bindep-install" ${SYSTEM_PIP} install ${PIP_INSTALL_ARGUMENTS} # Display list of installed packages with versions (debugging failures) "${SYSTEM_PIP}" freeze "${PIP}" freeze