|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright (c) 2021 The Bitcoin Core developers |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +export LC_ALL=C |
| 7 | +TOPDIR=${TOPDIR:-$(git rev-parse --show-toplevel)} |
| 8 | +BUILDDIR=${BUILDDIR:-$TOPDIR} |
| 9 | +BINDIR=${BINDIR:-$BUILDDIR/src} |
| 10 | +BITCOIND=${BITCOIND:-$BINDIR/bitcoind} |
| 11 | +SHARE_EXAMPLES_DIR=${SHARE_EXAMPLES_DIR:-$TOPDIR/share/examples} |
| 12 | +EXAMPLE_CONF_FILE=${EXAMPLE_CONF_FILE:-$SHARE_EXAMPLES_DIR/bitcoin.conf} |
| 13 | + |
| 14 | +[ ! -x "$BITCOIND" ] && echo "$BITCOIND not found or not executable." && exit 1 |
| 15 | + |
| 16 | +DIRTY="" |
| 17 | +VERSION_OUTPUT=$($BITCOIND --version) |
| 18 | +if [[ $VERSION_OUTPUT == *"dirty"* ]]; then |
| 19 | + DIRTY="${DIRTY}${BITCOIND}\n" |
| 20 | +fi |
| 21 | + |
| 22 | +if [ -n "$DIRTY" ] |
| 23 | +then |
| 24 | + echo -e "WARNING: $BITCOIND was built from a dirty tree.\n" |
| 25 | + echo -e "To safely generate a bitcoin.conf file, please commit your changes to $BITCOIND, rebuild, then run this script again.\n" |
| 26 | +fi |
| 27 | + |
| 28 | +echo 'Generating example bitcoin.conf file in share/examples/' |
| 29 | + |
| 30 | +# create the directory, if it doesn't exist |
| 31 | +mkdir -p "${SHARE_EXAMPLES_DIR}" |
| 32 | + |
| 33 | +# create the header text |
| 34 | +cat > "${EXAMPLE_CONF_FILE}" << 'EOF' |
| 35 | +## |
| 36 | +## bitcoin.conf configuration file. |
| 37 | +## Generated by contrib/devtools/gen-bitcoin-conf.sh. |
| 38 | +## |
| 39 | +## Lines beginning with # are comments. |
| 40 | +## All possible configuration options are provided. To use, copy this file |
| 41 | +## to your data directory (default or specified by -datadir), uncomment |
| 42 | +## options you would like to change, and save the file. |
| 43 | +## |
| 44 | +
|
| 45 | +
|
| 46 | +### Options |
| 47 | +EOF |
| 48 | + |
| 49 | +# parse the output from bitcoind --help |
| 50 | +# adding newlines is a bit funky to ensure portability for BSD |
| 51 | +# see here for more details: https://stackoverflow.com/a/24575385 |
| 52 | +${BITCOIND} --help \ |
| 53 | + | sed '1,/Print this help message and exit/d' \ |
| 54 | + | sed -E 's/^[[:space:]]{2}\-/#/' \ |
| 55 | + | sed -E 's/^[[:space:]]{7}/# /' \ |
| 56 | + | sed -E '/[=[:space:]]/!s/#.*$/&=1/' \ |
| 57 | + | awk '/^#[a-z]/{x=$0;next}{if (NF==0) print x"\n",x="";else print}' \ |
| 58 | + | sed 's,\(^[[:upper:]].*\)\:$,\ |
| 59 | +### \1,' \ |
| 60 | + | sed 's/[[:space:]]*$//' >> "${EXAMPLE_CONF_FILE}" |
| 61 | + |
| 62 | +# create the footer text |
| 63 | +cat >> "${EXAMPLE_CONF_FILE}" << 'EOF' |
| 64 | +
|
| 65 | +# [Sections] |
| 66 | +# Most options will apply to all networks. To confine an option to a specific |
| 67 | +# network, add it under the relevant section below. |
| 68 | +# |
| 69 | +# Note: If not specified under a network section, the options addnode, connect, |
| 70 | +# port, bind, rpcport, rpcbind, and wallet will only apply to mainnet. |
| 71 | +
|
| 72 | +# Options for mainnet |
| 73 | +[main] |
| 74 | +
|
| 75 | +# Options for testnet |
| 76 | +[test] |
| 77 | +
|
| 78 | +# Options for signet |
| 79 | +[signet] |
| 80 | +
|
| 81 | +# Options for regtest |
| 82 | +[regtest] |
| 83 | +EOF |
0 commit comments