#!/bin/bash

set -euo pipefail

###
# Initial Block Download script.
# 
# Runs a bitcoind process until initial block download is complete.
# Forwards the exit code from bitcoind onward.
#

MYPID=$$

# Setup
mkdir -p ibd
touch ibd/debug.log
chmod +x bitcoind

cleanup() {
    echo "Terminating (pid: ${1})"
    pkill -P ${MYPID} tail || true
}

# Launch bitcoind
./bitcoind -datadir=ibd -disablewallet &
bitcoin_pid=$!

trap "cleanup ${bitcoin_pid}" EXIT

# Wait for IBD to finish and kill the daemon
( 
    set +o pipefail
    tail -f ibd/debug.log | grep -m 1 'progress=1.000000'
    echo "Initial block download complete, killing bitcoin daemon."
    kill ${bitcoin_pid}
) &

# Show some progress 
tail -f ibd/debug.log | grep 'UpdateTip' | awk 'NR % 10000 == 0' &

# Wait for bitcoind to exit
wait ${bitcoin_pid}
exit $?

#!/bin/bash

set -euo pipefail

###
# Initial Block Download script.
# 
# Runs a bitcoind process until initial block download is complete.
# Forwards the exit code from bitcoind onward.
#

MYPID=$$

# Setup
mkdir -p ibd
touch ibd/debug.log
chmod +x bitcoind

cleanup() {
    echo "Terminating (pid: ${1})"
    pkill -P ${MYPID} tail || true
}

: ${PARAMS:=-disablewallet}

# Launch bitcoind
./bitcoind -datadir=ibd "${PARAMS}" &
bitcoin_pid=$!

trap "cleanup ${bitcoin_pid}" EXIT

# Wait for IBD to finish and kill the daemon
( 
    set +o pipefail
    tail -f ibd/debug.log | grep -m 1 'progress=1.000000'
    echo "Initial block download complete, killing bitcoin daemon."
    kill ${bitcoin_pid}
) &

# Show some progress 
tail -f ibd/debug.log | grep 'UpdateTip' | awk 'NR % 10000 == 0' &

# Wait for bitcoind to exit
wait ${bitcoin_pid}
exit $?

Add IBD parameters for CI.
[ci] Add IBD parameters for CI.

Summary: Allow parameters to be set for IBD via CI interface.

Test Plan: Fire a one-off build on this commit and see if it works

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Subscribers: teamcity

Differential Revision: https://reviews.bitcoinabc.org/D2027
