This repository has been archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
init.sh
executable file
·46 lines (40 loc) · 1.62 KB
/
init.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
#!/bin/sh
# Copyright (c) 2018, WSO2 Inc. (http://wso2.com) All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#use sudo su command and hit enter to give root permissions
#run the file with the command sh init.sh
# PATH TO YOUR HOSTS FILE
ETC_HOSTS=/etc/hosts
# IP Name and IP Adress
# IP Address need to be set to a variable sent from the testgrid side including the IP Address of the Load balancer
IPName="is.qa.com"
IPLoadBalancer=$serverHost
if [ -z "$IPLoadBalancer" ]; then
echo "IPLoadBalancer is empty, please initiate it and proceed."
exit 1;
else
#Remove the host entry if exists
sudo sed -i '/is.qa.com/d' /etc/hosts
#Find the Public IP address of the ELB
PublicIP="$(ping -c 1 $IPLoadBalancer | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
HOSTS_LINE="$PublicIP\t$IPName"
echo "Adding $IPName to your $ETC_HOSTS";
sudo -- sh -c -e "echo '$HOSTS_LINE' >> $ETC_HOSTS";
if [ -n "$(grep $IPName $ETC_HOSTS)" ]; then
echo "$IPName was added succesfully \n $(grep $IPName $ETC_HOSTS)";
else
echo "Failed to Add $IPName, Try again!";
exit 1;
fi
fi