github.com/decred/dcrlnd@v0.7.6/docker/dcrd/start-dcrd.sh (about) 1 #!/usr/bin/env bash 2 3 # exit from script if error was raised. 4 set -e 5 6 # error function is used within a bash function in order to send the error 7 # message directly to the stderr output and exit. 8 error() { 9 echo "$1" > /dev/stderr 10 exit 0 11 } 12 13 # return is used within bash function in order to return the value. 14 return() { 15 echo "$1" 16 } 17 18 # set_default function gives the ability to move the setting of default 19 # env variable from docker file to the script thereby giving the ability to the 20 # user override it durin container start. 21 set_default() { 22 # docker initialized env variables with blank string and we can't just 23 # use -z flag as usually. 24 BLANK_STRING='""' 25 26 VARIABLE="$1" 27 DEFAULT="$2" 28 29 if [[ -z "$VARIABLE" || "$VARIABLE" == "$BLANK_STRING" ]]; then 30 31 if [ -z "$DEFAULT" ]; then 32 error "You should specify default variable" 33 else 34 VARIABLE="$DEFAULT" 35 fi 36 fi 37 38 return "$VARIABLE" 39 } 40 41 # Set default variables if needed. 42 RPCUSER=$(set_default "$RPCUSER" "devuser") 43 RPCPASS=$(set_default "$RPCPASS" "devpass") 44 DEBUG=$(set_default "$DEBUG" "info") 45 NETWORK=$(set_default "$NETWORK" "simnet") 46 47 PARAMS="" 48 if [ "$NETWORK" != "mainnet" ]; then 49 PARAMS=$(echo --$NETWORK) 50 fi 51 52 PARAMS=$(echo $PARAMS \ 53 "--configfile=/data/dcrd.conf" \ 54 "--debuglevel=$DEBUG" \ 55 "--rpcuser=$RPCUSER" \ 56 "--rpcpass=$RPCPASS" \ 57 "--datadir=/data" \ 58 "--logdir=/data" \ 59 "--rpccert=/config/rpc.cert" \ 60 "--rpckey=/config/rpc.key" \ 61 "--rpclisten=0.0.0.0" \ 62 "--txindex" 63 ) 64 65 # Set the mining flag only if address is non empty. 66 if [[ -n "$MINING_ADDRESS" ]]; then 67 PARAMS="$PARAMS --miningaddr=$MINING_ADDRESS" 68 fi 69 70 # Create the dcrctl.conf based in the updated variables. 71 if [ ! -f "/root/.dcrctl/dcrctl.conf" ]; then 72 mkdir /root/.dcrctl 73 cat > "/root/.dcrctl/dcrctl.conf" <<EOF 74 rpcuser=${RPCUSER} 75 rpcpass=${RPCPASS} 76 rpccert="/config/rpc.cert" 77 walletrpcserver=dcrwallet 78 EOF 79 80 fi 81 82 # Add user parameters to command. 83 PARAMS="$PARAMS $@" 84 85 # Print command and start decred node. 86 echo "Command: dcrd $PARAMS" 87 exec dcrd $PARAMS