This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
setup.sh
218 lines (181 loc) · 4.87 KB
/
setup.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
#!/usr/bin/env bash
#!/bin/bash
set -e
#
# Core check
#
TEST_FAILURE=FALSE
# Check if the internet connection is working
wget -q --tries=2 --timeout=5 --spider http://google.com
if [[ $? -eq 0 ]]; then
echo "Internet connection is available: PASSED"
else
echo "Internet connection is available: FAILED"
TEST_FAILURE=TRUE
fi
# Check if /usr/local/ directory exists & writable ( needed for installing GPDB software )
if [ -d /usr/local ]; then
echo "Directory /usr/local/ exists: PASSED"
else
echo "Directory /usr/local/ exists: FAILED"
TEST_FAILURE=TRUE
fi
if [ -w /usr/local ]; then
echo "Directory /usr/local/ writable: PASSED"
else
echo "Directory /usr/local/ writable: FAILED"
TEST_FAILURE=TRUE
fi
# Check if the BASE DIRECTORY exists & writable
BASE_DIR=`grep BASE_DIR config.yml | cut -d':' -f2 | awk '{print $1}'`
if [ -d "$BASE_DIR" ]; then
echo "Base directory $BASE_DIR exists: PASSED"
else
echo "Base directory $BASE_DIR exists: FAILED"
TEST_FAILURE=TRUE
fi
if [ -w "$BASE_DIR" ]; then
echo "Directory $BASE_DIR writable: PASSED"
else
echo "Directory $BASE_DIR writable: FAILED"
TEST_FAILURE=TRUE
fi
# Check if the hostname is reachable
host=`grep MASTER_HOST config.yml | cut -d':' -f2 | awk '{print $1}'`
ping -c 1 $host &>/dev/null
if [ $? -eq 0 ]; then
echo "Host $host can be reached: PASSED"
else
echo "Host $host can be reached: FAILED"
TEST_FAILURE=TRUE
fi
# If any one of the precheck failed, then exit the setup process.
if [ $TEST_FAILURE == "TRUE" ]; then
echo "Pre check failed, exiting...."
fi
#
# Download and install GO Binaries.
#
# Setting up go version to download
VERSION="1.7.4"
DFILE="go$VERSION.linux-amd64.tar.gz"
# If the version of go already exit then uninstall it
if [ -d "$HOME/.go" ]; then
rm -rf $HOME/.go
fi
# Downloading the go tar file
echo "Downloading the GO binary $DFILE ..., please wait might take few minutes based on your internet connection"
wget https://storage.googleapis.com/golang/$DFILE -O /tmp/go.tar.gz -q
if [ $? -ne 0 ]; then
echo "Download failed! Exiting."
exit 1
fi
# Extracting the file
echo "Extracting ..."
tar -C "$HOME" -xzf /tmp/go.tar.gz
mv "$HOME/go" "$HOME/.go"
chown -R gpadmin:gpadmin "$HOME/.go"
#
# Update environment information
#
# Updating the bashrc with the information of GOROOT.
if grep -q "GOROOT" "$HOME/.bashrc";
then
echo "GOROOT binaries location is already updated on the .bashrc file"
else
touch "$HOME/.bashrc"
{
echo '# Golang binaries'
echo 'export GOROOT=$HOME/.go'
echo 'export PATH=$PATH:$GOROOT/bin'
} >> "$HOME/.bashrc"
fi
# Update bashrc with the information of GOPATH.
if grep -q "GOPATH" "$HOME/.bashrc";
then
echo "GOPATH location is already updated on the .bashrc file"
else
pwd=`pwd`
touch "$HOME/.bashrc"
{
echo '# GOPATH location'
echo 'export GOPATH='${pwd}
echo 'export PATH=$PATH:$GOPATH/bin'
} >> "$HOME/.bashrc"
fi
# Remove the downloaded tar file
rm -f /tmp/go.tar.gz
#
# Upgrading the code (if any)
#
echo "Pulling newer version of the code"
if [ -f $HOME/.config.yml ]; then
cp config.yml /tmp/config.yml
fi
if [ -f /tmp/config.yml ]; then
mv /tmp/config.yml $HOME/.config.yml
else
cp config.yml $HOME/.config.yml
fi
#
# Removed the gopkg.in/yaml.v2 folder
#
echo "Removing src / pkg directory to pull in the newer version of the code"
rm -rf src/
rm -rf pkg/
#
# Download program dependencies
#
echo "Downloading program dependencies"
# go-logging package
# YAML package
source "$HOME/.bashrc"
go get github.com/op/go-logging
if [ $? -ne 0 ]; then
echo "Download failed of dependencies (go-logging) package failed. Exiting....."
exit 1
fi
# YAML package
source "$HOME/.bashrc"
go get gopkg.in/yaml.v2
if [ $? -ne 0 ]; then
echo "Download failed of dependencies (yaml.v2) package failed. Exiting....."
exit 1
fi
# gpdb source code
source "$HOME/.bashrc"
go get github.com/ielizaga/piv-go-gpdb
if [ $? -ne 0 ]; then
echo "Download failed of dependencies (piv-go-gpdb) package failed. Exiting....."
exit 1
fi
#
# Changing the owner to gpadmin:gpadmin
#
chown -R gpadmin:gpadmin /home/gpadmin
#
# Build go executable file.
#
echo "Compiling the program... "
# Compile the program
go build $GOPATH/src/github.com/ielizaga/piv-go-gpdb/gpdb.go
if [ $? -ne 0 ]; then
echo "Cannot build gpdb executable, exiting ....."
exit 1
fi
# move the binary file to bin directory
if [ ! -d bin ]; then
mkdir -p $GOPATH/bin/
fi
# move it to bin directory (forcefully, no need to prompt)
mv -f gpdb $GOPATH/bin/
#
# Changing the owner to gpadmin:gpadmin
#
chown -R gpadmin:gpadmin /home/gpadmin
#
# Success message.
#
echo "GPDBInstall Script has been successfully installed"
echo "Config file is cached at location: "$HOME/.config.yml
echo "Please close this terminal and open up a new terminal to set the environment"