ansible/test/lib/ansible_test/_data/setup/remote.sh
Matt Clay d651bda123
Relocate ansible-test code. (#60147)
* Initial move of `test/runner/` content.

`test/runner/lib/` -> `test/lib/ansible_test/_internal/`
`test/runner/`     -> `test/lib/ansible_test/_internal/data/`

* Initial move of `test/sanity/` content.

`test/sanity/` -> `test/lib/ansible_test/_internal/data/sanity/` (except `test/sanity/ignore.txt`)

* Initial move of `test/units/pytest/` content.

`test/units/pytest/` -> `test/lib/ansible_test/_internal/data/pytest/`

* Follow-up move of `test/runner/unit/` content.

`test/lib/ansible_test/_internal/data/unit/` -> `test/lib/ansible_test/tests/unit/`

* Initial move of `ansible.cfg` content.

`test/units/ansible.cfg` -> `test/lib/ansible_test/_internal/data/units/ansible.cfg`
`test/env/ansible.cfg` -> `test/lib/ansible_test/_internal/data/env/ansible.cfg`

* Follow-up move of `data` directory.

`test/lib/ansible_test/_internal/data/` -> `test/lib/ansible_test/_data/`

* Update import statements.

* Add missing __init__.py for unit tests.

* Fix path references and miscellaneous issues.
2019-08-06 14:43:29 -07:00

105 lines
3.1 KiB
Bash

#!/bin/sh
set -eu
platform="$1"
python_version="$2"
python_interpreter="python${python_version}"
cd ~/
install_pip () {
if ! "${python_interpreter}" -m pip.__main__ --version --disable-pip-version-check 2>/dev/null; then
curl --silent --show-error https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
"${python_interpreter}" /tmp/get-pip.py --disable-pip-version-check --quiet
rm /tmp/get-pip.py
fi
}
if [ "${platform}" = "freebsd" ]; then
py_version="$(echo "${python_version}" | tr -d '.')"
while true; do
env ASSUME_ALWAYS_YES=YES pkg bootstrap && \
pkg install -q -y \
bash \
curl \
gtar \
"python${py_version}" \
"py${py_version}-Jinja2" \
"py${py_version}-virtualenv" \
"py${py_version}-cryptography" \
sudo \
&& break
echo "Failed to install packages. Sleeping before trying again..."
sleep 10
done
install_pip
if ! grep '^PermitRootLogin yes$' /etc/ssh/sshd_config > /dev/null; then
sed -i '' 's/^# *PermitRootLogin.*$/PermitRootLogin yes/;' /etc/ssh/sshd_config
service sshd restart
fi
elif [ "${platform}" = "rhel" ]; then
if grep '8\.' /etc/redhat-release; then
while true; do
yum module install -q -y python36 && \
yum install -q -y \
gcc \
python3-devel \
python3-jinja2 \
python3-virtualenv \
python3-cryptography \
iptables \
&& break
echo "Failed to install packages. Sleeping before trying again..."
sleep 10
done
else
while true; do
yum install -q -y \
gcc \
python-devel \
python-virtualenv \
python2-cryptography \
&& break
echo "Failed to install packages. Sleeping before trying again..."
sleep 10
done
install_pip
fi
elif [ "${platform}" = "osx" ]; then
while true; do
pip install --disable-pip-version-check --quiet \
virtualenv \
&& break
echo "Failed to install packages. Sleeping before trying again..."
sleep 10
done
fi
# Generate our ssh key and add it to our authorized_keys file.
# We also need to add localhost's server keys to known_hosts.
if [ ! -f "${HOME}/.ssh/id_rsa.pub" ]; then
ssh-keygen -m PEM -q -t rsa -N '' -f "${HOME}/.ssh/id_rsa"
cp "${HOME}/.ssh/id_rsa.pub" "${HOME}/.ssh/authorized_keys"
for key in /etc/ssh/ssh_host_*_key.pub; do
pk=$(cat "${key}")
echo "localhost ${pk}" >> "${HOME}/.ssh/known_hosts"
done
fi
# Improve prompts on remote host for interactive use.
# shellcheck disable=SC1117
cat << EOF > ~/.bashrc
alias ls='ls -G'
export PS1='\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
EOF
# Make sure ~/ansible/ is the starting directory for interactive shells.
if [ "${platform}" = "osx" ]; then
echo "cd ~/ansible/" >> ~/.bashrc
fi