2016-11-30 06:21:53 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
platform="$1"
|
2019-03-28 00:40:27 +01:00
|
|
|
python_version="$2"
|
|
|
|
python_interpreter="python${python_version}"
|
2016-11-30 06:21:53 +01:00
|
|
|
|
|
|
|
cd ~/
|
|
|
|
|
2019-03-27 05:20:35 +01:00
|
|
|
install_pip () {
|
2019-03-28 00:40:27 +01:00
|
|
|
if ! "${python_interpreter}" -m pip.__main__ --version --disable-pip-version-check 2>/dev/null; then
|
2019-03-27 05:20:35 +01:00
|
|
|
curl --silent --show-error https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py
|
2019-03-28 00:40:27 +01:00
|
|
|
"${python_interpreter}" /tmp/get-pip.py --disable-pip-version-check --quiet
|
2019-03-27 05:20:35 +01:00
|
|
|
rm /tmp/get-pip.py
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-11-30 06:21:53 +01:00
|
|
|
if [ "${platform}" = "freebsd" ]; then
|
2019-03-28 00:40:27 +01:00
|
|
|
py_version="$(echo "${python_version}" | tr -d '.')"
|
|
|
|
|
2017-07-14 06:24:22 +02:00
|
|
|
while true; do
|
2017-11-29 09:46:08 +01:00
|
|
|
env ASSUME_ALWAYS_YES=YES pkg bootstrap && \
|
2019-03-27 05:20:35 +01:00
|
|
|
pkg install -q -y \
|
2017-07-14 06:24:22 +02:00
|
|
|
bash \
|
|
|
|
curl \
|
|
|
|
gtar \
|
2019-03-28 00:40:27 +01:00
|
|
|
"python${py_version}" \
|
|
|
|
"py${py_version}-Jinja2" \
|
|
|
|
"py${py_version}-virtualenv" \
|
|
|
|
"py${py_version}-cryptography" \
|
2017-07-14 06:24:22 +02:00
|
|
|
sudo \
|
2019-03-27 05:20:35 +01:00
|
|
|
&& break
|
|
|
|
echo "Failed to install packages. Sleeping before trying again..."
|
|
|
|
sleep 10
|
2017-07-14 06:24:22 +02:00
|
|
|
done
|
2017-07-08 07:28:53 +02:00
|
|
|
|
2019-03-27 05:20:35 +01:00
|
|
|
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
|
2017-07-08 01:52:40 +02:00
|
|
|
elif [ "${platform}" = "rhel" ]; then
|
2018-11-17 04:09:27 +01:00
|
|
|
if grep '8\.' /etc/redhat-release; then
|
|
|
|
while true; do
|
2019-03-27 05:20:35 +01:00
|
|
|
yum module install -q -y python36 && \
|
|
|
|
yum install -q -y \
|
2018-11-17 04:09:27 +01:00
|
|
|
gcc \
|
|
|
|
python3-devel \
|
|
|
|
python3-jinja2 \
|
|
|
|
python3-virtualenv \
|
|
|
|
python3-cryptography \
|
|
|
|
iptables \
|
2019-03-27 05:20:35 +01:00
|
|
|
&& break
|
|
|
|
echo "Failed to install packages. Sleeping before trying again..."
|
|
|
|
sleep 10
|
2018-11-17 04:09:27 +01:00
|
|
|
done
|
|
|
|
else
|
|
|
|
while true; do
|
2019-03-27 05:20:35 +01:00
|
|
|
yum install -q -y \
|
2018-11-17 04:09:27 +01:00
|
|
|
gcc \
|
|
|
|
python-devel \
|
|
|
|
python-virtualenv \
|
|
|
|
python2-cryptography \
|
2019-03-27 05:20:35 +01:00
|
|
|
&& break
|
|
|
|
echo "Failed to install packages. Sleeping before trying again..."
|
|
|
|
sleep 10
|
2018-11-17 04:09:27 +01:00
|
|
|
done
|
|
|
|
|
2019-03-27 05:20:35 +01:00
|
|
|
install_pip
|
2018-11-17 04:09:27 +01:00
|
|
|
fi
|
2020-06-23 19:09:06 +02:00
|
|
|
|
|
|
|
# pin packaging and pyparsing to match the downstream vendored versions
|
|
|
|
"${python_interpreter}" -m pip install packaging==20.4 pyparsing==2.4.7 --disable-pip-version-check
|
2020-04-16 01:22:17 +02:00
|
|
|
elif [ "${platform}" = "centos" ]; then
|
|
|
|
while true; do
|
|
|
|
yum install -q -y \
|
|
|
|
gcc \
|
|
|
|
python-devel \
|
|
|
|
python-virtualenv \
|
|
|
|
python2-cryptography \
|
|
|
|
libffi-devel \
|
|
|
|
openssl-devel \
|
|
|
|
&& break
|
|
|
|
echo "Failed to install packages. Sleeping before trying again..."
|
|
|
|
sleep 10
|
|
|
|
done
|
|
|
|
|
|
|
|
install_pip
|
2019-03-27 05:20:35 +01:00
|
|
|
elif [ "${platform}" = "osx" ]; then
|
|
|
|
while true; do
|
|
|
|
pip install --disable-pip-version-check --quiet \
|
2020-02-11 01:29:47 +01:00
|
|
|
'virtualenv<20' \
|
2019-03-27 05:20:35 +01:00
|
|
|
&& break
|
|
|
|
echo "Failed to install packages. Sleeping before trying again..."
|
|
|
|
sleep 10
|
|
|
|
done
|
2020-01-30 00:56:51 +01:00
|
|
|
elif [ "${platform}" = "aix" ]; then
|
|
|
|
chfs -a size=1G /
|
2020-02-09 20:17:33 +01:00
|
|
|
chfs -a size=4G /usr
|
2020-01-30 00:56:51 +01:00
|
|
|
chfs -a size=1G /var
|
|
|
|
chfs -a size=1G /tmp
|
2020-02-09 20:17:33 +01:00
|
|
|
chfs -a size=2G /opt
|
2020-01-30 00:56:51 +01:00
|
|
|
while true; do
|
|
|
|
yum install -q -y \
|
|
|
|
gcc \
|
|
|
|
libffi-devel \
|
|
|
|
python-jinja2 \
|
|
|
|
python-cryptography \
|
|
|
|
python-pip && \
|
|
|
|
pip install --disable-pip-version-check --quiet virtualenv \
|
|
|
|
&& break
|
|
|
|
echo "Failed to install packages. Sleeping before trying again..."
|
|
|
|
sleep 10
|
|
|
|
done
|
2016-11-30 06:21:53 +01:00
|
|
|
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
|
2019-01-23 23:19:54 +01:00
|
|
|
ssh-keygen -m PEM -q -t rsa -N '' -f "${HOME}/.ssh/id_rsa"
|
2019-10-07 23:36:05 +02:00
|
|
|
# newer ssh-keygen PEM output (such as on RHEL 8.1) is not recognized by paramiko
|
|
|
|
touch "${HOME}/.ssh/id_rsa.new"
|
|
|
|
chmod 0600 "${HOME}/.ssh/id_rsa.new"
|
|
|
|
sed 's/\(BEGIN\|END\) PRIVATE KEY/\1 RSA PRIVATE KEY/' "${HOME}/.ssh/id_rsa" > "${HOME}/.ssh/id_rsa.new"
|
|
|
|
mv "${HOME}/.ssh/id_rsa.new" "${HOME}/.ssh/id_rsa"
|
2020-01-28 20:04:36 +01:00
|
|
|
cat "${HOME}/.ssh/id_rsa.pub" >> "${HOME}/.ssh/authorized_keys"
|
|
|
|
chmod 0600 "${HOME}/.ssh/authorized_keys"
|
2016-11-30 06:21:53 +01:00
|
|
|
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.
|
2018-09-21 20:38:22 +02:00
|
|
|
# shellcheck disable=SC1117
|
2016-11-30 06:21:53 +01:00
|
|
|
cat << EOF > ~/.bashrc
|
2020-01-28 20:24:56 +01:00
|
|
|
if ls --color > /dev/null 2>&1; then
|
|
|
|
alias ls='ls --color'
|
|
|
|
elif ls -G > /dev/null 2>&1; then
|
|
|
|
alias ls='ls -G'
|
|
|
|
fi
|
2016-11-30 06:21:53 +01:00
|
|
|
export PS1='\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
|
|
|
EOF
|
2017-07-08 01:52:40 +02:00
|
|
|
|
|
|
|
# Make sure ~/ansible/ is the starting directory for interactive shells.
|
|
|
|
if [ "${platform}" = "osx" ]; then
|
|
|
|
echo "cd ~/ansible/" >> ~/.bashrc
|
|
|
|
fi
|