2018-10-14 14:30:06 +02:00
#!/usr/bin/env bash
2018-10-03 19:39:28 +02:00
2018-11-12 03:11:09 +01:00
## Config setup
2018-11-05 04:42:35 +01:00
2018-11-12 03:11:09 +01:00
## Setup Values
2018-11-12 04:38:20 +01:00
DEBUGMODE = $( echo " debugmode= $DEBUGMODE " )
2018-11-12 04:20:38 +01:00
LBRYCRDURL = $( echo " lbrycrdurl=\"rpc:// $RPC_USER : $RPC_PASSWORD @10.5.1.2:9245\" " )
MYSQLDSN = $( echo " mysqldsn=\" $MYSQL_USER : $MYSQL_PASSWORD @tcp( $MYSQL_SERVER :3306)/ $MYSQL_DATABASE \" " )
APIMYSQLDSN = $( echo " apimysqldsn=\" $MYSQL_USER : $MYSQL_PASSWORD @tcp( $MYSQL_SERVER :3306)/ $MYSQL_DATABASE \" " )
2018-11-12 03:11:09 +01:00
## Setup Defaults
2018-11-12 04:38:20 +01:00
DEBUGMODE_DEFAULT = '#DEFAULT-debugmode=false'
2018-11-12 03:11:09 +01:00
LBRYCRDURL_DEFAULT = '#DEFAULT-lbrycrdurl="rpc://lbry:lbry@localhost:9245"'
2018-11-12 03:37:39 +01:00
MYSQLDSN_DEFAULT = '#DEFAULT-mysqldsn="lbry:lbry@tcp(localhost:3306)/chainquery"'
2018-11-12 04:40:27 +01:00
APIMYSQLDSN_DEFAULT = '#DEFAULT-apimysqldsn="lbry:lbry@tcp(localhost:3306)/chainquery"'
2018-11-12 03:11:09 +01:00
## Add setup value variable name to this list to get processed on container start
CONFIG_SETTINGS = (
2018-11-12 04:40:27 +01:00
DEBUGMODE
2018-11-12 03:11:09 +01:00
LBRYCRDURL
2018-11-12 04:40:27 +01:00
MYSQLDSN
2018-11-12 03:11:09 +01:00
APIMYSQLDSN
)
2018-11-12 03:20:04 +01:00
function set_configs( ) {
2018-11-12 03:11:09 +01:00
## Set configs on container start if not already set.
for i in " ${ !CONFIG_SETTINGS[@] } " ; do
## Indirect references http://tldp.org/LDP/abs/html/ivr.html
eval FROM_STRING = \$ " ${ CONFIG_SETTINGS [ $i ] } _DEFAULT "
eval TO_STRING = \$ ${ CONFIG_SETTINGS [ $i ] }
## TODO: Add a bit more magic to make sure that you're only configuring things if not set by config mounts.
2019-04-18 19:48:46 +02:00
sed -i " s~ $FROM_STRING ~ " $TO_STRING "~g" /etc/lbry/chainqueryconfig.toml
2018-11-12 03:11:09 +01:00
done
2018-11-12 03:37:39 +01:00
echo "Reading config for debugging."
2019-04-18 19:48:46 +02:00
cat /etc/lbry/chainqueryconfig.toml
2018-11-12 03:11:09 +01:00
}
2019-04-18 19:48:46 +02:00
if [ [ ! -f /etc/lbry/chainqueryconfig.toml ] ] ; then
2018-11-12 03:37:39 +01:00
echo "[INFO]: Did not find chainqueryconfig.toml"
2018-11-12 03:11:09 +01:00
echo " Installing default and configuring with provided environment variables if any."
2018-11-12 03:20:04 +01:00
## Install fresh copy of config file.
2019-04-18 19:48:46 +02:00
echo "cp -v /etc/lbry/chainqueryconfig.toml.orig /etc/lbry/chainqueryconfig.toml"
cp -v /etc/lbry/chainqueryconfig.toml.orig /etc/lbry/chainqueryconfig.toml
ls -lAh /etc/lbry/
2018-11-12 03:11:09 +01:00
set_configs
else
2019-04-18 19:48:46 +02:00
echo "[INFO]: Found a copy of chainqueryconfig.toml in /etc/lbry"
2018-11-12 03:11:09 +01:00
fi
2018-11-05 04:42:35 +01:00
2018-10-03 19:39:28 +02:00
## For now keeping this simple. Potentially eventually add all command args as envvars for the Dockerfile or use safe way to add args via docker-compose.yml
2019-04-18 19:48:46 +02:00
chainquery serve --configpath "/etc/lbry/"