-
Notifications
You must be signed in to change notification settings - Fork 20
/
install-latest.sh
executable file
·238 lines (214 loc) · 6.91 KB
/
install-latest.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
#!/usr/bin/env sh
# a lot of inspiration for this installer was taken from the tailscale installer script at https://github.com/tailscale/tailscale/blob/827abbeeaaf21388ec0dc7046d61d8350afe98f7/scripts/installer.sh
# exit if one command exits with non-zero exit code and treat unset variables as an error
set -eu
# detect the latest version of the exoscale cli
LATEST_URL=$(curl -L -s -o /dev/null -w %{url_effective} https://github.com/exoscale/cli/releases/latest)
LATEST_TAG=$(basename "${LATEST_URL}")
LATEST_VERSION=$(echo "$LATEST_TAG" | cut -c 2-)
OSTYPE=""
CPUARCHITECTURE=""
FILEEXT=""
PACKAGETYPE=""
is_apt_newer_than_v2_2() {
apt_version=$(apt-get --version 2>&1 | grep -oP '(?<=apt )[0-9]+\.[0-9]+\.[0-9]+')
if [ -z "$apt_version" ]; then
# can't determine apt version
return 1
elif [ "$(
dpkg --compare-versions "$apt_version" ge "2.2.0"
echo $?
)" -eq 0 ]; then
# apt is >= 2.2.0
return 0
else
# apt is < 2.2.0
return 1
fi
}
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
debian | ubuntu | pop | neon | zorin | linuxmint | elementary | parrot | mendel | galliumos | pureos | raspian | kali | Deepin)
if is_apt_newer_than_v2_2; then
PACKAGETYPE="apt"
else
PACKAGETYPE="dpkg"
fi
FILEEXT="deb"
OSTYPE="linux"
;;
fedora | rocky | almalinux | nobara | openmandriva | sangoma | risios)
PACKAGETYPE="dnf"
FILEEXT="rpm"
OSTYPE="linux"
;;
rhel)
VERSION="$(echo "$VERSION_ID" | cut -f1 -d.)"
PACKAGETYPE="dnf"
FILEEXT="rpm"
if [ "$VERSION" = "7" ]; then
PACKAGETYPE="yum"
fi
;;
centos)
PACKAGETYPE="dnf"
FILEEXT="rpm"
OSTYPE="linux"
if [ "$VERSION_ID" = "7" ]; then
PACKAGETYPE="yum"
fi
;;
amzn | xenenterprise)
PACKAGETYPE="yum"
FILEEXT="rpm"
OSTYPE="linux"
;;
*)
echo "your OS is not supported by this script, please install manually https://community.exoscale.com/documentation/tools/exoscale-command-line-interface/#installation"
exit 1
;;
esac
fi
# detect the cpu architecture
CPUARCHITECTURE="$(uname -m)"
case "$(uname -m)" in
x86_64)
CPUARCHITECTURE="amd64"
;;
aarch64)
CPUARCHITECTURE="arm64"
;;
armv7l)
CPUARCHITECTURE="armv7"
;;
esac
# Ideally we want to use curl, but on some installs we
# only have wget. Detect and use what's available.
CURL=
if type curl >/dev/null; then
CURL="curl -fsSL"
elif type wget >/dev/null; then
CURL="wget -q -O-"
fi
if [ -z "$CURL" ]; then
echo "The installer needs either curl or wget to download files."
echo "Please install either curl or wget to proceed."
exit 1
fi
TEST_URL="https://www.exoscale.com/"
RC=0
TEST_OUT=$($CURL "$TEST_URL" 2>&1) || RC=$?
if [ $RC != 0 ]; then
echo "The installer cannot reach $TEST_URL"
echo "Please make sure that your machine has internet access."
echo "Test output:"
echo $TEST_OUT
exit 1
fi
# work out if we can run privileged commands, and if so, how
CAN_ROOT=
SUDO=
if [ "$(id -u)" = 0 ]; then
CAN_ROOT=1
SUDO=""
elif type sudo >/dev/null; then
CAN_ROOT=1
SUDO="sudo"
elif type doas >/dev/null; then
CAN_ROOT=1
SUDO="doas"
fi
if [ "$CAN_ROOT" != "1" ]; then
echo "This installer needs to run commands as root."
echo "We tried looking for 'sudo' and 'doas', but couldn't find them."
echo "Either re-run this script as root, or set up sudo/doas."
exit 1
fi
GITHUB_DOWNLOAD_URL="https://github.com/exoscale/cli/releases/download"
TEMPDIR=$(mktemp -d)
PKGPREFIX="exoscale-cli"
PKGFILE="${PKGPREFIX}_${LATEST_VERSION}_${OSTYPE}_${CPUARCHITECTURE}.${FILEEXT}"
PKGSIGFILE=$PKGFILE.sig
PKGPATH=$TEMPDIR/$PKGFILE
PKGSIGPATH=$TEMPDIR/$PKGSIGFILE
download_pkg() {
$CURL "$GITHUB_DOWNLOAD_URL/${LATEST_TAG}/$PKGFILE" >$PKGPATH
CHECKSUMSFILE="${PKGPREFIX}_${LATEST_VERSION}_checksums.txt"
CHECKSUMSPATH=$TEMPDIR/$CHECKSUMSFILE
$CURL "$GITHUB_DOWNLOAD_URL/${LATEST_TAG}/$CHECKSUMSFILE" >$CHECKSUMSPATH
COMPUTED_CHECKSUM=$(sha256sum "$PKGPATH" | cut -d " " -f 1)
EXPECTED_CHECKSUM=$(grep -m 1 $PKGFILE $CHECKSUMSPATH | cut -d " " -f 1)
if [ "$COMPUTED_CHECKSUM" != "$EXPECTED_CHECKSUM" ]; then
echo "Error: Checksum of $PKGFILE does not match the expected checksum"
echo $COMPUTED_CHECKSUM
echo $EXPECTED_CHECKSUM
exit 1
fi
}
TOOLING_KEY_NAME="Exoscale Tooling <tooling@exoscale.ch>"
TOOLING_KEY_FINGERPRINT="7100E8BFD6199CE0374CB7F003686F8CDE378D41"
GPG_AVAILABLE=no
# downloads and verifies the signature file for the package if gpg is available
verify_pkg() {
if [ "$GPG_AVAILABLE" = "yes" ]; then
$CURL "$GITHUB_DOWNLOAD_URL/${LATEST_TAG}/$PKGSIGFILE" >$PKGSIGPATH
gpg --verify $PKGSIGPATH $PKGPATH
fi
}
if command -v gpg >/dev/null 2>&1 && [ "$PACKAGETYPE" != "yum" ]; then
if ! gpg --list-keys | grep -q $TOOLING_KEY_FINGERPRINT; then
gpg --keyserver keys.openpgp.org --recv-keys "$TOOLING_KEY_FINGERPRINT"
fi
GPG_AVAILABLE=yes
else
if [ "$PACKAGETYPE" = "apt" ]; then
# since gpg is not available, we have to fall back to installing via dpkg
PACKAGETYPE="dpkg"
fi
fi
install_rpm_pkg() {
repofile=/etc/yum.repos.d/exoscale-cli.repo
cat <<EOF | $SUDO tee $repofile
[exoscale-cli-repo]
name=exoscale-cli-repo
baseurl=https://sos-ch-gva-2.exo.io/exoscale-packages/rpm/cli
enabled=1
repo_gpgcheck=1
gpgcheck=0
gpgkey=https://keys.openpgp.org/vks/v1/by-fingerprint/7100E8BFD6199CE0374CB7F003686F8CDE378D41
EOF
if [ "$PACKAGETYPE" = "yum" ]; then
REPOFLAG=""
else
REPOFLAG="--repo=exoscale-cli-repo"
fi
if $PACKAGETYPE list installed exoscale-cli >/dev/null 2>&1; then
$SUDO $PACKAGETYPE makecache -y $REPOFLAG
$SUDO $PACKAGETYPE $REPOFLAG upgrade -y exoscale-cli
else
$SUDO $PACKAGETYPE makecache -y $REPOFLAG
$SUDO $PACKAGETYPE $REPOFLAG install -y exoscale-cli
fi
}
echo "Installing exo CLI, using $PACKAGETYPE"
case "$PACKAGETYPE" in
apt)
$SUDO mkdir -p /etc/apt/keyrings
gpg --export $TOOLING_KEY_FINGERPRINT | $SUDO tee /etc/apt/keyrings/exoscale.gpg >/dev/null
echo "deb [signed-by=/etc/apt/keyrings/exoscale.gpg] https://sos-ch-gva-2.exo.io/exoscale-packages/deb/cli stable main" | $SUDO tee /etc/apt/sources.list.d/exoscale.list >/dev/null
$SUDO apt-get update
$SUDO apt-get install -y exoscale-cli
;;
dpkg)
download_pkg
verify_pkg
$SUDO dpkg -i $PKGPATH
;;
yum)
install_rpm_pkg
;;
dnf)
install_rpm_pkg
;;
esac