Changeset View
Changeset View
Standalone View
Standalone View
contrib/seeds/test-seeds.sh
#!/usr/bin/env bash | #!/usr/bin/env bash | ||||
# Copyright (c) 2019 The Bitcoin developers | # Copyright (c) 2019 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
export LC_ALL=C | export LC_ALL=C | ||||
set -u | set -u | ||||
TOPLEVEL=$(git rev-parse --show-toplevel) | TOPLEVEL=$(git rev-parse --show-toplevel) | ||||
DEFAULT_BUILD_DIR="${TOPLEVEL}/build" | DEFAULT_BUILD_DIR="${TOPLEVEL}/build" | ||||
DEFAULT_RPC_PORT=18832 | |||||
help_message() { | help_message() { | ||||
echo "Test connecting to seed nodes. Outputs the seeds that were successfully connected to." | echo "Test connecting to seed nodes. Outputs the seeds that were successfully connected to." | ||||
echo "" | echo "" | ||||
echo "Example usages:" | echo "Example usages:" | ||||
echo "Mainnet: $0 < nodes_main.txt" | echo "Mainnet: $0 < nodes_main.txt" | ||||
echo "Testnet: $0 --testnet < nodes_test.txt" | echo "Testnet: $0 --testnet < nodes_test.txt" | ||||
echo "" | echo "" | ||||
echo "Options:" | echo "Options:" | ||||
echo "-t, --testnet Connect to testnet seeds (mainnet is default)." | echo "-t, --testnet Connect to testnet seeds (mainnet is default)." | ||||
echo "-h, --help Display this help message." | echo "-h, --help Display this help message." | ||||
echo "" | echo "" | ||||
echo "Environment Variables:" | echo "Environment Variables:" | ||||
echo "BUILD_DIR Default: ${DEFAULT_BUILD_DIR}" | echo "BUILD_DIR Default: ${DEFAULT_BUILD_DIR}" | ||||
echo "RPC_PORT Default: ${DEFAULT_RPC_PORT}" | |||||
exit 0 | exit 0 | ||||
} | } | ||||
: "${BUILD_DIR:=${DEFAULT_BUILD_DIR}}" | : "${BUILD_DIR:=${DEFAULT_BUILD_DIR}}" | ||||
OPTION_TESTNET="" | OPTION_TESTNET="" | ||||
# Parse command line arguments | # Parse command line arguments | ||||
while [[ $# -gt 0 ]]; do | while [[ $# -gt 0 ]]; do | ||||
Show All 21 Lines | if [ ! -x "${BITCOIND}" ]; then | ||||
exit 10 | exit 10 | ||||
fi | fi | ||||
if [ ! -x "${BITCOIN_CLI}" ]; then | if [ ! -x "${BITCOIN_CLI}" ]; then | ||||
echo "${BITCOIN_CLI} does not exist or has incorrect permissions." | echo "${BITCOIN_CLI} does not exist or has incorrect permissions." | ||||
exit 11 | exit 11 | ||||
fi | fi | ||||
TEMP_DATADIR=$(mktemp -d) | TEMP_DATADIR=$(mktemp -d) | ||||
BITCOIND="${BITCOIND} -datadir=${TEMP_DATADIR} ${OPTION_TESTNET} -rpcport=18832 -connect=0 -daemon" | : "${RPC_PORT:=${DEFAULT_RPC_PORT}}" | ||||
BITCOIN_CLI="${BITCOIN_CLI} -datadir=${TEMP_DATADIR} ${OPTION_TESTNET} -rpcport=18832" | BITCOIND="${BITCOIND} -datadir=${TEMP_DATADIR} ${OPTION_TESTNET} -rpcport=${RPC_PORT} -connect=0 -daemon" | ||||
BITCOIN_CLI="${BITCOIN_CLI} -datadir=${TEMP_DATADIR} ${OPTION_TESTNET} -rpcport=${RPC_PORT}" | |||||
>&2 echo "Spinning up bitcoind..." | >&2 echo "Spinning up bitcoind..." | ||||
${BITCOIND} || { | ${BITCOIND} || { | ||||
echo "Error starting bitcoind. Stopping script." | echo "Error starting bitcoind. Stopping script." | ||||
exit 12 | exit 12 | ||||
} | } | ||||
cleanup() { | cleanup() { | ||||
# Cleanup background processes spawned by this script. | # Cleanup background processes spawned by this script. | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |