forked from redhat-developer/odo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
executable file
·297 lines (244 loc) · 8.99 KB
/
installer.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/bash
set -e
# The version of odo to install. Possible values - "master" and "latest"
# master - builds from git master branch
# latest - released versions specified by LATEST_VERSION variable
ODO_VERSION="latest"
# Latest released odo version
LATEST_VERSION="v1.0.0-beta3"
GITHUB_RELEASES_URL="https://github.com/openshift/odo/releases/download/${LATEST_VERSION}"
BINTRAY_URL="https://dl.bintray.com/odo/odo/latest"
INSTALLATION_PATH="/usr/local/bin/"
PRIVILEGED_EXECUTION="sh -c"
DEBIAN_GPG_PUBLIC_KEY="https://bintray.com/user/downloadSubjectPublicKey?username=bintray"
DEBIAN_MASTER_REPOSITORY="https://dl.bintray.com/odo/odo-deb-dev"
DEBIAN_LATEST_REPOSITORY="https://dl.bintray.com/odo/odo-deb-releases"
RPM_MASTER_YUM_REPO="https://bintray.com/odo/odo-rpm-dev/rpm"
RPM_LATEST_YUM_REPO="https://bintray.com/odo/odo-rpm-releases/rpm"
SUPPORTED_PLATFORMS="
darwin-amd64
linux-amd64
linux-arm
"
# Used to determine whether to install or uninstall odo
INSTALLER_ACTION=""
parse_installer_action_flag ()
{
case "$@" in
# Set INSTALLER_ACTION to uninstall odo or install odo
# Include --uninstall flag when running installer.sh to uninstall and simply run installer.sh to install latest version of odo
--uninstall)
INSTALLER_ACTION="uninstall"
;;
*)
INSTALLER_ACTION="install"
;;
esac
}
echo_stderr ()
{
echo "$@" >&2
}
command_exists() {
distribution=$(get_distribution)
case "$distribution" in
ubuntu|debian)
# Use which to verify install/uninstall on ubuntu and debian distributions
which "$@" > /dev/null 2>&1
;;
*)
command -v "$@" > /dev/null 2>&1
;;
esac
}
check_platform() {
kernel="$(uname -s)"
if [ "$(uname -m)" = "x86_64" ]; then
arch="amd64"
fi
platform_type=$(echo "${kernel}-${arch}" | tr '[:upper:]' '[:lower:]')
if ! echo "# $SUPPORTED_PLATFORMS" | grep "$platform_type" > /dev/null; then
echo_stderr "
# The installer has detected your platform to be $platform_type, which is
# currently not supported by this installer script.
# Please visit the following URL for detailed installation steps:
# https://github.com/openshift/odo/#installation"
exit 1
fi
echo "$platform_type"
}
get_distribution() {
lsb_dist=""
if [ -r /etc/os-release ]; then
lsb_dist="$(. /etc/os-release && echo "$ID")"
fi
echo "$lsb_dist"
}
set_privileged_execution() {
if [ "$(id -u)" != "0" ]; then
if command_exists sudo; then
echo "# Installer will run privileged commands with sudo"
PRIVILEGED_EXECUTION='sudo -E sh -c'
elif command_exists su ; then
echo "# Installer will run privileged commands with \"su -c\""
PRIVILEGED_EXECUTION='su -c'
else
echo_stderr "#
This installer needs to run as root. The current user is not root, and we could not find "sudo" or "su" installed on the system. Please run again with root privileges, or install "sudo" or "su" packages.
"
fi
else
echo "# Installer is being run as root"
fi
}
invalid_odo_version_error() {
echo_stderr "# Invalid value of odo version provided. Provide master or latest."
exit 1
}
installer_odo() {
echo "# Detecting distribution..."
platform="$(check_platform)"
echo "# Detected platform: $platform"
if [ "$INSTALLER_ACTION" == "install" ] && command_exists odo; then
echo_stderr echo_stderr "#
odo version \"$(odo version --client)\" is already installed on your system. Running this installer script might cause issues with your current installation. If you want to install odo using this script, please remove the current installation of odo from you system.
Aborting now!
"
exit 1
elif [ "$INSTALLER_ACTION" == "uninstall" ] && ! command_exists odo; then
echo_stderr "# odo is not installed on your system. Ending execution of uninstall script."
exit 1
fi
# macOS specific steps
if [ $platform = "darwin-amd64" ]; then
if ! command_exists brew; then
echo_stderr "# brew command does not exist. Please install brew and run the installer again."
fi
if [ "$INSTALLER_ACTION" == "install" ]; then
brew tap kadel/odo
echo "# Installing odo ${ODO_VERSION} on macOS"
case $ODO_VERSION in
master)
brew install kadel/odo/odo -- HEAD
;;
latest)
brew install kadel/odo/odo
esac
elif [ "$INSTALLER_ACTION" == "uninstall" ]; then
echo "# Uninstalling odo on macOS"
brew uninstall odo
fi
return 0
fi
set_privileged_execution
distribution=$(get_distribution)
echo "# Detected distribution: $distribution"
case "$distribution" in
ubuntu|debian)
if [ "$INSTALLER_ACTION" == "install" ]; then
echo "# Installing odo version: $ODO_VERSION on $distribution"
echo "# Installing pre-requisites..."
$PRIVILEGED_EXECUTION "apt-get update"
$PRIVILEGED_EXECUTION "apt-get install -y gnupg apt-transport-https curl"
echo "# "Adding GPG public key...
$PRIVILEGED_EXECUTION "curl -L \"$DEBIAN_GPG_PUBLIC_KEY\" | apt-key add -"
echo "# Adding repository to /etc/apt/sources.list"
case "$ODO_VERSION" in
master)
$PRIVILEGED_EXECUTION "echo \"deb $DEBIAN_MASTER_REPOSITORY stretch main\" | tee -a /etc/apt/sources.list"
;;
latest)
$PRIVILEGED_EXECUTION "echo \"deb $DEBIAN_LATEST_REPOSITORY stretch main\" | tee -a /etc/apt/sources.list"
;;
*)
invalid_odo_version_error
esac
$PRIVILEGED_EXECUTION "apt-get update"
$PRIVILEGED_EXECUTION "apt-get install -y odo"
elif [ "$INSTALLER_ACTION" == "uninstall" ]; then
echo "# Uninstalling odo..."
$PRIVILEGED_EXECUTION "apt-get remove -y odo"
fi
;;
centos|fedora)
package_manager=""
case "$distribution" in
fedora)
package_manager="dnf"
;;
centos)
package_manager="yum"
;;
esac
if [ "$INSTALLER_ACTION" == "install" ]; then
echo "# Installing odo version $ODO_VERSION on $distribution"
echo "# Adding odo repo under /etc/yum.repos.d/"
case "$ODO_VERSION" in
master)
$PRIVILEGED_EXECUTION "curl -L $RPM_MASTER_YUM_REPO -o /etc/yum.repos.d/bintray-odo-odo-rpm-dev.repo"
;;
latest)
$PRIVILEGED_EXECUTION "curl -L $RPM_LATEST_YUM_REPO -o /etc/yum.repos.d/bintray-odo-odo-rpm-releases.repo"
;;
*)
invalid_odo_version_error
esac
$PRIVILEGED_EXECUTION "$package_manager install -y odo"
elif [ "$INSTALLER_ACTION" == "uninstall" ]; then
echo "# Uninstalling odo..."
$PRIVILEGED_EXECUTION "$package_manager remove -y odo"
fi
;;
*)
if [ "$INSTALLER_ACTION" == "install" ]; then
echo "# Could not identify distribution. Proceeding with a binary install..."
BINARY_URL=""
TMP_DIR=$(mktemp -d)
case "$ODO_VERSION" in
master)
BINARY_URL="$BINTRAY_URL/$platform/odo"
echo "# Downloading odo from $BINARY_URL"
curl -Lo $TMP_DIR/odo "$BINARY_URL"
;;
latest)
BINARY_URL="$GITHUB_RELEASES_URL/odo-$platform.gz"
echo "# Downloading odo from $BINARY_URL"
curl -Lo $TMP_DIR/odo.gz "$BINARY_URL"
echo "# Extracting odo.gz"
gunzip -d $TMP_DIR/odo.gz
;;
*)
invalid_odo_version_error
esac
echo "# Setting execute permissions on odo"
chmod +x $TMP_DIR/odo
echo "# Moving odo binary to $INSTALLATION_PATH"
$PRIVILEGED_EXECUTION "mv $TMP_DIR/odo $INSTALLATION_PATH"
echo "# odo has been successfully installed on your machine"
rm -r $TMP_DIR
elif [ "$INSTALLER_ACTION" == "uninstall" ]; then
echo "# Proceeding with removing binary..."
rm -r $INSTALLATION_PATH/odo
fi
;;
esac
}
verify_odo() {
if [ $INSTALLER_ACTION == "install" ] && command_exists odo; then
echo "
# Verification complete!
# odo version \"$(odo version --client)\" has been installed at $(type -P odo)
"
elif [ "$INSTALLER_ACTION" == "uninstall" ] && ! command_exists odo; then
echo "
# Verification complete!
# odo has been uninstalled"
else
echo_stderr "
# Something is wrong with odo installer. Please run the installer script again. If the issue persists, please create an issue at https://github.com/openshift/odo/issues"
exit 1
fi
}
parse_installer_action_flag "$@"
installer_odo
verify_odo