forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.sh
88 lines (71 loc) · 2.44 KB
/
remote.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
set -eu
platform="$1"
env
cd ~/
if [ "${platform}" = "freebsd" ]; then
while true; do
env ASSUME_ALWAYS_YES=YES pkg bootstrap && \
pkg install -y \
bash \
curl \
gtar \
python \
py27-Jinja2 \
py27-virtualenv \
py27-cryptography \
sudo \
&& break
echo "Failed to install packages. Sleeping before trying again..."
sleep 10
done
pip --version 2>/dev/null || curl --silent --show-error https://bootstrap.pypa.io/get-pip.py | python
elif [ "${platform}" = "rhel" ]; then
while true; do
yum install -y \
gcc \
python-devel \
python-jinja2 \
python-virtualenv \
python2-cryptography \
&& break
echo "Failed to install packages. Sleeping before trying again..."
sleep 10
done
pip --version 2>/dev/null || curl --silent --show-error https://bootstrap.pypa.io/get-pip.py | python
fi
if [ "${platform}" = "freebsd" ] || [ "${platform}" = "osx" ]; then
pip install 'virtualenv<20'
# Tests assume loopback addresses other than 127.0.0.1 will work.
# Add aliases for loopback addresses used by tests.
for i in 3 4 254; do
ifconfig lo0 alias "127.0.0.${i}" up
done
ifconfig lo0
fi
# Since tests run as root, we also need to be able to ssh to localhost as root.
sed -i= 's/^# *PermitRootLogin.*$/PermitRootLogin yes/;' /etc/ssh/sshd_config
if [ "${platform}" = "freebsd" ]; then
# Restart sshd for configuration changes and loopback aliases to work.
service sshd restart
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 -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