2026-05-19 01:57:42 +00:00
|
|
|
#!/usr/bin/env sh
|
2026-05-19 02:00:58 +00:00
|
|
|
# Seed /data/settings.js on first boot. The /data named volume overlays
|
|
|
|
|
# anything we COPY into /data during image build, so the file has to be
|
|
|
|
|
# planted after the volume mounts.
|
|
|
|
|
#
|
|
|
|
|
# Runs as root, fixes /data ownership + any stale directories left by
|
|
|
|
|
# previous bind-mount attempts, then drops to the node-red user.
|
2026-05-19 01:57:42 +00:00
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
DATA=/data
|
|
|
|
|
TPL=/usr/src/bf-settings.js
|
2026-05-19 02:00:58 +00:00
|
|
|
TARGET="$DATA/settings.js"
|
2026-05-19 01:57:42 +00:00
|
|
|
|
2026-05-19 02:00:58 +00:00
|
|
|
# Clear stale path if a previous broken bind-mount left a directory where
|
|
|
|
|
# we expect a file.
|
|
|
|
|
if [ -d "$TARGET" ]; then
|
|
|
|
|
echo "[bf-nodered] $TARGET is a directory (stale bind mount?). Removing."
|
|
|
|
|
rm -rf "$TARGET"
|
2026-05-19 01:57:42 +00:00
|
|
|
fi
|
|
|
|
|
|
2026-05-19 02:00:58 +00:00
|
|
|
if [ ! -f "$TARGET" ]; then
|
|
|
|
|
echo "[bf-nodered] seeding $TARGET from $TPL"
|
|
|
|
|
cp "$TPL" "$TARGET"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Ensure the volume + seeded file are owned by node-red.
|
|
|
|
|
chown -R node-red:root "$DATA" 2>/dev/null || true
|
|
|
|
|
|
2026-05-19 02:06:36 +00:00
|
|
|
# Drop to the node-red user before launching. nodered/node-red is Alpine
|
|
|
|
|
# based; the Dockerfile installs su-exec for this.
|
|
|
|
|
exec su-exec node-red:node-red npm start --cache /data/.npm -- --userDir /data "$@"
|