#!/bin/sh set -eu export BITCOIND_CHAIN="${BITCOIND_CHAIN:-main}" export BITCOIND_USER="${BITCOIND_USER:-user}" export BITCOIND_PASSWORD="${BITCOIND_PASSWORD:-pass}" export BITCOIND_FALLBACKFEE="${BITCOIND_FALLBACKFEE:-0}" export BITCOIND_RPCBIND="${BITCOIND_RPCBIND:-0.0.0.0}" export BITCOIND_RPCALLOWIP="${BITCOIND_RPCALLOWIP:-0.0.0.0/0}" export BITCOIND_TXINDEX="${BITCOIND_TXINDEX:-0}" export BITCOIND_TXOSPENDERINDEX="${BITCOIND_TXOSPENDERINDEX:-0}" export BITCOIND_EXTRA_ARGS="${BITCOIND_EXTRA_ARGS:-}" # The chain name decides the default RPC port, so an unknown value must stop the # container rather than fall through to a default: "-chain=testnet" (the name # Core does not use -- it wants "test") would otherwise be a mainnet node # holding a wallet the caller believes is worthless. case "$BITCOIND_CHAIN" in main) default_port=8332 ;; test) default_port=18332 ;; signet) default_port=38332 ;; regtest) default_port=18443 ;; *) echo "BITCOIND_CHAIN must be one of main, test, signet, regtest (got '$BITCOIND_CHAIN')" >&2 exit 1 ;; esac export BITCOIND_PORT="${BITCOIND_PORT:-$default_port}" case "$BITCOIND_PORT" in '' | *[!0-9]*) echo "BITCOIND_PORT must be a positive integer" >&2 exit 1 ;; esac # A named volume starts out owned by root. Non-recursive on purpose: the only # case that needs fixing is the empty datadir, and a synced mainnet chain is # hundreds of gigabytes -- walking it on every start would add minutes to each # restart. A datadir moved here from an image with another uid must be chowned # by hand, once (see README, "Notes"). mkdir -p "$BITCOIN_DATA" if [ "$(stat -c %u "$BITCOIN_DATA")" != "$USER_UID" ] then chown "$USER_UID:$USER_GID" "$BITCOIN_DATA" fi # Credentials for bitcoin-cli, so the health check does not have to repeat them # on a command line. Written before the daemon starts and readable only by the # daemon's user. rpcport is deliberately at the top level: bitcoin-cli is # invoked without -chain and therefore reads the mainnet section, whatever chain # the daemon runs -- what matters is that the number matches. cli_conf="${BITCOIN_DATA}/cli.conf" umask 077 cat > "$cli_conf" <