montana/Montana-Protocol/Code/docker/runtime/entrypoint.sh

65 lines
2.6 KiB
Bash
Raw Normal View History

2026-05-26 21:14:51 +03:00
#!/bin/sh
# Montana node container entrypoint.
#
# Runs as root just long enough to make the named-volume mountpoint writable
# by user montana, then drops privileges via runuser. On first start, the
2026-05-28 23:22:19 +03:00
# init step prints a 24-word mnemonic to stdout and saves it to mnemonic.txt.
#
# Network test mode (production binary, test parameters) via env:
# MONTANA_MNEMONIC fixed identity (so a test manifest can pre-list this node)
# MONTANA_GENESIS_MANIFEST_B64 base64 of a custom genesis manifest (test cohort)
# MONTANA_D_TEST_OVERRIDE small D → fast windows → fast admission VDF
# MONTANA_FASTSYNC_LAG_THRESHOLD lower lag threshold → observe fast-sync on a young chain
2026-05-26 21:14:51 +03:00
set -eu
DATA_DIR="/var/lib/montana"
MNEMONIC_FILE="$DATA_DIR/mnemonic.txt"
MANIFEST="/etc/montana/genesis-manifest.json"
LISTEN="${MONTANA_LISTEN:-/ip4/0.0.0.0/tcp/8444}"
chown -R montana:montana "$DATA_DIR"
2026-05-28 23:22:19 +03:00
# Test cohort: a supplied genesis manifest overrides the image-baked production one.
if [ -n "${MONTANA_GENESIS_MANIFEST_B64:-}" ]; then
echo "$MONTANA_GENESIS_MANIFEST_B64" | base64 -d > "$DATA_DIR/genesis-manifest.json"
chown montana:montana "$DATA_DIR/genesis-manifest.json"
MANIFEST="$DATA_DIR/genesis-manifest.json"
echo "[entrypoint] TEST MODE: using supplied genesis manifest"
fi
2026-05-26 21:14:51 +03:00
if [ ! -f "$DATA_DIR/identity.bin" ]; then
echo "================================================================"
echo " Montana node — first run on this volume"
2026-05-28 23:22:19 +03:00
echo " Generating identity. Save the 24 mnemonic words below."
2026-05-26 21:14:51 +03:00
echo "================================================================"
2026-05-28 23:22:19 +03:00
if [ -n "${MONTANA_MNEMONIC:-}" ]; then
runuser -u montana -- /usr/local/bin/montana-node init --data-dir "$DATA_DIR" \
--mnemonic "$MONTANA_MNEMONIC" | tee "$MNEMONIC_FILE"
else
runuser -u montana -- /usr/local/bin/montana-node init --data-dir "$DATA_DIR" \
| tee "$MNEMONIC_FILE"
fi
2026-05-26 21:14:51 +03:00
chmod 0400 "$MNEMONIC_FILE"
chown montana:montana "$MNEMONIC_FILE"
2026-05-28 23:22:19 +03:00
echo " Mnemonic saved to $MNEMONIC_FILE (mode 0400)."
fi
DTEST=""
if [ -n "${MONTANA_D_TEST_OVERRIDE:-}" ]; then
DTEST="--d-test-override $MONTANA_D_TEST_OVERRIDE"
echo "[entrypoint] TEST MODE: $DTEST"
fi
FASTSYNC_ENV=""
if [ -n "${MONTANA_FASTSYNC_LAG_THRESHOLD:-}" ]; then
FASTSYNC_ENV="MONTANA_FASTSYNC_LAG_THRESHOLD=$MONTANA_FASTSYNC_LAG_THRESHOLD"
echo "[entrypoint] fast-sync lag threshold override: $MONTANA_FASTSYNC_LAG_THRESHOLD"
2026-05-26 21:14:51 +03:00
fi
2026-05-28 23:22:19 +03:00
exec runuser -u montana -- env $FASTSYNC_ENV /usr/local/bin/montana-node start \
2026-05-26 21:14:51 +03:00
--data-dir "$DATA_DIR" \
--listen "$LISTEN" \
2026-05-28 23:22:19 +03:00
--genesis-manifest "$MANIFEST" \
$DTEST