Files
archie/scripts/archie-update-install
T
sam eaa436b09b docs+scripts: add archie-update-check, document missing config sections
The check-side of the reference update adapter never existed:
scripts/ had archie-update-install and archie-update-watchdog but no
archie-update-check, so any deployment that configured
chat.telegram.update_check_command pointing at the documented
"/usr/local/bin/archie-update-check" path had nothing there to run --
/update would report "not configured" regardless of what was actually
set. Add it: read-only, reports the daemon/agent components via git
describe against the local checkout and origin/main (no fetch-and-pull
the way install does), using the same "daemon"/"agent" component IDs
archie-update-watchdog's report and releaseupdate.ComponentDaemon/
ComponentAgent already use, so Service.Enrich and Report.Verify (this
session's earlier work) recognise it automatically.

Also fix archie-update-install's archie-agent build: it stamped
archied's ldflags but built archie-agent with none at all, so even a
native (non-container) archie-agent install reported an unstamped
"dev" build with installtype.Unknown.

config.example.toml gained every section that existed in the Go schema
but wasn't documented anywhere, not even commented: skills_dir,
plugin_dir, [chat.email], [chat].webhook_addr, [log], [memory] (noted
as currently unwired -- RegisterExternal is declared but never called
from cmd/archied, so the section has no effect yet), [[identities]]
(pointer to docs/architecture/identity.md rather than duplicating it),
and [[repos]].max_retries. tools.tool_policy.parallel_execution was
deliberately left undocumented: it's declared on ToolPolicy but never
read anywhere, genuinely dead rather than just underdocumented.
2026-08-24 00:32:37 +10:00

91 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# archie-update-install -- update installation adapter for archied's /update.
#
# archied runs this via CommandInstaller after the operator approves, and
# streams stdout to the chat live as each line is printed. The final line is
# a single "ARCHIE_UPDATE_RESULT {json}" the Go side parses to report which
# components changed; every other line is shown as plain progress text. It
# is exec'd directly, without a shell.
#
# This script only covers the synchronous phase: fetch, build, install,
# rebuild the agent image. Nothing here restarts archied directly -- that is
# handed off to archie-update-watchdog, launched detached via systemd-run so
# restarting archied.service doesn't kill this process before it can report
# a clean exit. The watchdog is also the only place a crash-loop on the new
# binary gets detected and rolled back, since by definition no Go code can
# be running to do that itself.
set -euo pipefail
# json_escape minimally escapes a string for embedding in a JSON document
# built by shell interpolation: backslashes first (so the quote-escaping
# backslash it inserts next isn't itself re-escaped), then double quotes.
json_escape() {
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
}
REPO="${ARCHIE_REPO_DIR:-$HOME/projects/archie-core}"
BIN_DIR="${ARCHIE_BIN_DIR:-$HOME/.local/bin}"
export PATH="/usr/local/go/bin:$PATH"
cd "$REPO"
PREV_GW="$(git describe --tags --match 'archied/v*' 2>/dev/null | sed 's|^archied/v||' || echo unknown)"
PREV_RT="$(git describe --tags --match 'archie/v*' 2>/dev/null | sed 's|^archie/v||' || echo unknown)"
echo "==> fetching"
git pull --ff-only
# Refresh the installed adapters from the checkout just fetched. The running
# shell continues with the old script, but the next /update uses the current
# implementation even when this invocation was started by an older install.
install -m755 "$REPO/scripts/archie-update-install" "$BIN_DIR/archie-update-install"
install -m755 "$REPO/scripts/archie-update-watchdog" "$BIN_DIR/archie-update-watchdog"
GW="$(git describe --tags --match 'archied/v*' | sed 's|^archied/v||')"
RT="$(git describe --tags --match 'archie/v*' | sed 's|^archie/v||')"
echo "==> building archied $GW / archie-agent $RT"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
go build -ldflags "-X main.gatewayVersion=$GW -X main.runtimeVersion=$RT -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary" \
-o "$tmp/archied" ./cmd/archied
go build -ldflags "-X github.com/samcharles93/archie-core/internal/app/agentworker.version=$RT -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary" \
-o "$tmp/archie-agent" ./cmd/archie-agent
echo "==> backing up current binaries"
[ -f "$BIN_DIR/archied" ] && cp -f "$BIN_DIR/archied" "$BIN_DIR/archied.prev"
[ -f "$BIN_DIR/archie-agent" ] && cp -f "$BIN_DIR/archie-agent" "$BIN_DIR/archie-agent.prev"
echo "==> installing"
install -m755 "$tmp/archied" "$BIN_DIR/archied"
install -m755 "$tmp/archie-agent" "$BIN_DIR/archie-agent"
echo "==> rebuilding agent image"
docker compose build agent
echo "==> handing off to the update watchdog for restart and health verification"
systemd-run --user --unit=archied-update-restart --collect --quiet \
--setenv=ARCHIE_BIN_DIR="$BIN_DIR" \
--setenv=ARCHIE_HEALTH_URL="${ARCHIE_HEALTH_URL:-http://127.0.0.1:8420}" \
--setenv=ARCHIE_UPDATE_REPORT_PATH="${ARCHIE_UPDATE_REPORT_PATH:-}" \
--setenv=ARCHIE_UPDATE_CHANNEL="${ARCHIE_UPDATE_CHANNEL:-}" \
--setenv=ARCHIE_UPDATE_CHAT_ID="${ARCHIE_UPDATE_CHAT_ID:-0}" \
--setenv=ARCHIE_UPDATE_THREAD_ID="${ARCHIE_UPDATE_THREAD_ID:-0}" \
--setenv=ARCHIE_UPDATE_PREVIOUS_GATEWAY="$PREV_GW" \
--setenv=ARCHIE_UPDATE_PREVIOUS_RUNTIME="$PREV_RT" \
--setenv=ARCHIE_UPDATE_INSTALLED_GATEWAY="$GW" \
--setenv=ARCHIE_UPDATE_INSTALLED_RUNTIME="$RT" \
"$REPO/scripts/archie-update-watchdog"
daemon_status="updated"
[ "$PREV_GW" = "$GW" ] && daemon_status="unchanged"
agent_status="updated"
[ "$PREV_RT" = "$RT" ] && agent_status="unchanged"
esc_prev_gw="$(json_escape "$PREV_GW")"
esc_prev_rt="$(json_escape "$PREV_RT")"
esc_gw="$(json_escape "$GW")"
esc_rt="$(json_escape "$RT")"
echo "ARCHIE_UPDATE_RESULT {\"previous\":{\"daemon\":\"$esc_prev_gw\",\"agent\":\"$esc_prev_rt\"},\"installed\":{\"daemon\":\"$esc_gw\",\"agent\":\"$esc_rt\"},\"components\":[{\"id\":\"daemon\",\"label\":\"daemon\",\"status\":\"$daemon_status\"},{\"id\":\"agent\",\"label\":\"agent\",\"status\":\"$agent_status\"}],\"restart_requested\":true}"