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 03:11:09 +01:00
APIMYSQLDSN_DEFAULT = '#DEFAULT-apihostport="0.0.0.0:6300"'
## Add setup value variable name to this list to get processed on container start
CONFIG_SETTINGS = (
LBRYCRDURL
MYSQLDSN_
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.
2018-11-12 03:37:39 +01:00
sed -i " s~ $FROM_STRING ~ " $TO_STRING "~g" /etc/chainquery/chainqueryconfig.toml
2018-11-12 03:11:09 +01:00
done
2018-11-12 03:37:39 +01:00
echo "Reading config for debugging."
cat /etc/chainquery/chainqueryconfig.toml
2018-11-12 03:11:09 +01:00
}
if [ [ ! -f /etc/chainquery/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.
2018-11-12 03:37:39 +01:00
echo "cp -v /etc/chainquery/chainqueryconfig.toml.orig /etc/chainquery/chainqueryconfig.toml"
cp -v /etc/chainquery/chainqueryconfig.toml.orig /etc/chainquery/chainqueryconfig.toml
chmod 755 /etc/chainquery/chainqueryconfig.toml
ls -lAh /etc/chainquery/
2018-11-12 03:11:09 +01:00
set_configs
else
echo "[INFO]: Found a copy of chainqueryconfig.toml in /etc/chainquery"
echo " Attempting to non destructively install any new environment configurations."
set_configs
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
2018-11-12 03:30:45 +01:00
su -c "chainquery serve -c " /etc/chainquery/"" chainquery