2018-06-05 19:55:28 +02:00
|
|
|
#!/bin/bash
|
2018-06-05 20:06:45 +02:00
|
|
|
set -eo pipefail
|
2018-06-05 19:55:28 +02:00
|
|
|
## Add -x to set if you want really explicit feedback.
|
2018-06-05 20:06:45 +02:00
|
|
|
## -u breaks unbound variables
|
2018-06-03 00:21:57 +02:00
|
|
|
## This docker-entrypoint will take a copy of the configuration and install any
|
2018-06-05 19:55:28 +02:00
|
|
|
## ENVVARS and then copy any required files into the /app/ directory next to any
|
2018-06-01 02:15:49 +02:00
|
|
|
## custom files added by the user.
|
2018-06-01 19:41:26 +02:00
|
|
|
|
|
|
|
# default to run whatever the user wanted like "/bin/ash"
|
|
|
|
## If user runs no need to run any more of the entrypoint script.
|
|
|
|
if [[ -z "$@" ]]; then
|
2018-06-01 22:23:27 +02:00
|
|
|
echof info "User did not attempt input. Now executing docker-entrypoint."
|
2018-06-01 19:41:26 +02:00
|
|
|
else
|
2018-06-05 18:27:51 +02:00
|
|
|
echof info "Running $@."
|
2018-06-01 19:41:26 +02:00
|
|
|
exec "$@"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-06-05 19:55:28 +02:00
|
|
|
ENVVARS=("MYSQL_ENV_MYSQL_USER"
|
|
|
|
"MYSQL_ENV_MYSQL_PASSWORD"
|
|
|
|
"MYSQL_ENV_MYSQL_DATABASE"
|
|
|
|
"MYSQL_ENV_MYSQL_ADDRESS"
|
|
|
|
"GOOGLE_ANALYTICS_UID"
|
|
|
|
"SITE_TITLE"
|
|
|
|
"SITE_ADDRESS"
|
|
|
|
"SITE_DESCRIPTION"
|
|
|
|
)
|
2018-06-05 20:06:45 +02:00
|
|
|
# MYSQL_ENV_MYSQL_USER=alphauser
|
|
|
|
# MYSQL_ENV_MYSQL_PASSWORD=alphapassword
|
|
|
|
# MYSQL_ENV_MYSQL_DATABASE=alphadatabase
|
|
|
|
# MYSQL_ENV_MYSQL_ADDRESS=alphaaddress
|
|
|
|
# GOOGLE_ANALYTICS_UID=alphauid
|
|
|
|
# SITE_TITLE=AlphaTitle
|
|
|
|
# SITE_ADDRESS=alpha.address.com
|
2018-06-05 19:55:28 +02:00
|
|
|
SITE_DESCRIPTION=alpha.description
|
2018-06-04 07:45:14 +02:00
|
|
|
|
|
|
|
function set_conf() {
|
|
|
|
case $1 in
|
2018-06-05 19:55:28 +02:00
|
|
|
MYSQL_ENV_MYSQL_USER )
|
|
|
|
if [[ -z "$MYSQL_ENV_MYSQL_USER" ]]; then
|
|
|
|
echof info "User did not attempt to configure $MYSQL_ENV_MYSQL_USER"
|
|
|
|
else
|
|
|
|
echof info "Configuring $MYSQL_ENV_MYSQL_USER."
|
|
|
|
echof info "Setting '$MYSQL_ENV_MYSQL_USER' $MYSQL_ENV_MYSQL_USER in /app/config/mysqlConfig.json"
|
|
|
|
sed -i 's/"username": "root"/"username": "'$MYSQL_ENV_MYSQL_USER'"/' /app/config/mysqlConfig.json
|
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
2018-06-05 19:55:28 +02:00
|
|
|
MYSQL_ENV_MYSQL_PASSWORD )
|
|
|
|
if [[ -z "$MYSQL_ENV_MYSQL_PASSWORD" ]]; then
|
|
|
|
echof info "User did not attempt to configure $MYSQL_ENV_MYSQL_PASSWORD"
|
|
|
|
else
|
|
|
|
## This echo should be sanitized of any secrets before this is finished.
|
|
|
|
echof info "Setting '$MYSQL_ENV_MYSQL_PASSWORD' $MYSQL_ENV_MYSQL_PASSWORD in /app/config/mysqlConfig.json"
|
|
|
|
sed -i 's/"password": ""/"password": "'$MYSQL_ENV_MYSQL_PASSWORD'"/' /app/config/mysqlConfig.json
|
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
2018-06-05 19:55:28 +02:00
|
|
|
MYSQL_ENV_MYSQL_DATABASE )
|
|
|
|
if [[ -z "$MYSQL_ENV_MYSQL_DATABASE" ]]; then
|
|
|
|
echof info "User did not attempt to configure $MYSQL_ENV_MYSQL_DATABASE"
|
|
|
|
else
|
|
|
|
echof info "Setting '$MYSQL_ENV_MYSQL_DATABASE' $MYSQL_ENV_MYSQL_DATABASE in /app/config/mysqlConfig.json"
|
|
|
|
sed -i 's/"database": "lbry"/"database": "'$MYSQL_ENV_MYSQL_DATABASE'"/' /app/config/mysqlConfig.json
|
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
2018-06-05 19:55:28 +02:00
|
|
|
MYSQL_SERVER_ADDRESS )
|
|
|
|
if [[ -z "$MYSQL_SERVER_ADDRESS" ]]; then
|
|
|
|
echof info "User did not attempt to configure $MYSQL_SERVER_ADDRESS"
|
|
|
|
else
|
|
|
|
echof warn "This variable is not currently available."
|
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
2018-06-05 19:55:28 +02:00
|
|
|
SITE_ADDRESS )
|
|
|
|
if [[ -z "$SITE_ADDRESS" ]]; then
|
|
|
|
echof info "User did not attempt to configure $SITE_ADDRESS"
|
|
|
|
else
|
|
|
|
echof info "Setting '$SITE_ADDRESS' $SITE_ADDRESS in /app/config/siteConfig.json"
|
2018-06-05 19:59:05 +02:00
|
|
|
sed -i 's,"host": "https://www.example.com","host": "https://"$SITE_ADDRESS,' /app/config/siteConfig.json
|
2018-06-05 19:55:28 +02:00
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
2018-06-05 19:55:28 +02:00
|
|
|
GOOGLE_ANALYTICS_UID )
|
|
|
|
if [[ -z "$GOOGLE_ANALYTICS_UID" ]]; then
|
|
|
|
echof info "User did not attempt to configure $GOOGLE_ANALYTICS_UID"
|
|
|
|
else
|
|
|
|
echof info "Setting '$GOOGLE_ANALYTICS_UID' $GOOGLE_ANALYTICS_UID in /app/config/siteConfig.json"
|
|
|
|
sed -i 's/"googleId": null/"googleId": '$GOOGLE_ANALYTICS_UID'/' /app/config/siteConfig.json
|
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
2018-06-05 19:55:28 +02:00
|
|
|
SITE_TITLE )
|
|
|
|
if [[ -z "$SITE_TITLE" ]]; then
|
|
|
|
echof info "User did not attempt to configure $SITE_TITLE"
|
|
|
|
else
|
|
|
|
echof info "Setting '$SITE_TITLE' $SITE_TITLE in /app/config/siteConfig.json"
|
|
|
|
sed -i 's/"title": "My Site"/"title": "'$SITE_TITLE'"/' /app/config/siteConfig.json
|
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
2018-06-05 19:55:28 +02:00
|
|
|
SITE_DESCRIPTION )
|
|
|
|
if [[ -z "$SITE_DESCRIPTION" ]]; then
|
|
|
|
echof info "User did not attempt to configure $SITE_DESCRIPTION"
|
|
|
|
else
|
|
|
|
echof info "Setting '$SITE_DESCRIPTION' $SITE_DESCRIPTION in /app/config/siteConfig.json"
|
|
|
|
sed -i 's/"description": "A decentralized hosting platform built on LBRY"/"Description": "'$SITE_DESCRIPTION'"/' /app/config/siteConfig.json
|
|
|
|
fi
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-06-03 00:46:51 +02:00
|
|
|
function configure_speech() {
|
|
|
|
# install configuration changes here.
|
2018-06-05 18:34:32 +02:00
|
|
|
echof info "Installing configuration files into /app/config/."
|
2018-06-04 07:45:14 +02:00
|
|
|
mkdir -p /app/config/
|
2018-09-30 23:18:46 +02:00
|
|
|
cp /usr/local/src/spee.ch/cli/defaults/mysqlConfig.json /app/config/mysqlConfig.json
|
|
|
|
cp /usr/local/src/spee.ch/cli/defaults/siteConfig.json /app/config/siteConfig.json
|
2018-06-05 18:34:32 +02:00
|
|
|
echof info "Installing any environment variables that have been set."
|
2018-06-05 19:55:28 +02:00
|
|
|
for i in "${ENVVARS[@]}"; do
|
2018-06-04 07:45:14 +02:00
|
|
|
if [[ -z "$i" ]]; then
|
2018-06-05 18:34:32 +02:00
|
|
|
echof info "$i was not set, moving on."
|
2018-06-04 07:45:14 +02:00
|
|
|
else
|
|
|
|
set_conf $i
|
|
|
|
fi
|
|
|
|
done
|
2018-06-03 00:46:51 +02:00
|
|
|
}
|
2018-06-01 22:20:50 +02:00
|
|
|
|
2018-06-03 00:46:51 +02:00
|
|
|
function final_permset() {
|
2018-06-05 20:20:51 +02:00
|
|
|
# ## Finally reassert permissions in case there is user added drift.
|
|
|
|
# rddo /app "test_for_dir" '775 "speech:speech"'
|
|
|
|
# rfdo /app "test_for_file" '665 "speech:speech"'
|
|
|
|
# ## Define any permission exceptions here.
|
|
|
|
# # test_for_dir /app/config 775 "speech:speech"
|
|
|
|
# # test_for_file /app/config/siteConfig.json 665 "speech:speech"
|
2018-06-05 20:23:49 +02:00
|
|
|
echof info "Copied Spee.ch and set permissions"
|
2018-06-03 00:46:51 +02:00
|
|
|
}
|
|
|
|
|
2018-06-04 07:45:14 +02:00
|
|
|
###################################
|
|
|
|
## Actual installation function. ##
|
|
|
|
###################################
|
2018-06-03 00:46:51 +02:00
|
|
|
# if Spee.ch is not yet installed, copy it into web root.
|
|
|
|
# This could be updated to be part of an upgrade mechanism.
|
|
|
|
if [ "$(ls -A /app)" ]; then
|
2018-06-05 18:34:32 +02:00
|
|
|
echof warn "/app is not Empty. It contains:" 1>&2
|
2018-06-03 00:46:51 +02:00
|
|
|
ls -A 1>&2
|
2018-06-03 00:51:43 +02:00
|
|
|
## If siteConfig.json isn't installed add it and configure or ignore and proceed.
|
2018-06-03 00:46:51 +02:00
|
|
|
if [ ! -e '/app/config/siteConfig.json' ]; then
|
2018-06-05 18:34:32 +02:00
|
|
|
echof warn "Spee.ch doesn't appear to have a configuration."
|
2018-06-05 19:55:28 +02:00
|
|
|
echof blank "Installing config"
|
2018-06-03 00:46:51 +02:00
|
|
|
configure_speech
|
|
|
|
else
|
2018-06-03 00:51:43 +02:00
|
|
|
## If the file exists skip configuration and proceed.
|
2018-06-05 18:34:32 +02:00
|
|
|
echof info "Spee.ch config already installed skipping configuration step."
|
2018-06-03 00:46:51 +02:00
|
|
|
final_permset
|
|
|
|
fi
|
2018-06-03 00:51:43 +02:00
|
|
|
## Install all other files after installing siteConfig.json
|
2018-06-05 18:34:32 +02:00
|
|
|
echof info "Making an attempt to nicely merge files using:"
|
2018-09-30 23:18:46 +02:00
|
|
|
echof run "mv -fnu /usr/local/src/spee.ch/* /app/"
|
|
|
|
mv -fnu /usr/local/src/spee.ch/* /app/
|
2018-06-03 00:51:43 +02:00
|
|
|
final_permset
|
2018-06-03 00:46:51 +02:00
|
|
|
else
|
2018-06-05 19:55:28 +02:00
|
|
|
echof info "Speech not installed, installing fresh copy now."
|
2018-06-03 00:46:51 +02:00
|
|
|
configure_speech
|
2018-09-30 23:18:46 +02:00
|
|
|
echof run "cp -r /usr/local/src/spee.ch/* /app/"
|
|
|
|
cp -r /usr/local/src/spee.ch/* /app/
|
2018-06-03 00:46:51 +02:00
|
|
|
final_permset
|
2018-06-01 19:41:26 +02:00
|
|
|
fi
|
|
|
|
|
2018-06-03 00:53:00 +02:00
|
|
|
## Superfluous permissions assertion maybe axe this later.
|
2018-06-05 20:23:49 +02:00
|
|
|
# echof run 'test_for_dir /app/config/siteConfig.json 775 "speech:speech"'
|
|
|
|
# test_for_file /app/config/siteConfig.json 775 "speech:speech"
|