clawdie-iso/scripts/stage-clawdie-iso.sh
Sam & Claude cf1c58a95c feat: stage the simplified clawdie agent into the ISO (Sam & Claude)
Adds an opt-in FEATURE_CLAWDIE lane that stages the new one-binary clawdie
agent (glasspane + herdr + DeepSeek/Telegram) from the shared ../colibri
checkout, alongside the existing Colibri daemon staging.

- build.cfg: FEATURE_CLAWDIE (default NO), CLAWDIE_ARTIFACT_DIR, CLAWDIE_ENABLE,
  plus build-flag credential notes.
- scripts/stage-clawdie-iso.sh: install clawdie binary + rc.d + rc.conf sample
  + optional clawdie.env override template.
- build.sh: resolve_clawdie_paths, preflight_clawdie_artifacts,
  install_clawdie_service (creates clawdie user/group, enables rc.d like
  Clawdie-AI), status line, and call-site wiring. Gated; default build unchanged.
- iso-build skill: clawdie preflight section + a "carry the XFCE operator-USB
  fixes" reminder for the next build (SDDM-over-LightDM, clawdie-live-gpu KMS,
  hardened USB power policy).

sh -n clean on build.sh and stage-clawdie-iso.sh; markdown gate clean on
touched files.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 09:10:49 +02:00

107 lines
3.5 KiB
Bash
Executable file

#!/bin/sh
# Stage the prebuilt `clawdie` FreeBSD binary + rc.d service into an image root.
#
# `clawdie` is the simplified, operator-friendly Colibri agent: one small binary
# (glasspane + herdr + DeepSeek/Telegram). This script does NOT build it — build
# or provide the artifact first, optionally with baked credentials:
#
# (cd ../colibri && CLAWDIE_TG_TOKEN=... CLAWDIE_DEEPSEEK_KEY=... \
# cargo build --release -p clawdie)
#
# Usage:
# COLIBRI_REPO=../colibri scripts/stage-clawdie-iso.sh /path/to/image-root
# CLAWDIE_ARTIFACT_DIR=/path/to/release scripts/stage-clawdie-iso.sh /path/to/image-root
set -eu
if [ "${1:-}" = "" ]; then
echo "usage: $0 DESTDIR" >&2
exit 64
fi
DESTDIR=$1
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
REPO_ROOT=$(CDPATH= cd -- "${SCRIPT_DIR}/.." && pwd)
COLIBRI_REPO=${COLIBRI_REPO:-"${REPO_ROOT}/../colibri"}
CLAWDIE_ARTIFACT_DIR=${CLAWDIE_ARTIFACT_DIR:-"${COLIBRI_REPO}/target/release"}
CLAWDIE_STAGE_ENABLE=${CLAWDIE_STAGE_ENABLE:-YES}
BIN_DIR="${DESTDIR}/usr/local/bin"
RC_DIR="${DESTDIR}/usr/local/etc/rc.d"
ETC_DIR="${DESTDIR}/usr/local/etc/clawdie"
DB_DIR="${DESTDIR}/var/db/clawdie"
RUN_DIR="${DESTDIR}/var/run/clawdie"
LOG_DIR="${DESTDIR}/var/log/clawdie"
RC_SOURCE="${COLIBRI_REPO}/packaging/freebsd/clawdie.in"
require_file() {
if [ ! -f "$1" ]; then
echo "missing required clawdie artifact: $1" >&2
exit 66
fi
}
require_exec() {
if [ ! -x "$1" ]; then
echo "missing executable clawdie artifact: $1" >&2
echo "hint: (cd ${COLIBRI_REPO} && cargo build --release -p clawdie)" >&2
exit 66
fi
}
require_file "${RC_SOURCE}"
require_exec "${CLAWDIE_ARTIFACT_DIR}/clawdie"
mkdir -p "${BIN_DIR}" "${RC_DIR}" "${ETC_DIR}" "${DB_DIR}" "${RUN_DIR}" "${LOG_DIR}"
install -m 0555 "${CLAWDIE_ARTIFACT_DIR}/clawdie" "${BIN_DIR}/clawdie"
install -m 0555 "${RC_SOURCE}" "${RC_DIR}/clawdie"
cat > "${ETC_DIR}/rc.conf.sample" <<EOF
# Clawdie agent service defaults for the Clawdie ISO.
# Merge into /etc/rc.conf or /etc/rc.conf.d/clawdie.
clawdie_enable="${CLAWDIE_STAGE_ENABLE}"
clawdie_user="clawdie"
clawdie_group="clawdie"
clawdie_data_dir="/var/db/clawdie"
clawdie_run_dir="/var/run/clawdie"
clawdie_socket="/var/run/clawdie/clawdie.sock"
clawdie_logfile="/var/log/clawdie/clawdie.log"
clawdie_host="\$(hostname)"
clawdie_env_file="/usr/local/etc/clawdie/clawdie.env"
EOF
# Per-host credential override template (binary keeps its baked build-flag
# defaults; this file is optional and only read if present + readable).
if [ ! -f "${ETC_DIR}/clawdie.env" ]; then
cat > "${ETC_DIR}/clawdie.env.sample" <<'EOF'
# Optional per-host credential overrides for clawdie.
# Copy to clawdie.env (chmod 0600) to override the baked build-flag values.
# CLAWDIE_TG_TOKEN=123456:telegram-bot-token
# CLAWDIE_DEEPSEEK_KEY=sk-deepseek-key
EOF
fi
cat > "${ETC_DIR}/README.iso" <<'EOF'
Clawdie agent ISO staging notes
===============================
The ISO build creates the clawdie user/group and enables the rc.d service
according to build.cfg. Out of the box clawdie offers exactly: a Telegram bot
and a DeepSeek lane — both normally baked at build time. Runtime validation:
service clawdie start
service clawdie status
sockstat | grep clawdie # Herdr socket bound
service clawdie stop
Lifted on purpose: cost modes, quotas, multi-provider fallback, per-user limits.
EOF
chmod 0750 "${DB_DIR}" "${RUN_DIR}" "${LOG_DIR}"
cat <<EOF
Staged clawdie into ${DESTDIR}
artifact : ${CLAWDIE_ARTIFACT_DIR}/clawdie
rc.d : ${RC_SOURCE}
enable : ${CLAWDIE_STAGE_ENABLE}
EOF