wrolpi/wrolpi/scripts/read_config_value.sh
Roland 4788b96aa9
ai: package llama-server for all three deployments, with idle unload
install_llama_cpp.sh builds llama-server from the SHA-pinned v0.3.0
source tarball (single source of truth: on-device upgrade, Pi image,
Live ISO, and the new docker/llm container all call it; version-marker
makes re-runs no-ops).  start_llama_server.sh refuses to start unless
ai.yaml enables AI and the active model file exists — which also covers
unmounted media.  wrolpi-llm.service is installed but deliberately
never enabled at boot: the Controller starts it on demand (registered
in managed_services; the llm compose service follows the samba
pattern), and the API's perpetual idle-unload worker asks the
Controller to stop it after the configured idle minutes.  llama-server
is localhost-only natively, internal-network-only in docker, and never
proxied by Caddy.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-29 16:26:44 -06:00

59 lines
2.2 KiB
Bash
Executable file

#! /usr/bin/env bash
# Read a single top-level scalar value from WROLPi's config (wrolpi.yaml).
#
# wrolpi.yaml is the source of truth for configuration, but scripts that run
# outside the Python API (e.g. start_kiwix_serve.sh, or a minimal Docker
# container) still need to read config values. This reader has zero
# dependencies -- no Python, no jq/yq -- so it runs identically everywhere.
#
# Usage: read_config_value.sh KEY [DEFAULT]
# Prints the value of the top-level scalar KEY, or DEFAULT (empty if omitted)
# when the config file or the key is missing/empty.
#
# Limitation: only top-level scalar keys are supported (sufficient for the
# *_destination keys). Nested keys, lists, and multi-line values are not
# parsed. wrolpi.yaml is written by PyYAML and is regular, so this is reliable
# for the keys it is used with.
set -u
KEY="${1:?Usage: read_config_value.sh KEY [DEFAULT]}"
DEFAULT="${2:-}"
MEDIA_DIRECTORY="${MEDIA_DIRECTORY:-/media/wrolpi}"
# Another top-level config file (e.g. ai.yaml) may be selected with WROLPI_CONFIG_FILE.
CONFIG="${WROLPI_CONFIG_FILE:-${MEDIA_DIRECTORY}/config/wrolpi.yaml}"
value=""
if [ -f "${CONFIG}" ]; then
value=$(awk -v key="${KEY}" '
# Only consider unindented (top-level) "key:" lines.
/^[A-Za-z0-9_]+[[:space:]]*:/ {
idx = index($0, ":")
k = substr($0, 1, idx - 1)
gsub(/[[:space:]]+$/, "", k)
if (k == key) {
v = substr($0, idx + 1)
sub(/^[[:space:]]+/, "", v) # leading whitespace
sub(/[[:space:]]+#.*$/, "", v) # trailing inline comment
sub(/[[:space:]]+$/, "", v) # trailing whitespace
# Unquoted YAML null means "unset"; return empty so the caller uses its
# default, matching how PyYAML/the Python config layer treat null.
if (v == "null" || v == "Null" || v == "NULL" || v == "~") {
print ""
exit
}
# Strip a matching pair of surrounding quotes.
if (v ~ /^".*"$/ || v ~ /^'\''.*'\''$/)
v = substr(v, 2, length(v) - 2)
print v
exit
}
}
' "${CONFIG}")
fi
if [ -z "${value}" ]; then
printf '%s\n' "${DEFAULT}"
else
printf '%s\n' "${value}"
fi