#!/bin/bash set -e CONFIG_DIR="/app/pyblock/pybitblock/config" mkdir -p "$CONFIG_DIR" # Fail fast with a clear message if the config dir is not writable. This is # almost always a UID mismatch between the host bind-mount owner and the # container user (Umbrel forces `user: "1000:1000"`). if ! touch "$CONFIG_DIR/.writetest" 2>/dev/null; then echo "[PyBLOCK] FATAL: cannot write to $CONFIG_DIR" >&2 echo "[PyBLOCK] The bind-mounted host directory must be writable by UID $(id -u):$(id -g)." >&2 echo "[PyBLOCK] On Umbrel, ensure \${APP_DATA_DIR}/data/config is owned by 1000:1000." >&2 ls -ld "$CONFIG_DIR" >&2 || true exit 1 fi rm -f "$CONFIG_DIR/.writetest" # Default to the bundled bitcoin-cli / lncli wrappers when the caller hasn't # overridden them. The wrappers route every CLI invocation through RPC/gRPC # against the Umbrel Bitcoin Core and LND containers, so PyBLOCK's mode A/B # work without a real local node binary on disk. if [ -n "$BITCOIN_RPC_HOST" ] && [ -x /usr/local/bin/bitcoin-cli ]; then export BITCOIN_CLI_PATH="${BITCOIN_CLI_PATH:-/usr/local/bin/bitcoin-cli}" fi if [ -n "$LND_HOST" ] && [ -x /usr/local/bin/lncli ]; then export LND_CLI_PATH="${LND_CLI_PATH:-/usr/local/bin/lncli}" fi # Auto-generate Bitcoin config from env vars if set if [ -n "$BITCOIN_RPC_HOST" ] && [ -n "$BITCOIN_RPC_USER" ]; then BITCOIN_RPC_PORT="${BITCOIN_RPC_PORT:-8332}" cat > "$CONFIG_DIR/bclock.conf" < "$CONFIG_DIR/blndconnect.conf" < "$CONFIG_DIR/intro.conf" echo "[PyBLOCK] Mode set to: ${PYBLOCK_MODE}" elif [ -n "$BITCOIN_RPC_HOST" ] && [ ! -f "$CONFIG_DIR/intro.conf" ]; then # Auto-detect mode from available env vars if [ -n "$LND_HOST" ] || [ -n "$LND_TLS_CERT_PATH" ]; then echo '"A"' > "$CONFIG_DIR/intro.conf" echo "[PyBLOCK] Auto-detected mode: A (Bitcoin + Lightning)" else echo '"B"' > "$CONFIG_DIR/intro.conf" echo "[PyBLOCK] Auto-detected mode: B (Bitcoin Only)" fi fi # Generate default settings if missing if [ ! -f "$CONFIG_DIR/pyblocksettings.conf" ]; then cat > "$CONFIG_DIR/pyblocksettings.conf" < "$CONFIG_DIR/pyblocksettingsClock.conf" <