2018-10-14 14:30:06 +02:00
|
|
|
#!/usr/bin/env bash
|
2019-04-27 21:02:37 +02:00
|
|
|
CONFIG_PATH=/etc/lbry/lbrycrd.conf
|
2018-10-11 02:28:43 +02:00
|
|
|
|
2019-04-30 20:28:07 +02:00
|
|
|
function override_config_option() {
|
|
|
|
# Remove existing config line from a config file
|
|
|
|
# and replace with environment fed value.
|
|
|
|
# Does nothing if the variable does not exist.
|
|
|
|
# var Name of ENV variable
|
|
|
|
# option Name of config option
|
|
|
|
# config Path of config file
|
|
|
|
local var=$1 option=$2 config=$3
|
|
|
|
if [[ -v $var ]]; then
|
|
|
|
# Remove the existing config option:
|
|
|
|
sed -i "/^$option\W*=/d" $config
|
|
|
|
# Add the value from the environment:
|
|
|
|
echo "$option=${!var}" >> $config
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-24 05:34:33 +02:00
|
|
|
function set_config() {
|
2019-04-30 20:28:07 +02:00
|
|
|
if [ -d "$CONFIG_PATH" ]; then
|
|
|
|
echo "$CONFIG_PATH is a directory when it should be a file."
|
|
|
|
exit 1
|
|
|
|
elif [ -f "$CONFIG_PATH" ]; then
|
|
|
|
echo "Merging the mounted config file with environment variables."
|
|
|
|
local MERGED_CONFIG=/tmp/lbrycrd_merged.conf
|
|
|
|
cat $CONFIG_PATH > $MERGED_CONFIG
|
|
|
|
echo "" >> $MERGED_CONFIG
|
|
|
|
override_config_option PORT port $MERGED_CONFIG
|
|
|
|
override_config_option RPC_USER rpcuser $MERGED_CONFIG
|
|
|
|
override_config_option RPC_PASSWORD rpcpassword $MERGED_CONFIG
|
|
|
|
override_config_option RPC_ALLOW_IP rpcallowip $MERGED_CONFIG
|
|
|
|
override_config_option RPC_PORT rpcport $MERGED_CONFIG
|
|
|
|
override_config_option RPC_BIND rpcbind $MERGED_CONFIG
|
|
|
|
# Make the new merged config file the new CONFIG_PATH
|
|
|
|
# This ensures that the original file the user mounted remains unmodified
|
|
|
|
CONFIG_PATH=$MERGED_CONFIG
|
2019-04-24 05:34:33 +02:00
|
|
|
else
|
|
|
|
echo "Creating a fresh config file from environment variables."
|
|
|
|
## Set config params
|
2019-04-30 20:28:07 +02:00
|
|
|
echo "port=${PORT=9246}" > $CONFIG_PATH
|
|
|
|
echo "rpcuser=${RPC_USER=lbry}" >> $CONFIG_PATH
|
|
|
|
echo "rpcpassword=${RPC_PASSWORD=lbry}" >> $CONFIG_PATH
|
|
|
|
echo "rpcallowip=${RPC_ALLOW_IP=127.0.0.1/24}" >> $CONFIG_PATH
|
|
|
|
echo "rpcport=${RPC_PORT=9245}" >> $CONFIG_PATH
|
|
|
|
echo "rpcbind=${RPC_BIND=0.0.0.0}" >> $CONFIG_PATH
|
2019-04-24 05:34:33 +02:00
|
|
|
fi
|
2019-04-30 20:28:07 +02:00
|
|
|
echo "Config: "
|
|
|
|
cat $CONFIG_PATH
|
2019-04-24 05:34:33 +02:00
|
|
|
}
|
|
|
|
|
2019-04-17 01:00:39 +02:00
|
|
|
## Ensure perms are correct prior to running main binary
|
|
|
|
/usr/bin/fix-permissions
|
2018-10-06 20:54:41 +02:00
|
|
|
|
2019-04-17 16:38:56 +02:00
|
|
|
## You can optionally specify a run mode if you want to use lbry defined presets for compatibility.
|
2018-11-13 02:27:11 +01:00
|
|
|
case $RUN_MODE in
|
2018-10-11 03:18:06 +02:00
|
|
|
default )
|
2019-04-24 05:34:33 +02:00
|
|
|
set_config
|
2019-04-17 01:00:39 +02:00
|
|
|
lbrycrdd -server -conf=$CONFIG_PATH -printtoconsole
|
2018-10-11 03:18:06 +02:00
|
|
|
;;
|
2019-04-24 05:34:33 +02:00
|
|
|
## If it's a first run you need to do a full index including all transactions
|
|
|
|
## tx index creates an index of every single transaction in the block history if
|
|
|
|
## not specified it will only create an index for transactions that are related to the wallet or have unspent outputs.
|
|
|
|
## This is generally specific to chainquery.
|
2018-10-11 03:18:06 +02:00
|
|
|
reindex )
|
2019-04-24 05:34:33 +02:00
|
|
|
## Apply this RUN_MODE in the case you need to update a dataset. NOTE: you do not need to use `RUN_MODE reindex` for more than one complete run.
|
|
|
|
set_config
|
2019-04-17 01:00:39 +02:00
|
|
|
lbrycrdd -server -txindex -reindex -conf=$CONFIG_PATH -printtoconsole
|
2018-10-11 03:18:06 +02:00
|
|
|
;;
|
|
|
|
chainquery )
|
2019-04-24 05:34:33 +02:00
|
|
|
## If your only goal is to run Chainquery against this instance of lbrycrd and you're starting a
|
|
|
|
## fresh local dataset use this run mode.
|
|
|
|
set_config
|
2019-04-17 01:00:39 +02:00
|
|
|
lbrycrdd -server -txindex -conf=$CONFIG_PATH -printtoconsole
|
2018-10-11 03:18:06 +02:00
|
|
|
;;
|
2019-04-24 05:34:33 +02:00
|
|
|
regtest )
|
|
|
|
## Set config params
|
|
|
|
## TODO: Make this more automagic in the future.
|
2019-04-27 21:02:37 +02:00
|
|
|
mkdir -p `dirname $CONFIG_PATH`
|
2019-04-27 23:22:12 +02:00
|
|
|
echo "rpcuser=lbry" > $CONFIG_PATH
|
|
|
|
echo "rpcpassword=lbry" >> $CONFIG_PATH
|
|
|
|
echo "rpcport=11337" >> $CONFIG_PATH
|
|
|
|
echo "rpcbind=0.0.0.0" >> $CONFIG_PATH
|
|
|
|
echo "rpcallowip=0.0.0.0/0" >> $CONFIG_PATH
|
|
|
|
echo "regtest=1" >> $CONFIG_PATH
|
|
|
|
echo "txindex=1" >> $CONFIG_PATH
|
|
|
|
echo "server=1" >> $CONFIG_PATH
|
|
|
|
echo "printtoconsole=1" >> $CONFIG_PATH
|
2019-04-24 05:34:33 +02:00
|
|
|
|
|
|
|
#nohup advance &>/dev/null &
|
2019-04-27 23:22:12 +02:00
|
|
|
lbrycrdd -conf=$CONFIG_PATH $1
|
2019-04-24 05:34:33 +02:00
|
|
|
;;
|
|
|
|
testnet )
|
|
|
|
## Set config params
|
|
|
|
## TODO: Make this more automagic in the future.
|
2019-04-27 21:02:37 +02:00
|
|
|
mkdir -p `dirname $CONFIG_PATH`
|
2019-04-27 23:22:12 +02:00
|
|
|
echo "rpcuser=lbry" > $CONFIG_PATH
|
|
|
|
echo "rpcpassword=lbry" >> $CONFIG_PATH
|
|
|
|
echo "rpcport=11337" >> $CONFIG_PATH
|
|
|
|
echo "rpcbind=0.0.0.0" >> $CONFIG_PATH
|
|
|
|
echo "rpcallowip=0.0.0.0/0" >> $CONFIG_PATH
|
|
|
|
echo "testnet=1" >> $CONFIG_PATH
|
|
|
|
echo "txindex=1" >> $CONFIG_PATH
|
|
|
|
echo "server=1" >> $CONFIG_PATH
|
|
|
|
echo "printtoconsole=1" >> $CONFIG_PATH
|
2019-04-24 05:34:33 +02:00
|
|
|
|
|
|
|
#nohup advance &>/dev/null &
|
2019-04-27 23:22:12 +02:00
|
|
|
lbrycrdd -conf=$CONFIG_PATH $1
|
2019-04-24 05:34:33 +02:00
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "Error, you must define a RUN_MODE environment variable."
|
|
|
|
echo "Available options are testnet, regtest, chainquery, default, and reindex"
|
|
|
|
;;
|
2018-10-11 03:18:06 +02:00
|
|
|
esac
|