-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·274 lines (230 loc) · 7.33 KB
/
install.sh
File metadata and controls
executable file
·274 lines (230 loc) · 7.33 KB
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
INSTALL_LOG=`mktemp /tmp/install_wavefront_XXXXXXXXXX.log`
function check_if_root_or_die() {
echo "Checking installation privileges"
echo -e "\nid -u" >>${INSTALL_LOG}
SCRIPT_UID=$(id -u)
if [ "$SCRIPT_UID" != 0 ]; then
echo "Installer should be run as root"
exit 1
fi
}
function exit_with_message() {
echo
echo $1
echo -e "\n$1" >> ${INSTALL_LOG}
if [[ $INSTALL_LOG && "$2" -eq 1 ]]; then
echo "For additional information, check the Wavefront install log: $INSTALL_LOG"
fi
echo
exit 1
}
function echo_right() {
TEXT=$1
echo
tput cuu1
tput cuf $(tput cols)
tput cub ${#TEXT}
echo $TEXT
}
function echo_failure() {
tput setaf 1 # 1 = red
echo_right "[ FAILED ]"
tput sgr0 # reset terminal
}
function exit_with_failure() {
echo_failure
exit_with_message "FAILURE: $1" 1
}
function install_pkg() {
if ! dpkg -s $1 >> ${INSTALL_LOG} 2>&1
then
echo "Installing $1 using apt-get"
apt-get install $1 -y >> ${INSTALL_LOG} 2>&1
fi
}
function remove_pkg() {
if ! dpkg -s $1 >> ${INSTALL_LOG} 2>&1
then
echo "Uninstalling $1 using apt-get"
apt-get remove $1 -y >> ${INSTALL_LOG} 2>&1
fi
}
function detect_operating_system() {
echo "Detecting operating system:"
if [ -f /etc/debian_version ]; then
echo -e "\ntest -f /etc/debian_version" >> ${INSTALL_LOG}
echo "Debian/Ubuntu"
OPERATING_SYSTEM="DEBIAN"
elif [ -f /etc/rocky-release ]; then
echo -e "\ntest -f /etc/rocky-release" >> ${INSTALL_LOG}
echo "Rocky Linux"
OPERATING_SYSTEM="ROCKY"
elif [ -f /etc/redhat-release ] || [ -f /etc/system-release-cpe ]; then
echo -e "\ntest -f /etc/redhat-release || test -f /etc/system-release-cpe" >> ${INSTALL_LOG}
echo "RedHat/CentOS"
OPERATING_SYSTEM="REDHAT"
elif [ "$(uname)" == "Darwin" ]; then
OPERATING_SYSTEM="MAC"
echo "Mac is not yet supported!"
exit 1
elif [ -f /etc/SUSE-brand ]; then
echo -e "\ntest -f /etc/SUSE-brand" >> ${INSTALL_LOG}
echo "OpenSUSE/SLE"
OPERATING_SYSTEM=`head -1 /etc/SUSE-brand`
else
echo -e "\ntest -f /etc/debian_version" >> "/tmp/wavefront_install.log"
echo -e "\ntest -f /etc/redhat-release || test -f /etc/system-release-cpe" >> ${INSTALL_LOG}
echo "Unsupported operating system"
exit 1
fi
export OPERATING_SYSTEM
}
function install_python() {
if [ $OPERATING_SYSTEM == "DEBIAN" ]; then
echo "Installing Python using apt-get"
apt-get update >> ${INSTALL_LOG} 2>&1
apt-get install python3 -y >> ${INSTALL_LOG} 2>&1
elif [ $OPERATING_SYSTEM == "REDHAT" ] || [ $OPERATING_SYSTEM == "ROCKY" ]; then
echo "Installing Python using yum"
yum install python3 -y >> ${INSTALL_LOG} 2>&1
elif [ $OPERATING_SYSTEM == "openSUSE" ] || [ $OPERATING_SYSTEM == "SLE" ]; then
echo "Installing Python using zypper"
zypper install python3 >> ${INSTALL_LOG} 2>&1
fi
if [ $? -ne 0 ]; then
exit_with_failure "Failed to install Python"
fi
}
function remove_python() {
PIP_PATH=$1
# wavefront cli
$PIP_PATH uninstall wavefront-cli -y
# pip
$PIP_PATH uninstall pip -y
# python
if [ $OPERATING_SYSTEM == "DEBIAN" ]; then
remove_pkg python3-distutils
echo "Uninstalling Python using apt-get"
apt-get remove python3 -y &> ${INSTALL_LOG}
apt-get autoremove -y &> ${INSTALL_LOG}
elif [ $OPERATING_SYSTEM == "REDHAT" ] || [ $OPERATING_SYSTEM == "ROCKY" ]; then
echo "Uninstalling Python using yum"
yum remove python3 -y &> ${INSTALL_LOG}
elif [ $OPERATING_SYSTEM == "openSUSE" ] || [ $OPERATING_SYSTEM == "SLE" ]; then
echo "Uninstalling Python using zypper"
zypper remove python3 &> ${INSTALL_LOG}
fi
}
function install_pip() {
PYTHON_PATH=$1
ver=$($PYTHON_PATH -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1\2/')
if [ "$ver" -lt "30" ]; then
curl -o /tmp/get-pip.py https://bootstrap.pypa.io/pip/2.7/get-pip.py >> ${INSTALL_LOG} 2>&1
elif [ "$ver" -ge "30" ]; then
curl -o /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py >> ${INSTALL_LOG} 2>&1
fi
if [ $? -ne 0 ]; then
exit_with_failure "Failed to download Pip"
fi
$PYTHON_PATH /tmp/get-pip.py >> ${INSTALL_LOG} 2>&1
if [ $? -ne 0 ]; then
exit_with_failure "Failed to install Pip"
fi
rm -f /tmp/get-pip.py 2> /dev/null
}
function install_wavecli() {
PIP_PATH=$1
$PIP_PATH uninstall wavefront-cli -y >> ${INSTALL_LOG} 2>&1
$PIP_PATH install "urllib3<2" >> ${INSTALL_LOG} 2>&1
$PIP_PATH install wavefront-cli >> ${INSTALL_LOG} 2>&1
if [ $? -ne 0 ]; then
exit_with_failure "Failed to install Wavefront CLI"
fi
# Find where it was installed
WAVE_PATH="/usr/local/bin/wave"
if [ -f "$WAVE_PATH" ]; then
echo "Wavefront CLI detected in $WAVE_PATH"
elif [ -f "/usr/bin/wave" ]; then
echo "Wavefront CLI detected in /usr/bin/wave"
WAVE_PATH="/usr/bin/wave"
else
exit_with_failure "Wavefront CLI not found."
fi
export WAVE_PATH
}
function detect_python(){
PYTHON_PATH=$(which python)
if [ -z "$PYTHON_PATH" ]; then
PYTHON_PATH=$(which python3)
fi
if [ -z "$PYTHON_PATH" ]; then
PYTHON_PATH=$(which python2)
fi
if [ -z "$PYTHON_PATH" ]; then
echo ""
else
echo "$PYTHON_PATH"
fi
}
function detect_pip(){
PIP_PATH=$(which pip)
if [ -z "$PIP_PATH" ]; then
PIP_PATH=$(which pip3)
fi
if [ -z "$PIP_PATH" ]; then
PIP_PATH=$(which pip2)
fi
if [ -z "$PIP_PATH" ]; then
echo ""
else
echo "$PIP_PATH"
fi
}
# main()
detect_operating_system
check_if_root_or_die
# If python was not installed before this script runs, uninstall it at the end.
PYTHON_INSTALLED=true
# Detect pip
PIP_PATH=$( detect_pip )
if [ "$PIP_PATH" == "" ]; then
# Detect python
PYTHON_PATH=$( detect_python )
if [ "$PYTHON_PATH" == "" ]; then
echo "Python is not installed. Installing Python."
echo "Python will be uninstalled automatically after installation finishes."
PYTHON_INSTALLED=false
install_python
PYTHON_PATH=$( detect_python )
if [ "$PYTHON_PATH" == "" ]; then
exit_with_failure "Failed to install python."
fi
else
echo "Python detected in ${PYTHON_PATH}"
fi
# Install distutils in Ubuntu, if not installed.
if [ $OPERATING_SYSTEM == "DEBIAN" ]; then
install_pkg python3-distutils
fi
echo "Pip is not installed, installing Pip."
install_pip $PYTHON_PATH
PIP_PATH=$( detect_pip )
if [ "$PIP_PATH" == "" ]; then
exit_with_failure "Failed to install pip."
fi
fi
# Make sure Wavefront CLI is installed. This function will export WAVE_PATH - holds the location of the wavefront cli binary
install_wavecli $PIP_PATH
# Capture command line args passed to shell script in a string
cli_args=""
for arg in "$@"
do
cli_args="$cli_args $arg"
done
# Run Cli installation process
$WAVE_PATH $cli_args
# Python was not installed before running this script, so remove it.
if [ $PYTHON_INSTALLED == false ]; then
remove_python $PIP_PATH
fi