mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.1 KiB
Bash
106 lines
3.1 KiB
Bash
8 years ago
|
#!/bin/sh
|
||
|
|
||
|
set -eu
|
||
|
|
||
|
platform="$1"
|
||
6 years ago
|
python_version="$2"
|
||
|
python_interpreter="python${python_version}"
|
||
8 years ago
|
|
||
|
cd ~/
|
||
|
|
||
6 years ago
|
install_pip () {
|
||
6 years ago
|
if ! "${python_interpreter}" -m pip.__main__ --version --disable-pip-version-check 2>/dev/null; then
|
||
6 years ago
|
curl --silent --show-error https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
|
||
6 years ago
|
"${python_interpreter}" /tmp/get-pip.py --disable-pip-version-check --quiet
|
||
6 years ago
|
rm /tmp/get-pip.py
|
||
|
fi
|
||
|
}
|
||
|
|
||
8 years ago
|
if [ "${platform}" = "freebsd" ]; then
|
||
6 years ago
|
py_version="$(echo "${python_version}" | tr -d '.')"
|
||
|
|
||
8 years ago
|
while true; do
|
||
7 years ago
|
env ASSUME_ALWAYS_YES=YES pkg bootstrap && \
|
||
6 years ago
|
pkg install -q -y \
|
||
8 years ago
|
bash \
|
||
|
curl \
|
||
|
gtar \
|
||
6 years ago
|
"python${py_version}" \
|
||
|
"py${py_version}-Jinja2" \
|
||
|
"py${py_version}-virtualenv" \
|
||
|
"py${py_version}-cryptography" \
|
||
8 years ago
|
sudo \
|
||
6 years ago
|
&& break
|
||
|
echo "Failed to install packages. Sleeping before trying again..."
|
||
|
sleep 10
|
||
8 years ago
|
done
|
||
8 years ago
|
|
||
6 years ago
|
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
|
||
8 years ago
|
elif [ "${platform}" = "rhel" ]; then
|
||
6 years ago
|
if grep '8\.' /etc/redhat-release; then
|
||
|
while true; do
|
||
6 years ago
|
yum module install -q -y python36 && \
|
||
|
yum install -q -y \
|
||
6 years ago
|
gcc \
|
||
|
python3-devel \
|
||
|
python3-jinja2 \
|
||
|
python3-virtualenv \
|
||
|
python3-cryptography \
|
||
|
iptables \
|
||
6 years ago
|
&& break
|
||
|
echo "Failed to install packages. Sleeping before trying again..."
|
||
|
sleep 10
|
||
6 years ago
|
done
|
||
|
else
|
||
|
while true; do
|
||
6 years ago
|
yum install -q -y \
|
||
6 years ago
|
gcc \
|
||
|
python-devel \
|
||
|
python-virtualenv \
|
||
|
python2-cryptography \
|
||
6 years ago
|
&& break
|
||
|
echo "Failed to install packages. Sleeping before trying again..."
|
||
|
sleep 10
|
||
6 years ago
|
done
|
||
|
|
||
6 years ago
|
install_pip
|
||
6 years ago
|
fi
|
||
6 years ago
|
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
|
||
8 years ago
|
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
|
||
6 years ago
|
ssh-keygen -m PEM -q -t rsa -N '' -f "${HOME}/.ssh/id_rsa"
|
||
8 years ago
|
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.
|
||
6 years ago
|
# shellcheck disable=SC1117
|
||
8 years ago
|
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
|
||
8 years ago
|
|
||
|
# Make sure ~/ansible/ is the starting directory for interactive shells.
|
||
|
if [ "${platform}" = "osx" ]; then
|
||
|
echo "cd ~/ansible/" >> ~/.bashrc
|
||
|
fi
|