-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
71 lines (63 loc) · 2.52 KB
/
entrypoint.sh
File metadata and controls
71 lines (63 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -e
# ── MeshPi Host entrypoint ────────────────────────────────────────────────────
# Supports two modes:
# CMD=host → run meshpi host (default)
# CMD=config → run interactive config wizard
# CMD=shell → drop to bash (debug)
# CMD=agent → run meshpi agent (LLM REPL)
# ─────────────────────────────────────────────────────────────────────────────
CONFIG_FILE="/root/.meshpi/config.env"
# If config.env doesn't exist, try to generate from environment variables
if [ ! -f "$CONFIG_FILE" ]; then
echo "[meshpi] No config.env found — generating from environment variables..."
mkdir -p /root/.meshpi && chmod 700 /root/.meshpi
# Build config.env from ENV vars (any MESHPI_CFG_* variable)
# e.g. MESHPI_CFG_WIFI_SSID=MyNet → WIFI_SSID="MyNet"
touch "$CONFIG_FILE" && chmod 600 "$CONFIG_FILE"
echo "# meshpi config — auto-generated from Docker environment" >> "$CONFIG_FILE"
# Iterate all env vars matching MESHPI_CFG_*
while IFS='=' read -r key value; do
if [[ "$key" == MESHPI_CFG_* ]]; then
cfg_key="${key#MESHPI_CFG_}"
echo "${cfg_key}=\"${value}\"" >> "$CONFIG_FILE"
echo "[meshpi] ${cfg_key} = ***"
fi
done < <(env)
# If still empty after scanning, warn
line_count=$(wc -l < "$CONFIG_FILE")
if [ "$line_count" -le 1 ]; then
echo "[meshpi] WARNING: config.env is empty."
echo "[meshpi] Mount a config.env at /root/.meshpi/config.env"
echo "[meshpi] or set MESHPI_CFG_* environment variables."
echo "[meshpi] Example: -e MESHPI_CFG_WIFI_SSID=MyNetwork"
else
echo "[meshpi] Generated config.env with $((line_count - 1)) fields."
fi
fi
echo "[meshpi] Host starting — port ${MESHPI_PORT:-7422}"
case "${1:-host}" in
host)
exec meshpi host \
--port "${MESHPI_PORT:-7422}" \
--bind "${MESHPI_BIND:-0.0.0.0}"
;;
host-agent)
exec meshpi host \
--port "${MESHPI_PORT:-7422}" \
--bind "${MESHPI_BIND:-0.0.0.0}" \
--agent
;;
config)
exec meshpi config
;;
agent)
exec meshpi agent
;;
shell|bash)
exec /bin/bash
;;
*)
exec "$@"
;;
esac