2019-02-23 16:58:58 +00:00
#!/bin/sh
2017-07-07 13:02:43 +00:00
set -e
2022-05-08 18:58:31 +00:00
eval " $( sh /parseurl.sh " $DATABASE_URL " ETHERPAD_DB) "
2017-07-07 13:02:43 +00:00
2022-05-08 18:58:31 +00:00
# ETHERPAD_DB_PASS is mandatory in mysql container, so we're not offering
2017-07-07 13:02:43 +00:00
# any default. If we're linked to MySQL through legacy link, then we can try
# using the password from the env variable MYSQL_ENV_MYSQL_ROOT_PASSWORD
2022-05-08 18:58:31 +00:00
# if [ "$ETHERPAD_DB_USER" = 'root' ]; then
# : ${ETHERPAD_DB_PASS:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
2017-07-18 11:55:37 +00:00
# fi
2022-05-08 18:58:31 +00:00
if [ -z " $ETHERPAD_DB_USER " ] ; then
echo >& 2 'error: missing required ETHERPAD_DB_USER environment variable'
echo >& 2 ' Did you forget to -e ETHERPAD_DB_USER=... ?'
exit 1
2017-07-07 13:02:43 +00:00
fi
2022-05-08 18:58:31 +00:00
if [ -z " $ETHERPAD_DB_PASS " ] ; then
echo >& 2 'error: missing required ETHERPAD_DB_PASS environment variable'
echo >& 2 ' Did you forget to -e ETHERPAD_DB_PASS=... ?'
exit 1
2017-07-07 13:02:43 +00:00
fi
2019-02-23 16:58:58 +00:00
# Sanitize DB information
ETHERPAD_DB_HOST = " ${ ETHERPAD_DB_HOST :- } "
ETHERPAD_DB_PORT = " ${ ETHERPAD_DB_PORT :- 3306 } "
# Sanitize etherpad info
ETHERPAD_PORT = " ${ ETHERPAD_PORT :- 9001 } "
ETHERPAD_TITLE = " ${ ETHERPAD_TITLE :- Etherpad } "
# Wait for database
echo "Waiting MySQL/MariaDB to be available on port 3306..."
while ! nc -z " ${ ETHERPAD_DB_HOST } " " ${ ETHERPAD_DB_PORT } " ; do
sleep 1 # wait for 1/10 of the second before check again
done
echo "Service MySQL/MariaDB seems ready"
sleep 1
2017-07-07 13:02:43 +00:00
# Check if database already exists
2019-02-23 16:58:58 +00:00
RESULT = " $( mysql \
2022-05-08 18:58:31 +00:00
" -u ${ ETHERPAD_DB_USER } " \
" -p ${ ETHERPAD_DB_PASS } " \
" -P ${ ETHERPAD_DB_PORT } " \
" -h ${ ETHERPAD_DB_HOST } " \
--skip-column-names \
-e " SHOW DATABASES LIKE ' ${ ETHERPAD_DB_NAME } ' " ) "
2017-07-07 13:02:43 +00:00
2019-02-23 16:58:58 +00:00
if [ " $RESULT " != " $ETHERPAD_DB_NAME " ] ; then
2022-05-08 18:58:31 +00:00
# mysql database does not exist, create it
echo " Creating database ${ ETHERPAD_DB_NAME } "
mysql " -u ${ ETHERPAD_DB_USER } " \
" -p ${ ETHERPAD_DB_PASS } " \
" -P ${ ETHERPAD_DB_PORT } " \
" -h ${ ETHERPAD_DB_HOST } " \
-e " create database ${ ETHERPAD_DB_NAME } "
2017-07-07 13:02:43 +00:00
fi
2019-02-23 16:58:58 +00:00
if ! [ -f settings.json ] ; then
2022-05-08 18:58:31 +00:00
echo "Creating database configuration"
cat <<- EOF > settings.json
{
"title" : " ${ ETHERPAD_TITLE } " ,
"ip" : "0.0.0.0" ,
"port" :${ ETHERPAD_PORT } ,
"skinName" : "colibris" ,
"trustProxy" : false,
"minify" : true,
"defaultPadText" : "Welcome to Etherpad!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nIMPORTANT: this pad will be deleted after 30 days. Please don't consider it as document storage." ,
"dbType" : "mysql" ,
"dbSettings" : {
"user" : " ${ ETHERPAD_DB_USER } " ,
"host" : " ${ ETHERPAD_DB_HOST } " ,
"password" : " ${ ETHERPAD_DB_PASS } " ,
"database" : " ${ ETHERPAD_DB_NAME } "
} ,
EOF
if [ -n " $ETHERPAD_ADMIN_PASSWORD " ] ; then
ETHERPAD_ADMIN_USER = " ${ ETHERPAD_ADMIN_USER :- admin } "
echo " Creating admin user configuration for $ETHERPAD_ADMIN_USER / $ETHERPAD_ADMIN_PASSWORD "
cat <<-EOF >> settings.json
"users" : {
" ${ ETHERPAD_ADMIN_USER } " : {
"password" : " ${ ETHERPAD_ADMIN_PASSWORD } " ,
"is_admin" : true
}
} ,
EOF
fi
cat <<- EOF >> settings.json
2022-05-08 19:02:12 +00:00
"ep_expiration" : {
"enabled" : true,
"max_days" : 30
}
2022-05-08 18:58:31 +00:00
}
EOF
2017-07-07 13:02:43 +00:00
fi
2019-02-23 16:58:58 +00:00
if ! grep -q '/* GLENUX BEGIN */' src/static/css/pad.css ; then
cat >> src/static/css/pad.css <<-MARK
/* GLENUX BEGIN */
body#innerdocbody {
font-size: 16px;
line-height: 20px
}
MARK
fi
2017-07-07 13:02:43 +00:00
exec " $@ "
2019-02-23 16:58:58 +00:00