Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/cube-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ on:
branches: [master]
paths:
- 'rust/cube-cli/**'
- 'install-cli.sh'
- 'install-cli.ps1'
- '.github/workflows/cube-cli.yml'
pull_request:
paths:
- 'rust/cube-cli/**'
- 'install-cli.sh'
- 'install-cli.ps1'
- '.github/workflows/cube-cli.yml'

concurrency:
Expand Down
44 changes: 44 additions & 0 deletions install-cli.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Cube CLI installer for Windows (x86_64).
#
# irm https://raw.githubusercontent.com/cube-js/cube/master/install-cli.ps1 | iex
#
# Environment overrides:
# CUBE_INSTALL_DIR install directory (default: %LOCALAPPDATA%\cube\bin)
# CUBE_VERSION release tag to install, e.g. v1.7.5 (default: latest)
$ErrorActionPreference = "Stop"

$Repo = "cube-js/cube"
$Target = "x86_64-pc-windows-msvc"

$Version = if ($env:CUBE_VERSION) { $env:CUBE_VERSION } else { "latest" }
$Url = if ($Version -eq "latest") {
"https://github.com/$Repo/releases/latest/download/cube-$Target.tar.gz"
} else {
"https://github.com/$Repo/releases/download/$Version/cube-$Target.tar.gz"
}

$Dir = if ($env:CUBE_INSTALL_DIR) { $env:CUBE_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "cube\bin" }
New-Item -ItemType Directory -Force -Path $Dir | Out-Null

$Tmp = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Force -Path $Tmp | Out-Null
try {
Write-Host "Downloading cube ($Target) from $Url…"
$Archive = Join-Path $Tmp "cube.tar.gz"
Invoke-WebRequest -Uri $Url -OutFile $Archive -UseBasicParsing

# tar ships with Windows 10 1803+.
tar -xzf $Archive -C $Tmp
Copy-Item -Force (Join-Path $Tmp "cube.exe") (Join-Path $Dir "cube.exe")

$Exe = Join-Path $Dir "cube.exe"
Write-Host "Installed $(& $Exe --version) to $Exe"

$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (($UserPath -split ";") -notcontains $Dir) {
[Environment]::SetEnvironmentVariable("Path", "$Dir;$UserPath", "User")
Write-Host "Added $Dir to your user PATH (restart your terminal to pick it up)."
}
} finally {
Remove-Item -Recurse -Force $Tmp -ErrorAction SilentlyContinue
}
73 changes: 73 additions & 0 deletions install-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh
# Cube CLI installer for Linux and macOS.
#
# curl -fsSL https://raw.githubusercontent.com/cube-js/cube/master/install-cli.sh | sh
#
# Environment overrides:
# CUBE_INSTALL_DIR install directory (default: /usr/local/bin if
# writable, else ~/.local/bin)
# CUBE_VERSION release tag to install, e.g. v1.7.5 (default: latest)
set -eu

REPO="cube-js/cube"

main() {
os=$(uname -s)
arch=$(uname -m)
case "$os" in
Linux) os_part="unknown-linux-musl" ;;
Darwin) os_part="apple-darwin" ;;
*) err "unsupported OS: $os (use install.ps1 on Windows)" ;;
esac
case "$arch" in
x86_64|amd64) arch_part="x86_64" ;;
arm64|aarch64) arch_part="aarch64" ;;
*) err "unsupported architecture: $arch" ;;
esac
target="${arch_part}-${os_part}"

if [ "${CUBE_VERSION:-latest}" = "latest" ]; then
url="https://github.com/${REPO}/releases/latest/download/cube-${target}.tar.gz"
else
url="https://github.com/${REPO}/releases/download/${CUBE_VERSION}/cube-${target}.tar.gz"
fi

dir="${CUBE_INSTALL_DIR:-}"
if [ -z "$dir" ]; then
if [ -w /usr/local/bin ]; then
dir=/usr/local/bin
else
dir="$HOME/.local/bin"
fi
fi
mkdir -p "$dir"

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

echo "Downloading cube (${target}) from ${url}…"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$tmp/cube.tar.gz"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$tmp/cube.tar.gz" "$url"
else
err "neither curl nor wget is available"
fi

tar -xzf "$tmp/cube.tar.gz" -C "$tmp"
install -m 755 "$tmp/cube" "$dir/cube"

echo "Installed $("$dir/cube" --version) to $dir/cube"
case ":$PATH:" in
*":$dir:"*) ;;
*) echo "NOTE: $dir is not on your PATH — add it, e.g.:"
echo " export PATH=\"$dir:\$PATH\"" ;;
esac
}

err() {
echo "error: $1" >&2
exit 1
}

main "$@"
Loading
Loading