#!/usr/bin/env bash # Copyright 2025 Octelium Labs, LLC. All rights reserved. MIT license. # # Usage: # curl -sSL https://... | bash # VERSION=v1.2.3 bash install.sh # install a specific version from GitHub # INSTALL_DIR=~/.local/bin bash install.sh # install the binaries into a custom directory # USE_SUDO=false bash install.sh # skip sudo # USE_PACKAGE_MANAGER=false bash install.sh # never use apt, dnf, yum, zypper or Homebrew # INSTALL_DESKTOP=true bash install.sh # install Octelium Desktop on Linux (true, false or auto) set -euo pipefail : "${USE_SUDO:="true"}" : "${DEBUG:="false"}" INSTALL_DIR_SET="${INSTALL_DIR:+true}" : "${INSTALL_DIR:="/usr/local/bin"}" : "${VERSION:=""}" : "${USE_PACKAGE_MANAGER:="auto"}" : "${INSTALL_DESKTOP:="auto"}" DOWNLOAD_REPO="https://github.com/octelium/octelium/releases" LATEST_RELEASE_URL="https://api.github.com/repos/octelium/octelium/releases/latest" GITHUB_API_VERSION="2026-03-10" PACKAGES_URL="https://packages.octelium.com" BINARIES=("octelium" "octeliumctl" "octops") DESKTOP_PACKAGE="octelium-desktop" BREW_FORMULA="octelium/tap/octelium" ECDSA_MIN_RPM_VERSION="4.19" HAS_CURL="$(type "curl" &>/dev/null && echo true || echo false)" HAS_WGET="$(type "wget" &>/dev/null && echo true || echo false)" HAS_TAR="$(type "tar" &>/dev/null && echo true || echo false)" HAS_SHA256SUM="$(type "sha256sum" &>/dev/null && echo true || echo false)" HAS_SHASUM="$(type "shasum" &>/dev/null && echo true || echo false)" PKG_MGR="" PKG_BIN_DIR="/usr/bin" REPO_FILE="" REPO_CREATED="false" METHOD="binary" TMP_ROOT="$(mktemp -d 2>/dev/null || mktemp -d -t 'octelium-install-XXXXXX')" cleanup() { [[ -d "${TMP_ROOT:-}" ]] && rm -rf "$TMP_ROOT" } trap cleanup EXIT INT TERM log() { echo "$*"; } warn() { echo " WARNING: $*" >&2; } die() { printf ' ERROR: %b\n' "$*" >&2; exit 1; } runAsRoot() { if [[ "$EUID" -ne 0 && "$USE_SUDO" == "true" ]]; then sudo "${@}" else "${@}" fi } initArch() { ARCH=$(uname -m) case "$ARCH" in armv5*) ARCH="armv5" ;; armv6*) ARCH="armv6" ;; armv7*) ARCH="arm" ;; aarch64|arm64) ARCH="arm64" ;; x86_64) ARCH="amd64" ;; x86|i686|i386) ARCH="386" ;; *) die "Unsupported architecture: $ARCH" ;; esac } initOS() { OS=$(uname | tr '[:upper:]' '[:lower:]') case "$OS" in mingw*) OS="windows" ;; esac } verifySupported() { case "$OS" in darwin|linux) ;; *) die "No prebuilt binary for ${OS}-${ARCH}. Build from source: https://github.com/octelium/octelium" ;; esac case "$ARCH" in amd64|arm64) ;; *) die "No prebuilt binary for ${OS}-${ARCH}. Build from source: https://github.com/octelium/octelium" ;; esac } installOnNixOS() { [[ "$OS" == "linux" && "$USE_PACKAGE_MANAGER" != "false" && -z "$VERSION" && -z "$INSTALL_DIR_SET" ]] || return 1 [[ -r /etc/os-release ]] || return 1 local ids ids=" $(. /etc/os-release && echo "${ID:-} ${ID_LIKE:-}") " [[ "$ids" == *" nixos "* ]] || return 1 type nix &>/dev/null || die "Nix is required on NixOS. See https://github.com/octelium/nix" log "Installing the Octelium CLIs to your Nix profile" nix --extra-experimental-features "nix-command flakes" profile install github:octelium/nix < /dev/null \ || die "Installation with Nix failed. See https://github.com/octelium/nix" if [[ "$INSTALL_DESKTOP" == "true" ]]; then warn "Octelium Desktop requires the NixOS module. Enable programs.octelium-desktop.enable as described at https://github.com/octelium/nix#nixos" fi log "Octelium has been successfully installed with Nix" log " Updates are managed by your Nix profile. See https://github.com/octelium/nix" log " Docs: https://octelium.com/docs" log " Repo: https://github.com/octelium/octelium" } installTool() { local tool="$1" local packages=("$tool") if [[ "$USE_PACKAGE_MANAGER" == "false" || -z "$PKG_MGR" || "$PKG_MGR" == "brew" ]] || ! hasRootAccess; then return 1 fi log "Installing $tool with $PKG_MGR" if [[ "$PKG_MGR" == "apt" ]]; then [[ "$tool" != "curl" ]] || packages+=("ca-certificates") runAsRoot apt-get update < /dev/null || return 1 fi installPackages "${packages[@]}" && type "$tool" &>/dev/null } ensureDownloader() { if [[ "$HAS_CURL" == "true" || "$HAS_WGET" == "true" ]]; then return 0 fi installTool curl || die "curl or wget is required." HAS_CURL="true" } download() { local url="$1" dest="$2" if [[ "$HAS_CURL" == "true" ]]; then curl -fsSL "$url" -o "$dest" else wget -qO "$dest" "$url" fi } initPackageManager() { if [[ "$OS" == "darwin" ]]; then if type brew &>/dev/null; then PKG_MGR="brew" PKG_BIN_DIR="$(brew --prefix)/bin" fi return 0 fi if [[ ! -r /etc/os-release ]]; then return 0 fi local ids ids=" $(. /etc/os-release && echo "${ID:-} ${ID_LIKE:-}") " case "$ids" in *" debian "*|*" ubuntu "*) if type apt-get &>/dev/null; then PKG_MGR="apt"; fi ;; *" fedora "*|*" rhel "*|*" centos "*|*" amzn "*) if type dnf &>/dev/null; then PKG_MGR="dnf" elif type yum &>/dev/null; then PKG_MGR="yum" fi ;; *" suse "*|*" opensuse "*|*" sles "*) if type zypper &>/dev/null; then PKG_MGR="zypper"; fi ;; esac } hasRootAccess() { [[ "$EUID" -eq 0 ]] || { [[ "$USE_SUDO" == "true" ]] && type sudo &>/dev/null; } } keyAlgorithm() { local bytes grep -v -e '^-----' -e '^=' -e ':' "$1" | tr -d ' \r\n' | base64 -d > "$TMP_ROOT/key.bin" 2>/dev/null || return 1 read -r -a bytes <<< "$(od -An -tu1 -N9 "$TMP_ROOT/key.bin")" case "${bytes[0]:-}" in 152) echo "${bytes[7]:-}" ;; 153) echo "${bytes[8]:-}" ;; esac } rpmSupportsRepositoryKey() { download "$PACKAGES_URL/keys/octelium.asc" "$TMP_ROOT/octelium.asc" || return 1 if [[ "$(keyAlgorithm "$TMP_ROOT/octelium.asc" || true)" != "19" ]]; then return 0 fi local version version="$(rpm --version 2>/dev/null || true)" version="${version##* }" [[ -n "$version" ]] || return 1 [[ "$(printf '%s\n' "$ECDSA_MIN_RPM_VERSION" "$version" | sort -V | head -n 1)" == "$ECDSA_MIN_RPM_VERSION" ]] } usePackageManager() { local reason="" if [[ "$USE_PACKAGE_MANAGER" == "false" ]]; then reason="USE_PACKAGE_MANAGER is false" elif [[ -n "$VERSION" ]]; then reason="VERSION is set" elif [[ -n "$INSTALL_DIR_SET" ]]; then reason="INSTALL_DIR is set" elif [[ -z "$PKG_MGR" ]]; then reason="no supported package manager was found" elif [[ "$PKG_MGR" == "brew" ]]; then [[ "$EUID" -ne 0 ]] || reason="Homebrew cannot run as root" elif ! hasRootAccess; then reason="root access is required" elif [[ "$PKG_MGR" != "apt" ]] && ! rpmSupportsRepositoryKey; then reason="the installed rpm cannot verify the repository signatures" fi if [[ -z "$reason" ]]; then return 0 fi if [[ "$USE_PACKAGE_MANAGER" == "true" ]]; then die "Cannot install with a package manager: $reason." fi log "Installing the binaries from GitHub since $reason." return 1 } setupRepository() { case "$PKG_MGR" in apt) REPO_FILE="/etc/apt/sources.list.d/octelium.sources" [[ -e "$REPO_FILE" ]] || REPO_CREATED="true" download "$PACKAGES_URL/keys/octelium.gpg" "$TMP_ROOT/octelium.gpg" || return 1 download "$PACKAGES_URL/deb/octelium.sources" "$TMP_ROOT/octelium.sources" || return 1 runAsRoot install -d -m 0755 /etc/apt/keyrings || return 1 runAsRoot install -m 0644 "$TMP_ROOT/octelium.gpg" /etc/apt/keyrings/octelium.gpg || return 1 runAsRoot install -m 0644 "$TMP_ROOT/octelium.sources" "$REPO_FILE" || return 1 runAsRoot apt-get update < /dev/null || warn "apt-get update reported errors." ;; dnf|yum) REPO_FILE="/etc/yum.repos.d/octelium.repo" [[ -e "$REPO_FILE" ]] || REPO_CREATED="true" download "$PACKAGES_URL/rpm/octelium.repo" "$TMP_ROOT/octelium.repo" || return 1 runAsRoot install -m 0644 "$TMP_ROOT/octelium.repo" "$REPO_FILE" || return 1 ;; zypper) if ! runAsRoot zypper --non-interactive repos octelium &>/dev/null < /dev/null; then REPO_CREATED="true" runAsRoot zypper --non-interactive addrepo "$PACKAGES_URL/rpm/octelium.repo" < /dev/null || return 1 fi runAsRoot zypper --non-interactive --gpg-auto-import-keys refresh octelium < /dev/null || return 1 ;; esac } removeRepository() { case "$PKG_MGR" in apt) runAsRoot rm -f "$REPO_FILE" /etc/apt/keyrings/octelium.gpg ;; dnf|yum) runAsRoot rm -f "$REPO_FILE" ;; zypper) runAsRoot zypper --non-interactive removerepo octelium < /dev/null ;; esac } installPackages() { case "$PKG_MGR" in apt) runAsRoot env DEBIAN_FRONTEND=noninteractive apt-get install -y "$@" < /dev/null ;; dnf|yum) runAsRoot "$PKG_MGR" install -y "$@" < /dev/null ;; zypper) runAsRoot zypper --non-interactive --gpg-auto-import-keys install "$@" < /dev/null ;; esac } ownedByPackage() { case "$PKG_MGR" in apt) dpkg -S "$1" &>/dev/null ;; *) rpm -qf "$1" &>/dev/null ;; esac } installWithPackageManager() { local cli if [[ "$PKG_MGR" == "brew" ]]; then log "Installing $BREW_FORMULA with Homebrew" removeBrewConflicts if brew install "$BREW_FORMULA" < /dev/null; then return 0 fi else log "Installing from $PACKAGES_URL with $PKG_MGR" if setupRepository && installPackages "${BINARIES[@]}"; then removeReplacedBinaries for cli in "${BINARIES[@]}"; do installCompletions "$cli" "$PKG_BIN_DIR/$cli" done return 0 fi if [[ "$REPO_CREATED" == "true" ]]; then removeRepository || true fi fi if [[ "$USE_PACKAGE_MANAGER" == "true" ]]; then die "Installation with $PKG_MGR failed." fi warn "Installation with $PKG_MGR failed, installing the binaries from GitHub instead." return 1 } removeFile() { if [[ -w "${1%/*}" ]]; then rm -f "$1" else runAsRoot rm -f "$1" fi } removeReplacedBinaries() { local bin path for bin in "${BINARIES[@]}"; do path="$INSTALL_DIR/$bin" if [[ -f "$path" && ! "$path" -ef "$PKG_BIN_DIR/$bin" ]] && ! ownedByPackage "$path"; then log "Removing $path, it is replaced by the $bin package" removeFile "$path" fi done } removeBrewConflicts() { local prefix bin path prefix="$(brew --prefix)" for bin in "${BINARIES[@]}"; do for path in "$INSTALL_DIR/$bin" "$prefix/bin/$bin" "$prefix/etc/bash_completion.d/$bin" \ "$prefix/share/zsh/site-functions/_$bin" "$prefix/share/fish/vendor_completions.d/$bin.fish"; do if [[ -f "$path" && ! -L "$path" ]]; then log "Removing $path, it is replaced by $BREW_FORMULA" removeFile "$path" fi done done } warnShadowedBinaries() { local bin path hash -r for bin in "${BINARIES[@]}"; do path="$(command -v "$bin" || true)" if [[ -n "$path" && ! "$path" -ef "$PKG_BIN_DIR/$bin" ]]; then warn "$path takes precedence over $PKG_BIN_DIR/$bin in your PATH." fi done } isContainer() { if [[ -f /.dockerenv || -f /run/.containerenv || -n "${container:-}" ]]; then return 0 fi if type systemd-detect-virt &>/dev/null && systemd-detect-virt --container --quiet; then return 0 fi grep -qaE 'docker|kubepods|containerd|lxc' /proc/1/cgroup 2>/dev/null } hasGraphicalSession() { if [[ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}${XDG_CURRENT_DESKTOP:-}" ]]; then return 0 fi type systemctl &>/dev/null && systemctl is-active --quiet display-manager.service 2>/dev/null } wantDesktop() { case "$INSTALL_DESKTOP" in true) return 0 ;; false) return 1 ;; esac [[ -z "${CI:-}" ]] || return 1 [[ -d /run/systemd/system ]] || return 1 ! isContainer || return 1 ! grep -qiE 'microsoft|wsl' /proc/sys/kernel/osrelease 2>/dev/null || return 1 hasGraphicalSession } resolveTag() { if [[ -n "$VERSION" ]]; then TAG="$VERSION" log "Using requested version: $TAG" else TAG="$(fetchLatestTag || true)" [[ -n "$TAG" ]] || die "Failed to fetch the latest release tag." fi [[ "$TAG" == v* ]] || die "Invalid release tag '$TAG': expected a tag beginning with 'v'." DOWNLOAD_URL_PREFIX="$DOWNLOAD_REPO/download/$TAG" } fetchLatestTag() { local response if [[ "$HAS_CURL" == "true" ]]; then response="$( curl -fsSL \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: $GITHUB_API_VERSION" \ "$LATEST_RELEASE_URL" )" || return 1 else response="$( wget -qO- \ --header="Accept: application/vnd.github+json" \ --header="X-GitHub-Api-Version: $GITHUB_API_VERSION" \ "$LATEST_RELEASE_URL" )" || return 1 fi printf '%s\n' "$response" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1 } verifyChecksum() { local filename="$1" local file="$TMP_ROOT/$filename" local checksums_file="$TMP_ROOT/SHA256SUMS" if [[ ! -f "$checksums_file" ]]; then local checksums_url="$DOWNLOAD_URL_PREFIX/SHA256SUMS" if ! download "$checksums_url" "$checksums_file"; then warn "Could not download checksums file — skipping verification for $filename." return 0 fi fi local expected="" read -r expected _ <<< "$(grep -E "(^|[[:space:]])${filename}($|[[:space:]])" "$checksums_file" || true)" if [[ -z "$expected" ]]; then warn "No checksum entry found for $filename — skipping verification." return 0 fi local actual if [[ "$HAS_SHA256SUM" == "true" ]]; then read -r actual _ <<< "$(sha256sum "$file")" elif [[ "$HAS_SHASUM" == "true" ]]; then read -r actual _ <<< "$(shasum -a 256 "$file")" else warn "No checksum tool available — skipping verification for $filename." return 0 fi if [[ "$actual" != "$expected" ]]; then die "Checksum mismatch for $filename!\n expected: $expected\n got: $actual" fi } downloadAndInstall() { local bin_name="$1" local filename="${bin_name}-${OS}-${ARCH}.tar.gz" local file_url="$DOWNLOAD_URL_PREFIX/$filename" local file="$TMP_ROOT/$filename" log "Downloading $file_url" if ! download "$file_url" "$file"; then die "Failed to download $file_url" fi [[ -s "$file" ]] || die "Downloaded file is empty: $file" verifyChecksum "$filename" tar xf "$file" -C "$TMP_ROOT" --no-same-owner [[ -f "$TMP_ROOT/$bin_name" ]] || die "Binary '$bin_name' not found in archive." runAsRoot cp "$TMP_ROOT/$bin_name" "$INSTALL_DIR/$bin_name" runAsRoot chmod +x "$INSTALL_DIR/$bin_name" } installBinaries() { [[ "$HAS_TAR" == "true" ]] || installTool tar \ || die "tar is required to extract the binaries." [[ "$HAS_SHA256SUM" == "true" || "$HAS_SHASUM" == "true" ]] \ || warn "sha256sum / shasum not found — skipping checksum verification." resolveTag if [[ ! -d "$INSTALL_DIR" ]]; then runAsRoot mkdir -p "$INSTALL_DIR" fi for cli in "${BINARIES[@]}"; do downloadAndInstall "$cli" installCompletions "$cli" "$INSTALL_DIR/$cli" done } installCompletions() { local bin="$1" local bin_path="$2" if ! "$bin_path" --help &>/dev/null; then warn " Binary failed to execute — skipping completions for $bin." return 0 fi if type "bash" &>/dev/null; then local bash_comp_dir="" if [[ "$OS" == "darwin" ]] && type "brew" &>/dev/null; then bash_comp_dir="$(brew --prefix)/etc/bash_completion.d" elif [[ "$OS" == "linux" ]]; then bash_comp_dir="/usr/share/bash-completion/completions" fi if [[ -n "$bash_comp_dir" && -d "$bash_comp_dir" ]]; then "$bin_path" completion bash > "$TMP_ROOT/${bin}.bash" runAsRoot cp "$TMP_ROOT/${bin}.bash" "$bash_comp_dir/$bin" fi fi if type "zsh" &>/dev/null; then local zsh_comp_dir="/usr/local/share/zsh/site-functions" if [[ "$OS" == "darwin" ]] && type "brew" &>/dev/null; then zsh_comp_dir="$(brew --prefix)/share/zsh/site-functions" fi if [[ -d "$zsh_comp_dir" ]]; then "$bin_path" completion zsh > "$TMP_ROOT/_${bin}" runAsRoot cp "$TMP_ROOT/_${bin}" "$zsh_comp_dir/_$bin" fi fi if type "fish" &>/dev/null; then local fish_comp_dir="/usr/share/fish/vendor_completions.d" if [[ "$OS" == "darwin" ]] && type "brew" &>/dev/null; then fish_comp_dir="$(brew --prefix)/share/fish/vendor_completions.d" fi if [[ -d "$fish_comp_dir" ]]; then "$bin_path" completion fish > "$TMP_ROOT/${bin}.fish" runAsRoot cp "$TMP_ROOT/${bin}.fish" "$fish_comp_dir/${bin}.fish" fi fi } installDesktop() { if [[ "$OS" != "linux" ]]; then if [[ "$INSTALL_DESKTOP" == "true" ]]; then warn "Octelium Desktop is currently only available for Linux." fi return 0 fi if [[ "$METHOD" != "package" ]]; then if [[ "$INSTALL_DESKTOP" == "true" ]]; then warn "Octelium Desktop can only be installed with a supported package manager." fi return 0 fi if ! wantDesktop; then return 0 fi log "Installing Octelium Desktop" if installPackages "$DESKTOP_PACKAGE"; then DESKTOP_INSTALLED="true" else warn "Octelium Desktop could not be installed. The command-line tools are installed." fi } upgradeCommand() { case "$PKG_MGR" in apt) echo "sudo apt-get update && sudo apt-get upgrade" ;; dnf|yum) echo "sudo $PKG_MGR upgrade" ;; zypper) echo "sudo zypper update" ;; brew) echo "brew upgrade octelium" ;; esac } [[ "$DEBUG" == "true" ]] && set -x DESKTOP_INSTALLED="false" initArch initOS verifySupported if installOnNixOS; then exit 0 fi initPackageManager ensureDownloader if usePackageManager && installWithPackageManager; then METHOD="package" warnShadowedBinaries else installBinaries fi installDesktop echo "" if [[ "$METHOD" == "package" && "$PKG_MGR" == "brew" ]]; then log "Octelium has been successfully installed with Homebrew" log " Updates are installed by Homebrew: $(upgradeCommand)" elif [[ "$METHOD" == "package" ]]; then log "Octelium has been successfully installed from $PACKAGES_URL" if [[ "$DESKTOP_INSTALLED" == "true" ]]; then log " Octelium Desktop has been installed too" fi log " Updates are installed by your package manager: $(upgradeCommand)" else log "Octelium binaries have been successfully installed" fi log " Docs: https://octelium.com/docs" log " Repo: https://github.com/octelium/octelium"