diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/install.sh | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..0bc8a8f --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,62 @@ +#!/bin/sh +# Build ai-memory from this checkout and put it on PATH, pinned. +# +# The reason this exists: `guix build -f guix.scm' prints a store path that +# changes with every rebuild, so scripts end up hard-coding one and keep running +# a binary that predates the source -- which is how a store was created with a +# schema too old for the code that later wrote to it. +# +# scripts/install.sh # build, GC-root it, link ~/.local/bin +# AI_MEMORY_ROOT=/opt/am scripts/install.sh +# scripts/install.sh --no-link # do not touch ~/.local/bin +# +# The GC root is what keeps a `guix gc' from taking the binary away; the link is +# what keeps people from having to remember a store hash. +set -eu + +ROOT=${AI_MEMORY_ROOT:-${XDG_STATE_HOME:-$HOME/.local/state}/ai-memory/root} +LINK=${AI_MEMORY_LINK:-${XDG_BIN_HOME:-$HOME/.local/bin}/ai-memory} +here=$(cd "$(dirname "$0")/.." && pwd) + +link=yes +for arg in "$@"; do + case $arg in + --no-link) link=no ;; + -h|--help) sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; + *) echo "install.sh: unknown argument $arg" >&2; exit 2 ;; + esac +done + +command -v guix >/dev/null 2>&1 || { + echo "install.sh: guix is not on PATH" >&2 + exit 1 +} + +mkdir -p "$(dirname "$ROOT")" +# Build from this checkout (guix.scm's source is a local-file, so the store path +# is a function of the tree) and root it in one step. +store=$(cd "$here" && guix build -f guix.scm --root="$ROOT") + +if [ ! -x "$ROOT/bin/ai-memory" ]; then + echo "install.sh: $ROOT/bin/ai-memory is missing after the build" >&2 + exit 1 +fi + +echo "ai-memory: $store" +echo "ai-memory: root $ROOT -> $(readlink -f "$ROOT")" + +if [ "$link" = yes ]; then + mkdir -p "$(dirname "$LINK")" + ln -sf "$ROOT/bin/ai-memory" "$LINK" + echo "ai-memory: $LINK -> $ROOT/bin/ai-memory" + case :$PATH: in + *:"$(dirname "$LINK")":*) ;; + *) echo "ai-memory: note: $(dirname "$LINK") is not on PATH" ;; + esac +fi + +"$ROOT/bin/ai-memory" --help >/dev/null 2>&1 || { + echo "install.sh: $ROOT/bin/ai-memory does not run" >&2 + exit 1 +} +echo "ai-memory: ok" |
