-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_jumphost.sh
executable file
·195 lines (168 loc) · 7.34 KB
/
setup_jumphost.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env bash
setup_function () {
echo "Installing dependencies and setting up installer environment"
if [ `whoami` != "root" ]; then
echo "must run as root, try \"sudo su\" and re-run"
exit 1
fi
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
export PYTHONPATH=$PYTHONPATH:$DIR
#verify the default route and ping the gateway
gateway=$(ip route | awk '/default/ {print $3}')
ping "$gateway" -c 4 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Gateway IP $gateway is reachable"
else
echo
echo "==================================================================="
echo "Gateway IP $gateway is not reachable, please check the configuration"
echo "==================================================================="
exit 1
fi
#check internet is accessible, http google.com
ipaddr='8.8.8.8'
ping "$ipaddr" -c 4 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Internet is reachable via external IP address ($ipaddr)"
else
echo
echo "=========================================================="
echo "Internet is not reachable, please check routes to internet"
echo "=========================================================="
exit 1
fi
url='www.google.com'
ping "$url" -c 4 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Internet is reachable via URL ($url), DNS is working"
else
echo
echo "=========================================================="
echo "Internet is not reachable, please check DNS configuration"
echo "=========================================================="
exit 1
fi
#check ubuntu version
expected_os_ver='14.04.4'
current_ver=$(cat -n /etc/lsb-release | tail -n 1 | awk '{print $3}')
check_os_version() {
[ "$1" == "`echo -e "$1\n$2" | sort -V | tail -n1`" ]
}
output=$(check_os_version $expected_os_ver $current_ver && echo "yes" || echo "no")
if [ $output == "yes" ]; then
echo "Host OS version matches with that of the expected OS version $expected_os_ver."
else
echo
echo "========================================================================="
echo "Host OS version does not match with expecting OS version $expected_os_ver"
echo "========================================================================="
exit 1
fi
apt-get update
cur_intf=$(/sbin/ip route | awk '/default/ {print $5}')
ip_intf=$(/sbin/ip -o -4 addr list $cur_intf | awk '{print $4}')
ip_only=$(/sbin/ip -o -4 addr list $cur_intf | awk '{print $4}' | cut -d/ -f1)
subnet_mask=$(/sbin/ifconfig $cur_intf | grep Mask | cut -d":" -f4)
dns_server=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}' | head -n1)
dns_search=$(cat /etc/resolv.conf | grep search | awk '{print $2}')
echo "Check the bridge configuration.."
bridgename="extbr"
sudo brctl show
if [ $? -eq 0 ]; then
echo "bridge-utils package is installed"
brctl show | grep $bridgename
if [ $? -eq 0 ]; then
echo "Bridge interface extbr, exists"
else
echo "Bridge interface extbr does not exists, hence creating the same"
brctl addbr extbr
fi
grep "$bridgename" /etc/network/interfaces
if [ $? -eq 0 ]; then
echo "Bridge interface extbr related configuration is updated in /etc/network/interfaces file."
else
echo "Updating /etc/network/interface with extbr interface configuration"
/sbin/ifconfig $bridgename $ip_only netmask $subnet_mask up && brctl addif $bridgename $cur_intf && ifup $bridgename && /sbin/ifconfig $cur_intf 0.0.0.0 && /sbin/route add default gw $gateway
#modify /etc/network/interfaces file
mv /etc/network/interfaces /etc/network/interfaces.bak
cat << EOF >> /etc/network/interfaces
auto lo
iface lo inet loopback
auto $cur_intf
iface $cur_intf inet manual
auto $bridgename
iface $bridgename inet static
address $ip_only
netmask $subnet_mask
gateway $gateway
dns-nameservers $dns_server
dns-search $dns_search
bridge_ports $cur_intf
bridge_stp off
bridge_fd 0
bridge_maxwait 0
EOF
fi
else
echo "bridge-utils package is not installed, installing it"
apt-get install -y bridge-utils
#create internet/external bridge and add interface of the default route this it
brctl addbr $bridgename && /sbin/ifconfig $bridgename $ip_only netmask $subnet_mask up && brctl addif $bridgename $cur_intf && ifup $bridgename && /sbin/ifconfig $cur_intf 0.0.0.0 && /sbin/route add default gw $gateway
if [ $? != 0 ]; then
echo
echo "=============================================================="
echo "Bridge interface creation failed!!!! check logs at location $1"
echo "=============================================================="
exit 1
else
echo "Bridge interface extbr is created successfully.."
fi
#modify /etc/network/interfaces file
echo "Modifying /etc/network/interfaces file with extbr bridge details"
mv /etc/network/interfaces /etc/network/interfaces.bak
cat << EOF >> /etc/network/interfaces
auto lo
iface lo inet loopback
auto $cur_intf
iface $cur_intf inet manual
auto $bridgename
iface $bridgename inet static
address $ip_only
netmask $subnet_mask
gateway $gateway
dns-nameservers $dns_server
dns-search $dns_search
bridge_ports $cur_intf
bridge_stp off
bridge_fd 0
bridge_maxwait 0
EOF
fi
#enable SSH to allow root to login
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
echo 'UseDNS no' >> /etc/ssh/sshd_config
service ssh restart
#install required pkgs
apt-get install -y software-properties-common
apt-get install -y apache2 cpu-checker
apt-get install -y python-pip python-dev build-essential libssl-dev libffi-dev
pip install virtualenv
if [ -d "$DIR/.pockit" ]; then
rm -rf $DIR/.pockit
fi
virtualenv $DIR/.pockit --system-site-packages
source $DIR/.pockit/bin/activate
pip install --no-cache-dir --ignore-installed -r $DIR/requirements.txt
#copy of images existing in webserver folder
sudo cp -r $DIR/artifacts /var/www/html/pockit_images
echo
echo "**********************************************************************************"
echo "Setup completed, next step to provision servermanager by doing ./smgr_provision.sh"
echo "**********************************************************************************"
echo
exit 0
}
log_file_name="setup_jumphost_log"
current_time=$(date "+%Y_%m_%d_%H_%M_%S")
new_log_file="$log_file_name-$(date "+%Y_%m_%d_%H_%M_%S").txt"
setup_function $new_log_file 2>&1 | tee -a logs/$new_log_file