-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·99 lines (82 loc) · 2.89 KB
/
install.sh
File metadata and controls
executable file
·99 lines (82 loc) · 2.89 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
#!/usr/bin/env sh
set -euo pipefail
INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}"
REPO="exasol-labs/saas-cli"
# ---------------------------------------------------------------------------
# Cleanup on exit
# ---------------------------------------------------------------------------
TMP_FILE=""
cleanup() {
if [ -n "$TMP_FILE" ] && [ -f "$TMP_FILE" ]; then
rm -f "$TMP_FILE"
fi
}
trap cleanup EXIT
# ---------------------------------------------------------------------------
# Platform detection
# ---------------------------------------------------------------------------
printf "Detecting platform... "
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin) OS_NAME="darwin" ;;
Linux) OS_NAME="linux" ;;
*)
echo ""
echo "Error: unsupported platform: ${OS}/${ARCH}"
echo "Download manually from: https://github.com/${REPO}/releases"
exit 1
;;
esac
case "$ARCH" in
x86_64) ARCH_NAME="amd64" ;;
arm64|aarch64) ARCH_NAME="arm64" ;;
*)
echo ""
echo "Error: unsupported platform: ${OS}/${ARCH}"
echo "Download manually from: https://github.com/${REPO}/releases"
exit 1
;;
esac
BINARY="exasol-saas-${OS_NAME}-${ARCH_NAME}"
echo "${OS_NAME}/${ARCH_NAME}"
# ---------------------------------------------------------------------------
# Version resolution
# ---------------------------------------------------------------------------
printf "Resolving latest version... "
if [ -z "${VERSION:-}" ]; then
VERSION="$(curl -fsSL -H "User-Agent: exasol-saas-installer" \
"https://api.github.com/repos/${REPO}/releases/latest" \
| grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')"
if [ -z "$VERSION" ]; then
echo ""
echo "Error: could not resolve latest version from GitHub API"
echo "Try setting VERSION manually: VERSION=v0.1.0 sh install.sh"
exit 1
fi
fi
echo "$VERSION"
# ---------------------------------------------------------------------------
# Download
# ---------------------------------------------------------------------------
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY}"
TMP_FILE="$(mktemp)"
echo "Downloading ${BINARY}..."
if ! curl -fsSL "$DOWNLOAD_URL" -o "$TMP_FILE"; then
echo "Error: download failed from ${DOWNLOAD_URL}"
exit 1
fi
# ---------------------------------------------------------------------------
# Install
# ---------------------------------------------------------------------------
mkdir -p "$INSTALL_DIR"
INSTALL_PATH="${INSTALL_DIR}/exasol-saas"
echo "Installing to ${INSTALL_PATH}..."
chmod +x "$TMP_FILE"
mv "$TMP_FILE" "$INSTALL_PATH"
TMP_FILE="" # prevent cleanup trap from trying to remove it
# ---------------------------------------------------------------------------
# Verify
# ---------------------------------------------------------------------------
"$INSTALL_PATH" --version
echo "exasol-saas ${VERSION} installed to ${INSTALL_PATH}"