#!/usr/bin/env bash # zk-memory one-line installer (Linux/macOS, also Git Bash on Windows). # # wget -qO- https://zk-armor-opencode-memory.hf.space | bash # install only # wget -qO- https://zk-armor-opencode-memory.hf.space | bash -s -- # install + login + run # wget -qO- https://zk-armor-opencode-memory.hf.space | bash -s -- -- --version # # Rules: first arg not starting with '-' is the service secret (login once). # Remaining args are passed to `zkmemory` (default: full pull -> run -> push). # Use --no-run to stop after install/login. set -euo pipefail export ZK_MEMORY_URL="${ZK_MEMORY_URL:-https://zk-armor-opencode-memory.hf.space}" GIT_REPO="https://huggingface.co/spaces/zk-Armor/opencode-memory" SECRET=""; NO_RUN=0; PASS=() for a in "$@"; do case "$a" in --no-run) NO_RUN=1 ;; -*) PASS+=("$a") ;; *) if [ -z "$SECRET" ]; then SECRET="$a"; else PASS+=("$a"); fi ;; esac done have() { command -v "$1" >/dev/null 2>&1; } if ! have uv; then echo "[zk-memory] installing uv ..." if have curl; then curl -LsSf https://astral.sh/uv/install.sh | sh elif have wget; then wget -qO- https://astral.sh/uv/install.sh | sh else echo "ERR: need curl or wget to install uv" >&2; exit 1 fi export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH" fi have uv || { echo "ERR: uv not found after install; add ~/.local/bin to PATH and retry" >&2; exit 1; } if ! have git; then echo "[zk-memory] git missing (needed once to fetch the tool), trying system install ..." if have apk; then apk add --no-cache git || true elif have apt-get; then sudo apt-get update -qq && sudo apt-get install -y -qq git || true elif have pacman; then sudo pacman -Sy --noconfirm git || true elif have brew; then brew install git || true elif have dnf; then sudo dnf install -y git || true fi fi have git || { echo "ERR: install git first (https://git-scm.com/downloads) and re-run" >&2; exit 1; } echo "[zk-memory] installing zkmemory ..." # Prefer a working system python3 when present (uv managed interpreters can # live on broken/redirected paths); else let uv fetch its own. PY_ARGS="" for py in python3 python; do if have "$py" && "$py" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 9) else 1)' 2>/dev/null; then PY_ARGS="--python $(command -v "$py")" echo "[zk-memory] using system $($py --version 2>&1)" break fi done # shellcheck disable=SC2086 if ! uv tool install $PY_ARGS --from "git+${GIT_REPO}" zkmemory 2>/dev/null; then # shellcheck disable=SC2086 uv tool upgrade $PY_ARGS zkmemory 2>/dev/null || uv tool install --force $PY_ARGS --from "git+${GIT_REPO}" zkmemory fi export PATH="$HOME/.local/bin:$PATH" if [ -n "$SECRET" ]; then zkmemory login "$SECRET" fi if [ "$NO_RUN" -eq 1 ]; then echo "[zk-memory] installed. run: zkmemory" exit 0 fi exec zkmemory "${PASS[@]:-}"