2018-06-01 02:08:01 +02:00
|
|
|
#!/bin/ash
|
2018-06-03 00:21:57 +02:00
|
|
|
set -euxo pipefail
|
|
|
|
## This docker-entrypoint will take a copy of the configuration and install any
|
2018-06-01 02:15:49 +02:00
|
|
|
## envvars and then copy any required files into the /app/ directory next to any
|
|
|
|
## 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 18:27:51 +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-04 07:45:14 +02:00
|
|
|
|
|
|
|
function set_conf() {
|
|
|
|
case $1 in
|
|
|
|
$MYSQL_ENV_MYSQL_USER )
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Setting '$MYSQL_ENV_MYSQL_USER' $1 in /app/config/mysqlConfig.json"
|
2018-06-04 07:45:14 +02:00
|
|
|
sed -i 's/"username": "root"/"username": "'$MYSQL_ENV_MYSQL_USER'"/' /app/config/mysqlConfig.json
|
|
|
|
;;
|
|
|
|
$MYSQL_ENV_MYSQL_PASSWORD )
|
2018-06-04 08:50:57 +02:00
|
|
|
## This echo should be sanitized of any secrets before this is finished.
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Setting '$MYSQL_ENV_MYSQL_PASSWORD' $1 in /app/config/mysqlConfig.json"
|
2018-06-04 07:45:14 +02:00
|
|
|
sed -i 's/"password": ""/"password": "'$MYSQL_ENV_MYSQL_PASSWORD'"/' /app/config/mysqlConfig.json
|
|
|
|
;;
|
|
|
|
$MYSQL_ENV_MYSQL_DATABASE )
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Setting '$MYSQL_ENV_MYSQL_DATABASE' $1 in /app/config/mysqlConfig.json"
|
2018-06-04 07:45:14 +02:00
|
|
|
sed -i 's/"database": "lbry"/"database": "'$MYSQL_ENV_MYSQL_DATABASE'"/' /app/config/mysqlConfig.json
|
|
|
|
;;
|
|
|
|
$MYSQL_SERVER_ADDRESS )
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof warn "This variable is not currently available."
|
2018-06-04 07:45:14 +02:00
|
|
|
;;
|
|
|
|
$SITE_ADDRESS )
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Setting '$SITE_ADDRESS' $1 in /app/config/siteConfig.json"
|
2018-06-04 07:45:14 +02:00
|
|
|
sed -i 's/"host": "https://www.example.com"/"host": "https://'$SITE_ADDRESS'"/' /app/config/siteConfig.json
|
|
|
|
;;
|
|
|
|
$GOOGLE_ANALYTICS_UID )
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Setting '$GOOGLE_ANALYTICS_UID' $1 in /app/config/siteConfig.json"
|
2018-06-04 07:45:14 +02:00
|
|
|
sed -i 's/"googleId": null/"googleId": '$GOOGLE_ANALYTICS_UID'/' /app/config/siteConfig.json
|
|
|
|
;;
|
|
|
|
$SITE_TITLE )
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Setting '$SITE_TITLE' $1 in /app/config/siteConfig.json"
|
2018-06-04 07:45:14 +02:00
|
|
|
sed -i 's/"title": "My Site"/"title": "'$SITE_TITLE'"/' /app/config/siteConfig.json
|
|
|
|
;;
|
|
|
|
$SITE_DESCRIPTION )
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Setting '$SITE_DESCRIPTION' $1 in /app/config/siteConfig.json"
|
2018-06-04 07:45:14 +02:00
|
|
|
sed -i 's/"description": "A decentralized hosting platform built on LBRY"/"Description": "'$SITE_DESCRIPTION'"/' /app/config/siteConfig.json
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2018-06-03 00:46:51 +02:00
|
|
|
function configure_speech() {
|
|
|
|
# install configuration changes here.
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Installing configuration files into /app/config/."
|
2018-06-04 07:45:14 +02:00
|
|
|
mkdir -p /app/config/
|
|
|
|
cp /usr/local/src/www.spee.ch/cli/defaults/mysqlConfig.json > /app/config/mysqlConfig.json
|
|
|
|
cp /usr/local/src/www.spee.ch/cli/defaults/siteConfig.json > /app/config/siteConfig.json
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof info "Installing any environment variables that have been set."
|
2018-06-04 07:45:14 +02:00
|
|
|
for i in "${envvars[@]}"; do
|
|
|
|
if [[ -z "$i" ]]; then
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash 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() {
|
|
|
|
## Finally reassert permissions in case there is user added drift.
|
2018-06-05 18:27:51 +02:00
|
|
|
rddo /app "/bin/ash test_for_dir" '775 "speech:speech"'
|
|
|
|
rfdo /app "/bin/ash test_for_file" '665 "speech:speech"'
|
2018-06-01 22:22:13 +02:00
|
|
|
## Define any permission exceptions here.
|
2018-06-05 18:27:51 +02:00
|
|
|
# /bin/ash test_for_dir /app/config 775 "speech:speech"
|
|
|
|
# /bin/ash test_for_file /app/config/siteConfig.json 665 "speech:speech"
|
|
|
|
/bin/ash 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:27:51 +02:00
|
|
|
/bin/ash 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:27:51 +02:00
|
|
|
/bin/ash echof warn "Spee.ch doesn't appear to have a configuration."
|
|
|
|
/bin/ash echof blank "Don't worry we can install it for you."
|
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:27:51 +02:00
|
|
|
/bin/ash 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:27:51 +02:00
|
|
|
/bin/ash echof info "Making an attempt to nicely merge files using:"
|
|
|
|
/bin/ash echof run "mv -fnu /usr/local/src/www.spee.ch/* /app/"
|
2018-06-03 00:46:51 +02:00
|
|
|
mv -fnu /usr/local/src/www.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 18:27:51 +02:00
|
|
|
/bin/ash echof info "Speech wasn't installed, installing fresh copy now."
|
2018-06-03 00:46:51 +02:00
|
|
|
configure_speech
|
2018-06-05 18:27:51 +02:00
|
|
|
/bin/ash echof run "mv /usr/local/src/www.spee.ch/* /app/"
|
2018-06-03 00:46:51 +02:00
|
|
|
mv /usr/local/src/www.spee.ch/* /app/
|
|
|
|
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 18:27:51 +02:00
|
|
|
/bin/ash echof run '/bin/ash test_for_dir /app/config/siteConfig.json 775 "speech:speech"'
|
|
|
|
/bin/ash test_for_file /app/config/siteConfig.json 775 "speech:speech"
|