feat(iso): Phase 1a — machine identity + local LLM probes #150
2 changed files with 71 additions and 1 deletions
|
|
@ -75,13 +75,22 @@ _rootpw_apply() {
|
|||
}
|
||||
|
||||
# Record success so the daemon sees a secured node and the gate stops prompting.
|
||||
# Also write a stable machine-id for hive identity (persists across reboots).
|
||||
_rootpw_mark_secured() {
|
||||
_machine_id_dir="/var/db/clawdie"
|
||||
mkdir -p "$(dirname "${SECURED_MARKER}")" 2>/dev/null || true
|
||||
mkdir -p "${_machine_id_dir}" 2>/dev/null || true
|
||||
# mirror the daemon's ownership intent; best-effort (no-op under test).
|
||||
chown colibri:colibri "$(dirname "${SECURED_MARKER}")" 2>/dev/null || true
|
||||
chmod 0750 "$(dirname "${SECURED_MARKER}")" 2>/dev/null || true
|
||||
: > "${SECURED_MARKER}"
|
||||
chmod 0644 "${SECURED_MARKER}" 2>/dev/null || true
|
||||
# Machine identity: generate once, persist forever.
|
||||
if [ ! -f "${_machine_id_dir}/machine-id" ]; then
|
||||
uuidgen > "${_machine_id_dir}/machine-id" 2>/dev/null || \
|
||||
printf '%s' "${HOSTNAME:-unknown}-$(date +%s)-${RANDOM}" > "${_machine_id_dir}/machine-id"
|
||||
fi
|
||||
chmod 0644 "${_machine_id_dir}/machine-id" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# --- interactive (console only; not unit-tested) ----------------------------
|
||||
|
|
|
|||
|
|
@ -244,6 +244,63 @@ collect_zfs_pools() {
|
|||
printf '[]'
|
||||
}
|
||||
|
||||
collect_machine_id() {
|
||||
_id_file="/var/db/clawdie/machine-id"
|
||||
if [ -f "$_id_file" ]; then
|
||||
printf '"%s"' "$(json_escape "$(head -1 "$_id_file" | tr -d '\n\r')")"
|
||||
else
|
||||
printf 'null'
|
||||
fi
|
||||
}
|
||||
|
||||
collect_ollama_status() {
|
||||
# Check if ollama is running and list available models.
|
||||
# Output: {"available":bool, "models":[...]}
|
||||
if command -v ollama >/dev/null 2>&1 && ollama list >/dev/null 2>&1; then
|
||||
printf '{"available":true,"models":['
|
||||
_first=1
|
||||
ollama list 2>/dev/null | tail -n +2 | while IFS= read -r _line; do
|
||||
_name=$(printf '%s' "$_line" | awk '{print $1}')
|
||||
[ -z "$_name" ] && continue
|
||||
if [ "$_first" -ne 1 ]; then printf ','; fi
|
||||
printf '"%s"' "$(json_escape "$_name")"
|
||||
_first=0
|
||||
done
|
||||
printf ']}'
|
||||
else
|
||||
printf '{"available":false,"models":[]}'
|
||||
fi
|
||||
}
|
||||
|
||||
collect_llama_cpp() {
|
||||
# Check for llama.cpp models in the standard directory.
|
||||
# Output: {"available":bool, "models":[...]}
|
||||
_model_dir="/var/db/models"
|
||||
if [ -d "$_model_dir" ] && ls "$_model_dir"/*.gguf >/dev/null 2>&1; then
|
||||
printf '{"available":true,"models":['
|
||||
_first=1
|
||||
for _m in "$_model_dir"/*.gguf; do
|
||||
[ -f "$_m" ] || continue
|
||||
_name=$(basename "$_m" .gguf)
|
||||
if [ "$_first" -ne 1 ]; then printf ','; fi
|
||||
printf '"%s"' "$(json_escape "$_name")"
|
||||
_first=0
|
||||
done
|
||||
printf ']}'
|
||||
else
|
||||
printf '{"available":false,"models":[]}'
|
||||
fi
|
||||
}
|
||||
|
||||
collect_local_llm() {
|
||||
# Aggregate ollama + llama.cpp into a single local_llm block.
|
||||
_ollama="$(collect_ollama_status)"
|
||||
_llamacpp="$(collect_llama_cpp)"
|
||||
_ollama_avail=$(printf '%s' "$_ollama" | sed 's/.*"available":\(true\|false\).*/\1/')
|
||||
_llamacpp_avail=$(printf '%s' "$_llamacpp" | sed 's/.*"available":\(true\|false\).*/\1/')
|
||||
printf '{"ollama":%s,"llama_cpp":%s}' "$_ollama" "$_llamacpp"
|
||||
}
|
||||
|
||||
########################################################################
|
||||
# assemble JSON
|
||||
########################################################################
|
||||
|
|
@ -264,9 +321,12 @@ _vulkan="$(collect_vulkan_support)"
|
|||
_boot_type="$(collect_boot_type)"
|
||||
_colibri="$(collect_colibri_running)"
|
||||
_zfs_pools="$(collect_zfs_pools)"
|
||||
_machine_id="$(collect_machine_id)"
|
||||
_local_llm="$(collect_local_llm)"
|
||||
|
||||
printf '{\n'
|
||||
printf ' "schema_version":"clawdie.hw-probe.v1",\n'
|
||||
printf ' "machine_id":%s,\n' "$_machine_id"
|
||||
printf ' "hostname":"%s",\n' "$(json_escape "$_hostname")"
|
||||
printf ' "freebsd_version":%s,\n' "$_freebsd_ver"
|
||||
printf ' "ram_gb":%s,\n' "$_ram_gb"
|
||||
|
|
@ -282,7 +342,8 @@ printf ' "xorg_running":%s,\n' "$_xorg"
|
|||
printf ' "vulkan_support":%s,\n' "$_vulkan"
|
||||
printf ' "boot_type":%s,\n' "$_boot_type"
|
||||
printf ' "colibri_running":%s,\n' "$_colibri"
|
||||
printf ' "zfs_pools":%s\n' "$_zfs_pools"
|
||||
printf ' "zfs_pools":%s,\n' "$_zfs_pools"
|
||||
printf ' "local_llm":%s\n' "$_local_llm"
|
||||
printf '}\n'
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue