#!/usr/bin/env bash set -euo pipefail # Lermy CLI installer and updater (macOS & Linux) # Usage: curl -fsSL https://lermy.com/install.sh | bash # # Checks your installed `lermy` version and updates only when a newer release # is available (set LERMY_FORCE_INSTALL=1 to reinstall unconditionally). # Also checks a local Lermy project SKILL.md (via LERMY_SKILL_PATH or # ./SKILL.md / ./.claude/skills/lermy-evidence/SKILL.md) and updates it when # a newer skill version is available on your Lermy server. VERSION="${LERMY_CLI_VERSION:-latest}" INSTALL_DIR="${LERMY_INSTALL_DIR:-$HOME/.local/bin}" FORCE_INSTALL="${LERMY_FORCE_INSTALL:-0}" SKILL_PATH="${LERMY_SKILL_PATH:-}" detect_target() { local os arch os="$(uname -s)" arch="$(uname -m)" case "$os" in Darwin) os_part="apple-darwin" ;; Linux) os_part="unknown-linux-gnu" ;; MINGW*|MSYS*|CYGWIN*) echo "Windows detected. Run the PowerShell installer instead:" >&2 echo " irm https://lermy.com/install.ps1 | iex" >&2 exit 1 ;; *) echo "Error: unsupported operating system '$os'. Supported: macOS (Darwin), Linux, and Windows (via install.ps1)." >&2 exit 1 ;; esac case "$arch" in arm64|aarch64) arch_part="aarch64" ;; x86_64|amd64) arch_part="x86_64" ;; *) echo "Error: unsupported CPU architecture '$arch'. Supported: arm64/aarch64 and x86_64/amd64." >&2 exit 1 ;; esac printf '%s-%s' "$arch_part" "$os_part" } resolve_base_url() { if [[ -n "${LERMY_INSTALL_BASE_URL:-}" ]]; then printf '%s' "${LERMY_INSTALL_BASE_URL%/}" return fi if [[ "$VERSION" == "latest" ]]; then printf '%s' "https://lermy.com/downloads/cli/latest" else local tag="$VERSION" if [[ "$tag" != cli-v* ]]; then tag="cli-v${tag#v}" fi printf 'https://lermy.com/downloads/cli/%s' "$tag" fi } sha256_file() { local file="$1" if command -v sha256sum >/dev/null 2>&1; then sha256sum "$file" | awk '{print $1}' elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$file" | awk '{print $1}' else echo "Error: neither sha256sum nor shasum is installed; cannot verify checksum." >&2 exit 1 fi } installed_version() { local bin="$1" if [[ -x "$bin" ]]; then "$bin" --version 2>/dev/null | awk '{print $2}' | tr -d '\r' || true fi } fetch_target_version() { local base_url="$1" if [[ "$VERSION" != "latest" ]]; then printf '%s' "${VERSION#cli-v}" | sed 's/^v//' return fi curl -fsSL "${base_url}/VERSION" 2>/dev/null | head -n 1 | tr -d '[:space:]' | sed 's/^v//' || true } check_and_update_skill() { local bin="$1" local -a candidates=() if [[ -n "$SKILL_PATH" ]]; then candidates+=("$SKILL_PATH") else for path in \ "./.claude/skills/lermy-evidence/SKILL.md" \ "./.codex/skills/lermy-evidence/SKILL.md" \ "./.agents/skills/lermy-evidence/SKILL.md" \ "./SKILL.md"; do if [[ -f "$path" ]] && grep -q '^name:[[:space:]]*lermy-evidence' "$path" 2>/dev/null; then candidates+=("$path") fi done fi if [[ ${#candidates[@]} -eq 0 ]]; then return 0 fi local candidate for candidate in "${candidates[@]}"; do if [[ ! -f "$candidate" ]]; then continue fi if ! grep -q '^name:[[:space:]]*lermy-evidence' "$candidate" 2>/dev/null; then continue fi local check_output="" if check_output="$("$bin" skill check "$candidate" 2>&1)"; then echo "$check_output" continue fi # Skill is outdated or check could not reach server. if printf '%s' "$check_output" | grep -qi 'outdated'; then echo "$check_output" local update_output="" if update_output="$("$bin" skill update "$candidate" 2>&1)"; then echo "$update_output" else echo "Could not auto-update skill at ${candidate} (${update_output})." echo "Sign in with 'lermy login' and run: lermy skill update --all" fi fi done } if ! command -v curl >/dev/null 2>&1; then echo "Error: curl is required to install lermy." >&2 exit 1 fi if ! command -v tar >/dev/null 2>&1; then echo "Error: tar is required to extract the lermy release archive." >&2 exit 1 fi TARGET="$(detect_target)" BASE_URL="$(resolve_base_url)" ARCHIVE="lermy-${TARGET}.tar.gz" BIN_DEST="${INSTALL_DIR}/lermy" CURRENT_VERSION="$(installed_version "$BIN_DEST")" TARGET_VERSION="$(fetch_target_version "$BASE_URL")" NEED_INSTALL=1 if [[ "$FORCE_INSTALL" != "1" && -n "$CURRENT_VERSION" && -n "$TARGET_VERSION" && "$CURRENT_VERSION" == "$TARGET_VERSION" ]]; then echo "lermy ${CURRENT_VERSION} is already up to date (${BIN_DEST})." NEED_INSTALL=0 fi if [[ "$NEED_INSTALL" == "1" ]]; then if [[ -n "$CURRENT_VERSION" && -n "$TARGET_VERSION" ]]; then echo "Updating lermy from ${CURRENT_VERSION} to ${TARGET_VERSION}..." else echo "Downloading ${ARCHIVE} from ${BASE_URL}..." fi TMP_DIR="$(mktemp -d)" trap 'rm -rf "$TMP_DIR"' EXIT curl -fsSL "${BASE_URL}/${ARCHIVE}" -o "${TMP_DIR}/${ARCHIVE}" curl -fsSL "${BASE_URL}/SHA256SUMS" -o "${TMP_DIR}/SHA256SUMS" EXPECTED_SHA="$(awk -v file="$ARCHIVE" ' { name = $2 sub(/^\*/, "", name) sub(/^\.\//, "", name) if (name == file) { print tolower($1) found = 1 exit } } END { if (!found) exit 1 } ' "${TMP_DIR}/SHA256SUMS" 2>/dev/null || true)" if [[ -z "$EXPECTED_SHA" ]]; then echo "Error: checksum entry for ${ARCHIVE} not found in SHA256SUMS." >&2 exit 1 fi ACTUAL_SHA="$(sha256_file "${TMP_DIR}/${ARCHIVE}" | tr '[:upper:]' '[:lower:]')" if [[ "$ACTUAL_SHA" != "$EXPECTED_SHA" ]]; then echo "Error: SHA-256 verification failed for ${ARCHIVE}." >&2 echo " expected: ${EXPECTED_SHA}" >&2 echo " actual: ${ACTUAL_SHA}" >&2 exit 1 fi echo "Verified SHA-256 checksum." tar -xzf "${TMP_DIR}/${ARCHIVE}" -C "$TMP_DIR" if [[ ! -f "${TMP_DIR}/lermy" ]]; then echo "Error: archive ${ARCHIVE} did not contain expected 'lermy' binary." >&2 exit 1 fi mkdir -p "$INSTALL_DIR" TMP_BIN="${INSTALL_DIR}/.lermy.tmp.$$" cp "${TMP_DIR}/lermy" "$TMP_BIN" chmod 0755 "$TMP_BIN" mv -f "$TMP_BIN" "$BIN_DEST" echo "Installed lermy to ${BIN_DEST}" fi case ":${PATH}:" in *":${INSTALL_DIR}:"*) ;; *) echo "" echo "Add ${INSTALL_DIR} to your PATH to run 'lermy' directly:" echo " export PATH=\"${INSTALL_DIR}:\$PATH\"" ;; esac "$BIN_DEST" --version check_and_update_skill "$BIN_DEST" if [[ -n "${LERMY_HANDOFF:-}" ]]; then echo "" if [[ -n "${LERMY_URL:-}" ]]; then "$BIN_DEST" --url "$LERMY_URL" handoff else "$BIN_DEST" handoff fi exit $? fi echo "" echo "Next steps: run 'lermy doctor' to check your environment, or 'lermy login' to sign in."