Skip to content

Commit 71c3597

Browse files
feat: installer
1 parent bccfb15 commit 71c3597

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-0
lines changed

install.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env sh
2+
set -euo pipefail
3+
4+
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
5+
REPO="exasol-labs/saas-cli"
6+
7+
# ---------------------------------------------------------------------------
8+
# Cleanup on exit
9+
# ---------------------------------------------------------------------------
10+
11+
TMP_FILE=""
12+
cleanup() {
13+
if [ -n "$TMP_FILE" ] && [ -f "$TMP_FILE" ]; then
14+
rm -f "$TMP_FILE"
15+
fi
16+
}
17+
trap cleanup EXIT
18+
19+
# ---------------------------------------------------------------------------
20+
# Platform detection
21+
# ---------------------------------------------------------------------------
22+
23+
printf "Detecting platform... "
24+
OS="$(uname -s)"
25+
ARCH="$(uname -m)"
26+
27+
case "$OS" in
28+
Darwin) OS_NAME="darwin" ;;
29+
Linux) OS_NAME="linux" ;;
30+
*)
31+
echo ""
32+
echo "Error: unsupported platform: ${OS}/${ARCH}"
33+
echo "Download manually from: https://github.com/${REPO}/releases"
34+
exit 1
35+
;;
36+
esac
37+
38+
case "$ARCH" in
39+
x86_64) ARCH_NAME="amd64" ;;
40+
arm64|aarch64) ARCH_NAME="arm64" ;;
41+
*)
42+
echo ""
43+
echo "Error: unsupported platform: ${OS}/${ARCH}"
44+
echo "Download manually from: https://github.com/${REPO}/releases"
45+
exit 1
46+
;;
47+
esac
48+
49+
BINARY="exasol-saas-${OS_NAME}-${ARCH_NAME}"
50+
echo "${OS_NAME}/${ARCH_NAME}"
51+
52+
# ---------------------------------------------------------------------------
53+
# Version resolution
54+
# ---------------------------------------------------------------------------
55+
56+
printf "Resolving latest version... "
57+
if [ -z "${VERSION:-}" ]; then
58+
VERSION="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \
59+
| grep '"tag_name"' | sed 's/.*"tag_name": *"\(.*\)".*/\1/')"
60+
if [ -z "$VERSION" ]; then
61+
echo ""
62+
echo "Error: could not resolve latest version from GitHub API"
63+
echo "Try setting VERSION manually: VERSION=v0.1.0 sh install.sh"
64+
exit 1
65+
fi
66+
fi
67+
echo "$VERSION"
68+
69+
# ---------------------------------------------------------------------------
70+
# Download
71+
# ---------------------------------------------------------------------------
72+
73+
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY}"
74+
TMP_FILE="$(mktemp)"
75+
76+
echo "Downloading ${BINARY}..."
77+
if ! curl -fsSL "$DOWNLOAD_URL" -o "$TMP_FILE"; then
78+
echo "Error: download failed from ${DOWNLOAD_URL}"
79+
exit 1
80+
fi
81+
82+
# ---------------------------------------------------------------------------
83+
# Install
84+
# ---------------------------------------------------------------------------
85+
86+
INSTALL_PATH="${INSTALL_DIR}/exasol-saas"
87+
echo "Installing to ${INSTALL_PATH}..."
88+
chmod +x "$TMP_FILE"
89+
mv "$TMP_FILE" "$INSTALL_PATH"
90+
TMP_FILE="" # prevent cleanup trap from trying to remove it
91+
92+
# ---------------------------------------------------------------------------
93+
# Verify
94+
# ---------------------------------------------------------------------------
95+
96+
"$INSTALL_PATH" --version
97+
echo "exasol-saas ${VERSION} installed to ${INSTALL_PATH}"

specs/installer/spec.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Spec: installer
2+
3+
A one-liner shell script that downloads and installs the correct pre-built `exasol-saas` binary for the current platform directly from the latest GitHub release.
4+
5+
## Output file
6+
7+
`install.sh` (repo root)
8+
9+
## Purpose
10+
11+
Allow users to install the CLI without cloning the repo, building from source, or manually selecting the right binary. A single `curl | sh` command handles everything.
12+
13+
## Usage
14+
15+
```bash
16+
curl -fsSL https://raw.githubusercontent.com/exasol-labs/saas-cli/main/install.sh | sh
17+
```
18+
19+
Users may also override the install directory:
20+
21+
```bash
22+
curl -fsSL .../install.sh | INSTALL_DIR=/usr/local/bin sh
23+
```
24+
25+
## Platform detection
26+
27+
Detect OS and architecture at runtime using `uname`.
28+
29+
### Supported platforms
30+
31+
| OS | Arch | Binary name |
32+
|---|---|---|
33+
| macOS | x86_64 / amd64 | `exasol-saas-darwin-amd64` |
34+
| macOS | arm64 (Apple Silicon) | `exasol-saas-darwin-arm64` |
35+
| Linux | x86_64 / amd64 | `exasol-saas-linux-amd64` |
36+
| Linux | aarch64 / arm64 | `exasol-saas-linux-arm64` |
37+
38+
Windows is not supported by this script (Windows users should download manually from the releases page).
39+
40+
If the detected OS/arch combination is unsupported, print a clear error with a link to the releases page and exit non-zero:
41+
```
42+
Error: unsupported platform: <OS>/<arch>
43+
Download manually from: https://github.com/exasol-labs/saas-cli/releases
44+
```
45+
46+
## Version resolution
47+
48+
By default, resolve the latest release version from the GitHub API:
49+
50+
```bash
51+
VERSION=$(curl -fsSL https://api.github.com/repos/exasol-labs/saas-cli/releases/latest \
52+
| grep '"tag_name"' | sed 's/.*"tag_name": *"\(.*\)".*/\1/')
53+
```
54+
55+
Users may pin a specific version via the `VERSION` environment variable:
56+
57+
```bash
58+
curl -fsSL .../install.sh | VERSION=v0.1.0 sh
59+
```
60+
61+
If version resolution fails (e.g. no network access to GitHub API, no releases published yet), print a clear error and exit non-zero.
62+
63+
## Download
64+
65+
Construct the download URL from the resolved version and binary name:
66+
67+
```
68+
https://github.com/exasol-labs/saas-cli/releases/download/<VERSION>/<BINARY>
69+
```
70+
71+
Download to a temporary file using `curl -fsSL`. On failure, print a clear error and exit non-zero.
72+
73+
## Install directory
74+
75+
Default install directory: `/usr/local/bin`.
76+
77+
Override via the `INSTALL_DIR` environment variable.
78+
79+
After downloading, move the binary to `$INSTALL_DIR/exasol-saas` and make it executable (`chmod +x`).
80+
81+
If the install directory is not writable, the `mv` will fail and bash's `-e` flag exits with a clear OS error. Do not attempt to use `sudo` automatically — the user should either run with appropriate permissions or override `INSTALL_DIR` to a writable path.
82+
83+
## Verification
84+
85+
After installing, run `exasol-saas --version` to confirm the binary works. Print the output.
86+
87+
On success, print:
88+
```
89+
exasol-saas <version> installed to <install-dir>/exasol-saas
90+
```
91+
92+
## Error handling
93+
94+
- Use `set -euo pipefail`.
95+
- Use `curl -fsSL` for all downloads so HTTP errors cause immediate failure.
96+
- Clean up the temporary file on exit (success or failure) using a `trap`.
97+
98+
## Prerequisites
99+
100+
The script requires only `curl` and basic POSIX tools (`uname`, `mv`, `chmod`). Both are available by default on macOS and all major Linux distributions. No additional dependencies.
101+
102+
## Example output
103+
104+
```
105+
Detecting platform... darwin/arm64
106+
Resolving latest version... v0.1.0
107+
Downloading exasol-saas-darwin-arm64...
108+
Installing to /usr/local/bin/exasol-saas...
109+
exasol-saas v0.1.0 installed to /usr/local/bin/exasol-saas
110+
```

0 commit comments

Comments
 (0)