forked from tmobile/jazz-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
centos7-provision.sh
256 lines (219 loc) · 8.24 KB
/
centos7-provision.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
#
# File: centos7-provision.sh
# Description: Installs jazz prerequisites on a Centos7 ec2-instance.
# if you already have the prerequisites installed, just run Installer.sh
# directly from the from the cloned jazz-installer folder.
# Variables section
# URLS
TERRAFORM_URL="https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip"
ATLASSIAN_CLI_URL="https://bobswift.atlassian.net/wiki/download/attachments/16285777/atlassian-cli-6.7.1-distribution.zip"
INSTALLER_GITHUB_URL="https://github.com/tmobile/jazz-installer.git"
PIP_URL="https://bootstrap.pypa.io/get-pip.py"
# Installation directory
INSTALL_DIR=$(pwd)
# Log file to record the installation logs
LOG_FILE_NAME=provision_setup.out
LOG_FILE=$(realpath "$INSTALL_DIR"/"$LOG_FILE_NAME")
JAZZ_INSTALLER_BRANCH="master"
# Default verbosity of the installation
VERBOSE=0
NC='\033[0m'
GREEN='\033[0;32m'
RED='\033[0;31m'
print_info()
{
# shellcheck disable=SC2059
printf "\\r${GREEN}$1${NC}\\n" 1>&3 2>&4
}
print_error()
{
# shellcheck disable=SC2059
printf "\\r${RED}$1${NC}\\n" 1>&3 2>&4
}
#Spin wheel
function spin_wheel () {
pid=$1 # Process Id of the previous running command
message=$2
spin='-\|/'
printf "\\r%s...." "$message" 1>&3 2>&4
i=0
while ps -p "$pid" > /dev/null
do
i=$(( (i+1) %4 ))
# shellcheck disable=SC2059
printf "\\r${GREEN}$message....${spin:$i:1}" 1>&3 2>&4
sleep .05
done
while s=$(ps -p "$pid" -o s=) && [[ "$s" && "$s" != 'Z' ]]; do
sleep 1
done
exitcode=$?
if [ $exitcode -gt 0 ]
then
print_error "$message....Failed"
exit
else
print_info "$message....Completed"
fi
}
trap 'printf "${RED}\nCancelled....\n${NC}" 1>&3 2>&4; exit' 2
trap '' SIGTSTP
function install_packages () {
# Download and Installing Softwares required for Jazz centos7-provision
# 2. Java Jdk - 8u112-linux-x64
# 3. Unzip
# 4. AWSCLI
# 5. Terraform
# 7. Atlassian CLI - 6.7.1
#Fork output redirection so we can control output if VERBOSE is set
exec 3>&1
exec 4>&2
# print verbosity mode during installation
if [ "$1" == 1 ]; then
print_info "You have started the installer in verbose mode" 1>&3 2>&4
elif [ "$1" == 0 ]; then
# Redirecting the stdout and stderr to /dev/null for non-verbose installation
exec 1>/dev/null
exec 2>/dev/null
print_info "You have started the installer in non-verbose mode" 1>&3 2>&4
fi
print_info "You may view the detailed installation logs at $LOG_FILE" 1>&3 2>&4
# Install git
if command -v git > /dev/null; then
print_info "Git already installed, using it"
else
sudo yum install -y git >> "$LOG_FILE" &
spin_wheel $! "Installing git"
fi
# Download and Install java
if command -v java > /dev/null; then
print_info "Java already installed, using it"
else
sudo yum install -y java-1.8.0-openjdk >> "$LOG_FILE" &
spin_wheel $! "Installing java"
rm -rf jdk-8u112-linux-x64.rpm
fi
# Download and Install unzip
if command -v unzip > /dev/null; then
print_info "Unzip already installed, using it"
else
sudo yum install -y unzip >> "$LOG_FILE" &
spin_wheel $! "Installing unzip"
fi
# Create a temporary folder .
# Here we will have all the temporary files needed and delete it at the end
sudo rm -rf "$INSTALL"_DIR/jazz_tmp
mkdir "$INSTALL_DIR"/jazz_tmp
#Download and Install Terraform
curl -v -L "$TERRAFORM_URL" -o "$INSTALL_DIR"/jazz_tmp/terraform.zip >> "$LOG_FILE" &
spin_wheel $! "Downloading terraform"
sudo unzip -o "$INSTALL_DIR"/jazz_tmp/terraform.zip -d /usr/bin >> "$LOG_FILE" &
spin_wheel $! "Installing terraform"
#Downloading and Install atlassian-cli
curl -L "$ATLASSIAN_CLI_URL" -o "$INSTALL_DIR"/jazz_tmp/atlassian-cli-6.7.1-distribution.zip >> "$LOG_FILE" &
spin_wheel $! "Downloading atlassian-cli"
unzip -o "$INSTALL_DIR"/jazz_tmp/atlassian-cli-6.7.1-distribution.zip -d "$INSTALL_DIR"/jazz_tmp/ >> "$LOG_FILE" &
spin_wheel $! "Fetching atlassian-cli"
#Get Jazz installer code base
if [ -z "$JAZZ_INSTALLER_BRANCH" ]; then
echo "Jazz branch to clone"
print_info "Skipping installer repo clone based on CLI flag"
else
sudo rm -rf jazz-installer
git clone -b "$JAZZ_INSTALLER_BRANCH" "$INSTALLER_GITHUB_URL" --depth 1 >> "$LOG_FILE" &
spin_wheel $! "Fetching jazz-installer repo"
fi
#Download and install pip
if command -v pip > /dev/null; then
print_info "pip already installed, using it"
else
curl -sL "$PIP_URL" -o get-pip.py
sudo python get-pip.py >> "$LOG_FILE" &
spin_wheel $! "Downloading and installing pip"
fi
if command -v aws > /dev/null; then
print_info "awscli already installed, using it"
else
# Download and Install awscli
sudo pip install awscli >> "$LOG_FILE" &
spin_wheel $! "Downloading & installing awscli bundle"
fi
# Installing epel
sudo yum install epel-release -y &> /dev/null &
spin_wheel $! "Installing epel"
# Installing jq
sudo yum install jq -y &> /dev/null &
spin_wheel $! "Installing jq"
# Installing beautifulsoup4
sudo yum install python-beautifulsoup4 -y &> /dev/null &
spin_wheel $! "Installing beautifulsoup4"
# Installing lxml
sudo pip install lxml &> /dev/null &
spin_wheel $! "Installing lxml"
# Installing boto3
sudo pip install boto3 &> /dev/null &
spin_wheel $! "Installing boto3"
#Undo output redirection and close unused file descriptors.
exec 1>&3 3>&-
exec 2>&4 4>&-
}
# Running the selector
while [ $# -gt 0 ] ; do
case "$1" in
-h|--help)
echo "Installs jazz prerequisites on a Centos7 ec2-instance."
echo ""
echo "./centos7-provision.sh [options]"
echo ""
echo "options:"
echo "-ib, --installer-branch [optional] centos7-provision repo branch to use. Defaults to 'master'"
echo "-nc, --no-clone [optional] Skip cloning the jazz-installer repo into the current directory. Default: repo is cloned."
echo "-v, --verbose 1|0 [optional] Enable/Disable verbose centos7-provision logs. Default:0(Disabled)"
echo "-t, --tags Key=stackName,Value=production [optional] Specify as space separated key/value pairs"
echo "-h, --help [optional] Describe help"
exit 0 ;;
-ib|--installer-branch)
shift
if [ ! -z "$1" ] ; then
JAZZ_INSTALLER_BRANCH="$1"
else
echo "No arguments supplied for installer branch name."
echo "Usage: ./centos7-provision.sh -ib installer_branch_name"
exit 1
fi
shift ;;
-nc|--no-clone)
shift
JAZZ_INSTALLER_BRANCH=''
shift ;;
-v|--verbose)
shift
if [[ ("$#" -gt 0) && ("$1" == "1") ]] || [[ ("$#" -gt 0) && ("$1" == "0") ]] ; then
VERBOSE="$1"
else
echo "Please specify 1 or 0 for verbosity. Enable/Disable verbose centos7-provision logs. Default:0(Disabled)"
echo "Usage: ./centos7-provision --verbose 1"
exit 1
fi
shift ;;
-t|--tags)
shift
while [ "$#" -gt 0 ] ; do
if [[ "$1" =~ Key=.*,Value=.* ]] && [[ ! "$1" =~ ";" ]] ; then
arr+=("$1")
elif [[ $1 == -* ]] ; then break
else
echo "Please specify tags in format: Key=stackName,Value=production"
echo "Usage: ./centos7-provision --tags Key=stackName,Value=production Key=department,Value=devops"
exit 1
fi
shift
done ;;
*)
echo "Invalid flag!"
echo "Please run './centos7-provision.sh -h' to see all the available options."
exit 1 ;;
esac
done
install_packages "$VERBOSE"