2017-01-12 03:12:32 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-01-13 23:23:30 +03:00
|
|
|
# exit from script if error was raised.
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# error function is used within a bash function in order to send the error
|
|
|
|
# message directly to the stderr output and exit.
|
|
|
|
error() {
|
|
|
|
echo "$1" > /dev/stderr
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# return is used within bash function in order to return the value.
|
|
|
|
return() {
|
|
|
|
echo "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# set_default function gives the ability to move the setting of default
|
|
|
|
# env variable from docker file to the script thereby giving the ability to the
|
|
|
|
# user override it durin container start.
|
|
|
|
set_default() {
|
2017-01-12 03:12:32 +03:00
|
|
|
# docker initialized env variables with blank string and we can't just
|
|
|
|
# use -z flag as usually.
|
|
|
|
BLANK_STRING='""'
|
|
|
|
|
|
|
|
VARIABLE="$1"
|
2017-01-13 23:23:30 +03:00
|
|
|
DEFAULT="$2"
|
2017-01-12 03:12:32 +03:00
|
|
|
|
|
|
|
if [[ -z "$VARIABLE" || "$VARIABLE" == "$BLANK_STRING" ]]; then
|
|
|
|
|
|
|
|
if [ -z "$DEFAULT" ]; then
|
2017-01-13 23:23:30 +03:00
|
|
|
error "You should specify default variable"
|
2017-01-12 03:12:32 +03:00
|
|
|
else
|
|
|
|
VARIABLE="$DEFAULT"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2017-01-13 23:23:30 +03:00
|
|
|
return "$VARIABLE"
|
2017-01-12 03:12:32 +03:00
|
|
|
}
|
|
|
|
|
2017-01-13 23:23:30 +03:00
|
|
|
# Set default variables if needed.
|
|
|
|
RPCUSER=$(set_default "$RPCUSER" "devuser")
|
|
|
|
RPCPASS=$(set_default "$RPCPASS" "devpass")
|
|
|
|
DEBUG=$(set_default "$DEBUG" "info")
|
2017-05-13 23:21:14 +03:00
|
|
|
NETWORK=$(set_default "$NETWORK" "simnet")
|
2017-01-13 23:23:30 +03:00
|
|
|
|
2019-01-12 22:03:23 +03:00
|
|
|
PARAMS=""
|
|
|
|
if [ "$NETWORK" != "mainnet" ]; then
|
|
|
|
PARAMS=$(echo --$NETWORK)
|
|
|
|
fi
|
|
|
|
|
|
|
|
PARAMS=$(echo $PARAMS \
|
2017-01-13 23:23:30 +03:00
|
|
|
"--debuglevel=$DEBUG" \
|
|
|
|
"--rpcuser=$RPCUSER" \
|
|
|
|
"--rpcpass=$RPCPASS" \
|
|
|
|
"--datadir=/data" \
|
|
|
|
"--logdir=/data" \
|
|
|
|
"--rpccert=/rpc/rpc.cert" \
|
|
|
|
"--rpckey=/rpc/rpc.key" \
|
2018-01-09 04:51:12 +03:00
|
|
|
"--rpclisten=0.0.0.0" \
|
|
|
|
"--txindex"
|
2017-01-13 23:23:30 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
# Set the mining flag only if address is non empty.
|
|
|
|
if [[ -n "$MINING_ADDRESS" ]]; then
|
|
|
|
PARAMS="$PARAMS --miningaddr=$MINING_ADDRESS"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Add user parameters to command.
|
|
|
|
PARAMS="$PARAMS $@"
|
|
|
|
|
|
|
|
# Print command and start bitcoin node.
|
|
|
|
echo "Command: btcd $PARAMS"
|
2018-03-21 21:09:29 +03:00
|
|
|
exec btcd $PARAMS
|
2017-01-12 03:12:32 +03:00
|
|
|
|