#!/usr/bin/env bash set -euo pipefail # ELPIS_PLATFORM overrides detection so the branch below can be exercised for a # platform other than the one running the script. It is not needed for a normal # install. platform=${ELPIS_PLATFORM:-"$(uname -s)-$(uname -m)"} case "$platform" in Linux-x86_64) asset=elpis-linux-x86_64 ;; Darwin-*) # Releases stopped carrying a macOS binary when that build left CI. Saying # so beats sending curl after an asset that will 404. printf 'Elpis does not publish a macOS binary yet; releases carry Linux x86_64 only.\n' >&2 printf 'Build from source with `cargo build --release -p codex-cli --bin codex`.\n' >&2 exit 1 ;; *) printf 'Elpis publishes a binary for Linux x86_64 only (detected %s).\n' \ "$platform" >&2 exit 1 ;; esac repository=${ELPIS_GITHUB_REPOSITORY:-MasihMoafi/Elpis} install_dir=${ELPIS_INSTALL_DIR:-"$HOME/.local/bin"} release_version=${ELPIS_RELEASE_VERSION:-v0.5.0} release_url="https://github.com/$repository/releases/download/$release_version" # macOS `mktemp` requires an explicit template, so do not shorten this to `mktemp -d`. temporary_dir=$(mktemp -d "${TMPDIR:-/tmp}/elpis-install.XXXXXX") trap 'rm -rf "$temporary_dir"' EXIT curl --fail --location --progress-bar \ "$release_url/$asset" --output "$temporary_dir/$asset" curl --fail --location --progress-bar \ "$release_url/$asset.sha256" --output "$temporary_dir/$asset.sha256" host=elpis-code-mode-host-linux-x86_64 curl --fail --location --progress-bar \ "$release_url/$host" --output "$temporary_dir/$host" curl --fail --location --progress-bar \ "$release_url/$host.sha256" --output "$temporary_dir/$host.sha256" if [ "$platform" = Linux-x86_64 ]; then resource=elpis-bwrap-linux-x86_64 curl --fail --location --progress-bar \ "$release_url/$resource" --output "$temporary_dir/$resource" curl --fail --location --progress-bar \ "$release_url/$resource.sha256" --output "$temporary_dir/$resource.sha256" fi ( cd "$temporary_dir" # macOS ships `shasum`, not GNU `sha256sum`; both read the same checksum format. if command -v sha256sum >/dev/null 2>&1; then sha256sum --check "$asset.sha256" sha256sum --check "$host.sha256" else shasum -a 256 --check "$asset.sha256" fi if [ "$platform" = Linux-x86_64 ]; then sha256sum --check "$resource.sha256" fi ) mkdir -p "$install_dir" if [ "$platform" = Linux-x86_64 ]; then mkdir -p "$install_dir/codex-resources" install -m 0755 "$temporary_dir/$resource" "$install_dir/codex-resources/.bwrap.installing" mv -f "$install_dir/codex-resources/.bwrap.installing" "$install_dir/codex-resources/bwrap" fi install -m 0755 "$temporary_dir/$host" "$install_dir/.codex-code-mode-host.installing" mv -f "$install_dir/.codex-code-mode-host.installing" "$install_dir/codex-code-mode-host" install -m 0755 "$temporary_dir/$asset" "$install_dir/.elpis.installing" mv -f "$install_dir/.elpis.installing" "$install_dir/elpis" printf 'Installed Elpis at %s\n' "$install_dir/elpis" if command -v rtk >/dev/null 2>&1; then printf 'RTK already installed at %s\n' "$(command -v rtk)" else printf 'RTK is optional; shell-output filtering stays off until it is installed.\n' fi